Commit 90e800cf authored by Peter Oberndorfer's avatar Peter Oberndorfer Committed by Alexandre Julliard

shlwapi: Allow SHOpenRegStream2 A/W to work with not existing values.

When mode is STGM_WRITE or STGM_READWRITE make sure key key exists. Only read data in STGM_READ or STGM_READWRITE mode. Do not depend on value type being REG_BINARY. Succeed when reading not existing values.
parent a35fd4f4
...@@ -440,21 +440,41 @@ static IStream *IStream_Create(HKEY hKey, LPBYTE pbBuffer, DWORD dwLength) ...@@ -440,21 +440,41 @@ static IStream *IStream_Create(HKEY hKey, LPBYTE pbBuffer, DWORD dwLength)
IStream * WINAPI SHOpenRegStream2A(HKEY hKey, LPCSTR pszSubkey, IStream * WINAPI SHOpenRegStream2A(HKEY hKey, LPCSTR pszSubkey,
LPCSTR pszValue,DWORD dwMode) LPCSTR pszValue,DWORD dwMode)
{ {
IStream *tmp;
HKEY hStrKey = NULL; HKEY hStrKey = NULL;
LPBYTE lpBuff = NULL; LPBYTE lpBuff = NULL;
DWORD dwLength, dwType; DWORD dwLength = 0;
LONG ret;
TRACE("(%p,%s,%s,0x%08x)\n", hKey, pszSubkey, pszValue, dwMode); TRACE("(%p,%s,%s,0x%08x)\n", hKey, pszSubkey, pszValue, dwMode);
/* Open the key, read in binary data and create stream */ if (dwMode == STGM_READ)
if (!RegOpenKeyExA (hKey, pszSubkey, 0, KEY_READ, &hStrKey) && ret = RegOpenKeyExA(hKey, pszSubkey, 0, KEY_READ, &hStrKey);
!RegQueryValueExA (hStrKey, pszValue, 0, 0, 0, &dwLength) && else /* in write mode we make sure the subkey exits */
(lpBuff = HeapAlloc (GetProcessHeap(), 0, dwLength)) && ret = RegCreateKeyExA(hKey, pszSubkey, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &hStrKey, NULL);
!RegQueryValueExA (hStrKey, pszValue, 0, &dwType, lpBuff, &dwLength) &&
dwType == REG_BINARY)
return IStream_Create(hStrKey, lpBuff, dwLength);
HeapFree (GetProcessHeap(), 0, lpBuff); if (ret == ERROR_SUCCESS)
{
if (dwMode == STGM_READ || dwMode == STGM_READWRITE)
{
/* read initial data */
ret = RegQueryValueExA(hStrKey, pszValue, 0, 0, 0, &dwLength);
if (ret == ERROR_SUCCESS && dwLength)
{
lpBuff = HeapAlloc(GetProcessHeap(), 0, dwLength);
RegQueryValueExA(hStrKey, pszValue, 0, 0, lpBuff, &dwLength);
}
}
if (!dwLength)
lpBuff = HeapAlloc(GetProcessHeap(), 0, dwLength);
tmp = IStream_Create(hStrKey, lpBuff, dwLength);
return tmp;
}
HeapFree(GetProcessHeap(), 0, lpBuff);
if (hStrKey) if (hStrKey)
RegCloseKey(hStrKey); RegCloseKey(hStrKey);
return NULL; return NULL;
...@@ -468,22 +488,42 @@ IStream * WINAPI SHOpenRegStream2A(HKEY hKey, LPCSTR pszSubkey, ...@@ -468,22 +488,42 @@ IStream * WINAPI SHOpenRegStream2A(HKEY hKey, LPCSTR pszSubkey,
IStream * WINAPI SHOpenRegStream2W(HKEY hKey, LPCWSTR pszSubkey, IStream * WINAPI SHOpenRegStream2W(HKEY hKey, LPCWSTR pszSubkey,
LPCWSTR pszValue, DWORD dwMode) LPCWSTR pszValue, DWORD dwMode)
{ {
IStream *tmp;
HKEY hStrKey = NULL; HKEY hStrKey = NULL;
LPBYTE lpBuff = NULL; LPBYTE lpBuff = NULL;
DWORD dwLength, dwType; DWORD dwLength = 0;
LONG ret;
TRACE("(%p,%s,%s,0x%08x)\n", hKey, debugstr_w(pszSubkey), TRACE("(%p,%s,%s,0x%08x)\n", hKey, debugstr_w(pszSubkey),
debugstr_w(pszValue), dwMode); debugstr_w(pszValue), dwMode);
/* Open the key, read in binary data and create stream */ if (dwMode == STGM_READ)
if (!RegOpenKeyExW (hKey, pszSubkey, 0, KEY_READ, &hStrKey) && ret = RegOpenKeyExW(hKey, pszSubkey, 0, KEY_READ, &hStrKey);
!RegQueryValueExW (hStrKey, pszValue, 0, 0, 0, &dwLength) && else /* in write mode we make sure the subkey exits */
(lpBuff = HeapAlloc (GetProcessHeap(), 0, dwLength)) && ret = RegCreateKeyExW(hKey, pszSubkey, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &hStrKey, NULL);
!RegQueryValueExW (hStrKey, pszValue, 0, &dwType, lpBuff, &dwLength) &&
dwType == REG_BINARY) if (ret == ERROR_SUCCESS)
return IStream_Create(hStrKey, lpBuff, dwLength); {
if (dwMode == STGM_READ || dwMode == STGM_READWRITE)
{
/* read initial data */
ret = RegQueryValueExW(hStrKey, pszValue, 0, 0, 0, &dwLength);
if (ret == ERROR_SUCCESS && dwLength)
{
lpBuff = HeapAlloc(GetProcessHeap(), 0, dwLength);
RegQueryValueExW(hStrKey, pszValue, 0, 0, lpBuff, &dwLength);
}
}
if (!dwLength)
lpBuff = HeapAlloc(GetProcessHeap(), 0, dwLength);
tmp = IStream_Create(hStrKey, lpBuff, dwLength);
return tmp;
}
HeapFree (GetProcessHeap(), 0, lpBuff); HeapFree(GetProcessHeap(), 0, lpBuff);
if (hStrKey) if (hStrKey)
RegCloseKey(hStrKey); RegCloseKey(hStrKey);
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment