Commit 91e41807 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

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

parent 50a7b239
...@@ -2981,12 +2981,27 @@ static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package) ...@@ -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 ) ...@@ -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 ...@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment