Rob Shearman : setupapi: Make the setupapi tests load on systems < Vista by providing a private implementation of RegDeleteTreeW.

Alexandre Julliard julliard at winehq.org
Fri Nov 2 08:10:26 CDT 2007


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

Author: Rob Shearman <rob at codeweavers.com>
Date:   Thu Nov  1 22:04:03 2007 +0000

setupapi: Make the setupapi tests load on systems < Vista by providing a private implementation of RegDeleteTreeW.

---

 dlls/setupapi/tests/devinst.c |   70 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 69 insertions(+), 1 deletions(-)

diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c
index 115da83..5dda333 100644
--- a/dlls/setupapi/tests/devinst.c
+++ b/dlls/setupapi/tests/devinst.c
@@ -70,6 +70,74 @@ static void init_function_pointers(void)
     pSetupDiRegisterDeviceInfo = (void *)GetProcAddress(hSetupAPI, "SetupDiRegisterDeviceInfo");
 }
 
+/* RegDeleteTreeW from dlls/advapi32/registry.c */
+LSTATUS WINAPI devinst_RegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
+{
+    LONG ret;
+    DWORD dwMaxSubkeyLen, dwMaxValueLen;
+    DWORD dwMaxLen, dwSize;
+    WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
+    HKEY hSubKey = hKey;
+
+    if(lpszSubKey)
+    {
+        ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
+        if (ret) return ret;
+    }
+
+    /* Get highest length for keys, values */
+    ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
+            &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
+    if (ret) goto cleanup;
+
+    dwMaxSubkeyLen++;
+    dwMaxValueLen++;
+    dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
+    if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
+    {
+        /* Name too big: alloc a buffer for it */
+        if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
+        {
+            ret = ERROR_NOT_ENOUGH_MEMORY;
+            goto cleanup;
+        }
+    }
+
+
+    /* Recursively delete all the subkeys */
+    while (TRUE)
+    {
+        dwSize = dwMaxLen;
+        if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
+                          NULL, NULL, NULL)) break;
+
+        ret = devinst_RegDeleteTreeW(hSubKey, lpszName);
+        if (ret) goto cleanup;
+    }
+
+    if (lpszSubKey)
+        ret = RegDeleteKeyW(hKey, lpszSubKey);
+    else
+        while (TRUE)
+        {
+            dwSize = dwMaxLen;
+            if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
+                  NULL, NULL, NULL, NULL)) break;
+
+            ret = RegDeleteValueW(hKey, lpszName);
+            if (ret) goto cleanup;
+        }
+
+cleanup:
+    /* Free buffer if allocated */
+    if (lpszName != szNameBuf)
+        HeapFree( GetProcessHeap(), 0, lpszName);
+    if(lpszSubKey)
+        RegCloseKey(hSubKey);
+    return ret;
+}
+
+
 static void test_SetupDiCreateDeviceInfoListEx(void) 
 {
     HDEVINFO devlist;
@@ -686,7 +754,7 @@ static void testDevRegKey(void)
         ret = pSetupDiCallClassInstaller(DIF_REMOVE, set, &devInfo);
         pSetupDiDestroyDeviceInfoList(set);
     }
-    RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
+    devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
 }
 
 START_TEST(devinst)




More information about the wine-cvs mailing list