msi: Add the ability to query a specific context for install properties.

This commit is contained in:
James Hawkins 2008-12-14 21:07:14 -06:00 committed by Alexandre Julliard
parent 880b9199a9
commit b5e3e19a19
4 changed files with 47 additions and 86 deletions

View File

@ -4158,19 +4158,10 @@ static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
return rc; return rc;
if (package->Context == MSIINSTALLCONTEXT_MACHINE) rc = MSIREG_OpenInstallProps(package->ProductCode, package->Context,
{ NULL, &props, TRUE);
rc = MSIREG_OpenInstallProps(package->ProductCode, szLocalSid,
&props, TRUE);
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
goto done; goto done;
}
else
{
rc = MSIREG_OpenCurrentUserInstallProps(package->ProductCode, &props, TRUE);
if (rc != ERROR_SUCCESS)
goto done;
}
msi_make_package_local(package, props); msi_make_package_local(package, props);
@ -4428,11 +4419,8 @@ static UINT ACTION_RegisterUser(MSIPACKAGE *package)
if (!productid) if (!productid)
return ERROR_SUCCESS; return ERROR_SUCCESS;
if (package->Context == MSIINSTALLCONTEXT_MACHINE) rc = MSIREG_OpenInstallProps(package->ProductCode, package->Context,
rc = MSIREG_OpenInstallProps(package->ProductCode, szLocalSid, &hkey, TRUE); NULL, &hkey, TRUE);
else
rc = MSIREG_OpenCurrentUserInstallProps(package->ProductCode, &hkey, TRUE);
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
goto end; goto end;

View File

@ -107,12 +107,7 @@ static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
return r; return r;
if (context == MSIINSTALLCONTEXT_MACHINE) r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
r = MSIREG_OpenInstallProps(szProduct, szLocalSid, &props, FALSE);
else if (context == MSIINSTALLCONTEXT_USERMANAGED ||
context == MSIINSTALLCONTEXT_USERUNMANAGED)
r = MSIREG_OpenCurrentUserInstallProps(szProduct, &props, FALSE);
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
return ERROR_UNKNOWN_PRODUCT; return ERROR_UNKNOWN_PRODUCT;
@ -406,11 +401,8 @@ static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
static const WCHAR szLocalPackage[] = { static const WCHAR szLocalPackage[] = {
'L','o','c','a','l','P','a','c','k','a','g','e',0}; 'L','o','c','a','l','P','a','c','k','a','g','e',0};
if (context == MSIINSTALLCONTEXT_MACHINE)
r = MSIREG_OpenInstallProps(product, szLocalSid, &props, FALSE);
else
r = MSIREG_OpenCurrentUserInstallProps(product, &props, FALSE);
r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
return ERROR_BAD_CONFIGURATION; return ERROR_BAD_CONFIGURATION;
@ -693,12 +685,12 @@ static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute, static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
awstring *szValue, LPDWORD pcchValueBuf) awstring *szValue, LPDWORD pcchValueBuf)
{ {
MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
UINT r = ERROR_UNKNOWN_PROPERTY; UINT r = ERROR_UNKNOWN_PROPERTY;
HKEY prodkey, userdata, source; HKEY prodkey, userdata, source;
LPWSTR val = NULL; LPWSTR val = NULL;
WCHAR squished_pc[GUID_SIZE]; WCHAR squished_pc[GUID_SIZE];
WCHAR packagecode[GUID_SIZE]; WCHAR packagecode[GUID_SIZE];
BOOL classes = FALSE;
BOOL badconfig = FALSE; BOOL badconfig = FALSE;
LONG res; LONG res;
DWORD save, type = REG_NONE; DWORD save, type = REG_NONE;
@ -729,13 +721,10 @@ static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
(r = MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE, (r = MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
&prodkey, FALSE)) == ERROR_SUCCESS) &prodkey, FALSE)) == ERROR_SUCCESS)
{ {
classes = TRUE; context = MSIINSTALLCONTEXT_MACHINE;
} }
if (classes) MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
MSIREG_OpenInstallProps(szProduct, szLocalSid, &userdata, FALSE);
else
MSIREG_OpenCurrentUserInstallProps(szProduct, &userdata, FALSE);
if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) || if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) || !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
@ -1038,15 +1027,17 @@ UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid) if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
/* FIXME: dwContext is provided, no need to search for it */
MSIREG_OpenProductKey(szProductCode, MSIINSTALLCONTEXT_USERMANAGED, MSIREG_OpenProductKey(szProductCode, MSIINSTALLCONTEXT_USERMANAGED,
&managed, FALSE); &managed, FALSE);
MSIREG_OpenProductKey(szProductCode, MSIINSTALLCONTEXT_USERUNMANAGED, MSIREG_OpenProductKey(szProductCode, MSIINSTALLCONTEXT_USERUNMANAGED,
&prod, FALSE); &prod, FALSE);
MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED) if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
{ {
package = INSTALLPROPERTY_LOCALPACKAGEW; package = INSTALLPROPERTY_LOCALPACKAGEW;
MSIREG_OpenCurrentUserInstallProps(szProductCode, &props, FALSE);
if (!props && !prod) if (!props && !prod)
goto done; goto done;
@ -1054,7 +1045,6 @@ UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED) else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
{ {
package = managed_local_package; package = managed_local_package;
MSIREG_OpenCurrentUserInstallProps(szProductCode, &props, FALSE);
if (!props && !managed) if (!props && !managed)
goto done; goto done;
@ -1062,7 +1052,6 @@ UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
else if (dwContext == MSIINSTALLCONTEXT_MACHINE) else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
{ {
package = INSTALLPROPERTY_LOCALPACKAGEW; package = INSTALLPROPERTY_LOCALPACKAGEW;
MSIREG_OpenInstallProps(szProductCode, szLocalSid, &props, FALSE);
MSIREG_OpenProductKey(szProductCode, dwContext, &classes, FALSE); MSIREG_OpenProductKey(szProductCode, dwContext, &classes, FALSE);
if (!props && !classes) if (!props && !classes)
@ -1373,11 +1362,7 @@ static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
}; };
if (context == MSIINSTALLCONTEXT_MACHINE) r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
r = MSIREG_OpenInstallProps(prodcode, szLocalSid, &hkey, FALSE);
else
r = MSIREG_OpenCurrentUserInstallProps(prodcode, &hkey, FALSE);
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
return FALSE; return FALSE;
@ -1491,9 +1476,9 @@ INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct) INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
{ {
MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
INSTALLSTATE state = INSTALLSTATE_ADVERTISED; INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
HKEY prodkey = 0, userdata = 0; HKEY prodkey = 0, userdata = 0;
BOOL user = TRUE;
DWORD val; DWORD val;
UINT r; UINT r;
@ -1515,21 +1500,12 @@ INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE, MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
&prodkey, FALSE) == ERROR_SUCCESS) &prodkey, FALSE) == ERROR_SUCCESS)
{ {
user = FALSE; context = MSIINSTALLCONTEXT_MACHINE;
} }
if (user) r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
{
r = MSIREG_OpenCurrentUserInstallProps(szProduct, &userdata, FALSE);
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
goto done; goto done;
}
else
{
r = MSIREG_OpenInstallProps(szProduct, szLocalSid, &userdata, FALSE);
if (r != ERROR_SUCCESS)
goto done;
}
if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val)) if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
goto done; goto done;
@ -1987,7 +1963,8 @@ static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
state = INSTALLSTATE_ABSENT; state = INSTALLSTATE_ABSENT;
if ((MSIREG_OpenInstallProps(szProduct, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS || if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
&hkey, FALSE) == ERROR_SUCCESS ||
MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
NULL, &hkey, FALSE) == ERROR_SUCCESS) && NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
msi_reg_get_val_dword(hkey, wininstaller, &version) && msi_reg_get_val_dword(hkey, wininstaller, &version) &&
@ -2652,8 +2629,10 @@ static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
return USERINFOSTATE_UNKNOWN; return USERINFOSTATE_UNKNOWN;
} }
if (MSIREG_OpenCurrentUserInstallProps(szProduct, &props, FALSE) != ERROR_SUCCESS && if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
MSIREG_OpenInstallProps(szProduct, szLocalSid, &props, FALSE) != ERROR_SUCCESS) NULL, &props, FALSE) != ERROR_SUCCESS &&
MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
NULL, &props, FALSE) != ERROR_SUCCESS)
{ {
RegCloseKey(hkey); RegCloseKey(hkey);
return USERINFOSTATE_ABSENT; return USERINFOSTATE_ABSENT;

View File

@ -780,9 +780,8 @@ extern UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT d
LPCWSTR szUserSid, HKEY *key, BOOL create); LPCWSTR szUserSid, HKEY *key, BOOL create);
extern UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext, extern UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
HKEY *key, BOOL create); HKEY *key, BOOL create);
extern UINT MSIREG_OpenCurrentUserInstallProps(LPCWSTR szProduct, HKEY* key, BOOL create); extern UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
extern UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, LPCWSTR szUserSID, LPCWSTR szUserSid, HKEY *key, BOOL create);
HKEY *key, BOOL create);
extern UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create); extern UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
extern UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create); extern UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
extern UINT MSIREG_DeleteProductKey(LPCWSTR szProduct); extern UINT MSIREG_DeleteProductKey(LPCWSTR szProduct);

View File

@ -871,10 +871,11 @@ UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
} }
UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, LPCWSTR szUserSID, UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
HKEY *key, BOOL create) LPCWSTR szUserSid, HKEY *key, BOOL create)
{ {
UINT rc; UINT rc;
LPWSTR usersid;
WCHAR squished_pc[GUID_SIZE]; WCHAR squished_pc[GUID_SIZE];
WCHAR keypath[0x200]; WCHAR keypath[0x200];
@ -883,22 +884,12 @@ UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, LPCWSTR szUserSID,
return ERROR_FUNCTION_FAILED; return ERROR_FUNCTION_FAILED;
TRACE("squished (%s)\n", debugstr_w(squished_pc)); TRACE("squished (%s)\n", debugstr_w(squished_pc));
sprintfW(keypath, szInstallProperties_fmt, szUserSID, squished_pc); if (dwContext == MSIINSTALLCONTEXT_MACHINE)
sprintfW(keypath, szInstallProperties_fmt, szLocalSid, squished_pc);
if (create) else if (szUserSid)
rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); sprintfW(keypath, szInstallProperties_fmt, szUserSid, squished_pc);
else else
rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); {
return rc;
}
UINT MSIREG_OpenCurrentUserInstallProps(LPCWSTR szProduct, HKEY *key,
BOOL create)
{
UINT rc;
LPWSTR usersid;
rc = get_user_sid(&usersid); rc = get_user_sid(&usersid);
if (rc != ERROR_SUCCESS || !usersid) if (rc != ERROR_SUCCESS || !usersid)
{ {
@ -906,10 +897,14 @@ UINT MSIREG_OpenCurrentUserInstallProps(LPCWSTR szProduct, HKEY *key,
return rc; return rc;
} }
rc = MSIREG_OpenInstallProps(szProduct, usersid, key, create); sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
LocalFree(usersid); LocalFree(usersid);
return rc; }
if (create)
return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
} }
UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct) UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)