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

commit 74196b80005cc1f990000447d53c4b08fcc7deb4
Author:     winesync <[email protected]>
AuthorDate: Sat Mar 12 16:34:11 2022 +0100
Commit:     Mark Jansen <[email protected]>
CommitDate: Sun Mar 20 19:27:55 2022 +0100

    [WINESYNC] msi: Re-publish product if previous installation with different 
package is detected.
    
    Signed-off-by: Piotr Caban <[email protected]>
    Signed-off-by: Hans Leidekker <[email protected]>
    Signed-off-by: Alexandre Julliard <[email protected]>
    
    wine commit id 21836b79dd0acbd16f802f7364c070e1004e48ea by Piotr Caban 
<[email protected]>
---
 dll/win32/msi/action.c  | 46 +++++++++++++++++++++++++++++++++++++++++-----
 dll/win32/msi/msipriv.h |  1 +
 dll/win32/msi/package.c |  4 ++--
 3 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/dll/win32/msi/action.c b/dll/win32/msi/action.c
index cd0f38a0469..c33326af387 100644
--- a/dll/win32/msi/action.c
+++ b/dll/win32/msi/action.c
@@ -4480,6 +4480,7 @@ static UINT ACTION_PublishProduct(MSIPACKAGE *package)
     UINT rc;
     HKEY hukey = NULL, hudkey = NULL;
     MSIRECORD *uirow;
+    BOOL republish = FALSE;
 
     if (!list_empty(&package->patches))
     {
@@ -4488,14 +4489,49 @@ static UINT ACTION_PublishProduct(MSIPACKAGE *package)
             goto end;
     }
 
+    rc = MSIREG_OpenProductKey(package->ProductCode, NULL, package->Context,
+                               &hukey, FALSE);
+    if (rc == ERROR_SUCCESS)
+    {
+        WCHAR *package_code;
+
+        package_code = msi_reg_get_val_str(hukey, 
INSTALLPROPERTY_PACKAGECODEW);
+        if (package_code)
+        {
+            WCHAR *guid;
+
+            guid = msi_get_package_code(package->db);
+            if (guid)
+            {
+                WCHAR packed[SQUASHED_GUID_SIZE];
+
+                squash_guid(guid, packed);
+                msi_free(guid);
+                if (!strcmpW(packed, package_code))
+                {
+                    TRACE("re-publishing product - new package\n");
+                    republish = TRUE;
+                }
+            }
+            msi_free(package_code);
+        }
+    }
+
     /* FIXME: also need to publish if the product is in advertise mode */
-    if (!msi_check_publish(package))
+    if (!republish && !msi_check_publish(package))
+    {
+        if (hukey)
+            RegCloseKey(hukey);
         return ERROR_SUCCESS;
+    }
 
-    rc = MSIREG_OpenProductKey(package->ProductCode, NULL, package->Context,
-                               &hukey, TRUE);
-    if (rc != ERROR_SUCCESS)
-        goto end;
+    if (!hukey)
+    {
+        rc = MSIREG_OpenProductKey(package->ProductCode, NULL, 
package->Context,
+                                   &hukey, TRUE);
+        if (rc != ERROR_SUCCESS)
+            goto end;
+    }
 
     rc = MSIREG_OpenUserDataProductKey(package->ProductCode, package->Context,
                                        NULL, &hudkey, TRUE);
diff --git a/dll/win32/msi/msipriv.h b/dll/win32/msi/msipriv.h
index 1ddae28aaea..845b32b5d8a 100644
--- a/dll/win32/msi/msipriv.h
+++ b/dll/win32/msi/msipriv.h
@@ -1049,6 +1049,7 @@ extern UINT 
msi_set_original_database_property(MSIDATABASE *, const WCHAR *) DEC
 extern WCHAR *msi_get_error_message(MSIDATABASE *, int) DECLSPEC_HIDDEN;
 extern UINT msi_strncpyWtoA(const WCHAR *str, int len, char *buf, DWORD *sz, 
BOOL remote) DECLSPEC_HIDDEN;
 extern UINT msi_strncpyW(const WCHAR *str, int len, WCHAR *buf, DWORD *sz) 
DECLSPEC_HIDDEN;
+extern WCHAR *msi_get_package_code(MSIDATABASE *db) DECLSPEC_HIDDEN;
 
 /* media */
 
diff --git a/dll/win32/msi/package.c b/dll/win32/msi/package.c
index 04ea2a75993..9e1e2be4a28 100644
--- a/dll/win32/msi/package.c
+++ b/dll/win32/msi/package.c
@@ -1385,7 +1385,7 @@ done:
     return r;
 }
 
-static WCHAR *get_package_code( MSIDATABASE *db )
+WCHAR *msi_get_package_code( MSIDATABASE *db )
 {
     WCHAR *ret;
     MSISUMMARYINFO *si;
@@ -1423,7 +1423,7 @@ static UINT get_local_package( const WCHAR *filename, 
WCHAR *localfile )
         msiobj_release( &db->hdr );
         return ERROR_INSTALL_PACKAGE_INVALID;
     }
-    if (!(package_code = get_package_code( db )))
+    if (!(package_code = msi_get_package_code( db )))
     {
         msi_free( product_code );
         msiobj_release( &db->hdr );

Reply via email to