Fix SHDeleteKey with multiple subkeys
Bill Medland
billmedland at mercuryspeed.com
Tue Oct 12 14:04:56 CDT 2004
Bill Medland (billmedland at mercuryspeed.com)
Fix SHDeleteKey so that it will handle deleting a key with more than
one subkey. Also includes test.
Index: wine/dlls/shlwapi/tests/shreg.c
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/tests/shreg.c,v
retrieving revision 1.15
diff -u -r1.15 shreg.c
--- wine/dlls/shlwapi/tests/shreg.c 27 Jan 2004 20:13:17 -0000 1.15
+++ wine/dlls/shlwapi/tests/shreg.c 12 Oct 2004 19:00:09 -0000
@@ -271,6 +271,41 @@
RegCloseKey(hKeyDst);
}
+static void test_SHDeleteKey()
+{
+ HKEY hKeyTest;
+ int sysfail=1;
+ if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKeyTest))
+ {
+ HKEY hKeyS;
+ if (!RegCreateKey(hKeyTest, "ODBC", &hKeyS))
+ {
+ HKEY hKeyO;
+ if (!RegCreateKey(hKeyS, "ODBC.INI", &hKeyO))
+ {
+ RegCloseKey (hKeyO);
+ if (!RegCreateKey(hKeyS, "ODBCINST.INI", &hKeyO))
+ {
+ RegCloseKey (hKeyO);
+ sysfail = 0;
+ }
+ }
+ RegCloseKey (hKeyS);
+ }
+ RegCloseKey (hKeyTest);
+ }
+ if (!sysfail)
+ {
+ HKEY hKeyS;
+ DWORD dwRet;
+ ok (!SHDeleteKey(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC"), "SHDeleteKey failed\n");
+ ok ((dwRet = RegOpenKey(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC", &hKeyS)) == ERROR_FILE_NOT_FOUND, "SHDeleteKey did not delete\n");
+ if (dwRet == ERROR_SUCCESS)
+ RegCloseKey (hKeyS);
+ }
+ else
+ ok (0, "Could not set up SHDeleteKey test\n");
+}
START_TEST(shreg)
{
@@ -285,5 +320,6 @@
test_SHQUeryValueEx();
test_SHGetRegPath();
test_SHCopyKey();
+ test_SHDeleteKey();
delete_key( hkey );
}
Index: wine/dlls/shlwapi/reg.c
===================================================================
RCS file: /home/wine/wine/dlls/shlwapi/reg.c,v
retrieving revision 1.52
diff -u -r1.52 reg.c
--- wine/dlls/shlwapi/reg.c 14 Sep 2004 19:31:22 -0000 1.52
+++ wine/dlls/shlwapi/reg.c 12 Oct 2004 19:00:24 -0000
@@ -1298,7 +1298,7 @@
*/
DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
{
- DWORD dwRet, dwKeyCount = 0, dwMaxSubkeyLen = 0, dwSize, i;
+ DWORD dwRet, dwMaxSubkeyLen = 0, dwSize;
CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
HKEY hSubKey = 0;
@@ -1307,8 +1307,8 @@
dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
if(!dwRet)
{
- /* Find how many subkeys there are */
- dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,
+ /* Find the maximum subkey length so that we can allocate a buffer */
+ dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
&dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);
if(!dwRet)
{
@@ -1321,14 +1321,15 @@
dwRet = ERROR_NOT_ENOUGH_MEMORY;
else
{
- /* Recursively delete all the subkeys */
- for(i = 0; i < dwKeyCount && !dwRet; i++)
+ while (dwRet == ERROR_SUCCESS)
{
dwSize = dwMaxSubkeyLen;
- dwRet = RegEnumKeyExA(hSubKey, i, lpszName, &dwSize, NULL, NULL, NULL, NULL);
- if(!dwRet)
+ dwRet = RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL, NULL, NULL, NULL);
+ if (dwRet == ERROR_SUCCESS || dwRet == ERROR_MORE_DATA)
dwRet = SHDeleteKeyA(hSubKey, lpszName);
}
+ if (dwRet == ERROR_NO_MORE_ITEMS)
+ dwRet = ERROR_SUCCESS;
if (lpszName != szNameBuf)
HeapFree(GetProcessHeap(), 0, lpszName); /* Free buffer if allocated */
}
More information about the wine-patches
mailing list