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

Alexandre Julliard julliard at winehq.org
Tue Sep 29 11:09:06 CDT 2009


Module: wine
Branch: master
Commit: 90e800cf9b3c60b41f38ee85b30570cff9e8631e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=90e800cf9b3c60b41f38ee85b30570cff9e8631e

Author: Peter Oberndorfer <kumbayo84 at arcor.de>
Date:   Mon Sep 28 22:24:12 2009 +0200

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.

---

 dlls/shlwapi/regstream.c |   80 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 60 insertions(+), 20 deletions(-)

diff --git a/dlls/shlwapi/regstream.c b/dlls/shlwapi/regstream.c
index c167843..275827d 100644
--- a/dlls/shlwapi/regstream.c
+++ b/dlls/shlwapi/regstream.c
@@ -440,21 +440,41 @@ static IStream *IStream_Create(HKEY hKey, LPBYTE pbBuffer, DWORD dwLength)
 IStream * WINAPI SHOpenRegStream2A(HKEY hKey, LPCSTR pszSubkey,
                                    LPCSTR pszValue,DWORD dwMode)
 {
+  IStream *tmp;
   HKEY hStrKey = NULL;
   LPBYTE lpBuff = NULL;
-  DWORD dwLength, dwType;
+  DWORD dwLength = 0;
+  LONG ret;
 
   TRACE("(%p,%s,%s,0x%08x)\n", hKey, pszSubkey, pszValue, dwMode);
 
-  /* Open the key, read in binary data and create stream */
-  if (!RegOpenKeyExA (hKey, pszSubkey, 0, KEY_READ, &hStrKey) &&
-      !RegQueryValueExA (hStrKey, pszValue, 0, 0, 0, &dwLength) &&
-      (lpBuff = HeapAlloc (GetProcessHeap(), 0, dwLength)) &&
-      !RegQueryValueExA (hStrKey, pszValue, 0, &dwType, lpBuff, &dwLength) &&
-      dwType == REG_BINARY)
-    return IStream_Create(hStrKey, lpBuff, dwLength);
+  if (dwMode == STGM_READ)
+    ret = RegOpenKeyExA(hKey, pszSubkey, 0, KEY_READ, &hStrKey);
+  else /* in write mode we make sure the subkey exits */
+    ret = RegCreateKeyExA(hKey, pszSubkey, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &hStrKey, NULL);
 
-  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)
     RegCloseKey(hStrKey);
   return NULL;
@@ -468,22 +488,42 @@ IStream * WINAPI SHOpenRegStream2A(HKEY hKey, LPCSTR pszSubkey,
 IStream * WINAPI SHOpenRegStream2W(HKEY hKey, LPCWSTR pszSubkey,
                                    LPCWSTR pszValue, DWORD dwMode)
 {
+  IStream *tmp;
   HKEY hStrKey = NULL;
   LPBYTE lpBuff = NULL;
-  DWORD dwLength, dwType;
+  DWORD dwLength = 0;
+  LONG ret;
 
   TRACE("(%p,%s,%s,0x%08x)\n", hKey, debugstr_w(pszSubkey),
         debugstr_w(pszValue), dwMode);
 
-  /* Open the key, read in binary data and create stream */
-  if (!RegOpenKeyExW (hKey, pszSubkey, 0, KEY_READ, &hStrKey) &&
-      !RegQueryValueExW (hStrKey, pszValue, 0, 0, 0, &dwLength) &&
-      (lpBuff = HeapAlloc (GetProcessHeap(), 0, dwLength)) &&
-      !RegQueryValueExW (hStrKey, pszValue, 0, &dwType, lpBuff, &dwLength) &&
-      dwType == REG_BINARY)
-    return IStream_Create(hStrKey, lpBuff, dwLength);
+  if (dwMode == STGM_READ)
+    ret = RegOpenKeyExW(hKey, pszSubkey, 0, KEY_READ, &hStrKey);
+  else /* in write mode we make sure the subkey exits */
+    ret = RegCreateKeyExW(hKey, pszSubkey, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &hStrKey, NULL);
+
+  if (ret == ERROR_SUCCESS)
+  {
+    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)
     RegCloseKey(hStrKey);
   return NULL;




More information about the wine-cvs mailing list