Sweden-Number/dlls/msi/upgrade.c

247 lines
7.5 KiB
C
Raw Normal View History

/*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* 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"
#include "wine/unicode.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;
langdword = atoiW(lang2);
if (attributes & msidbUpgradeAttributesLanguagesExclusive)
return (lang1 != langdword);
else
return (lang1 == langdword);
}
static BOOL find_product( const WCHAR *list, const WCHAR *product )
{
const WCHAR *p = list, *q;
if (!list) return FALSE;
for (;;)
{
while (*p && *p != '{') p++;
if (*p != '{') return FALSE;
q = p;
while (*q && *q != '}') q++;
if (*q != '}') return FALSE;
q++;
if (q - p < strlenW( product )) return FALSE;
if (!memcmp( p, product, (q - p) * sizeof(WCHAR) )) return TRUE;
p = q + 1;
while (*p && *p != ';') p++;
if (*p != ';') break;
}
return FALSE;
}
static void append_productcode( MSIPACKAGE *package, const WCHAR *action_prop, const WCHAR *product )
{
WCHAR *prop, *newprop;
DWORD len = 0;
UINT r;
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;
}
if (prop) len += strlenW( prop );
len += strlenW( product ) + 2;
if (!(newprop = msi_alloc( len * sizeof(WCHAR) ))) return;
if (prop)
{
strcpyW( newprop, prop );
strcatW( newprop, szSemiColon );
}
else newprop[0] = 0;
strcatW( newprop, product );
r = msi_set_property( package->db, action_prop, newprop, -1 );
if (r == ERROR_SUCCESS && !strcmpW( action_prop, szSourceDir ))
msi_reset_source_folders( package );
TRACE( "related product property %s now %s\n", debugstr_w(action_prop), debugstr_w(newprop) );
msi_free( prop );
msi_free( newprop );
}
static UINT ITERATE_FindRelatedProducts(MSIRECORD *rec, LPVOID param)
{
2009-01-15 09:46:57 +01:00
MSIPACKAGE *package = param;
WCHAR product[SQUASHED_GUID_SIZE];
DWORD index = 0, attributes = 0, sz = ARRAY_SIZE(product);
LPCWSTR upgrade_code;
HKEY hkey = 0;
UINT rc = ERROR_SUCCESS;
MSIRECORD *uirow;
upgrade_code = MSI_RecordGetString(rec,1);
rc = MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey, FALSE);
if (rc != ERROR_SUCCESS)
return ERROR_SUCCESS;
uirow = MSI_CreateRecord(1);
attributes = MSI_RecordGetInteger(rec,5);
while (rc == ERROR_SUCCESS)
{
rc = RegEnumValueW(hkey, index, product, &sz, NULL, NULL, NULL, NULL);
if (rc == ERROR_SUCCESS)
{
WCHAR productid[GUID_SIZE];
LPCWSTR ver, language, action_property;
DWORD check = 0, comp_ver, sz = 0x100;
HKEY hukey;
INT r;
TRACE("Looking at index %u product %s\n", index, debugstr_w(product));
unsquash_guid(product, productid);
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))
{
TRACE("product key not found\n");
rc = ERROR_SUCCESS;
index ++;
continue;
}
sz = sizeof(DWORD);
RegQueryValueExW(hukey, INSTALLPROPERTY_VERSIONW, NULL, NULL, (LPBYTE)&check, &sz);
/* check version minimum */
ver = MSI_RecordGetString(rec,2);
if (ver)
{
comp_ver = msi_version_str_to_dword(ver);
r = check - comp_ver;
if (r < 0 || (r == 0 && !(attributes & msidbUpgradeAttributesVersionMinInclusive)))
{
TRACE("version below minimum\n");
RegCloseKey(hukey);
index ++;
continue;
}
}
/* check version maximum */
ver = MSI_RecordGetString(rec,3);
if (ver)
{
comp_ver = msi_version_str_to_dword(ver);
r = check - comp_ver;
if (r > 0 || (r == 0 && !(attributes & msidbUpgradeAttributesVersionMaxInclusive)))
{
RegCloseKey(hukey);
index ++;
continue;
}
TRACE("version above maximum\n");
}
/* check language */
sz = sizeof(DWORD);
RegQueryValueExW(hukey, INSTALLPROPERTY_LANGUAGEW, NULL, NULL, (LPBYTE)&check, &sz);
RegCloseKey(hukey);
language = MSI_RecordGetString(rec,4);
if (!check_language(check, language, attributes))
{
index ++;
TRACE("language doesn't match\n");
continue;
}
TRACE("found related product\n");
action_property = MSI_RecordGetString(rec, 7);
append_productcode(package, action_property, productid);
MSI_RecordSetStringW(uirow, 1, productid);
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, uirow);
}
index ++;
}
RegCloseKey(hkey);
msiobj_release( &uirow->hdr);
return ERROR_SUCCESS;
}
UINT ACTION_FindRelatedProducts(MSIPACKAGE *package)
{
2011-07-27 10:53:26 +02:00
static const WCHAR query[] = {
'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
'`','U','p','g','r','a','d','e','`',0};
MSIQUERY *view;
2011-07-27 10:53:26 +02:00
UINT rc;
if (msi_get_property_int(package->db, szInstalled, 0))
{
TRACE("Skipping FindRelatedProducts action: product already installed\n");
return ERROR_SUCCESS;
}
2011-05-06 14:39:17 +02:00
if (msi_action_is_unique(package, szFindRelatedProducts))
{
TRACE("Skipping FindRelatedProducts action: already done in UI sequence\n");
return ERROR_SUCCESS;
}
else
2011-05-06 14:39:17 +02:00
msi_register_unique_action(package, szFindRelatedProducts);
2011-07-27 10:53:26 +02:00
rc = MSI_DatabaseOpenViewW(package->db, query, &view);
if (rc != ERROR_SUCCESS)
return ERROR_SUCCESS;
rc = MSI_IterateRecords(view, NULL, ITERATE_FindRelatedProducts, package);
msiobj_release(&view->hdr);
return rc;
}