msi: Expand REG_EXPAND_SZ keys when resolving AppSearch entries

Jérôme Gardou jerome.gardou at reactos.org
Wed Feb 19 15:21:01 CST 2014


---
 dlls/msi/appsearch.c     | 22 ++++++++++++++++++++++
 dlls/msi/tests/package.c | 22 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/dlls/msi/appsearch.c b/dlls/msi/appsearch.c
index 0d9c302..5bb240d 100644
--- a/dlls/msi/appsearch.c
+++ b/dlls/msi/appsearch.c
@@ -451,6 +451,28 @@ static UINT ACTION_AppSearchReg(MSIPACKAGE *package, 
LPWSTR *appValue, MSISIGNAT
     if (sz == 0)
         goto end;
 
+    /* Expand if needed */
+    if (regType == REG_EXPAND_SZ)
+    {
+        LPWSTR buf;
+        sz = ExpandEnvironmentStringsW((LPCWSTR)value, NULL, 0);
+        if (!sz)
+        {
+            ERR("ExpandEnvironmentStringsW failed.\n");
+            goto end;
+        }
+        buf = msi_alloc(sz * sizeof(WCHAR));
+        sz = ExpandEnvironmentStringsW((LPCWSTR)value, buf, sz);
+        if (!sz)
+        {
+            ERR("ExpandEnvironmentStringsW failed.\n");
+            msi_free(buf);
+            goto end;
+        }
+        msi_free(value);
+        value = (LPBYTE)buf;
+    }
+
     if ((regType == REG_SZ || regType == REG_EXPAND_SZ) &&
         (ptr = strchrW((LPWSTR)value, '"')) && (end = strchrW(++ptr, '"')))
         *end = '\0';
diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c
index 935a0fd..d1044fd 100644
--- a/dlls/msi/tests/package.c
+++ b/dlls/msi/tests/package.c
@@ -3656,6 +3656,8 @@ static void test_appsearch(void)
     MSIHANDLE hdb;
     CHAR prop[MAX_PATH];
     DWORD size;
+    HKEY hkey;
+    const char reg_expand_value[] = "%systemroot%\\system32\\notepad.exe";
 
     hdb = create_package_db();
     ok ( hdb, "failed to create package database\n" );
@@ -3669,12 +3671,23 @@ static void test_appsearch(void)
     r = add_appsearch_entry( hdb, "'NOTEPAD', 'NewSignature2'" );
     ok( r == ERROR_SUCCESS, "cannot add entry: %d\n", r );
 
+    r = add_appsearch_entry( hdb, "'REGEXPANDVAL', 'NewSignature3'" );
+    ok( r == ERROR_SUCCESS, "cannot add entry: %d\n", r );
+
     r = create_reglocator_table( hdb );
     ok( r == ERROR_SUCCESS, "cannot create RegLocator table: %d\n", r );
 
     r = add_reglocator_entry( hdb, "NewSignature1", 0, 
"htmlfile\\shell\\open\\command", "", 1 );
     ok( r == ERROR_SUCCESS, "cannot create RegLocator table: %d\n", r );
 
+    r = RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Winetest_msi", 0, NULL, 
0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
+    ok( r == ERROR_SUCCESS, "Could not create key: %d.\n", r );
+    r = RegSetValueExA(hkey, NULL, 0, REG_EXPAND_SZ, (const 
BYTE*)reg_expand_value, strlen(reg_expand_value) + 1);
+    ok( r == ERROR_SUCCESS, "Could not set key value: %d.\n", r);
+    RegCloseKey(hkey);
+    r = add_reglocator_entry( hdb, "NewSignature3", 1, 
"Software\\Winetest_msi", "", 1 );
+    ok( r == ERROR_SUCCESS, "cannot create RegLocator table: %d\n", r );
+
     r = create_drlocator_table( hdb );
     ok( r == ERROR_SUCCESS, "cannot create DrLocator table: %d\n", r );
 
@@ -3690,6 +3703,9 @@ static void test_appsearch(void)
     r = add_signature_entry( hdb, "'NewSignature2', 'NOTEPAD.EXE|
notepad.exe', '', '', '', '', '', '', ''" );
     ok( r == ERROR_SUCCESS, "cannot add signature: %d\n", r );
 
+    r = add_signature_entry( hdb, "'NewSignature3', 'NOTEPAD.EXE|
notepad.exe', '', '', '', '', '', '', ''" );
+    ok( r == ERROR_SUCCESS, "cannot add signature: %d\n", r );
+
     r = package_from_db( hdb, &hpkg );
     if (r == ERROR_INSTALL_PACKAGE_REJECTED)
     {
@@ -3716,9 +3732,15 @@ static void test_appsearch(void)
     r = MsiGetPropertyA( hpkg, "NOTEPAD", prop, &size );
     ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
 
+    size = sizeof(prop);
+    r = MsiGetPropertyA( hpkg, "REGEXPANDVAL", prop, &size );
+    ok( r == ERROR_SUCCESS, "get property failed: %d\n", r);
+    ok( lstrlenA(prop) != 0, "Expected non-zero length\n");
+
 done:
     MsiCloseHandle( hpkg );
     DeleteFileA(msifile);
+    RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Winetest_msi");
 }
 
 static void test_appsearch_complocator(void)
-- 
1.8.3.2




More information about the wine-patches mailing list