Display the correct text string in the action text field for the
[wine/multimedia.git] / dlls / msi / action.c
blob21387fac6b8ace03c923060de025a5a2098db992
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004,2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 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>
31 #define COBJMACROS
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winerror.h"
36 #include "winreg.h"
37 #include "wine/debug.h"
38 #include "msidefs.h"
39 #include "msipriv.h"
40 #include "winuser.h"
41 #include "shlobj.h"
42 #include "wine/unicode.h"
43 #include "winver.h"
44 #include "action.h"
46 #define REG_PROGRESS_VALUE 13200
47 #define COMPONENT_PROGRESS_VALUE 24000
49 WINE_DEFAULT_DEBUG_CHANNEL(msi);
52 * Prototypes
54 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
55 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
56 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI);
58 /*
59 * action handlers
61 typedef UINT (*STANDARDACTIONHANDLER)(MSIPACKAGE*);
63 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
64 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
65 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
66 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
67 static UINT ACTION_FileCost(MSIPACKAGE *package);
68 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
69 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
70 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
71 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
72 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
73 static UINT ACTION_RegisterUser(MSIPACKAGE *package);
74 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
75 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
76 static UINT ACTION_WriteIniValues(MSIPACKAGE *package);
77 static UINT ACTION_SelfRegModules(MSIPACKAGE *package);
78 static UINT ACTION_PublishFeatures(MSIPACKAGE *package);
79 static UINT ACTION_RegisterProduct(MSIPACKAGE *package);
80 static UINT ACTION_InstallExecute(MSIPACKAGE *package);
81 static UINT ACTION_InstallFinalize(MSIPACKAGE *package);
82 static UINT ACTION_ForceReboot(MSIPACKAGE *package);
83 static UINT ACTION_ResolveSource(MSIPACKAGE *package);
84 static UINT ACTION_ExecuteAction(MSIPACKAGE *package);
85 static UINT ACTION_RegisterFonts(MSIPACKAGE *package);
86 static UINT ACTION_PublishComponents(MSIPACKAGE *package);
89 * consts and values used
91 static const WCHAR c_colon[] = {'C',':','\\',0};
93 const static WCHAR szCreateFolders[] =
94 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
95 const static WCHAR szCostFinalize[] =
96 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
97 const WCHAR szInstallFiles[] =
98 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
99 const WCHAR szDuplicateFiles[] =
100 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
101 const static WCHAR szWriteRegistryValues[] =
102 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
103 'V','a','l','u','e','s',0};
104 const static WCHAR szCostInitialize[] =
105 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
106 const static WCHAR szFileCost[] =
107 {'F','i','l','e','C','o','s','t',0};
108 const static WCHAR szInstallInitialize[] =
109 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
110 const static WCHAR szInstallValidate[] =
111 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
112 const static WCHAR szLaunchConditions[] =
113 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
114 const static WCHAR szProcessComponents[] =
115 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
116 const static WCHAR szRegisterTypeLibraries[] =
117 {'R','e','g','i','s','t','e','r','T','y','p','e',
118 'L','i','b','r','a','r','i','e','s',0};
119 const WCHAR szRegisterClassInfo[] =
120 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
121 const WCHAR szRegisterProgIdInfo[] =
122 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
123 const static WCHAR szCreateShortcuts[] =
124 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
125 const static WCHAR szPublishProduct[] =
126 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
127 const static WCHAR szWriteIniValues[] =
128 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
129 const static WCHAR szSelfRegModules[] =
130 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
131 const static WCHAR szPublishFeatures[] =
132 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
133 const static WCHAR szRegisterProduct[] =
134 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
135 const static WCHAR szInstallExecute[] =
136 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
137 const static WCHAR szInstallExecuteAgain[] =
138 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
139 'A','g','a','i','n',0};
140 const static WCHAR szInstallFinalize[] =
141 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
142 const static WCHAR szForceReboot[] =
143 {'F','o','r','c','e','R','e','b','o','o','t',0};
144 const static WCHAR szResolveSource[] =
145 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
146 const WCHAR szAppSearch[] =
147 {'A','p','p','S','e','a','r','c','h',0};
148 const static WCHAR szAllocateRegistrySpace[] =
149 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
150 'S','p','a','c','e',0};
151 const static WCHAR szBindImage[] =
152 {'B','i','n','d','I','m','a','g','e',0};
153 const static WCHAR szCCPSearch[] =
154 {'C','C','P','S','e','a','r','c','h',0};
155 const static WCHAR szDeleteServices[] =
156 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
157 const static WCHAR szDisableRollback[] =
158 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
159 const static WCHAR szExecuteAction[] =
160 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
161 const WCHAR szFindRelatedProducts[] =
162 {'F','i','n','d','R','e','l','a','t','e','d',
163 'P','r','o','d','u','c','t','s',0};
164 const static WCHAR szInstallAdminPackage[] =
165 {'I','n','s','t','a','l','l','A','d','m','i','n',
166 'P','a','c','k','a','g','e',0};
167 const static WCHAR szInstallSFPCatalogFile[] =
168 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
169 'F','i','l','e',0};
170 const static WCHAR szIsolateComponents[] =
171 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
172 const WCHAR szMigrateFeatureStates[] =
173 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
174 'S','t','a','t','e','s',0};
175 const WCHAR szMoveFiles[] =
176 {'M','o','v','e','F','i','l','e','s',0};
177 const static WCHAR szMsiPublishAssemblies[] =
178 {'M','s','i','P','u','b','l','i','s','h',
179 'A','s','s','e','m','b','l','i','e','s',0};
180 const static WCHAR szMsiUnpublishAssemblies[] =
181 {'M','s','i','U','n','p','u','b','l','i','s','h',
182 'A','s','s','e','m','b','l','i','e','s',0};
183 const static WCHAR szInstallODBC[] =
184 {'I','n','s','t','a','l','l','O','D','B','C',0};
185 const static WCHAR szInstallServices[] =
186 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
187 const WCHAR szPatchFiles[] =
188 {'P','a','t','c','h','F','i','l','e','s',0};
189 const static WCHAR szPublishComponents[] =
190 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
191 const static WCHAR szRegisterComPlus[] =
192 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
193 const WCHAR szRegisterExtensionInfo[] =
194 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
195 'I','n','f','o',0};
196 const static WCHAR szRegisterFonts[] =
197 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
198 const WCHAR szRegisterMIMEInfo[] =
199 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
200 const static WCHAR szRegisterUser[] =
201 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
202 const WCHAR szRemoveDuplicateFiles[] =
203 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
204 'F','i','l','e','s',0};
205 const static WCHAR szRemoveEnvironmentStrings[] =
206 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
207 'S','t','r','i','n','g','s',0};
208 const WCHAR szRemoveExistingProducts[] =
209 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
210 'P','r','o','d','u','c','t','s',0};
211 const WCHAR szRemoveFiles[] =
212 {'R','e','m','o','v','e','F','i','l','e','s',0};
213 const static WCHAR szRemoveFolders[] =
214 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
215 const static WCHAR szRemoveIniValues[] =
216 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
217 const static WCHAR szRemoveODBC[] =
218 {'R','e','m','o','v','e','O','D','B','C',0};
219 const static WCHAR szRemoveRegistryValues[] =
220 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
221 'V','a','l','u','e','s',0};
222 const static WCHAR szRemoveShortcuts[] =
223 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
224 const static WCHAR szRMCCPSearch[] =
225 {'R','M','C','C','P','S','e','a','r','c','h',0};
226 const static WCHAR szScheduleReboot[] =
227 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
228 const static WCHAR szSelfUnregModules[] =
229 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
230 const static WCHAR szSetODBCFolders[] =
231 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
232 const static WCHAR szStartServices[] =
233 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
234 const static WCHAR szStopServices[] =
235 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
236 const static WCHAR szUnpublishComponents[] =
237 {'U','n','p','u','b','l','i','s','h',
238 'C','o','m','p','o','n','e','n','t','s',0};
239 const static WCHAR szUnpublishFeatures[] =
240 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
241 const WCHAR szUnregisterClassInfo[] =
242 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
243 'I','n','f','o',0};
244 const static WCHAR szUnregisterComPlus[] =
245 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
246 const WCHAR szUnregisterExtensionInfo[] =
247 {'U','n','r','e','g','i','s','t','e','r',
248 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
249 const static WCHAR szUnregisterFonts[] =
250 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
251 const WCHAR szUnregisterMIMEInfo[] =
252 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
253 const WCHAR szUnregisterProgIdInfo[] =
254 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
255 'I','n','f','o',0};
256 const static WCHAR szUnregisterTypeLibraries[] =
257 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
258 'L','i','b','r','a','r','i','e','s',0};
259 const static WCHAR szValidateProductID[] =
260 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
261 const static WCHAR szWriteEnvironmentStrings[] =
262 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
263 'S','t','r','i','n','g','s',0};
265 struct _actions {
266 LPCWSTR action;
267 STANDARDACTIONHANDLER handler;
270 static struct _actions StandardActions[] = {
271 { szAllocateRegistrySpace, NULL},
272 { szAppSearch, ACTION_AppSearch },
273 { szBindImage, NULL},
274 { szCCPSearch, NULL},
275 { szCostFinalize, ACTION_CostFinalize },
276 { szCostInitialize, ACTION_CostInitialize },
277 { szCreateFolders, ACTION_CreateFolders },
278 { szCreateShortcuts, ACTION_CreateShortcuts },
279 { szDeleteServices, NULL},
280 { szDisableRollback, NULL},
281 { szDuplicateFiles, ACTION_DuplicateFiles },
282 { szExecuteAction, ACTION_ExecuteAction },
283 { szFileCost, ACTION_FileCost },
284 { szFindRelatedProducts, ACTION_FindRelatedProducts },
285 { szForceReboot, ACTION_ForceReboot },
286 { szInstallAdminPackage, NULL},
287 { szInstallExecute, ACTION_InstallExecute },
288 { szInstallExecuteAgain, ACTION_InstallExecute },
289 { szInstallFiles, ACTION_InstallFiles},
290 { szInstallFinalize, ACTION_InstallFinalize },
291 { szInstallInitialize, ACTION_InstallInitialize },
292 { szInstallSFPCatalogFile, NULL},
293 { szInstallValidate, ACTION_InstallValidate },
294 { szIsolateComponents, NULL},
295 { szLaunchConditions, ACTION_LaunchConditions },
296 { szMigrateFeatureStates, NULL},
297 { szMoveFiles, NULL},
298 { szMsiPublishAssemblies, NULL},
299 { szMsiUnpublishAssemblies, NULL},
300 { szInstallODBC, NULL},
301 { szInstallServices, NULL},
302 { szPatchFiles, NULL},
303 { szProcessComponents, ACTION_ProcessComponents },
304 { szPublishComponents, ACTION_PublishComponents },
305 { szPublishFeatures, ACTION_PublishFeatures },
306 { szPublishProduct, ACTION_PublishProduct },
307 { szRegisterClassInfo, ACTION_RegisterClassInfo },
308 { szRegisterComPlus, NULL},
309 { szRegisterExtensionInfo, ACTION_RegisterExtensionInfo },
310 { szRegisterFonts, ACTION_RegisterFonts },
311 { szRegisterMIMEInfo, ACTION_RegisterMIMEInfo },
312 { szRegisterProduct, ACTION_RegisterProduct },
313 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
314 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
315 { szRegisterUser, ACTION_RegisterUser},
316 { szRemoveDuplicateFiles, NULL},
317 { szRemoveEnvironmentStrings, NULL},
318 { szRemoveExistingProducts, NULL},
319 { szRemoveFiles, NULL},
320 { szRemoveFolders, NULL},
321 { szRemoveIniValues, NULL},
322 { szRemoveODBC, NULL},
323 { szRemoveRegistryValues, NULL},
324 { szRemoveShortcuts, NULL},
325 { szResolveSource, ACTION_ResolveSource},
326 { szRMCCPSearch, NULL},
327 { szScheduleReboot, NULL},
328 { szSelfRegModules, ACTION_SelfRegModules },
329 { szSelfUnregModules, NULL},
330 { szSetODBCFolders, NULL},
331 { szStartServices, NULL},
332 { szStopServices, NULL},
333 { szUnpublishComponents, NULL},
334 { szUnpublishFeatures, NULL},
335 { szUnregisterClassInfo, NULL},
336 { szUnregisterComPlus, NULL},
337 { szUnregisterExtensionInfo, NULL},
338 { szUnregisterFonts, NULL},
339 { szUnregisterMIMEInfo, NULL},
340 { szUnregisterProgIdInfo, NULL},
341 { szUnregisterTypeLibraries, NULL},
342 { szValidateProductID, NULL},
343 { szWriteEnvironmentStrings, NULL},
344 { szWriteIniValues, ACTION_WriteIniValues },
345 { szWriteRegistryValues, ACTION_WriteRegistryValues},
346 { NULL, NULL},
350 /********************************************************
351 * helper functions
352 ********************************************************/
354 static void ce_actiontext(MSIPACKAGE* package, LPCWSTR action)
356 static const WCHAR szActionText[] =
357 {'A','c','t','i','o','n','T','e','x','t',0};
358 MSIRECORD *row;
360 row = MSI_CreateRecord(1);
361 MSI_RecordSetStringW(row,1,action);
362 ControlEvent_FireSubscribedEvent(package,szActionText, row);
363 msiobj_release(&row->hdr);
366 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
368 static const WCHAR template_s[]=
369 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
370 '.',0};
371 static const WCHAR format[] =
372 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
373 static const WCHAR Query_t[] =
374 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
375 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
376 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
377 ' ','\'','%','s','\'',0};
378 WCHAR message[1024];
379 WCHAR timet[0x100];
380 MSIRECORD * row = 0;
381 LPCWSTR ActionText;
382 LPWSTR deformated;
384 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
386 row = MSI_QueryGetRecord( package->db, Query_t, action );
387 if (!row)
388 return;
390 ActionText = MSI_RecordGetString(row,2);
391 deformat_string(package, ActionText, &deformated);
393 sprintfW(message,template_s,timet,action,deformated);
394 ce_actiontext(package, deformated);
395 msiobj_release(&row->hdr);
397 row = MSI_CreateRecord(1);
398 MSI_RecordSetStringW(row,1,message);
400 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
401 msiobj_release(&row->hdr);
402 HeapFree(GetProcessHeap(),0,deformated);
405 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
406 UINT rc)
408 MSIRECORD * row;
409 static const WCHAR template_s[]=
410 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
411 '%','s', '.',0};
412 static const WCHAR template_e[]=
413 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
414 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
415 '%','i','.',0};
416 static const WCHAR format[] =
417 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
418 WCHAR message[1024];
419 WCHAR timet[0x100];
421 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
422 if (start)
423 sprintfW(message,template_s,timet,action);
424 else
425 sprintfW(message,template_e,timet,action,rc);
427 row = MSI_CreateRecord(1);
428 MSI_RecordSetStringW(row,1,message);
430 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
431 msiobj_release(&row->hdr);
434 /****************************************************
435 * TOP level entry points
436 *****************************************************/
438 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
439 LPCWSTR szCommandLine, LPCWSTR msiFilePath)
441 DWORD sz;
442 WCHAR buffer[10];
443 UINT rc;
444 BOOL ui = FALSE;
445 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
446 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
447 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
449 MSI_SetPropertyW(package, szAction, szInstall);
451 package->script = HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT));
452 memset(package->script,0,sizeof(MSISCRIPT));
454 package->script->InWhatSequence = SEQUENCE_INSTALL;
456 package->msiFilePath= strdupW(msiFilePath);
458 if (szPackagePath)
460 LPWSTR p, check, path;
462 package->PackagePath = strdupW(szPackagePath);
463 path = strdupW(szPackagePath);
464 p = strrchrW(path,'\\');
465 if (p)
467 p++;
468 *p=0;
470 else
472 HeapFree(GetProcessHeap(),0,path);
473 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
474 GetCurrentDirectoryW(MAX_PATH,path);
475 strcatW(path,cszbs);
478 check = load_dynamic_property(package, cszSourceDir,NULL);
479 if (!check)
480 MSI_SetPropertyW(package, cszSourceDir, path);
481 else
482 HeapFree(GetProcessHeap(), 0, check);
484 HeapFree(GetProcessHeap(), 0, path);
487 if (szCommandLine)
489 LPWSTR ptr,ptr2;
490 ptr = (LPWSTR)szCommandLine;
492 while (*ptr)
494 WCHAR *prop = NULL;
495 WCHAR *val = NULL;
497 TRACE("Looking at %s\n",debugstr_w(ptr));
499 ptr2 = strchrW(ptr,'=');
500 if (ptr2)
502 BOOL quote=FALSE;
503 DWORD len = 0;
505 while (*ptr == ' ') ptr++;
506 len = ptr2-ptr;
507 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
508 memcpy(prop,ptr,len*sizeof(WCHAR));
509 prop[len]=0;
510 ptr2++;
512 len = 0;
513 ptr = ptr2;
514 while (*ptr && (quote || (!quote && *ptr!=' ')))
516 if (*ptr == '"')
517 quote = !quote;
518 ptr++;
519 len++;
522 if (*ptr2=='"')
524 ptr2++;
525 len -= 2;
527 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
528 memcpy(val,ptr2,len*sizeof(WCHAR));
529 val[len] = 0;
531 if (strlenW(prop) > 0)
533 TRACE("Found commandline property (%s) = (%s)\n",
534 debugstr_w(prop), debugstr_w(val));
535 MSI_SetPropertyW(package,prop,val);
537 HeapFree(GetProcessHeap(),0,val);
538 HeapFree(GetProcessHeap(),0,prop);
540 ptr++;
544 sz = 10;
545 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
547 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
549 package->script->InWhatSequence |= SEQUENCE_UI;
550 rc = ACTION_ProcessUISequence(package);
551 ui = TRUE;
552 if (rc == ERROR_SUCCESS)
554 package->script->InWhatSequence |= SEQUENCE_EXEC;
555 rc = ACTION_ProcessExecSequence(package,TRUE);
558 else
559 rc = ACTION_ProcessExecSequence(package,FALSE);
561 else
562 rc = ACTION_ProcessExecSequence(package,FALSE);
564 if (rc == -1)
566 /* install was halted but should be considered a success */
567 rc = ERROR_SUCCESS;
570 package->script->CurrentlyScripting= FALSE;
572 /* process the ending type action */
573 if (rc == ERROR_SUCCESS)
574 ACTION_PerformActionSequence(package,-1,ui);
575 else if (rc == ERROR_INSTALL_USEREXIT)
576 ACTION_PerformActionSequence(package,-2,ui);
577 else if (rc == ERROR_INSTALL_SUSPEND)
578 ACTION_PerformActionSequence(package,-4,ui);
579 else /* failed */
580 ACTION_PerformActionSequence(package,-3,ui);
582 /* finish up running custom actions */
583 ACTION_FinishCustomActions(package);
585 return rc;
588 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
590 UINT rc = ERROR_SUCCESS;
591 MSIRECORD * row = 0;
592 static const WCHAR ExecSeqQuery[] =
593 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
594 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
595 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
596 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
598 static const WCHAR UISeqQuery[] =
599 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
600 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
601 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
602 ' ', '=',' ','%','i',0};
604 if (UI)
605 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
606 else
607 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
609 if (row)
611 LPCWSTR action, cond;
613 TRACE("Running the actions\n");
615 /* check conditions */
616 cond = MSI_RecordGetString(row,2);
617 if (cond)
619 /* this is a hack to skip errors in the condition code */
620 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
621 goto end;
624 action = MSI_RecordGetString(row,1);
625 if (!action)
627 ERR("failed to fetch action\n");
628 rc = ERROR_FUNCTION_FAILED;
629 goto end;
632 if (UI)
633 rc = ACTION_PerformUIAction(package,action);
634 else
635 rc = ACTION_PerformAction(package,action,FALSE);
636 end:
637 msiobj_release(&row->hdr);
639 else
640 rc = ERROR_SUCCESS;
642 return rc;
645 typedef struct {
646 MSIPACKAGE* package;
647 BOOL UI;
648 } iterate_action_param;
650 static UINT ITERATE_Actions(MSIRECORD *row, LPVOID param)
652 iterate_action_param *iap= (iterate_action_param*)param;
653 UINT rc;
654 LPCWSTR cond, action;
656 action = MSI_RecordGetString(row,1);
657 if (!action)
659 ERR("Error is retrieving action name\n");
660 return ERROR_FUNCTION_FAILED;
663 /* check conditions */
664 cond = MSI_RecordGetString(row,2);
665 if (cond)
667 /* this is a hack to skip errors in the condition code */
668 if (MSI_EvaluateConditionW(iap->package, cond) == MSICONDITION_FALSE)
670 TRACE("Skipping action: %s (condition is false)\n",
671 debugstr_w(action));
672 return ERROR_SUCCESS;
676 if (iap->UI)
677 rc = ACTION_PerformUIAction(iap->package,action);
678 else
679 rc = ACTION_PerformAction(iap->package,action,FALSE);
681 msi_dialog_check_messages( NULL );
683 if (iap->package->CurrentInstallState != ERROR_SUCCESS )
684 rc = iap->package->CurrentInstallState;
686 if (rc == ERROR_FUNCTION_NOT_CALLED)
687 rc = ERROR_SUCCESS;
689 if (rc != ERROR_SUCCESS)
690 ERR("Execution halted due to error (%i)\n",rc);
692 return rc;
695 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
697 MSIQUERY * view;
698 UINT rc;
699 static const WCHAR ExecSeqQuery[] =
700 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
701 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
702 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
703 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
704 'O','R','D','E','R',' ', 'B','Y',' ',
705 '`','S','e','q','u','e','n','c','e','`',0 };
706 MSIRECORD * row = 0;
707 static const WCHAR IVQuery[] =
708 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
709 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
710 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
711 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
712 ' ','\'', 'I','n','s','t','a','l','l',
713 'V','a','l','i','d','a','t','e','\'', 0};
714 INT seq = 0;
715 iterate_action_param iap;
717 iap.package = package;
718 iap.UI = FALSE;
720 if (package->script->ExecuteSequenceRun)
722 TRACE("Execute Sequence already Run\n");
723 return ERROR_SUCCESS;
726 package->script->ExecuteSequenceRun = TRUE;
728 /* get the sequence number */
729 if (UIran)
731 row = MSI_QueryGetRecord(package->db, IVQuery);
732 if( !row )
733 return ERROR_FUNCTION_FAILED;
734 seq = MSI_RecordGetInteger(row,1);
735 msiobj_release(&row->hdr);
738 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
739 if (rc == ERROR_SUCCESS)
741 TRACE("Running the actions\n");
743 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
744 msiobj_release(&view->hdr);
747 return rc;
750 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
752 MSIQUERY * view;
753 UINT rc;
754 static const WCHAR ExecSeqQuery [] =
755 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
756 '`','I','n','s','t','a','l','l',
757 'U','I','S','e','q','u','e','n','c','e','`',
758 ' ','W','H','E','R','E',' ',
759 '`','S','e','q','u','e','n','c','e','`',' ',
760 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
761 '`','S','e','q','u','e','n','c','e','`',0};
762 iterate_action_param iap;
764 iap.package = package;
765 iap.UI = TRUE;
767 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
769 if (rc == ERROR_SUCCESS)
771 TRACE("Running the actions \n");
773 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
774 msiobj_release(&view->hdr);
777 return rc;
780 /********************************************************
781 * ACTION helper functions and functions that perform the actions
782 *******************************************************/
783 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
784 UINT* rc, BOOL force )
786 BOOL ret = FALSE;
787 BOOL run = force;
788 int i;
790 if (!run && !package->script->CurrentlyScripting)
791 run = TRUE;
793 if (!run)
795 if (strcmpW(action,szInstallFinalize) == 0 ||
796 strcmpW(action,szInstallExecute) == 0 ||
797 strcmpW(action,szInstallExecuteAgain) == 0)
798 run = TRUE;
801 i = 0;
802 while (StandardActions[i].action != NULL)
804 if (strcmpW(StandardActions[i].action, action)==0)
806 if (!run)
808 ui_actioninfo(package, action, TRUE, 0);
809 *rc = schedule_action(package,INSTALL_SCRIPT,action);
810 ui_actioninfo(package, action, FALSE, *rc);
812 else
814 ui_actionstart(package, action);
815 if (StandardActions[i].handler)
817 *rc = StandardActions[i].handler(package);
819 else
821 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
822 *rc = ERROR_SUCCESS;
825 ret = TRUE;
826 break;
828 i++;
830 return ret;
833 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
834 UINT* rc, BOOL force )
836 BOOL ret=FALSE;
837 UINT arc;
839 arc = ACTION_CustomAction(package,action, force);
841 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
843 *rc = arc;
844 ret = TRUE;
846 return ret;
850 * A lot of actions are really important even if they don't do anything
851 * explicit... Lots of properties are set at the beginning of the installation
852 * CostFinalize does a bunch of work to translate the directories and such
854 * But until I get write access to the database that is hard, so I am going to
855 * hack it to see if I can get something to run.
857 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
859 UINT rc = ERROR_SUCCESS;
860 BOOL handled;
862 TRACE("Performing action (%s)\n",debugstr_w(action));
864 handled = ACTION_HandleStandardAction(package, action, &rc, force);
866 if (!handled)
867 handled = ACTION_HandleCustomAction(package, action, &rc, force);
869 if (!handled)
871 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
872 rc = ERROR_FUNCTION_NOT_CALLED;
875 return rc;
878 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
880 UINT rc = ERROR_SUCCESS;
881 BOOL handled = FALSE;
883 TRACE("Performing action (%s)\n",debugstr_w(action));
885 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
887 if (!handled)
888 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
890 if( !handled && ACTION_DialogBox(package,action) == ERROR_SUCCESS )
891 handled = TRUE;
893 if (!handled)
895 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
896 rc = ERROR_FUNCTION_NOT_CALLED;
899 return rc;
904 * Actual Action Handlers
907 static UINT ITERATE_CreateFolders(MSIRECORD *row, LPVOID param)
909 MSIPACKAGE *package = (MSIPACKAGE*)param;
910 LPCWSTR dir;
911 LPWSTR full_path;
912 MSIRECORD *uirow;
913 MSIFOLDER *folder;
915 dir = MSI_RecordGetString(row,1);
916 if (!dir)
918 ERR("Unable to get folder id \n");
919 return ERROR_SUCCESS;
922 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
923 if (!full_path)
925 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
926 return ERROR_SUCCESS;
929 TRACE("Folder is %s\n",debugstr_w(full_path));
931 /* UI stuff */
932 uirow = MSI_CreateRecord(1);
933 MSI_RecordSetStringW(uirow,1,full_path);
934 ui_actiondata(package,szCreateFolders,uirow);
935 msiobj_release( &uirow->hdr );
937 if (folder->State == 0)
938 create_full_pathW(full_path);
940 folder->State = 3;
942 HeapFree(GetProcessHeap(),0,full_path);
943 return ERROR_SUCCESS;
948 * Also we cannot enable/disable components either, so for now I am just going
949 * to do all the directories for all the components.
951 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
953 static const WCHAR ExecSeqQuery[] =
954 {'S','E','L','E','C','T',' ',
955 '`','D','i','r','e','c','t','o','r','y','_','`',
956 ' ','F','R','O','M',' ',
957 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
958 UINT rc;
959 MSIQUERY *view;
961 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
962 if (rc != ERROR_SUCCESS)
963 return ERROR_SUCCESS;
965 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateFolders, package);
966 msiobj_release(&view->hdr);
968 return rc;
971 static MSICOMPONENT* load_component( MSIRECORD * row )
973 MSICOMPONENT *comp;
974 DWORD sz;
976 comp = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSICOMPONENT) );
977 if (!comp)
978 return comp;
980 /* fill in the data */
981 sz = IDENTIFIER_SIZE;
982 MSI_RecordGetStringW(row,1,comp->Component,&sz);
984 TRACE("Loading Component %s\n",
985 debugstr_w(comp->Component));
987 sz = 0x100;
988 if (!MSI_RecordIsNull(row,2))
989 MSI_RecordGetStringW(row,2,comp->ComponentId,&sz);
991 sz = IDENTIFIER_SIZE;
992 MSI_RecordGetStringW(row,3,comp->Directory,&sz);
994 comp->Attributes = MSI_RecordGetInteger(row,4);
996 sz = 0x100;
997 MSI_RecordGetStringW(row,5,comp->Condition,&sz);
999 sz = IDENTIFIER_SIZE;
1000 MSI_RecordGetStringW(row,6,comp->KeyPath,&sz);
1002 comp->Installed = INSTALLSTATE_ABSENT;
1003 comp->Action = INSTALLSTATE_UNKNOWN;
1004 comp->ActionRequest = INSTALLSTATE_UNKNOWN;
1006 comp->Enabled = TRUE;
1008 return comp;
1011 typedef struct {
1012 MSIPACKAGE *package;
1013 MSIFEATURE *feature;
1014 } _ilfs;
1016 static UINT add_feature_component( MSIFEATURE *feature, MSICOMPONENT *comp )
1018 ComponentList *cl;
1020 cl = HeapAlloc( GetProcessHeap(), 0, sizeof (*cl) );
1021 if ( !cl )
1022 return ERROR_NOT_ENOUGH_MEMORY;
1023 cl->component = comp;
1024 list_add_tail( &feature->Components, &cl->entry );
1026 return ERROR_SUCCESS;
1029 static UINT iterate_component_check( MSIRECORD *row, LPVOID param )
1031 _ilfs* ilfs= (_ilfs*)param;
1032 MSIPACKAGE *package = ilfs->package;
1033 MSIFEATURE *feature = ilfs->feature;
1034 MSICOMPONENT *comp;
1036 comp = load_component( row );
1037 if (!comp)
1038 return ERROR_FUNCTION_FAILED;
1040 list_add_tail( &package->components, &comp->entry );
1041 add_feature_component( feature, comp );
1043 TRACE("Loaded new component %p\n", comp);
1045 return ERROR_SUCCESS;
1048 static UINT iterate_load_featurecomponents(MSIRECORD *row, LPVOID param)
1050 _ilfs* ilfs= (_ilfs*)param;
1051 LPCWSTR component;
1052 DWORD rc;
1053 MSICOMPONENT *comp;
1054 MSIQUERY * view;
1055 static const WCHAR Query[] =
1056 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1057 '`','C','o','m','p','o','n','e','n','t','`',' ',
1058 'W','H','E','R','E',' ',
1059 '`','C','o','m','p','o','n','e','n','t','`',' ',
1060 '=','\'','%','s','\'',0};
1062 component = MSI_RecordGetString(row,1);
1064 /* check to see if the component is already loaded */
1065 comp = get_loaded_component( ilfs->package, component );
1066 if (comp)
1068 TRACE("Component %s already loaded\n", debugstr_w(component) );
1069 add_feature_component( ilfs->feature, comp );
1070 return ERROR_SUCCESS;
1073 rc = MSI_OpenQuery(ilfs->package->db, &view, Query, component);
1074 if (rc != ERROR_SUCCESS)
1075 return ERROR_SUCCESS;
1077 rc = MSI_IterateRecords(view, NULL, iterate_component_check, ilfs);
1078 msiobj_release( &view->hdr );
1080 return ERROR_SUCCESS;
1083 static UINT load_feature(MSIRECORD * row, LPVOID param)
1085 MSIPACKAGE* package = (MSIPACKAGE*)param;
1086 MSIFEATURE* feature;
1087 DWORD sz;
1088 static const WCHAR Query1[] =
1089 {'S','E','L','E','C','T',' ',
1090 '`','C','o','m','p','o','n','e','n','t','_','`',
1091 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1092 'C','o','m','p','o','n','e','n','t','s','`',' ',
1093 'W','H','E','R','E',' ',
1094 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1095 MSIQUERY * view;
1096 UINT rc;
1097 _ilfs ilfs;
1099 /* fill in the data */
1101 feature = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFEATURE) );
1102 if (!feature)
1103 return ERROR_NOT_ENOUGH_MEMORY;
1105 list_init( &feature->Components );
1107 sz = IDENTIFIER_SIZE;
1108 MSI_RecordGetStringW(row,1,feature->Feature,&sz);
1110 TRACE("Loading feature %s\n",debugstr_w(feature->Feature));
1112 sz = IDENTIFIER_SIZE;
1113 if (!MSI_RecordIsNull(row,2))
1114 MSI_RecordGetStringW(row,2,feature->Feature_Parent,&sz);
1116 sz = 0x100;
1117 if (!MSI_RecordIsNull(row,3))
1118 MSI_RecordGetStringW(row,3,feature->Title,&sz);
1120 sz = 0x100;
1121 if (!MSI_RecordIsNull(row,4))
1122 MSI_RecordGetStringW(row,4,feature->Description,&sz);
1124 if (!MSI_RecordIsNull(row,5))
1125 feature->Display = MSI_RecordGetInteger(row,5);
1127 feature->Level= MSI_RecordGetInteger(row,6);
1129 sz = IDENTIFIER_SIZE;
1130 if (!MSI_RecordIsNull(row,7))
1131 MSI_RecordGetStringW(row,7,feature->Directory,&sz);
1133 feature->Attributes = MSI_RecordGetInteger(row,8);
1135 feature->Installed = INSTALLSTATE_ABSENT;
1136 feature->Action = INSTALLSTATE_UNKNOWN;
1137 feature->ActionRequest = INSTALLSTATE_UNKNOWN;
1139 list_add_tail( &package->features, &feature->entry );
1141 /* load feature components */
1143 rc = MSI_OpenQuery( package->db, &view, Query1, feature->Feature );
1144 if (rc != ERROR_SUCCESS)
1145 return ERROR_SUCCESS;
1147 ilfs.package = package;
1148 ilfs.feature = feature;
1150 MSI_IterateRecords(view, NULL, iterate_load_featurecomponents , &ilfs);
1151 msiobj_release(&view->hdr);
1153 return ERROR_SUCCESS;
1156 static UINT load_file(MSIRECORD *row, LPVOID param)
1158 MSIPACKAGE* package = (MSIPACKAGE*)param;
1159 LPCWSTR component;
1160 MSIFILE *file;
1162 /* fill in the data */
1164 file = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFILE) );
1165 if (!file)
1166 return ERROR_NOT_ENOUGH_MEMORY;
1168 file->File = load_dynamic_stringW( row, 1 );
1170 component = MSI_RecordGetString( row, 2 );
1171 file->Component = get_loaded_component( package, component );
1173 if (!file->Component)
1174 ERR("Unfound Component %s\n",debugstr_w(component));
1176 file->FileName = load_dynamic_stringW( row, 3 );
1177 reduce_to_longfilename( file->FileName );
1179 file->ShortName = load_dynamic_stringW( row, 3 );
1180 reduce_to_shortfilename( file->ShortName );
1182 file->FileSize = MSI_RecordGetInteger( row, 4 );
1183 file->Version = load_dynamic_stringW( row, 5 );
1184 file->Language = load_dynamic_stringW( row, 6 );
1185 file->Attributes = MSI_RecordGetInteger( row, 7 );
1186 file->Sequence = MSI_RecordGetInteger( row, 8 );
1188 file->Temporary = FALSE;
1189 file->State = 0;
1191 TRACE("File Loaded (%s)\n",debugstr_w(file->File));
1193 list_add_tail( &package->files, &file->entry );
1195 return ERROR_SUCCESS;
1198 static UINT load_all_files(MSIPACKAGE *package)
1200 MSIQUERY * view;
1201 UINT rc;
1202 static const WCHAR Query[] =
1203 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1204 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1205 '`','S','e','q','u','e','n','c','e','`', 0};
1207 if (!package)
1208 return ERROR_INVALID_HANDLE;
1210 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1211 if (rc != ERROR_SUCCESS)
1212 return ERROR_SUCCESS;
1214 rc = MSI_IterateRecords(view, NULL, load_file, package);
1215 msiobj_release(&view->hdr);
1217 return ERROR_SUCCESS;
1222 * I am not doing any of the costing functionality yet.
1223 * Mostly looking at doing the Component and Feature loading
1225 * The native MSI does A LOT of modification to tables here. Mostly adding
1226 * a lot of temporary columns to the Feature and Component tables.
1228 * note: Native msi also tracks the short filename. But I am only going to
1229 * track the long ones. Also looking at this directory table
1230 * it appears that the directory table does not get the parents
1231 * resolved base on property only based on their entries in the
1232 * directory table.
1234 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1236 MSIQUERY * view;
1237 UINT rc;
1238 static const WCHAR Query_all[] =
1239 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1240 '`','F','e','a','t','u','r','e','`',0};
1241 static const WCHAR szCosting[] =
1242 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1243 static const WCHAR szZero[] = { '0', 0 };
1244 WCHAR buffer[3];
1245 DWORD sz = 3;
1247 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1248 if (buffer[0]=='1')
1249 return ERROR_SUCCESS;
1251 MSI_SetPropertyW(package, szCosting, szZero);
1252 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1254 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1255 if (rc != ERROR_SUCCESS)
1256 return rc;
1258 rc = MSI_IterateRecords(view, NULL, load_feature, package);
1259 msiobj_release(&view->hdr);
1261 load_all_files(package);
1263 return ERROR_SUCCESS;
1266 static UINT execute_script(MSIPACKAGE *package, UINT script )
1268 int i;
1269 UINT rc = ERROR_SUCCESS;
1271 TRACE("Executing Script %i\n",script);
1273 for (i = 0; i < package->script->ActionCount[script]; i++)
1275 LPWSTR action;
1276 action = package->script->Actions[script][i];
1277 ui_actionstart(package, action);
1278 TRACE("Executing Action (%s)\n",debugstr_w(action));
1279 rc = ACTION_PerformAction(package, action, TRUE);
1280 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1281 if (rc != ERROR_SUCCESS)
1282 break;
1284 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1286 package->script->ActionCount[script] = 0;
1287 package->script->Actions[script] = NULL;
1288 return rc;
1291 static UINT ACTION_FileCost(MSIPACKAGE *package)
1293 return ERROR_SUCCESS;
1297 static MSIFOLDER *load_folder( MSIPACKAGE *package, LPCWSTR dir )
1299 static const WCHAR Query[] =
1300 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1301 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1302 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1303 ' ','=',' ','\'','%','s','\'',
1305 LPWSTR ptargetdir, targetdir, srcdir;
1306 LPCWSTR parent;
1307 LPWSTR shortname = NULL;
1308 MSIRECORD * row = 0;
1309 MSIFOLDER *folder;
1311 TRACE("Looking for dir %s\n",debugstr_w(dir));
1313 folder = get_loaded_folder( package, dir );
1314 if (folder)
1315 return folder;
1317 TRACE("Working to load %s\n",debugstr_w(dir));
1319 folder = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFOLDER) );
1320 if (!folder)
1321 return NULL;
1323 folder->Directory = strdupW(dir);
1325 row = MSI_QueryGetRecord(package->db, Query, dir);
1326 if (!row)
1327 return NULL;
1329 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1331 /* split src and target dir */
1332 if (strchrW(targetdir,':'))
1334 srcdir=strchrW(targetdir,':');
1335 *srcdir=0;
1336 srcdir ++;
1338 else
1339 srcdir=NULL;
1341 /* for now only pick long filename versions */
1342 if (strchrW(targetdir,'|'))
1344 shortname = targetdir;
1345 targetdir = strchrW(targetdir,'|');
1346 *targetdir = 0;
1347 targetdir ++;
1349 /* for the sourcedir pick the short filename */
1350 if (srcdir && strchrW(srcdir,'|'))
1352 LPWSTR p = strchrW(srcdir,'|');
1353 *p = 0;
1356 /* now check for root dirs */
1357 if (targetdir[0] == '.' && targetdir[1] == 0)
1358 targetdir = NULL;
1360 if (targetdir)
1362 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1363 HeapFree(GetProcessHeap(),0, folder->TargetDefault);
1364 folder->TargetDefault = strdupW(targetdir);
1367 if (srcdir)
1368 folder->SourceDefault = strdupW(srcdir);
1369 else if (shortname)
1370 folder->SourceDefault = strdupW(shortname);
1371 else if (targetdir)
1372 folder->SourceDefault = strdupW(targetdir);
1373 HeapFree(GetProcessHeap(), 0, ptargetdir);
1374 TRACE(" SourceDefault = %s\n", debugstr_w( folder->SourceDefault ));
1376 parent = MSI_RecordGetString(row,2);
1377 if (parent)
1379 folder->Parent = load_folder( package, parent );
1380 if ( folder->Parent )
1381 TRACE("loaded parent %p %s\n", folder->Parent,
1382 debugstr_w(folder->Parent->Directory));
1383 else
1384 ERR("failed to load parent folder %s\n", debugstr_w(parent));
1387 folder->Property = load_dynamic_property( package, dir, NULL );
1389 msiobj_release(&row->hdr);
1391 list_add_tail( &package->folders, &folder->entry );
1393 TRACE("%s returning %p\n",debugstr_w(dir),folder);
1395 return folder;
1398 /* scan for and update current install states */
1399 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
1401 MSICOMPONENT *comp;
1402 MSIFEATURE *feature;
1404 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1406 INSTALLSTATE res;
1407 res = MsiGetComponentPathW( package->ProductCode,
1408 comp->ComponentId, NULL, NULL);
1409 if (res < 0)
1410 res = INSTALLSTATE_ABSENT;
1411 comp->Installed = res;
1414 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1416 ComponentList *cl;
1417 INSTALLSTATE res = -10;
1419 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1421 comp= cl->component;
1423 if (res == -10)
1424 res = comp->Installed;
1425 else
1427 if (res == comp->Installed)
1428 continue;
1430 if (res != comp->Installed)
1431 res = INSTALLSTATE_INCOMPLETE;
1437 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
1438 INSTALLSTATE state)
1440 static const WCHAR all[]={'A','L','L',0};
1441 LPWSTR override = NULL;
1442 BOOL rc = FALSE;
1443 MSIFEATURE *feature;
1445 override = load_dynamic_property(package, property, NULL);
1446 if (override)
1448 rc = TRUE;
1449 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1451 if (strcmpiW(override,all)==0)
1453 feature->ActionRequest= state;
1454 feature->Action = state;
1456 else
1458 LPWSTR ptr = override;
1459 LPWSTR ptr2 = strchrW(override,',');
1461 while (ptr)
1463 if ((ptr2 &&
1464 strncmpW(ptr,feature->Feature, ptr2-ptr)==0)
1465 || (!ptr2 && strcmpW(ptr,feature->Feature)==0))
1467 feature->ActionRequest= state;
1468 feature->Action = state;
1469 break;
1471 if (ptr2)
1473 ptr=ptr2+1;
1474 ptr2 = strchrW(ptr,',');
1476 else
1477 break;
1481 HeapFree(GetProcessHeap(),0,override);
1484 return rc;
1487 static UINT SetFeatureStates(MSIPACKAGE *package)
1489 LPWSTR level;
1490 INT install_level;
1491 static const WCHAR szlevel[] =
1492 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1493 static const WCHAR szAddLocal[] =
1494 {'A','D','D','L','O','C','A','L',0};
1495 static const WCHAR szRemove[] =
1496 {'R','E','M','O','V','E',0};
1497 BOOL override = FALSE;
1498 MSICOMPONENT* component;
1499 MSIFEATURE *feature;
1502 /* I do not know if this is where it should happen.. but */
1504 TRACE("Checking Install Level\n");
1506 level = load_dynamic_property(package,szlevel,NULL);
1507 if (level)
1509 install_level = atoiW(level);
1510 HeapFree(GetProcessHeap(), 0, level);
1512 else
1513 install_level = 1;
1515 /* ok hereis the _real_ rub
1516 * all these activation/deactivation things happen in order and things
1517 * later on the list override things earlier on the list.
1518 * 1) INSTALLLEVEL processing
1519 * 2) ADDLOCAL
1520 * 3) REMOVE
1521 * 4) ADDSOURCE
1522 * 5) ADDDEFAULT
1523 * 6) REINSTALL
1524 * 7) COMPADDLOCAL
1525 * 8) COMPADDSOURCE
1526 * 9) FILEADDLOCAL
1527 * 10) FILEADDSOURCE
1528 * 11) FILEADDDEFAULT
1529 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1530 * ignored for all the features. seems strange, especially since it is not
1531 * documented anywhere, but it is how it works.
1533 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1534 * REMOVE are the big ones, since we don't handle administrative installs
1535 * yet anyway.
1537 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
1538 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
1540 if (!override)
1542 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1544 BOOL feature_state = ((feature->Level > 0) &&
1545 (feature->Level <= install_level));
1547 if ((feature_state) && (feature->Action == INSTALLSTATE_UNKNOWN))
1549 if (feature->Attributes & msidbFeatureAttributesFavorSource)
1551 feature->ActionRequest = INSTALLSTATE_SOURCE;
1552 feature->Action = INSTALLSTATE_SOURCE;
1554 else if (feature->Attributes & msidbFeatureAttributesFavorAdvertise)
1556 feature->ActionRequest = INSTALLSTATE_ADVERTISED;
1557 feature->Action = INSTALLSTATE_ADVERTISED;
1559 else
1561 feature->ActionRequest = INSTALLSTATE_LOCAL;
1562 feature->Action = INSTALLSTATE_LOCAL;
1567 else
1569 /* set the Preselected Property */
1570 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1571 static const WCHAR szOne[] = { '1', 0 };
1573 MSI_SetPropertyW(package,szPreselected,szOne);
1577 * now we want to enable or disable components base on feature
1580 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1582 ComponentList *cl;
1584 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1585 debugstr_w(feature->Feature), feature->Installed, feature->Action,
1586 feature->ActionRequest);
1588 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1590 component = cl->component;
1592 if (!component->Enabled)
1594 component->Action = INSTALLSTATE_UNKNOWN;
1595 component->ActionRequest = INSTALLSTATE_UNKNOWN;
1597 else
1599 if (feature->Action == INSTALLSTATE_LOCAL)
1601 component->Action = INSTALLSTATE_LOCAL;
1602 component->ActionRequest = INSTALLSTATE_LOCAL;
1604 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
1606 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1607 (component->Action == INSTALLSTATE_ABSENT) ||
1608 (component->Action == INSTALLSTATE_ADVERTISED))
1611 component->Action = INSTALLSTATE_SOURCE;
1612 component->ActionRequest = INSTALLSTATE_SOURCE;
1615 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
1617 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1618 (component->Action == INSTALLSTATE_ABSENT))
1621 component->Action = INSTALLSTATE_ADVERTISED;
1622 component->ActionRequest = INSTALLSTATE_ADVERTISED;
1625 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
1627 if (component->Action == INSTALLSTATE_UNKNOWN)
1629 component->Action = INSTALLSTATE_ABSENT;
1630 component->ActionRequest = INSTALLSTATE_ABSENT;
1637 LIST_FOR_EACH_ENTRY( component, &package->components, MSICOMPONENT, entry )
1639 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1640 debugstr_w(component->Component), component->Installed,
1641 component->Action, component->ActionRequest);
1645 return ERROR_SUCCESS;
1648 static UINT ITERATE_CostFinalizeDirectories(MSIRECORD *row, LPVOID param)
1650 MSIPACKAGE *package = (MSIPACKAGE*)param;
1651 LPCWSTR name;
1652 LPWSTR path;
1654 name = MSI_RecordGetString(row,1);
1656 /* This helper function now does ALL the work */
1657 TRACE("Dir %s ...\n",debugstr_w(name));
1658 load_folder(package,name);
1659 path = resolve_folder(package,name,FALSE,TRUE,NULL);
1660 TRACE("resolves to %s\n",debugstr_w(path));
1661 HeapFree( GetProcessHeap(), 0, path);
1663 return ERROR_SUCCESS;
1666 static UINT ITERATE_CostFinalizeConditions(MSIRECORD *row, LPVOID param)
1668 MSIPACKAGE *package = (MSIPACKAGE*)param;
1669 LPCWSTR name;
1670 MSIFEATURE *feature;
1672 name = MSI_RecordGetString( row, 1 );
1674 feature = get_loaded_feature( package, name );
1675 if (!feature)
1676 ERR("FAILED to find loaded feature %s\n",debugstr_w(name));
1677 else
1679 LPCWSTR Condition;
1680 Condition = MSI_RecordGetString(row,3);
1682 if (MSI_EvaluateConditionW(package,Condition) == MSICONDITION_TRUE)
1684 int level = MSI_RecordGetInteger(row,2);
1685 TRACE("Reseting feature %s to level %i\n", debugstr_w(name), level);
1686 feature->Level = level;
1689 return ERROR_SUCCESS;
1694 * A lot is done in this function aside from just the costing.
1695 * The costing needs to be implemented at some point but for now I am going
1696 * to focus on the directory building
1699 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
1701 static const WCHAR ExecSeqQuery[] =
1702 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1703 '`','D','i','r','e','c','t','o','r','y','`',0};
1704 static const WCHAR ConditionQuery[] =
1705 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1706 '`','C','o','n','d','i','t','i','o','n','`',0};
1707 static const WCHAR szCosting[] =
1708 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1709 static const WCHAR szlevel[] =
1710 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1711 static const WCHAR szOne[] = { '1', 0 };
1712 MSICOMPONENT *comp;
1713 MSIFILE *file;
1714 UINT rc;
1715 MSIQUERY * view;
1716 LPWSTR level;
1717 DWORD sz = 3;
1718 WCHAR buffer[3];
1720 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1721 if (buffer[0]=='1')
1722 return ERROR_SUCCESS;
1724 TRACE("Building Directory properties\n");
1726 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1727 if (rc == ERROR_SUCCESS)
1729 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeDirectories,
1730 package);
1731 msiobj_release(&view->hdr);
1734 TRACE("File calculations\n");
1736 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
1738 MSICOMPONENT* comp = NULL;
1740 comp = file->Component;
1742 if (file->Temporary == TRUE)
1743 continue;
1745 if (comp)
1747 LPWSTR p;
1749 /* calculate target */
1750 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
1752 HeapFree(GetProcessHeap(),0,file->TargetPath);
1754 TRACE("file %s is named %s\n",
1755 debugstr_w(file->File),debugstr_w(file->FileName));
1757 file->TargetPath = build_directory_name(2, p, file->FileName);
1759 HeapFree(GetProcessHeap(),0,p);
1761 TRACE("file %s resolves to %s\n",
1762 debugstr_w(file->File),debugstr_w(file->TargetPath));
1764 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
1766 file->State = 1;
1767 comp->Cost += file->FileSize;
1769 else
1771 if (file->Version)
1773 DWORD handle;
1774 DWORD versize;
1775 UINT sz;
1776 LPVOID version;
1777 static const WCHAR name[] =
1778 {'\\',0};
1779 static const WCHAR name_fmt[] =
1780 {'%','u','.','%','u','.','%','u','.','%','u',0};
1781 WCHAR filever[0x100];
1782 VS_FIXEDFILEINFO *lpVer;
1784 TRACE("Version comparison.. \n");
1785 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
1786 version = HeapAlloc(GetProcessHeap(),0,versize);
1787 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
1789 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
1791 sprintfW(filever,name_fmt,
1792 HIWORD(lpVer->dwFileVersionMS),
1793 LOWORD(lpVer->dwFileVersionMS),
1794 HIWORD(lpVer->dwFileVersionLS),
1795 LOWORD(lpVer->dwFileVersionLS));
1797 TRACE("new %s old %s\n", debugstr_w(file->Version),
1798 debugstr_w(filever));
1799 if (strcmpiW(filever,file->Version)<0)
1801 file->State = 2;
1802 FIXME("cost should be diff in size\n");
1803 comp->Cost += file->FileSize;
1805 else
1806 file->State = 3;
1807 HeapFree(GetProcessHeap(),0,version);
1809 else
1810 file->State = 3;
1815 TRACE("Evaluating Condition Table\n");
1817 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
1818 if (rc == ERROR_SUCCESS)
1820 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeConditions,
1821 package);
1822 msiobj_release(&view->hdr);
1825 TRACE("Enabling or Disabling Components\n");
1826 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1828 if (comp->Condition[0])
1830 if (MSI_EvaluateConditionW(package,
1831 comp->Condition) == MSICONDITION_FALSE)
1833 TRACE("Disabling component %s\n", debugstr_w(comp->Component));
1834 comp->Enabled = FALSE;
1839 MSI_SetPropertyW(package,szCosting,szOne);
1840 /* set default run level if not set */
1841 level = load_dynamic_property(package,szlevel,NULL);
1842 if (!level)
1843 MSI_SetPropertyW(package,szlevel, szOne);
1844 else
1845 HeapFree(GetProcessHeap(),0,level);
1847 ACTION_UpdateInstallStates(package);
1849 return SetFeatureStates(package);
1852 /* OK this value is "interpreted" and then formatted based on the
1853 first few characters */
1854 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
1855 DWORD *size)
1857 LPSTR data = NULL;
1858 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
1860 if (value[1]=='x')
1862 LPWSTR ptr;
1863 CHAR byte[5];
1864 LPWSTR deformated = NULL;
1865 int count;
1867 deformat_string(package, &value[2], &deformated);
1869 /* binary value type */
1870 ptr = deformated;
1871 *type = REG_BINARY;
1872 if (strlenW(ptr)%2)
1873 *size = (strlenW(ptr)/2)+1;
1874 else
1875 *size = strlenW(ptr)/2;
1877 data = HeapAlloc(GetProcessHeap(),0,*size);
1879 byte[0] = '0';
1880 byte[1] = 'x';
1881 byte[4] = 0;
1882 count = 0;
1883 /* if uneven pad with a zero in front */
1884 if (strlenW(ptr)%2)
1886 byte[2]= '0';
1887 byte[3]= *ptr;
1888 ptr++;
1889 data[count] = (BYTE)strtol(byte,NULL,0);
1890 count ++;
1891 TRACE("Uneven byte count\n");
1893 while (*ptr)
1895 byte[2]= *ptr;
1896 ptr++;
1897 byte[3]= *ptr;
1898 ptr++;
1899 data[count] = (BYTE)strtol(byte,NULL,0);
1900 count ++;
1902 HeapFree(GetProcessHeap(),0,deformated);
1904 TRACE("Data %li bytes(%i)\n",*size,count);
1906 else
1908 LPWSTR deformated;
1909 LPWSTR p;
1910 DWORD d = 0;
1911 deformat_string(package, &value[1], &deformated);
1913 *type=REG_DWORD;
1914 *size = sizeof(DWORD);
1915 data = HeapAlloc(GetProcessHeap(),0,*size);
1916 p = deformated;
1917 if (*p == '-')
1918 p++;
1919 while (*p)
1921 if ( (*p < '0') || (*p > '9') )
1922 break;
1923 d *= 10;
1924 d += (*p - '0');
1925 p++;
1927 if (deformated[0] == '-')
1928 d = -d;
1929 *(LPDWORD)data = d;
1930 TRACE("DWORD %li\n",*(LPDWORD)data);
1932 HeapFree(GetProcessHeap(),0,deformated);
1935 else
1937 static const WCHAR szMulti[] = {'[','~',']',0};
1938 LPCWSTR ptr;
1939 *type=REG_SZ;
1941 if (value[0]=='#')
1943 if (value[1]=='%')
1945 ptr = &value[2];
1946 *type=REG_EXPAND_SZ;
1948 else
1949 ptr = &value[1];
1951 else
1952 ptr=value;
1954 if (strstrW(value,szMulti))
1955 *type = REG_MULTI_SZ;
1957 *size = deformat_string(package, ptr,(LPWSTR*)&data);
1959 return data;
1962 static UINT ITERATE_WriteRegistryValues(MSIRECORD *row, LPVOID param)
1964 MSIPACKAGE *package = (MSIPACKAGE*)param;
1965 static const WCHAR szHCR[] =
1966 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1967 'R','O','O','T','\\',0};
1968 static const WCHAR szHCU[] =
1969 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1970 'U','S','E','R','\\',0};
1971 static const WCHAR szHLM[] =
1972 {'H','K','E','Y','_','L','O','C','A','L','_',
1973 'M','A','C','H','I','N','E','\\',0};
1974 static const WCHAR szHU[] =
1975 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1977 LPSTR value_data = NULL;
1978 HKEY root_key, hkey;
1979 DWORD type,size;
1980 LPWSTR deformated;
1981 LPCWSTR szRoot, component, name, key, value;
1982 MSICOMPONENT *comp;
1983 MSIRECORD * uirow;
1984 LPWSTR uikey;
1985 INT root;
1986 BOOL check_first = FALSE;
1987 UINT rc;
1989 ui_progress(package,2,0,0,0);
1991 value = NULL;
1992 key = NULL;
1993 uikey = NULL;
1994 name = NULL;
1996 component = MSI_RecordGetString(row, 6);
1997 comp = get_loaded_component(package,component);
1998 if (!comp)
1999 return ERROR_SUCCESS;
2001 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2003 TRACE("Skipping write due to disabled component %s\n",
2004 debugstr_w(component));
2006 comp->Action = comp->Installed;
2008 return ERROR_SUCCESS;
2011 comp->Action = INSTALLSTATE_LOCAL;
2013 name = MSI_RecordGetString(row, 4);
2014 if( MSI_RecordIsNull(row,5) && name )
2016 /* null values can have special meanings */
2017 if (name[0]=='-' && name[1] == 0)
2018 return ERROR_SUCCESS;
2019 else if ((name[0]=='+' && name[1] == 0) ||
2020 (name[0] == '*' && name[1] == 0))
2021 name = NULL;
2022 check_first = TRUE;
2025 root = MSI_RecordGetInteger(row,2);
2026 key = MSI_RecordGetString(row, 3);
2028 /* get the root key */
2029 switch (root)
2031 case -1:
2033 static const WCHAR szALLUSER[] = {'A','L','L','U','S','E','R','S',0};
2034 LPWSTR all_users = load_dynamic_property(package, szALLUSER, NULL);
2035 if (all_users && all_users[0] == '1')
2037 root_key = HKEY_LOCAL_MACHINE;
2038 szRoot = szHLM;
2040 else
2042 root_key = HKEY_CURRENT_USER;
2043 szRoot = szHCU;
2045 HeapFree(GetProcessHeap(),0,all_users);
2047 break;
2048 case 0: root_key = HKEY_CLASSES_ROOT;
2049 szRoot = szHCR;
2050 break;
2051 case 1: root_key = HKEY_CURRENT_USER;
2052 szRoot = szHCU;
2053 break;
2054 case 2: root_key = HKEY_LOCAL_MACHINE;
2055 szRoot = szHLM;
2056 break;
2057 case 3: root_key = HKEY_USERS;
2058 szRoot = szHU;
2059 break;
2060 default:
2061 ERR("Unknown root %i\n",root);
2062 root_key=NULL;
2063 szRoot = NULL;
2064 break;
2066 if (!root_key)
2067 return ERROR_SUCCESS;
2069 deformat_string(package, key , &deformated);
2070 size = strlenW(deformated) + strlenW(szRoot) + 1;
2071 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
2072 strcpyW(uikey,szRoot);
2073 strcatW(uikey,deformated);
2075 if (RegCreateKeyW( root_key, deformated, &hkey))
2077 ERR("Could not create key %s\n",debugstr_w(deformated));
2078 HeapFree(GetProcessHeap(),0,deformated);
2079 HeapFree(GetProcessHeap(),0,uikey);
2080 return ERROR_SUCCESS;
2082 HeapFree(GetProcessHeap(),0,deformated);
2084 value = MSI_RecordGetString(row,5);
2085 if (value)
2086 value_data = parse_value(package, value, &type, &size);
2087 else
2089 static const WCHAR szEmpty[] = {0};
2090 value_data = (LPSTR)strdupW(szEmpty);
2091 size = 0;
2092 type = REG_SZ;
2095 deformat_string(package, name, &deformated);
2097 /* get the double nulls to terminate SZ_MULTI */
2098 if (type == REG_MULTI_SZ)
2099 size +=sizeof(WCHAR);
2101 if (!check_first)
2103 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
2104 debugstr_w(uikey));
2105 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE)value_data, size);
2107 else
2109 DWORD sz = 0;
2110 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
2111 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2113 TRACE("value %s of %s checked already exists\n",
2114 debugstr_w(deformated), debugstr_w(uikey));
2116 else
2118 TRACE("Checked and setting value %s of %s\n",
2119 debugstr_w(deformated), debugstr_w(uikey));
2120 if (deformated || size)
2121 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE) value_data, size);
2124 RegCloseKey(hkey);
2126 uirow = MSI_CreateRecord(3);
2127 MSI_RecordSetStringW(uirow,2,deformated);
2128 MSI_RecordSetStringW(uirow,1,uikey);
2130 if (type == REG_SZ)
2131 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2132 else
2133 MSI_RecordSetStringW(uirow,3,value);
2135 ui_actiondata(package,szWriteRegistryValues,uirow);
2136 msiobj_release( &uirow->hdr );
2138 HeapFree(GetProcessHeap(),0,value_data);
2139 HeapFree(GetProcessHeap(),0,deformated);
2140 HeapFree(GetProcessHeap(),0,uikey);
2142 return ERROR_SUCCESS;
2145 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2147 UINT rc;
2148 MSIQUERY * view;
2149 static const WCHAR ExecSeqQuery[] =
2150 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2151 '`','R','e','g','i','s','t','r','y','`',0 };
2153 if (!package)
2154 return ERROR_INVALID_HANDLE;
2156 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2157 if (rc != ERROR_SUCCESS)
2158 return ERROR_SUCCESS;
2160 /* increment progress bar each time action data is sent */
2161 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
2163 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteRegistryValues, package);
2165 msiobj_release(&view->hdr);
2166 return rc;
2169 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
2171 package->script->CurrentlyScripting = TRUE;
2173 return ERROR_SUCCESS;
2177 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
2179 MSICOMPONENT *comp;
2180 DWORD progress = 0;
2181 DWORD total = 0;
2182 static const WCHAR q1[]=
2183 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2184 '`','R','e','g','i','s','t','r','y','`',0};
2185 UINT rc;
2186 MSIQUERY * view;
2187 MSIRECORD * row = 0;
2188 MSIFEATURE *feature;
2189 MSIFILE *file;
2191 TRACE(" InstallValidate \n");
2193 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
2194 if (rc != ERROR_SUCCESS)
2195 return ERROR_SUCCESS;
2197 rc = MSI_ViewExecute(view, 0);
2198 if (rc != ERROR_SUCCESS)
2200 MSI_ViewClose(view);
2201 msiobj_release(&view->hdr);
2202 return rc;
2204 while (1)
2206 rc = MSI_ViewFetch(view,&row);
2207 if (rc != ERROR_SUCCESS)
2209 rc = ERROR_SUCCESS;
2210 break;
2212 progress +=1;
2214 msiobj_release(&row->hdr);
2216 MSI_ViewClose(view);
2217 msiobj_release(&view->hdr);
2219 total = total + progress * REG_PROGRESS_VALUE;
2220 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2222 total += COMPONENT_PROGRESS_VALUE;
2224 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2226 total += file->FileSize;
2228 ui_progress(package,0,total,0,0);
2230 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2232 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2233 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2234 feature->ActionRequest);
2237 return ERROR_SUCCESS;
2240 static UINT ITERATE_LaunchConditions(MSIRECORD *row, LPVOID param)
2242 MSIPACKAGE* package = (MSIPACKAGE*)param;
2243 LPCWSTR cond = NULL;
2244 LPCWSTR message = NULL;
2245 static const WCHAR title[]=
2246 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2248 cond = MSI_RecordGetString(row,1);
2250 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
2252 LPWSTR deformated;
2253 message = MSI_RecordGetString(row,2);
2254 deformat_string(package,message,&deformated);
2255 MessageBoxW(NULL,deformated,title,MB_OK);
2256 HeapFree(GetProcessHeap(),0,deformated);
2257 return ERROR_FUNCTION_FAILED;
2260 return ERROR_SUCCESS;
2263 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
2265 UINT rc;
2266 MSIQUERY * view = NULL;
2267 static const WCHAR ExecSeqQuery[] =
2268 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2269 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2271 TRACE("Checking launch conditions\n");
2273 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2274 if (rc != ERROR_SUCCESS)
2275 return ERROR_SUCCESS;
2277 rc = MSI_IterateRecords(view, NULL, ITERATE_LaunchConditions, package);
2278 msiobj_release(&view->hdr);
2280 return rc;
2283 static LPWSTR resolve_keypath( MSIPACKAGE* package, MSICOMPONENT *cmp )
2286 if (cmp->KeyPath[0]==0)
2288 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
2289 return p;
2291 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
2293 MSIRECORD * row = 0;
2294 UINT root,len;
2295 LPWSTR deformated,buffer,deformated_name;
2296 LPCWSTR key,name;
2297 static const WCHAR ExecSeqQuery[] =
2298 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2299 '`','R','e','g','i','s','t','r','y','`',' ',
2300 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2301 ' ','=',' ' ,'\'','%','s','\'',0 };
2302 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
2303 static const WCHAR fmt2[]=
2304 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2306 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
2307 if (!row)
2308 return NULL;
2310 root = MSI_RecordGetInteger(row,2);
2311 key = MSI_RecordGetString(row, 3);
2312 name = MSI_RecordGetString(row, 4);
2313 deformat_string(package, key , &deformated);
2314 deformat_string(package, name, &deformated_name);
2316 len = strlenW(deformated) + 6;
2317 if (deformated_name)
2318 len+=strlenW(deformated_name);
2320 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
2322 if (deformated_name)
2323 sprintfW(buffer,fmt2,root,deformated,deformated_name);
2324 else
2325 sprintfW(buffer,fmt,root,deformated);
2327 HeapFree(GetProcessHeap(),0,deformated);
2328 HeapFree(GetProcessHeap(),0,deformated_name);
2329 msiobj_release(&row->hdr);
2331 return buffer;
2333 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
2335 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2336 return NULL;
2338 else
2340 MSIFILE *file = get_loaded_file( package, cmp->KeyPath );
2342 if (file)
2343 return strdupW( file->TargetPath );
2345 return NULL;
2348 static HKEY openSharedDLLsKey(void)
2350 HKEY hkey=0;
2351 static const WCHAR path[] =
2352 {'S','o','f','t','w','a','r','e','\\',
2353 'M','i','c','r','o','s','o','f','t','\\',
2354 'W','i','n','d','o','w','s','\\',
2355 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2356 'S','h','a','r','e','d','D','L','L','s',0};
2358 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
2359 return hkey;
2362 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
2364 HKEY hkey;
2365 DWORD count=0;
2366 DWORD type;
2367 DWORD sz = sizeof(count);
2368 DWORD rc;
2370 hkey = openSharedDLLsKey();
2371 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
2372 if (rc != ERROR_SUCCESS)
2373 count = 0;
2374 RegCloseKey(hkey);
2375 return count;
2378 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
2380 HKEY hkey;
2382 hkey = openSharedDLLsKey();
2383 if (count > 0)
2384 RegSetValueExW(hkey,path,0,REG_DWORD,
2385 (LPBYTE)&count,sizeof(count));
2386 else
2387 RegDeleteValueW(hkey,path);
2388 RegCloseKey(hkey);
2389 return count;
2393 * Return TRUE if the count should be written out and FALSE if not
2395 static void ACTION_RefCountComponent( MSIPACKAGE* package, MSICOMPONENT *comp )
2397 MSIFEATURE *feature;
2398 INT count = 0;
2399 BOOL write = FALSE;
2401 /* only refcount DLLs */
2402 if (comp->KeyPath[0]==0 ||
2403 comp->Attributes & msidbComponentAttributesRegistryKeyPath ||
2404 comp->Attributes & msidbComponentAttributesODBCDataSource)
2405 write = FALSE;
2406 else
2408 count = ACTION_GetSharedDLLsCount( comp->FullKeypath);
2409 write = (count > 0);
2411 if (comp->Attributes & msidbComponentAttributesSharedDllRefCount)
2412 write = TRUE;
2415 /* increment counts */
2416 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2418 ComponentList *cl;
2420 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ))
2421 continue;
2423 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2425 if ( cl->component == comp )
2426 count++;
2430 /* decrement counts */
2431 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2433 ComponentList *cl;
2435 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ABSENT ))
2436 continue;
2438 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2440 if ( cl->component == comp )
2441 count--;
2445 /* ref count all the files in the component */
2446 if (write)
2448 MSIFILE *file;
2450 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2452 if (file->Temporary)
2453 continue;
2454 if (file->Component == comp)
2455 ACTION_WriteSharedDLLsCount( file->TargetPath, count );
2459 /* add a count for permenent */
2460 if (comp->Attributes & msidbComponentAttributesPermanent)
2461 count ++;
2463 comp->RefCount = count;
2465 if (write)
2466 ACTION_WriteSharedDLLsCount( comp->FullKeypath, comp->RefCount );
2470 * Ok further analysis makes me think that this work is
2471 * actually done in the PublishComponents and PublishFeatures
2472 * step, and not here. It appears like the keypath and all that is
2473 * resolved in this step, however actually written in the Publish steps.
2474 * But we will leave it here for now because it is unclear
2476 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
2478 WCHAR squished_pc[GUID_SIZE];
2479 WCHAR squished_cc[GUID_SIZE];
2480 UINT rc;
2481 MSICOMPONENT *comp;
2482 HKEY hkey=0,hkey2=0;
2484 if (!package)
2485 return ERROR_INVALID_HANDLE;
2487 /* writes the Component and Features values to the registry */
2489 rc = MSIREG_OpenComponents(&hkey);
2490 if (rc != ERROR_SUCCESS)
2491 goto end;
2493 squash_guid(package->ProductCode,squished_pc);
2494 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
2496 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2498 ui_progress(package,2,0,0,0);
2499 if (comp->ComponentId[0]!=0)
2501 WCHAR *keypath = NULL;
2502 MSIRECORD * uirow;
2504 squash_guid(comp->ComponentId,squished_cc);
2506 keypath = resolve_keypath( package, comp );
2507 comp->FullKeypath = keypath;
2509 /* do the refcounting */
2510 ACTION_RefCountComponent( package, comp );
2512 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2513 debugstr_w(comp->Component),
2514 debugstr_w(squished_cc),
2515 debugstr_w(comp->FullKeypath),
2516 comp->RefCount);
2518 * Write the keypath out if the component is to be registered
2519 * and delete the key if the component is to be deregistered
2521 if (ACTION_VerifyComponentForAction(package, comp,
2522 INSTALLSTATE_LOCAL))
2524 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
2525 if (rc != ERROR_SUCCESS)
2526 continue;
2528 if (keypath)
2530 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPBYTE)keypath,
2531 (strlenW(keypath)+1)*sizeof(WCHAR));
2533 if (comp->Attributes & msidbComponentAttributesPermanent)
2535 static const WCHAR szPermKey[] =
2536 { '0','0','0','0','0','0','0','0','0','0','0','0',
2537 '0','0','0','0','0','0','0', '0','0','0','0','0',
2538 '0','0','0','0','0','0','0','0',0};
2540 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
2541 (LPBYTE)keypath,
2542 (strlenW(keypath)+1)*sizeof(WCHAR));
2545 RegCloseKey(hkey2);
2547 /* UI stuff */
2548 uirow = MSI_CreateRecord(3);
2549 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2550 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2551 MSI_RecordSetStringW(uirow,3,keypath);
2552 ui_actiondata(package,szProcessComponents,uirow);
2553 msiobj_release( &uirow->hdr );
2556 else if (ACTION_VerifyComponentForAction(package, comp,
2557 INSTALLSTATE_ABSENT))
2559 DWORD res;
2561 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
2562 if (rc != ERROR_SUCCESS)
2563 continue;
2565 RegDeleteValueW(hkey2,squished_pc);
2567 /* if the key is empty delete it */
2568 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
2569 RegCloseKey(hkey2);
2570 if (res == ERROR_NO_MORE_ITEMS)
2571 RegDeleteKeyW(hkey,squished_cc);
2573 /* UI stuff */
2574 uirow = MSI_CreateRecord(2);
2575 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2576 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2577 ui_actiondata(package,szProcessComponents,uirow);
2578 msiobj_release( &uirow->hdr );
2582 end:
2583 RegCloseKey(hkey);
2584 return rc;
2587 typedef struct {
2588 CLSID clsid;
2589 LPWSTR source;
2591 LPWSTR path;
2592 ITypeLib *ptLib;
2593 } typelib_struct;
2595 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
2596 LPWSTR lpszName, LONG_PTR lParam)
2598 TLIBATTR *attr;
2599 typelib_struct *tl_struct = (typelib_struct*) lParam;
2600 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
2601 int sz;
2602 HRESULT res;
2604 if (!IS_INTRESOURCE(lpszName))
2606 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
2607 return TRUE;
2610 sz = strlenW(tl_struct->source)+4;
2611 sz *= sizeof(WCHAR);
2613 if ((INT)lpszName == 1)
2614 tl_struct->path = strdupW(tl_struct->source);
2615 else
2617 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
2618 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
2621 TRACE("trying %s\n", debugstr_w(tl_struct->path));
2622 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
2623 if (!SUCCEEDED(res))
2625 HeapFree(GetProcessHeap(),0,tl_struct->path);
2626 tl_struct->path = NULL;
2628 return TRUE;
2631 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
2632 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
2634 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2635 return FALSE;
2638 HeapFree(GetProcessHeap(),0,tl_struct->path);
2639 tl_struct->path = NULL;
2641 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2642 ITypeLib_Release(tl_struct->ptLib);
2644 return TRUE;
2647 static UINT ITERATE_RegisterTypeLibraries(MSIRECORD *row, LPVOID param)
2649 MSIPACKAGE* package = (MSIPACKAGE*)param;
2650 LPCWSTR component;
2651 MSICOMPONENT *comp;
2652 MSIFILE *file;
2653 typelib_struct tl_struct;
2654 HMODULE module;
2655 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
2657 component = MSI_RecordGetString(row,3);
2658 comp = get_loaded_component(package,component);
2659 if (!comp)
2660 return ERROR_SUCCESS;
2662 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2664 TRACE("Skipping typelib reg due to disabled component\n");
2666 comp->Action = comp->Installed;
2668 return ERROR_SUCCESS;
2671 comp->Action = INSTALLSTATE_LOCAL;
2673 file = get_loaded_file( package, comp->KeyPath );
2674 if (!file)
2675 return ERROR_SUCCESS;
2677 module = LoadLibraryExW( file->TargetPath, NULL, LOAD_LIBRARY_AS_DATAFILE );
2678 if (module != NULL)
2680 LPWSTR guid;
2681 guid = load_dynamic_stringW(row,1);
2682 CLSIDFromString(guid, &tl_struct.clsid);
2683 HeapFree(GetProcessHeap(),0,guid);
2684 tl_struct.source = strdupW( file->TargetPath );
2685 tl_struct.path = NULL;
2687 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
2688 (LONG_PTR)&tl_struct);
2690 if (tl_struct.path != NULL)
2692 LPWSTR help = NULL;
2693 LPCWSTR helpid;
2694 HRESULT res;
2696 helpid = MSI_RecordGetString(row,6);
2698 if (helpid)
2699 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
2700 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
2701 HeapFree(GetProcessHeap(),0,help);
2703 if (!SUCCEEDED(res))
2704 ERR("Failed to register type library %s\n",
2705 debugstr_w(tl_struct.path));
2706 else
2708 ui_actiondata(package,szRegisterTypeLibraries,row);
2710 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
2713 ITypeLib_Release(tl_struct.ptLib);
2714 HeapFree(GetProcessHeap(),0,tl_struct.path);
2716 else
2717 ERR("Failed to load type library %s\n",
2718 debugstr_w(tl_struct.source));
2720 FreeLibrary(module);
2721 HeapFree(GetProcessHeap(),0,tl_struct.source);
2723 else
2724 ERR("Could not load file! %s\n", debugstr_w(file->TargetPath));
2726 return ERROR_SUCCESS;
2729 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
2732 * OK this is a bit confusing.. I am given a _Component key and I believe
2733 * that the file that is being registered as a type library is the "key file
2734 * of that component" which I interpret to mean "The file in the KeyPath of
2735 * that component".
2737 UINT rc;
2738 MSIQUERY * view;
2739 static const WCHAR Query[] =
2740 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2741 '`','T','y','p','e','L','i','b','`',0};
2743 if (!package)
2744 return ERROR_INVALID_HANDLE;
2746 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2747 if (rc != ERROR_SUCCESS)
2748 return ERROR_SUCCESS;
2750 rc = MSI_IterateRecords(view, NULL, ITERATE_RegisterTypeLibraries, package);
2751 msiobj_release(&view->hdr);
2752 return rc;
2755 static UINT ITERATE_CreateShortcuts(MSIRECORD *row, LPVOID param)
2757 MSIPACKAGE *package = (MSIPACKAGE*)param;
2758 LPWSTR target_file, target_folder;
2759 LPCWSTR buffer;
2760 WCHAR filename[0x100];
2761 DWORD sz;
2762 MSICOMPONENT *comp;
2763 static const WCHAR szlnk[]={'.','l','n','k',0};
2764 IShellLinkW *sl;
2765 IPersistFile *pf;
2766 HRESULT res;
2768 buffer = MSI_RecordGetString(row,4);
2769 comp = get_loaded_component(package,buffer);
2770 if (!comp)
2771 return ERROR_SUCCESS;
2773 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2775 TRACE("Skipping shortcut creation due to disabled component\n");
2777 comp->Action = comp->Installed;
2779 return ERROR_SUCCESS;
2782 comp->Action = INSTALLSTATE_LOCAL;
2784 ui_actiondata(package,szCreateShortcuts,row);
2786 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2787 &IID_IShellLinkW, (LPVOID *) &sl );
2789 if (FAILED(res))
2791 ERR("Is IID_IShellLink\n");
2792 return ERROR_SUCCESS;
2795 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
2796 if( FAILED( res ) )
2798 ERR("Is IID_IPersistFile\n");
2799 return ERROR_SUCCESS;
2802 buffer = MSI_RecordGetString(row,2);
2803 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
2805 /* may be needed because of a bug somehwere else */
2806 create_full_pathW(target_folder);
2808 sz = 0x100;
2809 MSI_RecordGetStringW(row,3,filename,&sz);
2810 reduce_to_longfilename(filename);
2811 if (!strchrW(filename,'.') || strcmpiW(strchrW(filename,'.'),szlnk))
2812 strcatW(filename,szlnk);
2813 target_file = build_directory_name(2, target_folder, filename);
2814 HeapFree(GetProcessHeap(),0,target_folder);
2816 buffer = MSI_RecordGetString(row,5);
2817 if (strchrW(buffer,'['))
2819 LPWSTR deformated;
2820 deformat_string(package,buffer,&deformated);
2821 IShellLinkW_SetPath(sl,deformated);
2822 HeapFree(GetProcessHeap(),0,deformated);
2824 else
2826 LPWSTR keypath;
2827 FIXME("poorly handled shortcut format, advertised shortcut\n");
2828 keypath = strdupW( comp->FullKeypath );
2829 IShellLinkW_SetPath(sl,keypath);
2830 HeapFree(GetProcessHeap(),0,keypath);
2833 if (!MSI_RecordIsNull(row,6))
2835 LPWSTR deformated;
2836 buffer = MSI_RecordGetString(row,6);
2837 deformat_string(package,buffer,&deformated);
2838 IShellLinkW_SetArguments(sl,deformated);
2839 HeapFree(GetProcessHeap(),0,deformated);
2842 if (!MSI_RecordIsNull(row,7))
2844 buffer = MSI_RecordGetString(row,7);
2845 IShellLinkW_SetDescription(sl,buffer);
2848 if (!MSI_RecordIsNull(row,8))
2849 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
2851 if (!MSI_RecordIsNull(row,9))
2853 WCHAR *Path = NULL;
2854 INT index;
2856 buffer = MSI_RecordGetString(row,9);
2858 build_icon_path(package,buffer,&Path);
2859 index = MSI_RecordGetInteger(row,10);
2861 IShellLinkW_SetIconLocation(sl,Path,index);
2862 HeapFree(GetProcessHeap(),0,Path);
2865 if (!MSI_RecordIsNull(row,11))
2866 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
2868 if (!MSI_RecordIsNull(row,12))
2870 LPWSTR Path;
2871 buffer = MSI_RecordGetString(row,12);
2872 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
2873 IShellLinkW_SetWorkingDirectory(sl,Path);
2874 HeapFree(GetProcessHeap(), 0, Path);
2877 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
2878 IPersistFile_Save(pf,target_file,FALSE);
2880 HeapFree(GetProcessHeap(),0,target_file);
2882 IPersistFile_Release( pf );
2883 IShellLinkW_Release( sl );
2885 return ERROR_SUCCESS;
2888 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
2890 UINT rc;
2891 HRESULT res;
2892 MSIQUERY * view;
2893 static const WCHAR Query[] =
2894 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2895 '`','S','h','o','r','t','c','u','t','`',0};
2897 if (!package)
2898 return ERROR_INVALID_HANDLE;
2900 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2901 if (rc != ERROR_SUCCESS)
2902 return ERROR_SUCCESS;
2904 res = CoInitialize( NULL );
2905 if (FAILED (res))
2907 ERR("CoInitialize failed\n");
2908 return ERROR_FUNCTION_FAILED;
2911 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateShortcuts, package);
2912 msiobj_release(&view->hdr);
2914 CoUninitialize();
2916 return rc;
2919 static UINT ITERATE_PublishProduct(MSIRECORD *row, LPVOID param)
2921 MSIPACKAGE* package = (MSIPACKAGE*)param;
2922 HANDLE the_file;
2923 LPWSTR FilePath=NULL;
2924 LPCWSTR FileName=NULL;
2925 CHAR buffer[1024];
2926 DWORD sz;
2927 UINT rc;
2929 FileName = MSI_RecordGetString(row,1);
2930 if (!FileName)
2932 ERR("Unable to get FileName\n");
2933 return ERROR_SUCCESS;
2936 build_icon_path(package,FileName,&FilePath);
2938 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
2940 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2941 FILE_ATTRIBUTE_NORMAL, NULL);
2943 if (the_file == INVALID_HANDLE_VALUE)
2945 ERR("Unable to create file %s\n",debugstr_w(FilePath));
2946 HeapFree(GetProcessHeap(),0,FilePath);
2947 return ERROR_SUCCESS;
2952 DWORD write;
2953 sz = 1024;
2954 rc = MSI_RecordReadStream(row,2,buffer,&sz);
2955 if (rc != ERROR_SUCCESS)
2957 ERR("Failed to get stream\n");
2958 CloseHandle(the_file);
2959 DeleteFileW(FilePath);
2960 break;
2962 WriteFile(the_file,buffer,sz,&write,NULL);
2963 } while (sz == 1024);
2965 HeapFree(GetProcessHeap(),0,FilePath);
2967 CloseHandle(the_file);
2968 return ERROR_SUCCESS;
2972 * 99% of the work done here is only done for
2973 * advertised installs. However this is where the
2974 * Icon table is processed and written out
2975 * so that is what I am going to do here.
2977 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
2979 UINT rc;
2980 MSIQUERY * view;
2981 static const WCHAR Query[]=
2982 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2983 '`','I','c','o','n','`',0};
2984 /* for registry stuff */
2985 HKEY hkey=0;
2986 HKEY hukey=0;
2987 static const WCHAR szProductLanguage[] =
2988 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
2989 static const WCHAR szARPProductIcon[] =
2990 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
2991 static const WCHAR szProductVersion[] =
2992 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
2993 DWORD langid;
2994 LPWSTR buffer;
2995 DWORD size;
2996 MSIHANDLE hDb, hSumInfo;
2998 if (!package)
2999 return ERROR_INVALID_HANDLE;
3001 /* write out icon files */
3003 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3004 if (rc == ERROR_SUCCESS)
3006 MSI_IterateRecords(view, NULL, ITERATE_PublishProduct, package);
3007 msiobj_release(&view->hdr);
3010 /* ok there is a lot more done here but i need to figure out what */
3012 rc = MSIREG_OpenProductsKey(package->ProductCode,&hkey,TRUE);
3013 if (rc != ERROR_SUCCESS)
3014 goto end;
3016 rc = MSIREG_OpenUserProductsKey(package->ProductCode,&hukey,TRUE);
3017 if (rc != ERROR_SUCCESS)
3018 goto end;
3021 buffer = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTNAMEW,NULL);
3022 size = strlenW(buffer)*sizeof(WCHAR);
3023 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTNAMEW,0,REG_SZ,
3024 (LPBYTE)buffer,size);
3025 HeapFree(GetProcessHeap(),0,buffer);
3027 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3028 size = sizeof(DWORD);
3029 langid = atoiW(buffer);
3030 RegSetValueExW(hukey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3031 (LPBYTE)&langid,size);
3032 HeapFree(GetProcessHeap(),0,buffer);
3034 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
3035 if (buffer)
3037 LPWSTR path;
3038 build_icon_path(package,buffer,&path);
3039 size = strlenW(path) * sizeof(WCHAR);
3040 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTICONW,0,REG_SZ,
3041 (LPBYTE)path,size);
3043 HeapFree(GetProcessHeap(),0,buffer);
3045 buffer = load_dynamic_property(package,szProductVersion,NULL);
3046 if (buffer)
3048 DWORD verdword = build_version_dword(buffer);
3049 size = sizeof(DWORD);
3050 RegSetValueExW(hukey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD, (LPBYTE
3051 )&verdword,size);
3053 HeapFree(GetProcessHeap(),0,buffer);
3055 FIXME("Need to write more keys to the user registry\n");
3057 hDb= alloc_msihandle( &package->db->hdr );
3058 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
3059 MsiCloseHandle(hDb);
3060 if (rc == ERROR_SUCCESS)
3062 WCHAR guidbuffer[0x200];
3063 size = 0x200;
3064 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
3065 guidbuffer, &size);
3066 if (rc == ERROR_SUCCESS)
3068 WCHAR squashed[GUID_SIZE];
3069 /* for now we only care about the first guid */
3070 LPWSTR ptr = strchrW(guidbuffer,';');
3071 if (ptr) *ptr = 0;
3072 squash_guid(guidbuffer,squashed);
3073 size = strlenW(squashed)*sizeof(WCHAR);
3074 RegSetValueExW(hukey,INSTALLPROPERTY_PACKAGECODEW,0,REG_SZ,
3075 (LPBYTE)squashed, size);
3077 else
3079 ERR("Unable to query Revision_Number... \n");
3080 rc = ERROR_SUCCESS;
3082 MsiCloseHandle(hSumInfo);
3084 else
3086 ERR("Unable to open Summary Information\n");
3087 rc = ERROR_SUCCESS;
3090 end:
3092 RegCloseKey(hkey);
3093 RegCloseKey(hukey);
3095 return rc;
3098 static UINT ITERATE_WriteIniValues(MSIRECORD *row, LPVOID param)
3100 MSIPACKAGE *package = (MSIPACKAGE*)param;
3101 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
3102 LPWSTR deformated_section, deformated_key, deformated_value;
3103 LPWSTR folder, fullname = NULL;
3104 MSIRECORD * uirow;
3105 INT action;
3106 MSICOMPONENT *comp;
3107 static const WCHAR szWindowsFolder[] =
3108 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3110 component = MSI_RecordGetString(row, 8);
3111 comp = get_loaded_component(package,component);
3113 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
3115 TRACE("Skipping ini file due to disabled component %s\n",
3116 debugstr_w(component));
3118 comp->Action = comp->Installed;
3120 return ERROR_SUCCESS;
3123 comp->Action = INSTALLSTATE_LOCAL;
3125 identifier = MSI_RecordGetString(row,1);
3126 filename = MSI_RecordGetString(row,2);
3127 dirproperty = MSI_RecordGetString(row,3);
3128 section = MSI_RecordGetString(row,4);
3129 key = MSI_RecordGetString(row,5);
3130 value = MSI_RecordGetString(row,6);
3131 action = MSI_RecordGetInteger(row,7);
3133 deformat_string(package,section,&deformated_section);
3134 deformat_string(package,key,&deformated_key);
3135 deformat_string(package,value,&deformated_value);
3137 if (dirproperty)
3139 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
3140 if (!folder)
3141 folder = load_dynamic_property(package,dirproperty,NULL);
3143 else
3144 folder = load_dynamic_property(package, szWindowsFolder, NULL);
3146 if (!folder)
3148 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
3149 goto cleanup;
3152 fullname = build_directory_name(2, folder, filename);
3154 if (action == 0)
3156 TRACE("Adding value %s to section %s in %s\n",
3157 debugstr_w(deformated_key), debugstr_w(deformated_section),
3158 debugstr_w(fullname));
3159 WritePrivateProfileStringW(deformated_section, deformated_key,
3160 deformated_value, fullname);
3162 else if (action == 1)
3164 WCHAR returned[10];
3165 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
3166 returned, 10, fullname);
3167 if (returned[0] == 0)
3169 TRACE("Adding value %s to section %s in %s\n",
3170 debugstr_w(deformated_key), debugstr_w(deformated_section),
3171 debugstr_w(fullname));
3173 WritePrivateProfileStringW(deformated_section, deformated_key,
3174 deformated_value, fullname);
3177 else if (action == 3)
3178 FIXME("Append to existing section not yet implemented\n");
3180 uirow = MSI_CreateRecord(4);
3181 MSI_RecordSetStringW(uirow,1,identifier);
3182 MSI_RecordSetStringW(uirow,2,deformated_section);
3183 MSI_RecordSetStringW(uirow,3,deformated_key);
3184 MSI_RecordSetStringW(uirow,4,deformated_value);
3185 ui_actiondata(package,szWriteIniValues,uirow);
3186 msiobj_release( &uirow->hdr );
3187 cleanup:
3188 HeapFree(GetProcessHeap(),0,fullname);
3189 HeapFree(GetProcessHeap(),0,folder);
3190 HeapFree(GetProcessHeap(),0,deformated_key);
3191 HeapFree(GetProcessHeap(),0,deformated_value);
3192 HeapFree(GetProcessHeap(),0,deformated_section);
3193 return ERROR_SUCCESS;
3196 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
3198 UINT rc;
3199 MSIQUERY * view;
3200 static const WCHAR ExecSeqQuery[] =
3201 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3202 '`','I','n','i','F','i','l','e','`',0};
3204 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3205 if (rc != ERROR_SUCCESS)
3207 TRACE("no IniFile table\n");
3208 return ERROR_SUCCESS;
3211 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteIniValues, package);
3212 msiobj_release(&view->hdr);
3213 return rc;
3216 static UINT ITERATE_SelfRegModules(MSIRECORD *row, LPVOID param)
3218 MSIPACKAGE *package = (MSIPACKAGE*)param;
3219 LPCWSTR filename;
3220 LPWSTR FullName;
3221 MSIFILE *file;
3222 DWORD len;
3223 static const WCHAR ExeStr[] =
3224 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3225 static const WCHAR close[] = {'\"',0};
3226 STARTUPINFOW si;
3227 PROCESS_INFORMATION info;
3228 BOOL brc;
3230 memset(&si,0,sizeof(STARTUPINFOW));
3232 filename = MSI_RecordGetString(row,1);
3233 file = get_loaded_file( package, filename );
3235 if (!file)
3237 ERR("Unable to find file id %s\n",debugstr_w(filename));
3238 return ERROR_SUCCESS;
3241 len = strlenW(ExeStr) + strlenW( file->TargetPath ) + 2;
3243 FullName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3244 strcpyW(FullName,ExeStr);
3245 strcatW( FullName, file->TargetPath );
3246 strcatW(FullName,close);
3248 TRACE("Registering %s\n",debugstr_w(FullName));
3249 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL, c_colon,
3250 &si, &info);
3252 if (brc)
3253 msi_dialog_check_messages(info.hProcess);
3255 HeapFree(GetProcessHeap(),0,FullName);
3256 return ERROR_SUCCESS;
3259 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
3261 UINT rc;
3262 MSIQUERY * view;
3263 static const WCHAR ExecSeqQuery[] =
3264 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3265 '`','S','e','l','f','R','e','g','`',0};
3267 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3268 if (rc != ERROR_SUCCESS)
3270 TRACE("no SelfReg table\n");
3271 return ERROR_SUCCESS;
3274 MSI_IterateRecords(view, NULL, ITERATE_SelfRegModules, package);
3275 msiobj_release(&view->hdr);
3277 return ERROR_SUCCESS;
3280 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
3282 MSIFEATURE *feature;
3283 UINT rc;
3284 HKEY hkey=0;
3285 HKEY hukey=0;
3287 if (!package)
3288 return ERROR_INVALID_HANDLE;
3290 rc = MSIREG_OpenFeaturesKey(package->ProductCode,&hkey,TRUE);
3291 if (rc != ERROR_SUCCESS)
3292 goto end;
3294 rc = MSIREG_OpenUserFeaturesKey(package->ProductCode,&hukey,TRUE);
3295 if (rc != ERROR_SUCCESS)
3296 goto end;
3298 /* here the guids are base 85 encoded */
3299 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
3301 ComponentList *cl;
3302 LPWSTR data = NULL;
3303 GUID clsid;
3304 INT size;
3305 BOOL absent = FALSE;
3307 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ) &&
3308 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_SOURCE ) &&
3309 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED ))
3310 absent = TRUE;
3312 size = 1;
3313 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3315 size += 21;
3317 if (feature->Feature_Parent[0])
3318 size += strlenW( feature->Feature_Parent )+2;
3320 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
3322 data[0] = 0;
3323 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3325 MSICOMPONENT* component = cl->component;
3326 WCHAR buf[21];
3328 memset(buf,0,sizeof(buf));
3329 if ( component->ComponentId[0] )
3331 TRACE("From %s\n",debugstr_w(component->ComponentId));
3332 CLSIDFromString(component->ComponentId, &clsid);
3333 encode_base85_guid(&clsid,buf);
3334 TRACE("to %s\n",debugstr_w(buf));
3335 strcatW(data,buf);
3338 if (feature->Feature_Parent[0])
3340 static const WCHAR sep[] = {'\2',0};
3341 strcatW(data,sep);
3342 strcatW(data,feature->Feature_Parent);
3345 size = (strlenW(data)+1)*sizeof(WCHAR);
3346 RegSetValueExW( hkey, feature->Feature, 0, REG_SZ, (LPBYTE)data,size );
3347 HeapFree(GetProcessHeap(),0,data);
3349 if (!absent)
3351 size = strlenW(feature->Feature_Parent)*sizeof(WCHAR);
3352 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3353 (LPBYTE)feature->Feature_Parent,size);
3355 else
3357 size = (strlenW(feature->Feature_Parent)+2)* sizeof(WCHAR);
3358 data = HeapAlloc(GetProcessHeap(),0,size);
3359 data[0] = 0x6;
3360 strcpyW( &data[1], feature->Feature_Parent );
3361 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3362 (LPBYTE)data,size);
3363 HeapFree(GetProcessHeap(),0,data);
3367 end:
3368 RegCloseKey(hkey);
3369 RegCloseKey(hukey);
3370 return rc;
3373 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
3375 HKEY hkey=0;
3376 LPWSTR buffer = NULL;
3377 UINT rc,i;
3378 DWORD size;
3379 static WCHAR szNONE[] = {0};
3380 static const WCHAR szWindowsInstaler[] =
3381 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3382 static const WCHAR szPropKeys[][80] =
3384 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3385 {'A','R','P','C','O','N','T','A','C','T',0},
3386 {'A','R','P','C','O','M','M','E','N','T','S',0},
3387 {'P','r','o','d','u','c','t','N','a','m','e',0},
3388 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3389 {'A','R','P','H','E','L','P','L','I','N','K',0},
3390 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3391 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3392 {'S','o','u','r','c','e','D','i','r',0},
3393 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3394 {'A','R','P','R','E','A','D','M','E',0},
3395 {'A','R','P','S','I','Z','E',0},
3396 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3397 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3398 {0},
3401 static const WCHAR szRegKeys[][80] =
3403 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3404 {'C','o','n','t','a','c','t',0},
3405 {'C','o','m','m','e','n','t','s',0},
3406 {'D','i','s','p','l','a','y','N','a','m','e',0},
3407 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3408 {'H','e','l','p','L','i','n','k',0},
3409 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3410 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3411 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3412 {'P','u','b','l','i','s','h','e','r',0},
3413 {'R','e','a','d','m','e',0},
3414 {'S','i','z','e',0},
3415 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3416 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3417 {0},
3420 static const WCHAR installerPathFmt[] = {
3421 '%','s','\\',
3422 'I','n','s','t','a','l','l','e','r','\\',0};
3423 static const WCHAR fmt[] = {
3424 '%','s','\\',
3425 'I','n','s','t','a','l','l','e','r','\\',
3426 '%','x','.','m','s','i',0};
3427 static const WCHAR szUpgradeCode[] =
3428 {'U','p','g','r','a','d','e','C','o','d','e',0};
3429 static const WCHAR modpath_fmt[] =
3430 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3431 static const WCHAR szModifyPath[] =
3432 {'M','o','d','i','f','y','P','a','t','h',0};
3433 static const WCHAR szUninstallString[] =
3434 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3435 static const WCHAR szEstimatedSize[] =
3436 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3437 static const WCHAR szProductLanguage[] =
3438 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3439 static const WCHAR szProductVersion[] =
3440 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3442 SYSTEMTIME systime;
3443 static const WCHAR date_fmt[] = {'%','i','%','i','%','i',0};
3444 LPWSTR upgrade_code;
3445 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
3446 INT num,start;
3448 if (!package)
3449 return ERROR_INVALID_HANDLE;
3451 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3452 if (rc != ERROR_SUCCESS)
3453 goto end;
3455 /* dump all the info i can grab */
3456 FIXME("Flesh out more information \n");
3458 i = 0;
3459 while (szPropKeys[i][0]!=0)
3461 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3462 if (rc != ERROR_SUCCESS)
3463 buffer = szNONE;
3464 size = strlenW(buffer)*sizeof(WCHAR);
3465 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3466 HeapFree(GetProcessHeap(),0,buffer);
3467 i++;
3470 rc = 0x1;
3471 size = sizeof(rc);
3472 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPBYTE)&rc,size);
3474 /* copy the package locally */
3475 num = GetTickCount() & 0xffff;
3476 if (!num)
3477 num = 1;
3478 start = num;
3479 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
3480 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
3481 windir,num);
3484 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
3485 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
3486 if (handle != INVALID_HANDLE_VALUE)
3488 CloseHandle(handle);
3489 break;
3491 if (GetLastError() != ERROR_FILE_EXISTS &&
3492 GetLastError() != ERROR_SHARING_VIOLATION)
3493 break;
3494 if (!(++num & 0xffff)) num = 1;
3495 sprintfW(packagefile,fmt,num);
3496 } while (num != start);
3498 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
3499 create_full_pathW(path);
3500 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
3501 if (!CopyFileW(package->msiFilePath,packagefile,FALSE))
3502 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3503 debugstr_w(package->msiFilePath), debugstr_w(packagefile),
3504 GetLastError());
3505 size = strlenW(packagefile)*sizeof(WCHAR);
3506 RegSetValueExW(hkey,INSTALLPROPERTY_LOCALPACKAGEW,0,REG_SZ,
3507 (LPBYTE)packagefile,size);
3509 /* do ModifyPath and UninstallString */
3510 size = deformat_string(package,modpath_fmt,&buffer);
3511 RegSetValueExW(hkey,szModifyPath,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3512 RegSetValueExW(hkey,szUninstallString,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3513 HeapFree(GetProcessHeap(),0,buffer);
3515 FIXME("Write real Estimated Size when we have it\n");
3516 size = 0;
3517 RegSetValueExW(hkey,szEstimatedSize,0,REG_DWORD,(LPBYTE)&size,sizeof(DWORD));
3519 GetLocalTime(&systime);
3520 size = 9*sizeof(WCHAR);
3521 buffer= HeapAlloc(GetProcessHeap(),0,size);
3522 sprintfW(buffer,date_fmt,systime.wYear,systime.wMonth,systime.wDay);
3523 size = strlenW(buffer)*sizeof(WCHAR);
3524 RegSetValueExW(hkey,INSTALLPROPERTY_INSTALLDATEW,0,REG_SZ,
3525 (LPBYTE)buffer,size);
3526 HeapFree(GetProcessHeap(),0,buffer);
3528 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3529 size = atoiW(buffer);
3530 RegSetValueExW(hkey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3531 (LPBYTE)&size,sizeof(DWORD));
3532 HeapFree(GetProcessHeap(),1,buffer);
3534 buffer = load_dynamic_property(package,szProductVersion,NULL);
3535 if (buffer)
3537 DWORD verdword = build_version_dword(buffer);
3538 DWORD vermajor = verdword>>24;
3539 DWORD verminor = (verdword>>16)&0x00FF;
3540 size = sizeof(DWORD);
3541 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD,
3542 (LPBYTE)&verdword,size);
3543 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMAJORW,0,REG_DWORD,
3544 (LPBYTE)&vermajor,size);
3545 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMINORW,0,REG_DWORD,
3546 (LPBYTE)&verminor,size);
3548 HeapFree(GetProcessHeap(),0,buffer);
3550 /* Handle Upgrade Codes */
3551 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
3552 if (upgrade_code)
3554 HKEY hkey2;
3555 WCHAR squashed[33];
3556 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3557 squash_guid(package->ProductCode,squashed);
3558 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3559 RegCloseKey(hkey2);
3560 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3561 squash_guid(package->ProductCode,squashed);
3562 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3563 RegCloseKey(hkey2);
3565 HeapFree(GetProcessHeap(),0,upgrade_code);
3568 end:
3569 RegCloseKey(hkey);
3571 return ERROR_SUCCESS;
3574 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
3576 UINT rc;
3578 if (!package)
3579 return ERROR_INVALID_HANDLE;
3581 rc = execute_script(package,INSTALL_SCRIPT);
3583 return rc;
3586 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
3588 UINT rc;
3590 if (!package)
3591 return ERROR_INVALID_HANDLE;
3593 /* turn off scheduleing */
3594 package->script->CurrentlyScripting= FALSE;
3596 /* first do the same as an InstallExecute */
3597 rc = ACTION_InstallExecute(package);
3598 if (rc != ERROR_SUCCESS)
3599 return rc;
3601 /* then handle Commit Actions */
3602 rc = execute_script(package,COMMIT_SCRIPT);
3604 return rc;
3607 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
3609 static const WCHAR RunOnce[] = {
3610 'S','o','f','t','w','a','r','e','\\',
3611 'M','i','c','r','o','s','o','f','t','\\',
3612 'W','i','n','d','o','w','s','\\',
3613 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3614 'R','u','n','O','n','c','e',0};
3615 static const WCHAR InstallRunOnce[] = {
3616 'S','o','f','t','w','a','r','e','\\',
3617 'M','i','c','r','o','s','o','f','t','\\',
3618 'W','i','n','d','o','w','s','\\',
3619 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3620 'I','n','s','t','a','l','l','e','r','\\',
3621 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3623 static const WCHAR msiexec_fmt[] = {
3624 '%','s',
3625 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3626 '\"','%','s','\"',0};
3627 static const WCHAR install_fmt[] = {
3628 '/','I',' ','\"','%','s','\"',' ',
3629 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3630 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3631 WCHAR buffer[256], sysdir[MAX_PATH];
3632 HKEY hkey;
3633 WCHAR squished_pc[100];
3634 DWORD size;
3636 if (!package)
3637 return ERROR_INVALID_HANDLE;
3639 squash_guid(package->ProductCode,squished_pc);
3641 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
3642 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
3643 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
3644 squished_pc);
3646 size = strlenW(buffer)*sizeof(WCHAR);
3647 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3648 RegCloseKey(hkey);
3650 TRACE("Reboot command %s\n",debugstr_w(buffer));
3652 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
3653 sprintfW(buffer,install_fmt,package->ProductCode,squished_pc);
3655 size = strlenW(buffer)*sizeof(WCHAR);
3656 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3657 RegCloseKey(hkey);
3659 return ERROR_INSTALL_SUSPEND;
3662 UINT ACTION_ResolveSource(MSIPACKAGE* package)
3664 DWORD attrib;
3665 UINT rc;
3667 * we are currently doing what should be done here in the top level Install
3668 * however for Adminastrative and uninstalls this step will be needed
3670 if (!package->PackagePath)
3671 return ERROR_SUCCESS;
3673 attrib = GetFileAttributesW(package->PackagePath);
3674 if (attrib == INVALID_FILE_ATTRIBUTES)
3676 LPWSTR prompt;
3677 LPWSTR msg;
3678 DWORD size = 0;
3680 rc = MsiSourceListGetInfoW(package->ProductCode, NULL,
3681 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3682 INSTALLPROPERTY_DISKPROMPTW,NULL,&size);
3683 if (rc == ERROR_MORE_DATA)
3685 prompt = HeapAlloc(GetProcessHeap(),0,size * sizeof(WCHAR));
3686 MsiSourceListGetInfoW(package->ProductCode, NULL,
3687 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3688 INSTALLPROPERTY_DISKPROMPTW,prompt,&size);
3690 else
3691 prompt = strdupW(package->PackagePath);
3693 msg = generate_error_string(package,1302,1,prompt);
3694 while(attrib == INVALID_FILE_ATTRIBUTES)
3696 rc = MessageBoxW(NULL,msg,NULL,MB_OKCANCEL);
3697 if (rc == IDCANCEL)
3699 rc = ERROR_INSTALL_USEREXIT;
3700 break;
3702 attrib = GetFileAttributesW(package->PackagePath);
3704 HeapFree(GetProcessHeap(),0,prompt);
3705 rc = ERROR_SUCCESS;
3707 else
3708 return ERROR_SUCCESS;
3710 return rc;
3713 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
3715 HKEY hkey=0;
3716 LPWSTR buffer;
3717 LPWSTR productid;
3718 UINT rc,i;
3719 DWORD size;
3721 static const WCHAR szPropKeys[][80] =
3723 {'P','r','o','d','u','c','t','I','D',0},
3724 {'U','S','E','R','N','A','M','E',0},
3725 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3726 {0},
3729 static const WCHAR szRegKeys[][80] =
3731 {'P','r','o','d','u','c','t','I','D',0},
3732 {'R','e','g','O','w','n','e','r',0},
3733 {'R','e','g','C','o','m','p','a','n','y',0},
3734 {0},
3737 if (!package)
3738 return ERROR_INVALID_HANDLE;
3740 productid = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTIDW,
3741 &rc);
3742 if (!productid)
3743 return ERROR_SUCCESS;
3745 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3746 if (rc != ERROR_SUCCESS)
3747 goto end;
3749 i = 0;
3750 while (szPropKeys[i][0]!=0)
3752 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3753 if (rc == ERROR_SUCCESS)
3755 size = strlenW(buffer)*sizeof(WCHAR);
3756 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3758 else
3759 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
3760 i++;
3763 end:
3764 HeapFree(GetProcessHeap(),0,productid);
3765 RegCloseKey(hkey);
3767 return ERROR_SUCCESS;
3771 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
3773 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
3774 static const WCHAR szTwo[] = {'2',0};
3775 UINT rc;
3776 LPWSTR level;
3777 level = load_dynamic_property(package,szUILevel,NULL);
3779 MSI_SetPropertyW(package,szUILevel,szTwo);
3780 package->script->InWhatSequence |= SEQUENCE_EXEC;
3781 rc = ACTION_ProcessExecSequence(package,FALSE);
3782 MSI_SetPropertyW(package,szUILevel,level);
3783 HeapFree(GetProcessHeap(),0,level);
3784 return rc;
3789 * Code based off of code located here
3790 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3792 * Using string index 4 (full font name) instead of 1 (family name)
3794 static LPWSTR load_ttfname_from(LPCWSTR filename)
3796 HANDLE handle;
3797 LPWSTR ret = NULL;
3798 int i;
3800 typedef struct _tagTT_OFFSET_TABLE{
3801 USHORT uMajorVersion;
3802 USHORT uMinorVersion;
3803 USHORT uNumOfTables;
3804 USHORT uSearchRange;
3805 USHORT uEntrySelector;
3806 USHORT uRangeShift;
3807 }TT_OFFSET_TABLE;
3809 typedef struct _tagTT_TABLE_DIRECTORY{
3810 char szTag[4]; /* table name */
3811 ULONG uCheckSum; /* Check sum */
3812 ULONG uOffset; /* Offset from beginning of file */
3813 ULONG uLength; /* length of the table in bytes */
3814 }TT_TABLE_DIRECTORY;
3816 typedef struct _tagTT_NAME_TABLE_HEADER{
3817 USHORT uFSelector; /* format selector. Always 0 */
3818 USHORT uNRCount; /* Name Records count */
3819 USHORT uStorageOffset; /* Offset for strings storage,
3820 * from start of the table */
3821 }TT_NAME_TABLE_HEADER;
3823 typedef struct _tagTT_NAME_RECORD{
3824 USHORT uPlatformID;
3825 USHORT uEncodingID;
3826 USHORT uLanguageID;
3827 USHORT uNameID;
3828 USHORT uStringLength;
3829 USHORT uStringOffset; /* from start of storage area */
3830 }TT_NAME_RECORD;
3832 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3833 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3835 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
3836 FILE_ATTRIBUTE_NORMAL, 0 );
3837 if (handle != INVALID_HANDLE_VALUE)
3839 TT_TABLE_DIRECTORY tblDir;
3840 BOOL bFound = FALSE;
3841 TT_OFFSET_TABLE ttOffsetTable;
3843 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
3844 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
3845 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
3846 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
3848 if (ttOffsetTable.uMajorVersion != 1 ||
3849 ttOffsetTable.uMinorVersion != 0)
3850 return NULL;
3852 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
3854 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
3855 if (strncmp(tblDir.szTag,"name",4)==0)
3857 bFound = TRUE;
3858 tblDir.uLength = SWAPLONG(tblDir.uLength);
3859 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
3860 break;
3864 if (bFound)
3866 TT_NAME_TABLE_HEADER ttNTHeader;
3867 TT_NAME_RECORD ttRecord;
3869 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
3870 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
3871 NULL,NULL);
3873 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
3874 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
3875 bFound = FALSE;
3876 for(i=0; i<ttNTHeader.uNRCount; i++)
3878 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
3879 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
3880 /* 4 is the Full Font Name */
3881 if(ttRecord.uNameID == 4)
3883 int nPos;
3884 LPSTR buf;
3885 static LPCSTR tt = " (TrueType)";
3887 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
3888 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
3889 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
3890 SetFilePointer(handle, tblDir.uOffset +
3891 ttRecord.uStringOffset +
3892 ttNTHeader.uStorageOffset,
3893 NULL, FILE_BEGIN);
3894 buf = HeapAlloc(GetProcessHeap(), 0,
3895 ttRecord.uStringLength + 1 + strlen(tt));
3896 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
3897 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
3898 if (strlen(buf) > 0)
3900 strcat(buf,tt);
3901 ret = strdupAtoW(buf);
3902 HeapFree(GetProcessHeap(),0,buf);
3903 break;
3906 HeapFree(GetProcessHeap(),0,buf);
3907 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
3911 CloseHandle(handle);
3913 else
3914 ERR("Unable to open font file %s\n", debugstr_w(filename));
3916 TRACE("Returning fontname %s\n",debugstr_w(ret));
3917 return ret;
3920 static UINT ITERATE_RegisterFonts(MSIRECORD *row, LPVOID param)
3922 MSIPACKAGE *package = (MSIPACKAGE*)param;
3923 LPWSTR name;
3924 LPCWSTR filename;
3925 MSIFILE *file;
3926 DWORD size;
3927 static const WCHAR regfont1[] =
3928 {'S','o','f','t','w','a','r','e','\\',
3929 'M','i','c','r','o','s','o','f','t','\\',
3930 'W','i','n','d','o','w','s',' ','N','T','\\',
3931 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3932 'F','o','n','t','s',0};
3933 static const WCHAR regfont2[] =
3934 {'S','o','f','t','w','a','r','e','\\',
3935 'M','i','c','r','o','s','o','f','t','\\',
3936 'W','i','n','d','o','w','s','\\',
3937 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3938 'F','o','n','t','s',0};
3939 HKEY hkey1;
3940 HKEY hkey2;
3942 filename = MSI_RecordGetString( row, 1 );
3943 file = get_loaded_file( package, filename );
3944 if (!file)
3946 ERR("Unable to load file\n");
3947 return ERROR_SUCCESS;
3950 /* check to make sure that component is installed */
3951 if (!ACTION_VerifyComponentForAction(package,
3952 file->Component, INSTALLSTATE_LOCAL))
3954 TRACE("Skipping: Component not scheduled for install\n");
3955 return ERROR_SUCCESS;
3958 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
3959 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
3961 if (MSI_RecordIsNull(row,2))
3962 name = load_ttfname_from( file->TargetPath );
3963 else
3964 name = load_dynamic_stringW(row,2);
3966 if (name)
3968 size = strlenW( file->FileName ) * sizeof(WCHAR);
3969 RegSetValueExW( hkey1, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3970 RegSetValueExW( hkey2, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3973 HeapFree(GetProcessHeap(),0,name);
3974 RegCloseKey(hkey1);
3975 RegCloseKey(hkey2);
3976 return ERROR_SUCCESS;
3979 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
3981 UINT rc;
3982 MSIQUERY * view;
3983 static const WCHAR ExecSeqQuery[] =
3984 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3985 '`','F','o','n','t','`',0};
3987 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3988 if (rc != ERROR_SUCCESS)
3990 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
3991 return ERROR_SUCCESS;
3994 MSI_IterateRecords(view, NULL, ITERATE_RegisterFonts, package);
3995 msiobj_release(&view->hdr);
3997 return ERROR_SUCCESS;
4000 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
4002 MSIPACKAGE *package = (MSIPACKAGE*)param;
4003 LPCWSTR compgroupid=NULL;
4004 LPCWSTR feature=NULL;
4005 LPCWSTR text = NULL;
4006 LPCWSTR qualifier = NULL;
4007 LPCWSTR component = NULL;
4008 LPWSTR advertise = NULL;
4009 LPWSTR output = NULL;
4010 HKEY hkey;
4011 UINT rc = ERROR_SUCCESS;
4012 MSICOMPONENT *comp;
4013 DWORD sz = 0;
4015 component = MSI_RecordGetString(rec,3);
4016 comp = get_loaded_component(package,component);
4018 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL) &&
4019 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_SOURCE) &&
4020 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_ADVERTISED))
4022 TRACE("Skipping: Component %s not scheduled for install\n",
4023 debugstr_w(component));
4025 return ERROR_SUCCESS;
4028 compgroupid = MSI_RecordGetString(rec,1);
4030 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
4031 if (rc != ERROR_SUCCESS)
4032 goto end;
4034 text = MSI_RecordGetString(rec,4);
4035 qualifier = MSI_RecordGetString(rec,2);
4036 feature = MSI_RecordGetString(rec,5);
4038 advertise = create_component_advertise_string(package, comp, feature);
4040 sz = strlenW(advertise);
4042 if (text)
4043 sz += lstrlenW(text);
4045 sz+=3;
4046 sz *= sizeof(WCHAR);
4048 output = HeapAlloc(GetProcessHeap(),0,sz);
4049 memset(output,0,sz);
4050 strcpyW(output,advertise);
4052 if (text)
4053 strcatW(output,text);
4055 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
4056 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
4058 end:
4059 RegCloseKey(hkey);
4060 HeapFree(GetProcessHeap(),0,output);
4062 return rc;
4066 * At present I am ignorning the advertised components part of this and only
4067 * focusing on the qualified component sets
4069 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
4071 UINT rc;
4072 MSIQUERY * view;
4073 static const WCHAR ExecSeqQuery[] =
4074 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4075 '`','P','u','b','l','i','s','h',
4076 'C','o','m','p','o','n','e','n','t','`',0};
4078 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4079 if (rc != ERROR_SUCCESS)
4080 return ERROR_SUCCESS;
4082 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
4083 msiobj_release(&view->hdr);
4085 return rc;