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)
38 #include "wine/debug.h"
47 #include "wine/unicode.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(msi);
51 static BOOL check_language(DWORD lang1, LPCWSTR lang2, DWORD attributes)
55 if (!lang2 || lang2[0]==0)
58 langdword = atoiW(lang2);
60 if (attributes & msidbUpgradeAttributesLanguagesExclusive)
61 return (lang1 != langdword);
63 return (lang1 == langdword);
66 static void append_productcode(MSIPACKAGE* package, LPCWSTR action_property,
72 static const WCHAR separator[] = {';',0};
74 prop = load_dynamic_property(package, action_property, NULL);
83 len += strlenW(productid);
88 newprop = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
92 strcpyW(newprop,prop);
93 strcatW(newprop,separator);
97 strcatW(newprop,productid);
99 MSI_SetPropertyW(package, action_property, newprop);
100 TRACE("Found Related Product... %s now %s\n",debugstr_w(action_property),
101 debugstr_w(newprop));
102 HeapFree(GetProcessHeap(),0,prop);
103 HeapFree(GetProcessHeap(),0,newprop);
106 static UINT ITERATE_FindRelatedProducts(MSIRECORD *rec, LPVOID param)
108 MSIPACKAGE *package = (MSIPACKAGE*)param;
109 WCHAR product[GUID_SIZE];
111 DWORD attributes = 0;
112 DWORD sz = GUID_SIZE;
113 LPCWSTR upgrade_code;
115 UINT rc = ERROR_SUCCESS;
117 upgrade_code = MSI_RecordGetString(rec,1);
119 rc = MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey, FALSE);
120 if (rc != ERROR_SUCCESS)
121 return ERROR_SUCCESS;
123 attributes = MSI_RecordGetInteger(rec,5);
125 while (rc == ERROR_SUCCESS)
127 rc = RegEnumValueW(hkey, index, product, &sz, NULL, NULL, NULL, NULL);
128 TRACE("Looking at (%li) %s\n",index,debugstr_w(product));
129 if (rc == ERROR_SUCCESS)
131 WCHAR productid[GUID_SIZE];
134 LPCWSTR action_property;
135 DWORD check = 0x00000000;
136 DWORD comp_ver = 0x00000000;
140 static const WCHAR szVersion[] =
141 {'V','e','r','s','i','o','n',0};
142 static const WCHAR szLanguage[] =
143 {'L','a','n','g','u','a','g','e',0};
145 unsquash_guid(product,productid);
146 rc = MSIREG_OpenUserProductsKey(productid, &hukey, FALSE);
147 if (rc != ERROR_SUCCESS)
155 RegQueryValueExW(hukey, szVersion, NULL, NULL, (LPBYTE)&check,
158 ver = MSI_RecordGetString(rec,2);
159 comp_ver = build_version_dword(ver);
160 r = check - comp_ver;
161 if (r < 0 || (r == 0 && !(attributes &
162 msidbUpgradeAttributesVersionMinInclusive)))
170 ver = MSI_RecordGetString(rec,3);
171 comp_ver = build_version_dword(ver);
172 r = check - comp_ver;
173 if (r > 0 || (r == 0 && !(attributes &
174 msidbUpgradeAttributesVersionMaxInclusive)))
183 RegQueryValueExW(hukey, szLanguage, NULL, NULL, (LPBYTE)&check,
186 language = MSI_RecordGetString(rec,4);
187 TRACE("Checking languages 0x%lx and %s\n", check,
188 debugstr_w(language));
189 if (!check_language(check, language, attributes))
195 action_property = MSI_RecordGetString(rec,7);
196 append_productcode(package,action_property,productid);
202 return ERROR_SUCCESS;
205 UINT ACTION_FindRelatedProducts(MSIPACKAGE *package)
207 static const WCHAR Query[] =
208 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',
209 ' ','`','U','p','g','r','a','d','e','`',0};
210 UINT rc = ERROR_SUCCESS;
213 if (package->script && package->script->FindRelatedProductsRun)
214 return ERROR_SUCCESS;
217 package->script->FindRelatedProductsRun = TRUE;
219 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
220 if (rc != ERROR_SUCCESS)
221 return ERROR_SUCCESS;
223 rc = MSI_IterateRecords(view, NULL, ITERATE_FindRelatedProducts, package);
224 msiobj_release(&view->hdr);