2005-06-09 14:05:27 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2005 Aric Stewart for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-06-09 14:05:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actions focused on in this module
|
|
|
|
*
|
|
|
|
* FindRelatedProducts
|
|
|
|
* MigrateFeatureStates (TODO)
|
|
|
|
* RemoveExistingProducts (TODO)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "msidefs.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
|
|
|
static BOOL check_language(DWORD lang1, LPCWSTR lang2, DWORD attributes)
|
|
|
|
{
|
|
|
|
DWORD langdword;
|
|
|
|
|
|
|
|
if (!lang2 || lang2[0]==0)
|
|
|
|
return TRUE;
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
langdword = wcstol(lang2, NULL, 10);
|
2005-06-09 14:05:27 +02:00
|
|
|
|
|
|
|
if (attributes & msidbUpgradeAttributesLanguagesExclusive)
|
|
|
|
return (lang1 != langdword);
|
|
|
|
else
|
|
|
|
return (lang1 == langdword);
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:34:58 +01:00
|
|
|
static BOOL find_product( const WCHAR *list, const WCHAR *product )
|
2005-06-09 14:05:27 +02:00
|
|
|
{
|
2018-11-02 11:34:58 +01:00
|
|
|
const WCHAR *p = list, *q;
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2018-11-02 11:34:58 +01:00
|
|
|
if (!list) return FALSE;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
while (*p && *p != '{') p++;
|
|
|
|
if (*p != '{') return FALSE;
|
|
|
|
q = p;
|
|
|
|
while (*q && *q != '}') q++;
|
|
|
|
if (*q != '}') return FALSE;
|
|
|
|
q++;
|
2019-06-13 08:42:35 +02:00
|
|
|
if (q - p < lstrlenW( product )) return FALSE;
|
2018-11-02 11:34:58 +01:00
|
|
|
if (!memcmp( p, product, (q - p) * sizeof(WCHAR) )) return TRUE;
|
|
|
|
p = q + 1;
|
|
|
|
while (*p && *p != ';') p++;
|
|
|
|
if (*p != ';') break;
|
|
|
|
}
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2018-11-02 11:34:58 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2018-11-02 11:34:58 +01:00
|
|
|
static void append_productcode( MSIPACKAGE *package, const WCHAR *action_prop, const WCHAR *product )
|
|
|
|
{
|
|
|
|
WCHAR *prop, *newprop;
|
|
|
|
DWORD len = 0;
|
|
|
|
UINT r;
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2018-11-02 11:34:58 +01:00
|
|
|
prop = msi_dup_property( package->db, action_prop );
|
|
|
|
if (find_product( prop, product ))
|
|
|
|
{
|
|
|
|
TRACE( "related product property %s already contains %s\n", debugstr_w(action_prop), debugstr_w(product) );
|
|
|
|
msi_free( prop );
|
|
|
|
return;
|
|
|
|
}
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
if (prop) len += lstrlenW( prop );
|
|
|
|
len += lstrlenW( product ) + 2;
|
2018-11-02 11:34:58 +01:00
|
|
|
if (!(newprop = msi_alloc( len * sizeof(WCHAR) ))) return;
|
2005-06-09 14:05:27 +02:00
|
|
|
if (prop)
|
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW( newprop, prop );
|
2020-10-29 11:47:14 +01:00
|
|
|
lstrcatW( newprop, L";" );
|
2005-06-09 14:05:27 +02:00
|
|
|
}
|
2018-11-02 11:34:58 +01:00
|
|
|
else newprop[0] = 0;
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcatW( newprop, product );
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2018-11-02 11:34:58 +01:00
|
|
|
r = msi_set_property( package->db, action_prop, newprop, -1 );
|
2020-10-29 11:47:14 +01:00
|
|
|
if (r == ERROR_SUCCESS && !wcscmp( action_prop, L"SourceDir" ))
|
2018-10-10 16:14:28 +02:00
|
|
|
msi_reset_source_folders( package );
|
2010-04-21 11:38:17 +02:00
|
|
|
|
2018-11-02 11:34:58 +01:00
|
|
|
TRACE( "related product property %s now %s\n", debugstr_w(action_prop), debugstr_w(newprop) );
|
2010-04-21 11:38:17 +02:00
|
|
|
|
2005-09-20 13:57:19 +02:00
|
|
|
msi_free( prop );
|
|
|
|
msi_free( newprop );
|
2005-06-09 14:05:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT ITERATE_FindRelatedProducts(MSIRECORD *rec, LPVOID param)
|
|
|
|
{
|
2009-01-15 09:46:57 +01:00
|
|
|
MSIPACKAGE *package = param;
|
2016-11-04 13:28:07 +01:00
|
|
|
WCHAR product[SQUASHED_GUID_SIZE];
|
2018-08-20 21:15:43 +02:00
|
|
|
DWORD index = 0, attributes = 0, sz = ARRAY_SIZE(product);
|
2005-06-09 14:05:27 +02:00
|
|
|
LPCWSTR upgrade_code;
|
|
|
|
HKEY hkey = 0;
|
|
|
|
UINT rc = ERROR_SUCCESS;
|
2005-06-16 18:08:58 +02:00
|
|
|
MSIRECORD *uirow;
|
2005-06-09 14:05:27 +02:00
|
|
|
|
|
|
|
upgrade_code = MSI_RecordGetString(rec,1);
|
|
|
|
|
|
|
|
rc = MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey, FALSE);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2005-06-16 18:08:58 +02:00
|
|
|
uirow = MSI_CreateRecord(1);
|
2005-06-09 14:05:27 +02:00
|
|
|
attributes = MSI_RecordGetInteger(rec,5);
|
2009-03-22 22:30:16 +01:00
|
|
|
|
2005-06-09 14:05:27 +02:00
|
|
|
while (rc == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
rc = RegEnumValueW(hkey, index, product, &sz, NULL, NULL, NULL, NULL);
|
|
|
|
if (rc == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WCHAR productid[GUID_SIZE];
|
2011-05-17 11:08:49 +02:00
|
|
|
LPCWSTR ver, language, action_property;
|
|
|
|
DWORD check = 0, comp_ver, sz = 0x100;
|
2005-06-09 14:05:27 +02:00
|
|
|
HKEY hukey;
|
|
|
|
INT r;
|
|
|
|
|
2011-05-17 11:08:49 +02:00
|
|
|
TRACE("Looking at index %u product %s\n", index, debugstr_w(product));
|
|
|
|
|
2008-11-04 05:16:43 +01:00
|
|
|
unsquash_guid(product, productid);
|
2011-05-17 11:09:14 +02:00
|
|
|
if (MSIREG_OpenProductKey(productid, NULL, MSIINSTALLCONTEXT_USERMANAGED, &hukey, FALSE) &&
|
|
|
|
MSIREG_OpenProductKey(productid, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, &hukey, FALSE) &&
|
|
|
|
MSIREG_OpenProductKey(productid, NULL, MSIINSTALLCONTEXT_MACHINE, &hukey, FALSE))
|
2005-06-09 14:05:27 +02:00
|
|
|
{
|
2011-05-17 11:08:49 +02:00
|
|
|
TRACE("product key not found\n");
|
2005-06-09 14:05:27 +02:00
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
index ++;
|
|
|
|
continue;
|
|
|
|
}
|
2008-11-04 05:16:43 +01:00
|
|
|
|
2005-06-09 14:05:27 +02:00
|
|
|
sz = sizeof(DWORD);
|
2011-05-17 11:08:49 +02:00
|
|
|
RegQueryValueExW(hukey, INSTALLPROPERTY_VERSIONW, NULL, NULL, (LPBYTE)&check, &sz);
|
|
|
|
|
|
|
|
/* check version minimum */
|
2005-06-09 14:05:27 +02:00
|
|
|
ver = MSI_RecordGetString(rec,2);
|
2010-05-24 20:33:28 +02:00
|
|
|
if (ver)
|
2005-06-09 14:05:27 +02:00
|
|
|
{
|
2010-05-24 20:33:28 +02:00
|
|
|
comp_ver = msi_version_str_to_dword(ver);
|
|
|
|
r = check - comp_ver;
|
|
|
|
if (r < 0 || (r == 0 && !(attributes & msidbUpgradeAttributesVersionMinInclusive)))
|
|
|
|
{
|
2011-05-17 11:08:49 +02:00
|
|
|
TRACE("version below minimum\n");
|
2010-05-24 20:33:28 +02:00
|
|
|
RegCloseKey(hukey);
|
|
|
|
index ++;
|
|
|
|
continue;
|
|
|
|
}
|
2005-06-09 14:05:27 +02:00
|
|
|
}
|
|
|
|
|
2011-05-17 11:08:49 +02:00
|
|
|
/* check version maximum */
|
2005-06-09 14:05:27 +02:00
|
|
|
ver = MSI_RecordGetString(rec,3);
|
2010-05-24 20:33:28 +02:00
|
|
|
if (ver)
|
2005-06-09 14:05:27 +02:00
|
|
|
{
|
2010-05-24 20:33:28 +02:00
|
|
|
comp_ver = msi_version_str_to_dword(ver);
|
|
|
|
r = check - comp_ver;
|
|
|
|
if (r > 0 || (r == 0 && !(attributes & msidbUpgradeAttributesVersionMaxInclusive)))
|
|
|
|
{
|
|
|
|
RegCloseKey(hukey);
|
|
|
|
index ++;
|
|
|
|
continue;
|
|
|
|
}
|
2011-05-17 11:08:49 +02:00
|
|
|
TRACE("version above maximum\n");
|
2005-06-09 14:05:27 +02:00
|
|
|
}
|
|
|
|
|
2011-05-17 11:08:49 +02:00
|
|
|
/* check language */
|
2005-06-09 14:05:27 +02:00
|
|
|
sz = sizeof(DWORD);
|
2011-05-17 11:08:49 +02:00
|
|
|
RegQueryValueExW(hukey, INSTALLPROPERTY_LANGUAGEW, NULL, NULL, (LPBYTE)&check, &sz);
|
2005-06-09 14:05:27 +02:00
|
|
|
RegCloseKey(hukey);
|
|
|
|
language = MSI_RecordGetString(rec,4);
|
|
|
|
if (!check_language(check, language, attributes))
|
|
|
|
{
|
|
|
|
index ++;
|
2011-05-17 11:08:49 +02:00
|
|
|
TRACE("language doesn't match\n");
|
2011-10-10 23:58:59 +02:00
|
|
|
continue;
|
2005-06-09 14:05:27 +02:00
|
|
|
}
|
2011-05-17 11:08:49 +02:00
|
|
|
TRACE("found related product\n");
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2010-03-05 12:25:31 +01:00
|
|
|
action_property = MSI_RecordGetString(rec, 7);
|
|
|
|
append_productcode(package, action_property, productid);
|
|
|
|
MSI_RecordSetStringW(uirow, 1, productid);
|
2017-07-07 16:03:15 +02:00
|
|
|
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, uirow);
|
2005-06-09 14:05:27 +02:00
|
|
|
}
|
|
|
|
index ++;
|
|
|
|
}
|
|
|
|
RegCloseKey(hkey);
|
2005-06-16 18:08:58 +02:00
|
|
|
msiobj_release( &uirow->hdr);
|
2020-10-29 11:47:14 +01:00
|
|
|
|
2005-06-09 14:05:27 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT ACTION_FindRelatedProducts(MSIPACKAGE *package)
|
|
|
|
{
|
|
|
|
MSIQUERY *view;
|
2011-07-27 10:53:26 +02:00
|
|
|
UINT rc;
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (msi_get_property_int(package->db, L"Installed", 0))
|
2010-03-02 14:58:27 +01:00
|
|
|
{
|
|
|
|
TRACE("Skipping FindRelatedProducts action: product already installed\n");
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2020-10-29 11:47:14 +01:00
|
|
|
if (msi_action_is_unique(package, L"FindRelatedProducts"))
|
2005-06-30 22:45:43 +02:00
|
|
|
{
|
2010-03-23 11:46:00 +01:00
|
|
|
TRACE("Skipping FindRelatedProducts action: already done in UI sequence\n");
|
2005-06-09 14:05:27 +02:00
|
|
|
return ERROR_SUCCESS;
|
2005-06-30 22:45:43 +02:00
|
|
|
}
|
|
|
|
else
|
2020-10-29 11:47:14 +01:00
|
|
|
msi_register_unique_action(package, L"FindRelatedProducts");
|
2005-06-09 14:05:27 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
rc = MSI_DatabaseOpenViewW(package->db, L"SELECT * FROM `Upgrade`", &view);
|
2005-06-09 14:05:27 +02:00
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
return ERROR_SUCCESS;
|
2020-10-29 11:47:14 +01:00
|
|
|
|
2005-06-09 14:05:27 +02:00
|
|
|
rc = MSI_IterateRecords(view, NULL, ITERATE_FindRelatedProducts, package);
|
|
|
|
msiobj_release(&view->hdr);
|
|
|
|
return rc;
|
|
|
|
}
|