quartz: Fix IAMDirectSound interface definition.
[wine/multimedia.git] / dlls / msi / upgrade.c
blob6d5f4cf6e28e9a7c539e3611a5c00548b36b5fd6
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;
65 prop = msi_dup_property(package, action_property );
66 if (prop)
67 len = strlenW(prop);
68 else
69 len = 0;
71 /*separator*/
72 len ++;
74 len += strlenW(productid);
76 /*null*/
77 len++;
79 newprop = msi_alloc( len*sizeof(WCHAR) );
81 if (prop)
83 strcpyW(newprop,prop);
84 strcatW(newprop,szSemiColon);
86 else
87 newprop[0] = 0;
88 strcatW(newprop,productid);
90 MSI_SetPropertyW(package, action_property, newprop);
91 TRACE("Found Related Product... %s now %s\n",debugstr_w(action_property),
92 debugstr_w(newprop));
93 msi_free( prop );
94 msi_free( newprop );
97 static UINT ITERATE_FindRelatedProducts(MSIRECORD *rec, LPVOID param)
99 MSIPACKAGE *package = param;
100 WCHAR product[GUID_SIZE];
101 DWORD index = 0;
102 DWORD attributes = 0;
103 DWORD sz = GUID_SIZE;
104 LPCWSTR upgrade_code;
105 HKEY hkey = 0;
106 UINT rc = ERROR_SUCCESS;
107 MSIRECORD *uirow;
109 upgrade_code = MSI_RecordGetString(rec,1);
111 rc = MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey, FALSE);
112 if (rc != ERROR_SUCCESS)
113 return ERROR_SUCCESS;
115 uirow = MSI_CreateRecord(1);
116 attributes = MSI_RecordGetInteger(rec,5);
118 while (rc == ERROR_SUCCESS)
120 rc = RegEnumValueW(hkey, index, product, &sz, NULL, NULL, NULL, NULL);
121 TRACE("Looking at (%i) %s\n",index,debugstr_w(product));
122 if (rc == ERROR_SUCCESS)
124 WCHAR productid[GUID_SIZE];
125 LPCWSTR ver;
126 LPCWSTR language;
127 LPCWSTR action_property;
128 DWORD check = 0x00000000;
129 DWORD comp_ver = 0x00000000;
130 DWORD sz = 0x100;
131 HKEY hukey;
132 INT r;
134 unsquash_guid(product, productid);
135 rc = MSIREG_OpenProductKey(productid, NULL, package->Context,
136 &hukey, FALSE);
137 if (rc != ERROR_SUCCESS)
139 rc = ERROR_SUCCESS;
140 index ++;
141 continue;
144 sz = sizeof(DWORD);
145 RegQueryValueExW(hukey, INSTALLPROPERTY_VERSIONW, NULL, NULL,
146 (LPBYTE)&check, &sz);
147 /* check min */
148 ver = MSI_RecordGetString(rec,2);
149 comp_ver = msi_version_str_to_dword(ver);
150 r = check - comp_ver;
151 if (r < 0 || (r == 0 && !(attributes &
152 msidbUpgradeAttributesVersionMinInclusive)))
154 RegCloseKey(hukey);
155 index ++;
156 continue;
159 /* check max */
160 ver = MSI_RecordGetString(rec,3);
161 comp_ver = msi_version_str_to_dword(ver);
162 r = check - comp_ver;
163 if (r > 0 || (r == 0 && !(attributes &
164 msidbUpgradeAttributesVersionMaxInclusive)))
166 RegCloseKey(hukey);
167 index ++;
168 continue;
171 /* check language*/
172 sz = sizeof(DWORD);
173 RegQueryValueExW(hukey, INSTALLPROPERTY_LANGUAGEW, NULL, NULL,
174 (LPBYTE)&check, &sz);
175 RegCloseKey(hukey);
176 language = MSI_RecordGetString(rec,4);
177 TRACE("Checking languages %x and %s\n", check,
178 debugstr_w(language));
179 if (!check_language(check, language, attributes))
181 index ++;
182 continue;
185 action_property = MSI_RecordGetString(rec,7);
186 append_productcode(package,action_property,productid);
187 ui_actiondata(package,szFindRelatedProducts,uirow);
189 index ++;
191 RegCloseKey(hkey);
192 msiobj_release( &uirow->hdr);
194 return ERROR_SUCCESS;
197 UINT ACTION_FindRelatedProducts(MSIPACKAGE *package)
199 static const WCHAR Query[] =
200 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',
201 ' ','`','U','p','g','r','a','d','e','`',0};
202 UINT rc = ERROR_SUCCESS;
203 MSIQUERY *view;
205 if (check_unique_action(package,szFindRelatedProducts))
207 TRACE("Skipping FindRelatedProducts action: already done on client side\n");
208 return ERROR_SUCCESS;
210 else
211 register_unique_action(package,szFindRelatedProducts);
213 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
214 if (rc != ERROR_SUCCESS)
215 return ERROR_SUCCESS;
217 rc = MSI_IterateRecords(view, NULL, ITERATE_FindRelatedProducts, package);
218 msiobj_release(&view->hdr);
220 return rc;