urlmon: Correctly handle BINDF_NO_UI in handle_http_error.
[wine/multimedia.git] / dlls / msi / upgrade.c
blob94806610045b437025e7566c76ca1a7937ed1c71
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Actions focused on in this module
24 * FindRelatedProducts
25 * MigrateFeatureStates (TODO)
26 * RemoveExistingProducts (TODO)
29 #include <stdarg.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "winreg.h"
35 #include "wine/debug.h"
36 #include "msidefs.h"
37 #include "msipriv.h"
38 #include "winuser.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
43 static BOOL check_language(DWORD lang1, LPCWSTR lang2, DWORD attributes)
45 DWORD langdword;
47 if (!lang2 || lang2[0]==0)
48 return TRUE;
50 langdword = atoiW(lang2);
52 if (attributes & msidbUpgradeAttributesLanguagesExclusive)
53 return (lang1 != langdword);
54 else
55 return (lang1 == langdword);
58 static void append_productcode(MSIPACKAGE* package, LPCWSTR action_property,
59 LPCWSTR productid)
61 LPWSTR prop;
62 LPWSTR newprop;
63 DWORD len;
64 UINT r;
66 prop = msi_dup_property(package->db, action_property );
67 if (prop)
68 len = strlenW(prop);
69 else
70 len = 0;
72 /*separator*/
73 len ++;
75 len += strlenW(productid);
77 /*null*/
78 len++;
80 newprop = msi_alloc( len*sizeof(WCHAR) );
82 if (prop)
84 strcpyW(newprop,prop);
85 strcatW(newprop,szSemiColon);
87 else
88 newprop[0] = 0;
89 strcatW(newprop,productid);
91 r = msi_set_property( package->db, action_property, newprop );
92 if (r == ERROR_SUCCESS && !strcmpW( action_property, szSourceDir ))
93 msi_reset_folders( package, TRUE );
95 TRACE("Found Related Product... %s now %s\n",
96 debugstr_w(action_property), debugstr_w(newprop));
98 msi_free( prop );
99 msi_free( newprop );
102 static UINT ITERATE_FindRelatedProducts(MSIRECORD *rec, LPVOID param)
104 MSIPACKAGE *package = param;
105 WCHAR product[GUID_SIZE];
106 DWORD index = 0;
107 DWORD attributes = 0;
108 DWORD sz = GUID_SIZE;
109 LPCWSTR upgrade_code;
110 HKEY hkey = 0;
111 UINT rc = ERROR_SUCCESS;
112 MSIRECORD *uirow;
114 upgrade_code = MSI_RecordGetString(rec,1);
116 rc = MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey, FALSE);
117 if (rc != ERROR_SUCCESS)
118 return ERROR_SUCCESS;
120 uirow = MSI_CreateRecord(1);
121 attributes = MSI_RecordGetInteger(rec,5);
123 while (rc == ERROR_SUCCESS)
125 rc = RegEnumValueW(hkey, index, product, &sz, NULL, NULL, NULL, NULL);
126 if (rc == ERROR_SUCCESS)
128 WCHAR productid[GUID_SIZE];
129 LPCWSTR ver, language, action_property;
130 DWORD check = 0, comp_ver, sz = 0x100;
131 HKEY hukey;
132 INT r;
134 TRACE("Looking at index %u product %s\n", index, debugstr_w(product));
136 unsquash_guid(product, productid);
137 if (MSIREG_OpenProductKey(productid, NULL, MSIINSTALLCONTEXT_USERMANAGED, &hukey, FALSE) &&
138 MSIREG_OpenProductKey(productid, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, &hukey, FALSE) &&
139 MSIREG_OpenProductKey(productid, NULL, MSIINSTALLCONTEXT_MACHINE, &hukey, FALSE))
141 TRACE("product key not found\n");
142 rc = ERROR_SUCCESS;
143 index ++;
144 continue;
147 sz = sizeof(DWORD);
148 RegQueryValueExW(hukey, INSTALLPROPERTY_VERSIONW, NULL, NULL, (LPBYTE)&check, &sz);
150 /* check version minimum */
151 ver = MSI_RecordGetString(rec,2);
152 if (ver)
154 comp_ver = msi_version_str_to_dword(ver);
155 r = check - comp_ver;
156 if (r < 0 || (r == 0 && !(attributes & msidbUpgradeAttributesVersionMinInclusive)))
158 TRACE("version below minimum\n");
159 RegCloseKey(hukey);
160 index ++;
161 continue;
165 /* check version maximum */
166 ver = MSI_RecordGetString(rec,3);
167 if (ver)
169 comp_ver = msi_version_str_to_dword(ver);
170 r = check - comp_ver;
171 if (r > 0 || (r == 0 && !(attributes & msidbUpgradeAttributesVersionMaxInclusive)))
173 RegCloseKey(hukey);
174 index ++;
175 continue;
177 TRACE("version above maximum\n");
180 /* check language */
181 sz = sizeof(DWORD);
182 RegQueryValueExW(hukey, INSTALLPROPERTY_LANGUAGEW, NULL, NULL, (LPBYTE)&check, &sz);
183 RegCloseKey(hukey);
184 language = MSI_RecordGetString(rec,4);
185 if (!check_language(check, language, attributes))
187 index ++;
188 TRACE("language doesn't match\n");
189 continue;
191 TRACE("found related product\n");
193 action_property = MSI_RecordGetString(rec, 7);
194 append_productcode(package, action_property, productid);
195 MSI_RecordSetStringW(uirow, 1, productid);
196 msi_ui_actiondata(package, szFindRelatedProducts, uirow);
198 index ++;
200 RegCloseKey(hkey);
201 msiobj_release( &uirow->hdr);
203 return ERROR_SUCCESS;
206 UINT ACTION_FindRelatedProducts(MSIPACKAGE *package)
208 static const WCHAR query[] = {
209 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
210 '`','U','p','g','r','a','d','e','`',0};
211 MSIQUERY *view;
212 UINT rc;
214 if (msi_get_property_int(package->db, szInstalled, 0))
216 TRACE("Skipping FindRelatedProducts action: product already installed\n");
217 return ERROR_SUCCESS;
219 if (msi_action_is_unique(package, szFindRelatedProducts))
221 TRACE("Skipping FindRelatedProducts action: already done in UI sequence\n");
222 return ERROR_SUCCESS;
224 else
225 msi_register_unique_action(package, szFindRelatedProducts);
227 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
228 if (rc != ERROR_SUCCESS)
229 return ERROR_SUCCESS;
231 rc = MSI_IterateRecords(view, NULL, ITERATE_FindRelatedProducts, package);
232 msiobj_release(&view->hdr);
233 return rc;