From 288af81a7cd8e3a809160259e8f1aec8d54a2cef Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Wed, 18 Jun 2008 00:51:13 -0500 Subject: [PATCH] msi: Fix the ProcessComponents action to handle the package context. --- dlls/msi/action.c | 13 +++++++++++-- dlls/msi/msipriv.h | 2 ++ dlls/msi/registry.c | 36 ++++++++++++++++++++++++++++++++++-- dlls/msi/tests/install.c | 25 +++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/dlls/msi/action.c b/dlls/msi/action.c index ca7da987824..30bb7cf3cad 100644 --- a/dlls/msi/action.c +++ b/dlls/msi/action.c @@ -2886,7 +2886,11 @@ static UINT ACTION_ProcessComponents(MSIPACKAGE *package) if (!comp->FullKeypath) continue; - rc = MSIREG_OpenUserDataComponentKey(comp->ComponentId, &hkey, TRUE); + if (package->Context == MSIINSTALLCONTEXT_MACHINE) + rc = MSIREG_OpenLocalUserDataComponentKey(comp->ComponentId, &hkey, TRUE); + else + rc = MSIREG_OpenUserDataComponentKey(comp->ComponentId, &hkey, TRUE); + if (rc != ERROR_SUCCESS) continue; @@ -2904,7 +2908,12 @@ static UINT ACTION_ProcessComponents(MSIPACKAGE *package) RegCloseKey(hkey); } else if (ACTION_VerifyComponentForAction(comp, INSTALLSTATE_ABSENT)) - MSIREG_DeleteUserDataComponentKey(comp->ComponentId); + { + if (package->Context == MSIINSTALLCONTEXT_MACHINE) + MSIREG_DeleteLocalUserDataComponentKey(comp->ComponentId); + else + MSIREG_DeleteUserDataComponentKey(comp->ComponentId); + } /* UI stuff */ uirow = MSI_CreateRecord(3); diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index 6dcd267ba6e..098206543e1 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -768,6 +768,7 @@ extern UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create); extern UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create); extern UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create); extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create); +extern UINT MSIREG_OpenLocalUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create); extern UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create); extern UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create); extern UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create); @@ -786,6 +787,7 @@ extern UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, B extern UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create); extern UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create); extern UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct); +extern UINT MSIREG_DeleteLocalUserDataComponentKey(LPCWSTR szComponent); extern UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent); extern LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name ); diff --git a/dlls/msi/registry.c b/dlls/msi/registry.c index 37558e7f002..6135b470024 100644 --- a/dlls/msi/registry.c +++ b/dlls/msi/registry.c @@ -214,6 +214,8 @@ static const WCHAR szInstaller_LocalManagedProd_fmt[] = { 'I','n','s','t','a','l','l','e','r','\\', 'P','r','o','d','u','c','t','s','\\','%','s',0}; +static const WCHAR localsid[] = {'S','-','1','-','5','-','1','8',0}; + BOOL unsquash_guid(LPCWSTR in, LPWSTR out) { DWORD i,n=0; @@ -666,6 +668,38 @@ UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create) return rc; } +UINT MSIREG_OpenLocalUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create) +{ + WCHAR comp[GUID_SIZE]; + WCHAR keypath[0x200]; + + TRACE("%s\n", debugstr_w(szComponent)); + if (!squash_guid(szComponent, comp)) + return ERROR_FUNCTION_FAILED; + TRACE("squished (%s)\n", debugstr_w(comp)); + + sprintfW(keypath, szUserDataComp_fmt, localsid, comp); + + if (create) + return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); + + return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); +} + +UINT MSIREG_DeleteLocalUserDataComponentKey(LPCWSTR szComponent) +{ + WCHAR comp[GUID_SIZE]; + WCHAR keypath[0x200]; + + TRACE("%s\n", debugstr_w(szComponent)); + if (!squash_guid(szComponent, comp)) + return ERROR_FUNCTION_FAILED; + TRACE("squished (%s)\n", debugstr_w(comp)); + + sprintfW(keypath, szUserDataComp_fmt, localsid, comp); + return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); +} + UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create) { UINT rc; @@ -795,8 +829,6 @@ UINT MSIREG_OpenCurrentUserInstallProps(LPCWSTR szProduct, HKEY *key, UINT MSIREG_OpenLocalSystemInstallProps(LPCWSTR szProduct, HKEY *key, BOOL create) { - static const WCHAR localsid[] = {'S','-','1','-','5','-','1','8',0}; - return MSIREG_OpenInstallProps(szProduct, localsid, key, create); } diff --git a/dlls/msi/tests/install.c b/dlls/msi/tests/install.c index 410121dc3a1..bf329a1d762 100644 --- a/dlls/msi/tests/install.c +++ b/dlls/msi/tests/install.c @@ -2773,6 +2773,31 @@ static void test_publish_processcomponents(void) RegDeleteKeyA(comp, ""); RegCloseKey(comp); + /* ProcessComponents, machine */ + r = MsiInstallProductA(msifile, "PROCESS_COMPONENTS=1 ALLUSERS=1"); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + ok(delete_pf("msitest\\maximus", TRUE), "File not installed\n"); + ok(delete_pf("msitest", FALSE), "File not installed\n"); + + sprintf(keypath, keyfmt, "S-1-5-18"); + + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, keypath, &comp); + ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); + + size = MAX_PATH; + res = RegQueryValueExA(comp, "84A88FD7F6998CE40A22FB59F6B9C2BB", + NULL, NULL, (LPBYTE)val, &size); + ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); + ok(!lstrcmpA(val, "C:\\Program Files\\msitest\\maximus"), + "Expected \"%s\", got \"%s\"\n", "C:\\Program Files\\msitest\\maximus", val); + + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, compkey, &hkey); + ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res); + + RegDeleteValueA(comp, "84A88FD7F6998CE40A22FB59F6B9C2BB"); + RegDeleteKeyA(comp, ""); + RegCloseKey(comp); + DeleteFile(msifile); DeleteFile("msitest\\maximus"); RemoveDirectory("msitest");