[ADVAPI32_VISTA] Use RegDeleteTree from reg.c

This commit is contained in:
Timo Kreuzer 2023-12-14 20:01:40 +02:00
parent 3dfe367784
commit 90a9171276
3 changed files with 2 additions and 103 deletions

View file

@ -1737,6 +1737,7 @@ Cleanup:
}
#endif
#endif // _ADVAPI32_VISTA_
/************************************************************************
* RegDeleteTreeW
@ -1859,6 +1860,7 @@ RegDeleteTreeA(IN HKEY hKey,
return Ret;
}
#ifndef _ADVAPI32_VISTA_
/************************************************************************
* RegDisableReflectionKey

View file

@ -13,7 +13,6 @@ include_directories(
list(APPEND SOURCE
DllMain.c
../advapi32/reg/reg.c
RegDeleteTree.c
RegSetKeyValue.c
RegLoadMUIString.c
${CMAKE_CURRENT_BINARY_DIR}/advapi32_vista.def)

View file

@ -1,102 +0,0 @@
#include "advapi32_vista.h"
/* heap allocation helpers */
static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
static inline void *heap_alloc( size_t len )
{
return HeapAlloc( GetProcessHeap(), 0, len );
}
static inline BOOL heap_free( void *mem )
{
return HeapFree( GetProcessHeap(), 0, mem );
}
/* Taken from Wine advapi32/registry.c */
/******************************************************************************
* RegDeleteTreeW [ADVAPI32.@]
*
*/
LSTATUS WINAPI 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 = heap_alloc( 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 = 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)
heap_free( lpszName);
if(lpszSubKey)
RegCloseKey(hSubKey);
return ret;
}
/******************************************************************************
* RegDeleteTreeA [ADVAPI32.@]
*
*/
LSTATUS WINAPI RegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
{
LONG ret;
UNICODE_STRING lpszSubKeyW;
if (lpszSubKey) RtlCreateUnicodeStringFromAsciiz( &lpszSubKeyW, lpszSubKey);
else lpszSubKeyW.Buffer = NULL;
ret = RegDeleteTreeW( hKey, lpszSubKeyW.Buffer);
RtlFreeUnicodeString( &lpszSubKeyW );
return ret;
}