Fix SHDeleteKey so that it will handle deleting a key with more than
one subkey. Also includes test.
This commit is contained in:
parent
5ec458fd41
commit
3f3e29254b
|
@ -1298,7 +1298,7 @@ DWORD WINAPI SHQueryValueExW(HKEY hKey, LPCWSTR lpszValue,
|
|||
*/
|
||||
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 @@ DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
|
|||
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 @@ DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
|
|||
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 */
|
||||
}
|
||||
|
|
|
@ -271,6 +271,41 @@ static void test_SHCopyKey(void)
|
|||
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 @@ START_TEST(shreg)
|
|||
test_SHQUeryValueEx();
|
||||
test_SHGetRegPath();
|
||||
test_SHCopyKey();
|
||||
test_SHDeleteKey();
|
||||
delete_key( hkey );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue