https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ba86f76417c383373370b30e71a16610dc756e2d

commit ba86f76417c383373370b30e71a16610dc756e2d
Author:     winesync <[email protected]>
AuthorDate: Sat Mar 12 16:34:04 2022 +0100
Commit:     Mark Jansen <[email protected]>
CommitDate: Sun Mar 20 19:27:53 2022 +0100

    [WINESYNC] msi: Only delete empty registry keys in delete_key().
    
    Signed-off-by: Zebediah Figura <[email protected]>
    Signed-off-by: Hans Leidekker <[email protected]>
    Signed-off-by: Alexandre Julliard <[email protected]>
    
    wine commit id 91e418073f64368110a9339d17fad36ad26c1a7f by Zebediah Figura 
<[email protected]>
---
 dll/win32/msi/action.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/dll/win32/msi/action.c b/dll/win32/msi/action.c
index dbd08e57db4..e5633821af0 100644
--- a/dll/win32/msi/action.c
+++ b/dll/win32/msi/action.c
@@ -2988,12 +2988,27 @@ static UINT ACTION_WriteRegistryValues(MSIPACKAGE 
*package)
     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 
)
 {
+    LONG res = ERROR_SUCCESS;
     REGSAM access = 0;
     WCHAR *subkey, *p;
     HKEY hkey;
-    LONG res;
 
     access |= get_registry_view( comp );
 
@@ -3006,10 +3021,15 @@ static void delete_key( const MSICOMPONENT *comp, HKEY 
root, const WCHAR *path )
             if (!p[1]) continue; /* trailing backslash */
             hkey = open_key( comp, root, subkey, FALSE, access | READ_CONTROL 
);
             if (!hkey) break;
+            if (!is_key_empty(comp, hkey, p + 1))
+            {
+                RegCloseKey(hkey);
+                break;
+            }
             res = RegDeleteKeyExW( hkey, p + 1, access, 0 );
             RegCloseKey( hkey );
         }
-        else
+        else if (is_key_empty(comp, root, subkey))
             res = RegDeleteKeyExW( root, subkey, access, 0 );
         if (res)
         {
@@ -3024,17 +3044,14 @@ static void delete_value( const MSICOMPONENT *comp, 
HKEY root, const WCHAR *path
 {
     LONG res;
     HKEY hkey;
-    DWORD num_subkeys, num_values;
 
     if ((hkey = open_key( comp, root, path, FALSE, KEY_SET_VALUE | 
KEY_QUERY_VALUE )))
     {
         if ((res = RegDeleteValueW( hkey, value )))
             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 );
-        if (!res && !num_subkeys && !num_values)
+        if (is_key_empty(comp, root, path))
         {
             TRACE("removing empty key %s\n", debugstr_w(path));
             delete_key( comp, root, path );

Reply via email to