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
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
37 #include "wine/debug.h"
42 #include "wine/unicode.h"
46 #define REG_PROGRESS_VALUE 13200
47 #define COMPONENT_PROGRESS_VALUE 24000
49 WINE_DEFAULT_DEBUG_CHANNEL(msi);
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);
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);
90 * consts and values used
92 static const WCHAR c_colon[] = {'C',':','\\',0};
94 const static WCHAR szCreateFolders[] =
95 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
96 const static WCHAR szCostFinalize[] =
97 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
98 const WCHAR szInstallFiles[] =
99 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
100 const WCHAR szDuplicateFiles[] =
101 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
102 const static WCHAR szWriteRegistryValues[] =
103 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
104 'V','a','l','u','e','s',0};
105 const static WCHAR szCostInitialize[] =
106 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
107 const static WCHAR szFileCost[] =
108 {'F','i','l','e','C','o','s','t',0};
109 const static WCHAR szInstallInitialize[] =
110 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
111 const static WCHAR szInstallValidate[] =
112 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
113 const static WCHAR szLaunchConditions[] =
114 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
115 const static WCHAR szProcessComponents[] =
116 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
117 const static WCHAR szRegisterTypeLibraries[] =
118 {'R','e','g','i','s','t','e','r','T','y','p','e',
119 'L','i','b','r','a','r','i','e','s',0};
120 const WCHAR szRegisterClassInfo[] =
121 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
122 const WCHAR szRegisterProgIdInfo[] =
123 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
124 const static WCHAR szCreateShortcuts[] =
125 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
126 const static WCHAR szPublishProduct[] =
127 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
128 const static WCHAR szWriteIniValues[] =
129 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
130 const static WCHAR szSelfRegModules[] =
131 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
132 const static WCHAR szPublishFeatures[] =
133 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
134 const static WCHAR szRegisterProduct[] =
135 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
136 const static WCHAR szInstallExecute[] =
137 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
138 const static WCHAR szInstallExecuteAgain[] =
139 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
140 'A','g','a','i','n',0};
141 const static WCHAR szInstallFinalize[] =
142 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
143 const static WCHAR szForceReboot[] =
144 {'F','o','r','c','e','R','e','b','o','o','t',0};
145 const static WCHAR szResolveSource[] =
146 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
147 const WCHAR szAppSearch[] =
148 {'A','p','p','S','e','a','r','c','h',0};
149 const static WCHAR szAllocateRegistrySpace[] =
150 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
151 'S','p','a','c','e',0};
152 const static WCHAR szBindImage[] =
153 {'B','i','n','d','I','m','a','g','e',0};
154 const static WCHAR szCCPSearch[] =
155 {'C','C','P','S','e','a','r','c','h',0};
156 const static WCHAR szDeleteServices[] =
157 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
158 const static WCHAR szDisableRollback[] =
159 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
160 const static WCHAR szExecuteAction[] =
161 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
162 const WCHAR szFindRelatedProducts[] =
163 {'F','i','n','d','R','e','l','a','t','e','d',
164 'P','r','o','d','u','c','t','s',0};
165 const static WCHAR szInstallAdminPackage[] =
166 {'I','n','s','t','a','l','l','A','d','m','i','n',
167 'P','a','c','k','a','g','e',0};
168 const static WCHAR szInstallSFPCatalogFile[] =
169 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
171 const static WCHAR szIsolateComponents[] =
172 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
173 const WCHAR szMigrateFeatureStates[] =
174 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
175 'S','t','a','t','e','s',0};
176 const WCHAR szMoveFiles[] =
177 {'M','o','v','e','F','i','l','e','s',0};
178 const static WCHAR szMsiPublishAssemblies[] =
179 {'M','s','i','P','u','b','l','i','s','h',
180 'A','s','s','e','m','b','l','i','e','s',0};
181 const static WCHAR szMsiUnpublishAssemblies[] =
182 {'M','s','i','U','n','p','u','b','l','i','s','h',
183 'A','s','s','e','m','b','l','i','e','s',0};
184 const static WCHAR szInstallODBC[] =
185 {'I','n','s','t','a','l','l','O','D','B','C',0};
186 const static WCHAR szInstallServices[] =
187 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
188 const WCHAR szPatchFiles[] =
189 {'P','a','t','c','h','F','i','l','e','s',0};
190 const static WCHAR szPublishComponents[] =
191 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
192 const static WCHAR szRegisterComPlus[] =
193 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
194 const WCHAR szRegisterExtensionInfo[] =
195 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
197 const static WCHAR szRegisterFonts[] =
198 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
199 const WCHAR szRegisterMIMEInfo[] =
200 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
201 const static WCHAR szRegisterUser[] =
202 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
203 const WCHAR szRemoveDuplicateFiles[] =
204 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
205 'F','i','l','e','s',0};
206 const static WCHAR szRemoveEnvironmentStrings[] =
207 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
208 'S','t','r','i','n','g','s',0};
209 const WCHAR szRemoveExistingProducts[] =
210 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
211 'P','r','o','d','u','c','t','s',0};
212 const WCHAR szRemoveFiles[] =
213 {'R','e','m','o','v','e','F','i','l','e','s',0};
214 const static WCHAR szRemoveFolders[] =
215 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
216 const static WCHAR szRemoveIniValues[] =
217 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
218 const static WCHAR szRemoveODBC[] =
219 {'R','e','m','o','v','e','O','D','B','C',0};
220 const static WCHAR szRemoveRegistryValues[] =
221 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
222 'V','a','l','u','e','s',0};
223 const static WCHAR szRemoveShortcuts[] =
224 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
225 const static WCHAR szRMCCPSearch[] =
226 {'R','M','C','C','P','S','e','a','r','c','h',0};
227 const static WCHAR szScheduleReboot[] =
228 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
229 const static WCHAR szSelfUnregModules[] =
230 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
231 const static WCHAR szSetODBCFolders[] =
232 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
233 const static WCHAR szStartServices[] =
234 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
235 const static WCHAR szStopServices[] =
236 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
237 const static WCHAR szUnpublishComponents[] =
238 {'U','n','p','u','b','l','i','s','h',
239 'C','o','m','p','o','n','e','n','t','s',0};
240 const static WCHAR szUnpublishFeatures[] =
241 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
242 const WCHAR szUnregisterClassInfo[] =
243 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
245 const static WCHAR szUnregisterComPlus[] =
246 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
247 const WCHAR szUnregisterExtensionInfo[] =
248 {'U','n','r','e','g','i','s','t','e','r',
249 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
250 const static WCHAR szUnregisterFonts[] =
251 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
252 const WCHAR szUnregisterMIMEInfo[] =
253 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
254 const WCHAR szUnregisterProgIdInfo[] =
255 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
257 const static WCHAR szUnregisterTypeLibraries[] =
258 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
259 'L','i','b','r','a','r','i','e','s',0};
260 const static WCHAR szValidateProductID[] =
261 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
262 const static WCHAR szWriteEnvironmentStrings[] =
263 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
264 'S','t','r','i','n','g','s',0};
268 STANDARDACTIONHANDLER handler;
271 static struct _actions StandardActions[] = {
272 { szAllocateRegistrySpace, NULL},
273 { szAppSearch, ACTION_AppSearch },
274 { szBindImage, NULL},
275 { szCCPSearch, NULL},
276 { szCostFinalize, ACTION_CostFinalize },
277 { szCostInitialize, ACTION_CostInitialize },
278 { szCreateFolders, ACTION_CreateFolders },
279 { szCreateShortcuts, ACTION_CreateShortcuts },
280 { szDeleteServices, NULL},
281 { szDisableRollback, NULL},
282 { szDuplicateFiles, ACTION_DuplicateFiles },
283 { szExecuteAction, ACTION_ExecuteAction },
284 { szFileCost, ACTION_FileCost },
285 { szFindRelatedProducts, ACTION_FindRelatedProducts },
286 { szForceReboot, ACTION_ForceReboot },
287 { szInstallAdminPackage, NULL},
288 { szInstallExecute, ACTION_InstallExecute },
289 { szInstallExecuteAgain, ACTION_InstallExecute },
290 { szInstallFiles, ACTION_InstallFiles},
291 { szInstallFinalize, ACTION_InstallFinalize },
292 { szInstallInitialize, ACTION_InstallInitialize },
293 { szInstallSFPCatalogFile, NULL},
294 { szInstallValidate, ACTION_InstallValidate },
295 { szIsolateComponents, NULL},
296 { szLaunchConditions, ACTION_LaunchConditions },
297 { szMigrateFeatureStates, NULL},
298 { szMoveFiles, NULL},
299 { szMsiPublishAssemblies, NULL},
300 { szMsiUnpublishAssemblies, NULL},
301 { szInstallODBC, NULL},
302 { szInstallServices, NULL},
303 { szPatchFiles, NULL},
304 { szProcessComponents, ACTION_ProcessComponents },
305 { szPublishComponents, ACTION_PublishComponents },
306 { szPublishFeatures, ACTION_PublishFeatures },
307 { szPublishProduct, ACTION_PublishProduct },
308 { szRegisterClassInfo, ACTION_RegisterClassInfo },
309 { szRegisterComPlus, NULL},
310 { szRegisterExtensionInfo, ACTION_RegisterExtensionInfo },
311 { szRegisterFonts, ACTION_RegisterFonts },
312 { szRegisterMIMEInfo, ACTION_RegisterMIMEInfo },
313 { szRegisterProduct, ACTION_RegisterProduct },
314 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
315 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
316 { szRegisterUser, ACTION_RegisterUser},
317 { szRemoveDuplicateFiles, NULL},
318 { szRemoveEnvironmentStrings, NULL},
319 { szRemoveExistingProducts, NULL},
320 { szRemoveFiles, NULL},
321 { szRemoveFolders, NULL},
322 { szRemoveIniValues, NULL},
323 { szRemoveODBC, NULL},
324 { szRemoveRegistryValues, NULL},
325 { szRemoveShortcuts, NULL},
326 { szResolveSource, ACTION_ResolveSource},
327 { szRMCCPSearch, NULL},
328 { szScheduleReboot, NULL},
329 { szSelfRegModules, ACTION_SelfRegModules },
330 { szSelfUnregModules, NULL},
331 { szSetODBCFolders, NULL},
332 { szStartServices, NULL},
333 { szStopServices, NULL},
334 { szUnpublishComponents, NULL},
335 { szUnpublishFeatures, NULL},
336 { szUnregisterClassInfo, NULL},
337 { szUnregisterComPlus, NULL},
338 { szUnregisterExtensionInfo, NULL},
339 { szUnregisterFonts, NULL},
340 { szUnregisterMIMEInfo, NULL},
341 { szUnregisterProgIdInfo, NULL},
342 { szUnregisterTypeLibraries, NULL},
343 { szValidateProductID, NULL},
344 { szWriteEnvironmentStrings, NULL},
345 { szWriteIniValues, ACTION_WriteIniValues },
346 { szWriteRegistryValues, ACTION_WriteRegistryValues},
350 static void ce_actiontext(MSIPACKAGE* package, LPCWSTR action)
352 static const WCHAR szActionText[] =
353 {'A','c','t','i','o','n','T','e','x','t',0};
356 row = MSI_CreateRecord(1);
357 MSI_RecordSetStringW(row,1,action);
358 ControlEvent_FireSubscribedEvent(package,szActionText, row);
359 msiobj_release(&row->hdr);
362 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
364 static const WCHAR template_s[]=
365 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
367 static const WCHAR format[] =
368 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
369 static const WCHAR Query_t[] =
370 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
371 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
372 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
373 ' ','\'','%','s','\'',0};
379 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
381 row = MSI_QueryGetRecord( package->db, Query_t, action );
385 ActionText = MSI_RecordGetString(row,2);
387 sprintfW(message,template_s,timet,action,ActionText);
388 msiobj_release(&row->hdr);
390 row = MSI_CreateRecord(1);
391 MSI_RecordSetStringW(row,1,message);
393 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
394 msiobj_release(&row->hdr);
397 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
401 static const WCHAR template_s[]=
402 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
404 static const WCHAR template_e[]=
405 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
406 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
408 static const WCHAR format[] =
409 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
413 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
415 sprintfW(message,template_s,timet,action);
417 sprintfW(message,template_e,timet,action,rc);
419 row = MSI_CreateRecord(1);
420 MSI_RecordSetStringW(row,1,message);
422 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
423 msiobj_release(&row->hdr);
426 /****************************************************
427 * TOP level entry points
428 *****************************************************/
430 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
431 LPCWSTR szCommandLine)
437 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
438 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
439 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
441 MSI_SetPropertyW(package, szAction, szInstall);
443 package->script = HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT));
444 memset(package->script,0,sizeof(MSISCRIPT));
448 LPWSTR p, check, path;
450 package->PackagePath = strdupW(szPackagePath);
451 path = strdupW(szPackagePath);
452 p = strrchrW(path,'\\');
460 HeapFree(GetProcessHeap(),0,path);
461 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
462 GetCurrentDirectoryW(MAX_PATH,path);
466 check = load_dynamic_property(package, cszSourceDir,NULL);
468 MSI_SetPropertyW(package, cszSourceDir, path);
470 HeapFree(GetProcessHeap(), 0, check);
472 HeapFree(GetProcessHeap(), 0, path);
478 ptr = (LPWSTR)szCommandLine;
485 TRACE("Looking at %s\n",debugstr_w(ptr));
487 ptr2 = strchrW(ptr,'=');
493 while (*ptr == ' ') ptr++;
495 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
496 memcpy(prop,ptr,len*sizeof(WCHAR));
502 while (*ptr && (quote || (!quote && *ptr!=' ')))
515 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
516 memcpy(val,ptr2,len*sizeof(WCHAR));
519 if (strlenW(prop) > 0)
521 TRACE("Found commandline property (%s) = (%s)\n",
522 debugstr_w(prop), debugstr_w(val));
523 MSI_SetPropertyW(package,prop,val);
525 HeapFree(GetProcessHeap(),0,val);
526 HeapFree(GetProcessHeap(),0,prop);
533 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
535 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
537 rc = ACTION_ProcessUISequence(package);
539 if (rc == ERROR_SUCCESS)
540 rc = ACTION_ProcessExecSequence(package,TRUE);
543 rc = ACTION_ProcessExecSequence(package,FALSE);
546 rc = ACTION_ProcessExecSequence(package,FALSE);
550 /* install was halted but should be considered a success */
554 package->script->CurrentlyScripting= FALSE;
556 /* process the ending type action */
557 if (rc == ERROR_SUCCESS)
558 ACTION_PerformActionSequence(package,-1,ui);
559 else if (rc == ERROR_INSTALL_USEREXIT)
560 ACTION_PerformActionSequence(package,-2,ui);
561 else if (rc == ERROR_INSTALL_SUSPEND)
562 ACTION_PerformActionSequence(package,-4,ui);
564 ACTION_PerformActionSequence(package,-3,ui);
566 /* finish up running custom actions */
567 ACTION_FinishCustomActions(package);
572 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
574 UINT rc = ERROR_SUCCESS;
576 static const WCHAR ExecSeqQuery[] =
577 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
578 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
579 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
580 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
582 static const WCHAR UISeqQuery[] =
583 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
584 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
585 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
586 ' ', '=',' ','%','i',0};
589 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
591 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
595 LPCWSTR action, cond;
597 TRACE("Running the actions\n");
599 /* check conditions */
600 cond = MSI_RecordGetString(row,2);
603 /* this is a hack to skip errors in the condition code */
604 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
608 action = MSI_RecordGetString(row,1);
611 ERR("failed to fetch action\n");
612 rc = ERROR_FUNCTION_FAILED;
617 rc = ACTION_PerformUIAction(package,action);
619 rc = ACTION_PerformAction(package,action,FALSE);
621 msiobj_release(&row->hdr);
629 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
633 static const WCHAR ExecSeqQuery[] =
634 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
635 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
636 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
637 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
638 'O','R','D','E','R',' ', 'B','Y',' ',
639 '`','S','e','q','u','e','n','c','e','`',0 };
641 static const WCHAR IVQuery[] =
642 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
643 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
644 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
645 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
646 ' ','\'', 'I','n','s','t','a','l','l',
647 'V','a','l','i','d','a','t','e','\'', 0};
651 if (package->script->ExecuteSequenceRun)
653 TRACE("Execute Sequence already Run\n");
654 return ERROR_SUCCESS;
657 package->script->ExecuteSequenceRun = TRUE;
659 /* get the sequence number */
662 row = MSI_QueryGetRecord(package->db, IVQuery);
664 return ERROR_FUNCTION_FAILED;
665 seq = MSI_RecordGetInteger(row,1);
666 msiobj_release(&row->hdr);
669 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
670 if (rc == ERROR_SUCCESS)
672 rc = MSI_ViewExecute(view, 0);
674 if (rc != ERROR_SUCCESS)
677 msiobj_release(&view->hdr);
681 TRACE("Running the actions\n");
685 LPCWSTR cond, action;
687 rc = MSI_ViewFetch(view,&row);
688 if (rc != ERROR_SUCCESS)
694 action = MSI_RecordGetString(row,1);
697 ERR("Error in retrieving action name\n");
698 rc = ERROR_FUNCTION_FAILED;
699 msiobj_release(&row->hdr);
703 /* check conditions */
704 cond = MSI_RecordGetString(row,2);
707 /* this is a hack to skip errors in the condition code */
708 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
710 TRACE("Skipping action: %s (condition is false)\n",
712 msiobj_release(&row->hdr);
717 rc = ACTION_PerformAction(package,action,FALSE);
719 if (rc == ERROR_FUNCTION_NOT_CALLED)
722 if (rc != ERROR_SUCCESS)
724 ERR("Execution halted due to error (%i)\n",rc);
725 msiobj_release(&row->hdr);
729 msiobj_release(&row->hdr);
733 msiobj_release(&view->hdr);
741 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
745 static const WCHAR ExecSeqQuery [] =
746 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
747 '`','I','n','s','t','a','l','l',
748 'U','I','S','e','q','u','e','n','c','e','`',
749 ' ','W','H','E','R','E',' ',
750 '`','S','e','q','u','e','n','c','e','`',' ',
751 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
752 '`','S','e','q','u','e','n','c','e','`',0};
754 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
756 if (rc == ERROR_SUCCESS)
758 rc = MSI_ViewExecute(view, 0);
760 if (rc != ERROR_SUCCESS)
763 msiobj_release(&view->hdr);
767 TRACE("Running the actions \n");
771 LPCWSTR action, cond;
774 rc = MSI_ViewFetch(view,&row);
775 if (rc != ERROR_SUCCESS)
781 action = MSI_RecordGetString(row,1);
784 ERR("failed to fetch action\n");
785 rc = ERROR_FUNCTION_FAILED;
786 msiobj_release(&row->hdr);
790 /* check conditions */
791 cond = MSI_RecordGetString(row,2);
794 /* this is a hack to skip errors in the condition code */
795 if (MSI_EvaluateConditionW(package,cond) == MSICONDITION_FALSE)
797 TRACE("Skipping action: %s (condition is false)\n",
799 msiobj_release(&row->hdr);
804 rc = ACTION_PerformUIAction(package,action);
806 if (rc == ERROR_FUNCTION_NOT_CALLED)
809 if (rc != ERROR_SUCCESS)
811 ERR("Execution halted due to error (%i)\n",rc);
812 msiobj_release(&row->hdr);
816 msiobj_release(&row->hdr);
820 msiobj_release(&view->hdr);
827 /********************************************************
828 * ACTION helper functions and functions that perform the actions
829 *******************************************************/
830 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
831 UINT* rc, BOOL force )
837 if (!run && !package->script->CurrentlyScripting)
842 if (strcmpW(action,szInstallFinalize) == 0 ||
843 strcmpW(action,szInstallExecute) == 0 ||
844 strcmpW(action,szInstallExecuteAgain) == 0)
849 while (StandardActions[i].action != NULL)
851 if (strcmpW(StandardActions[i].action, action)==0)
853 ce_actiontext(package, action);
856 ui_actioninfo(package, action, TRUE, 0);
857 *rc = schedule_action(package,INSTALL_SCRIPT,action);
858 ui_actioninfo(package, action, FALSE, *rc);
862 ui_actionstart(package, action);
863 if (StandardActions[i].handler)
865 *rc = StandardActions[i].handler(package);
869 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
881 static BOOL ACTION_HandleDialogBox( MSIPACKAGE *package, LPCWSTR dialog, UINT* rc )
885 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
887 *rc = package->CurrentInstallState;
893 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
894 UINT* rc, BOOL force )
899 arc = ACTION_CustomAction(package,action, force);
901 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
910 * A lot of actions are really important even if they don't do anything
911 * explicit... Lots of properties are set at the beginning of the installation
912 * CostFinalize does a bunch of work to translate the directories and such
914 * But until I get write access to the database that is hard, so I am going to
915 * hack it to see if I can get something to run.
917 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
919 UINT rc = ERROR_SUCCESS;
922 TRACE("Performing action (%s)\n",debugstr_w(action));
924 handled = ACTION_HandleStandardAction(package, action, &rc, force);
927 handled = ACTION_HandleCustomAction(package, action, &rc, force);
931 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
932 rc = ERROR_FUNCTION_NOT_CALLED;
935 package->CurrentInstallState = rc;
939 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
941 UINT rc = ERROR_SUCCESS;
942 BOOL handled = FALSE;
944 TRACE("Performing action (%s)\n",debugstr_w(action));
946 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
949 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
952 handled = ACTION_HandleDialogBox(package, action, &rc);
954 msi_dialog_check_messages( NULL );
958 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
959 rc = ERROR_FUNCTION_NOT_CALLED;
962 package->CurrentInstallState = rc;
967 * Also we cannot enable/disable components either, so for now I am just going
968 * to do all the directories for all the components.
970 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
972 static const WCHAR ExecSeqQuery[] =
973 {'S','E','L','E','C','T',' ',
974 '`','D','i','r','e','c','t','o','r','y','_','`',
975 ' ','F','R','O','M',' ',
976 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
981 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
982 if (rc != ERROR_SUCCESS)
983 return ERROR_SUCCESS;
985 rc = MSI_ViewExecute(view, 0);
986 if (rc != ERROR_SUCCESS)
989 msiobj_release(&view->hdr);
997 MSIRECORD *row = NULL, *uirow;
999 rc = MSI_ViewFetch(view,&row);
1000 if (rc != ERROR_SUCCESS)
1006 dir = MSI_RecordGetString(row,1);
1009 ERR("Unable to get folder id \n");
1010 msiobj_release(&row->hdr);
1014 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1017 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1018 msiobj_release(&row->hdr);
1022 TRACE("Folder is %s\n",debugstr_w(full_path));
1025 uirow = MSI_CreateRecord(1);
1026 MSI_RecordSetStringW(uirow,1,full_path);
1027 ui_actiondata(package,szCreateFolders,uirow);
1028 msiobj_release( &uirow->hdr );
1030 if (folder->State == 0)
1031 create_full_pathW(full_path);
1035 msiobj_release(&row->hdr);
1036 HeapFree(GetProcessHeap(),0,full_path);
1038 MSI_ViewClose(view);
1039 msiobj_release(&view->hdr);
1044 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1046 int index = package->loaded_components;
1049 /* fill in the data */
1051 package->loaded_components++;
1052 if (package->loaded_components == 1)
1053 package->components = HeapAlloc(GetProcessHeap(),0,
1054 sizeof(MSICOMPONENT));
1056 package->components = HeapReAlloc(GetProcessHeap(),0,
1057 package->components, package->loaded_components *
1058 sizeof(MSICOMPONENT));
1060 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1062 sz = IDENTIFIER_SIZE;
1063 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1065 TRACE("Loading Component %s\n",
1066 debugstr_w(package->components[index].Component));
1069 if (!MSI_RecordIsNull(row,2))
1070 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1072 sz = IDENTIFIER_SIZE;
1073 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1075 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1078 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1080 sz = IDENTIFIER_SIZE;
1081 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1083 package->components[index].Installed = INSTALLSTATE_ABSENT;
1084 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1085 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1087 package->components[index].Enabled = TRUE;
1092 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1094 int index = package->loaded_features;
1096 static const WCHAR Query1[] =
1097 {'S','E','L','E','C','T',' ',
1098 '`','C','o','m','p','o','n','e','n','t','_','`',
1099 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1100 'C','o','m','p','o','n','e','n','t','s','`',' ',
1101 'W','H','E','R','E',' ',
1102 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1103 static const WCHAR Query2[] =
1104 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1105 '`','C','o','m','p','o','n','e','n','t','`',' ',
1106 'W','H','E','R','E',' ',
1107 '`','C','o','m','p','o','n','e','n','t','`',' ',
1108 '=','\'','%','s','\'',0};
1115 /* fill in the data */
1117 package->loaded_features ++;
1118 if (package->loaded_features == 1)
1119 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1121 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1122 package->loaded_features * sizeof(MSIFEATURE));
1124 memset(&package->features[index],0,sizeof(MSIFEATURE));
1126 sz = IDENTIFIER_SIZE;
1127 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1129 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1131 sz = IDENTIFIER_SIZE;
1132 if (!MSI_RecordIsNull(row,2))
1133 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1136 if (!MSI_RecordIsNull(row,3))
1137 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1140 if (!MSI_RecordIsNull(row,4))
1141 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1143 if (!MSI_RecordIsNull(row,5))
1144 package->features[index].Display = MSI_RecordGetInteger(row,5);
1146 package->features[index].Level= MSI_RecordGetInteger(row,6);
1148 sz = IDENTIFIER_SIZE;
1149 if (!MSI_RecordIsNull(row,7))
1150 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1152 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1154 package->features[index].Installed = INSTALLSTATE_ABSENT;
1155 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1156 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1158 /* load feature components */
1160 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1161 if (rc != ERROR_SUCCESS)
1163 rc = MSI_ViewExecute(view,0);
1164 if (rc != ERROR_SUCCESS)
1166 MSI_ViewClose(view);
1167 msiobj_release(&view->hdr);
1175 INT cnt = package->features[index].ComponentCount;
1177 rc = MSI_ViewFetch(view,&row2);
1178 if (rc != ERROR_SUCCESS)
1181 component = MSI_RecordGetString(row2,1);
1183 /* check to see if the component is already loaded */
1184 c_indx = get_loaded_component(package,component);
1187 TRACE("Component %s already loaded at %i\n", debugstr_w(component),
1189 package->features[index].Components[cnt] = c_indx;
1190 package->features[index].ComponentCount ++;
1191 msiobj_release( &row2->hdr );
1195 rc = MSI_OpenQuery(package->db, &view2, Query2, component);
1196 if (rc != ERROR_SUCCESS)
1198 msiobj_release( &row2->hdr );
1201 rc = MSI_ViewExecute(view2,0);
1202 if (rc != ERROR_SUCCESS)
1204 msiobj_release( &row2->hdr );
1205 MSI_ViewClose(view2);
1206 msiobj_release( &view2->hdr );
1213 rc = MSI_ViewFetch(view2,&row3);
1214 if (rc != ERROR_SUCCESS)
1216 c_indx = load_component(package,row3);
1217 msiobj_release( &row3->hdr );
1219 package->features[index].Components[cnt] = c_indx;
1220 package->features[index].ComponentCount ++;
1221 TRACE("Loaded new component to index %i\n",c_indx);
1223 MSI_ViewClose(view2);
1224 msiobj_release( &view2->hdr );
1225 msiobj_release( &row2->hdr );
1227 MSI_ViewClose(view);
1228 msiobj_release(&view->hdr);
1231 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1233 DWORD index = package->loaded_files;
1236 /* fill in the data */
1238 package->loaded_files++;
1239 if (package->loaded_files== 1)
1240 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1242 package->files = HeapReAlloc(GetProcessHeap(),0,
1243 package->files , package->loaded_files * sizeof(MSIFILE));
1245 memset(&package->files[index],0,sizeof(MSIFILE));
1247 package->files[index].File = load_dynamic_stringW(row, 1);
1249 component = MSI_RecordGetString(row, 2);
1250 package->files[index].ComponentIndex = get_loaded_component(package,
1253 if (package->files[index].ComponentIndex == -1)
1254 ERR("Unfound Component %s\n",debugstr_w(component));
1256 package->files[index].FileName = load_dynamic_stringW(row,3);
1257 reduce_to_longfilename(package->files[index].FileName);
1259 package->files[index].ShortName = load_dynamic_stringW(row,3);
1260 reduce_to_shortfilename(package->files[index].ShortName);
1262 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1263 package->files[index].Version = load_dynamic_stringW(row, 5);
1264 package->files[index].Language = load_dynamic_stringW(row, 6);
1265 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1266 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1268 package->files[index].Temporary = FALSE;
1269 package->files[index].State = 0;
1271 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1273 return ERROR_SUCCESS;
1276 static UINT load_all_files(MSIPACKAGE *package)
1281 static const WCHAR Query[] =
1282 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1283 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1284 '`','S','e','q','u','e','n','c','e','`', 0};
1287 return ERROR_INVALID_HANDLE;
1289 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1290 if (rc != ERROR_SUCCESS)
1291 return ERROR_SUCCESS;
1293 rc = MSI_ViewExecute(view, 0);
1294 if (rc != ERROR_SUCCESS)
1296 MSI_ViewClose(view);
1297 msiobj_release(&view->hdr);
1298 return ERROR_SUCCESS;
1303 rc = MSI_ViewFetch(view,&row);
1304 if (rc != ERROR_SUCCESS)
1309 load_file(package,row);
1310 msiobj_release(&row->hdr);
1312 MSI_ViewClose(view);
1313 msiobj_release(&view->hdr);
1315 return ERROR_SUCCESS;
1320 * I am not doing any of the costing functionality yet.
1321 * Mostly looking at doing the Component and Feature loading
1323 * The native MSI does A LOT of modification to tables here. Mostly adding
1324 * a lot of temporary columns to the Feature and Component tables.
1326 * note: Native msi also tracks the short filename. But I am only going to
1327 * track the long ones. Also looking at this directory table
1328 * it appears that the directory table does not get the parents
1329 * resolved base on property only based on their entries in the
1332 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1337 static const WCHAR Query_all[] =
1338 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1339 '`','F','e','a','t','u','r','e','`',0};
1340 static const WCHAR szCosting[] =
1341 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1342 static const WCHAR szZero[] = { '0', 0 };
1346 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1348 return ERROR_SUCCESS;
1350 MSI_SetPropertyW(package, szCosting, szZero);
1351 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1353 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1354 if (rc != ERROR_SUCCESS)
1356 rc = MSI_ViewExecute(view,0);
1357 if (rc != ERROR_SUCCESS)
1359 MSI_ViewClose(view);
1360 msiobj_release(&view->hdr);
1367 rc = MSI_ViewFetch(view,&row);
1368 if (rc != ERROR_SUCCESS)
1371 load_feature(package,row);
1372 msiobj_release(&row->hdr);
1374 MSI_ViewClose(view);
1375 msiobj_release(&view->hdr);
1377 load_all_files(package);
1379 return ERROR_SUCCESS;
1382 static UINT execute_script(MSIPACKAGE *package, UINT script )
1385 UINT rc = ERROR_SUCCESS;
1387 TRACE("Executing Script %i\n",script);
1389 for (i = 0; i < package->script->ActionCount[script]; i++)
1392 action = package->script->Actions[script][i];
1393 ui_actionstart(package, action);
1394 TRACE("Executing Action (%s)\n",debugstr_w(action));
1395 rc = ACTION_PerformAction(package, action, TRUE);
1396 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1397 if (rc != ERROR_SUCCESS)
1400 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1402 package->script->ActionCount[script] = 0;
1403 package->script->Actions[script] = NULL;
1407 static UINT ACTION_FileCost(MSIPACKAGE *package)
1409 return ERROR_SUCCESS;
1413 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1415 static const WCHAR Query[] =
1416 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1417 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1418 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1419 ' ','=',' ','\'','%','s','\'',
1421 LPWSTR ptargetdir, targetdir, srcdir;
1423 LPWSTR shortname = NULL;
1424 MSIRECORD * row = 0;
1428 TRACE("Looking for dir %s\n",debugstr_w(dir));
1430 for (i = 0; i < package->loaded_folders; i++)
1432 if (strcmpW(package->folders[i].Directory,dir)==0)
1434 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1439 TRACE("Working to load %s\n",debugstr_w(dir));
1441 index = package->loaded_folders++;
1442 if (package->loaded_folders==1)
1443 package->folders = HeapAlloc(GetProcessHeap(),0,
1446 package->folders= HeapReAlloc(GetProcessHeap(),0,
1447 package->folders, package->loaded_folders*
1450 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1452 package->folders[index].Directory = strdupW(dir);
1454 row = MSI_QueryGetRecord(package->db, Query, dir);
1458 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1460 /* split src and target dir */
1461 if (strchrW(targetdir,':'))
1463 srcdir=strchrW(targetdir,':');
1470 /* for now only pick long filename versions */
1471 if (strchrW(targetdir,'|'))
1473 shortname = targetdir;
1474 targetdir = strchrW(targetdir,'|');
1478 /* for the sourcedir pick the short filename */
1479 if (srcdir && strchrW(srcdir,'|'))
1481 LPWSTR p = strchrW(srcdir,'|');
1485 /* now check for root dirs */
1486 if (targetdir[0] == '.' && targetdir[1] == 0)
1489 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1494 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1495 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
1496 package->folders[index].TargetDefault = strdupW(targetdir);
1500 package->folders[index].SourceDefault = strdupW(srcdir);
1502 package->folders[index].SourceDefault = strdupW(shortname);
1504 package->folders[index].SourceDefault = strdupW(targetdir);
1505 HeapFree(GetProcessHeap(), 0, ptargetdir);
1506 TRACE(" SourceDefault = %s\n",debugstr_w(package->folders[index].SourceDefault));
1508 parent = MSI_RecordGetString(row,2);
1511 i = load_folder(package,parent);
1512 package->folders[index].ParentIndex = i;
1513 TRACE("Parent is index %i... %s %s\n",
1514 package->folders[index].ParentIndex,
1515 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1516 debugstr_w(parent));
1519 package->folders[index].ParentIndex = -2;
1521 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
1523 msiobj_release(&row->hdr);
1524 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1528 /* scan for and update current install states */
1529 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
1534 productcode = load_dynamic_property(package,szProductCode,NULL);
1536 for (i = 0; i < package->loaded_components; i++)
1539 res = MsiGetComponentPathW(productcode,
1540 package->components[i].ComponentId , NULL, NULL);
1542 res = INSTALLSTATE_ABSENT;
1543 package->components[i].Installed = res;
1546 for (i = 0; i < package->loaded_features; i++)
1548 INSTALLSTATE res = -10;
1550 for (j = 0; j < package->features[i].ComponentCount; j++)
1552 MSICOMPONENT* component = &package->components[package->features[i].
1555 res = component->Installed;
1558 if (res == component->Installed)
1561 if (res != component->Installed)
1562 res = INSTALLSTATE_INCOMPLETE;
1568 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
1571 static const WCHAR all[]={'A','L','L',0};
1572 LPWSTR override = NULL;
1576 override = load_dynamic_property(package, property, NULL);
1580 for(i = 0; i < package->loaded_features; i++)
1582 if (strcmpiW(override,all)==0)
1584 package->features[i].ActionRequest= state;
1585 package->features[i].Action = state;
1589 LPWSTR ptr = override;
1590 LPWSTR ptr2 = strchrW(override,',');
1595 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
1597 strcmpW(ptr,package->features[i].Feature)==0))
1599 package->features[i].ActionRequest= state;
1600 package->features[i].Action = state;
1606 ptr2 = strchrW(ptr,',');
1613 HeapFree(GetProcessHeap(),0,override);
1619 static UINT SetFeatureStates(MSIPACKAGE *package)
1625 static const WCHAR szlevel[] =
1626 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1627 static const WCHAR szAddLocal[] =
1628 {'A','D','D','L','O','C','A','L',0};
1629 static const WCHAR szRemove[] =
1630 {'R','E','M','O','V','E',0};
1631 BOOL override = FALSE;
1633 /* I do not know if this is where it should happen.. but */
1635 TRACE("Checking Install Level\n");
1637 level = load_dynamic_property(package,szlevel,NULL);
1640 install_level = atoiW(level);
1641 HeapFree(GetProcessHeap(), 0, level);
1646 /* ok hereis the _real_ rub
1647 * all these activation/deactivation things happen in order and things
1648 * later on the list override things earlier on the list.
1649 * 1) INSTALLLEVEL processing
1659 * 11) FILEADDDEFAULT
1660 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1661 * ignored for all the features. seems strange, especially since it is not
1662 * documented anywhere, but it is how it works.
1664 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1665 * REMOVE are the big ones, since we don't handle administrative installs
1668 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
1669 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
1673 for(i = 0; i < package->loaded_features; i++)
1675 BOOL feature_state = ((package->features[i].Level > 0) &&
1676 (package->features[i].Level <= install_level));
1678 if ((feature_state) &&
1679 (package->features[i].Action == INSTALLSTATE_UNKNOWN))
1681 if (package->features[i].Attributes &
1682 msidbFeatureAttributesFavorSource)
1684 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
1685 package->features[i].Action = INSTALLSTATE_SOURCE;
1687 else if (package->features[i].Attributes &
1688 msidbFeatureAttributesFavorAdvertise)
1690 package->features[i].ActionRequest =INSTALLSTATE_ADVERTISED;
1691 package->features[i].Action =INSTALLSTATE_ADVERTISED;
1695 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
1696 package->features[i].Action = INSTALLSTATE_LOCAL;
1703 /* set the Preselected Property */
1704 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1705 static const WCHAR szOne[] = { '1', 0 };
1707 MSI_SetPropertyW(package,szPreselected,szOne);
1711 * now we want to enable or disable components base on feature
1714 for(i = 0; i < package->loaded_features; i++)
1716 MSIFEATURE* feature = &package->features[i];
1717 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1718 debugstr_w(feature->Feature), feature->Installed, feature->Action,
1719 feature->ActionRequest);
1721 for( j = 0; j < feature->ComponentCount; j++)
1723 MSICOMPONENT* component = &package->components[
1724 feature->Components[j]];
1726 if (!component->Enabled)
1728 component->Action = INSTALLSTATE_UNKNOWN;
1729 component->ActionRequest = INSTALLSTATE_UNKNOWN;
1733 if (feature->Action == INSTALLSTATE_LOCAL)
1735 component->Action = INSTALLSTATE_LOCAL;
1736 component->ActionRequest = INSTALLSTATE_LOCAL;
1738 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
1740 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1741 (component->Action == INSTALLSTATE_ABSENT) ||
1742 (component->Action == INSTALLSTATE_ADVERTISED))
1745 component->Action = INSTALLSTATE_SOURCE;
1746 component->ActionRequest = INSTALLSTATE_SOURCE;
1749 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
1751 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1752 (component->Action == INSTALLSTATE_ABSENT))
1755 component->Action = INSTALLSTATE_ADVERTISED;
1756 component->ActionRequest = INSTALLSTATE_ADVERTISED;
1759 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
1761 if (component->Action == INSTALLSTATE_UNKNOWN)
1763 component->Action = INSTALLSTATE_ABSENT;
1764 component->ActionRequest = INSTALLSTATE_ABSENT;
1771 for(i = 0; i < package->loaded_components; i++)
1773 MSICOMPONENT* component= &package->components[i];
1775 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1776 debugstr_w(component->Component), component->Installed,
1777 component->Action, component->ActionRequest);
1781 return ERROR_SUCCESS;
1785 * A lot is done in this function aside from just the costing.
1786 * The costing needs to be implemented at some point but for now I am going
1787 * to focus on the directory building
1790 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
1792 static const WCHAR ExecSeqQuery[] =
1793 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1794 '`','D','i','r','e','c','t','o','r','y','`',0};
1795 static const WCHAR ConditionQuery[] =
1796 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1797 '`','C','o','n','d','i','t','i','o','n','`',0};
1798 static const WCHAR szCosting[] =
1799 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1800 static const WCHAR szlevel[] =
1801 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1802 static const WCHAR szOne[] = { '1', 0 };
1810 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1812 return ERROR_SUCCESS;
1814 TRACE("Building Directory properties\n");
1816 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1817 if (rc == ERROR_SUCCESS)
1819 rc = MSI_ViewExecute(view, 0);
1820 if (rc != ERROR_SUCCESS)
1822 MSI_ViewClose(view);
1823 msiobj_release(&view->hdr);
1831 MSIRECORD * row = 0;
1833 rc = MSI_ViewFetch(view,&row);
1834 if (rc != ERROR_SUCCESS)
1840 name = MSI_RecordGetString(row,1);
1842 /* This helper function now does ALL the work */
1843 TRACE("Dir %s ...\n",debugstr_w(name));
1844 load_folder(package,name);
1845 path = resolve_folder(package,name,FALSE,TRUE,NULL);
1846 TRACE("resolves to %s\n",debugstr_w(path));
1847 HeapFree( GetProcessHeap(), 0, path);
1849 msiobj_release(&row->hdr);
1851 MSI_ViewClose(view);
1852 msiobj_release(&view->hdr);
1855 TRACE("File calculations %i files\n",package->loaded_files);
1857 for (i = 0; i < package->loaded_files; i++)
1859 MSICOMPONENT* comp = NULL;
1860 MSIFILE* file= NULL;
1862 file = &package->files[i];
1863 if (file->ComponentIndex >= 0)
1864 comp = &package->components[file->ComponentIndex];
1866 if (file->Temporary == TRUE)
1873 /* calculate target */
1874 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
1876 HeapFree(GetProcessHeap(),0,file->TargetPath);
1878 TRACE("file %s is named %s\n",
1879 debugstr_w(file->File),debugstr_w(file->FileName));
1881 file->TargetPath = build_directory_name(2, p, file->FileName);
1883 HeapFree(GetProcessHeap(),0,p);
1885 TRACE("file %s resolves to %s\n",
1886 debugstr_w(file->File),debugstr_w(file->TargetPath));
1888 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
1891 comp->Cost += file->FileSize;
1901 static const WCHAR name[] =
1903 static const WCHAR name_fmt[] =
1904 {'%','u','.','%','u','.','%','u','.','%','u',0};
1905 WCHAR filever[0x100];
1906 VS_FIXEDFILEINFO *lpVer;
1908 TRACE("Version comparison.. \n");
1909 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
1910 version = HeapAlloc(GetProcessHeap(),0,versize);
1911 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
1913 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
1915 sprintfW(filever,name_fmt,
1916 HIWORD(lpVer->dwFileVersionMS),
1917 LOWORD(lpVer->dwFileVersionMS),
1918 HIWORD(lpVer->dwFileVersionLS),
1919 LOWORD(lpVer->dwFileVersionLS));
1921 TRACE("new %s old %s\n", debugstr_w(file->Version),
1922 debugstr_w(filever));
1923 if (strcmpiW(filever,file->Version)<0)
1926 FIXME("cost should be diff in size\n");
1927 comp->Cost += file->FileSize;
1931 HeapFree(GetProcessHeap(),0,version);
1939 TRACE("Evaluating Condition Table\n");
1941 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
1942 if (rc == ERROR_SUCCESS)
1944 rc = MSI_ViewExecute(view, 0);
1945 if (rc != ERROR_SUCCESS)
1947 MSI_ViewClose(view);
1948 msiobj_release(&view->hdr);
1955 MSIRECORD * row = 0;
1958 rc = MSI_ViewFetch(view,&row);
1960 if (rc != ERROR_SUCCESS)
1966 Feature = MSI_RecordGetString(row,1);
1968 feature_index = get_loaded_feature(package,Feature);
1969 if (feature_index < 0)
1970 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
1974 Condition = MSI_RecordGetString(row,3);
1976 if (MSI_EvaluateConditionW(package,Condition) ==
1979 int level = MSI_RecordGetInteger(row,2);
1980 TRACE("Reseting feature %s to level %i\n",
1981 debugstr_w(Feature), level);
1982 package->features[feature_index].Level = level;
1986 msiobj_release(&row->hdr);
1988 MSI_ViewClose(view);
1989 msiobj_release(&view->hdr);
1992 TRACE("Enabling or Disabling Components\n");
1993 for (i = 0; i < package->loaded_components; i++)
1995 if (package->components[i].Condition[0])
1997 if (MSI_EvaluateConditionW(package,
1998 package->components[i].Condition) == MSICONDITION_FALSE)
2000 TRACE("Disabling component %s\n",
2001 debugstr_w(package->components[i].Component));
2002 package->components[i].Enabled = FALSE;
2007 MSI_SetPropertyW(package,szCosting,szOne);
2008 /* set default run level if not set */
2009 level = load_dynamic_property(package,szlevel,NULL);
2011 MSI_SetPropertyW(package,szlevel, szOne);
2013 HeapFree(GetProcessHeap(),0,level);
2015 ACTION_UpdateInstallStates(package);
2017 return SetFeatureStates(package);
2022 /* OK this value is "interpreted" and then formatted based on the
2023 first few characters */
2024 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
2028 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
2034 LPWSTR deformated = NULL;
2037 deformat_string(package, &value[2], &deformated);
2039 /* binary value type */
2043 *size = (strlenW(ptr)/2)+1;
2045 *size = strlenW(ptr)/2;
2047 data = HeapAlloc(GetProcessHeap(),0,*size);
2053 /* if uneven pad with a zero in front */
2059 data[count] = (BYTE)strtol(byte,NULL,0);
2061 TRACE("Uneven byte count\n");
2069 data[count] = (BYTE)strtol(byte,NULL,0);
2072 HeapFree(GetProcessHeap(),0,deformated);
2074 TRACE("Data %li bytes(%i)\n",*size,count);
2081 deformat_string(package, &value[1], &deformated);
2084 *size = sizeof(DWORD);
2085 data = HeapAlloc(GetProcessHeap(),0,*size);
2091 if ( (*p < '0') || (*p > '9') )
2097 if (deformated[0] == '-')
2100 TRACE("DWORD %li\n",*(LPDWORD)data);
2102 HeapFree(GetProcessHeap(),0,deformated);
2107 static const WCHAR szMulti[] = {'[','~',']',0};
2116 *type=REG_EXPAND_SZ;
2124 if (strstrW(value,szMulti))
2125 *type = REG_MULTI_SZ;
2127 *size = deformat_string(package, ptr,(LPWSTR*)&data);
2132 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2136 MSIRECORD * row = 0;
2137 static const WCHAR ExecSeqQuery[] =
2138 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2139 '`','R','e','g','i','s','t','r','y','`',0 };
2142 return ERROR_INVALID_HANDLE;
2144 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2145 if (rc != ERROR_SUCCESS)
2146 return ERROR_SUCCESS;
2148 rc = MSI_ViewExecute(view, 0);
2149 if (rc != ERROR_SUCCESS)
2151 MSI_ViewClose(view);
2152 msiobj_release(&view->hdr);
2156 /* increment progress bar each time action data is sent */
2157 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
2161 static const WCHAR szHCR[] =
2162 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
2163 'R','O','O','T','\\',0};
2164 static const WCHAR szHCU[] =
2165 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
2166 'U','S','E','R','\\',0};
2167 static const WCHAR szHLM[] =
2168 {'H','K','E','Y','_','L','O','C','A','L','_',
2169 'M','A','C','H','I','N','E','\\',0};
2170 static const WCHAR szHU[] =
2171 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2173 LPSTR value_data = NULL;
2174 HKEY root_key, hkey;
2177 LPCWSTR szRoot, component, name, key, value;
2178 INT component_index;
2182 BOOL check_first = FALSE;
2184 rc = MSI_ViewFetch(view,&row);
2185 if (rc != ERROR_SUCCESS)
2190 ui_progress(package,2,0,0,0);
2197 component = MSI_RecordGetString(row, 6);
2198 component_index = get_loaded_component(package,component);
2200 if (!ACTION_VerifyComponentForAction(package, component_index,
2201 INSTALLSTATE_LOCAL))
2203 TRACE("Skipping write due to disabled component %s\n",
2204 debugstr_w(component));
2205 msiobj_release(&row->hdr);
2207 package->components[component_index].Action =
2208 package->components[component_index].Installed;
2213 package->components[component_index].Action = INSTALLSTATE_LOCAL;
2215 name = MSI_RecordGetString(row, 4);
2216 if( MSI_RecordIsNull(row,5) && name )
2218 /* null values can have special meanings */
2219 if (name[0]=='-' && name[1] == 0)
2221 msiobj_release(&row->hdr);
2224 else if ((name[0]=='+' && name[1] == 0) ||
2225 (name[0] == '*' && name[1] == 0))
2230 root = MSI_RecordGetInteger(row,2);
2231 key = MSI_RecordGetString(row, 3);
2233 /* get the root key */
2236 case 0: root_key = HKEY_CLASSES_ROOT;
2239 case 1: root_key = HKEY_CURRENT_USER;
2242 case 2: root_key = HKEY_LOCAL_MACHINE;
2245 case 3: root_key = HKEY_USERS;
2249 ERR("Unknown root %i\n",root);
2256 msiobj_release(&row->hdr);
2260 deformat_string(package, key , &deformated);
2261 size = strlenW(deformated) + strlenW(szRoot) + 1;
2262 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
2263 strcpyW(uikey,szRoot);
2264 strcatW(uikey,deformated);
2266 if (RegCreateKeyW( root_key, deformated, &hkey))
2268 ERR("Could not create key %s\n",debugstr_w(deformated));
2269 msiobj_release(&row->hdr);
2270 HeapFree(GetProcessHeap(),0,deformated);
2273 HeapFree(GetProcessHeap(),0,deformated);
2275 value = MSI_RecordGetString(row,5);
2277 value_data = parse_value(package, value, &type, &size);
2280 static const WCHAR szEmpty[] = {0};
2281 value_data = (LPSTR)strdupW(szEmpty);
2286 deformat_string(package, name, &deformated);
2288 /* get the double nulls to terminate SZ_MULTI */
2289 if (type == REG_MULTI_SZ)
2290 size +=sizeof(WCHAR);
2294 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
2296 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
2301 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
2302 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2304 TRACE("value %s of %s checked already exists\n",
2305 debugstr_w(deformated), debugstr_w(uikey));
2309 TRACE("Checked and setting value %s of %s\n",
2310 debugstr_w(deformated), debugstr_w(uikey));
2311 if (deformated || size)
2312 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
2316 uirow = MSI_CreateRecord(3);
2317 MSI_RecordSetStringW(uirow,2,deformated);
2318 MSI_RecordSetStringW(uirow,1,uikey);
2321 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2323 MSI_RecordSetStringW(uirow,3,value);
2325 ui_actiondata(package,szWriteRegistryValues,uirow);
2326 msiobj_release( &uirow->hdr );
2328 HeapFree(GetProcessHeap(),0,value_data);
2329 HeapFree(GetProcessHeap(),0,deformated);
2331 msiobj_release(&row->hdr);
2334 HeapFree(GetProcessHeap(),0,uikey);
2336 MSI_ViewClose(view);
2337 msiobj_release(&view->hdr);
2341 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
2343 package->script->CurrentlyScripting = TRUE;
2345 return ERROR_SUCCESS;
2349 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
2353 static const WCHAR q1[]=
2354 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2355 '`','R','e','g','i','s','t','r','y','`',0};
2358 MSIRECORD * row = 0;
2361 TRACE(" InstallValidate \n");
2363 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
2364 if (rc != ERROR_SUCCESS)
2365 return ERROR_SUCCESS;
2367 rc = MSI_ViewExecute(view, 0);
2368 if (rc != ERROR_SUCCESS)
2370 MSI_ViewClose(view);
2371 msiobj_release(&view->hdr);
2376 rc = MSI_ViewFetch(view,&row);
2377 if (rc != ERROR_SUCCESS)
2384 msiobj_release(&row->hdr);
2386 MSI_ViewClose(view);
2387 msiobj_release(&view->hdr);
2389 total = total + progress * REG_PROGRESS_VALUE;
2390 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
2391 for (i=0; i < package->loaded_files; i++)
2392 total += package->files[i].FileSize;
2393 ui_progress(package,0,total,0,0);
2395 for(i = 0; i < package->loaded_features; i++)
2397 MSIFEATURE* feature = &package->features[i];
2398 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2399 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2400 feature->ActionRequest);
2403 return ERROR_SUCCESS;
2406 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
2409 MSIQUERY * view = NULL;
2410 MSIRECORD * row = 0;
2411 static const WCHAR ExecSeqQuery[] =
2412 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2413 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2414 static const WCHAR title[]=
2415 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2417 TRACE("Checking launch conditions\n");
2419 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2420 if (rc != ERROR_SUCCESS)
2421 return ERROR_SUCCESS;
2423 rc = MSI_ViewExecute(view, 0);
2424 if (rc != ERROR_SUCCESS)
2426 MSI_ViewClose(view);
2427 msiobj_release(&view->hdr);
2432 while (rc == ERROR_SUCCESS)
2434 LPCWSTR cond = NULL;
2435 LPCWSTR message = NULL;
2437 rc = MSI_ViewFetch(view,&row);
2438 if (rc != ERROR_SUCCESS)
2444 cond = MSI_RecordGetString(row,1);
2446 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
2449 message = MSI_RecordGetString(row,2);
2450 deformat_string(package,message,&deformated);
2451 MessageBoxW(NULL,deformated,title,MB_OK);
2452 HeapFree(GetProcessHeap(),0,deformated);
2453 rc = ERROR_FUNCTION_FAILED;
2455 msiobj_release(&row->hdr);
2457 MSI_ViewClose(view);
2458 msiobj_release(&view->hdr);
2462 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
2465 MSICOMPONENT* cmp = &package->components[component_index];
2467 if (cmp->KeyPath[0]==0)
2469 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
2472 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
2474 MSIRECORD * row = 0;
2476 LPWSTR deformated,buffer,deformated_name;
2478 static const WCHAR ExecSeqQuery[] =
2479 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2480 '`','R','e','g','i','s','t','r','y','`',' ',
2481 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2482 ' ','=',' ' ,'\'','%','s','\'',0 };
2483 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
2484 static const WCHAR fmt2[]=
2485 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2487 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
2491 root = MSI_RecordGetInteger(row,2);
2492 key = MSI_RecordGetString(row, 3);
2493 name = MSI_RecordGetString(row, 4);
2494 deformat_string(package, key , &deformated);
2495 deformat_string(package, name, &deformated_name);
2497 len = strlenW(deformated) + 6;
2498 if (deformated_name)
2499 len+=strlenW(deformated_name);
2501 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
2503 if (deformated_name)
2504 sprintfW(buffer,fmt2,root,deformated,deformated_name);
2506 sprintfW(buffer,fmt,root,deformated);
2508 HeapFree(GetProcessHeap(),0,deformated);
2509 HeapFree(GetProcessHeap(),0,deformated_name);
2510 msiobj_release(&row->hdr);
2514 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
2516 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2522 j = get_loaded_file(package,cmp->KeyPath);
2526 LPWSTR p = strdupW(package->files[j].TargetPath);
2533 static HKEY openSharedDLLsKey(void)
2536 static const WCHAR path[] =
2537 {'S','o','f','t','w','a','r','e','\\',
2538 'M','i','c','r','o','s','o','f','t','\\',
2539 'W','i','n','d','o','w','s','\\',
2540 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2541 'S','h','a','r','e','d','D','L','L','s',0};
2543 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
2547 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
2552 DWORD sz = sizeof(count);
2555 hkey = openSharedDLLsKey();
2556 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
2557 if (rc != ERROR_SUCCESS)
2563 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
2567 hkey = openSharedDLLsKey();
2569 RegSetValueExW(hkey,path,0,REG_DWORD,
2570 (LPBYTE)&count,sizeof(count));
2572 RegDeleteValueW(hkey,path);
2578 * Return TRUE if the count should be written out and FALSE if not
2580 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
2586 /* only refcount DLLs */
2587 if (package->components[index].KeyPath[0]==0 ||
2588 package->components[index].Attributes &
2589 msidbComponentAttributesRegistryKeyPath ||
2590 package->components[index].Attributes &
2591 msidbComponentAttributesODBCDataSource)
2595 count = ACTION_GetSharedDLLsCount(package->components[index].
2597 write = (count > 0);
2599 if (package->components[index].Attributes &
2600 msidbComponentAttributesSharedDllRefCount)
2604 /* increment counts */
2605 for (j = 0; j < package->loaded_features; j++)
2609 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
2612 for (i = 0; i < package->features[j].ComponentCount; i++)
2614 if (package->features[j].Components[i] == index)
2618 /* decrement counts */
2619 for (j = 0; j < package->loaded_features; j++)
2622 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
2625 for (i = 0; i < package->features[j].ComponentCount; i++)
2627 if (package->features[j].Components[i] == index)
2632 /* ref count all the files in the component */
2634 for (j = 0; j < package->loaded_files; j++)
2636 if (package->files[j].Temporary)
2638 if (package->files[j].ComponentIndex == index)
2639 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
2642 /* add a count for permenent */
2643 if (package->components[index].Attributes &
2644 msidbComponentAttributesPermanent)
2647 package->components[index].RefCount = count;
2650 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
2651 package->components[index].RefCount);
2655 * Ok further analysis makes me think that this work is
2656 * actually done in the PublishComponents and PublishFeatures
2657 * step, and not here. It appears like the keypath and all that is
2658 * resolved in this step, however actually written in the Publish steps.
2659 * But we will leave it here for now because it is unclear
2661 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
2664 WCHAR squished_pc[GUID_SIZE];
2665 WCHAR squished_cc[GUID_SIZE];
2668 HKEY hkey=0,hkey2=0;
2671 return ERROR_INVALID_HANDLE;
2673 /* writes the Component and Features values to the registry */
2674 productcode = load_dynamic_property(package,szProductCode,&rc);
2678 rc = MSIREG_OpenComponents(&hkey);
2679 if (rc != ERROR_SUCCESS)
2682 squash_guid(productcode,squished_pc);
2683 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
2684 for (i = 0; i < package->loaded_components; i++)
2686 ui_progress(package,2,0,0,0);
2687 if (package->components[i].ComponentId[0]!=0)
2689 WCHAR *keypath = NULL;
2692 squash_guid(package->components[i].ComponentId,squished_cc);
2694 keypath = resolve_keypath(package,i);
2695 package->components[i].FullKeypath = keypath;
2697 /* do the refcounting */
2698 ACTION_RefCountComponent( package, i);
2700 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2701 debugstr_w(package->components[i].Component),
2702 debugstr_w(squished_cc),
2703 debugstr_w(package->components[i].FullKeypath),
2704 package->components[i].RefCount);
2706 * Write the keypath out if the component is to be registered
2707 * and delete the key if the component is to be deregistered
2709 if (ACTION_VerifyComponentForAction(package, i,
2710 INSTALLSTATE_LOCAL))
2712 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
2713 if (rc != ERROR_SUCCESS)
2718 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
2719 (strlenW(keypath)+1)*sizeof(WCHAR));
2721 if (package->components[i].Attributes &
2722 msidbComponentAttributesPermanent)
2724 static const WCHAR szPermKey[] =
2725 { '0','0','0','0','0','0','0','0','0','0','0','0',
2726 '0','0','0','0','0','0','0', '0','0','0','0','0',
2727 '0','0','0','0','0','0','0','0',0};
2729 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
2731 (strlenW(keypath)+1)*sizeof(WCHAR));
2737 uirow = MSI_CreateRecord(3);
2738 MSI_RecordSetStringW(uirow,1,productcode);
2739 MSI_RecordSetStringW(uirow,2,package->components[i].
2741 MSI_RecordSetStringW(uirow,3,keypath);
2742 ui_actiondata(package,szProcessComponents,uirow);
2743 msiobj_release( &uirow->hdr );
2746 else if (ACTION_VerifyComponentForAction(package, i,
2747 INSTALLSTATE_ABSENT))
2751 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
2752 if (rc != ERROR_SUCCESS)
2755 RegDeleteValueW(hkey2,squished_pc);
2757 /* if the key is empty delete it */
2758 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
2760 if (res == ERROR_NO_MORE_ITEMS)
2761 RegDeleteKeyW(hkey,squished_cc);
2764 uirow = MSI_CreateRecord(2);
2765 MSI_RecordSetStringW(uirow,1,productcode);
2766 MSI_RecordSetStringW(uirow,2,package->components[i].
2768 ui_actiondata(package,szProcessComponents,uirow);
2769 msiobj_release( &uirow->hdr );
2774 HeapFree(GetProcessHeap(), 0, productcode);
2787 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
2788 LPWSTR lpszName, LONG_PTR lParam)
2791 typelib_struct *tl_struct = (typelib_struct*) lParam;
2792 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
2796 if (!IS_INTRESOURCE(lpszName))
2798 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
2802 sz = strlenW(tl_struct->source)+4;
2803 sz *= sizeof(WCHAR);
2805 if ((INT)lpszName == 1)
2806 tl_struct->path = strdupW(tl_struct->source);
2809 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
2810 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
2813 TRACE("trying %s\n", debugstr_w(tl_struct->path));
2814 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
2815 if (!SUCCEEDED(res))
2817 HeapFree(GetProcessHeap(),0,tl_struct->path);
2818 tl_struct->path = NULL;
2823 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
2824 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
2826 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2830 HeapFree(GetProcessHeap(),0,tl_struct->path);
2831 tl_struct->path = NULL;
2833 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2834 ITypeLib_Release(tl_struct->ptLib);
2839 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
2842 * OK this is a bit confusing.. I am given a _Component key and I believe
2843 * that the file that is being registered as a type library is the "key file
2844 * of that component" which I interpret to mean "The file in the KeyPath of
2849 MSIRECORD * row = 0;
2850 static const WCHAR Query[] =
2851 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2852 '`','T','y','p','e','L','i','b','`',0};
2855 return ERROR_INVALID_HANDLE;
2857 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2858 if (rc != ERROR_SUCCESS)
2859 return ERROR_SUCCESS;
2861 rc = MSI_ViewExecute(view, 0);
2862 if (rc != ERROR_SUCCESS)
2864 MSI_ViewClose(view);
2865 msiobj_release(&view->hdr);
2873 typelib_struct tl_struct;
2875 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
2877 rc = MSI_ViewFetch(view,&row);
2878 if (rc != ERROR_SUCCESS)
2884 component = MSI_RecordGetString(row,3);
2885 index = get_loaded_component(package,component);
2888 msiobj_release(&row->hdr);
2892 if (!ACTION_VerifyComponentForAction(package, index,
2893 INSTALLSTATE_LOCAL))
2895 TRACE("Skipping typelib reg due to disabled component\n");
2896 msiobj_release(&row->hdr);
2898 package->components[index].Action =
2899 package->components[index].Installed;
2904 package->components[index].Action = INSTALLSTATE_LOCAL;
2906 index = get_loaded_file(package,package->components[index].KeyPath);
2910 msiobj_release(&row->hdr);
2914 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
2915 LOAD_LIBRARY_AS_DATAFILE);
2919 guid = load_dynamic_stringW(row,1);
2920 CLSIDFromString(guid, &tl_struct.clsid);
2921 HeapFree(GetProcessHeap(),0,guid);
2922 tl_struct.source = strdupW(package->files[index].TargetPath);
2923 tl_struct.path = NULL;
2925 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
2926 (LONG_PTR)&tl_struct);
2928 if (tl_struct.path != NULL)
2934 helpid = MSI_RecordGetString(row,6);
2937 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
2938 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
2939 HeapFree(GetProcessHeap(),0,help);
2941 if (!SUCCEEDED(res))
2942 ERR("Failed to register type library %s\n",
2943 debugstr_w(tl_struct.path));
2946 ui_actiondata(package,szRegisterTypeLibraries,row);
2948 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
2951 ITypeLib_Release(tl_struct.ptLib);
2952 HeapFree(GetProcessHeap(),0,tl_struct.path);
2955 ERR("Failed to load type library %s\n",
2956 debugstr_w(tl_struct.source));
2958 FreeLibrary(module);
2959 HeapFree(GetProcessHeap(),0,tl_struct.source);
2962 ERR("Could not load file! %s\n",
2963 debugstr_w(package->files[index].TargetPath));
2964 msiobj_release(&row->hdr);
2966 MSI_ViewClose(view);
2967 msiobj_release(&view->hdr);
2971 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
2975 MSIRECORD * row = 0;
2976 static const WCHAR Query[] =
2977 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2978 '`','S','h','o','r','t','c','u','t','`',0};
2984 return ERROR_INVALID_HANDLE;
2986 res = CoInitialize( NULL );
2989 ERR("CoInitialize failed\n");
2990 return ERROR_FUNCTION_FAILED;
2993 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2994 if (rc != ERROR_SUCCESS)
2995 return ERROR_SUCCESS;
2997 rc = MSI_ViewExecute(view, 0);
2998 if (rc != ERROR_SUCCESS)
3000 MSI_ViewClose(view);
3001 msiobj_release(&view->hdr);
3007 LPWSTR target_file, target_folder;
3009 WCHAR filename[0x100];
3012 static const WCHAR szlnk[]={'.','l','n','k',0};
3014 rc = MSI_ViewFetch(view,&row);
3015 if (rc != ERROR_SUCCESS)
3021 buffer = MSI_RecordGetString(row,4);
3022 index = get_loaded_component(package,buffer);
3026 msiobj_release(&row->hdr);
3030 if (!ACTION_VerifyComponentForAction(package, index,
3031 INSTALLSTATE_LOCAL))
3033 TRACE("Skipping shortcut creation due to disabled component\n");
3034 msiobj_release(&row->hdr);
3036 package->components[index].Action =
3037 package->components[index].Installed;
3042 package->components[index].Action = INSTALLSTATE_LOCAL;
3044 ui_actiondata(package,szCreateShortcuts,row);
3046 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3047 &IID_IShellLinkW, (LPVOID *) &sl );
3051 ERR("Is IID_IShellLink\n");
3052 msiobj_release(&row->hdr);
3056 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
3059 ERR("Is IID_IPersistFile\n");
3060 msiobj_release(&row->hdr);
3064 buffer = MSI_RecordGetString(row,2);
3065 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
3067 /* may be needed because of a bug somehwere else */
3068 create_full_pathW(target_folder);
3071 MSI_RecordGetStringW(row,3,filename,&sz);
3072 reduce_to_longfilename(filename);
3073 if (!strchrW(filename,'.') || strcmpiW(strchrW(filename,'.'),szlnk))
3074 strcatW(filename,szlnk);
3075 target_file = build_directory_name(2, target_folder, filename);
3076 HeapFree(GetProcessHeap(),0,target_folder);
3078 buffer = MSI_RecordGetString(row,5);
3079 if (strchrW(buffer,'['))
3082 deformat_string(package,buffer,&deformated);
3083 IShellLinkW_SetPath(sl,deformated);
3084 HeapFree(GetProcessHeap(),0,deformated);
3089 FIXME("poorly handled shortcut format, advertised shortcut\n");
3090 keypath = strdupW(package->components[index].FullKeypath);
3091 IShellLinkW_SetPath(sl,keypath);
3092 HeapFree(GetProcessHeap(),0,keypath);
3095 if (!MSI_RecordIsNull(row,6))
3098 buffer = MSI_RecordGetString(row,6);
3099 deformat_string(package,buffer,&deformated);
3100 IShellLinkW_SetArguments(sl,deformated);
3101 HeapFree(GetProcessHeap(),0,deformated);
3104 if (!MSI_RecordIsNull(row,7))
3106 buffer = MSI_RecordGetString(row,7);
3107 IShellLinkW_SetDescription(sl,buffer);
3110 if (!MSI_RecordIsNull(row,8))
3111 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
3113 if (!MSI_RecordIsNull(row,9))
3118 buffer = MSI_RecordGetString(row,9);
3120 build_icon_path(package,buffer,&Path);
3121 index = MSI_RecordGetInteger(row,10);
3123 IShellLinkW_SetIconLocation(sl,Path,index);
3124 HeapFree(GetProcessHeap(),0,Path);
3127 if (!MSI_RecordIsNull(row,11))
3128 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
3130 if (!MSI_RecordIsNull(row,12))
3133 buffer = MSI_RecordGetString(row,12);
3134 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
3135 IShellLinkW_SetWorkingDirectory(sl,Path);
3136 HeapFree(GetProcessHeap(), 0, Path);
3139 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
3140 IPersistFile_Save(pf,target_file,FALSE);
3142 HeapFree(GetProcessHeap(),0,target_file);
3144 IPersistFile_Release( pf );
3145 IShellLinkW_Release( sl );
3147 msiobj_release(&row->hdr);
3149 MSI_ViewClose(view);
3150 msiobj_release(&view->hdr);
3160 * 99% of the work done here is only done for
3161 * advertised installs. However this is where the
3162 * Icon table is processed and written out
3163 * so that is what I am going to do here.
3165 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
3169 MSIRECORD * row = 0;
3170 static const WCHAR Query[]=
3171 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3172 '`','I','c','o','n','`',0};
3174 /* for registry stuff */
3178 static const WCHAR szProductName[] =
3179 {'P','r','o','d','u','c','t','N','a','m','e',0};
3180 static const WCHAR szPackageCode[] =
3181 {'P','a','c','k','a','g','e','C','o','d','e',0};
3182 static const WCHAR szLanguage[] =
3183 {'L','a','n','g','u','a','g','e',0};
3184 static const WCHAR szProductLanguage[] =
3185 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3186 static const WCHAR szProductIcon[] =
3187 {'P','r','o','d','u','c','t','I','c','o','n',0};
3188 static const WCHAR szARPProductIcon[] =
3189 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
3190 static const WCHAR szProductVersion[] =
3191 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3192 static const WCHAR szVersion[] =
3193 {'V','e','r','s','i','o','n',0};
3197 MSIHANDLE hDb, hSumInfo;
3200 return ERROR_INVALID_HANDLE;
3202 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3203 if (rc != ERROR_SUCCESS)
3206 rc = MSI_ViewExecute(view, 0);
3207 if (rc != ERROR_SUCCESS)
3209 MSI_ViewClose(view);
3210 msiobj_release(&view->hdr);
3217 LPWSTR FilePath=NULL;
3218 LPCWSTR FileName=NULL;
3221 rc = MSI_ViewFetch(view,&row);
3222 if (rc != ERROR_SUCCESS)
3228 FileName = MSI_RecordGetString(row,1);
3231 ERR("Unable to get FileName\n");
3232 msiobj_release(&row->hdr);
3236 build_icon_path(package,FileName,&FilePath);
3238 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
3240 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
3241 FILE_ATTRIBUTE_NORMAL, NULL);
3243 if (the_file == INVALID_HANDLE_VALUE)
3245 ERR("Unable to create file %s\n",debugstr_w(FilePath));
3246 msiobj_release(&row->hdr);
3247 HeapFree(GetProcessHeap(),0,FilePath);
3255 rc = MSI_RecordReadStream(row,2,buffer,&sz);
3256 if (rc != ERROR_SUCCESS)
3258 ERR("Failed to get stream\n");
3259 CloseHandle(the_file);
3260 DeleteFileW(FilePath);
3263 WriteFile(the_file,buffer,sz,&write,NULL);
3264 } while (sz == 1024);
3266 HeapFree(GetProcessHeap(),0,FilePath);
3268 CloseHandle(the_file);
3269 msiobj_release(&row->hdr);
3271 MSI_ViewClose(view);
3272 msiobj_release(&view->hdr);
3275 /* ok there is a lot more done here but i need to figure out what */
3276 productcode = load_dynamic_property(package,szProductCode,&rc);
3280 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
3281 if (rc != ERROR_SUCCESS)
3284 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
3285 if (rc != ERROR_SUCCESS)
3289 buffer = load_dynamic_property(package,szProductName,NULL);
3290 size = strlenW(buffer)*sizeof(WCHAR);
3291 RegSetValueExW(hukey,szProductName,0,REG_SZ, (BYTE *)buffer,size);
3292 HeapFree(GetProcessHeap(),0,buffer);
3294 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3295 size = sizeof(DWORD);
3296 langid = atoiW(buffer);
3297 RegSetValueExW(hukey,szLanguage,0,REG_DWORD, (BYTE *)&langid,size);
3298 HeapFree(GetProcessHeap(),0,buffer);
3300 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
3304 build_icon_path(package,buffer,&path);
3305 size = strlenW(path) * sizeof(WCHAR);
3306 RegSetValueExW(hukey,szProductIcon,0,REG_SZ, (BYTE *)path,size);
3308 HeapFree(GetProcessHeap(),0,buffer);
3310 buffer = load_dynamic_property(package,szProductVersion,NULL);
3313 DWORD verdword = build_version_dword(buffer);
3314 size = sizeof(DWORD);
3315 RegSetValueExW(hukey,szVersion,0,REG_DWORD, (BYTE *)&verdword,size);
3317 HeapFree(GetProcessHeap(),0,buffer);
3319 FIXME("Need to write more keys to the user registry\n");
3321 hDb= alloc_msihandle( &package->db->hdr );
3322 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
3323 MsiCloseHandle(hDb);
3324 if (rc == ERROR_SUCCESS)
3326 WCHAR guidbuffer[0x200];
3328 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
3330 if (rc == ERROR_SUCCESS)
3332 WCHAR squashed[GUID_SIZE];
3333 /* for now we only care about the first guid */
3334 LPWSTR ptr = strchrW(guidbuffer,';');
3336 squash_guid(guidbuffer,squashed);
3337 size = strlenW(squashed)*sizeof(WCHAR);
3338 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
3343 ERR("Unable to query Revision_Number... \n");
3346 MsiCloseHandle(hSumInfo);
3350 ERR("Unable to open Summary Information\n");
3356 HeapFree(GetProcessHeap(),0,productcode);
3363 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
3367 MSIRECORD * row = 0;
3368 static const WCHAR ExecSeqQuery[] =
3369 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3370 '`','I','n','i','F','i','l','e','`',0};
3371 static const WCHAR szWindowsFolder[] =
3372 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3374 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3375 if (rc != ERROR_SUCCESS)
3377 TRACE("no IniFile table\n");
3378 return ERROR_SUCCESS;
3381 rc = MSI_ViewExecute(view, 0);
3382 if (rc != ERROR_SUCCESS)
3384 MSI_ViewClose(view);
3385 msiobj_release(&view->hdr);
3391 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
3392 LPWSTR deformated_section, deformated_key, deformated_value;
3393 LPWSTR folder, fullname = NULL;
3395 INT component_index,action;
3397 rc = MSI_ViewFetch(view,&row);
3398 if (rc != ERROR_SUCCESS)
3404 component = MSI_RecordGetString(row, 8);
3405 component_index = get_loaded_component(package,component);
3407 if (!ACTION_VerifyComponentForAction(package, component_index,
3408 INSTALLSTATE_LOCAL))
3410 TRACE("Skipping ini file due to disabled component %s\n",
3411 debugstr_w(component));
3412 msiobj_release(&row->hdr);
3414 package->components[component_index].Action =
3415 package->components[component_index].Installed;
3420 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3422 identifier = MSI_RecordGetString(row,1);
3423 filename = MSI_RecordGetString(row,2);
3424 dirproperty = MSI_RecordGetString(row,3);
3425 section = MSI_RecordGetString(row,4);
3426 key = MSI_RecordGetString(row,5);
3427 value = MSI_RecordGetString(row,6);
3428 action = MSI_RecordGetInteger(row,7);
3430 deformat_string(package,section,&deformated_section);
3431 deformat_string(package,key,&deformated_key);
3432 deformat_string(package,value,&deformated_value);
3436 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
3438 folder = load_dynamic_property(package,dirproperty,NULL);
3441 folder = load_dynamic_property(package, szWindowsFolder, NULL);
3445 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
3449 fullname = build_directory_name(3, folder, filename, NULL);
3453 TRACE("Adding value %s to section %s in %s\n",
3454 debugstr_w(deformated_key), debugstr_w(deformated_section),
3455 debugstr_w(fullname));
3456 WritePrivateProfileStringW(deformated_section, deformated_key,
3457 deformated_value, fullname);
3459 else if (action == 1)
3462 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
3463 returned, 10, fullname);
3464 if (returned[0] == 0)
3466 TRACE("Adding value %s to section %s in %s\n",
3467 debugstr_w(deformated_key), debugstr_w(deformated_section),
3468 debugstr_w(fullname));
3470 WritePrivateProfileStringW(deformated_section, deformated_key,
3471 deformated_value, fullname);
3474 else if (action == 3)
3476 FIXME("Append to existing section not yet implemented\n");
3479 uirow = MSI_CreateRecord(4);
3480 MSI_RecordSetStringW(uirow,1,identifier);
3481 MSI_RecordSetStringW(uirow,2,deformated_section);
3482 MSI_RecordSetStringW(uirow,3,deformated_key);
3483 MSI_RecordSetStringW(uirow,4,deformated_value);
3484 ui_actiondata(package,szWriteIniValues,uirow);
3485 msiobj_release( &uirow->hdr );
3487 HeapFree(GetProcessHeap(),0,fullname);
3488 HeapFree(GetProcessHeap(),0,folder);
3489 HeapFree(GetProcessHeap(),0,deformated_key);
3490 HeapFree(GetProcessHeap(),0,deformated_value);
3491 HeapFree(GetProcessHeap(),0,deformated_section);
3492 msiobj_release(&row->hdr);
3494 MSI_ViewClose(view);
3495 msiobj_release(&view->hdr);
3499 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
3503 MSIRECORD * row = 0;
3504 static const WCHAR ExecSeqQuery[] =
3505 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3506 '`','S','e','l','f','R','e','g','`',0};
3508 static const WCHAR ExeStr[] =
3509 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3510 static const WCHAR close[] = {'\"',0};
3512 PROCESS_INFORMATION info;
3515 memset(&si,0,sizeof(STARTUPINFOW));
3517 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3518 if (rc != ERROR_SUCCESS)
3520 TRACE("no SelfReg table\n");
3521 return ERROR_SUCCESS;
3524 rc = MSI_ViewExecute(view, 0);
3525 if (rc != ERROR_SUCCESS)
3527 MSI_ViewClose(view);
3528 msiobj_release(&view->hdr);
3539 rc = MSI_ViewFetch(view,&row);
3540 if (rc != ERROR_SUCCESS)
3546 filename = MSI_RecordGetString(row,1);
3547 index = get_loaded_file(package,filename);
3551 ERR("Unable to find file id %s\n",debugstr_w(filename));
3552 msiobj_release(&row->hdr);
3556 len = strlenW(ExeStr);
3557 len += strlenW(package->files[index].TargetPath);
3560 FullName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3561 strcpyW(FullName,ExeStr);
3562 strcatW(FullName,package->files[index].TargetPath);
3563 strcatW(FullName,close);
3565 TRACE("Registering %s\n",debugstr_w(FullName));
3566 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL,
3567 c_colon, &si, &info);
3570 msi_dialog_check_messages(info.hProcess);
3572 HeapFree(GetProcessHeap(),0,FullName);
3573 msiobj_release(&row->hdr);
3575 MSI_ViewClose(view);
3576 msiobj_release(&view->hdr);
3580 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
3589 return ERROR_INVALID_HANDLE;
3591 productcode = load_dynamic_property(package,szProductCode,&rc);
3595 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
3596 if (rc != ERROR_SUCCESS)
3599 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
3600 if (rc != ERROR_SUCCESS)
3603 /* here the guids are base 85 encoded */
3604 for (i = 0; i < package->loaded_features; i++)
3610 BOOL absent = FALSE;
3612 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL) &&
3613 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_SOURCE) &&
3614 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_ADVERTISED))
3617 size = package->features[i].ComponentCount*21;
3619 if (package->features[i].Feature_Parent[0])
3620 size += strlenW(package->features[i].Feature_Parent)+2;
3622 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
3625 for (j = 0; j < package->features[i].ComponentCount; j++)
3628 memset(buf,0,sizeof(buf));
3629 if (package->components
3630 [package->features[i].Components[j]].ComponentId[0]!=0)
3632 TRACE("From %s\n",debugstr_w(package->components
3633 [package->features[i].Components[j]].ComponentId));
3634 CLSIDFromString(package->components
3635 [package->features[i].Components[j]].ComponentId,
3637 encode_base85_guid(&clsid,buf);
3638 TRACE("to %s\n",debugstr_w(buf));
3642 if (package->features[i].Feature_Parent[0])
3644 static const WCHAR sep[] = {'\2',0};
3646 strcatW(data,package->features[i].Feature_Parent);
3649 size = (strlenW(data)+1)*sizeof(WCHAR);
3650 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
3652 HeapFree(GetProcessHeap(),0,data);
3656 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
3657 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
3658 (LPSTR)package->features[i].Feature_Parent,size);
3662 size = (strlenW(package->features[i].Feature_Parent)+2)*
3664 data = HeapAlloc(GetProcessHeap(),0,size);
3666 strcpyW(&data[1],package->features[i].Feature_Parent);
3667 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
3669 HeapFree(GetProcessHeap(),0,data);
3676 HeapFree(GetProcessHeap(), 0, productcode);
3680 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
3683 LPWSTR buffer = NULL;
3687 static WCHAR szNONE[] = {0};
3688 static const WCHAR szWindowsInstaler[] =
3689 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3690 static const WCHAR szPropKeys[][80] =
3692 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3693 {'A','R','P','C','O','N','T','A','C','T',0},
3694 {'A','R','P','C','O','M','M','E','N','T','S',0},
3695 {'P','r','o','d','u','c','t','N','a','m','e',0},
3696 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3697 {'A','R','P','H','E','L','P','L','I','N','K',0},
3698 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3699 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3700 {'S','o','u','r','c','e','D','i','r',0},
3701 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3702 {'A','R','P','R','E','A','D','M','E',0},
3703 {'A','R','P','S','I','Z','E',0},
3704 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3705 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3709 static const WCHAR szRegKeys[][80] =
3711 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3712 {'C','o','n','t','a','c','t',0},
3713 {'C','o','m','m','e','n','t','s',0},
3714 {'D','i','s','p','l','a','y','N','a','m','e',0},
3715 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3716 {'H','e','l','p','L','i','n','k',0},
3717 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3718 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3719 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3720 {'P','u','b','l','i','s','h','e','r',0},
3721 {'R','e','a','d','m','e',0},
3722 {'S','i','z','e',0},
3723 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3724 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3728 static const WCHAR installerPathFmt[] = {
3730 'I','n','s','t','a','l','l','e','r','\\',0};
3731 static const WCHAR fmt[] = {
3733 'I','n','s','t','a','l','l','e','r','\\',
3734 '%','x','.','m','s','i',0};
3735 static const WCHAR szLocalPackage[]=
3736 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
3737 static const WCHAR szUpgradeCode[] =
3738 {'U','p','g','r','a','d','e','C','o','d','e',0};
3739 static const WCHAR modpath_fmt[] =
3740 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3741 static const WCHAR szModifyPath[] =
3742 {'M','o','d','i','f','y','P','a','t','h',0};
3743 static const WCHAR szUninstallString[] =
3744 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3745 static const WCHAR szEstimatedSize[] =
3746 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3747 static const WCHAR szInstallDate[] =
3748 {'I','n','s','t','a','l','l','D','a','t','e',0};
3749 static const WCHAR szLanguage[] =
3750 {'L','a','n','g','u','a','g','e',0};
3751 static const WCHAR szProductLanguage[] =
3752 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3753 static const WCHAR szProductVersion[] =
3754 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3755 static const WCHAR szVersion[] =
3756 {'V','e','r','s','i','o','n',0};
3757 static const WCHAR szVersionMajor[] =
3758 {'V','e','r','s','i','o','n','M','a','j','o','r',0};
3759 static const WCHAR szVersionMinor[] =
3760 {'V','e','r','s','i','o','n','M','i','n','o','r',0};
3763 static const WCHAR date_fmt[] = {'%','i','%','i','%','i',0};
3764 LPWSTR upgrade_code;
3765 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
3769 return ERROR_INVALID_HANDLE;
3771 productcode = load_dynamic_property(package,szProductCode,&rc);
3775 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
3776 if (rc != ERROR_SUCCESS)
3779 /* dump all the info i can grab */
3780 FIXME("Flesh out more information \n");
3783 while (szPropKeys[i][0]!=0)
3785 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3786 if (rc != ERROR_SUCCESS)
3788 size = strlenW(buffer)*sizeof(WCHAR);
3789 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
3790 HeapFree(GetProcessHeap(),0,buffer);
3796 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
3798 /* copy the package locally */
3799 num = GetTickCount() & 0xffff;
3803 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
3804 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
3808 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
3809 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
3810 if (handle != INVALID_HANDLE_VALUE)
3812 CloseHandle(handle);
3815 if (GetLastError() != ERROR_FILE_EXISTS &&
3816 GetLastError() != ERROR_SHARING_VIOLATION)
3818 if (!(++num & 0xffff)) num = 1;
3819 sprintfW(packagefile,fmt,num);
3820 } while (num != start);
3822 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
3823 create_full_pathW(path);
3824 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
3825 if (!CopyFileW(package->PackagePath,packagefile,FALSE))
3826 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3827 debugstr_w(package->PackagePath), debugstr_w(packagefile),
3829 size = strlenW(packagefile)*sizeof(WCHAR);
3830 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
3832 /* do ModifyPath and UninstallString */
3833 size = deformat_string(package,modpath_fmt,&buffer);
3834 RegSetValueExW(hkey,szModifyPath,0,REG_EXPAND_SZ,(LPSTR)buffer,size);
3835 RegSetValueExW(hkey,szUninstallString,0,REG_EXPAND_SZ,(LPSTR)buffer,size);
3836 HeapFree(GetProcessHeap(),0,buffer);
3838 FIXME("Write real Estimated Size when we have it\n");
3840 RegSetValueExW(hkey,szEstimatedSize,0,REG_DWORD,(LPSTR)&size,sizeof(DWORD));
3842 GetLocalTime(&systime);
3843 size = 9*sizeof(WCHAR);
3844 buffer= HeapAlloc(GetProcessHeap(),0,size);
3845 sprintfW(buffer,date_fmt,systime.wYear,systime.wMonth,systime.wDay);
3846 size = strlenW(buffer)*sizeof(WCHAR);
3847 RegSetValueExW(hkey,szInstallDate,0,REG_SZ,(LPSTR)buffer,size);
3848 HeapFree(GetProcessHeap(),0,buffer);
3850 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3851 size = atoiW(buffer);
3852 RegSetValueExW(hkey,szLanguage,0,REG_DWORD, (LPSTR)&size,sizeof(DWORD));
3853 HeapFree(GetProcessHeap(),1,buffer);
3855 buffer = load_dynamic_property(package,szProductVersion,NULL);
3858 DWORD verdword = build_version_dword(buffer);
3859 DWORD vermajor = verdword>>24;
3860 DWORD verminor = (verdword>>16)&0x00FF;
3861 size = sizeof(DWORD);
3862 RegSetValueExW(hkey,szVersion,0,REG_DWORD,(LPSTR)&verdword,size);
3863 RegSetValueExW(hkey,szVersionMajor,0,REG_DWORD,(LPSTR)&vermajor,size);
3864 RegSetValueExW(hkey,szVersionMinor,0,REG_DWORD,(LPSTR)&verminor,size);
3866 HeapFree(GetProcessHeap(),0,buffer);
3868 /* Handle Upgrade Codes */
3869 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
3874 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3875 squash_guid(productcode,squashed);
3876 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3878 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3879 squash_guid(productcode,squashed);
3880 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3883 HeapFree(GetProcessHeap(),0,upgrade_code);
3887 HeapFree(GetProcessHeap(),0,productcode);
3890 return ERROR_SUCCESS;
3893 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
3898 return ERROR_INVALID_HANDLE;
3900 rc = execute_script(package,INSTALL_SCRIPT);
3905 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
3910 return ERROR_INVALID_HANDLE;
3912 /* turn off scheduleing */
3913 package->script->CurrentlyScripting= FALSE;
3915 /* first do the same as an InstallExecute */
3916 rc = ACTION_InstallExecute(package);
3917 if (rc != ERROR_SUCCESS)
3920 /* then handle Commit Actions */
3921 rc = execute_script(package,COMMIT_SCRIPT);
3926 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
3928 static const WCHAR RunOnce[] = {
3929 'S','o','f','t','w','a','r','e','\\',
3930 'M','i','c','r','o','s','o','f','t','\\',
3931 'W','i','n','d','o','w','s','\\',
3932 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3933 'R','u','n','O','n','c','e',0};
3934 static const WCHAR InstallRunOnce[] = {
3935 'S','o','f','t','w','a','r','e','\\',
3936 'M','i','c','r','o','s','o','f','t','\\',
3937 'W','i','n','d','o','w','s','\\',
3938 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3939 'I','n','s','t','a','l','l','e','r','\\',
3940 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3942 static const WCHAR msiexec_fmt[] = {
3944 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3945 '\"','%','s','\"',0};
3946 static const WCHAR install_fmt[] = {
3947 '/','I',' ','\"','%','s','\"',' ',
3948 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3949 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3950 WCHAR buffer[256], sysdir[MAX_PATH];
3953 WCHAR squished_pc[100];
3956 static const WCHAR szLUS[] = {
3957 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
3958 static const WCHAR szSourceList[] = {
3959 'S','o','u','r','c','e','L','i','s','t',0};
3960 static const WCHAR szPackageName[] = {
3961 'P','a','c','k','a','g','e','N','a','m','e',0};
3964 return ERROR_INVALID_HANDLE;
3966 productcode = load_dynamic_property(package,szProductCode,&rc);
3970 squash_guid(productcode,squished_pc);
3972 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
3973 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
3974 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
3977 size = strlenW(buffer)*sizeof(WCHAR);
3978 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
3981 TRACE("Reboot command %s\n",debugstr_w(buffer));
3983 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
3984 sprintfW(buffer,install_fmt,productcode,squished_pc);
3986 size = strlenW(buffer)*sizeof(WCHAR);
3987 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
3990 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
3991 if (rc == ERROR_SUCCESS)
3995 RegCreateKeyW(hukey, szSourceList, &hukey2);
3996 buf = load_dynamic_property(package,cszSourceDir,NULL);
3997 size = strlenW(buf)*sizeof(WCHAR);
3998 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
3999 HeapFree(GetProcessHeap(),0,buf);
4001 buf = strrchrW(package->PackagePath,'\\');
4005 size = strlenW(buf)*sizeof(WCHAR);
4006 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
4009 RegCloseKey(hukey2);
4011 HeapFree(GetProcessHeap(),0,productcode);
4013 return ERROR_INSTALL_SUSPEND;
4016 UINT ACTION_ResolveSource(MSIPACKAGE* package)
4019 * we are currently doing what should be done here in the top level Install
4020 * however for Adminastrative and uninstalls this step will be needed
4022 return ERROR_SUCCESS;
4025 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
4027 static const WCHAR szProductID[]=
4028 {'P','r','o','d','u','c','t','I','D',0};
4036 static const WCHAR szPropKeys[][80] =
4038 {'P','r','o','d','u','c','t','I','D',0},
4039 {'U','S','E','R','N','A','M','E',0},
4040 {'C','O','M','P','A','N','Y','N','A','M','E',0},
4044 static const WCHAR szRegKeys[][80] =
4046 {'P','r','o','d','u','c','t','I','D',0},
4047 {'R','e','g','O','w','n','e','r',0},
4048 {'R','e','g','C','o','m','p','a','n','y',0},
4053 return ERROR_INVALID_HANDLE;
4055 productid = load_dynamic_property(package,szProductID,&rc);
4057 return ERROR_SUCCESS;
4059 productcode = load_dynamic_property(package,szProductCode,&rc);
4063 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
4064 if (rc != ERROR_SUCCESS)
4068 while (szPropKeys[i][0]!=0)
4070 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
4071 if (rc == ERROR_SUCCESS)
4073 size = strlenW(buffer)*sizeof(WCHAR);
4074 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
4077 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
4082 HeapFree(GetProcessHeap(),0,productcode);
4083 HeapFree(GetProcessHeap(),0,productid);
4086 return ERROR_SUCCESS;
4090 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
4093 rc = ACTION_ProcessExecSequence(package,FALSE);
4099 * Code based off of code located here
4100 * http://www.codeproject.com/gdi/fontnamefromfile.asp
4102 * Using string index 4 (full font name) instead of 1 (family name)
4104 static LPWSTR load_ttfname_from(LPCWSTR filename)
4110 typedef struct _tagTT_OFFSET_TABLE{
4111 USHORT uMajorVersion;
4112 USHORT uMinorVersion;
4113 USHORT uNumOfTables;
4114 USHORT uSearchRange;
4115 USHORT uEntrySelector;
4119 typedef struct _tagTT_TABLE_DIRECTORY{
4120 char szTag[4]; /* table name */
4121 ULONG uCheckSum; /* Check sum */
4122 ULONG uOffset; /* Offset from beginning of file */
4123 ULONG uLength; /* length of the table in bytes */
4124 }TT_TABLE_DIRECTORY;
4126 typedef struct _tagTT_NAME_TABLE_HEADER{
4127 USHORT uFSelector; /* format selector. Always 0 */
4128 USHORT uNRCount; /* Name Records count */
4129 USHORT uStorageOffset; /* Offset for strings storage,
4130 * from start of the table */
4131 }TT_NAME_TABLE_HEADER;
4133 typedef struct _tagTT_NAME_RECORD{
4138 USHORT uStringLength;
4139 USHORT uStringOffset; /* from start of storage area */
4142 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
4143 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
4145 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
4146 FILE_ATTRIBUTE_NORMAL, 0 );
4147 if (handle != INVALID_HANDLE_VALUE)
4149 TT_TABLE_DIRECTORY tblDir;
4150 BOOL bFound = FALSE;
4151 TT_OFFSET_TABLE ttOffsetTable;
4153 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
4154 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
4155 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
4156 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
4158 if (ttOffsetTable.uMajorVersion != 1 ||
4159 ttOffsetTable.uMinorVersion != 0)
4162 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
4164 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
4165 if (strncmp(tblDir.szTag,"name",4)==0)
4168 tblDir.uLength = SWAPLONG(tblDir.uLength);
4169 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
4176 TT_NAME_TABLE_HEADER ttNTHeader;
4177 TT_NAME_RECORD ttRecord;
4179 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
4180 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
4183 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
4184 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
4186 for(i=0; i<ttNTHeader.uNRCount; i++)
4188 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
4189 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
4190 /* 4 is the Full Font Name */
4191 if(ttRecord.uNameID == 4)
4195 static LPCSTR tt = " (TrueType)";
4197 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
4198 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
4199 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
4200 SetFilePointer(handle, tblDir.uOffset +
4201 ttRecord.uStringOffset +
4202 ttNTHeader.uStorageOffset,
4204 buf = HeapAlloc(GetProcessHeap(), 0,
4205 ttRecord.uStringLength + 1 + strlen(tt));
4206 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
4207 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
4208 if (strlen(buf) > 0)
4211 ret = strdupAtoW(buf);
4212 HeapFree(GetProcessHeap(),0,buf);
4216 HeapFree(GetProcessHeap(),0,buf);
4217 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
4221 CloseHandle(handle);
4224 ERR("Unable to open font file %s\n", debugstr_w(filename));
4226 TRACE("Returning fontname %s\n",debugstr_w(ret));
4230 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
4234 MSIRECORD * row = 0;
4235 static const WCHAR ExecSeqQuery[] =
4236 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4237 '`','F','o','n','t','`',0};
4238 static const WCHAR regfont1[] =
4239 {'S','o','f','t','w','a','r','e','\\',
4240 'M','i','c','r','o','s','o','f','t','\\',
4241 'W','i','n','d','o','w','s',' ','N','T','\\',
4242 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4243 'F','o','n','t','s',0};
4244 static const WCHAR regfont2[] =
4245 {'S','o','f','t','w','a','r','e','\\',
4246 'M','i','c','r','o','s','o','f','t','\\',
4247 'W','i','n','d','o','w','s','\\',
4248 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4249 'F','o','n','t','s',0};
4253 TRACE("%p\n", package);
4255 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4256 if (rc != ERROR_SUCCESS)
4258 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
4259 return ERROR_SUCCESS;
4262 rc = MSI_ViewExecute(view, 0);
4263 if (rc != ERROR_SUCCESS)
4265 MSI_ViewClose(view);
4266 msiobj_release(&view->hdr);
4267 TRACE("MSI_ViewExecute returned %d\n", rc);
4268 return ERROR_SUCCESS;
4271 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
4272 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
4281 rc = MSI_ViewFetch(view,&row);
4282 if (rc != ERROR_SUCCESS)
4288 file = MSI_RecordGetString(row,1);
4289 index = get_loaded_file(package,file);
4292 ERR("Unable to load file\n");
4296 /* check to make sure that component is installed */
4297 if (!ACTION_VerifyComponentForAction(package,
4298 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
4300 TRACE("Skipping: Component not scheduled for install\n");
4302 msiobj_release(&row->hdr);
4307 if (MSI_RecordIsNull(row,2))
4308 name = load_ttfname_from(package->files[index].TargetPath);
4310 name = load_dynamic_stringW(row,2);
4314 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
4315 RegSetValueExW(hkey1,name,0,REG_SZ,
4316 (LPBYTE)package->files[index].FileName,size);
4317 RegSetValueExW(hkey2,name,0,REG_SZ,
4318 (LPBYTE)package->files[index].FileName,size);
4321 HeapFree(GetProcessHeap(),0,name);
4322 msiobj_release(&row->hdr);
4324 MSI_ViewClose(view);
4325 msiobj_release(&view->hdr);
4330 TRACE("returning %d\n", rc);
4334 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
4336 MSIPACKAGE *package = (MSIPACKAGE*)param;
4337 LPCWSTR compgroupid=NULL;
4338 LPCWSTR feature=NULL;
4339 LPCWSTR text = NULL;
4340 LPCWSTR qualifier = NULL;
4341 LPCWSTR component = NULL;
4342 LPWSTR advertise = NULL;
4343 LPWSTR output = NULL;
4345 UINT rc = ERROR_SUCCESS;
4349 component = MSI_RecordGetString(rec,3);
4350 index = get_loaded_component(package,component);
4352 if (!ACTION_VerifyComponentForAction(package, index,
4353 INSTALLSTATE_LOCAL) &&
4354 !ACTION_VerifyComponentForAction(package, index,
4355 INSTALLSTATE_SOURCE) &&
4356 !ACTION_VerifyComponentForAction(package, index,
4357 INSTALLSTATE_ADVERTISED))
4359 TRACE("Skipping: Component %s not scheduled for install\n",
4360 debugstr_w(component));
4362 return ERROR_SUCCESS;
4365 compgroupid = MSI_RecordGetString(rec,1);
4367 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
4368 if (rc != ERROR_SUCCESS)
4371 text = MSI_RecordGetString(rec,4);
4372 qualifier = MSI_RecordGetString(rec,2);
4373 feature = MSI_RecordGetString(rec,5);
4375 advertise = create_component_advertise_string(package,
4376 &package->components[index], feature);
4378 sz = strlenW(advertise);
4381 sz += lstrlenW(text);
4384 sz *= sizeof(WCHAR);
4386 output = HeapAlloc(GetProcessHeap(),0,sz);
4387 memset(output,0,sz);
4388 strcpyW(output,advertise);
4391 strcatW(output,text);
4393 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
4394 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
4398 HeapFree(GetProcessHeap(),0,output);
4404 * At present I am ignorning the advertised components part of this and only
4405 * focusing on the qualified component sets
4407 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
4411 static const WCHAR ExecSeqQuery[] =
4412 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4413 '`','P','u','b','l','i','s','h',
4414 'C','o','m','p','o','n','e','n','t','`',0};
4416 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4417 if (rc != ERROR_SUCCESS)
4418 return ERROR_SUCCESS;
4420 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
4421 msiobj_release(&view->hdr);