msi: Only delete empty registry keys in delete_key().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2018-06-01 21:48:20 -05:00 committed by Alexandre Julliard
parent 50a7b239bd
commit 91e418073f
1 changed files with 23 additions and 6 deletions

View File

@ -2981,12 +2981,27 @@ static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
return rc; return rc;
} }
static int is_key_empty(const MSICOMPONENT *comp, HKEY root, const WCHAR *path)
{
DWORD subkeys, values;
HKEY key;
LONG res;
key = open_key(comp, root, path, FALSE, get_registry_view(comp) | KEY_READ);
if (!key) return 0;
res = RegQueryInfoKeyW(key, 0, 0, 0, &subkeys, 0, 0, &values, 0, 0, 0, 0);
RegCloseKey(key);
return !res && !subkeys && !values;
}
static void delete_key( const MSICOMPONENT *comp, HKEY root, const WCHAR *path ) static void delete_key( const MSICOMPONENT *comp, HKEY root, const WCHAR *path )
{ {
LONG res = ERROR_SUCCESS;
REGSAM access = 0; REGSAM access = 0;
WCHAR *subkey, *p; WCHAR *subkey, *p;
HKEY hkey; HKEY hkey;
LONG res;
access |= get_registry_view( comp ); access |= get_registry_view( comp );
@ -2999,10 +3014,15 @@ static void delete_key( const MSICOMPONENT *comp, HKEY root, const WCHAR *path )
if (!p[1]) continue; /* trailing backslash */ if (!p[1]) continue; /* trailing backslash */
hkey = open_key( comp, root, subkey, FALSE, access | READ_CONTROL ); hkey = open_key( comp, root, subkey, FALSE, access | READ_CONTROL );
if (!hkey) break; if (!hkey) break;
if (!is_key_empty(comp, hkey, p + 1))
{
RegCloseKey(hkey);
break;
}
res = RegDeleteKeyExW( hkey, p + 1, access, 0 ); res = RegDeleteKeyExW( hkey, p + 1, access, 0 );
RegCloseKey( hkey ); RegCloseKey( hkey );
} }
else else if (is_key_empty(comp, root, subkey))
res = RegDeleteKeyExW( root, subkey, access, 0 ); res = RegDeleteKeyExW( root, subkey, access, 0 );
if (res) if (res)
{ {
@ -3017,17 +3037,14 @@ static void delete_value( const MSICOMPONENT *comp, HKEY root, const WCHAR *path
{ {
LONG res; LONG res;
HKEY hkey; HKEY hkey;
DWORD num_subkeys, num_values;
if ((hkey = open_key( comp, root, path, FALSE, KEY_SET_VALUE | KEY_QUERY_VALUE ))) if ((hkey = open_key( comp, root, path, FALSE, KEY_SET_VALUE | KEY_QUERY_VALUE )))
{ {
if ((res = RegDeleteValueW( hkey, value ))) if ((res = RegDeleteValueW( hkey, value )))
TRACE("failed to delete value %s (%d)\n", debugstr_w(value), res); TRACE("failed to delete value %s (%d)\n", debugstr_w(value), res);
res = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, &num_subkeys, NULL, NULL, &num_values,
NULL, NULL, NULL, NULL );
RegCloseKey( hkey ); RegCloseKey( hkey );
if (!res && !num_subkeys && !num_values) if (is_key_empty(comp, root, path))
{ {
TRACE("removing empty key %s\n", debugstr_w(path)); TRACE("removing empty key %s\n", debugstr_w(path));
delete_key( comp, root, path ); delete_key( comp, root, path );