2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Actions focused on in this module
25 * MigrateFeatureStates (TODO)
26 * RemoveExistingProducts (TODO)
35 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msi);
44 extern const WCHAR szFindRelatedProducts[];
45 extern const WCHAR szMigrateFeatureStates[];
46 extern const WCHAR szRemoveExistingProducts[];
48 static BOOL check_language(DWORD lang1, LPCWSTR lang2, DWORD attributes)
52 if (!lang2 || lang2[0]==0)
55 langdword = atoiW(lang2);
57 if (attributes & msidbUpgradeAttributesLanguagesExclusive)
58 return (lang1 != langdword);
60 return (lang1 == langdword);
63 static void append_productcode(MSIPACKAGE* package, LPCWSTR action_property,
69 static const WCHAR separator[] = {';',0};
71 prop = msi_dup_property(package, action_property );
80 len += strlenW(productid);
85 newprop = msi_alloc( len*sizeof(WCHAR) );
89 strcpyW(newprop,prop);
90 strcatW(newprop,separator);
94 strcatW(newprop,productid);
96 MSI_SetPropertyW(package, action_property, newprop);
97 TRACE("Found Related Product... %s now %s\n",debugstr_w(action_property),
103 static UINT ITERATE_FindRelatedProducts(MSIRECORD *rec, LPVOID param)
105 MSIPACKAGE *package = (MSIPACKAGE*)param;
106 WCHAR product[GUID_SIZE];
108 DWORD attributes = 0;
109 DWORD sz = GUID_SIZE;
110 LPCWSTR upgrade_code;
112 UINT rc = ERROR_SUCCESS;
115 upgrade_code = MSI_RecordGetString(rec,1);
117 rc = MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey, FALSE);
118 if (rc != ERROR_SUCCESS)
119 return ERROR_SUCCESS;
121 uirow = MSI_CreateRecord(1);
122 attributes = MSI_RecordGetInteger(rec,5);
124 while (rc == ERROR_SUCCESS)
126 rc = RegEnumValueW(hkey, index, product, &sz, NULL, NULL, NULL, NULL);
127 TRACE("Looking at (%li) %s\n",index,debugstr_w(product));
128 if (rc == ERROR_SUCCESS)
130 WCHAR productid[GUID_SIZE];
133 LPCWSTR action_property;
134 DWORD check = 0x00000000;
135 DWORD comp_ver = 0x00000000;
140 unsquash_guid(product,productid);
141 rc = MSIREG_OpenUserProductsKey(productid, &hukey, FALSE);
142 if (rc != ERROR_SUCCESS)
150 RegQueryValueExW(hukey, INSTALLPROPERTY_VERSIONW, NULL, NULL,
151 (LPBYTE)&check, &sz);
153 ver = MSI_RecordGetString(rec,2);
154 comp_ver = build_version_dword(ver);
155 r = check - comp_ver;
156 if (r < 0 || (r == 0 && !(attributes &
157 msidbUpgradeAttributesVersionMinInclusive)))
165 ver = MSI_RecordGetString(rec,3);
166 comp_ver = build_version_dword(ver);
167 r = check - comp_ver;
168 if (r > 0 || (r == 0 && !(attributes &
169 msidbUpgradeAttributesVersionMaxInclusive)))
178 RegQueryValueExW(hukey, INSTALLPROPERTY_LANGUAGEW, NULL, NULL,
179 (LPBYTE)&check, &sz);
181 language = MSI_RecordGetString(rec,4);
182 TRACE("Checking languages 0x%lx and %s\n", check,
183 debugstr_w(language));
184 if (!check_language(check, language, attributes))
190 action_property = MSI_RecordGetString(rec,7);
191 append_productcode(package,action_property,productid);
192 ui_actiondata(package,szFindRelatedProducts,uirow);
197 msiobj_release( &uirow->hdr);
199 return ERROR_SUCCESS;
202 UINT ACTION_FindRelatedProducts(MSIPACKAGE *package)
204 static const WCHAR Query[] =
205 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',
206 ' ','`','U','p','g','r','a','d','e','`',0};
207 UINT rc = ERROR_SUCCESS;
210 if (check_unique_action(package,szFindRelatedProducts))
212 TRACE("Skipping FindRelatedProducts action: already done on client side\n");
213 return ERROR_SUCCESS;
216 register_unique_action(package,szFindRelatedProducts);
218 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
219 if (rc != ERROR_SUCCESS)
220 return ERROR_SUCCESS;
222 rc = MSI_IterateRecords(view, NULL, ITERATE_FindRelatedProducts, package);
223 msiobj_release(&view->hdr);