Since multiple progids can refer to 1 class we need to check if that
[wine/testsucceed.git] / dlls / msi / action.c
blob3dcf63a4eab71bf07e8619a57181853e9dce1672
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 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 * Pages I need
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
29 #include <stdarg.h>
30 #include <stdio.h>
32 #define COBJMACROS
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "winreg.h"
38 #include "wine/debug.h"
39 #include "fdi.h"
40 #include "msi.h"
41 #include "msiquery.h"
42 #include "msidefs.h"
43 #include "msvcrt/fcntl.h"
44 #include "objbase.h"
45 #include "objidl.h"
46 #include "msipriv.h"
47 #include "winnls.h"
48 #include "winuser.h"
49 #include "shlobj.h"
50 #include "wine/unicode.h"
51 #include "winver.h"
52 #include "action.h"
54 #define REG_PROGRESS_VALUE 13200
55 #define COMPONENT_PROGRESS_VALUE 24000
57 WINE_DEFAULT_DEBUG_CHANNEL(msi);
60 * Prototypes
62 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
63 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
64 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI);
65 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
66 LPWSTR *FilePath);
68 /*
69 * action handlers
71 typedef UINT (*STANDARDACTIONHANDLER)(MSIPACKAGE*);
73 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
74 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
75 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
76 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
77 static UINT ACTION_FileCost(MSIPACKAGE *package);
78 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
79 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
80 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
81 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
82 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
83 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
84 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
85 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
86 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
87 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package);
88 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package);
89 static UINT ACTION_RegisterUser(MSIPACKAGE *package);
90 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
91 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
92 static UINT ACTION_WriteIniValues(MSIPACKAGE *package);
93 static UINT ACTION_SelfRegModules(MSIPACKAGE *package);
94 static UINT ACTION_PublishFeatures(MSIPACKAGE *package);
95 static UINT ACTION_RegisterProduct(MSIPACKAGE *package);
96 static UINT ACTION_InstallExecute(MSIPACKAGE *package);
97 static UINT ACTION_InstallFinalize(MSIPACKAGE *package);
98 static UINT ACTION_ForceReboot(MSIPACKAGE *package);
99 static UINT ACTION_ResolveSource(MSIPACKAGE *package);
100 static UINT ACTION_ExecuteAction(MSIPACKAGE *package);
101 static UINT ACTION_RegisterFonts(MSIPACKAGE *package);
102 static UINT ACTION_PublishComponents(MSIPACKAGE *package);
106 * consts and values used
108 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
109 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
110 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
111 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
112 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
113 static const WCHAR c_colon[] = {'C',':','\\',0};
114 static const WCHAR szProductCode[]=
115 {'P','r','o','d','u','c','t','C','o','d','e',0};
116 static const WCHAR cszbs[]={'\\',0};
117 const static WCHAR szCreateFolders[] =
118 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
119 const static WCHAR szCostFinalize[] =
120 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
121 const static WCHAR szInstallFiles[] =
122 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
123 const static WCHAR szDuplicateFiles[] =
124 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
125 const static WCHAR szWriteRegistryValues[] =
126 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
127 'V','a','l','u','e','s',0};
128 const static WCHAR szCostInitialize[] =
129 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
130 const static WCHAR szFileCost[] =
131 {'F','i','l','e','C','o','s','t',0};
132 const static WCHAR szInstallInitialize[] =
133 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
134 const static WCHAR szInstallValidate[] =
135 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
136 const static WCHAR szLaunchConditions[] =
137 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
138 const static WCHAR szProcessComponents[] =
139 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
140 const static WCHAR szRegisterTypeLibraries[] =
141 {'R','e','g','i','s','t','e','r','T','y','p','e',
142 'L','i','b','r','a','r','i','e','s',0};
143 const static WCHAR szRegisterClassInfo[] =
144 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
145 const static WCHAR szRegisterProgIdInfo[] =
146 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
147 const static WCHAR szCreateShortcuts[] =
148 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
149 const static WCHAR szPublishProduct[] =
150 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
151 const static WCHAR szWriteIniValues[] =
152 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
153 const static WCHAR szSelfRegModules[] =
154 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
155 const static WCHAR szPublishFeatures[] =
156 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
157 const static WCHAR szRegisterProduct[] =
158 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
159 const static WCHAR szInstallExecute[] =
160 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
161 const static WCHAR szInstallExecuteAgain[] =
162 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
163 'A','g','a','i','n',0};
164 const static WCHAR szInstallFinalize[] =
165 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
166 const static WCHAR szForceReboot[] =
167 {'F','o','r','c','e','R','e','b','o','o','t',0};
168 const static WCHAR szResolveSource[] =
169 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
170 const static WCHAR szAppSearch[] =
171 {'A','p','p','S','e','a','r','c','h',0};
172 const static WCHAR szAllocateRegistrySpace[] =
173 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
174 'S','p','a','c','e',0};
175 const static WCHAR szBindImage[] =
176 {'B','i','n','d','I','m','a','g','e',0};
177 const static WCHAR szCCPSearch[] =
178 {'C','C','P','S','e','a','r','c','h',0};
179 const static WCHAR szDeleteServices[] =
180 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
181 const static WCHAR szDisableRollback[] =
182 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
183 const static WCHAR szExecuteAction[] =
184 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
185 const static WCHAR szFindRelatedProducts[] =
186 {'F','i','n','d','R','e','l','a','t','e','d',
187 'P','r','o','d','u','c','t','s',0};
188 const static WCHAR szInstallAdminPackage[] =
189 {'I','n','s','t','a','l','l','A','d','m','i','n',
190 'P','a','c','k','a','g','e',0};
191 const static WCHAR szInstallSFPCatalogFile[] =
192 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
193 'F','i','l','e',0};
194 const static WCHAR szIsolateComponents[] =
195 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
196 const static WCHAR szMigrateFeatureStates[] =
197 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
198 'S','t','a','t','e','s',0};
199 const static WCHAR szMoveFiles[] =
200 {'M','o','v','e','F','i','l','e','s',0};
201 const static WCHAR szMsiPublishAssemblies[] =
202 {'M','s','i','P','u','b','l','i','s','h',
203 'A','s','s','e','m','b','l','i','e','s',0};
204 const static WCHAR szMsiUnpublishAssemblies[] =
205 {'M','s','i','U','n','p','u','b','l','i','s','h',
206 'A','s','s','e','m','b','l','i','e','s',0};
207 const static WCHAR szInstallODBC[] =
208 {'I','n','s','t','a','l','l','O','D','B','C',0};
209 const static WCHAR szInstallServices[] =
210 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
211 const static WCHAR szPatchFiles[] =
212 {'P','a','t','c','h','F','i','l','e','s',0};
213 const static WCHAR szPublishComponents[] =
214 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
215 const static WCHAR szRegisterComPlus[] =
216 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
217 const static WCHAR szRegisterExtensionInfo[] =
218 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
219 'I','n','f','o',0};
220 const static WCHAR szRegisterFonts[] =
221 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
222 const static WCHAR szRegisterMIMEInfo[] =
223 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
224 const static WCHAR szRegisterUser[] =
225 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
226 const static WCHAR szRemoveDuplicateFiles[] =
227 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
228 'F','i','l','e','s',0};
229 const static WCHAR szRemoveEnvironmentStrings[] =
230 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
231 'S','t','r','i','n','g','s',0};
232 const static WCHAR szRemoveExistingProducts[] =
233 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
234 'P','r','o','d','u','c','t','s',0};
235 const static WCHAR szRemoveFiles[] =
236 {'R','e','m','o','v','e','F','i','l','e','s',0};
237 const static WCHAR szRemoveFolders[] =
238 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
239 const static WCHAR szRemoveIniValues[] =
240 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
241 const static WCHAR szRemoveODBC[] =
242 {'R','e','m','o','v','e','O','D','B','C',0};
243 const static WCHAR szRemoveRegistryValues[] =
244 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
245 'V','a','l','u','e','s',0};
246 const static WCHAR szRemoveShortcuts[] =
247 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
248 const static WCHAR szRMCCPSearch[] =
249 {'R','M','C','C','P','S','e','a','r','c','h',0};
250 const static WCHAR szScheduleReboot[] =
251 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
252 const static WCHAR szSelfUnregModules[] =
253 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
254 const static WCHAR szSetODBCFolders[] =
255 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
256 const static WCHAR szStartServices[] =
257 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
258 const static WCHAR szStopServices[] =
259 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
260 const static WCHAR szUnpublishComponents[] =
261 {'U','n','p','u','b','l','i','s','h',
262 'C','o','m','p','o','n','e','n','t','s',0};
263 const static WCHAR szUnpublishFeatures[] =
264 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
265 const static WCHAR szUnregisterClassInfo[] =
266 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
267 'I','n','f','o',0};
268 const static WCHAR szUnregisterComPlus[] =
269 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
270 const static WCHAR szUnregisterExtensionInfo[] =
271 {'U','n','r','e','g','i','s','t','e','r',
272 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
273 const static WCHAR szUnregisterFonts[] =
274 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
275 const static WCHAR szUnregisterMIMEInfo[] =
276 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
277 const static WCHAR szUnregisterProgIdInfo[] =
278 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
279 'I','n','f','o',0};
280 const static WCHAR szUnregisterTypeLibraries[] =
281 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
282 'L','i','b','r','a','r','i','e','s',0};
283 const static WCHAR szValidateProductID[] =
284 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
285 const static WCHAR szWriteEnvironmentStrings[] =
286 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
287 'S','t','r','i','n','g','s',0};
289 struct _actions {
290 LPCWSTR action;
291 STANDARDACTIONHANDLER handler;
294 static struct _actions StandardActions[] = {
295 { szAllocateRegistrySpace, NULL},
296 { szAppSearch, ACTION_AppSearch },
297 { szBindImage, NULL},
298 { szCCPSearch, NULL},
299 { szCostFinalize, ACTION_CostFinalize },
300 { szCostInitialize, ACTION_CostInitialize },
301 { szCreateFolders, ACTION_CreateFolders },
302 { szCreateShortcuts, ACTION_CreateShortcuts },
303 { szDeleteServices, NULL},
304 { szDisableRollback, NULL},
305 { szDuplicateFiles, ACTION_DuplicateFiles },
306 { szExecuteAction, ACTION_ExecuteAction },
307 { szFileCost, ACTION_FileCost },
308 { szFindRelatedProducts, NULL},
309 { szForceReboot, ACTION_ForceReboot },
310 { szInstallAdminPackage, NULL},
311 { szInstallExecute, ACTION_InstallExecute },
312 { szInstallExecuteAgain, ACTION_InstallExecute },
313 { szInstallFiles, ACTION_InstallFiles},
314 { szInstallFinalize, ACTION_InstallFinalize },
315 { szInstallInitialize, ACTION_InstallInitialize },
316 { szInstallSFPCatalogFile, NULL},
317 { szInstallValidate, ACTION_InstallValidate },
318 { szIsolateComponents, NULL},
319 { szLaunchConditions, ACTION_LaunchConditions },
320 { szMigrateFeatureStates, NULL},
321 { szMoveFiles, NULL},
322 { szMsiPublishAssemblies, NULL},
323 { szMsiUnpublishAssemblies, NULL},
324 { szInstallODBC, NULL},
325 { szInstallServices, NULL},
326 { szPatchFiles, NULL},
327 { szProcessComponents, ACTION_ProcessComponents },
328 { szPublishComponents, ACTION_PublishComponents },
329 { szPublishFeatures, ACTION_PublishFeatures },
330 { szPublishProduct, ACTION_PublishProduct },
331 { szRegisterClassInfo, ACTION_RegisterClassInfo },
332 { szRegisterComPlus, NULL},
333 { szRegisterExtensionInfo, ACTION_RegisterExtensionInfo },
334 { szRegisterFonts, ACTION_RegisterFonts },
335 { szRegisterMIMEInfo, ACTION_RegisterMIMEInfo },
336 { szRegisterProduct, ACTION_RegisterProduct },
337 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
338 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
339 { szRegisterUser, ACTION_RegisterUser},
340 { szRemoveDuplicateFiles, NULL},
341 { szRemoveEnvironmentStrings, NULL},
342 { szRemoveExistingProducts, NULL},
343 { szRemoveFiles, NULL},
344 { szRemoveFolders, NULL},
345 { szRemoveIniValues, NULL},
346 { szRemoveODBC, NULL},
347 { szRemoveRegistryValues, NULL},
348 { szRemoveShortcuts, NULL},
349 { szResolveSource, ACTION_ResolveSource},
350 { szRMCCPSearch, NULL},
351 { szScheduleReboot, NULL},
352 { szSelfRegModules, ACTION_SelfRegModules },
353 { szSelfUnregModules, NULL},
354 { szSetODBCFolders, NULL},
355 { szStartServices, NULL},
356 { szStopServices, NULL},
357 { szUnpublishComponents, NULL},
358 { szUnpublishFeatures, NULL},
359 { szUnregisterClassInfo, NULL},
360 { szUnregisterComPlus, NULL},
361 { szUnregisterExtensionInfo, NULL},
362 { szUnregisterFonts, NULL},
363 { szUnregisterMIMEInfo, NULL},
364 { szUnregisterProgIdInfo, NULL},
365 { szUnregisterTypeLibraries, NULL},
366 { szValidateProductID, NULL},
367 { szWriteEnvironmentStrings, NULL},
368 { szWriteIniValues, ACTION_WriteIniValues },
369 { szWriteRegistryValues, ACTION_WriteRegistryValues},
370 { NULL, NULL},
374 /********************************************************
375 * helper functions to get around current HACKS and such
376 ********************************************************/
377 inline static void reduce_to_longfilename(WCHAR* filename)
379 LPWSTR p = strchrW(filename,'|');
380 if (p)
381 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
384 inline static void reduce_to_shortfilename(WCHAR* filename)
386 LPWSTR p = strchrW(filename,'|');
387 if (p)
388 *p = 0;
391 WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
393 UINT rc;
394 DWORD sz;
395 LPWSTR ret;
397 sz = 0;
398 if (MSI_RecordIsNull(row,index))
399 return NULL;
401 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
403 /* having an empty string is different than NULL */
404 if (sz == 0)
406 ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
407 ret[0] = 0;
408 return ret;
411 sz ++;
412 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
413 rc = MSI_RecordGetStringW(row,index,ret,&sz);
414 if (rc!=ERROR_SUCCESS)
416 ERR("Unable to load dynamic string\n");
417 HeapFree(GetProcessHeap(), 0, ret);
418 ret = NULL;
420 return ret;
423 LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop, UINT* rc)
425 DWORD sz = 0;
426 LPWSTR str;
427 UINT r;
429 r = MSI_GetPropertyW(package, prop, NULL, &sz);
430 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
432 if (rc)
433 *rc = r;
434 return NULL;
436 sz++;
437 str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
438 r = MSI_GetPropertyW(package, prop, str, &sz);
439 if (r != ERROR_SUCCESS)
441 HeapFree(GetProcessHeap(),0,str);
442 str = NULL;
444 if (rc)
445 *rc = r;
446 return str;
449 int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
451 int rc = -1;
452 DWORD i;
454 for (i = 0; i < package->loaded_components; i++)
456 if (strcmpW(Component,package->components[i].Component)==0)
458 rc = i;
459 break;
462 return rc;
465 int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
467 int rc = -1;
468 DWORD i;
470 for (i = 0; i < package->loaded_features; i++)
472 if (strcmpW(Feature,package->features[i].Feature)==0)
474 rc = i;
475 break;
478 return rc;
481 int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
483 int rc = -1;
484 DWORD i;
486 for (i = 0; i < package->loaded_files; i++)
488 if (strcmpW(file,package->files[i].File)==0)
490 rc = i;
491 break;
494 return rc;
497 int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
499 DWORD i;
500 DWORD index;
502 if (!package)
503 return -2;
505 for (i=0; i < package->loaded_files; i++)
506 if (strcmpW(package->files[i].File,name)==0)
507 return -1;
509 index = package->loaded_files;
510 package->loaded_files++;
511 if (package->loaded_files== 1)
512 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
513 else
514 package->files = HeapReAlloc(GetProcessHeap(),0,
515 package->files , package->loaded_files * sizeof(MSIFILE));
517 memset(&package->files[index],0,sizeof(MSIFILE));
519 package->files[index].File = strdupW(name);
520 package->files[index].TargetPath = strdupW(path);
521 package->files[index].Temporary = TRUE;
523 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
525 return 0;
528 static void remove_tracked_tempfiles(MSIPACKAGE* package)
530 DWORD i;
532 if (!package)
533 return;
535 for (i = 0; i < package->loaded_files; i++)
537 if (package->files[i].Temporary)
539 TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
540 DeleteFileW(package->files[i].TargetPath);
546 /* wrapper to resist a need for a full rewrite right now */
547 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
549 if (ptr)
551 MSIRECORD *rec = MSI_CreateRecord(1);
552 DWORD size = 0;
554 MSI_RecordSetStringW(rec,0,ptr);
555 MSI_FormatRecordW(package,rec,NULL,&size);
556 if (size >= 0)
558 size++;
559 *data = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
560 if (size > 1)
561 MSI_FormatRecordW(package,rec,*data,&size);
562 else
563 *data[0] = 0;
564 msiobj_release( &rec->hdr );
565 return sizeof(WCHAR)*size;
567 msiobj_release( &rec->hdr );
570 *data = NULL;
571 return 0;
574 /* Called when the package is being closed */
575 void ACTION_free_package_structures( MSIPACKAGE* package)
577 INT i;
579 TRACE("Freeing package action data\n");
581 remove_tracked_tempfiles(package);
583 /* No dynamic buffers in features */
584 if (package->features && package->loaded_features > 0)
585 HeapFree(GetProcessHeap(),0,package->features);
587 for (i = 0; i < package->loaded_folders; i++)
589 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
590 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
591 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
592 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
593 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
594 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
596 if (package->folders && package->loaded_folders > 0)
597 HeapFree(GetProcessHeap(),0,package->folders);
599 for (i = 0; i < package->loaded_components; i++)
600 HeapFree(GetProcessHeap(),0,package->components[i].FullKeypath);
602 if (package->components && package->loaded_components > 0)
603 HeapFree(GetProcessHeap(),0,package->components);
605 for (i = 0; i < package->loaded_files; i++)
607 HeapFree(GetProcessHeap(),0,package->files[i].File);
608 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
609 HeapFree(GetProcessHeap(),0,package->files[i].ShortName);
610 HeapFree(GetProcessHeap(),0,package->files[i].Version);
611 HeapFree(GetProcessHeap(),0,package->files[i].Language);
612 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
613 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
616 if (package->files && package->loaded_files > 0)
617 HeapFree(GetProcessHeap(),0,package->files);
619 /* clean up extension, progid, class and verb structures */
620 for (i = 0; i < package->loaded_classes; i++)
622 HeapFree(GetProcessHeap(),0,package->classes[i].Description);
623 HeapFree(GetProcessHeap(),0,package->classes[i].FileTypeMask);
624 HeapFree(GetProcessHeap(),0,package->classes[i].IconPath);
625 HeapFree(GetProcessHeap(),0,package->classes[i].DefInprocHandler);
626 HeapFree(GetProcessHeap(),0,package->classes[i].DefInprocHandler32);
627 HeapFree(GetProcessHeap(),0,package->classes[i].Argument);
628 HeapFree(GetProcessHeap(),0,package->classes[i].ProgIDText);
631 if (package->classes && package->loaded_classes > 0)
632 HeapFree(GetProcessHeap(),0,package->classes);
634 for (i = 0; i < package->loaded_extensions; i++)
636 HeapFree(GetProcessHeap(),0,package->extensions[i].ProgIDText);
639 if (package->extensions && package->loaded_extensions > 0)
640 HeapFree(GetProcessHeap(),0,package->extensions);
642 for (i = 0; i < package->loaded_progids; i++)
644 HeapFree(GetProcessHeap(),0,package->progids[i].ProgID);
645 HeapFree(GetProcessHeap(),0,package->progids[i].Description);
646 HeapFree(GetProcessHeap(),0,package->progids[i].IconPath);
649 if (package->progids && package->loaded_progids > 0)
650 HeapFree(GetProcessHeap(),0,package->progids);
652 for (i = 0; i < package->loaded_verbs; i++)
654 HeapFree(GetProcessHeap(),0,package->verbs[i].Verb);
655 HeapFree(GetProcessHeap(),0,package->verbs[i].Command);
656 HeapFree(GetProcessHeap(),0,package->verbs[i].Argument);
659 if (package->verbs && package->loaded_verbs > 0)
660 HeapFree(GetProcessHeap(),0,package->verbs);
662 for (i = 0; i < package->loaded_mimes; i++)
663 HeapFree(GetProcessHeap(),0,package->mimes[i].ContentType);
665 if (package->mimes && package->loaded_mimes > 0)
666 HeapFree(GetProcessHeap(),0,package->mimes);
668 for (i = 0; i < package->loaded_appids; i++)
670 HeapFree(GetProcessHeap(),0,package->appids[i].RemoteServerName);
671 HeapFree(GetProcessHeap(),0,package->appids[i].LocalServer);
672 HeapFree(GetProcessHeap(),0,package->appids[i].ServiceParameters);
673 HeapFree(GetProcessHeap(),0,package->appids[i].DllSurrogate);
676 if (package->appids && package->loaded_appids > 0)
677 HeapFree(GetProcessHeap(),0,package->appids);
679 if (package->script)
681 for (i = 0; i < TOTAL_SCRIPTS; i++)
683 int j;
684 for (j = 0; j < package->script->ActionCount[i]; j++)
685 HeapFree(GetProcessHeap(),0,package->script->Actions[i][j]);
687 HeapFree(GetProcessHeap(),0,package->script->Actions[i]);
689 HeapFree(GetProcessHeap(),0,package->script);
692 HeapFree(GetProcessHeap(),0,package->PackagePath);
694 /* cleanup control event subscriptions */
695 ControlEvent_CleanupSubscriptions(package);
698 static void ce_actiontext(MSIPACKAGE* package, LPCWSTR action)
700 static const WCHAR szActionText[] =
701 {'A','c','t','i','o','n','T','e','x','t',0};
702 MSIRECORD *row;
704 row = MSI_CreateRecord(1);
705 MSI_RecordSetStringW(row,1,action);
706 ControlEvent_FireSubscribedEvent(package,szActionText, row);
707 msiobj_release(&row->hdr);
710 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
712 MSIRECORD * row;
714 row = MSI_CreateRecord(4);
715 MSI_RecordSetInteger(row,1,a);
716 MSI_RecordSetInteger(row,2,b);
717 MSI_RecordSetInteger(row,3,c);
718 MSI_RecordSetInteger(row,4,d);
719 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
720 msiobj_release(&row->hdr);
722 msi_dialog_check_messages(NULL);
725 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
727 static const WCHAR Query_t[] =
728 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
729 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
730 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
731 ' ','\'','%','s','\'',0};
732 WCHAR message[1024];
733 MSIRECORD * row = 0;
734 DWORD size;
735 static const WCHAR szActionData[] =
736 {'A','c','t','i','o','n','D','a','t','a',0};
738 if (!package->LastAction || strcmpW(package->LastAction,action))
740 row = MSI_QueryGetRecord(package->db, Query_t, action);
741 if (!row)
742 return;
744 if (MSI_RecordIsNull(row,3))
746 msiobj_release(&row->hdr);
747 return;
750 /* update the cached actionformat */
751 HeapFree(GetProcessHeap(),0,package->ActionFormat);
752 package->ActionFormat = load_dynamic_stringW(row,3);
754 HeapFree(GetProcessHeap(),0,package->LastAction);
755 package->LastAction = strdupW(action);
757 msiobj_release(&row->hdr);
760 MSI_RecordSetStringW(record,0,package->ActionFormat);
761 size = 1024;
762 MSI_FormatRecordW(package,record,message,&size);
764 row = MSI_CreateRecord(1);
765 MSI_RecordSetStringW(row,1,message);
767 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
769 ControlEvent_FireSubscribedEvent(package,szActionData, row);
771 msiobj_release(&row->hdr);
775 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
777 static const WCHAR template_s[]=
778 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
779 '.',0};
780 static const WCHAR format[] =
781 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
782 static const WCHAR Query_t[] =
783 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
784 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
785 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
786 ' ','\'','%','s','\'',0};
787 WCHAR message[1024];
788 WCHAR timet[0x100];
789 MSIRECORD * row = 0;
790 WCHAR *ActionText=NULL;
792 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
794 row = MSI_QueryGetRecord( package->db, Query_t, action );
795 if (!row)
796 return;
798 ActionText = load_dynamic_stringW(row,2);
799 msiobj_release(&row->hdr);
801 sprintfW(message,template_s,timet,action,ActionText);
803 row = MSI_CreateRecord(1);
804 MSI_RecordSetStringW(row,1,message);
806 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
807 msiobj_release(&row->hdr);
808 HeapFree(GetProcessHeap(),0,ActionText);
811 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
812 UINT rc)
814 MSIRECORD * row;
815 static const WCHAR template_s[]=
816 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
817 '%','s', '.',0};
818 static const WCHAR template_e[]=
819 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
820 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
821 '%','i','.',0};
822 static const WCHAR format[] =
823 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
824 WCHAR message[1024];
825 WCHAR timet[0x100];
827 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
828 if (start)
829 sprintfW(message,template_s,timet,action);
830 else
831 sprintfW(message,template_e,timet,action,rc);
833 row = MSI_CreateRecord(1);
834 MSI_RecordSetStringW(row,1,message);
836 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
837 msiobj_release(&row->hdr);
841 * build_directory_name()
843 * This function is to save messing round with directory names
844 * It handles adding backslashes between path segments,
845 * and can add \ at the end of the directory name if told to.
847 * It takes a variable number of arguments.
848 * It always allocates a new string for the result, so make sure
849 * to free the return value when finished with it.
851 * The first arg is the number of path segments that follow.
852 * The arguments following count are a list of path segments.
853 * A path segment may be NULL.
855 * Path segments will be added with a \ separating them.
856 * A \ will not be added after the last segment, however if the
857 * last segment is NULL, then the last character will be a \
860 static LPWSTR build_directory_name(DWORD count, ...)
862 DWORD sz = 1, i;
863 LPWSTR dir;
864 va_list va;
866 va_start(va,count);
867 for(i=0; i<count; i++)
869 LPCWSTR str = va_arg(va,LPCWSTR);
870 if (str)
871 sz += strlenW(str) + 1;
873 va_end(va);
875 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
876 dir[0]=0;
878 va_start(va,count);
879 for(i=0; i<count; i++)
881 LPCWSTR str = va_arg(va,LPCWSTR);
882 if (!str)
883 continue;
884 strcatW(dir, str);
885 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
886 strcatW(dir, cszbs);
888 return dir;
891 static BOOL ACTION_VerifyComponentForAction(MSIPACKAGE* package, INT index,
892 INSTALLSTATE check )
894 if (package->components[index].Installed == check)
895 return FALSE;
897 if (package->components[index].ActionRequest == check)
898 return TRUE;
899 else
900 return FALSE;
903 static BOOL ACTION_VerifyFeatureForAction(MSIPACKAGE* package, INT index,
904 INSTALLSTATE check )
906 if (package->features[index].Installed == check)
907 return FALSE;
909 if (package->features[index].ActionRequest == check)
910 return TRUE;
911 else
912 return FALSE;
916 /****************************************************
917 * TOP level entry points
918 *****************************************************/
920 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
921 LPCWSTR szCommandLine)
923 DWORD sz;
924 WCHAR buffer[10];
925 UINT rc;
926 BOOL ui = FALSE;
927 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
928 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
929 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
931 MSI_SetPropertyW(package, szAction, szInstall);
933 package->script = HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT));
934 memset(package->script,0,sizeof(MSISCRIPT));
936 if (szPackagePath)
938 LPWSTR p, check, path;
940 package->PackagePath = strdupW(szPackagePath);
941 path = strdupW(szPackagePath);
942 p = strrchrW(path,'\\');
943 if (p)
945 p++;
946 *p=0;
948 else
950 HeapFree(GetProcessHeap(),0,path);
951 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
952 GetCurrentDirectoryW(MAX_PATH,path);
953 strcatW(path,cszbs);
956 check = load_dynamic_property(package, cszSourceDir,NULL);
957 if (!check)
958 MSI_SetPropertyW(package, cszSourceDir, path);
959 else
960 HeapFree(GetProcessHeap(), 0, check);
962 HeapFree(GetProcessHeap(), 0, path);
965 if (szCommandLine)
967 LPWSTR ptr,ptr2;
968 ptr = (LPWSTR)szCommandLine;
970 while (*ptr)
972 WCHAR *prop = NULL;
973 WCHAR *val = NULL;
975 TRACE("Looking at %s\n",debugstr_w(ptr));
977 ptr2 = strchrW(ptr,'=');
978 if (ptr2)
980 BOOL quote=FALSE;
981 DWORD len = 0;
983 while (*ptr == ' ') ptr++;
984 len = ptr2-ptr;
985 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
986 memcpy(prop,ptr,len*sizeof(WCHAR));
987 prop[len]=0;
988 ptr2++;
990 len = 0;
991 ptr = ptr2;
992 while (*ptr && (quote || (!quote && *ptr!=' ')))
994 if (*ptr == '"')
995 quote = !quote;
996 ptr++;
997 len++;
1000 if (*ptr2=='"')
1002 ptr2++;
1003 len -= 2;
1005 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
1006 memcpy(val,ptr2,len*sizeof(WCHAR));
1007 val[len] = 0;
1009 if (strlenW(prop) > 0)
1011 TRACE("Found commandline property (%s) = (%s)\n",
1012 debugstr_w(prop), debugstr_w(val));
1013 MSI_SetPropertyW(package,prop,val);
1015 HeapFree(GetProcessHeap(),0,val);
1016 HeapFree(GetProcessHeap(),0,prop);
1018 ptr++;
1022 sz = 10;
1023 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
1025 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
1027 rc = ACTION_ProcessUISequence(package);
1028 ui = TRUE;
1029 if (rc == ERROR_SUCCESS)
1030 rc = ACTION_ProcessExecSequence(package,TRUE);
1032 else
1033 rc = ACTION_ProcessExecSequence(package,FALSE);
1035 else
1036 rc = ACTION_ProcessExecSequence(package,FALSE);
1038 if (rc == -1)
1040 /* install was halted but should be considered a success */
1041 rc = ERROR_SUCCESS;
1044 package->script->CurrentlyScripting= FALSE;
1046 /* process the ending type action */
1047 if (rc == ERROR_SUCCESS)
1048 ACTION_PerformActionSequence(package,-1,ui);
1049 else if (rc == ERROR_INSTALL_USEREXIT)
1050 ACTION_PerformActionSequence(package,-2,ui);
1051 else if (rc == ERROR_INSTALL_SUSPEND)
1052 ACTION_PerformActionSequence(package,-4,ui);
1053 else /* failed */
1054 ACTION_PerformActionSequence(package,-3,ui);
1056 /* finish up running custom actions */
1057 ACTION_FinishCustomActions(package);
1059 return rc;
1062 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
1064 UINT rc = ERROR_SUCCESS;
1065 WCHAR buffer[0x100];
1066 DWORD sz = 0x100;
1067 MSIRECORD * row = 0;
1068 static const WCHAR ExecSeqQuery[] =
1069 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1070 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1071 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1072 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
1074 static const WCHAR UISeqQuery[] =
1075 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1076 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1077 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
1078 ' ', '=',' ','%','i',0};
1080 if (UI)
1081 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
1082 else
1083 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
1085 if (row)
1087 TRACE("Running the actions\n");
1089 /* check conditions */
1090 if (!MSI_RecordIsNull(row,2))
1092 LPWSTR cond = NULL;
1093 cond = load_dynamic_stringW(row,2);
1095 if (cond)
1097 /* this is a hack to skip errors in the condition code */
1098 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1100 HeapFree(GetProcessHeap(),0,cond);
1101 goto end;
1103 else
1104 HeapFree(GetProcessHeap(),0,cond);
1108 sz=0x100;
1109 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1110 if (rc != ERROR_SUCCESS)
1112 ERR("Error is %x\n",rc);
1113 msiobj_release(&row->hdr);
1114 goto end;
1117 if (UI)
1118 rc = ACTION_PerformUIAction(package,buffer);
1119 else
1120 rc = ACTION_PerformAction(package,buffer, FALSE);
1121 end:
1122 msiobj_release(&row->hdr);
1124 else
1125 rc = ERROR_SUCCESS;
1127 return rc;
1130 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1132 MSIQUERY * view;
1133 UINT rc;
1134 static const WCHAR ExecSeqQuery[] =
1135 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1136 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1137 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1138 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
1139 'O','R','D','E','R',' ', 'B','Y',' ',
1140 '`','S','e','q','u','e','n','c','e','`',0 };
1141 MSIRECORD * row = 0;
1142 static const WCHAR IVQuery[] =
1143 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
1144 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
1145 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
1146 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
1147 ' ','\'', 'I','n','s','t','a','l','l',
1148 'V','a','l','i','d','a','t','e','\'', 0};
1149 INT seq = 0;
1152 if (package->script->ExecuteSequenceRun)
1154 TRACE("Execute Sequence already Run\n");
1155 return ERROR_SUCCESS;
1158 package->script->ExecuteSequenceRun = TRUE;
1160 /* get the sequence number */
1161 if (UIran)
1163 row = MSI_QueryGetRecord(package->db, IVQuery);
1164 if( !row )
1165 return ERROR_FUNCTION_FAILED;
1166 seq = MSI_RecordGetInteger(row,1);
1167 msiobj_release(&row->hdr);
1170 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1171 if (rc == ERROR_SUCCESS)
1173 rc = MSI_ViewExecute(view, 0);
1175 if (rc != ERROR_SUCCESS)
1177 MSI_ViewClose(view);
1178 msiobj_release(&view->hdr);
1179 goto end;
1182 TRACE("Running the actions\n");
1184 while (1)
1186 WCHAR buffer[0x100];
1187 DWORD sz = 0x100;
1189 rc = MSI_ViewFetch(view,&row);
1190 if (rc != ERROR_SUCCESS)
1192 rc = ERROR_SUCCESS;
1193 break;
1196 sz=0x100;
1197 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1198 if (rc != ERROR_SUCCESS)
1200 ERR("Error is %x\n",rc);
1201 msiobj_release(&row->hdr);
1202 break;
1205 /* check conditions */
1206 if (!MSI_RecordIsNull(row,2))
1208 LPWSTR cond = NULL;
1209 cond = load_dynamic_stringW(row,2);
1211 if (cond)
1213 /* this is a hack to skip errors in the condition code */
1214 if (MSI_EvaluateConditionW(package, cond) ==
1215 MSICONDITION_FALSE)
1217 HeapFree(GetProcessHeap(),0,cond);
1218 msiobj_release(&row->hdr);
1219 TRACE("Skipping action: %s (condition is false)\n",
1220 debugstr_w(buffer));
1221 continue;
1223 else
1224 HeapFree(GetProcessHeap(),0,cond);
1228 rc = ACTION_PerformAction(package,buffer, FALSE);
1230 if (rc == ERROR_FUNCTION_NOT_CALLED)
1231 rc = ERROR_SUCCESS;
1233 if (rc != ERROR_SUCCESS)
1235 ERR("Execution halted due to error (%i)\n",rc);
1236 msiobj_release(&row->hdr);
1237 break;
1240 msiobj_release(&row->hdr);
1243 MSI_ViewClose(view);
1244 msiobj_release(&view->hdr);
1247 end:
1248 return rc;
1252 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1254 MSIQUERY * view;
1255 UINT rc;
1256 static const WCHAR ExecSeqQuery [] =
1257 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1258 '`','I','n','s','t','a','l','l',
1259 'U','I','S','e','q','u','e','n','c','e','`',
1260 ' ','W','H','E','R','E',' ',
1261 '`','S','e','q','u','e','n','c','e','`',' ',
1262 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1263 '`','S','e','q','u','e','n','c','e','`',0};
1265 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1267 if (rc == ERROR_SUCCESS)
1269 rc = MSI_ViewExecute(view, 0);
1271 if (rc != ERROR_SUCCESS)
1273 MSI_ViewClose(view);
1274 msiobj_release(&view->hdr);
1275 goto end;
1278 TRACE("Running the actions \n");
1280 while (1)
1282 WCHAR buffer[0x100];
1283 DWORD sz = 0x100;
1284 MSIRECORD * row = 0;
1286 rc = MSI_ViewFetch(view,&row);
1287 if (rc != ERROR_SUCCESS)
1289 rc = ERROR_SUCCESS;
1290 break;
1293 sz=0x100;
1294 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1295 if (rc != ERROR_SUCCESS)
1297 ERR("Error is %x\n",rc);
1298 msiobj_release(&row->hdr);
1299 break;
1303 /* check conditions */
1304 if (!MSI_RecordIsNull(row,2))
1306 LPWSTR cond = NULL;
1307 cond = load_dynamic_stringW(row,2);
1309 if (cond)
1311 /* this is a hack to skip errors in the condition code */
1312 if (MSI_EvaluateConditionW(package, cond) ==
1313 MSICONDITION_FALSE)
1315 HeapFree(GetProcessHeap(),0,cond);
1316 msiobj_release(&row->hdr);
1317 TRACE("Skipping action: %s (condition is false)\n",
1318 debugstr_w(buffer));
1319 continue;
1321 else
1322 HeapFree(GetProcessHeap(),0,cond);
1326 rc = ACTION_PerformUIAction(package,buffer);
1328 if (rc == ERROR_FUNCTION_NOT_CALLED)
1329 rc = ERROR_SUCCESS;
1331 if (rc != ERROR_SUCCESS)
1333 ERR("Execution halted due to error (%i)\n",rc);
1334 msiobj_release(&row->hdr);
1335 break;
1338 msiobj_release(&row->hdr);
1341 MSI_ViewClose(view);
1342 msiobj_release(&view->hdr);
1345 end:
1346 return rc;
1349 /********************************************************
1350 * ACTION helper functions and functions that perform the actions
1351 *******************************************************/
1352 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
1353 UINT* rc, BOOL force )
1355 BOOL ret = FALSE;
1356 BOOL run = force;
1357 int i;
1359 if (!run && !package->script->CurrentlyScripting)
1360 run = TRUE;
1362 if (!run)
1364 if (strcmpW(action,szInstallFinalize) == 0 ||
1365 strcmpW(action,szInstallExecute) == 0 ||
1366 strcmpW(action,szInstallExecuteAgain) == 0)
1367 run = TRUE;
1370 i = 0;
1371 while (StandardActions[i].action != NULL)
1373 if (strcmpW(StandardActions[i].action, action)==0)
1375 ce_actiontext(package, action);
1376 if (!run)
1378 ui_actioninfo(package, action, TRUE, 0);
1379 *rc = schedule_action(package,INSTALL_SCRIPT,action);
1380 ui_actioninfo(package, action, FALSE, *rc);
1382 else
1384 ui_actionstart(package, action);
1385 if (StandardActions[i].handler)
1387 *rc = StandardActions[i].handler(package);
1389 else
1391 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1392 *rc = ERROR_SUCCESS;
1395 ret = TRUE;
1396 break;
1398 i++;
1400 return ret;
1403 BOOL ACTION_HandleDialogBox(MSIPACKAGE *package, LPCWSTR dialog, UINT* rc)
1405 BOOL ret = FALSE;
1407 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1409 *rc = package->CurrentInstallState;
1410 ret = TRUE;
1412 return ret;
1415 BOOL ACTION_HandleCustomAction(MSIPACKAGE* package, LPCWSTR action, UINT* rc,
1416 BOOL force )
1418 BOOL ret=FALSE;
1419 UINT arc;
1421 arc = ACTION_CustomAction(package,action, force);
1423 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1425 *rc = arc;
1426 ret = TRUE;
1428 return ret;
1432 * A lot of actions are really important even if they don't do anything
1433 * explicit... Lots of properties are set at the beginning of the installation
1434 * CostFinalize does a bunch of work to translate the directories and such
1436 * But until I get write access to the database that is hard, so I am going to
1437 * hack it to see if I can get something to run.
1439 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
1441 UINT rc = ERROR_SUCCESS;
1442 BOOL handled;
1444 TRACE("Performing action (%s)\n",debugstr_w(action));
1446 handled = ACTION_HandleStandardAction(package, action, &rc, force);
1448 if (!handled)
1449 handled = ACTION_HandleCustomAction(package, action, &rc, force);
1451 if (!handled)
1453 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1454 rc = ERROR_FUNCTION_NOT_CALLED;
1457 package->CurrentInstallState = rc;
1458 return rc;
1461 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1463 UINT rc = ERROR_SUCCESS;
1464 BOOL handled = FALSE;
1466 TRACE("Performing action (%s)\n",debugstr_w(action));
1468 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
1470 if (!handled)
1471 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
1473 if (!handled)
1474 handled = ACTION_HandleDialogBox(package, action, &rc);
1476 msi_dialog_check_messages( NULL );
1478 if (!handled)
1480 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1481 rc = ERROR_FUNCTION_NOT_CALLED;
1484 package->CurrentInstallState = rc;
1485 return rc;
1488 /***********************************************************************
1489 * create_full_pathW
1491 * Recursively create all directories in the path.
1493 * shamelessly stolen from setupapi/queue.c
1495 static BOOL create_full_pathW(const WCHAR *path)
1497 BOOL ret = TRUE;
1498 int len;
1499 WCHAR *new_path;
1501 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1502 sizeof(WCHAR));
1504 strcpyW(new_path, path);
1506 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1507 new_path[len - 1] = 0;
1509 while(!CreateDirectoryW(new_path, NULL))
1511 WCHAR *slash;
1512 DWORD last_error = GetLastError();
1513 if(last_error == ERROR_ALREADY_EXISTS)
1514 break;
1516 if(last_error != ERROR_PATH_NOT_FOUND)
1518 ret = FALSE;
1519 break;
1522 if(!(slash = strrchrW(new_path, '\\')))
1524 ret = FALSE;
1525 break;
1528 len = slash - new_path;
1529 new_path[len] = 0;
1530 if(!create_full_pathW(new_path))
1532 ret = FALSE;
1533 break;
1535 new_path[len] = '\\';
1538 HeapFree(GetProcessHeap(), 0, new_path);
1539 return ret;
1543 * Also we cannot enable/disable components either, so for now I am just going
1544 * to do all the directories for all the components.
1546 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1548 static const WCHAR ExecSeqQuery[] =
1549 {'S','E','L','E','C','T',' ',
1550 '`','D','i','r','e','c','t','o','r','y','_','`',
1551 ' ','F','R','O','M',' ',
1552 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
1553 UINT rc;
1554 MSIQUERY *view;
1555 MSIFOLDER *folder;
1557 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1558 if (rc != ERROR_SUCCESS)
1559 return ERROR_SUCCESS;
1561 rc = MSI_ViewExecute(view, 0);
1562 if (rc != ERROR_SUCCESS)
1564 MSI_ViewClose(view);
1565 msiobj_release(&view->hdr);
1566 return rc;
1569 while (1)
1571 WCHAR dir[0x100];
1572 LPWSTR full_path;
1573 DWORD sz;
1574 MSIRECORD *row = NULL, *uirow;
1576 rc = MSI_ViewFetch(view,&row);
1577 if (rc != ERROR_SUCCESS)
1579 rc = ERROR_SUCCESS;
1580 break;
1583 sz=0x100;
1584 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1586 if (rc!= ERROR_SUCCESS)
1588 ERR("Unable to get folder id \n");
1589 msiobj_release(&row->hdr);
1590 continue;
1593 sz = MAX_PATH;
1594 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1595 if (!full_path)
1597 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1598 msiobj_release(&row->hdr);
1599 continue;
1602 TRACE("Folder is %s\n",debugstr_w(full_path));
1604 /* UI stuff */
1605 uirow = MSI_CreateRecord(1);
1606 MSI_RecordSetStringW(uirow,1,full_path);
1607 ui_actiondata(package,szCreateFolders,uirow);
1608 msiobj_release( &uirow->hdr );
1610 if (folder->State == 0)
1611 create_full_pathW(full_path);
1613 folder->State = 3;
1615 msiobj_release(&row->hdr);
1616 HeapFree(GetProcessHeap(),0,full_path);
1618 MSI_ViewClose(view);
1619 msiobj_release(&view->hdr);
1621 return rc;
1624 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1626 int index = package->loaded_components;
1627 DWORD sz;
1629 /* fill in the data */
1631 package->loaded_components++;
1632 if (package->loaded_components == 1)
1633 package->components = HeapAlloc(GetProcessHeap(),0,
1634 sizeof(MSICOMPONENT));
1635 else
1636 package->components = HeapReAlloc(GetProcessHeap(),0,
1637 package->components, package->loaded_components *
1638 sizeof(MSICOMPONENT));
1640 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1642 sz = IDENTIFIER_SIZE;
1643 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1645 TRACE("Loading Component %s\n",
1646 debugstr_w(package->components[index].Component));
1648 sz = 0x100;
1649 if (!MSI_RecordIsNull(row,2))
1650 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1652 sz = IDENTIFIER_SIZE;
1653 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1655 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1657 sz = 0x100;
1658 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1660 sz = IDENTIFIER_SIZE;
1661 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1663 package->components[index].Installed = INSTALLSTATE_ABSENT;
1664 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1665 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1667 package->components[index].Enabled = TRUE;
1669 return index;
1672 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1674 int index = package->loaded_features;
1675 DWORD sz;
1676 static const WCHAR Query1[] =
1677 {'S','E','L','E','C','T',' ',
1678 '`','C','o','m','p','o','n','e','n','t','_','`',
1679 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1680 'C','o','m','p','o','n','e','n','t','s','`',' ',
1681 'W','H','E','R','E',' ',
1682 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1683 static const WCHAR Query2[] =
1684 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1685 '`','C','o','m','p','o','n','e','n','t','`',' ',
1686 'W','H','E','R','E',' ',
1687 '`','C','o','m','p','o','n','e','n','t','`',' ',
1688 '=','\'','%','s','\'',0};
1689 MSIQUERY * view;
1690 MSIQUERY * view2;
1691 MSIRECORD * row2;
1692 MSIRECORD * row3;
1693 UINT rc;
1695 /* fill in the data */
1697 package->loaded_features ++;
1698 if (package->loaded_features == 1)
1699 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1700 else
1701 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1702 package->loaded_features * sizeof(MSIFEATURE));
1704 memset(&package->features[index],0,sizeof(MSIFEATURE));
1706 sz = IDENTIFIER_SIZE;
1707 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1709 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1711 sz = IDENTIFIER_SIZE;
1712 if (!MSI_RecordIsNull(row,2))
1713 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1715 sz = 0x100;
1716 if (!MSI_RecordIsNull(row,3))
1717 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1719 sz = 0x100;
1720 if (!MSI_RecordIsNull(row,4))
1721 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1723 if (!MSI_RecordIsNull(row,5))
1724 package->features[index].Display = MSI_RecordGetInteger(row,5);
1726 package->features[index].Level= MSI_RecordGetInteger(row,6);
1728 sz = IDENTIFIER_SIZE;
1729 if (!MSI_RecordIsNull(row,7))
1730 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1732 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1734 package->features[index].Installed = INSTALLSTATE_ABSENT;
1735 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1736 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1738 /* load feature components */
1740 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1741 if (rc != ERROR_SUCCESS)
1742 return;
1743 rc = MSI_ViewExecute(view,0);
1744 if (rc != ERROR_SUCCESS)
1746 MSI_ViewClose(view);
1747 msiobj_release(&view->hdr);
1748 return;
1750 while (1)
1752 DWORD sz = 0x100;
1753 WCHAR buffer[0x100];
1754 DWORD rc;
1755 INT c_indx;
1756 INT cnt = package->features[index].ComponentCount;
1758 rc = MSI_ViewFetch(view,&row2);
1759 if (rc != ERROR_SUCCESS)
1760 break;
1762 sz = 0x100;
1763 MSI_RecordGetStringW(row2,1,buffer,&sz);
1765 /* check to see if the component is already loaded */
1766 c_indx = get_loaded_component(package,buffer);
1767 if (c_indx != -1)
1769 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1770 c_indx);
1771 package->features[index].Components[cnt] = c_indx;
1772 package->features[index].ComponentCount ++;
1773 msiobj_release( &row2->hdr );
1774 continue;
1777 rc = MSI_OpenQuery(package->db, &view2, Query2, buffer);
1778 if (rc != ERROR_SUCCESS)
1780 msiobj_release( &row2->hdr );
1781 continue;
1783 rc = MSI_ViewExecute(view2,0);
1784 if (rc != ERROR_SUCCESS)
1786 msiobj_release( &row2->hdr );
1787 MSI_ViewClose(view2);
1788 msiobj_release( &view2->hdr );
1789 continue;
1791 while (1)
1793 DWORD rc;
1795 rc = MSI_ViewFetch(view2,&row3);
1796 if (rc != ERROR_SUCCESS)
1797 break;
1798 c_indx = load_component(package,row3);
1799 msiobj_release( &row3->hdr );
1801 package->features[index].Components[cnt] = c_indx;
1802 package->features[index].ComponentCount ++;
1803 TRACE("Loaded new component to index %i\n",c_indx);
1805 MSI_ViewClose(view2);
1806 msiobj_release( &view2->hdr );
1807 msiobj_release( &row2->hdr );
1809 MSI_ViewClose(view);
1810 msiobj_release(&view->hdr);
1813 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1815 DWORD index = package->loaded_files;
1816 DWORD i;
1817 LPWSTR buffer;
1819 /* fill in the data */
1821 package->loaded_files++;
1822 if (package->loaded_files== 1)
1823 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1824 else
1825 package->files = HeapReAlloc(GetProcessHeap(),0,
1826 package->files , package->loaded_files * sizeof(MSIFILE));
1828 memset(&package->files[index],0,sizeof(MSIFILE));
1830 package->files[index].File = load_dynamic_stringW(row, 1);
1831 buffer = load_dynamic_stringW(row, 2);
1833 package->files[index].ComponentIndex = -1;
1834 for (i = 0; i < package->loaded_components; i++)
1835 if (strcmpW(package->components[i].Component,buffer)==0)
1837 package->files[index].ComponentIndex = i;
1838 break;
1840 if (package->files[index].ComponentIndex == -1)
1841 ERR("Unfound Component %s\n",debugstr_w(buffer));
1842 HeapFree(GetProcessHeap(), 0, buffer);
1844 package->files[index].FileName = load_dynamic_stringW(row,3);
1845 reduce_to_longfilename(package->files[index].FileName);
1847 package->files[index].ShortName = load_dynamic_stringW(row,3);
1848 reduce_to_shortfilename(package->files[index].ShortName);
1850 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1851 package->files[index].Version = load_dynamic_stringW(row, 5);
1852 package->files[index].Language = load_dynamic_stringW(row, 6);
1853 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1854 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1856 package->files[index].Temporary = FALSE;
1857 package->files[index].State = 0;
1859 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1861 return ERROR_SUCCESS;
1864 static UINT load_all_files(MSIPACKAGE *package)
1866 MSIQUERY * view;
1867 MSIRECORD * row;
1868 UINT rc;
1869 static const WCHAR Query[] =
1870 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1871 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1872 '`','S','e','q','u','e','n','c','e','`', 0};
1874 if (!package)
1875 return ERROR_INVALID_HANDLE;
1877 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1878 if (rc != ERROR_SUCCESS)
1879 return ERROR_SUCCESS;
1881 rc = MSI_ViewExecute(view, 0);
1882 if (rc != ERROR_SUCCESS)
1884 MSI_ViewClose(view);
1885 msiobj_release(&view->hdr);
1886 return ERROR_SUCCESS;
1889 while (1)
1891 rc = MSI_ViewFetch(view,&row);
1892 if (rc != ERROR_SUCCESS)
1894 rc = ERROR_SUCCESS;
1895 break;
1897 load_file(package,row);
1898 msiobj_release(&row->hdr);
1900 MSI_ViewClose(view);
1901 msiobj_release(&view->hdr);
1903 return ERROR_SUCCESS;
1908 * I am not doing any of the costing functionality yet.
1909 * Mostly looking at doing the Component and Feature loading
1911 * The native MSI does A LOT of modification to tables here. Mostly adding
1912 * a lot of temporary columns to the Feature and Component tables.
1914 * note: Native msi also tracks the short filename. But I am only going to
1915 * track the long ones. Also looking at this directory table
1916 * it appears that the directory table does not get the parents
1917 * resolved base on property only based on their entries in the
1918 * directory table.
1920 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1922 MSIQUERY * view;
1923 MSIRECORD * row;
1924 UINT rc;
1925 static const WCHAR Query_all[] =
1926 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1927 '`','F','e','a','t','u','r','e','`',0};
1928 static const WCHAR szCosting[] =
1929 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1930 static const WCHAR szZero[] = { '0', 0 };
1931 WCHAR buffer[3];
1932 DWORD sz = 3;
1934 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1935 if (buffer[0]=='1')
1936 return ERROR_SUCCESS;
1938 MSI_SetPropertyW(package, szCosting, szZero);
1939 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1941 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1942 if (rc != ERROR_SUCCESS)
1943 return rc;
1944 rc = MSI_ViewExecute(view,0);
1945 if (rc != ERROR_SUCCESS)
1947 MSI_ViewClose(view);
1948 msiobj_release(&view->hdr);
1949 return rc;
1951 while (1)
1953 DWORD rc;
1955 rc = MSI_ViewFetch(view,&row);
1956 if (rc != ERROR_SUCCESS)
1957 break;
1959 load_feature(package,row);
1960 msiobj_release(&row->hdr);
1962 MSI_ViewClose(view);
1963 msiobj_release(&view->hdr);
1965 load_all_files(package);
1967 return ERROR_SUCCESS;
1970 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
1972 UINT count;
1973 LPWSTR *newbuf = NULL;
1974 if (script >= TOTAL_SCRIPTS)
1976 FIXME("Unknown script requested %i\n",script);
1977 return ERROR_FUNCTION_FAILED;
1979 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
1981 count = package->script->ActionCount[script];
1982 package->script->ActionCount[script]++;
1983 if (count != 0)
1984 newbuf = HeapReAlloc(GetProcessHeap(),0,
1985 package->script->Actions[script],
1986 package->script->ActionCount[script]* sizeof(LPWSTR));
1987 else
1988 newbuf = HeapAlloc(GetProcessHeap(),0, sizeof(LPWSTR));
1990 newbuf[count] = strdupW(action);
1991 package->script->Actions[script] = newbuf;
1993 return ERROR_SUCCESS;
1996 UINT execute_script(MSIPACKAGE *package, UINT script )
1998 int i;
1999 UINT rc = ERROR_SUCCESS;
2001 TRACE("Executing Script %i\n",script);
2003 for (i = 0; i < package->script->ActionCount[script]; i++)
2005 LPWSTR action;
2006 action = package->script->Actions[script][i];
2007 ui_actionstart(package, action);
2008 TRACE("Executing Action (%s)\n",debugstr_w(action));
2009 rc = ACTION_PerformAction(package, action, TRUE);
2010 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
2011 if (rc != ERROR_SUCCESS)
2012 break;
2014 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
2016 package->script->ActionCount[script] = 0;
2017 package->script->Actions[script] = NULL;
2018 return rc;
2021 static UINT ACTION_FileCost(MSIPACKAGE *package)
2023 return ERROR_SUCCESS;
2027 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
2029 static const WCHAR Query[] =
2030 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2031 '`','D','i','r','e','c', 't','o','r','y','`',' ',
2032 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
2033 ' ','=',' ','\'','%','s','\'',
2035 LPWSTR ptargetdir, targetdir, parent, srcdir;
2036 LPWSTR shortname = NULL;
2037 MSIRECORD * row = 0;
2038 INT index = -1;
2039 DWORD i;
2041 TRACE("Looking for dir %s\n",debugstr_w(dir));
2043 for (i = 0; i < package->loaded_folders; i++)
2045 if (strcmpW(package->folders[i].Directory,dir)==0)
2047 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
2048 return i;
2052 TRACE("Working to load %s\n",debugstr_w(dir));
2054 index = package->loaded_folders++;
2055 if (package->loaded_folders==1)
2056 package->folders = HeapAlloc(GetProcessHeap(),0,
2057 sizeof(MSIFOLDER));
2058 else
2059 package->folders= HeapReAlloc(GetProcessHeap(),0,
2060 package->folders, package->loaded_folders*
2061 sizeof(MSIFOLDER));
2063 memset(&package->folders[index],0,sizeof(MSIFOLDER));
2065 package->folders[index].Directory = strdupW(dir);
2067 row = MSI_QueryGetRecord(package->db, Query, dir);
2068 if (!row)
2069 return -1;
2071 ptargetdir = targetdir = load_dynamic_stringW(row,3);
2073 /* split src and target dir */
2074 if (strchrW(targetdir,':'))
2076 srcdir=strchrW(targetdir,':');
2077 *srcdir=0;
2078 srcdir ++;
2080 else
2081 srcdir=NULL;
2083 /* for now only pick long filename versions */
2084 if (strchrW(targetdir,'|'))
2086 shortname = targetdir;
2087 targetdir = strchrW(targetdir,'|');
2088 *targetdir = 0;
2089 targetdir ++;
2091 /* for the sourcedir pick the short filename */
2092 if (srcdir && strchrW(srcdir,'|'))
2094 LPWSTR p = strchrW(srcdir,'|');
2095 *p = 0;
2098 /* now check for root dirs */
2099 if (targetdir[0] == '.' && targetdir[1] == 0)
2100 targetdir = NULL;
2102 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
2103 srcdir = NULL;
2105 if (targetdir)
2107 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2108 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2109 package->folders[index].TargetDefault = strdupW(targetdir);
2112 if (srcdir)
2113 package->folders[index].SourceDefault = strdupW(srcdir);
2114 else if (shortname)
2115 package->folders[index].SourceDefault = strdupW(shortname);
2116 else if (targetdir)
2117 package->folders[index].SourceDefault = strdupW(targetdir);
2118 HeapFree(GetProcessHeap(), 0, ptargetdir);
2119 TRACE(" SourceDefault = %s\n",debugstr_w(package->folders[index].SourceDefault));
2121 parent = load_dynamic_stringW(row,2);
2122 if (parent)
2124 i = load_folder(package,parent);
2125 package->folders[index].ParentIndex = i;
2126 TRACE("Parent is index %i... %s %s\n",
2127 package->folders[index].ParentIndex,
2128 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2129 debugstr_w(parent));
2131 else
2132 package->folders[index].ParentIndex = -2;
2133 HeapFree(GetProcessHeap(), 0, parent);
2135 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2137 msiobj_release(&row->hdr);
2138 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2139 return index;
2143 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
2144 BOOL set_prop, MSIFOLDER **folder)
2146 DWORD i;
2147 LPWSTR p, path = NULL;
2149 TRACE("Working to resolve %s\n",debugstr_w(name));
2151 /* special resolving for Target and Source root dir */
2152 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2154 if (!source)
2156 path = load_dynamic_property(package,cszTargetDir,NULL);
2157 if (!path)
2159 path = load_dynamic_property(package,cszRootDrive,NULL);
2160 if (set_prop)
2161 MSI_SetPropertyW(package,cszTargetDir,path);
2163 if (folder)
2165 for (i = 0; i < package->loaded_folders; i++)
2167 if (strcmpW(package->folders[i].Directory,name)==0)
2168 break;
2170 *folder = &(package->folders[i]);
2172 return path;
2174 else
2176 path = load_dynamic_property(package,cszSourceDir,NULL);
2177 if (!path)
2179 path = load_dynamic_property(package,cszDatabase,NULL);
2180 if (path)
2182 p = strrchrW(path,'\\');
2183 if (p)
2184 *(p+1) = 0;
2187 if (folder)
2189 for (i = 0; i < package->loaded_folders; i++)
2191 if (strcmpW(package->folders[i].Directory,name)==0)
2192 break;
2194 *folder = &(package->folders[i]);
2196 return path;
2200 for (i = 0; i < package->loaded_folders; i++)
2202 if (strcmpW(package->folders[i].Directory,name)==0)
2203 break;
2206 if (i >= package->loaded_folders)
2207 return NULL;
2209 if (folder)
2210 *folder = &(package->folders[i]);
2212 if (!source && package->folders[i].ResolvedTarget)
2214 path = strdupW(package->folders[i].ResolvedTarget);
2215 TRACE(" already resolved to %s\n",debugstr_w(path));
2216 return path;
2218 else if (source && package->folders[i].ResolvedSource)
2220 path = strdupW(package->folders[i].ResolvedSource);
2221 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
2222 return path;
2224 else if (!source && package->folders[i].Property)
2226 path = build_directory_name(2, package->folders[i].Property, NULL);
2228 TRACE(" internally set to %s\n",debugstr_w(path));
2229 if (set_prop)
2230 MSI_SetPropertyW(package,name,path);
2231 return path;
2234 if (package->folders[i].ParentIndex >= 0)
2236 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2238 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2240 p = resolve_folder(package, parent, source, set_prop, NULL);
2241 if (!source)
2243 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2244 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2245 package->folders[i].ResolvedTarget = strdupW(path);
2246 TRACE(" resolved into %s\n",debugstr_w(path));
2247 if (set_prop)
2248 MSI_SetPropertyW(package,name,path);
2250 else
2252 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2253 TRACE(" (source)resolved into %s\n",debugstr_w(path));
2254 package->folders[i].ResolvedSource = strdupW(path);
2256 HeapFree(GetProcessHeap(),0,p);
2258 return path;
2261 /* scan for and update current install states */
2262 void ACTION_UpdateInstallStates(MSIPACKAGE *package)
2264 int i;
2265 LPWSTR productcode;
2267 productcode = load_dynamic_property(package,szProductCode,NULL);
2269 for (i = 0; i < package->loaded_components; i++)
2271 INSTALLSTATE res;
2272 res = MsiGetComponentPathW(productcode,
2273 package->components[i].ComponentId , NULL, NULL);
2274 if (res < 0)
2275 res = INSTALLSTATE_ABSENT;
2276 package->components[i].Installed = res;
2279 for (i = 0; i < package->loaded_features; i++)
2281 INSTALLSTATE res = -10;
2282 int j;
2283 for (j = 0; j < package->features[i].ComponentCount; j++)
2285 MSICOMPONENT* component = &package->components[package->features[i].
2286 Components[j]];
2287 if (res == -10)
2288 res = component->Installed;
2289 else
2291 if (res == component->Installed)
2292 continue;
2294 if (res != component->Installed)
2295 res = INSTALLSTATE_INCOMPLETE;
2301 /* update compoennt state based on a feature change */
2302 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2304 int i;
2305 INSTALLSTATE newstate;
2306 MSIFEATURE *feature;
2308 i = get_loaded_feature(package,szFeature);
2309 if (i < 0)
2310 return;
2312 feature = &package->features[i];
2313 newstate = feature->ActionRequest;
2315 for( i = 0; i < feature->ComponentCount; i++)
2317 MSICOMPONENT* component = &package->components[feature->Components[i]];
2319 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
2320 newstate, debugstr_w(component->Component), component->Installed,
2321 component->Action, component->ActionRequest);
2323 if (!component->Enabled)
2324 continue;
2325 else
2327 if (newstate == INSTALLSTATE_LOCAL)
2329 component->ActionRequest = INSTALLSTATE_LOCAL;
2330 component->Action = INSTALLSTATE_LOCAL;
2332 else
2334 int j,k;
2336 component->ActionRequest = newstate;
2337 component->Action = newstate;
2339 /*if any other feature wants is local we need to set it local*/
2340 for (j = 0;
2341 j < package->loaded_features &&
2342 component->ActionRequest != INSTALLSTATE_LOCAL;
2343 j++)
2345 for (k = 0; k < package->features[j].ComponentCount; k++)
2346 if ( package->features[j].Components[k] ==
2347 feature->Components[i] )
2349 if (package->features[j].ActionRequest ==
2350 INSTALLSTATE_LOCAL)
2352 TRACE("Saved by %s\n", debugstr_w(package->features[j].Feature));
2353 component->ActionRequest = INSTALLSTATE_LOCAL;
2354 component->Action = INSTALLSTATE_LOCAL;
2356 break;
2361 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
2362 newstate, debugstr_w(component->Component), component->Installed,
2363 component->Action, component->ActionRequest);
2367 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
2368 INSTALLSTATE state)
2370 static const WCHAR all[]={'A','L','L',0};
2371 LPWSTR override = NULL;
2372 INT i;
2373 BOOL rc = FALSE;
2375 override = load_dynamic_property(package, property, NULL);
2376 if (override)
2378 rc = TRUE;
2379 for(i = 0; i < package->loaded_features; i++)
2381 if (strcmpiW(override,all)==0)
2383 package->features[i].ActionRequest= state;
2384 package->features[i].Action = state;
2386 else
2388 LPWSTR ptr = override;
2389 LPWSTR ptr2 = strchrW(override,',');
2391 while (ptr)
2393 if ((ptr2 &&
2394 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2395 || (!ptr2 &&
2396 strcmpW(ptr,package->features[i].Feature)==0))
2398 package->features[i].ActionRequest= state;
2399 package->features[i].Action = state;
2400 break;
2402 if (ptr2)
2404 ptr=ptr2+1;
2405 ptr2 = strchrW(ptr,',');
2407 else
2408 break;
2412 HeapFree(GetProcessHeap(),0,override);
2415 return rc;
2418 static UINT SetFeatureStates(MSIPACKAGE *package)
2420 LPWSTR level;
2421 INT install_level;
2422 DWORD i;
2423 INT j;
2424 static const WCHAR szlevel[] =
2425 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2426 static const WCHAR szAddLocal[] =
2427 {'A','D','D','L','O','C','A','L',0};
2428 static const WCHAR szRemove[] =
2429 {'R','E','M','O','V','E',0};
2430 BOOL override = FALSE;
2432 /* I do not know if this is where it should happen.. but */
2434 TRACE("Checking Install Level\n");
2436 level = load_dynamic_property(package,szlevel,NULL);
2437 if (level)
2439 install_level = atoiW(level);
2440 HeapFree(GetProcessHeap(), 0, level);
2442 else
2443 install_level = 1;
2445 /* ok hereis the _real_ rub
2446 * all these activation/deactivation things happen in order and things
2447 * later on the list override things earlier on the list.
2448 * 1) INSTALLLEVEL processing
2449 * 2) ADDLOCAL
2450 * 3) REMOVE
2451 * 4) ADDSOURCE
2452 * 5) ADDDEFAULT
2453 * 6) REINSTALL
2454 * 7) COMPADDLOCAL
2455 * 8) COMPADDSOURCE
2456 * 9) FILEADDLOCAL
2457 * 10) FILEADDSOURCE
2458 * 11) FILEADDDEFAULT
2459 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2460 * ignored for all the features. seems strange, especially since it is not
2461 * documented anywhere, but it is how it works.
2463 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2464 * REMOVE are the big ones, since we don't handle administrative installs
2465 * yet anyway.
2467 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
2468 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
2470 if (!override)
2472 for(i = 0; i < package->loaded_features; i++)
2474 BOOL feature_state = ((package->features[i].Level > 0) &&
2475 (package->features[i].Level <= install_level));
2477 if ((feature_state) &&
2478 (package->features[i].Action == INSTALLSTATE_UNKNOWN))
2480 if (package->features[i].Attributes &
2481 msidbFeatureAttributesFavorSource)
2483 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
2484 package->features[i].Action = INSTALLSTATE_SOURCE;
2486 else if (package->features[i].Attributes &
2487 msidbFeatureAttributesFavorAdvertise)
2489 package->features[i].ActionRequest =INSTALLSTATE_ADVERTISED;
2490 package->features[i].Action =INSTALLSTATE_ADVERTISED;
2492 else
2494 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
2495 package->features[i].Action = INSTALLSTATE_LOCAL;
2502 * now we want to enable or disable components base on feature
2505 for(i = 0; i < package->loaded_features; i++)
2507 MSIFEATURE* feature = &package->features[i];
2508 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2509 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2510 feature->ActionRequest);
2512 for( j = 0; j < feature->ComponentCount; j++)
2514 MSICOMPONENT* component = &package->components[
2515 feature->Components[j]];
2517 if (!component->Enabled)
2519 component->Action = INSTALLSTATE_UNKNOWN;
2520 component->ActionRequest = INSTALLSTATE_UNKNOWN;
2522 else
2524 if (feature->Action == INSTALLSTATE_LOCAL)
2526 component->Action = INSTALLSTATE_LOCAL;
2527 component->ActionRequest = INSTALLSTATE_LOCAL;
2529 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
2531 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2532 (component->Action == INSTALLSTATE_ABSENT) ||
2533 (component->Action == INSTALLSTATE_ADVERTISED))
2536 component->Action = INSTALLSTATE_SOURCE;
2537 component->ActionRequest = INSTALLSTATE_SOURCE;
2540 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
2542 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2543 (component->Action == INSTALLSTATE_ABSENT))
2546 component->Action = INSTALLSTATE_ADVERTISED;
2547 component->ActionRequest = INSTALLSTATE_ADVERTISED;
2550 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
2552 if (component->Action == INSTALLSTATE_UNKNOWN)
2554 component->Action = INSTALLSTATE_ABSENT;
2555 component->ActionRequest = INSTALLSTATE_ABSENT;
2562 for(i = 0; i < package->loaded_components; i++)
2564 MSICOMPONENT* component= &package->components[i];
2566 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2567 debugstr_w(component->Component), component->Installed,
2568 component->Action, component->ActionRequest);
2572 return ERROR_SUCCESS;
2576 * A lot is done in this function aside from just the costing.
2577 * The costing needs to be implemented at some point but for now I am going
2578 * to focus on the directory building
2581 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2583 static const WCHAR ExecSeqQuery[] =
2584 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2585 '`','D','i','r','e','c','t','o','r','y','`',0};
2586 static const WCHAR ConditionQuery[] =
2587 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2588 '`','C','o','n','d','i','t','i','o','n','`',0};
2589 static const WCHAR szCosting[] =
2590 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2591 static const WCHAR szlevel[] =
2592 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2593 static const WCHAR szOne[] = { '1', 0 };
2594 UINT rc;
2595 MSIQUERY * view;
2596 DWORD i;
2597 LPWSTR level;
2598 DWORD sz = 3;
2599 WCHAR buffer[3];
2601 MSI_GetPropertyW(package, szCosting, buffer, &sz);
2602 if (buffer[0]=='1')
2603 return ERROR_SUCCESS;
2605 TRACE("Building Directory properties\n");
2607 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2608 if (rc == ERROR_SUCCESS)
2610 rc = MSI_ViewExecute(view, 0);
2611 if (rc != ERROR_SUCCESS)
2613 MSI_ViewClose(view);
2614 msiobj_release(&view->hdr);
2615 return rc;
2618 while (1)
2620 WCHAR name[0x100];
2621 LPWSTR path;
2622 MSIRECORD * row = 0;
2623 DWORD sz;
2625 rc = MSI_ViewFetch(view,&row);
2626 if (rc != ERROR_SUCCESS)
2628 rc = ERROR_SUCCESS;
2629 break;
2632 sz=0x100;
2633 MSI_RecordGetStringW(row,1,name,&sz);
2635 /* This helper function now does ALL the work */
2636 TRACE("Dir %s ...\n",debugstr_w(name));
2637 load_folder(package,name);
2638 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2639 TRACE("resolves to %s\n",debugstr_w(path));
2640 HeapFree( GetProcessHeap(), 0, path);
2642 msiobj_release(&row->hdr);
2644 MSI_ViewClose(view);
2645 msiobj_release(&view->hdr);
2648 TRACE("File calculations %i files\n",package->loaded_files);
2650 for (i = 0; i < package->loaded_files; i++)
2652 MSICOMPONENT* comp = NULL;
2653 MSIFILE* file= NULL;
2655 file = &package->files[i];
2656 if (file->ComponentIndex >= 0)
2657 comp = &package->components[file->ComponentIndex];
2659 if (file->Temporary == TRUE)
2660 continue;
2662 if (comp)
2664 LPWSTR p;
2666 /* calculate target */
2667 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2669 HeapFree(GetProcessHeap(),0,file->TargetPath);
2671 TRACE("file %s is named %s\n",
2672 debugstr_w(file->File),debugstr_w(file->FileName));
2674 file->TargetPath = build_directory_name(2, p, file->FileName);
2676 HeapFree(GetProcessHeap(),0,p);
2678 TRACE("file %s resolves to %s\n",
2679 debugstr_w(file->File),debugstr_w(file->TargetPath));
2681 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2683 file->State = 1;
2684 comp->Cost += file->FileSize;
2686 else
2688 if (file->Version)
2690 DWORD handle;
2691 DWORD versize;
2692 UINT sz;
2693 LPVOID version;
2694 static const WCHAR name[] =
2695 {'\\',0};
2696 static const WCHAR name_fmt[] =
2697 {'%','u','.','%','u','.','%','u','.','%','u',0};
2698 WCHAR filever[0x100];
2699 VS_FIXEDFILEINFO *lpVer;
2701 TRACE("Version comparison.. \n");
2702 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2703 version = HeapAlloc(GetProcessHeap(),0,versize);
2704 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2706 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2708 sprintfW(filever,name_fmt,
2709 HIWORD(lpVer->dwFileVersionMS),
2710 LOWORD(lpVer->dwFileVersionMS),
2711 HIWORD(lpVer->dwFileVersionLS),
2712 LOWORD(lpVer->dwFileVersionLS));
2714 TRACE("new %s old %s\n", debugstr_w(file->Version),
2715 debugstr_w(filever));
2716 if (strcmpiW(filever,file->Version)<0)
2718 file->State = 2;
2719 FIXME("cost should be diff in size\n");
2720 comp->Cost += file->FileSize;
2722 else
2723 file->State = 3;
2724 HeapFree(GetProcessHeap(),0,version);
2726 else
2727 file->State = 3;
2732 TRACE("Evaluating Condition Table\n");
2734 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2735 if (rc == ERROR_SUCCESS)
2737 rc = MSI_ViewExecute(view, 0);
2738 if (rc != ERROR_SUCCESS)
2740 MSI_ViewClose(view);
2741 msiobj_release(&view->hdr);
2742 return rc;
2745 while (1)
2747 WCHAR Feature[0x100];
2748 MSIRECORD * row = 0;
2749 DWORD sz;
2750 int feature_index;
2752 rc = MSI_ViewFetch(view,&row);
2754 if (rc != ERROR_SUCCESS)
2756 rc = ERROR_SUCCESS;
2757 break;
2760 sz = 0x100;
2761 MSI_RecordGetStringW(row,1,Feature,&sz);
2763 feature_index = get_loaded_feature(package,Feature);
2764 if (feature_index < 0)
2765 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2766 else
2768 LPWSTR Condition;
2769 Condition = load_dynamic_stringW(row,3);
2771 if (MSI_EvaluateConditionW(package,Condition) ==
2772 MSICONDITION_TRUE)
2774 int level = MSI_RecordGetInteger(row,2);
2775 TRACE("Reseting feature %s to level %i\n",
2776 debugstr_w(Feature), level);
2777 package->features[feature_index].Level = level;
2779 HeapFree(GetProcessHeap(),0,Condition);
2782 msiobj_release(&row->hdr);
2784 MSI_ViewClose(view);
2785 msiobj_release(&view->hdr);
2788 TRACE("Enabling or Disabling Components\n");
2789 for (i = 0; i < package->loaded_components; i++)
2791 if (package->components[i].Condition[0])
2793 if (MSI_EvaluateConditionW(package,
2794 package->components[i].Condition) == MSICONDITION_FALSE)
2796 TRACE("Disabling component %s\n",
2797 debugstr_w(package->components[i].Component));
2798 package->components[i].Enabled = FALSE;
2803 MSI_SetPropertyW(package,szCosting,szOne);
2804 /* set default run level if not set */
2805 level = load_dynamic_property(package,szlevel,NULL);
2806 if (!level)
2807 MSI_SetPropertyW(package,szlevel, szOne);
2808 else
2809 HeapFree(GetProcessHeap(),0,level);
2811 ACTION_UpdateInstallStates(package);
2813 return SetFeatureStates(package);
2817 * This is a helper function for handling embedded cabinet media
2819 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2820 WCHAR* source)
2822 UINT rc;
2823 USHORT* data;
2824 UINT size;
2825 DWORD write;
2826 HANDLE the_file;
2827 WCHAR tmp[MAX_PATH];
2829 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2830 if (rc != ERROR_SUCCESS)
2831 return rc;
2833 write = MAX_PATH;
2834 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2835 GetTempPathW(MAX_PATH,tmp);
2837 GetTempFileNameW(tmp,stream_name,0,source);
2839 track_tempfile(package,strrchrW(source,'\\'), source);
2840 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2841 FILE_ATTRIBUTE_NORMAL, NULL);
2843 if (the_file == INVALID_HANDLE_VALUE)
2845 ERR("Unable to create file %s\n",debugstr_w(source));
2846 rc = ERROR_FUNCTION_FAILED;
2847 goto end;
2850 WriteFile(the_file,data,size,&write,NULL);
2851 CloseHandle(the_file);
2852 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2853 end:
2854 HeapFree(GetProcessHeap(),0,data);
2855 return rc;
2859 /* Support functions for FDI functions */
2860 typedef struct
2862 MSIPACKAGE* package;
2863 LPCSTR cab_path;
2864 LPCSTR file_name;
2865 } CabData;
2867 static void * cabinet_alloc(ULONG cb)
2869 return HeapAlloc(GetProcessHeap(), 0, cb);
2872 static void cabinet_free(void *pv)
2874 HeapFree(GetProcessHeap(), 0, pv);
2877 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2879 DWORD dwAccess = 0;
2880 DWORD dwShareMode = 0;
2881 DWORD dwCreateDisposition = OPEN_EXISTING;
2882 switch (oflag & _O_ACCMODE)
2884 case _O_RDONLY:
2885 dwAccess = GENERIC_READ;
2886 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2887 break;
2888 case _O_WRONLY:
2889 dwAccess = GENERIC_WRITE;
2890 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2891 break;
2892 case _O_RDWR:
2893 dwAccess = GENERIC_READ | GENERIC_WRITE;
2894 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2895 break;
2897 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2898 dwCreateDisposition = CREATE_NEW;
2899 else if (oflag & _O_CREAT)
2900 dwCreateDisposition = CREATE_ALWAYS;
2901 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
2902 dwCreateDisposition, 0, NULL);
2905 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2907 DWORD dwRead;
2908 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2909 return dwRead;
2910 return 0;
2913 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2915 DWORD dwWritten;
2916 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2917 return dwWritten;
2918 return 0;
2921 static int cabinet_close(INT_PTR hf)
2923 return CloseHandle((HANDLE)hf) ? 0 : -1;
2926 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2928 /* flags are compatible and so are passed straight through */
2929 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2932 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2934 /* FIXME: try to do more processing in this function */
2935 switch (fdint)
2937 case fdintCOPY_FILE:
2939 CabData *data = (CabData*) pfdin->pv;
2940 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2941 char *file;
2943 LPWSTR trackname;
2944 LPWSTR trackpath;
2945 LPWSTR tracknametmp;
2946 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2948 if (data->file_name && lstrcmpiA(data->file_name,pfdin->psz1))
2949 return 0;
2951 file = cabinet_alloc((len+1)*sizeof(char));
2952 strcpy(file, data->cab_path);
2953 strcat(file, pfdin->psz1);
2955 TRACE("file: %s\n", debugstr_a(file));
2957 /* track this file so it can be deleted if not installed */
2958 trackpath=strdupAtoW(file);
2959 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2960 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2961 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2963 strcpyW(trackname,tmpprefix);
2964 strcatW(trackname,tracknametmp);
2966 track_tempfile(data->package, trackname, trackpath);
2968 HeapFree(GetProcessHeap(),0,trackpath);
2969 HeapFree(GetProcessHeap(),0,trackname);
2970 HeapFree(GetProcessHeap(),0,tracknametmp);
2972 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2974 case fdintCLOSE_FILE_INFO:
2976 FILETIME ft;
2977 FILETIME ftLocal;
2978 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2979 return -1;
2980 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2981 return -1;
2982 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2983 return -1;
2985 cabinet_close(pfdin->hf);
2986 return 1;
2988 default:
2989 return 0;
2993 /***********************************************************************
2994 * extract_cabinet_file
2996 * Extract files from a cab file.
2998 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2999 const WCHAR* path, const WCHAR* file)
3001 HFDI hfdi;
3002 ERF erf;
3003 BOOL ret;
3004 char *cabinet;
3005 char *cab_path;
3006 char *file_name;
3007 CabData data;
3009 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
3010 debugstr_w(file), debugstr_w(path));
3012 hfdi = FDICreate(cabinet_alloc,
3013 cabinet_free,
3014 cabinet_open,
3015 cabinet_read,
3016 cabinet_write,
3017 cabinet_close,
3018 cabinet_seek,
3020 &erf);
3021 if (!hfdi)
3023 ERR("FDICreate failed\n");
3024 return FALSE;
3027 if (!(cabinet = strdupWtoA( source )))
3029 FDIDestroy(hfdi);
3030 return FALSE;
3032 if (!(cab_path = strdupWtoA( path )))
3034 FDIDestroy(hfdi);
3035 HeapFree(GetProcessHeap(), 0, cabinet);
3036 return FALSE;
3039 data.package = package;
3040 data.cab_path = cab_path;
3041 if (file)
3042 file_name = strdupWtoA(file);
3043 else
3044 file_name = NULL;
3045 data.file_name = file_name;
3047 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
3049 if (!ret)
3050 ERR("FDICopy failed\n");
3052 FDIDestroy(hfdi);
3054 HeapFree(GetProcessHeap(), 0, cabinet);
3055 HeapFree(GetProcessHeap(), 0, cab_path);
3056 HeapFree(GetProcessHeap(), 0, file_name);
3058 return ret;
3061 static UINT ready_media_for_file(MSIPACKAGE *package, WCHAR* path,
3062 MSIFILE* file)
3064 UINT rc = ERROR_SUCCESS;
3065 MSIRECORD * row = 0;
3066 static WCHAR source[MAX_PATH];
3067 static const WCHAR ExecSeqQuery[] =
3068 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3069 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3070 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
3071 ' ','%', 'i',' ','O','R','D','E','R',' ','B','Y',' ',
3072 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',0};
3073 WCHAR cab[0x100];
3074 DWORD sz=0x100;
3075 INT seq;
3076 static UINT last_sequence = 0;
3078 if (file->Attributes & msidbFileAttributesNoncompressed)
3080 TRACE("Uncompressed File, no media to ready.\n");
3081 return ERROR_SUCCESS;
3084 if (file->Sequence <= last_sequence)
3086 TRACE("Media already ready (%u, %u)\n",file->Sequence,last_sequence);
3087 /*extract_a_cabinet_file(package, source,path,file->File); */
3088 return ERROR_SUCCESS;
3091 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, file->Sequence);
3092 if (!row)
3093 return ERROR_FUNCTION_FAILED;
3095 seq = MSI_RecordGetInteger(row,2);
3096 last_sequence = seq;
3098 if (!MSI_RecordIsNull(row,4))
3100 sz=0x100;
3101 MSI_RecordGetStringW(row,4,cab,&sz);
3102 TRACE("Source is CAB %s\n",debugstr_w(cab));
3103 /* the stream does not contain the # character */
3104 if (cab[0]=='#')
3106 writeout_cabinet_stream(package,&cab[1],source);
3107 strcpyW(path,source);
3108 *(strrchrW(path,'\\')+1)=0;
3110 else
3112 sz = MAX_PATH;
3113 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
3115 ERR("No Source dir defined \n");
3116 rc = ERROR_FUNCTION_FAILED;
3118 else
3120 strcpyW(path,source);
3121 strcatW(source,cab);
3122 /* extract the cab file into a folder in the temp folder */
3123 sz = MAX_PATH;
3124 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
3125 != ERROR_SUCCESS)
3126 GetTempPathW(MAX_PATH,path);
3129 rc = !extract_a_cabinet_file(package, source,path,NULL);
3131 else
3133 sz = MAX_PATH;
3134 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
3135 strcpyW(path,source);
3137 msiobj_release(&row->hdr);
3138 return rc;
3141 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
3143 UINT rc = ERROR_SUCCESS;
3144 MSIFOLDER *folder;
3145 LPWSTR install_path;
3147 install_path = resolve_folder(package, package->components[component].Directory,
3148 FALSE, FALSE, &folder);
3149 if (!install_path)
3150 return ERROR_FUNCTION_FAILED;
3152 /* create the path */
3153 if (folder->State == 0)
3155 create_full_pathW(install_path);
3156 folder->State = 2;
3158 HeapFree(GetProcessHeap(), 0, install_path);
3160 return rc;
3163 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3165 UINT rc = ERROR_SUCCESS;
3166 DWORD index;
3167 MSIRECORD * uirow;
3168 WCHAR uipath[MAX_PATH];
3170 if (!package)
3171 return ERROR_INVALID_HANDLE;
3173 /* increment progress bar each time action data is sent */
3174 ui_progress(package,1,1,0,0);
3176 for (index = 0; index < package->loaded_files; index++)
3178 WCHAR path_to_source[MAX_PATH];
3179 MSIFILE *file;
3181 file = &package->files[index];
3183 if (file->Temporary)
3184 continue;
3187 if (!ACTION_VerifyComponentForAction(package, file->ComponentIndex,
3188 INSTALLSTATE_LOCAL))
3190 ui_progress(package,2,file->FileSize,0,0);
3191 TRACE("File %s is not scheduled for install\n",
3192 debugstr_w(file->File));
3194 continue;
3197 if ((file->State == 1) || (file->State == 2))
3199 LPWSTR p;
3200 MSICOMPONENT* comp = NULL;
3202 TRACE("Installing %s\n",debugstr_w(file->File));
3203 rc = ready_media_for_file(package, path_to_source, file);
3205 * WARNING!
3206 * our file table could change here because a new temp file
3207 * may have been created
3209 file = &package->files[index];
3210 if (rc != ERROR_SUCCESS)
3212 ERR("Unable to ready media\n");
3213 rc = ERROR_FUNCTION_FAILED;
3214 break;
3217 create_component_directory( package, file->ComponentIndex);
3219 /* recalculate file paths because things may have changed */
3221 if (file->ComponentIndex >= 0)
3222 comp = &package->components[file->ComponentIndex];
3224 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3225 HeapFree(GetProcessHeap(),0,file->TargetPath);
3227 file->TargetPath = build_directory_name(2, p, file->FileName);
3228 HeapFree(GetProcessHeap(),0,p);
3230 if (file->Attributes & msidbFileAttributesNoncompressed)
3232 p = resolve_folder(package, comp->Directory, TRUE, FALSE, NULL);
3233 file->SourcePath = build_directory_name(2, p, file->ShortName);
3234 HeapFree(GetProcessHeap(),0,p);
3236 else
3237 file->SourcePath = build_directory_name(2, path_to_source,
3238 file->File);
3241 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3242 debugstr_w(file->TargetPath));
3244 /* the UI chunk */
3245 uirow=MSI_CreateRecord(9);
3246 MSI_RecordSetStringW(uirow,1,file->File);
3247 strcpyW(uipath,file->TargetPath);
3248 *(strrchrW(uipath,'\\')+1)=0;
3249 MSI_RecordSetStringW(uirow,9,uipath);
3250 MSI_RecordSetInteger(uirow,6,file->FileSize);
3251 ui_actiondata(package,szInstallFiles,uirow);
3252 msiobj_release( &uirow->hdr );
3253 ui_progress(package,2,file->FileSize,0,0);
3256 if (file->Attributes & msidbFileAttributesNoncompressed)
3257 rc = CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3258 else
3259 rc = MoveFileW(file->SourcePath, file->TargetPath);
3261 if (!rc)
3263 rc = GetLastError();
3264 ERR("Unable to move/copy file (%s -> %s) (error %d)\n",
3265 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3266 rc);
3267 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3269 if (!CopyFileW(file->SourcePath,file->TargetPath,FALSE))
3270 ERR("Unable to copy file (%s -> %s) (error %ld)\n",
3271 debugstr_w(file->SourcePath),
3272 debugstr_w(file->TargetPath), GetLastError());
3273 if (!(file->Attributes & msidbFileAttributesNoncompressed))
3274 DeleteFileW(file->SourcePath);
3275 rc = 0;
3277 else if (rc == ERROR_FILE_NOT_FOUND)
3279 ERR("Source File Not Found! Continuing\n");
3280 rc = 0;
3282 else if (file->Attributes & msidbFileAttributesVital)
3284 ERR("Ignoring Error and continuing (nonvital file)...\n");
3285 rc = 0;
3288 else
3290 file->State = 4;
3291 rc = ERROR_SUCCESS;
3296 return rc;
3299 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3300 LPWSTR* file_source)
3302 DWORD index;
3304 if (!package)
3305 return ERROR_INVALID_HANDLE;
3307 for (index = 0; index < package->loaded_files; index ++)
3309 if (strcmpW(file_key,package->files[index].File)==0)
3311 if (package->files[index].State >= 2)
3313 *file_source = strdupW(package->files[index].TargetPath);
3314 return ERROR_SUCCESS;
3316 else
3317 return ERROR_FILE_NOT_FOUND;
3321 return ERROR_FUNCTION_FAILED;
3324 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3326 UINT rc;
3327 MSIQUERY * view;
3328 MSIRECORD * row = 0;
3329 static const WCHAR ExecSeqQuery[] =
3330 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3331 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
3333 if (!package)
3334 return ERROR_INVALID_HANDLE;
3336 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3337 if (rc != ERROR_SUCCESS)
3338 return ERROR_SUCCESS;
3340 rc = MSI_ViewExecute(view, 0);
3341 if (rc != ERROR_SUCCESS)
3343 MSI_ViewClose(view);
3344 msiobj_release(&view->hdr);
3345 return rc;
3348 while (1)
3350 WCHAR file_key[0x100];
3351 WCHAR *file_source = NULL;
3352 WCHAR dest_name[0x100];
3353 LPWSTR dest_path, dest;
3354 WCHAR component[0x100];
3355 INT component_index;
3357 DWORD sz=0x100;
3359 rc = MSI_ViewFetch(view,&row);
3360 if (rc != ERROR_SUCCESS)
3362 rc = ERROR_SUCCESS;
3363 break;
3366 sz=0x100;
3367 rc = MSI_RecordGetStringW(row,2,component,&sz);
3368 if (rc != ERROR_SUCCESS)
3370 ERR("Unable to get component\n");
3371 msiobj_release(&row->hdr);
3372 break;
3375 component_index = get_loaded_component(package,component);
3377 if (!ACTION_VerifyComponentForAction(package, component_index,
3378 INSTALLSTATE_LOCAL))
3380 TRACE("Skipping copy due to disabled component\n");
3382 /* the action taken was the same as the current install state */
3383 package->components[component_index].Action =
3384 package->components[component_index].Installed;
3386 msiobj_release(&row->hdr);
3387 continue;
3390 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3392 sz=0x100;
3393 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3394 if (rc != ERROR_SUCCESS)
3396 ERR("Unable to get file key\n");
3397 msiobj_release(&row->hdr);
3398 break;
3401 rc = get_file_target(package,file_key,&file_source);
3403 if (rc != ERROR_SUCCESS)
3405 ERR("Original file unknown %s\n",debugstr_w(file_key));
3406 msiobj_release(&row->hdr);
3407 HeapFree(GetProcessHeap(),0,file_source);
3408 continue;
3411 if (MSI_RecordIsNull(row,4))
3413 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3415 else
3417 sz=0x100;
3418 MSI_RecordGetStringW(row,4,dest_name,&sz);
3419 reduce_to_longfilename(dest_name);
3422 if (MSI_RecordIsNull(row,5))
3424 LPWSTR p;
3425 dest_path = strdupW(file_source);
3426 p = strrchrW(dest_path,'\\');
3427 if (p)
3428 *p=0;
3430 else
3432 WCHAR destkey[0x100];
3433 sz=0x100;
3434 MSI_RecordGetStringW(row,5,destkey,&sz);
3435 sz = 0x100;
3436 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3437 if (!dest_path)
3439 ERR("Unable to get destination folder\n");
3440 msiobj_release(&row->hdr);
3441 HeapFree(GetProcessHeap(),0,file_source);
3442 break;
3446 dest = build_directory_name(2, dest_path, dest_name);
3448 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3449 debugstr_w(dest));
3451 if (strcmpW(file_source,dest))
3452 rc = !CopyFileW(file_source,dest,TRUE);
3453 else
3454 rc = ERROR_SUCCESS;
3456 if (rc != ERROR_SUCCESS)
3457 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
3459 FIXME("We should track these duplicate files as well\n");
3461 msiobj_release(&row->hdr);
3462 HeapFree(GetProcessHeap(),0,dest_path);
3463 HeapFree(GetProcessHeap(),0,dest);
3464 HeapFree(GetProcessHeap(),0,file_source);
3466 MSI_ViewClose(view);
3467 msiobj_release(&view->hdr);
3468 return rc;
3472 /* OK this value is "interpreted" and then formatted based on the
3473 first few characters */
3474 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3475 DWORD *size)
3477 LPSTR data = NULL;
3478 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3480 if (value[1]=='x')
3482 LPWSTR ptr;
3483 CHAR byte[5];
3484 LPWSTR deformated = NULL;
3485 int count;
3487 deformat_string(package, &value[2], &deformated);
3489 /* binary value type */
3490 ptr = deformated;
3491 *type = REG_BINARY;
3492 if (strlenW(ptr)%2)
3493 *size = (strlenW(ptr)/2)+1;
3494 else
3495 *size = strlenW(ptr)/2;
3497 data = HeapAlloc(GetProcessHeap(),0,*size);
3499 byte[0] = '0';
3500 byte[1] = 'x';
3501 byte[4] = 0;
3502 count = 0;
3503 /* if uneven pad with a zero in front */
3504 if (strlenW(ptr)%2)
3506 byte[2]= '0';
3507 byte[3]= *ptr;
3508 ptr++;
3509 data[count] = (BYTE)strtol(byte,NULL,0);
3510 count ++;
3511 TRACE("Uneven byte count\n");
3513 while (*ptr)
3515 byte[2]= *ptr;
3516 ptr++;
3517 byte[3]= *ptr;
3518 ptr++;
3519 data[count] = (BYTE)strtol(byte,NULL,0);
3520 count ++;
3522 HeapFree(GetProcessHeap(),0,deformated);
3524 TRACE("Data %li bytes(%i)\n",*size,count);
3526 else
3528 LPWSTR deformated;
3529 LPWSTR p;
3530 DWORD d = 0;
3531 deformat_string(package, &value[1], &deformated);
3533 *type=REG_DWORD;
3534 *size = sizeof(DWORD);
3535 data = HeapAlloc(GetProcessHeap(),0,*size);
3536 p = deformated;
3537 if (*p == '-')
3538 p++;
3539 while (*p)
3541 if ( (*p < '0') || (*p > '9') )
3542 break;
3543 d *= 10;
3544 d += (*p - '0');
3545 p++;
3547 if (deformated[0] == '-')
3548 d = -d;
3549 *(LPDWORD)data = d;
3550 TRACE("DWORD %li\n",*(LPDWORD)data);
3552 HeapFree(GetProcessHeap(),0,deformated);
3555 else
3557 static const WCHAR szMulti[] = {'[','~',']',0};
3558 WCHAR *ptr;
3559 *type=REG_SZ;
3561 if (value[0]=='#')
3563 if (value[1]=='%')
3565 ptr = &value[2];
3566 *type=REG_EXPAND_SZ;
3568 else
3569 ptr = &value[1];
3571 else
3572 ptr=value;
3574 if (strstrW(value,szMulti))
3575 *type = REG_MULTI_SZ;
3577 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3579 return data;
3582 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3584 UINT rc;
3585 MSIQUERY * view;
3586 MSIRECORD * row = 0;
3587 static const WCHAR ExecSeqQuery[] =
3588 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3589 '`','R','e','g','i','s','t','r','y','`',0 };
3591 if (!package)
3592 return ERROR_INVALID_HANDLE;
3594 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3595 if (rc != ERROR_SUCCESS)
3596 return ERROR_SUCCESS;
3598 rc = MSI_ViewExecute(view, 0);
3599 if (rc != ERROR_SUCCESS)
3601 MSI_ViewClose(view);
3602 msiobj_release(&view->hdr);
3603 return rc;
3606 /* increment progress bar each time action data is sent */
3607 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3609 while (1)
3611 static const WCHAR szHCR[] =
3612 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3613 'R','O','O','T','\\',0};
3614 static const WCHAR szHCU[] =
3615 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3616 'U','S','E','R','\\',0};
3617 static const WCHAR szHLM[] =
3618 {'H','K','E','Y','_','L','O','C','A','L','_',
3619 'M','A','C','H','I','N','E','\\',0};
3620 static const WCHAR szHU[] =
3621 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3623 LPSTR value_data = NULL;
3624 HKEY root_key, hkey;
3625 DWORD type,size;
3626 LPWSTR value, key, name, component, deformated;
3627 LPCWSTR szRoot;
3628 INT component_index;
3629 MSIRECORD * uirow;
3630 LPWSTR uikey;
3631 INT root;
3632 BOOL check_first = FALSE;
3634 rc = MSI_ViewFetch(view,&row);
3635 if (rc != ERROR_SUCCESS)
3637 rc = ERROR_SUCCESS;
3638 break;
3640 ui_progress(package,2,0,0,0);
3642 value = NULL;
3643 key = NULL;
3644 uikey = NULL;
3645 name = NULL;
3647 component = load_dynamic_stringW(row, 6);
3648 component_index = get_loaded_component(package,component);
3650 if (!ACTION_VerifyComponentForAction(package, component_index,
3651 INSTALLSTATE_LOCAL))
3653 TRACE("Skipping write due to disabled component\n");
3654 msiobj_release(&row->hdr);
3656 package->components[component_index].Action =
3657 package->components[component_index].Installed;
3659 goto next;
3662 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3664 name = load_dynamic_stringW(row, 4);
3665 if( MSI_RecordIsNull(row,5) && name )
3667 /* null values can have special meanings */
3668 if (name[0]=='-' && name[1] == 0)
3670 msiobj_release(&row->hdr);
3671 goto next;
3673 else if ((name[0]=='+' && name[1] == 0) ||
3674 (name[0] == '*' && name[1] == 0))
3676 HeapFree(GetProcessHeap(),0,name);
3677 name = NULL;
3678 check_first = TRUE;
3682 root = MSI_RecordGetInteger(row,2);
3683 key = load_dynamic_stringW(row, 3);
3686 /* get the root key */
3687 switch (root)
3689 case 0: root_key = HKEY_CLASSES_ROOT;
3690 szRoot = szHCR;
3691 break;
3692 case 1: root_key = HKEY_CURRENT_USER;
3693 szRoot = szHCU;
3694 break;
3695 case 2: root_key = HKEY_LOCAL_MACHINE;
3696 szRoot = szHLM;
3697 break;
3698 case 3: root_key = HKEY_USERS;
3699 szRoot = szHU;
3700 break;
3701 default:
3702 ERR("Unknown root %i\n",root);
3703 root_key=NULL;
3704 szRoot = NULL;
3705 break;
3707 if (!root_key)
3709 msiobj_release(&row->hdr);
3710 goto next;
3713 deformat_string(package, key , &deformated);
3714 size = strlenW(deformated) + strlenW(szRoot) + 1;
3715 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3716 strcpyW(uikey,szRoot);
3717 strcatW(uikey,deformated);
3719 if (RegCreateKeyW( root_key, deformated, &hkey))
3721 ERR("Could not create key %s\n",debugstr_w(deformated));
3722 msiobj_release(&row->hdr);
3723 HeapFree(GetProcessHeap(),0,deformated);
3724 goto next;
3726 HeapFree(GetProcessHeap(),0,deformated);
3728 value = load_dynamic_stringW(row,5);
3729 if (value)
3730 value_data = parse_value(package, value, &type, &size);
3731 else
3733 static const WCHAR szEmpty[] = {0};
3734 value_data = (LPSTR)strdupW(szEmpty);
3735 size = 0;
3736 type = REG_SZ;
3739 deformat_string(package, name, &deformated);
3741 /* get the double nulls to terminate SZ_MULTI */
3742 if (type == REG_MULTI_SZ)
3743 size +=sizeof(WCHAR);
3745 if (!check_first)
3747 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
3748 debugstr_w(uikey));
3749 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3751 else
3753 DWORD sz = 0;
3754 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
3755 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3757 TRACE("value %s of %s checked already exists\n",
3758 debugstr_w(deformated), debugstr_w(uikey));
3760 else
3762 TRACE("Checked and setting value %s of %s\n",
3763 debugstr_w(deformated), debugstr_w(uikey));
3764 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3768 uirow = MSI_CreateRecord(3);
3769 MSI_RecordSetStringW(uirow,2,deformated);
3770 MSI_RecordSetStringW(uirow,1,uikey);
3772 if (type == REG_SZ)
3773 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3774 else
3775 MSI_RecordSetStringW(uirow,3,value);
3777 ui_actiondata(package,szWriteRegistryValues,uirow);
3778 msiobj_release( &uirow->hdr );
3780 HeapFree(GetProcessHeap(),0,value_data);
3781 HeapFree(GetProcessHeap(),0,value);
3782 HeapFree(GetProcessHeap(),0,deformated);
3784 msiobj_release(&row->hdr);
3785 RegCloseKey(hkey);
3786 next:
3787 HeapFree(GetProcessHeap(),0,uikey);
3788 HeapFree(GetProcessHeap(),0,key);
3789 HeapFree(GetProcessHeap(),0,name);
3790 HeapFree(GetProcessHeap(),0,component);
3792 MSI_ViewClose(view);
3793 msiobj_release(&view->hdr);
3794 return rc;
3797 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3799 package->script->CurrentlyScripting = TRUE;
3801 return ERROR_SUCCESS;
3805 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3807 DWORD progress = 0;
3808 DWORD total = 0;
3809 static const WCHAR q1[]=
3810 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3811 '`','R','e','g','i','s','t','r','y','`',0};
3812 UINT rc;
3813 MSIQUERY * view;
3814 MSIRECORD * row = 0;
3815 int i;
3817 TRACE(" InstallValidate \n");
3819 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3820 if (rc != ERROR_SUCCESS)
3821 return ERROR_SUCCESS;
3823 rc = MSI_ViewExecute(view, 0);
3824 if (rc != ERROR_SUCCESS)
3826 MSI_ViewClose(view);
3827 msiobj_release(&view->hdr);
3828 return rc;
3830 while (1)
3832 rc = MSI_ViewFetch(view,&row);
3833 if (rc != ERROR_SUCCESS)
3835 rc = ERROR_SUCCESS;
3836 break;
3838 progress +=1;
3840 msiobj_release(&row->hdr);
3842 MSI_ViewClose(view);
3843 msiobj_release(&view->hdr);
3845 total = total + progress * REG_PROGRESS_VALUE;
3846 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3847 for (i=0; i < package->loaded_files; i++)
3848 total += package->files[i].FileSize;
3849 ui_progress(package,0,total,0,0);
3851 for(i = 0; i < package->loaded_features; i++)
3853 MSIFEATURE* feature = &package->features[i];
3854 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
3855 debugstr_w(feature->Feature), feature->Installed, feature->Action,
3856 feature->ActionRequest);
3859 return ERROR_SUCCESS;
3862 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3864 UINT rc;
3865 MSIQUERY * view = NULL;
3866 MSIRECORD * row = 0;
3867 static const WCHAR ExecSeqQuery[] =
3868 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3869 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
3870 static const WCHAR title[]=
3871 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3873 TRACE("Checking launch conditions\n");
3875 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3876 if (rc != ERROR_SUCCESS)
3877 return ERROR_SUCCESS;
3879 rc = MSI_ViewExecute(view, 0);
3880 if (rc != ERROR_SUCCESS)
3882 MSI_ViewClose(view);
3883 msiobj_release(&view->hdr);
3884 return rc;
3887 rc = ERROR_SUCCESS;
3888 while (rc == ERROR_SUCCESS)
3890 LPWSTR cond = NULL;
3891 LPWSTR message = NULL;
3893 rc = MSI_ViewFetch(view,&row);
3894 if (rc != ERROR_SUCCESS)
3896 rc = ERROR_SUCCESS;
3897 break;
3900 cond = load_dynamic_stringW(row,1);
3902 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3904 LPWSTR deformated;
3905 message = load_dynamic_stringW(row,2);
3906 deformat_string(package,message,&deformated);
3907 MessageBoxW(NULL,deformated,title,MB_OK);
3908 HeapFree(GetProcessHeap(),0,message);
3909 HeapFree(GetProcessHeap(),0,deformated);
3910 rc = ERROR_FUNCTION_FAILED;
3912 HeapFree(GetProcessHeap(),0,cond);
3913 msiobj_release(&row->hdr);
3915 MSI_ViewClose(view);
3916 msiobj_release(&view->hdr);
3917 return rc;
3920 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3921 component_index)
3923 MSICOMPONENT* cmp = &package->components[component_index];
3925 if (cmp->KeyPath[0]==0)
3927 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3928 return p;
3930 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
3932 MSIRECORD * row = 0;
3933 UINT root,len;
3934 LPWSTR key,deformated,buffer,name,deformated_name;
3935 static const WCHAR ExecSeqQuery[] =
3936 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3937 '`','R','e','g','i','s','t','r','y','`',' ',
3938 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
3939 ' ','=',' ' ,'\'','%','s','\'',0 };
3940 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
3941 static const WCHAR fmt2[]=
3942 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3944 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
3945 if (!row)
3946 return NULL;
3948 root = MSI_RecordGetInteger(row,2);
3949 key = load_dynamic_stringW(row, 3);
3950 name = load_dynamic_stringW(row, 4);
3951 deformat_string(package, key , &deformated);
3952 deformat_string(package, name, &deformated_name);
3954 len = strlenW(deformated) + 6;
3955 if (deformated_name)
3956 len+=strlenW(deformated_name);
3958 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3960 if (deformated_name)
3961 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3962 else
3963 sprintfW(buffer,fmt,root,deformated);
3965 HeapFree(GetProcessHeap(),0,key);
3966 HeapFree(GetProcessHeap(),0,deformated);
3967 HeapFree(GetProcessHeap(),0,name);
3968 HeapFree(GetProcessHeap(),0,deformated_name);
3969 msiobj_release(&row->hdr);
3971 return buffer;
3973 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
3975 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3976 return NULL;
3978 else
3980 int j;
3981 j = get_loaded_file(package,cmp->KeyPath);
3983 if (j>=0)
3985 LPWSTR p = strdupW(package->files[j].TargetPath);
3986 return p;
3989 return NULL;
3992 static HKEY openSharedDLLsKey()
3994 HKEY hkey=0;
3995 static const WCHAR path[] =
3996 {'S','o','f','t','w','a','r','e','\\',
3997 'M','i','c','r','o','s','o','f','t','\\',
3998 'W','i','n','d','o','w','s','\\',
3999 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4000 'S','h','a','r','e','d','D','L','L','s',0};
4002 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
4003 return hkey;
4006 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
4008 HKEY hkey;
4009 DWORD count=0;
4010 DWORD type;
4011 DWORD sz = sizeof(count);
4012 DWORD rc;
4014 hkey = openSharedDLLsKey();
4015 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
4016 if (rc != ERROR_SUCCESS)
4017 count = 0;
4018 RegCloseKey(hkey);
4019 return count;
4022 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
4024 HKEY hkey;
4026 hkey = openSharedDLLsKey();
4027 if (count > 0)
4028 RegSetValueExW(hkey,path,0,REG_DWORD,
4029 (LPBYTE)&count,sizeof(count));
4030 else
4031 RegDeleteValueW(hkey,path);
4032 RegCloseKey(hkey);
4033 return count;
4037 * Return TRUE if the count should be written out and FALSE if not
4039 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
4041 INT count = 0;
4042 BOOL write = FALSE;
4043 INT j;
4045 /* only refcount DLLs */
4046 if (package->components[index].KeyPath[0]==0 ||
4047 package->components[index].Attributes &
4048 msidbComponentAttributesRegistryKeyPath ||
4049 package->components[index].Attributes &
4050 msidbComponentAttributesODBCDataSource)
4051 write = FALSE;
4052 else
4054 count = ACTION_GetSharedDLLsCount(package->components[index].
4055 FullKeypath);
4056 write = (count > 0);
4058 if (package->components[index].Attributes &
4059 msidbComponentAttributesSharedDllRefCount)
4060 write = TRUE;
4063 /* increment counts */
4064 for (j = 0; j < package->loaded_features; j++)
4066 int i;
4068 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
4069 continue;
4071 for (i = 0; i < package->features[j].ComponentCount; i++)
4073 if (package->features[j].Components[i] == index)
4074 count++;
4077 /* decrement counts */
4078 for (j = 0; j < package->loaded_features; j++)
4080 int i;
4081 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
4082 continue;
4084 for (i = 0; i < package->features[j].ComponentCount; i++)
4086 if (package->features[j].Components[i] == index)
4087 count--;
4091 /* ref count all the files in the component */
4092 if (write)
4093 for (j = 0; j < package->loaded_files; j++)
4095 if (package->files[j].Temporary)
4096 continue;
4097 if (package->files[j].ComponentIndex == index)
4098 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
4101 /* add a count for permenent */
4102 if (package->components[index].Attributes &
4103 msidbComponentAttributesPermanent)
4104 count ++;
4106 package->components[index].RefCount = count;
4108 if (write)
4109 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
4110 package->components[index].RefCount);
4114 * Ok further analysis makes me think that this work is
4115 * actually done in the PublishComponents and PublishFeatures
4116 * step, and not here. It appears like the keypath and all that is
4117 * resolved in this step, however actually written in the Publish steps.
4118 * But we will leave it here for now because it is unclear
4120 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
4122 LPWSTR productcode;
4123 WCHAR squished_pc[GUID_SIZE];
4124 WCHAR squished_cc[GUID_SIZE];
4125 UINT rc;
4126 DWORD i;
4127 HKEY hkey=0,hkey2=0;
4129 if (!package)
4130 return ERROR_INVALID_HANDLE;
4132 /* writes the Component and Features values to the registry */
4133 productcode = load_dynamic_property(package,szProductCode,&rc);
4134 if (!productcode)
4135 return rc;
4137 rc = MSIREG_OpenComponents(&hkey);
4138 if (rc != ERROR_SUCCESS)
4139 goto end;
4141 squash_guid(productcode,squished_pc);
4142 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
4143 for (i = 0; i < package->loaded_components; i++)
4145 ui_progress(package,2,0,0,0);
4146 if (package->components[i].ComponentId[0]!=0)
4148 WCHAR *keypath = NULL;
4149 MSIRECORD * uirow;
4151 squash_guid(package->components[i].ComponentId,squished_cc);
4153 keypath = resolve_keypath(package,i);
4154 package->components[i].FullKeypath = keypath;
4156 /* do the refcounting */
4157 ACTION_RefCountComponent( package, i);
4159 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
4160 debugstr_w(package->components[i].Component),
4161 debugstr_w(squished_cc),
4162 debugstr_w(package->components[i].FullKeypath),
4163 package->components[i].RefCount);
4165 * Write the keypath out if the component is to be registered
4166 * and delete the key if the component is to be deregistered
4168 if (ACTION_VerifyComponentForAction(package, i,
4169 INSTALLSTATE_LOCAL))
4171 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
4172 if (rc != ERROR_SUCCESS)
4173 continue;
4175 if (keypath)
4177 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
4178 (strlenW(keypath)+1)*sizeof(WCHAR));
4180 if (package->components[i].Attributes &
4181 msidbComponentAttributesPermanent)
4183 static const WCHAR szPermKey[] =
4184 { '0','0','0','0','0','0','0','0','0','0','0','0',
4185 '0','0','0','0','0','0','0', '0','0','0','0','0',
4186 '0','0','0','0','0','0','0','0',0};
4188 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
4189 (LPVOID)keypath,
4190 (strlenW(keypath)+1)*sizeof(WCHAR));
4193 RegCloseKey(hkey2);
4195 /* UI stuff */
4196 uirow = MSI_CreateRecord(3);
4197 MSI_RecordSetStringW(uirow,1,productcode);
4198 MSI_RecordSetStringW(uirow,2,package->components[i].
4199 ComponentId);
4200 MSI_RecordSetStringW(uirow,3,keypath);
4201 ui_actiondata(package,szProcessComponents,uirow);
4202 msiobj_release( &uirow->hdr );
4205 else if (ACTION_VerifyComponentForAction(package, i,
4206 INSTALLSTATE_ABSENT))
4208 DWORD res;
4210 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
4211 if (rc != ERROR_SUCCESS)
4212 continue;
4214 RegDeleteValueW(hkey2,squished_pc);
4216 /* if the key is empty delete it */
4217 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
4218 RegCloseKey(hkey2);
4219 if (res == ERROR_NO_MORE_ITEMS)
4220 RegDeleteKeyW(hkey,squished_cc);
4222 /* UI stuff */
4223 uirow = MSI_CreateRecord(2);
4224 MSI_RecordSetStringW(uirow,1,productcode);
4225 MSI_RecordSetStringW(uirow,2,package->components[i].
4226 ComponentId);
4227 ui_actiondata(package,szProcessComponents,uirow);
4228 msiobj_release( &uirow->hdr );
4232 end:
4233 HeapFree(GetProcessHeap(), 0, productcode);
4234 RegCloseKey(hkey);
4235 return rc;
4238 typedef struct {
4239 CLSID clsid;
4240 LPWSTR source;
4242 LPWSTR path;
4243 ITypeLib *ptLib;
4244 } typelib_struct;
4246 BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
4247 LPWSTR lpszName, LONG_PTR lParam)
4249 TLIBATTR *attr;
4250 typelib_struct *tl_struct = (typelib_struct*) lParam;
4251 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
4252 int sz;
4253 HRESULT res;
4255 if (!IS_INTRESOURCE(lpszName))
4257 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
4258 return TRUE;
4261 sz = strlenW(tl_struct->source)+4;
4262 sz *= sizeof(WCHAR);
4264 if ((INT)lpszName == 1)
4265 tl_struct->path = strdupW(tl_struct->source);
4266 else
4268 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
4269 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
4272 TRACE("trying %s\n", debugstr_w(tl_struct->path));
4273 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
4274 if (!SUCCEEDED(res))
4276 HeapFree(GetProcessHeap(),0,tl_struct->path);
4277 tl_struct->path = NULL;
4279 return TRUE;
4282 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
4283 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
4285 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4286 return FALSE;
4289 HeapFree(GetProcessHeap(),0,tl_struct->path);
4290 tl_struct->path = NULL;
4292 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4293 ITypeLib_Release(tl_struct->ptLib);
4295 return TRUE;
4298 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4301 * OK this is a bit confusing.. I am given a _Component key and I believe
4302 * that the file that is being registered as a type library is the "key file
4303 * of that component" which I interpret to mean "The file in the KeyPath of
4304 * that component".
4306 UINT rc;
4307 MSIQUERY * view;
4308 MSIRECORD * row = 0;
4309 static const WCHAR Query[] =
4310 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4311 '`','T','y','p','e','L','i','b','`',0};
4313 if (!package)
4314 return ERROR_INVALID_HANDLE;
4316 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4317 if (rc != ERROR_SUCCESS)
4318 return ERROR_SUCCESS;
4320 rc = MSI_ViewExecute(view, 0);
4321 if (rc != ERROR_SUCCESS)
4323 MSI_ViewClose(view);
4324 msiobj_release(&view->hdr);
4325 return rc;
4328 while (1)
4330 WCHAR component[0x100];
4331 DWORD sz;
4332 INT index;
4333 LPWSTR guid;
4334 typelib_struct tl_struct;
4335 HMODULE module;
4336 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
4338 rc = MSI_ViewFetch(view,&row);
4339 if (rc != ERROR_SUCCESS)
4341 rc = ERROR_SUCCESS;
4342 break;
4345 sz = 0x100;
4346 MSI_RecordGetStringW(row,3,component,&sz);
4348 index = get_loaded_component(package,component);
4349 if (index < 0)
4351 msiobj_release(&row->hdr);
4352 continue;
4355 if (!ACTION_VerifyComponentForAction(package, index,
4356 INSTALLSTATE_LOCAL))
4358 TRACE("Skipping typelib reg due to disabled component\n");
4359 msiobj_release(&row->hdr);
4361 package->components[index].Action =
4362 package->components[index].Installed;
4364 continue;
4367 package->components[index].Action = INSTALLSTATE_LOCAL;
4369 index = get_loaded_file(package,package->components[index].KeyPath);
4371 if (index < 0)
4373 msiobj_release(&row->hdr);
4374 continue;
4377 guid = load_dynamic_stringW(row,1);
4378 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
4379 LOAD_LIBRARY_AS_DATAFILE);
4380 if (module != NULL)
4382 CLSIDFromString(guid, &tl_struct.clsid);
4383 tl_struct.source = strdupW(package->files[index].TargetPath);
4384 tl_struct.path = NULL;
4386 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
4387 (LONG_PTR)&tl_struct);
4389 if (tl_struct.path != NULL)
4391 LPWSTR help;
4392 WCHAR helpid[0x100];
4393 HRESULT res;
4395 sz = 0x100;
4396 MSI_RecordGetStringW(row,6,helpid,&sz);
4398 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4399 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
4400 HeapFree(GetProcessHeap(),0,help);
4402 if (!SUCCEEDED(res))
4403 ERR("Failed to register type library %s\n",
4404 debugstr_w(tl_struct.path));
4405 else
4407 ui_actiondata(package,szRegisterTypeLibraries,row);
4409 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
4412 ITypeLib_Release(tl_struct.ptLib);
4413 HeapFree(GetProcessHeap(),0,tl_struct.path);
4415 else
4416 ERR("Failed to load type library %s\n",
4417 debugstr_w(tl_struct.source));
4419 FreeLibrary(module);
4420 HeapFree(GetProcessHeap(),0,tl_struct.source);
4422 else
4423 ERR("Could not load file! %s\n",
4424 debugstr_w(package->files[index].TargetPath));
4425 msiobj_release(&row->hdr);
4427 MSI_ViewClose(view);
4428 msiobj_release(&view->hdr);
4429 return rc;
4432 static INT load_appid(MSIPACKAGE* package, MSIRECORD *row)
4434 DWORD index = package->loaded_appids;
4435 DWORD sz;
4436 LPWSTR buffer;
4438 /* fill in the data */
4440 package->loaded_appids++;
4441 if (package->loaded_appids == 1)
4442 package->appids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIAPPID));
4443 else
4444 package->appids = HeapReAlloc(GetProcessHeap(),0,
4445 package->appids, package->loaded_appids * sizeof(MSIAPPID));
4447 memset(&package->appids[index],0,sizeof(MSIAPPID));
4449 sz = IDENTIFIER_SIZE;
4450 MSI_RecordGetStringW(row, 1, package->appids[index].AppID, &sz);
4451 TRACE("loading appid %s\n",debugstr_w(package->appids[index].AppID));
4453 buffer = load_dynamic_stringW(row,2);
4454 deformat_string(package,buffer,&package->appids[index].RemoteServerName);
4455 HeapFree(GetProcessHeap(),0,buffer);
4457 package->appids[index].LocalServer = load_dynamic_stringW(row,3);
4458 package->appids[index].ServiceParameters = load_dynamic_stringW(row,4);
4459 package->appids[index].DllSurrogate = load_dynamic_stringW(row,5);
4461 package->appids[index].ActivateAtStorage = !MSI_RecordIsNull(row,6);
4462 package->appids[index].RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
4464 return index;
4467 static INT load_given_appid(MSIPACKAGE *package, LPCWSTR appid)
4469 INT rc;
4470 MSIRECORD *row;
4471 INT i;
4472 static const WCHAR ExecSeqQuery[] =
4473 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4474 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
4475 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
4477 if (!appid)
4478 return -1;
4480 /* check for appids already loaded */
4481 for (i = 0; i < package->loaded_appids; i++)
4482 if (strcmpiW(package->appids[i].AppID,appid)==0)
4484 TRACE("found appid %s at index %i\n",debugstr_w(appid),i);
4485 return i;
4488 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, appid);
4489 if (!row)
4490 return -1;
4492 rc = load_appid(package, row);
4493 msiobj_release(&row->hdr);
4495 return rc;
4498 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
4499 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid);
4501 static INT load_progid(MSIPACKAGE* package, MSIRECORD *row)
4503 DWORD index = package->loaded_progids;
4504 LPWSTR buffer;
4506 /* fill in the data */
4508 package->loaded_progids++;
4509 if (package->loaded_progids == 1)
4510 package->progids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIPROGID));
4511 else
4512 package->progids = HeapReAlloc(GetProcessHeap(),0,
4513 package->progids , package->loaded_progids * sizeof(MSIPROGID));
4515 memset(&package->progids[index],0,sizeof(MSIPROGID));
4517 package->progids[index].ProgID = load_dynamic_stringW(row,1);
4518 TRACE("loading progid %s\n",debugstr_w(package->progids[index].ProgID));
4520 buffer = load_dynamic_stringW(row,2);
4521 package->progids[index].ParentIndex = load_given_progid(package,buffer);
4522 if (package->progids[index].ParentIndex < 0 && buffer)
4523 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
4524 HeapFree(GetProcessHeap(),0,buffer);
4526 buffer = load_dynamic_stringW(row,3);
4527 package->progids[index].ClassIndex = load_given_class(package,buffer);
4528 if (package->progids[index].ClassIndex< 0 && buffer)
4529 FIXME("Unknown class %s\n",debugstr_w(buffer));
4530 HeapFree(GetProcessHeap(),0,buffer);
4532 package->progids[index].Description = load_dynamic_stringW(row,4);
4534 if (!MSI_RecordIsNull(row,6))
4536 INT icon_index = MSI_RecordGetInteger(row,6);
4537 LPWSTR FileName = load_dynamic_stringW(row,5);
4538 LPWSTR FilePath;
4539 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4541 build_icon_path(package,FileName,&FilePath);
4543 package->progids[index].IconPath =
4544 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+10)*
4545 sizeof(WCHAR));
4547 sprintfW(package->progids[index].IconPath,fmt,FilePath,icon_index);
4549 HeapFree(GetProcessHeap(),0,FilePath);
4550 HeapFree(GetProcessHeap(),0,FileName);
4552 else
4554 buffer = load_dynamic_stringW(row,5);
4555 if (buffer)
4556 build_icon_path(package,buffer,&(package->progids[index].IconPath));
4557 HeapFree(GetProcessHeap(),0,buffer);
4560 package->progids[index].CurVerIndex = -1;
4561 package->progids[index].VersionIndIndex = -1;
4563 /* if we have a parent then we may be that parents CurVer */
4564 if (package->progids[index].ParentIndex >= 0 &&
4565 package->progids[index].ParentIndex != index)
4567 int pindex = package->progids[index].ParentIndex;
4568 while (package->progids[pindex].ParentIndex>= 0)
4569 pindex = package->progids[pindex].ParentIndex;
4571 FIXME("BAD BAD need to determing if we are really the CurVer\n");
4573 package->progids[index].CurVerIndex = pindex;
4574 package->progids[pindex].VersionIndIndex = index;
4577 return index;
4580 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid)
4582 INT rc;
4583 MSIRECORD *row;
4584 INT i;
4585 static const WCHAR ExecSeqQuery[] =
4586 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4587 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
4588 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
4590 if (!progid)
4591 return -1;
4593 /* check for progids already loaded */
4594 for (i = 0; i < package->loaded_progids; i++)
4595 if (strcmpiW(package->progids[i].ProgID,progid)==0)
4597 TRACE("found progid %s at index %i\n",debugstr_w(progid), i);
4598 return i;
4601 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, progid);
4602 if(!row)
4603 return -1;
4605 rc = load_progid(package, row);
4606 msiobj_release(&row->hdr);
4608 return rc;
4611 static INT load_class(MSIPACKAGE* package, MSIRECORD *row)
4613 DWORD index = package->loaded_classes;
4614 DWORD sz,i;
4615 LPWSTR buffer;
4617 /* fill in the data */
4619 package->loaded_classes++;
4620 if (package->loaded_classes== 1)
4621 package->classes = HeapAlloc(GetProcessHeap(),0,sizeof(MSICLASS));
4622 else
4623 package->classes = HeapReAlloc(GetProcessHeap(),0,
4624 package->classes, package->loaded_classes * sizeof(MSICLASS));
4626 memset(&package->classes[index],0,sizeof(MSICLASS));
4628 sz = IDENTIFIER_SIZE;
4629 MSI_RecordGetStringW(row, 1, package->classes[index].CLSID, &sz);
4630 TRACE("loading class %s\n",debugstr_w(package->classes[index].CLSID));
4631 sz = IDENTIFIER_SIZE;
4632 MSI_RecordGetStringW(row, 2, package->classes[index].Context, &sz);
4633 buffer = load_dynamic_stringW(row,3);
4634 package->classes[index].ComponentIndex = get_loaded_component(package,
4635 buffer);
4636 HeapFree(GetProcessHeap(),0,buffer);
4638 package->classes[index].ProgIDText = load_dynamic_stringW(row,4);
4639 package->classes[index].ProgIDIndex =
4640 load_given_progid(package, package->classes[index].ProgIDText);
4642 package->classes[index].Description = load_dynamic_stringW(row,5);
4644 buffer = load_dynamic_stringW(row,6);
4645 if (buffer)
4646 package->classes[index].AppIDIndex =
4647 load_given_appid(package, buffer);
4648 else
4649 package->classes[index].AppIDIndex = -1;
4650 HeapFree(GetProcessHeap(),0,buffer);
4652 package->classes[index].FileTypeMask = load_dynamic_stringW(row,7);
4654 if (!MSI_RecordIsNull(row,9))
4657 INT icon_index = MSI_RecordGetInteger(row,9);
4658 LPWSTR FileName = load_dynamic_stringW(row,8);
4659 LPWSTR FilePath;
4660 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4662 build_icon_path(package,FileName,&FilePath);
4664 package->classes[index].IconPath =
4665 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4666 sizeof(WCHAR));
4668 sprintfW(package->classes[index].IconPath,fmt,FilePath,icon_index);
4670 HeapFree(GetProcessHeap(),0,FilePath);
4671 HeapFree(GetProcessHeap(),0,FileName);
4673 else
4675 buffer = load_dynamic_stringW(row,8);
4676 if (buffer)
4677 build_icon_path(package,buffer,&(package->classes[index].IconPath));
4678 HeapFree(GetProcessHeap(),0,buffer);
4681 if (!MSI_RecordIsNull(row,10))
4683 i = MSI_RecordGetInteger(row,10);
4684 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4686 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4687 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
4689 switch(i)
4691 case 1:
4692 package->classes[index].DefInprocHandler = strdupW(ole2);
4693 break;
4694 case 2:
4695 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4696 break;
4697 case 3:
4698 package->classes[index].DefInprocHandler = strdupW(ole2);
4699 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4700 break;
4703 else
4705 package->classes[index].DefInprocHandler32 = load_dynamic_stringW(
4706 row, 10);
4707 reduce_to_longfilename(package->classes[index].DefInprocHandler32);
4710 buffer = load_dynamic_stringW(row,11);
4711 deformat_string(package,buffer,&package->classes[index].Argument);
4712 HeapFree(GetProcessHeap(),0,buffer);
4714 buffer = load_dynamic_stringW(row,12);
4715 package->classes[index].FeatureIndex = get_loaded_feature(package,buffer);
4716 HeapFree(GetProcessHeap(),0,buffer);
4718 package->classes[index].Attributes = MSI_RecordGetInteger(row,13);
4720 return index;
4724 * the Class table has 3 primary keys. Generally it is only
4725 * referenced through the first CLSID key. However when loading
4726 * all of the classes we need to make sure we do not ignore rows
4727 * with other Context and ComponentIndexs
4729 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid)
4731 INT rc;
4732 MSIRECORD *row;
4733 INT i;
4734 static const WCHAR ExecSeqQuery[] =
4735 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4736 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
4737 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
4740 if (!classid)
4741 return -1;
4743 /* check for classes already loaded */
4744 for (i = 0; i < package->loaded_classes; i++)
4745 if (strcmpiW(package->classes[i].CLSID,classid)==0)
4747 TRACE("found class %s at index %i\n",debugstr_w(classid), i);
4748 return i;
4751 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
4752 if (!row)
4753 return -1;
4755 rc = load_class(package, row);
4756 msiobj_release(&row->hdr);
4758 return rc;
4761 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension);
4763 static INT load_mime(MSIPACKAGE* package, MSIRECORD *row)
4765 DWORD index = package->loaded_mimes;
4766 DWORD sz;
4767 LPWSTR buffer;
4769 /* fill in the data */
4771 package->loaded_mimes++;
4772 if (package->loaded_mimes== 1)
4773 package->mimes= HeapAlloc(GetProcessHeap(),0,sizeof(MSIMIME));
4774 else
4775 package->mimes= HeapReAlloc(GetProcessHeap(),0,
4776 package->mimes, package->loaded_mimes*
4777 sizeof(MSIMIME));
4779 memset(&package->mimes[index],0,sizeof(MSIMIME));
4781 package->mimes[index].ContentType = load_dynamic_stringW(row,1);
4782 TRACE("loading mime %s\n",debugstr_w(package->mimes[index].ContentType));
4784 buffer = load_dynamic_stringW(row,2);
4785 package->mimes[index].ExtensionIndex = load_given_extension(package,
4786 buffer);
4787 HeapFree(GetProcessHeap(),0,buffer);
4789 sz = IDENTIFIER_SIZE;
4790 MSI_RecordGetStringW(row,3,package->mimes[index].CLSID,&sz);
4791 package->mimes[index].ClassIndex= load_given_class(package,
4792 package->mimes[index].CLSID);
4794 return index;
4797 static INT load_given_mime(MSIPACKAGE *package, LPCWSTR mime)
4799 INT rc;
4800 MSIRECORD *row;
4801 INT i;
4802 static const WCHAR ExecSeqQuery[] =
4803 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4804 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
4805 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
4806 '\'','%','s','\'',0};
4808 if (!mime)
4809 return -1;
4811 /* check for mime already loaded */
4812 for (i = 0; i < package->loaded_mimes; i++)
4813 if (strcmpiW(package->mimes[i].ContentType,mime)==0)
4815 TRACE("found mime %s at index %i\n",debugstr_w(mime), i);
4816 return i;
4819 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
4820 if (!row)
4821 return -1;
4823 rc = load_mime(package, row);
4824 msiobj_release(&row->hdr);
4826 return rc;
4829 static INT load_extension(MSIPACKAGE* package, MSIRECORD *row)
4831 DWORD index = package->loaded_extensions;
4832 DWORD sz;
4833 LPWSTR buffer;
4835 /* fill in the data */
4837 package->loaded_extensions++;
4838 if (package->loaded_extensions == 1)
4839 package->extensions = HeapAlloc(GetProcessHeap(),0,sizeof(MSIEXTENSION));
4840 else
4841 package->extensions = HeapReAlloc(GetProcessHeap(),0,
4842 package->extensions, package->loaded_extensions*
4843 sizeof(MSIEXTENSION));
4845 memset(&package->extensions[index],0,sizeof(MSIEXTENSION));
4847 sz = 256;
4848 MSI_RecordGetStringW(row,1,package->extensions[index].Extension,&sz);
4849 TRACE("loading extension %s\n",
4850 debugstr_w(package->extensions[index].Extension));
4852 buffer = load_dynamic_stringW(row,2);
4853 package->extensions[index].ComponentIndex =
4854 get_loaded_component(package,buffer);
4855 HeapFree(GetProcessHeap(),0,buffer);
4857 package->extensions[index].ProgIDText = load_dynamic_stringW(row,3);
4858 package->extensions[index].ProgIDIndex = load_given_progid(package,
4859 package->extensions[index].ProgIDText);
4861 buffer = load_dynamic_stringW(row,4);
4862 package->extensions[index].MIMEIndex = load_given_mime(package,buffer);
4863 HeapFree(GetProcessHeap(),0,buffer);
4865 buffer = load_dynamic_stringW(row,5);
4866 package->extensions[index].FeatureIndex =
4867 get_loaded_feature(package,buffer);
4868 HeapFree(GetProcessHeap(),0,buffer);
4870 return index;
4874 * While the extension table has 2 primary keys, this function is only looking
4875 * at the Extension key which is what is referenced as a forign key
4877 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension)
4879 INT rc;
4880 MSIRECORD *row;
4881 INT i;
4882 static const WCHAR ExecSeqQuery[] =
4883 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4884 '`','E','x','t','e','n','s','i','o','n','`',' ',
4885 'W','H','E','R','E',' ',
4886 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
4887 '\'','%','s','\'',0};
4889 if (!extension)
4890 return -1;
4892 /* check for extensions already loaded */
4893 for (i = 0; i < package->loaded_extensions; i++)
4894 if (strcmpiW(package->extensions[i].Extension,extension)==0)
4896 TRACE("extension %s already loaded at %i\n",debugstr_w(extension),
4898 return i;
4901 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, extension);
4902 if (!row)
4903 return -1;
4905 rc = load_extension(package, row);
4906 msiobj_release(&row->hdr);
4908 return rc;
4911 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
4913 MSIPACKAGE* package = (MSIPACKAGE*)param;
4914 DWORD index = package->loaded_verbs;
4915 LPWSTR buffer;
4917 /* fill in the data */
4919 package->loaded_verbs++;
4920 if (package->loaded_verbs == 1)
4921 package->verbs = HeapAlloc(GetProcessHeap(),0,sizeof(MSIVERB));
4922 else
4923 package->verbs = HeapReAlloc(GetProcessHeap(),0,
4924 package->verbs , package->loaded_verbs * sizeof(MSIVERB));
4926 memset(&package->verbs[index],0,sizeof(MSIVERB));
4928 buffer = load_dynamic_stringW(row,1);
4929 package->verbs[index].ExtensionIndex = load_given_extension(package,buffer);
4930 if (package->verbs[index].ExtensionIndex < 0 && buffer)
4931 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
4932 HeapFree(GetProcessHeap(),0,buffer);
4934 package->verbs[index].Verb = load_dynamic_stringW(row,2);
4935 TRACE("loading verb %s\n",debugstr_w(package->verbs[index].Verb));
4936 package->verbs[index].Sequence = MSI_RecordGetInteger(row,3);
4938 buffer = load_dynamic_stringW(row,4);
4939 deformat_string(package,buffer,&package->verbs[index].Command);
4940 HeapFree(GetProcessHeap(),0,buffer);
4942 buffer = load_dynamic_stringW(row,5);
4943 deformat_string(package,buffer,&package->verbs[index].Argument);
4944 HeapFree(GetProcessHeap(),0,buffer);
4946 /* assosiate the verb with the correct extension */
4947 if (package->verbs[index].ExtensionIndex >= 0)
4949 MSIEXTENSION* extension = &package->extensions[package->verbs[index].
4950 ExtensionIndex];
4951 int count = extension->VerbCount;
4953 if (count >= 99)
4954 FIXME("Exceeding max verb count! Increase that limit!!!\n");
4955 else
4957 extension->VerbCount++;
4958 extension->Verbs[count] = index;
4962 return ERROR_SUCCESS;
4965 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
4967 LPWSTR clsid;
4968 LPWSTR context;
4969 LPWSTR buffer;
4970 INT component_index;
4971 MSIPACKAGE* package =(MSIPACKAGE*)param;
4972 INT i;
4973 BOOL match = FALSE;
4975 clsid = load_dynamic_stringW(rec,1);
4976 context = load_dynamic_stringW(rec,2);
4977 buffer = load_dynamic_stringW(rec,3);
4978 component_index = get_loaded_component(package,buffer);
4980 for (i = 0; i < package->loaded_classes; i++)
4982 if (strcmpiW(clsid,package->classes[i].CLSID))
4983 continue;
4984 if (strcmpW(context,package->classes[i].Context))
4985 continue;
4986 if (component_index == package->classes[i].ComponentIndex)
4988 match = TRUE;
4989 break;
4993 HeapFree(GetProcessHeap(),0,buffer);
4994 HeapFree(GetProcessHeap(),0,clsid);
4995 HeapFree(GetProcessHeap(),0,context);
4997 if (!match)
4998 load_class(package, rec);
5000 return ERROR_SUCCESS;
5003 static VOID load_all_classes(MSIPACKAGE *package)
5005 UINT rc = ERROR_SUCCESS;
5006 MSIQUERY *view;
5008 static const WCHAR ExecSeqQuery[] =
5009 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
5010 '`','C','l','a','s','s','`',0};
5012 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5013 if (rc != ERROR_SUCCESS)
5014 return;
5016 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
5017 msiobj_release(&view->hdr);
5020 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
5022 LPWSTR buffer;
5023 LPWSTR extension;
5024 INT component_index;
5025 MSIPACKAGE* package =(MSIPACKAGE*)param;
5026 BOOL match = FALSE;
5027 INT i;
5029 extension = load_dynamic_stringW(rec,1);
5030 buffer = load_dynamic_stringW(rec,2);
5031 component_index = get_loaded_component(package,buffer);
5033 for (i = 0; i < package->loaded_extensions; i++)
5035 if (strcmpiW(extension,package->extensions[i].Extension))
5036 continue;
5037 if (component_index == package->extensions[i].ComponentIndex)
5039 match = TRUE;
5040 break;
5044 HeapFree(GetProcessHeap(),0,buffer);
5045 HeapFree(GetProcessHeap(),0,extension);
5047 if (!match)
5048 load_extension(package, rec);
5050 return ERROR_SUCCESS;
5053 static VOID load_all_extensions(MSIPACKAGE *package)
5055 UINT rc = ERROR_SUCCESS;
5056 MSIQUERY *view;
5058 static const WCHAR ExecSeqQuery[] =
5059 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5060 '`','E','x','t','e','n','s','i','o','n','`',0};
5062 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5063 if (rc != ERROR_SUCCESS)
5064 return;
5066 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
5067 msiobj_release(&view->hdr);
5070 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
5072 LPWSTR buffer;
5073 MSIPACKAGE* package =(MSIPACKAGE*)param;
5075 buffer = load_dynamic_stringW(rec,1);
5076 load_given_progid(package,buffer);
5077 HeapFree(GetProcessHeap(),0,buffer);
5078 return ERROR_SUCCESS;
5081 static VOID load_all_progids(MSIPACKAGE *package)
5083 UINT rc = ERROR_SUCCESS;
5084 MSIQUERY *view;
5086 static const WCHAR ExecSeqQuery[] =
5087 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
5088 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
5090 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5091 if (rc != ERROR_SUCCESS)
5092 return;
5094 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
5095 msiobj_release(&view->hdr);
5098 static VOID load_all_verbs(MSIPACKAGE *package)
5100 UINT rc = ERROR_SUCCESS;
5101 MSIQUERY *view;
5103 static const WCHAR ExecSeqQuery[] =
5104 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5105 '`','V','e','r','b','`',0};
5107 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5108 if (rc != ERROR_SUCCESS)
5109 return;
5111 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
5112 msiobj_release(&view->hdr);
5115 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
5117 LPWSTR buffer;
5118 MSIPACKAGE* package =(MSIPACKAGE*)param;
5120 buffer = load_dynamic_stringW(rec,1);
5121 load_given_mime(package,buffer);
5122 HeapFree(GetProcessHeap(),0,buffer);
5123 return ERROR_SUCCESS;
5126 static VOID load_all_mimes(MSIPACKAGE *package)
5128 UINT rc = ERROR_SUCCESS;
5129 MSIQUERY *view;
5131 static const WCHAR ExecSeqQuery[] =
5132 {'S','E','L','E','C','T',' ',
5133 '`','C','o','n','t','e','n','t','T','y','p','e','`',
5134 ' ','F','R','O','M',' ',
5135 '`','M','I','M','E','`',0};
5137 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5138 if (rc != ERROR_SUCCESS)
5139 return;
5141 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
5142 msiobj_release(&view->hdr);
5145 static void load_classes_and_such(MSIPACKAGE *package)
5147 TRACE("Loading all the class info and related tables\n");
5149 /* check if already loaded */
5150 if (package->classes || package->extensions || package->progids ||
5151 package->verbs || package->mimes)
5152 return;
5154 load_all_classes(package);
5155 load_all_extensions(package);
5156 load_all_progids(package);
5157 /* these loads must come after the other loads */
5158 load_all_verbs(package);
5159 load_all_mimes(package);
5162 static void mark_progid_for_install(MSIPACKAGE* package, INT index)
5164 MSIPROGID* progid;
5165 int i;
5167 if (index < 0 || index >= package->loaded_progids)
5168 return;
5170 progid = &package->progids[index];
5172 if (progid->InstallMe == TRUE)
5173 return;
5175 progid->InstallMe = TRUE;
5177 /* all children if this is a parent also install */
5178 for (i = 0; i < package->loaded_progids; i++)
5179 if (package->progids[i].ParentIndex == index)
5180 mark_progid_for_install(package,i);
5183 static void mark_mime_for_install(MSIPACKAGE* package, INT index)
5185 MSIMIME* mime;
5187 if (index < 0 || index >= package->loaded_mimes)
5188 return;
5190 mime = &package->mimes[index];
5192 if (mime->InstallMe == TRUE)
5193 return;
5195 mime->InstallMe = TRUE;
5198 static UINT register_appid(MSIPACKAGE *package, int appidIndex, LPCWSTR app )
5200 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5201 HKEY hkey2,hkey3;
5203 if (!package)
5204 return ERROR_INVALID_HANDLE;
5206 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
5207 RegCreateKeyW(hkey2,package->appids[appidIndex].AppID,&hkey3);
5208 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
5209 (strlenW(app)+1)*sizeof(WCHAR));
5211 if (package->appids[appidIndex].RemoteServerName)
5213 UINT size;
5214 static const WCHAR szRemoteServerName[] =
5215 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
5218 size = (strlenW(package->appids[appidIndex].RemoteServerName)+1) *
5219 sizeof(WCHAR);
5221 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,
5222 (LPVOID)package->appids[appidIndex].RemoteServerName,
5223 size);
5226 if (package->appids[appidIndex].LocalServer)
5228 static const WCHAR szLocalService[] =
5229 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
5230 UINT size;
5231 size = (strlenW(package->appids[appidIndex].LocalServer)+1) *
5232 sizeof(WCHAR);
5234 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,
5235 (LPVOID)package->appids[appidIndex].LocalServer,size);
5238 if (package->appids[appidIndex].ServiceParameters)
5240 static const WCHAR szService[] =
5241 {'S','e','r','v','i','c','e',
5242 'P','a','r','a','m','e','t','e','r','s',0};
5243 UINT size;
5244 size = (strlenW(package->appids[appidIndex].ServiceParameters)+1) *
5245 sizeof(WCHAR);
5246 RegSetValueExW(hkey3,szService,0,REG_SZ,
5247 (LPVOID)package->appids[appidIndex].ServiceParameters,
5248 size);
5251 if (package->appids[appidIndex].DllSurrogate)
5253 static const WCHAR szDLL[] =
5254 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
5255 UINT size;
5256 size = (strlenW(package->appids[appidIndex].DllSurrogate)+1) *
5257 sizeof(WCHAR);
5258 RegSetValueExW(hkey3,szDLL,0,REG_SZ,
5259 (LPVOID)package->appids[appidIndex].DllSurrogate,size);
5262 if (package->appids[appidIndex].ActivateAtStorage)
5264 static const WCHAR szActivate[] =
5265 {'A','c','t','i','v','a','t','e','A','s',
5266 'S','t','o','r','a','g','e',0};
5267 static const WCHAR szY[] = {'Y',0};
5269 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
5272 if (package->appids[appidIndex].RunAsInteractiveUser)
5274 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
5275 static const WCHAR szUser[] =
5276 {'I','n','t','e','r','a','c','t','i','v','e',' ',
5277 'U','s','e','r',0};
5279 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,sizeof(szUser));
5282 RegCloseKey(hkey3);
5283 RegCloseKey(hkey2);
5284 return ERROR_SUCCESS;
5287 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
5290 * Again I am assuming the words, "Whose key file represents" when referring
5291 * to a Component as to meaning that Components KeyPath file
5294 UINT rc;
5295 MSIRECORD *uirow;
5296 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5297 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
5298 static const WCHAR szVIProgID[] = { 'V','e','r','s','i','o','n','I','n','d','e','p','e','n','d','e','n','t','P','r','o','g','I','D',0 };
5299 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5300 static const WCHAR szSpace[] = {' ',0};
5301 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
5302 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
5303 HKEY hkey,hkey2,hkey3;
5304 BOOL install_on_demand = FALSE;
5305 int i;
5307 if (!package)
5308 return ERROR_INVALID_HANDLE;
5310 load_classes_and_such(package);
5311 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
5312 if (rc != ERROR_SUCCESS)
5313 return ERROR_FUNCTION_FAILED;
5315 /* install_on_demand should be set if OLE supports install on demand OLE
5316 * servers. For now i am defaulting to FALSE because i do not know how to
5317 * check, and i am told our builtin OLE does not support it
5320 for (i = 0; i < package->loaded_classes; i++)
5322 INT index,f_index;
5323 DWORD size, sz;
5324 LPWSTR argument;
5326 if (package->classes[i].ComponentIndex < 0)
5328 continue;
5331 index = package->classes[i].ComponentIndex;
5332 f_index = package->classes[i].FeatureIndex;
5335 * yes. MSDN says that these are based on _Feature_ not on
5336 * Component. So verify the feature is to be installed
5338 if ((!ACTION_VerifyFeatureForAction(package, f_index,
5339 INSTALLSTATE_LOCAL)) &&
5340 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
5341 f_index, INSTALLSTATE_ADVERTISED)))
5343 TRACE("Skipping class %s reg due to disabled feature %s\n",
5344 debugstr_w(package->classes[i].CLSID),
5345 debugstr_w(package->features[f_index].Feature));
5347 continue;
5350 TRACE("Registering index %i class %s\n",i,
5351 debugstr_w(package->classes[i].CLSID));
5353 package->classes[i].Installed = TRUE;
5354 if (package->classes[i].ProgIDIndex >= 0)
5355 mark_progid_for_install(package, package->classes[i].ProgIDIndex);
5357 RegCreateKeyW(hkey,package->classes[i].CLSID,&hkey2);
5359 if (package->classes[i].Description)
5360 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)package->classes[i].
5361 Description, (strlenW(package->classes[i].
5362 Description)+1)*sizeof(WCHAR));
5364 RegCreateKeyW(hkey2,package->classes[i].Context,&hkey3);
5365 index = get_loaded_file(package,package->components[index].KeyPath);
5368 /* the context server is a short path name
5369 * except for if it is InprocServer32...
5371 if (strcmpiW(package->classes[i].Context,szInprocServer32)!=0)
5373 sz = 0;
5374 sz = GetShortPathNameW(package->files[index].TargetPath, NULL, 0);
5375 if (sz == 0)
5377 ERR("Unable to find short path for CLSID COM Server\n");
5378 argument = NULL;
5380 else
5382 size = sz * sizeof(WCHAR);
5384 if (package->classes[i].Argument)
5386 size += strlenW(package->classes[i].Argument) *
5387 sizeof(WCHAR);
5388 size += sizeof(WCHAR);
5391 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5392 GetShortPathNameW(package->files[index].TargetPath, argument,
5393 sz);
5395 if (package->classes[i].Argument)
5397 strcatW(argument,szSpace);
5398 strcatW(argument,package->classes[i].Argument);
5402 else
5404 size = lstrlenW(package->files[index].TargetPath) * sizeof(WCHAR);
5406 if (package->classes[i].Argument)
5408 size += strlenW(package->classes[i].Argument) * sizeof(WCHAR);
5409 size += sizeof(WCHAR);
5412 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5413 strcpyW(argument, package->files[index].TargetPath);
5415 if (package->classes[i].Argument)
5417 strcatW(argument,szSpace);
5418 strcatW(argument,package->classes[i].Argument);
5422 if (argument)
5424 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
5425 HeapFree(GetProcessHeap(),0,argument);
5428 RegCloseKey(hkey3);
5430 if (package->classes[i].ProgIDIndex >= 0 ||
5431 package->classes[i].ProgIDText)
5433 LPCWSTR progid;
5435 if (package->classes[i].ProgIDIndex >= 0)
5436 progid = package->progids[
5437 package->classes[i].ProgIDIndex].ProgID;
5438 else
5439 progid = package->classes[i].ProgIDText;
5441 RegCreateKeyW(hkey2,szProgID,&hkey3);
5442 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)progid,
5443 (strlenW(progid)+1) *sizeof(WCHAR));
5444 RegCloseKey(hkey3);
5446 if (package->classes[i].ProgIDIndex >= 0 &&
5447 package->progids[package->classes[i].ProgIDIndex].
5448 VersionIndIndex >= 0)
5450 LPWSTR viprogid = strdupW(package->progids[package->progids[
5451 package->classes[i].ProgIDIndex].VersionIndIndex].
5452 ProgID);
5453 RegCreateKeyW(hkey2,szVIProgID,&hkey3);
5454 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)viprogid,
5455 (strlenW(viprogid)+1) *sizeof(WCHAR));
5456 RegCloseKey(hkey3);
5457 HeapFree(GetProcessHeap(), 0, viprogid);
5461 if (package->classes[i].AppIDIndex >= 0)
5463 RegSetValueExW(hkey2,szAppID,0,REG_SZ,
5464 (LPVOID)package->appids[package->classes[i].AppIDIndex].AppID,
5465 (strlenW(package->appids[package->classes[i].AppIDIndex].AppID)+1)
5466 *sizeof(WCHAR));
5468 register_appid(package,package->classes[i].AppIDIndex,
5469 package->classes[i].Description);
5472 if (package->classes[i].IconPath)
5474 static const WCHAR szDefaultIcon[] =
5475 {'D','e','f','a','u','l','t','I','c','o','n',0};
5477 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
5479 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5480 (LPVOID)package->classes[i].IconPath,
5481 (strlenW(package->classes[i].IconPath)+1) *
5482 sizeof(WCHAR));
5484 RegCloseKey(hkey3);
5487 if (package->classes[i].DefInprocHandler)
5489 static const WCHAR szInproc[] =
5490 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
5492 size = (strlenW(package->classes[i].DefInprocHandler) + 1) *
5493 sizeof(WCHAR);
5494 RegCreateKeyW(hkey2,szInproc,&hkey3);
5495 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5496 (LPVOID)package->classes[i].DefInprocHandler, size);
5497 RegCloseKey(hkey3);
5500 if (package->classes[i].DefInprocHandler32)
5502 static const WCHAR szInproc32[] =
5503 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
5505 size = (strlenW(package->classes[i].DefInprocHandler32) + 1) *
5506 sizeof(WCHAR);
5508 RegCreateKeyW(hkey2,szInproc32,&hkey3);
5509 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5510 (LPVOID)package->classes[i].DefInprocHandler32,size);
5511 RegCloseKey(hkey3);
5514 RegCloseKey(hkey2);
5516 /* if there is a FileTypeMask, register the FileType */
5517 if (package->classes[i].FileTypeMask)
5519 LPWSTR ptr, ptr2;
5520 LPWSTR keyname;
5521 INT index = 0;
5522 ptr = package->classes[i].FileTypeMask;
5523 while (ptr && *ptr)
5525 ptr2 = strchrW(ptr,';');
5526 if (ptr2)
5527 *ptr2 = 0;
5528 keyname = HeapAlloc(GetProcessHeap(),0,(strlenW(szFileType_fmt)+
5529 strlenW(package->classes[i].CLSID) + 4)
5530 * sizeof(WCHAR));
5531 sprintfW(keyname,szFileType_fmt, package->classes[i].CLSID,
5532 index);
5534 RegCreateKeyW(HKEY_CLASSES_ROOT,keyname,&hkey2);
5535 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPVOID)ptr,
5536 strlenW(ptr)*sizeof(WCHAR));
5537 RegCloseKey(hkey2);
5538 HeapFree(GetProcessHeap(), 0, keyname);
5540 if (ptr2)
5541 ptr = ptr2+1;
5542 else
5543 ptr = NULL;
5545 index ++;
5549 uirow = MSI_CreateRecord(1);
5551 MSI_RecordSetStringW(uirow,1,package->classes[i].CLSID);
5552 ui_actiondata(package,szRegisterClassInfo,uirow);
5553 msiobj_release(&uirow->hdr);
5556 RegCloseKey(hkey);
5557 return rc;
5560 static UINT register_progid_base(MSIPACKAGE* package, MSIPROGID* progid,
5561 LPWSTR clsid)
5563 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5564 static const WCHAR szDefaultIcon[] =
5565 {'D','e','f','a','u','l','t','I','c','o','n',0};
5566 HKEY hkey,hkey2;
5568 RegCreateKeyW(HKEY_CLASSES_ROOT,progid->ProgID,&hkey);
5570 if (progid->Description)
5572 RegSetValueExW(hkey,NULL,0,REG_SZ,
5573 (LPVOID)progid->Description,
5574 (strlenW(progid->Description)+1) *
5575 sizeof(WCHAR));
5578 if (progid->ClassIndex >= 0)
5580 RegCreateKeyW(hkey,szCLSID,&hkey2);
5581 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5582 (LPVOID)package->classes[progid->ClassIndex].CLSID,
5583 (strlenW(package->classes[progid->ClassIndex].CLSID)+1)
5584 * sizeof(WCHAR));
5586 if (clsid)
5587 strcpyW(clsid,package->classes[progid->ClassIndex].CLSID);
5589 RegCloseKey(hkey2);
5591 else
5593 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
5596 if (progid->IconPath)
5598 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5600 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5601 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5602 RegCloseKey(hkey2);
5604 return ERROR_SUCCESS;
5607 static UINT register_progid(MSIPACKAGE *package, MSIPROGID* progid,
5608 LPWSTR clsid)
5610 UINT rc = ERROR_SUCCESS;
5612 if (progid->ParentIndex < 0)
5613 rc = register_progid_base(package, progid, clsid);
5614 else
5616 DWORD disp;
5617 HKEY hkey,hkey2;
5618 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5619 static const WCHAR szDefaultIcon[] =
5620 {'D','e','f','a','u','l','t','I','c','o','n',0};
5621 static const WCHAR szCurVer[] =
5622 {'C','u','r','V','e','r',0};
5624 /* check if already registered */
5625 RegCreateKeyExW(HKEY_CLASSES_ROOT, progid->ProgID, 0, NULL, 0,
5626 KEY_ALL_ACCESS, NULL, &hkey, &disp );
5627 if (disp == REG_OPENED_EXISTING_KEY)
5629 TRACE("Key already registered\n");
5630 RegCloseKey(hkey);
5631 return rc;
5634 TRACE("Registering Parent %s index %i\n",
5635 debugstr_w(package->progids[progid->ParentIndex].ProgID),
5636 progid->ParentIndex);
5637 rc = register_progid(package,&package->progids[progid->ParentIndex],
5638 clsid);
5640 /* clsid is same as parent */
5641 RegCreateKeyW(hkey,szCLSID,&hkey2);
5642 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
5643 sizeof(WCHAR));
5645 RegCloseKey(hkey2);
5648 if (progid->Description)
5650 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid->Description,
5651 (strlenW(progid->Description)+1) * sizeof(WCHAR));
5654 if (progid->IconPath)
5656 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5657 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5658 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5659 RegCloseKey(hkey2);
5662 /* write out the current version */
5663 if (progid->CurVerIndex >= 0)
5665 RegCreateKeyW(hkey,szCurVer,&hkey2);
5666 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5667 (LPVOID)package->progids[progid->CurVerIndex].ProgID,
5668 (strlenW(package->progids[progid->CurVerIndex].ProgID)+1) *
5669 sizeof(WCHAR));
5670 RegCloseKey(hkey2);
5673 RegCloseKey(hkey);
5675 return rc;
5678 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
5680 INT i;
5681 MSIRECORD *uirow;
5683 if (!package)
5684 return ERROR_INVALID_HANDLE;
5686 load_classes_and_such(package);
5688 for (i = 0; i < package->loaded_progids; i++)
5690 WCHAR clsid[0x1000];
5692 /* check if this progid is to be installed */
5693 package->progids[i].InstallMe = ((package->progids[i].InstallMe) ||
5694 (package->progids[i].ClassIndex >= 0 &&
5695 package->classes[package->progids[i].ClassIndex].Installed));
5697 if (!package->progids[i].InstallMe)
5699 TRACE("progid %s not scheduled to be installed\n",
5700 debugstr_w(package->progids[i].ProgID));
5701 continue;
5704 TRACE("Registering progid %s index %i\n",
5705 debugstr_w(package->progids[i].ProgID), i);
5707 register_progid(package,&package->progids[i],clsid);
5709 uirow = MSI_CreateRecord(1);
5710 MSI_RecordSetStringW(uirow,1,package->progids[i].ProgID);
5711 ui_actiondata(package,szRegisterProgIdInfo,uirow);
5712 msiobj_release(&uirow->hdr);
5715 return ERROR_SUCCESS;
5718 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
5719 LPWSTR *FilePath)
5721 LPWSTR ProductCode;
5722 LPWSTR SystemFolder;
5723 LPWSTR dest;
5724 UINT rc;
5726 static const WCHAR szInstaller[] =
5727 {'M','i','c','r','o','s','o','f','t','\\',
5728 'I','n','s','t','a','l','l','e','r','\\',0};
5729 static const WCHAR szFolder[] =
5730 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
5732 ProductCode = load_dynamic_property(package,szProductCode,&rc);
5733 if (!ProductCode)
5734 return rc;
5736 SystemFolder = load_dynamic_property(package,szFolder,NULL);
5738 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
5740 create_full_pathW(dest);
5742 *FilePath = build_directory_name(2, dest, icon_name);
5744 HeapFree(GetProcessHeap(),0,SystemFolder);
5745 HeapFree(GetProcessHeap(),0,ProductCode);
5746 HeapFree(GetProcessHeap(),0,dest);
5747 return ERROR_SUCCESS;
5750 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
5752 UINT rc;
5753 MSIQUERY * view;
5754 MSIRECORD * row = 0;
5755 static const WCHAR Query[] =
5756 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5757 '`','S','h','o','r','t','c','u','t','`',0};
5758 IShellLinkW *sl;
5759 IPersistFile *pf;
5760 HRESULT res;
5762 if (!package)
5763 return ERROR_INVALID_HANDLE;
5765 res = CoInitialize( NULL );
5766 if (FAILED (res))
5768 ERR("CoInitialize failed\n");
5769 return ERROR_FUNCTION_FAILED;
5772 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5773 if (rc != ERROR_SUCCESS)
5774 return ERROR_SUCCESS;
5776 rc = MSI_ViewExecute(view, 0);
5777 if (rc != ERROR_SUCCESS)
5779 MSI_ViewClose(view);
5780 msiobj_release(&view->hdr);
5781 return rc;
5784 while (1)
5786 LPWSTR target_file, target_folder;
5787 WCHAR buffer[0x100];
5788 DWORD sz;
5789 DWORD index;
5790 static const WCHAR szlnk[]={'.','l','n','k',0};
5792 rc = MSI_ViewFetch(view,&row);
5793 if (rc != ERROR_SUCCESS)
5795 rc = ERROR_SUCCESS;
5796 break;
5799 sz = 0x100;
5800 MSI_RecordGetStringW(row,4,buffer,&sz);
5802 index = get_loaded_component(package,buffer);
5804 if (index < 0)
5806 msiobj_release(&row->hdr);
5807 continue;
5810 if (!ACTION_VerifyComponentForAction(package, index,
5811 INSTALLSTATE_LOCAL))
5813 TRACE("Skipping shortcut creation due to disabled component\n");
5814 msiobj_release(&row->hdr);
5816 package->components[index].Action =
5817 package->components[index].Installed;
5819 continue;
5822 package->components[index].Action = INSTALLSTATE_LOCAL;
5824 ui_actiondata(package,szCreateShortcuts,row);
5826 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
5827 &IID_IShellLinkW, (LPVOID *) &sl );
5829 if (FAILED(res))
5831 ERR("Is IID_IShellLink\n");
5832 msiobj_release(&row->hdr);
5833 continue;
5836 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
5837 if( FAILED( res ) )
5839 ERR("Is IID_IPersistFile\n");
5840 msiobj_release(&row->hdr);
5841 continue;
5844 sz = 0x100;
5845 MSI_RecordGetStringW(row,2,buffer,&sz);
5846 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
5848 /* may be needed because of a bug somehwere else */
5849 create_full_pathW(target_folder);
5851 sz = 0x100;
5852 MSI_RecordGetStringW(row,3,buffer,&sz);
5853 reduce_to_longfilename(buffer);
5854 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
5855 strcatW(buffer,szlnk);
5856 target_file = build_directory_name(2, target_folder, buffer);
5857 HeapFree(GetProcessHeap(),0,target_folder);
5859 sz = 0x100;
5860 MSI_RecordGetStringW(row,5,buffer,&sz);
5861 if (strchrW(buffer,'['))
5863 LPWSTR deformated;
5864 deformat_string(package,buffer,&deformated);
5865 IShellLinkW_SetPath(sl,deformated);
5866 HeapFree(GetProcessHeap(),0,deformated);
5868 else
5870 LPWSTR keypath;
5871 FIXME("poorly handled shortcut format, advertised shortcut\n");
5872 keypath = strdupW(package->components[index].FullKeypath);
5873 IShellLinkW_SetPath(sl,keypath);
5874 HeapFree(GetProcessHeap(),0,keypath);
5877 if (!MSI_RecordIsNull(row,6))
5879 LPWSTR deformated;
5880 sz = 0x100;
5881 MSI_RecordGetStringW(row,6,buffer,&sz);
5882 deformat_string(package,buffer,&deformated);
5883 IShellLinkW_SetArguments(sl,deformated);
5884 HeapFree(GetProcessHeap(),0,deformated);
5887 if (!MSI_RecordIsNull(row,7))
5889 LPWSTR deformated;
5890 deformated = load_dynamic_stringW(row,7);
5891 IShellLinkW_SetDescription(sl,deformated);
5892 HeapFree(GetProcessHeap(),0,deformated);
5895 if (!MSI_RecordIsNull(row,8))
5896 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
5898 if (!MSI_RecordIsNull(row,9))
5900 WCHAR *Path = NULL;
5901 INT index;
5903 sz = 0x100;
5904 MSI_RecordGetStringW(row,9,buffer,&sz);
5906 build_icon_path(package,buffer,&Path);
5907 index = MSI_RecordGetInteger(row,10);
5909 IShellLinkW_SetIconLocation(sl,Path,index);
5910 HeapFree(GetProcessHeap(),0,Path);
5913 if (!MSI_RecordIsNull(row,11))
5914 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
5916 if (!MSI_RecordIsNull(row,12))
5918 LPWSTR Path;
5919 sz = 0x100;
5920 MSI_RecordGetStringW(row,12,buffer,&sz);
5921 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
5922 IShellLinkW_SetWorkingDirectory(sl,Path);
5923 HeapFree(GetProcessHeap(), 0, Path);
5926 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
5927 IPersistFile_Save(pf,target_file,FALSE);
5929 HeapFree(GetProcessHeap(),0,target_file);
5931 IPersistFile_Release( pf );
5932 IShellLinkW_Release( sl );
5934 msiobj_release(&row->hdr);
5936 MSI_ViewClose(view);
5937 msiobj_release(&view->hdr);
5940 CoUninitialize();
5942 return rc;
5947 * 99% of the work done here is only done for
5948 * advertised installs. However this is where the
5949 * Icon table is processed and written out
5950 * so that is what I am going to do here.
5952 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
5954 UINT rc;
5955 MSIQUERY * view;
5956 MSIRECORD * row = 0;
5957 static const WCHAR Query[]=
5958 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5959 '`','I','c','o','n','`',0};
5960 DWORD sz;
5961 /* for registry stuff */
5962 LPWSTR productcode;
5963 HKEY hkey=0;
5964 HKEY hukey=0;
5965 static const WCHAR szProductName[] =
5966 {'P','r','o','d','u','c','t','N','a','m','e',0};
5967 static const WCHAR szPackageCode[] =
5968 {'P','a','c','k','a','g','e','C','o','d','e',0};
5969 LPWSTR buffer;
5970 DWORD size;
5971 MSIHANDLE hDb, hSumInfo;
5973 if (!package)
5974 return ERROR_INVALID_HANDLE;
5976 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5977 if (rc != ERROR_SUCCESS)
5978 goto next;
5980 rc = MSI_ViewExecute(view, 0);
5981 if (rc != ERROR_SUCCESS)
5983 MSI_ViewClose(view);
5984 msiobj_release(&view->hdr);
5985 goto next;
5988 while (1)
5990 HANDLE the_file;
5991 WCHAR *FilePath=NULL;
5992 WCHAR *FileName=NULL;
5993 CHAR buffer[1024];
5995 rc = MSI_ViewFetch(view,&row);
5996 if (rc != ERROR_SUCCESS)
5998 rc = ERROR_SUCCESS;
5999 break;
6002 FileName = load_dynamic_stringW(row,1);
6003 if (!FileName)
6005 ERR("Unable to get FileName\n");
6006 msiobj_release(&row->hdr);
6007 continue;
6010 build_icon_path(package,FileName,&FilePath);
6012 HeapFree(GetProcessHeap(),0,FileName);
6014 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
6016 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
6017 FILE_ATTRIBUTE_NORMAL, NULL);
6019 if (the_file == INVALID_HANDLE_VALUE)
6021 ERR("Unable to create file %s\n",debugstr_w(FilePath));
6022 msiobj_release(&row->hdr);
6023 HeapFree(GetProcessHeap(),0,FilePath);
6024 continue;
6029 DWORD write;
6030 sz = 1024;
6031 rc = MSI_RecordReadStream(row,2,buffer,&sz);
6032 if (rc != ERROR_SUCCESS)
6034 ERR("Failed to get stream\n");
6035 CloseHandle(the_file);
6036 DeleteFileW(FilePath);
6037 break;
6039 WriteFile(the_file,buffer,sz,&write,NULL);
6040 } while (sz == 1024);
6042 HeapFree(GetProcessHeap(),0,FilePath);
6044 CloseHandle(the_file);
6045 msiobj_release(&row->hdr);
6047 MSI_ViewClose(view);
6048 msiobj_release(&view->hdr);
6050 next:
6051 /* ok there is a lot more done here but i need to figure out what */
6052 productcode = load_dynamic_property(package,szProductCode,&rc);
6053 if (!productcode)
6054 return rc;
6056 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
6057 if (rc != ERROR_SUCCESS)
6058 goto end;
6060 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6061 if (rc != ERROR_SUCCESS)
6062 goto end;
6065 buffer = load_dynamic_property(package,szProductName,NULL);
6066 size = strlenW(buffer)*sizeof(WCHAR);
6067 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
6068 HeapFree(GetProcessHeap(),0,buffer);
6069 FIXME("Need to write more keys to the user registry\n");
6071 hDb= alloc_msihandle( &package->db->hdr );
6072 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
6073 MsiCloseHandle(hDb);
6074 if (rc == ERROR_SUCCESS)
6076 WCHAR guidbuffer[0x200];
6077 size = 0x200;
6078 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
6079 guidbuffer, &size);
6080 if (rc == ERROR_SUCCESS)
6082 WCHAR squashed[GUID_SIZE];
6083 /* for now we only care about the first guid */
6084 LPWSTR ptr = strchrW(guidbuffer,';');
6085 if (ptr) *ptr = 0;
6086 squash_guid(guidbuffer,squashed);
6087 size = strlenW(squashed)*sizeof(WCHAR);
6088 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
6089 size);
6091 else
6093 ERR("Unable to query Revision_Number... \n");
6094 rc = ERROR_SUCCESS;
6096 MsiCloseHandle(hSumInfo);
6098 else
6100 ERR("Unable to open Summary Information\n");
6101 rc = ERROR_SUCCESS;
6104 end:
6106 HeapFree(GetProcessHeap(),0,productcode);
6107 RegCloseKey(hkey);
6108 RegCloseKey(hukey);
6110 return rc;
6113 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
6115 UINT rc;
6116 MSIQUERY * view;
6117 MSIRECORD * row = 0;
6118 static const WCHAR ExecSeqQuery[] =
6119 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6120 '`','I','n','i','F','i','l','e','`',0};
6121 static const WCHAR szWindowsFolder[] =
6122 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
6124 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6125 if (rc != ERROR_SUCCESS)
6127 TRACE("no IniFile table\n");
6128 return ERROR_SUCCESS;
6131 rc = MSI_ViewExecute(view, 0);
6132 if (rc != ERROR_SUCCESS)
6134 MSI_ViewClose(view);
6135 msiobj_release(&view->hdr);
6136 return rc;
6139 while (1)
6141 LPWSTR component,filename,dirproperty,section,key,value,identifier;
6142 LPWSTR deformated_section, deformated_key, deformated_value;
6143 LPWSTR folder, fullname = NULL;
6144 MSIRECORD * uirow;
6145 INT component_index,action;
6147 rc = MSI_ViewFetch(view,&row);
6148 if (rc != ERROR_SUCCESS)
6150 rc = ERROR_SUCCESS;
6151 break;
6154 component = load_dynamic_stringW(row, 8);
6155 component_index = get_loaded_component(package,component);
6156 HeapFree(GetProcessHeap(),0,component);
6158 if (!ACTION_VerifyComponentForAction(package, component_index,
6159 INSTALLSTATE_LOCAL))
6161 TRACE("Skipping ini file due to disabled component\n");
6162 msiobj_release(&row->hdr);
6164 package->components[component_index].Action =
6165 package->components[component_index].Installed;
6167 continue;
6170 package->components[component_index].Action = INSTALLSTATE_LOCAL;
6172 identifier = load_dynamic_stringW(row,1);
6173 filename = load_dynamic_stringW(row,2);
6174 dirproperty = load_dynamic_stringW(row,3);
6175 section = load_dynamic_stringW(row,4);
6176 key = load_dynamic_stringW(row,5);
6177 value = load_dynamic_stringW(row,6);
6178 action = MSI_RecordGetInteger(row,7);
6180 deformat_string(package,section,&deformated_section);
6181 deformat_string(package,key,&deformated_key);
6182 deformat_string(package,value,&deformated_value);
6184 if (dirproperty)
6186 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
6187 if (!folder)
6188 folder = load_dynamic_property(package,dirproperty,NULL);
6190 else
6191 folder = load_dynamic_property(package, szWindowsFolder, NULL);
6193 if (!folder)
6195 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
6196 goto cleanup;
6199 fullname = build_directory_name(3, folder, filename, NULL);
6201 if (action == 0)
6203 TRACE("Adding value %s to section %s in %s\n",
6204 debugstr_w(deformated_key), debugstr_w(deformated_section),
6205 debugstr_w(fullname));
6206 WritePrivateProfileStringW(deformated_section, deformated_key,
6207 deformated_value, fullname);
6209 else if (action == 1)
6211 WCHAR returned[10];
6212 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
6213 returned, 10, fullname);
6214 if (returned[0] == 0)
6216 TRACE("Adding value %s to section %s in %s\n",
6217 debugstr_w(deformated_key), debugstr_w(deformated_section),
6218 debugstr_w(fullname));
6220 WritePrivateProfileStringW(deformated_section, deformated_key,
6221 deformated_value, fullname);
6224 else if (action == 3)
6226 FIXME("Append to existing section not yet implemented\n");
6229 uirow = MSI_CreateRecord(4);
6230 MSI_RecordSetStringW(uirow,1,identifier);
6231 MSI_RecordSetStringW(uirow,2,deformated_section);
6232 MSI_RecordSetStringW(uirow,3,deformated_key);
6233 MSI_RecordSetStringW(uirow,4,deformated_value);
6234 ui_actiondata(package,szWriteIniValues,uirow);
6235 msiobj_release( &uirow->hdr );
6236 cleanup:
6237 HeapFree(GetProcessHeap(),0,identifier);
6238 HeapFree(GetProcessHeap(),0,fullname);
6239 HeapFree(GetProcessHeap(),0,filename);
6240 HeapFree(GetProcessHeap(),0,key);
6241 HeapFree(GetProcessHeap(),0,value);
6242 HeapFree(GetProcessHeap(),0,section);
6243 HeapFree(GetProcessHeap(),0,dirproperty);
6244 HeapFree(GetProcessHeap(),0,folder);
6245 HeapFree(GetProcessHeap(),0,deformated_key);
6246 HeapFree(GetProcessHeap(),0,deformated_value);
6247 HeapFree(GetProcessHeap(),0,deformated_section);
6248 msiobj_release(&row->hdr);
6250 MSI_ViewClose(view);
6251 msiobj_release(&view->hdr);
6252 return rc;
6255 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
6257 UINT rc;
6258 MSIQUERY * view;
6259 MSIRECORD * row = 0;
6260 static const WCHAR ExecSeqQuery[] =
6261 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6262 '`','S','e','l','f','R','e','g','`',0};
6264 static const WCHAR ExeStr[] =
6265 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
6266 static const WCHAR close[] = {'\"',0};
6267 STARTUPINFOW si;
6268 PROCESS_INFORMATION info;
6269 BOOL brc;
6271 memset(&si,0,sizeof(STARTUPINFOW));
6273 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6274 if (rc != ERROR_SUCCESS)
6276 TRACE("no SelfReg table\n");
6277 return ERROR_SUCCESS;
6280 rc = MSI_ViewExecute(view, 0);
6281 if (rc != ERROR_SUCCESS)
6283 MSI_ViewClose(view);
6284 msiobj_release(&view->hdr);
6285 return rc;
6288 while (1)
6290 LPWSTR filename;
6291 INT index;
6292 DWORD len;
6294 rc = MSI_ViewFetch(view,&row);
6295 if (rc != ERROR_SUCCESS)
6297 rc = ERROR_SUCCESS;
6298 break;
6301 filename = load_dynamic_stringW(row,1);
6302 index = get_loaded_file(package,filename);
6304 if (index < 0)
6306 ERR("Unable to find file id %s\n",debugstr_w(filename));
6307 HeapFree(GetProcessHeap(),0,filename);
6308 msiobj_release(&row->hdr);
6309 continue;
6311 HeapFree(GetProcessHeap(),0,filename);
6313 len = strlenW(ExeStr);
6314 len += strlenW(package->files[index].TargetPath);
6315 len +=2;
6317 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
6318 strcpyW(filename,ExeStr);
6319 strcatW(filename,package->files[index].TargetPath);
6320 strcatW(filename,close);
6322 TRACE("Registering %s\n",debugstr_w(filename));
6323 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
6324 c_colon, &si, &info);
6326 if (brc)
6327 msi_dialog_check_messages(info.hProcess);
6329 HeapFree(GetProcessHeap(),0,filename);
6330 msiobj_release(&row->hdr);
6332 MSI_ViewClose(view);
6333 msiobj_release(&view->hdr);
6334 return rc;
6337 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
6339 LPWSTR productcode;
6340 UINT rc;
6341 DWORD i;
6342 HKEY hkey=0;
6343 HKEY hukey=0;
6345 if (!package)
6346 return ERROR_INVALID_HANDLE;
6348 productcode = load_dynamic_property(package,szProductCode,&rc);
6349 if (!productcode)
6350 return rc;
6352 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
6353 if (rc != ERROR_SUCCESS)
6354 goto end;
6356 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
6357 if (rc != ERROR_SUCCESS)
6358 goto end;
6360 /* here the guids are base 85 encoded */
6361 for (i = 0; i < package->loaded_features; i++)
6363 LPWSTR data = NULL;
6364 GUID clsid;
6365 int j;
6366 INT size;
6367 BOOL absent = FALSE;
6369 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL) &&
6370 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_SOURCE) &&
6371 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_ADVERTISED))
6372 absent = TRUE;
6374 size = package->features[i].ComponentCount*21;
6375 size +=1;
6376 if (package->features[i].Feature_Parent[0])
6377 size += strlenW(package->features[i].Feature_Parent)+2;
6379 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
6381 data[0] = 0;
6382 for (j = 0; j < package->features[i].ComponentCount; j++)
6384 WCHAR buf[21];
6385 memset(buf,0,sizeof(buf));
6386 if (package->components
6387 [package->features[i].Components[j]].ComponentId[0]!=0)
6389 TRACE("From %s\n",debugstr_w(package->components
6390 [package->features[i].Components[j]].ComponentId));
6391 CLSIDFromString(package->components
6392 [package->features[i].Components[j]].ComponentId,
6393 &clsid);
6394 encode_base85_guid(&clsid,buf);
6395 TRACE("to %s\n",debugstr_w(buf));
6396 strcatW(data,buf);
6399 if (package->features[i].Feature_Parent[0])
6401 static const WCHAR sep[] = {'\2',0};
6402 strcatW(data,sep);
6403 strcatW(data,package->features[i].Feature_Parent);
6406 size = (strlenW(data)+1)*sizeof(WCHAR);
6407 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
6408 (LPSTR)data,size);
6409 HeapFree(GetProcessHeap(),0,data);
6411 if (!absent)
6413 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
6414 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6415 (LPSTR)package->features[i].Feature_Parent,size);
6417 else
6419 size = (strlenW(package->features[i].Feature_Parent)+2)*
6420 sizeof(WCHAR);
6421 data = HeapAlloc(GetProcessHeap(),0,size);
6422 data[0] = 0x6;
6423 strcpyW(&data[1],package->features[i].Feature_Parent);
6424 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6425 (LPSTR)data,size);
6426 HeapFree(GetProcessHeap(),0,data);
6430 end:
6431 RegCloseKey(hkey);
6432 RegCloseKey(hukey);
6433 HeapFree(GetProcessHeap(), 0, productcode);
6434 return rc;
6437 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
6439 HKEY hkey=0;
6440 LPWSTR buffer;
6441 LPWSTR productcode;
6442 UINT rc,i;
6443 DWORD size;
6444 static WCHAR szNONE[] = {0};
6445 static const WCHAR szWindowsInstaler[] =
6446 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
6447 static const WCHAR szPropKeys[][80] =
6449 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
6450 {'A','R','P','C','O','N','T','A','C','T',0},
6451 {'A','R','P','C','O','M','M','E','N','T','S',0},
6452 {'P','r','o','d','u','c','t','N','a','m','e',0},
6453 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
6454 {'A','R','P','H','E','L','P','L','I','N','K',0},
6455 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
6456 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
6457 {'S','o','u','r','c','e','D','i','r',0},
6458 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
6459 {'A','R','P','R','E','A','D','M','E',0},
6460 {'A','R','P','S','I','Z','E',0},
6461 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
6462 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
6463 {0},
6466 static const WCHAR szRegKeys[][80] =
6468 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
6469 {'C','o','n','t','a','c','t',0},
6470 {'C','o','m','m','e','n','t','s',0},
6471 {'D','i','s','p','l','a','y','N','a','m','e',0},
6472 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
6473 {'H','e','l','p','L','i','n','k',0},
6474 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
6475 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
6476 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
6477 {'P','u','b','l','i','s','h','e','r',0},
6478 {'R','e','a','d','m','e',0},
6479 {'S','i','z','e',0},
6480 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
6481 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
6482 {0},
6485 static const WCHAR installerPathFmt[] = {
6486 '%','s','\\',
6487 'I','n','s','t','a','l','l','e','r','\\',0};
6488 static const WCHAR fmt[] = {
6489 '%','s','\\',
6490 'I','n','s','t','a','l','l','e','r','\\',
6491 '%','x','.','m','s','i',0};
6492 static const WCHAR szLocalPackage[]=
6493 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
6494 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
6495 INT num,start;
6497 if (!package)
6498 return ERROR_INVALID_HANDLE;
6500 productcode = load_dynamic_property(package,szProductCode,&rc);
6501 if (!productcode)
6502 return rc;
6504 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
6505 if (rc != ERROR_SUCCESS)
6506 goto end;
6508 /* dump all the info i can grab */
6509 FIXME("Flesh out more information \n");
6511 i = 0;
6512 while (szPropKeys[i][0]!=0)
6514 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
6515 if (rc != ERROR_SUCCESS)
6516 buffer = szNONE;
6517 size = strlenW(buffer)*sizeof(WCHAR);
6518 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
6519 i++;
6522 rc = 0x1;
6523 size = sizeof(rc);
6524 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
6526 /* copy the package locally */
6527 num = GetTickCount() & 0xffff;
6528 if (!num)
6529 num = 1;
6530 start = num;
6531 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
6532 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
6533 windir,num);
6536 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
6537 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
6538 if (handle != INVALID_HANDLE_VALUE)
6540 CloseHandle(handle);
6541 break;
6543 if (GetLastError() != ERROR_FILE_EXISTS &&
6544 GetLastError() != ERROR_SHARING_VIOLATION)
6545 break;
6546 if (!(++num & 0xffff)) num = 1;
6547 sprintfW(packagefile,fmt,num);
6548 } while (num != start);
6550 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
6551 create_full_pathW(path);
6552 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
6553 if (!CopyFileW(package->PackagePath,packagefile,FALSE))
6554 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
6555 debugstr_w(package->PackagePath), debugstr_w(packagefile),
6556 GetLastError());
6557 size = strlenW(packagefile)*sizeof(WCHAR);
6558 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
6560 end:
6561 HeapFree(GetProcessHeap(),0,productcode);
6562 RegCloseKey(hkey);
6564 return ERROR_SUCCESS;
6567 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
6569 UINT rc;
6571 if (!package)
6572 return ERROR_INVALID_HANDLE;
6574 rc = execute_script(package,INSTALL_SCRIPT);
6576 return rc;
6579 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
6581 UINT rc;
6583 if (!package)
6584 return ERROR_INVALID_HANDLE;
6586 /* turn off scheduleing */
6587 package->script->CurrentlyScripting= FALSE;
6589 /* first do the same as an InstallExecute */
6590 rc = ACTION_InstallExecute(package);
6591 if (rc != ERROR_SUCCESS)
6592 return rc;
6594 /* then handle Commit Actions */
6595 rc = execute_script(package,COMMIT_SCRIPT);
6597 return rc;
6600 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
6602 static const WCHAR RunOnce[] = {
6603 'S','o','f','t','w','a','r','e','\\',
6604 'M','i','c','r','o','s','o','f','t','\\',
6605 'W','i','n','d','o','w','s','\\',
6606 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6607 'R','u','n','O','n','c','e',0};
6608 static const WCHAR InstallRunOnce[] = {
6609 'S','o','f','t','w','a','r','e','\\',
6610 'M','i','c','r','o','s','o','f','t','\\',
6611 'W','i','n','d','o','w','s','\\',
6612 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6613 'I','n','s','t','a','l','l','e','r','\\',
6614 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
6616 static const WCHAR msiexec_fmt[] = {
6617 '%','s',
6618 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
6619 '\"','%','s','\"',0};
6620 static const WCHAR install_fmt[] = {
6621 '/','I',' ','\"','%','s','\"',' ',
6622 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
6623 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
6624 WCHAR buffer[256], sysdir[MAX_PATH];
6625 HKEY hkey,hukey;
6626 LPWSTR productcode;
6627 WCHAR squished_pc[100];
6628 INT rc;
6629 DWORD size;
6630 static const WCHAR szLUS[] = {
6631 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
6632 static const WCHAR szSourceList[] = {
6633 'S','o','u','r','c','e','L','i','s','t',0};
6634 static const WCHAR szPackageName[] = {
6635 'P','a','c','k','a','g','e','N','a','m','e',0};
6637 if (!package)
6638 return ERROR_INVALID_HANDLE;
6640 productcode = load_dynamic_property(package,szProductCode,&rc);
6641 if (!productcode)
6642 return rc;
6644 squash_guid(productcode,squished_pc);
6646 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
6647 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
6648 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
6649 squished_pc);
6651 size = strlenW(buffer)*sizeof(WCHAR);
6652 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6653 RegCloseKey(hkey);
6655 TRACE("Reboot command %s\n",debugstr_w(buffer));
6657 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
6658 sprintfW(buffer,install_fmt,productcode,squished_pc);
6660 size = strlenW(buffer)*sizeof(WCHAR);
6661 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6662 RegCloseKey(hkey);
6664 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6665 if (rc == ERROR_SUCCESS)
6667 HKEY hukey2;
6668 LPWSTR buf;
6669 RegCreateKeyW(hukey, szSourceList, &hukey2);
6670 buf = load_dynamic_property(package,cszSourceDir,NULL);
6671 size = strlenW(buf)*sizeof(WCHAR);
6672 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
6673 HeapFree(GetProcessHeap(),0,buf);
6675 buf = strrchrW(package->PackagePath,'\\');
6676 if (buf)
6678 buf++;
6679 size = strlenW(buf)*sizeof(WCHAR);
6680 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
6683 RegCloseKey(hukey2);
6685 HeapFree(GetProcessHeap(),0,productcode);
6687 return ERROR_INSTALL_SUSPEND;
6690 UINT ACTION_ResolveSource(MSIPACKAGE* package)
6693 * we are currently doing what should be done here in the top level Install
6694 * however for Adminastrative and uninstalls this step will be needed
6696 return ERROR_SUCCESS;
6699 static LPWSTR create_component_advertise_string(MSIPACKAGE* package,
6700 MSICOMPONENT* component, LPCWSTR feature)
6702 LPWSTR productid=NULL;
6703 GUID clsid;
6704 WCHAR productid_85[21];
6705 WCHAR component_85[21];
6707 * I have a fair bit of confusion as to when a < is used and when a > is
6708 * used. I do not think i have it right...
6710 * Ok it appears that the > is used if there is a guid for the compoenent
6711 * and the < is used if not.
6713 static WCHAR fmt1[] = {'%','s','%','s','<',0,0};
6714 static WCHAR fmt2[] = {'%','s','%','s','>','%','s',0,0};
6715 LPWSTR output = NULL;
6716 DWORD sz = 0;
6718 memset(productid_85,0,sizeof(productid_85));
6719 memset(component_85,0,sizeof(component_85));
6721 productid = load_dynamic_property(package,szProductCode,NULL);
6722 CLSIDFromString(productid, &clsid);
6724 encode_base85_guid(&clsid,productid_85);
6726 CLSIDFromString(component->ComponentId, &clsid);
6727 encode_base85_guid(&clsid,component_85);
6729 TRACE("Doing something with this... %s %s %s\n",
6730 debugstr_w(productid_85), debugstr_w(feature),
6731 debugstr_w(component_85));
6733 sz = lstrlenW(productid_85) + lstrlenW(feature);
6734 if (component)
6735 sz += lstrlenW(component_85);
6737 sz+=3;
6738 sz *= sizeof(WCHAR);
6740 output = HeapAlloc(GetProcessHeap(),0,sz);
6741 memset(output,0,sz);
6743 if (component)
6744 sprintfW(output,fmt2,productid_85,feature,component_85);
6745 else
6746 sprintfW(output,fmt1,productid_85,feature);
6748 HeapFree(GetProcessHeap(),0,productid);
6750 return output;
6753 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
6754 MSICOMPONENT* component, MSIEXTENSION* extension,
6755 MSIVERB* verb, INT* Sequence )
6757 LPWSTR keyname;
6758 HKEY key;
6759 static const WCHAR szShell[] = {'s','h','e','l','l',0};
6760 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
6761 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
6762 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
6763 LPWSTR command;
6764 DWORD size;
6765 LPWSTR advertise;
6767 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
6769 TRACE("Making Key %s\n",debugstr_w(keyname));
6770 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6771 size = strlenW(component->FullKeypath);
6772 if (verb->Argument)
6773 size += strlenW(verb->Argument);
6774 size += 4;
6776 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6777 if (verb->Argument)
6778 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
6779 else
6780 sprintfW(command, fmt2, component->FullKeypath);
6782 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)command, (strlenW(command)+1)*
6783 sizeof(WCHAR));
6784 HeapFree(GetProcessHeap(),0,command);
6786 advertise = create_component_advertise_string(package, component,
6787 package->features[extension->FeatureIndex].Feature);
6789 size = strlenW(advertise);
6791 if (verb->Argument)
6792 size += strlenW(verb->Argument);
6793 size += 4;
6795 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6796 memset(command,0,size*sizeof(WCHAR));
6798 strcpyW(command,advertise);
6799 if (verb->Argument)
6801 static const WCHAR szSpace[] = {' ',0};
6802 strcatW(command,szSpace);
6803 strcatW(command,verb->Argument);
6806 RegSetValueExW(key, szCommand, 0, REG_MULTI_SZ, (LPBYTE)command,
6807 (strlenW(command)+2)*sizeof(WCHAR));
6809 RegCloseKey(key);
6810 HeapFree(GetProcessHeap(),0,keyname);
6811 HeapFree(GetProcessHeap(),0,advertise);
6812 HeapFree(GetProcessHeap(),0,command);
6814 if (verb->Command)
6816 keyname = build_directory_name(3, progid, szShell, verb->Verb);
6817 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6818 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Command,
6819 (strlenW(verb->Command)+1) *sizeof(WCHAR));
6820 RegCloseKey(key);
6821 HeapFree(GetProcessHeap(),0,keyname);
6824 if (verb->Sequence != MSI_NULL_INTEGER)
6826 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
6828 *Sequence = verb->Sequence;
6829 keyname = build_directory_name(2, progid, szShell);
6830 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6831 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Verb,
6832 (strlenW(verb->Verb)+1) *sizeof(WCHAR));
6833 RegCloseKey(key);
6834 HeapFree(GetProcessHeap(),0,keyname);
6837 return ERROR_SUCCESS;
6840 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
6842 static const WCHAR szContentType[] =
6843 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
6844 HKEY hkey;
6845 INT i;
6846 MSIRECORD *uirow;
6847 BOOL install_on_demand = TRUE;
6849 if (!package)
6850 return ERROR_INVALID_HANDLE;
6852 load_classes_and_such(package);
6854 /* We need to set install_on_demand based on if the shell handles advertised
6855 * shortcuts and the like. Because Mike McCormack is working on this i am
6856 * going to default to TRUE
6859 for (i = 0; i < package->loaded_extensions; i++)
6861 WCHAR extension[257];
6862 INT index,f_index;
6864 index = package->extensions[i].ComponentIndex;
6865 f_index = package->extensions[i].FeatureIndex;
6867 if (index < 0)
6868 continue;
6871 * yes. MSDN says that these are based on _Feature_ not on
6872 * Component. So verify the feature is to be installed
6874 if ((!ACTION_VerifyFeatureForAction(package, f_index,
6875 INSTALLSTATE_LOCAL)) &&
6876 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
6877 f_index, INSTALLSTATE_ADVERTISED)))
6879 TRACE("Skipping extension %s reg due to disabled feature %s\n",
6880 debugstr_w(package->extensions[i].Extension),
6881 debugstr_w(package->features[f_index].Feature));
6883 continue;
6886 TRACE("Registering extension %s index %i\n",
6887 debugstr_w(package->extensions[i].Extension), i);
6889 package->extensions[i].Installed = TRUE;
6891 /* this is only registered if the extension has at least 1 verb
6892 * according to MSDN
6894 if (package->extensions[i].ProgIDIndex >= 0 &&
6895 package->extensions[i].VerbCount > 0)
6896 mark_progid_for_install(package, package->extensions[i].ProgIDIndex);
6898 if (package->extensions[i].MIMEIndex >= 0)
6899 mark_mime_for_install(package, package->extensions[i].MIMEIndex);
6901 extension[0] = '.';
6902 extension[1] = 0;
6903 strcatW(extension,package->extensions[i].Extension);
6905 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
6907 if (package->extensions[i].MIMEIndex >= 0)
6909 RegSetValueExW(hkey,szContentType,0,REG_SZ,
6910 (LPVOID)package->mimes[package->extensions[i].
6911 MIMEIndex].ContentType,
6912 (strlenW(package->mimes[package->extensions[i].
6913 MIMEIndex].ContentType)+1)*sizeof(WCHAR));
6916 if (package->extensions[i].ProgIDIndex >= 0 ||
6917 package->extensions[i].ProgIDText)
6919 static const WCHAR szSN[] =
6920 {'\\','S','h','e','l','l','N','e','w',0};
6921 HKEY hkey2;
6922 LPWSTR newkey;
6923 LPCWSTR progid;
6924 INT v;
6925 INT Sequence = MSI_NULL_INTEGER;
6927 if (package->extensions[i].ProgIDIndex >= 0)
6928 progid = package->progids[package->extensions[i].
6929 ProgIDIndex].ProgID;
6930 else
6931 progid = package->extensions[i].ProgIDText;
6933 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
6934 (strlenW(progid)+1)*sizeof(WCHAR));
6936 newkey = HeapAlloc(GetProcessHeap(),0,
6937 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
6939 strcpyW(newkey,progid);
6940 strcatW(newkey,szSN);
6941 RegCreateKeyW(hkey,newkey,&hkey2);
6942 RegCloseKey(hkey2);
6944 HeapFree(GetProcessHeap(),0,newkey);
6946 /* do all the verbs */
6947 for (v = 0; v < package->extensions[i].VerbCount; v++)
6948 register_verb(package, progid,
6949 &package->components[index],
6950 &package->extensions[i],
6951 &package->verbs[package->extensions[i].Verbs[v]],
6952 &Sequence);
6955 RegCloseKey(hkey);
6957 uirow = MSI_CreateRecord(1);
6958 MSI_RecordSetStringW(uirow,1,package->extensions[i].Extension);
6959 ui_actiondata(package,szRegisterExtensionInfo,uirow);
6960 msiobj_release(&uirow->hdr);
6963 return ERROR_SUCCESS;
6966 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
6968 static const WCHAR szExten[] =
6969 {'E','x','t','e','n','s','i','o','n',0 };
6970 HKEY hkey;
6971 INT i;
6972 MSIRECORD *uirow;
6974 if (!package)
6975 return ERROR_INVALID_HANDLE;
6977 load_classes_and_such(package);
6979 for (i = 0; i < package->loaded_mimes; i++)
6981 WCHAR extension[257];
6982 LPCWSTR exten;
6983 LPCWSTR mime;
6984 static const WCHAR fmt[] =
6985 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
6986 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
6987 LPWSTR key;
6990 * check if the MIME is to be installed. Either as requesed by an
6991 * extension or Class
6993 package->mimes[i].InstallMe = ((package->mimes[i].InstallMe) ||
6994 (package->mimes[i].ClassIndex >= 0 &&
6995 package->classes[package->mimes[i].ClassIndex].Installed) ||
6996 (package->mimes[i].ExtensionIndex >=0 &&
6997 package->extensions[package->mimes[i].ExtensionIndex].Installed));
6999 if (!package->mimes[i].InstallMe)
7001 TRACE("MIME %s not scheduled to be installed\n",
7002 debugstr_w(package->mimes[i].ContentType));
7003 continue;
7006 mime = package->mimes[i].ContentType;
7007 exten = package->extensions[package->mimes[i].ExtensionIndex].Extension;
7008 extension[0] = '.';
7009 extension[1] = 0;
7010 strcatW(extension,exten);
7012 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
7013 sizeof(WCHAR));
7014 sprintfW(key,fmt,mime);
7015 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
7016 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
7017 (strlenW(extension)+1)*sizeof(WCHAR));
7019 HeapFree(GetProcessHeap(),0,key);
7021 if (package->mimes[i].CLSID[0])
7023 FIXME("Handle non null for field 3\n");
7026 RegCloseKey(hkey);
7028 uirow = MSI_CreateRecord(2);
7029 MSI_RecordSetStringW(uirow,1,package->mimes[i].ContentType);
7030 MSI_RecordSetStringW(uirow,2,exten);
7031 ui_actiondata(package,szRegisterMIMEInfo,uirow);
7032 msiobj_release(&uirow->hdr);
7035 return ERROR_SUCCESS;
7038 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
7040 static const WCHAR szProductID[]=
7041 {'P','r','o','d','u','c','t','I','D',0};
7042 HKEY hkey=0;
7043 LPWSTR buffer;
7044 LPWSTR productcode;
7045 LPWSTR productid;
7046 UINT rc,i;
7047 DWORD size;
7049 static const WCHAR szPropKeys[][80] =
7051 {'P','r','o','d','u','c','t','I','D',0},
7052 {'U','S','E','R','N','A','M','E',0},
7053 {'C','O','M','P','A','N','Y','N','A','M','E',0},
7054 {0},
7057 static const WCHAR szRegKeys[][80] =
7059 {'P','r','o','d','u','c','t','I','D',0},
7060 {'R','e','g','O','w','n','e','r',0},
7061 {'R','e','g','C','o','m','p','a','n','y',0},
7062 {0},
7065 if (!package)
7066 return ERROR_INVALID_HANDLE;
7068 productid = load_dynamic_property(package,szProductID,&rc);
7069 if (!productid)
7070 return ERROR_SUCCESS;
7072 productcode = load_dynamic_property(package,szProductCode,&rc);
7073 if (!productcode)
7074 return rc;
7076 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
7077 if (rc != ERROR_SUCCESS)
7078 goto end;
7080 i = 0;
7081 while (szPropKeys[i][0]!=0)
7083 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
7084 if (rc == ERROR_SUCCESS)
7086 size = strlenW(buffer)*sizeof(WCHAR);
7087 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
7089 else
7090 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
7091 i++;
7094 end:
7095 HeapFree(GetProcessHeap(),0,productcode);
7096 HeapFree(GetProcessHeap(),0,productid);
7097 RegCloseKey(hkey);
7099 return ERROR_SUCCESS;
7103 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
7105 UINT rc;
7106 rc = ACTION_ProcessExecSequence(package,FALSE);
7107 return rc;
7112 * Code based off of code located here
7113 * http://www.codeproject.com/gdi/fontnamefromfile.asp
7115 * Using string index 4 (full font name) instead of 1 (family name)
7117 static LPWSTR load_ttfname_from(LPCWSTR filename)
7119 HANDLE handle;
7120 LPWSTR ret = NULL;
7121 int i;
7123 typedef struct _tagTT_OFFSET_TABLE{
7124 USHORT uMajorVersion;
7125 USHORT uMinorVersion;
7126 USHORT uNumOfTables;
7127 USHORT uSearchRange;
7128 USHORT uEntrySelector;
7129 USHORT uRangeShift;
7130 }TT_OFFSET_TABLE;
7132 typedef struct _tagTT_TABLE_DIRECTORY{
7133 char szTag[4]; /* table name */
7134 ULONG uCheckSum; /* Check sum */
7135 ULONG uOffset; /* Offset from beginning of file */
7136 ULONG uLength; /* length of the table in bytes */
7137 }TT_TABLE_DIRECTORY;
7139 typedef struct _tagTT_NAME_TABLE_HEADER{
7140 USHORT uFSelector; /* format selector. Always 0 */
7141 USHORT uNRCount; /* Name Records count */
7142 USHORT uStorageOffset; /* Offset for strings storage,
7143 * from start of the table */
7144 }TT_NAME_TABLE_HEADER;
7146 typedef struct _tagTT_NAME_RECORD{
7147 USHORT uPlatformID;
7148 USHORT uEncodingID;
7149 USHORT uLanguageID;
7150 USHORT uNameID;
7151 USHORT uStringLength;
7152 USHORT uStringOffset; /* from start of storage area */
7153 }TT_NAME_RECORD;
7155 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
7156 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
7158 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
7159 FILE_ATTRIBUTE_NORMAL, 0 );
7160 if (handle != INVALID_HANDLE_VALUE)
7162 TT_TABLE_DIRECTORY tblDir;
7163 BOOL bFound = FALSE;
7164 TT_OFFSET_TABLE ttOffsetTable;
7166 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
7167 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
7168 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
7169 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
7171 if (ttOffsetTable.uMajorVersion != 1 ||
7172 ttOffsetTable.uMinorVersion != 0)
7173 return NULL;
7175 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
7177 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
7178 if (strncmp(tblDir.szTag,"name",4)==0)
7180 bFound = TRUE;
7181 tblDir.uLength = SWAPLONG(tblDir.uLength);
7182 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
7183 break;
7187 if (bFound)
7189 TT_NAME_TABLE_HEADER ttNTHeader;
7190 TT_NAME_RECORD ttRecord;
7192 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
7193 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
7194 NULL,NULL);
7196 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
7197 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
7198 bFound = FALSE;
7199 for(i=0; i<ttNTHeader.uNRCount; i++)
7201 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
7202 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
7203 /* 4 is the Full Font Name */
7204 if(ttRecord.uNameID == 4)
7206 int nPos;
7207 LPSTR buf;
7208 static const LPSTR tt = " (TrueType)";
7210 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
7211 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
7212 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
7213 SetFilePointer(handle, tblDir.uOffset +
7214 ttRecord.uStringOffset +
7215 ttNTHeader.uStorageOffset,
7216 NULL, FILE_BEGIN);
7217 buf = HeapAlloc(GetProcessHeap(), 0,
7218 ttRecord.uStringLength + 1 + strlen(tt));
7219 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
7220 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
7221 if (strlen(buf) > 0)
7223 strcat(buf,tt);
7224 ret = strdupAtoW(buf);
7225 HeapFree(GetProcessHeap(),0,buf);
7226 break;
7229 HeapFree(GetProcessHeap(),0,buf);
7230 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
7234 CloseHandle(handle);
7236 else
7237 ERR("Unable to open font file %s\n", debugstr_w(filename));
7239 TRACE("Returning fontname %s\n",debugstr_w(ret));
7240 return ret;
7243 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
7245 UINT rc;
7246 MSIQUERY * view;
7247 MSIRECORD * row = 0;
7248 static const WCHAR ExecSeqQuery[] =
7249 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7250 '`','F','o','n','t','`',0};
7251 static const WCHAR regfont1[] =
7252 {'S','o','f','t','w','a','r','e','\\',
7253 'M','i','c','r','o','s','o','f','t','\\',
7254 'W','i','n','d','o','w','s',' ','N','T','\\',
7255 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7256 'F','o','n','t','s',0};
7257 static const WCHAR regfont2[] =
7258 {'S','o','f','t','w','a','r','e','\\',
7259 'M','i','c','r','o','s','o','f','t','\\',
7260 'W','i','n','d','o','w','s','\\',
7261 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7262 'F','o','n','t','s',0};
7263 HKEY hkey1;
7264 HKEY hkey2;
7266 TRACE("%p\n", package);
7268 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7269 if (rc != ERROR_SUCCESS)
7271 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
7272 return ERROR_SUCCESS;
7275 rc = MSI_ViewExecute(view, 0);
7276 if (rc != ERROR_SUCCESS)
7278 MSI_ViewClose(view);
7279 msiobj_release(&view->hdr);
7280 TRACE("MSI_ViewExecute returned %d\n", rc);
7281 return ERROR_SUCCESS;
7284 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
7285 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
7287 while (1)
7289 LPWSTR name;
7290 LPWSTR file;
7291 UINT index;
7292 DWORD size;
7294 rc = MSI_ViewFetch(view,&row);
7295 if (rc != ERROR_SUCCESS)
7297 rc = ERROR_SUCCESS;
7298 break;
7301 file = load_dynamic_stringW(row,1);
7302 index = get_loaded_file(package,file);
7303 if (index < 0)
7305 ERR("Unable to load file\n");
7306 HeapFree(GetProcessHeap(),0,file);
7307 continue;
7310 /* check to make sure that component is installed */
7311 if (!ACTION_VerifyComponentForAction(package,
7312 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
7314 TRACE("Skipping: Component not scheduled for install\n");
7315 HeapFree(GetProcessHeap(),0,file);
7317 msiobj_release(&row->hdr);
7319 continue;
7322 if (MSI_RecordIsNull(row,2))
7323 name = load_ttfname_from(package->files[index].TargetPath);
7324 else
7325 name = load_dynamic_stringW(row,2);
7327 if (name)
7329 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
7330 RegSetValueExW(hkey1,name,0,REG_SZ,
7331 (LPBYTE)package->files[index].FileName,size);
7332 RegSetValueExW(hkey2,name,0,REG_SZ,
7333 (LPBYTE)package->files[index].FileName,size);
7336 HeapFree(GetProcessHeap(),0,file);
7337 HeapFree(GetProcessHeap(),0,name);
7338 msiobj_release(&row->hdr);
7340 MSI_ViewClose(view);
7341 msiobj_release(&view->hdr);
7343 RegCloseKey(hkey1);
7344 RegCloseKey(hkey2);
7346 TRACE("returning %d\n", rc);
7347 return rc;
7350 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
7352 MSIPACKAGE *package = (MSIPACKAGE*)param;
7353 LPWSTR compgroupid=NULL;
7354 LPWSTR feature=NULL;
7355 LPWSTR text = NULL;
7356 LPWSTR qualifier = NULL;
7357 LPWSTR component = NULL;
7358 LPWSTR advertise = NULL;
7359 LPWSTR output = NULL;
7360 HKEY hkey;
7361 UINT rc = ERROR_SUCCESS;
7362 UINT index;
7363 DWORD sz = 0;
7365 component = load_dynamic_stringW(rec,3);
7366 index = get_loaded_component(package,component);
7368 if (!ACTION_VerifyComponentForAction(package, index,
7369 INSTALLSTATE_LOCAL) &&
7370 !ACTION_VerifyComponentForAction(package, index,
7371 INSTALLSTATE_SOURCE) &&
7372 !ACTION_VerifyComponentForAction(package, index,
7373 INSTALLSTATE_ADVERTISED))
7375 TRACE("Skipping: Component %s not scheduled for install\n",
7376 debugstr_w(component));
7378 HeapFree(GetProcessHeap(),0,component);
7379 return ERROR_SUCCESS;
7382 compgroupid = load_dynamic_stringW(rec,1);
7384 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
7385 if (rc != ERROR_SUCCESS)
7386 goto end;
7388 text = load_dynamic_stringW(rec,4);
7389 qualifier = load_dynamic_stringW(rec,2);
7390 feature = load_dynamic_stringW(rec,5);
7392 advertise = create_component_advertise_string(package,
7393 &package->components[index], feature);
7395 sz = strlenW(advertise);
7397 if (text)
7398 sz += lstrlenW(text);
7400 sz+=3;
7401 sz *= sizeof(WCHAR);
7403 output = HeapAlloc(GetProcessHeap(),0,sz);
7404 memset(output,0,sz);
7405 strcpyW(output,advertise);
7407 if (text)
7408 strcatW(output,text);
7410 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
7411 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
7413 end:
7414 RegCloseKey(hkey);
7415 HeapFree(GetProcessHeap(),0,output);
7416 HeapFree(GetProcessHeap(),0,compgroupid);
7417 HeapFree(GetProcessHeap(),0,component);
7418 HeapFree(GetProcessHeap(),0,feature);
7419 HeapFree(GetProcessHeap(),0,text);
7420 HeapFree(GetProcessHeap(),0,qualifier);
7422 return rc;
7426 * At present I am ignorning the advertised components part of this and only
7427 * focusing on the qualified component sets
7429 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
7431 UINT rc;
7432 MSIQUERY * view;
7433 static const WCHAR ExecSeqQuery[] =
7434 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7435 '`','P','u','b','l','i','s','h',
7436 'C','o','m','p','o','n','e','n','t','`',0};
7438 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7439 if (rc != ERROR_SUCCESS)
7440 return ERROR_SUCCESS;
7442 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
7443 msiobj_release(&view->hdr);
7445 return rc;
7448 /* Msi functions that seem appropriate here */
7450 /***********************************************************************
7451 * MsiDoActionA (MSI.@)
7453 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
7455 LPWSTR szwAction;
7456 UINT rc;
7458 TRACE(" exteral attempt at action %s\n",szAction);
7460 if (!szAction)
7461 return ERROR_FUNCTION_FAILED;
7462 if (hInstall == 0)
7463 return ERROR_FUNCTION_FAILED;
7465 szwAction = strdupAtoW(szAction);
7467 if (!szwAction)
7468 return ERROR_FUNCTION_FAILED;
7471 rc = MsiDoActionW(hInstall, szwAction);
7472 HeapFree(GetProcessHeap(),0,szwAction);
7473 return rc;
7476 /***********************************************************************
7477 * MsiDoActionW (MSI.@)
7479 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
7481 MSIPACKAGE *package;
7482 UINT ret = ERROR_INVALID_HANDLE;
7484 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
7486 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7487 if( package )
7489 ret = ACTION_PerformUIAction(package,szAction);
7490 msiobj_release( &package->hdr );
7492 return ret;
7495 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
7496 LPSTR szPathBuf, DWORD* pcchPathBuf)
7498 LPWSTR szwFolder;
7499 LPWSTR szwPathBuf;
7500 UINT rc;
7502 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7504 if (!szFolder)
7505 return ERROR_FUNCTION_FAILED;
7506 if (hInstall == 0)
7507 return ERROR_FUNCTION_FAILED;
7509 szwFolder = strdupAtoW(szFolder);
7511 if (!szwFolder)
7512 return ERROR_FUNCTION_FAILED;
7514 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7516 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7518 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7519 *pcchPathBuf, NULL, NULL );
7521 HeapFree(GetProcessHeap(),0,szwFolder);
7522 HeapFree(GetProcessHeap(),0,szwPathBuf);
7524 return rc;
7527 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7528 szPathBuf, DWORD* pcchPathBuf)
7530 LPWSTR path;
7531 UINT rc = ERROR_FUNCTION_FAILED;
7532 MSIPACKAGE *package;
7534 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7536 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7537 if (!package)
7538 return ERROR_INVALID_HANDLE;
7539 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
7540 msiobj_release( &package->hdr );
7542 if (path && (strlenW(path) > *pcchPathBuf))
7544 *pcchPathBuf = strlenW(path)+1;
7545 rc = ERROR_MORE_DATA;
7547 else if (path)
7549 *pcchPathBuf = strlenW(path)+1;
7550 strcpyW(szPathBuf,path);
7551 TRACE("Returning Path %s\n",debugstr_w(path));
7552 rc = ERROR_SUCCESS;
7554 HeapFree(GetProcessHeap(),0,path);
7556 return rc;
7560 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
7561 LPSTR szPathBuf, DWORD* pcchPathBuf)
7563 LPWSTR szwFolder;
7564 LPWSTR szwPathBuf;
7565 UINT rc;
7567 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7569 if (!szFolder)
7570 return ERROR_FUNCTION_FAILED;
7571 if (hInstall == 0)
7572 return ERROR_FUNCTION_FAILED;
7574 szwFolder = strdupAtoW(szFolder);
7575 if (!szwFolder)
7576 return ERROR_FUNCTION_FAILED;
7578 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7580 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7582 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7583 *pcchPathBuf, NULL, NULL );
7585 HeapFree(GetProcessHeap(),0,szwFolder);
7586 HeapFree(GetProcessHeap(),0,szwPathBuf);
7588 return rc;
7591 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7592 szPathBuf, DWORD* pcchPathBuf)
7594 LPWSTR path;
7595 UINT rc = ERROR_FUNCTION_FAILED;
7596 MSIPACKAGE *package;
7598 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7600 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7601 if( !package )
7602 return ERROR_INVALID_HANDLE;
7603 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
7604 msiobj_release( &package->hdr );
7606 if (path && strlenW(path) > *pcchPathBuf)
7608 *pcchPathBuf = strlenW(path)+1;
7609 rc = ERROR_MORE_DATA;
7611 else if (path)
7613 *pcchPathBuf = strlenW(path)+1;
7614 strcpyW(szPathBuf,path);
7615 TRACE("Returning Path %s\n",debugstr_w(path));
7616 rc = ERROR_SUCCESS;
7618 HeapFree(GetProcessHeap(),0,path);
7620 return rc;
7624 /***********************************************************************
7625 * MsiSetTargetPathA (MSI.@)
7627 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
7628 LPCSTR szFolderPath)
7630 LPWSTR szwFolder;
7631 LPWSTR szwFolderPath;
7632 UINT rc;
7634 if (!szFolder)
7635 return ERROR_FUNCTION_FAILED;
7636 if (hInstall == 0)
7637 return ERROR_FUNCTION_FAILED;
7639 szwFolder = strdupAtoW(szFolder);
7640 if (!szwFolder)
7641 return ERROR_FUNCTION_FAILED;
7643 szwFolderPath = strdupAtoW(szFolderPath);
7644 if (!szwFolderPath)
7646 HeapFree(GetProcessHeap(),0,szwFolder);
7647 return ERROR_FUNCTION_FAILED;
7650 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
7652 HeapFree(GetProcessHeap(),0,szwFolder);
7653 HeapFree(GetProcessHeap(),0,szwFolderPath);
7655 return rc;
7658 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
7659 LPCWSTR szFolderPath)
7661 DWORD i;
7662 LPWSTR path = NULL;
7663 LPWSTR path2 = NULL;
7664 MSIFOLDER *folder;
7666 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
7668 if (package==NULL)
7669 return ERROR_INVALID_HANDLE;
7671 if (szFolderPath[0]==0)
7672 return ERROR_FUNCTION_FAILED;
7674 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
7675 return ERROR_FUNCTION_FAILED;
7677 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
7679 if (!path)
7680 return ERROR_INVALID_PARAMETER;
7682 HeapFree(GetProcessHeap(),0,folder->Property);
7683 folder->Property = build_directory_name(2, szFolderPath, NULL);
7685 if (lstrcmpiW(path, folder->Property) == 0)
7688 * Resolved Target has not really changed, so just
7689 * set this folder and do not recalculate everything.
7691 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
7692 folder->ResolvedTarget = NULL;
7693 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
7694 HeapFree(GetProcessHeap(),0,path2);
7696 else
7698 for (i = 0; i < package->loaded_folders; i++)
7700 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
7701 package->folders[i].ResolvedTarget=NULL;
7704 for (i = 0; i < package->loaded_folders; i++)
7706 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
7707 TRUE, NULL);
7708 HeapFree(GetProcessHeap(),0,path2);
7711 HeapFree(GetProcessHeap(),0,path);
7713 return ERROR_SUCCESS;
7716 /***********************************************************************
7717 * MsiSetTargetPathW (MSI.@)
7719 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
7720 LPCWSTR szFolderPath)
7722 MSIPACKAGE *package;
7723 UINT ret;
7725 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
7727 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7728 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
7729 msiobj_release( &package->hdr );
7730 return ret;
7733 /***********************************************************************
7734 * MsiGetMode (MSI.@)
7736 * Returns an internal installer state (if it is running in a mode iRunMode)
7738 * PARAMS
7739 * hInstall [I] Handle to the installation
7740 * hRunMode [I] Checking run mode
7741 * MSIRUNMODE_ADMIN Administrative mode
7742 * MSIRUNMODE_ADVERTISE Advertisement mode
7743 * MSIRUNMODE_MAINTENANCE Maintenance mode
7744 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
7745 * MSIRUNMODE_LOGENABLED Log file is writing
7746 * MSIRUNMODE_OPERATIONS Operations in progress??
7747 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
7748 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
7749 * MSIRUNMODE_CABINET Files from cabinet are installed
7750 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
7751 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
7752 * MSIRUNMODE_RESERVED11 Reserved
7753 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
7754 * MSIRUNMODE_ZAWENABLED Demand installation is supported
7755 * MSIRUNMODE_RESERVED14 Reserved
7756 * MSIRUNMODE_RESERVED15 Reserved
7757 * MSIRUNMODE_SCHEDULED called from install script
7758 * MSIRUNMODE_ROLLBACK called from rollback script
7759 * MSIRUNMODE_COMMIT called from commit script
7761 * RETURNS
7762 * In the state: TRUE
7763 * Not in the state: FALSE
7767 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
7769 FIXME("STUB (iRunMode=%i)\n",iRunMode);
7770 return TRUE;
7773 /***********************************************************************
7774 * MsiSetFeatureStateA (MSI.@)
7776 * According to the docs, when this is called it immediately recalculates
7777 * all the component states as well
7779 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
7780 INSTALLSTATE iState)
7782 LPWSTR szwFeature = NULL;
7783 UINT rc;
7785 szwFeature = strdupAtoW(szFeature);
7787 if (!szwFeature)
7788 return ERROR_FUNCTION_FAILED;
7790 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
7792 HeapFree(GetProcessHeap(),0,szwFeature);
7794 return rc;
7799 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
7800 INSTALLSTATE iState)
7802 INT index, i;
7803 UINT rc = ERROR_SUCCESS;
7805 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7807 index = get_loaded_feature(package,szFeature);
7808 if (index < 0)
7809 return ERROR_UNKNOWN_FEATURE;
7811 if (iState == INSTALLSTATE_ADVERTISED &&
7812 package->features[index].Attributes &
7813 msidbFeatureAttributesDisallowAdvertise)
7814 return ERROR_FUNCTION_FAILED;
7816 package->features[index].ActionRequest= iState;
7817 package->features[index].Action= iState;
7819 ACTION_UpdateComponentStates(package,szFeature);
7821 /* update all the features that are children of this feature */
7822 for (i = 0; i < package->loaded_features; i++)
7824 if (strcmpW(szFeature, package->features[i].Feature_Parent) == 0)
7825 MSI_SetFeatureStateW(package, package->features[i].Feature, iState);
7828 return rc;
7831 /***********************************************************************
7832 * MsiSetFeatureStateW (MSI.@)
7834 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
7835 INSTALLSTATE iState)
7837 MSIPACKAGE* package;
7838 UINT rc = ERROR_SUCCESS;
7840 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7842 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7843 if (!package)
7844 return ERROR_INVALID_HANDLE;
7846 rc = MSI_SetFeatureStateW(package,szFeature,iState);
7848 msiobj_release( &package->hdr );
7849 return rc;
7852 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
7853 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7855 LPWSTR szwFeature = NULL;
7856 UINT rc;
7858 szwFeature = strdupAtoW(szFeature);
7860 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
7862 HeapFree( GetProcessHeap(), 0 , szwFeature);
7864 return rc;
7867 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
7868 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7870 INT index;
7872 index = get_loaded_feature(package,szFeature);
7873 if (index < 0)
7874 return ERROR_UNKNOWN_FEATURE;
7876 if (piInstalled)
7877 *piInstalled = package->features[index].Installed;
7879 if (piAction)
7880 *piAction = package->features[index].Action;
7882 TRACE("returning %i %i\n",*piInstalled,*piAction);
7884 return ERROR_SUCCESS;
7887 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
7888 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7890 MSIPACKAGE* package;
7891 UINT ret;
7893 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
7894 piAction);
7896 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7897 if (!package)
7898 return ERROR_INVALID_HANDLE;
7899 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
7900 msiobj_release( &package->hdr );
7901 return ret;
7904 /***********************************************************************
7905 * MsiGetComponentStateA (MSI.@)
7907 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
7908 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7910 LPWSTR szwComponent= NULL;
7911 UINT rc;
7913 szwComponent= strdupAtoW(szComponent);
7915 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
7917 HeapFree( GetProcessHeap(), 0 , szwComponent);
7919 return rc;
7922 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
7923 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7925 INT index;
7927 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
7928 piAction);
7930 index = get_loaded_component(package,szComponent);
7931 if (index < 0)
7932 return ERROR_UNKNOWN_COMPONENT;
7934 if (piInstalled)
7935 *piInstalled = package->components[index].Installed;
7937 if (piAction)
7938 *piAction = package->components[index].Action;
7940 TRACE("states (%i, %i)\n",
7941 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
7943 return ERROR_SUCCESS;
7946 /***********************************************************************
7947 * MsiGetComponentStateW (MSI.@)
7949 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
7950 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7952 MSIPACKAGE* package;
7953 UINT ret;
7955 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
7956 piInstalled, piAction);
7958 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7959 if (!package)
7960 return ERROR_INVALID_HANDLE;
7961 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
7962 msiobj_release( &package->hdr );
7963 return ret;