From 70be1e77460a767366808593cfd961bf24cc8cc5 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Mon, 3 Nov 2008 22:16:43 -0600 Subject: [PATCH] msi: Factor out the code to open a product key. --- dlls/msi/action.c | 13 +++----- dlls/msi/msi.c | 81 ++++++++++++++++++++++++---------------------- dlls/msi/msipriv.h | 5 ++- dlls/msi/registry.c | 93 +++++++++++++++++++---------------------------------- dlls/msi/source.c | 12 ++++--- dlls/msi/upgrade.c | 7 ++-- 6 files changed, 93 insertions(+), 118 deletions(-) diff --git a/dlls/msi/action.c b/dlls/msi/action.c index 09a4915d202..fda0059b02a 100644 --- a/dlls/msi/action.c +++ b/dlls/msi/action.c @@ -3582,22 +3582,19 @@ static UINT ACTION_PublishProduct(MSIPACKAGE *package) if (!msi_check_publish(package)) return ERROR_SUCCESS; + rc = MSIREG_OpenProductKey(package->ProductCode, package->Context, + &hukey, TRUE); + if (rc != ERROR_SUCCESS) + goto end; + if (package->Context == MSIINSTALLCONTEXT_MACHINE) { - rc = MSIREG_OpenLocalClassesProductKey(package->ProductCode, &hukey, TRUE); - if (rc != ERROR_SUCCESS) - goto end; - rc = MSIREG_OpenLocalUserDataProductKey(package->ProductCode, &hudkey, TRUE); if (rc != ERROR_SUCCESS) goto end; } else { - rc = MSIREG_OpenUserProductsKey(package->ProductCode, &hukey, TRUE); - if (rc != ERROR_SUCCESS) - goto end; - rc = MSIREG_OpenUserDataProductKey(package->ProductCode, &hudkey, TRUE); if (rc != ERROR_SUCCESS) goto end; diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index 79407387f90..b629bc6903c 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -51,11 +51,14 @@ static UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context) *context = MSIINSTALLCONTEXT_NONE; - if (MSIREG_OpenLocalManagedProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS) + if (MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED, + &hkey, FALSE) == ERROR_SUCCESS) *context = MSIINSTALLCONTEXT_USERMANAGED; - else if (MSIREG_OpenLocalClassesProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS) + else if (MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE, + &hkey, FALSE) == ERROR_SUCCESS) *context = MSIINSTALLCONTEXT_MACHINE; - else if (MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS) + else if (MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, + &hkey, FALSE) == ERROR_SUCCESS) *context = MSIINSTALLCONTEXT_USERUNMANAGED; RegCloseKey(hkey); @@ -644,9 +647,12 @@ UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer) sz = GUID_SIZE; unsquash_guid(squished_prod, szBuffer); - if (MSIREG_OpenLocalManagedProductKey(szBuffer, &prodkey, FALSE) == ERROR_SUCCESS || - MSIREG_OpenUserProductsKey(szBuffer, &prodkey, FALSE) == ERROR_SUCCESS || - MSIREG_OpenLocalClassesProductKey(szBuffer, &prodkey, FALSE) == ERROR_SUCCESS) + if (MSIREG_OpenProductKey(szBuffer, MSIINSTALLCONTEXT_USERMANAGED, + &prodkey, FALSE) == ERROR_SUCCESS || + MSIREG_OpenProductKey(szBuffer, MSIINSTALLCONTEXT_USERUNMANAGED, + &prodkey, FALSE) == ERROR_SUCCESS || + MSIREG_OpenProductKey(szBuffer, MSIINSTALLCONTEXT_MACHINE, + &prodkey, FALSE) == ERROR_SUCCESS) { RegCloseKey(prodkey); rc = ERROR_SUCCESS; @@ -716,16 +722,14 @@ static UINT WINAPI MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute, if (!squash_guid(szProduct, squished_pc)) return ERROR_INVALID_PARAMETER; - r = MSIREG_OpenLocalManagedProductKey(szProduct, &prodkey, FALSE); - if (r != ERROR_SUCCESS) + if ((r = MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED, + &prodkey, FALSE)) != ERROR_SUCCESS && + (r = MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, + &prodkey, FALSE)) != ERROR_SUCCESS && + (r = MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE, + &prodkey, FALSE)) == ERROR_SUCCESS) { - r = MSIREG_OpenUserProductsKey(szProduct, &prodkey, FALSE); - if (r != ERROR_SUCCESS) - { - r = MSIREG_OpenLocalClassesProductKey(szProduct, &prodkey, FALSE); - if (r == ERROR_SUCCESS) - classes = TRUE; - } + classes = TRUE; } if (classes) @@ -1034,8 +1038,10 @@ UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid, if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid) return ERROR_INVALID_PARAMETER; - MSIREG_OpenLocalManagedProductKey(szProductCode, &managed, FALSE); - MSIREG_OpenUserProductsKey(szProductCode, &prod, FALSE); + MSIREG_OpenProductKey(szProductCode, MSIINSTALLCONTEXT_USERMANAGED, + &managed, FALSE); + MSIREG_OpenProductKey(szProductCode, MSIINSTALLCONTEXT_USERUNMANAGED, + &prod, FALSE); if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED) { @@ -1057,7 +1063,7 @@ UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid, { package = INSTALLPROPERTY_LOCALPACKAGEW; MSIREG_OpenLocalSystemProductKey(szProductCode, &props, FALSE); - MSIREG_OpenLocalClassesProductKey(szProductCode, &classes, FALSE); + MSIREG_OpenProductKey(szProductCode, dwContext, &classes, FALSE); if (!props && !classes) goto done; @@ -1271,13 +1277,7 @@ static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context) UINT r; HKEY hkey; - if (context == MSIINSTALLCONTEXT_MACHINE) - r = MSIREG_OpenLocalClassesProductKey(prodcode, &hkey, FALSE); - else if (context == MSIINSTALLCONTEXT_USERUNMANAGED) - r = MSIREG_OpenUserProductsKey(prodcode, &hkey, FALSE); - else - r = MSIREG_OpenLocalManagedProductKey(prodcode, &hkey, FALSE); - + r = MSIREG_OpenProductKey(prodcode, context, &hkey, FALSE); RegCloseKey(hkey); return (r == ERROR_SUCCESS); } @@ -1430,16 +1430,14 @@ INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct) if (lstrlenW(szProduct) != GUID_SIZE - 1) return INSTALLSTATE_INVALIDARG; - r = MSIREG_OpenLocalManagedProductKey(szProduct, &prodkey, FALSE); - if (r != ERROR_SUCCESS) + if (MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED, + &prodkey, FALSE) != ERROR_SUCCESS && + MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, + &prodkey, FALSE) != ERROR_SUCCESS && + MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE, + &prodkey, FALSE) == ERROR_SUCCESS) { - r = MSIREG_OpenUserProductsKey(szProduct, &prodkey, FALSE); - if (r != ERROR_SUCCESS) - { - r = MSIREG_OpenLocalClassesProductKey(szProduct, &prodkey, FALSE); - if (r == ERROR_SUCCESS) - user = FALSE; - } + user = FALSE; } if (user) @@ -1797,8 +1795,10 @@ static INSTALLSTATE WINAPI MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szCom } if (state != INSTALLSTATE_LOCAL && - (MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS || - MSIREG_OpenLocalClassesProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS)) + (MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, + &hkey, FALSE) == ERROR_SUCCESS || + MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE, + &hkey, FALSE) == ERROR_SUCCESS)) { RegCloseKey(hkey); @@ -2431,9 +2431,12 @@ static USERINFOSTATE WINAPI MSI_GetUserInfo(LPCWSTR szProduct, if (!szProduct || !squash_guid(szProduct, squished_pc)) return USERINFOSTATE_INVALIDARG; - if (MSIREG_OpenLocalManagedProductKey(szProduct, &hkey, FALSE) != ERROR_SUCCESS && - MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE) != ERROR_SUCCESS && - MSIREG_OpenLocalClassesProductKey(szProduct, &hkey, FALSE) != ERROR_SUCCESS) + if (MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED, + &hkey, FALSE) != ERROR_SUCCESS && + MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, + &hkey, FALSE) != ERROR_SUCCESS && + MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE, + &hkey, FALSE) != ERROR_SUCCESS) { return USERINFOSTATE_UNKNOWN; } diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index a28382012ba..3aa1a85dcd7 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -764,7 +764,8 @@ extern BOOL encode_base85_guid(GUID *,LPWSTR); extern BOOL decode_base85_guid(LPCWSTR,GUID*); extern UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create); extern UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct); -extern UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create); +extern UINT MSIREG_OpenProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, + HKEY* key, BOOL create); 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); @@ -786,9 +787,7 @@ extern UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct); extern UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct); extern UINT MSIREG_OpenLocalSystemProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create); extern UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create); -extern UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create); extern UINT MSIREG_OpenLocalClassesFeaturesKey(LPCWSTR szProductCode, HKEY *key, BOOL create); -extern UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create); extern UINT MSIREG_OpenManagedFeaturesKey(LPCWSTR szProductCode, HKEY *key, BOOL create); extern UINT MSIREG_OpenLocalUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create); extern UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct); diff --git a/dlls/msi/registry.c b/dlls/msi/registry.c index 2cd860a4827..85907eba2e6 100644 --- a/dlls/msi/registry.c +++ b/dlls/msi/registry.c @@ -525,25 +525,48 @@ UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct) return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); } -UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create) +UINT MSIREG_OpenProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, + HKEY *key, BOOL create) { - UINT rc; + UINT r; + LPWSTR usersid; + HKEY root = HKEY_LOCAL_MACHINE; WCHAR squished_pc[GUID_SIZE]; - WCHAR keypath[0x200]; + WCHAR keypath[MAX_PATH]; - TRACE("%s\n",debugstr_w(szProduct)); - if (!squash_guid(szProduct,squished_pc)) + TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create); + + if (!squash_guid(szProduct, squished_pc)) return ERROR_FUNCTION_FAILED; + TRACE("squished (%s)\n", debugstr_w(squished_pc)); - sprintfW(keypath,szUserProduct_fmt,squished_pc); + if (context == MSIINSTALLCONTEXT_MACHINE) + { + sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc); + } + else if (context == MSIINSTALLCONTEXT_USERUNMANAGED) + { + root = HKEY_CURRENT_USER; + sprintfW(keypath, szUserProduct_fmt, squished_pc); + } + else + { + r = get_user_sid(&usersid); + if (r != ERROR_SUCCESS || !usersid) + { + ERR("Failed to retrieve user SID: %d\n", r); + return r; + } + + sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc); + LocalFree(usersid); + } if (create) - rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key); - else - rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key); + return RegCreateKeyW(root, keypath, key); - return rc; + return RegOpenKeyW(root, keypath, key); } UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct) @@ -1068,26 +1091,6 @@ UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL cre return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); } -UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create) -{ - WCHAR squished_pc[GUID_SIZE]; - WCHAR keypath[0x200]; - - TRACE("%s\n", debugstr_w(szProductCode)); - - if (!squash_guid(szProductCode, squished_pc)) - return ERROR_FUNCTION_FAILED; - - TRACE("squished (%s)\n", debugstr_w(squished_pc)); - - sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc); - - if (create) - return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); - - return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); -} - UINT MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode) { WCHAR squished_pc[GUID_SIZE]; @@ -1142,36 +1145,6 @@ UINT MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode) return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); } -UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create) -{ - WCHAR squished_pc[GUID_SIZE]; - WCHAR keypath[0x200]; - LPWSTR usersid; - UINT r; - - TRACE("%s\n", debugstr_w(szProductCode)); - - if (!squash_guid(szProductCode, squished_pc)) - return ERROR_FUNCTION_FAILED; - - TRACE("squished (%s)\n", debugstr_w(squished_pc)); - - r = get_user_sid(&usersid); - if (r != ERROR_SUCCESS || !usersid) - { - ERR("Failed to retrieve user SID: %d\n", r); - return r; - } - - sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc); - LocalFree(usersid); - - if (create) - return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); - - return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); -} - UINT MSIREG_OpenManagedFeaturesKey(LPCWSTR szProductCode, HKEY *key, BOOL create) { WCHAR squished_pc[GUID_SIZE]; diff --git a/dlls/msi/source.c b/dlls/msi/source.c index b07402241b8..e8e4a113d5a 100644 --- a/dlls/msi/source.c +++ b/dlls/msi/source.c @@ -64,21 +64,21 @@ static UINT OpenSourceKey(LPCWSTR szProduct, HKEY* key, DWORD dwOptions, if (dwOptions & MSICODE_PATCH) rc = MSIREG_OpenUserPatchesKey(szProduct, &rootkey, create); else - rc = MSIREG_OpenUserProductsKey(szProduct, &rootkey, create); + rc = MSIREG_OpenProductKey(szProduct, context, &rootkey, create); } else if (context == MSIINSTALLCONTEXT_USERMANAGED) { if (dwOptions & MSICODE_PATCH) rc = MSIREG_OpenUserPatchesKey(szProduct, &rootkey, create); else - rc = MSIREG_OpenLocalManagedProductKey(szProduct, &rootkey, create); + rc = MSIREG_OpenProductKey(szProduct, context, &rootkey, create); } else if (context == MSIINSTALLCONTEXT_MACHINE) { if (dwOptions & MSICODE_PATCH) rc = MSIREG_OpenPatchesKey(szProduct, &rootkey, create); else - rc = MSIREG_OpenLocalClassesProductKey(szProduct, &rootkey, create); + rc = MSIREG_OpenProductKey(szProduct, context, &rootkey, create); } if (rc != ERROR_SUCCESS) @@ -903,12 +903,14 @@ UINT WINAPI MsiSourceListAddSourceW( LPCWSTR szProduct, LPCWSTR szUserName, msi_free(psid); } - r = MSIREG_OpenLocalManagedProductKey(szProduct, &hkey, FALSE); + r = MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED, + &hkey, FALSE); if (r == ERROR_SUCCESS) context = MSIINSTALLCONTEXT_USERMANAGED; else { - r = MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE); + r = MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, + &hkey, FALSE); if (r != ERROR_SUCCESS) return ERROR_UNKNOWN_PRODUCT; diff --git a/dlls/msi/upgrade.c b/dlls/msi/upgrade.c index da954997bb9..d86f9738c7a 100644 --- a/dlls/msi/upgrade.c +++ b/dlls/msi/upgrade.c @@ -136,15 +136,16 @@ static UINT ITERATE_FindRelatedProducts(MSIRECORD *rec, LPVOID param) HKEY hukey; INT r; - unsquash_guid(product,productid); - rc = MSIREG_OpenUserProductsKey(productid, &hukey, FALSE); + unsquash_guid(product, productid); + rc = MSIREG_OpenProductKey(productid, package->Context, + &hukey, FALSE); if (rc != ERROR_SUCCESS) { rc = ERROR_SUCCESS; index ++; continue; } - + sz = sizeof(DWORD); RegQueryValueExW(hukey, INSTALLPROPERTY_VERSIONW, NULL, NULL, (LPBYTE)&check, &sz); -- 2.11.4.GIT