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);
89 * consts and values used
91 static const WCHAR c_colon[] = {'C',':','\\',0};
93 const static WCHAR szCreateFolders[] =
94 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
95 const static WCHAR szCostFinalize[] =
96 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
97 const WCHAR szInstallFiles[] =
98 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
99 const WCHAR szDuplicateFiles[] =
100 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
101 const static WCHAR szWriteRegistryValues[] =
102 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
103 'V','a','l','u','e','s',0};
104 const static WCHAR szCostInitialize[] =
105 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
106 const static WCHAR szFileCost[] =
107 {'F','i','l','e','C','o','s','t',0};
108 const static WCHAR szInstallInitialize[] =
109 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
110 const static WCHAR szInstallValidate[] =
111 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
112 const static WCHAR szLaunchConditions[] =
113 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
114 const static WCHAR szProcessComponents[] =
115 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
116 const static WCHAR szRegisterTypeLibraries[] =
117 {'R','e','g','i','s','t','e','r','T','y','p','e',
118 'L','i','b','r','a','r','i','e','s',0};
119 const WCHAR szRegisterClassInfo[] =
120 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
121 const WCHAR szRegisterProgIdInfo[] =
122 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
123 const static WCHAR szCreateShortcuts[] =
124 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
125 const static WCHAR szPublishProduct[] =
126 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
127 const static WCHAR szWriteIniValues[] =
128 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
129 const static WCHAR szSelfRegModules[] =
130 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
131 const static WCHAR szPublishFeatures[] =
132 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
133 const static WCHAR szRegisterProduct[] =
134 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
135 const static WCHAR szInstallExecute[] =
136 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
137 const static WCHAR szInstallExecuteAgain[] =
138 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
139 'A','g','a','i','n',0};
140 const static WCHAR szInstallFinalize[] =
141 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
142 const static WCHAR szForceReboot[] =
143 {'F','o','r','c','e','R','e','b','o','o','t',0};
144 const static WCHAR szResolveSource[] =
145 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
146 const WCHAR szAppSearch[] =
147 {'A','p','p','S','e','a','r','c','h',0};
148 const static WCHAR szAllocateRegistrySpace[] =
149 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
150 'S','p','a','c','e',0};
151 const static WCHAR szBindImage[] =
152 {'B','i','n','d','I','m','a','g','e',0};
153 const static WCHAR szCCPSearch[] =
154 {'C','C','P','S','e','a','r','c','h',0};
155 const static WCHAR szDeleteServices[] =
156 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
157 const static WCHAR szDisableRollback[] =
158 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
159 const static WCHAR szExecuteAction[] =
160 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
161 const WCHAR szFindRelatedProducts[] =
162 {'F','i','n','d','R','e','l','a','t','e','d',
163 'P','r','o','d','u','c','t','s',0};
164 const static WCHAR szInstallAdminPackage[] =
165 {'I','n','s','t','a','l','l','A','d','m','i','n',
166 'P','a','c','k','a','g','e',0};
167 const static WCHAR szInstallSFPCatalogFile[] =
168 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
170 const static WCHAR szIsolateComponents[] =
171 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
172 const WCHAR szMigrateFeatureStates[] =
173 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
174 'S','t','a','t','e','s',0};
175 const WCHAR szMoveFiles[] =
176 {'M','o','v','e','F','i','l','e','s',0};
177 const static WCHAR szMsiPublishAssemblies[] =
178 {'M','s','i','P','u','b','l','i','s','h',
179 'A','s','s','e','m','b','l','i','e','s',0};
180 const static WCHAR szMsiUnpublishAssemblies[] =
181 {'M','s','i','U','n','p','u','b','l','i','s','h',
182 'A','s','s','e','m','b','l','i','e','s',0};
183 const static WCHAR szInstallODBC[] =
184 {'I','n','s','t','a','l','l','O','D','B','C',0};
185 const static WCHAR szInstallServices[] =
186 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
187 const WCHAR szPatchFiles[] =
188 {'P','a','t','c','h','F','i','l','e','s',0};
189 const static WCHAR szPublishComponents[] =
190 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
191 const static WCHAR szRegisterComPlus[] =
192 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
193 const WCHAR szRegisterExtensionInfo[] =
194 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
196 const static WCHAR szRegisterFonts[] =
197 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
198 const WCHAR szRegisterMIMEInfo[] =
199 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
200 const static WCHAR szRegisterUser[] =
201 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
202 const WCHAR szRemoveDuplicateFiles[] =
203 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
204 'F','i','l','e','s',0};
205 const static WCHAR szRemoveEnvironmentStrings[] =
206 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
207 'S','t','r','i','n','g','s',0};
208 const WCHAR szRemoveExistingProducts[] =
209 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
210 'P','r','o','d','u','c','t','s',0};
211 const WCHAR szRemoveFiles[] =
212 {'R','e','m','o','v','e','F','i','l','e','s',0};
213 const static WCHAR szRemoveFolders[] =
214 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
215 const static WCHAR szRemoveIniValues[] =
216 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
217 const static WCHAR szRemoveODBC[] =
218 {'R','e','m','o','v','e','O','D','B','C',0};
219 const static WCHAR szRemoveRegistryValues[] =
220 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
221 'V','a','l','u','e','s',0};
222 const static WCHAR szRemoveShortcuts[] =
223 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
224 const static WCHAR szRMCCPSearch[] =
225 {'R','M','C','C','P','S','e','a','r','c','h',0};
226 const static WCHAR szScheduleReboot[] =
227 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
228 const static WCHAR szSelfUnregModules[] =
229 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
230 const static WCHAR szSetODBCFolders[] =
231 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
232 const static WCHAR szStartServices[] =
233 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
234 const static WCHAR szStopServices[] =
235 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
236 const static WCHAR szUnpublishComponents[] =
237 {'U','n','p','u','b','l','i','s','h',
238 'C','o','m','p','o','n','e','n','t','s',0};
239 const static WCHAR szUnpublishFeatures[] =
240 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
241 const WCHAR szUnregisterClassInfo[] =
242 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
244 const static WCHAR szUnregisterComPlus[] =
245 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
246 const WCHAR szUnregisterExtensionInfo[] =
247 {'U','n','r','e','g','i','s','t','e','r',
248 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
249 const static WCHAR szUnregisterFonts[] =
250 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
251 const WCHAR szUnregisterMIMEInfo[] =
252 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
253 const WCHAR szUnregisterProgIdInfo[] =
254 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
256 const static WCHAR szUnregisterTypeLibraries[] =
257 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
258 'L','i','b','r','a','r','i','e','s',0};
259 const static WCHAR szValidateProductID[] =
260 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
261 const static WCHAR szWriteEnvironmentStrings[] =
262 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
263 'S','t','r','i','n','g','s',0};
267 STANDARDACTIONHANDLER handler;
270 static struct _actions StandardActions[] = {
271 { szAllocateRegistrySpace, NULL},
272 { szAppSearch, ACTION_AppSearch },
273 { szBindImage, NULL},
274 { szCCPSearch, NULL},
275 { szCostFinalize, ACTION_CostFinalize },
276 { szCostInitialize, ACTION_CostInitialize },
277 { szCreateFolders, ACTION_CreateFolders },
278 { szCreateShortcuts, ACTION_CreateShortcuts },
279 { szDeleteServices, NULL},
280 { szDisableRollback, NULL},
281 { szDuplicateFiles, ACTION_DuplicateFiles },
282 { szExecuteAction, ACTION_ExecuteAction },
283 { szFileCost, ACTION_FileCost },
284 { szFindRelatedProducts, ACTION_FindRelatedProducts },
285 { szForceReboot, ACTION_ForceReboot },
286 { szInstallAdminPackage, NULL},
287 { szInstallExecute, ACTION_InstallExecute },
288 { szInstallExecuteAgain, ACTION_InstallExecute },
289 { szInstallFiles, ACTION_InstallFiles},
290 { szInstallFinalize, ACTION_InstallFinalize },
291 { szInstallInitialize, ACTION_InstallInitialize },
292 { szInstallSFPCatalogFile, NULL},
293 { szInstallValidate, ACTION_InstallValidate },
294 { szIsolateComponents, NULL},
295 { szLaunchConditions, ACTION_LaunchConditions },
296 { szMigrateFeatureStates, NULL},
297 { szMoveFiles, NULL},
298 { szMsiPublishAssemblies, NULL},
299 { szMsiUnpublishAssemblies, NULL},
300 { szInstallODBC, NULL},
301 { szInstallServices, NULL},
302 { szPatchFiles, NULL},
303 { szProcessComponents, ACTION_ProcessComponents },
304 { szPublishComponents, ACTION_PublishComponents },
305 { szPublishFeatures, ACTION_PublishFeatures },
306 { szPublishProduct, ACTION_PublishProduct },
307 { szRegisterClassInfo, ACTION_RegisterClassInfo },
308 { szRegisterComPlus, NULL},
309 { szRegisterExtensionInfo, ACTION_RegisterExtensionInfo },
310 { szRegisterFonts, ACTION_RegisterFonts },
311 { szRegisterMIMEInfo, ACTION_RegisterMIMEInfo },
312 { szRegisterProduct, ACTION_RegisterProduct },
313 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
314 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
315 { szRegisterUser, ACTION_RegisterUser},
316 { szRemoveDuplicateFiles, NULL},
317 { szRemoveEnvironmentStrings, NULL},
318 { szRemoveExistingProducts, NULL},
319 { szRemoveFiles, NULL},
320 { szRemoveFolders, NULL},
321 { szRemoveIniValues, NULL},
322 { szRemoveODBC, NULL},
323 { szRemoveRegistryValues, NULL},
324 { szRemoveShortcuts, NULL},
325 { szResolveSource, ACTION_ResolveSource},
326 { szRMCCPSearch, NULL},
327 { szScheduleReboot, NULL},
328 { szSelfRegModules, ACTION_SelfRegModules },
329 { szSelfUnregModules, NULL},
330 { szSetODBCFolders, NULL},
331 { szStartServices, NULL},
332 { szStopServices, NULL},
333 { szUnpublishComponents, NULL},
334 { szUnpublishFeatures, NULL},
335 { szUnregisterClassInfo, NULL},
336 { szUnregisterComPlus, NULL},
337 { szUnregisterExtensionInfo, NULL},
338 { szUnregisterFonts, NULL},
339 { szUnregisterMIMEInfo, NULL},
340 { szUnregisterProgIdInfo, NULL},
341 { szUnregisterTypeLibraries, NULL},
342 { szValidateProductID, NULL},
343 { szWriteEnvironmentStrings, NULL},
344 { szWriteIniValues, ACTION_WriteIniValues },
345 { szWriteRegistryValues, ACTION_WriteRegistryValues},
350 /********************************************************
352 ********************************************************/
354 static void ce_actiontext(MSIPACKAGE* package, LPCWSTR action)
356 static const WCHAR szActionText[] =
357 {'A','c','t','i','o','n','T','e','x','t',0};
360 row = MSI_CreateRecord(1);
361 MSI_RecordSetStringW(row,1,action);
362 ControlEvent_FireSubscribedEvent(package,szActionText, row);
363 msiobj_release(&row->hdr);
366 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
368 static const WCHAR template_s[]=
369 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
371 static const WCHAR format[] =
372 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
373 static const WCHAR Query_t[] =
374 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
375 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
376 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
377 ' ','\'','%','s','\'',0};
384 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
386 row = MSI_QueryGetRecord( package->db, Query_t, action );
390 ActionText = MSI_RecordGetString(row,2);
391 deformat_string(package, ActionText, &deformated);
393 sprintfW(message,template_s,timet,action,deformated);
394 ce_actiontext(package, deformated);
395 msiobj_release(&row->hdr);
397 row = MSI_CreateRecord(1);
398 MSI_RecordSetStringW(row,1,message);
400 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
401 msiobj_release(&row->hdr);
402 HeapFree(GetProcessHeap(),0,deformated);
405 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
409 static const WCHAR template_s[]=
410 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
412 static const WCHAR template_e[]=
413 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
414 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
416 static const WCHAR format[] =
417 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
421 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
423 sprintfW(message,template_s,timet,action);
425 sprintfW(message,template_e,timet,action,rc);
427 row = MSI_CreateRecord(1);
428 MSI_RecordSetStringW(row,1,message);
430 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
431 msiobj_release(&row->hdr);
434 /****************************************************
435 * TOP level entry points
436 *****************************************************/
438 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
439 LPCWSTR szCommandLine, LPCWSTR msiFilePath)
445 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
446 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
447 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
449 MSI_SetPropertyW(package, szAction, szInstall);
451 package->script = HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT));
452 memset(package->script,0,sizeof(MSISCRIPT));
454 package->script->InWhatSequence = SEQUENCE_INSTALL;
456 package->msiFilePath= strdupW(msiFilePath);
460 LPWSTR p, check, path;
462 package->PackagePath = strdupW(szPackagePath);
463 path = strdupW(szPackagePath);
464 p = strrchrW(path,'\\');
472 HeapFree(GetProcessHeap(),0,path);
473 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
474 GetCurrentDirectoryW(MAX_PATH,path);
478 check = load_dynamic_property(package, cszSourceDir,NULL);
480 MSI_SetPropertyW(package, cszSourceDir, path);
482 HeapFree(GetProcessHeap(), 0, check);
484 HeapFree(GetProcessHeap(), 0, path);
490 ptr = (LPWSTR)szCommandLine;
497 TRACE("Looking at %s\n",debugstr_w(ptr));
499 ptr2 = strchrW(ptr,'=');
505 while (*ptr == ' ') ptr++;
507 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
508 memcpy(prop,ptr,len*sizeof(WCHAR));
514 while (*ptr && (quote || (!quote && *ptr!=' ')))
527 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
528 memcpy(val,ptr2,len*sizeof(WCHAR));
531 if (strlenW(prop) > 0)
533 TRACE("Found commandline property (%s) = (%s)\n",
534 debugstr_w(prop), debugstr_w(val));
535 MSI_SetPropertyW(package,prop,val);
537 HeapFree(GetProcessHeap(),0,val);
538 HeapFree(GetProcessHeap(),0,prop);
545 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
547 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
549 package->script->InWhatSequence |= SEQUENCE_UI;
550 rc = ACTION_ProcessUISequence(package);
552 if (rc == ERROR_SUCCESS)
554 package->script->InWhatSequence |= SEQUENCE_EXEC;
555 rc = ACTION_ProcessExecSequence(package,TRUE);
559 rc = ACTION_ProcessExecSequence(package,FALSE);
562 rc = ACTION_ProcessExecSequence(package,FALSE);
566 /* install was halted but should be considered a success */
570 package->script->CurrentlyScripting= FALSE;
572 /* process the ending type action */
573 if (rc == ERROR_SUCCESS)
574 ACTION_PerformActionSequence(package,-1,ui);
575 else if (rc == ERROR_INSTALL_USEREXIT)
576 ACTION_PerformActionSequence(package,-2,ui);
577 else if (rc == ERROR_INSTALL_SUSPEND)
578 ACTION_PerformActionSequence(package,-4,ui);
580 ACTION_PerformActionSequence(package,-3,ui);
582 /* finish up running custom actions */
583 ACTION_FinishCustomActions(package);
588 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
590 UINT rc = ERROR_SUCCESS;
592 static const WCHAR ExecSeqQuery[] =
593 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
594 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
595 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
596 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
598 static const WCHAR UISeqQuery[] =
599 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
600 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
601 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
602 ' ', '=',' ','%','i',0};
605 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
607 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
611 LPCWSTR action, cond;
613 TRACE("Running the actions\n");
615 /* check conditions */
616 cond = MSI_RecordGetString(row,2);
619 /* this is a hack to skip errors in the condition code */
620 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
624 action = MSI_RecordGetString(row,1);
627 ERR("failed to fetch action\n");
628 rc = ERROR_FUNCTION_FAILED;
633 rc = ACTION_PerformUIAction(package,action);
635 rc = ACTION_PerformAction(package,action,FALSE);
637 msiobj_release(&row->hdr);
648 } iterate_action_param;
650 static UINT ITERATE_Actions(MSIRECORD *row, LPVOID param)
652 iterate_action_param *iap= (iterate_action_param*)param;
654 LPCWSTR cond, action;
656 action = MSI_RecordGetString(row,1);
659 ERR("Error is retrieving action name\n");
660 return ERROR_FUNCTION_FAILED;
663 /* check conditions */
664 cond = MSI_RecordGetString(row,2);
667 /* this is a hack to skip errors in the condition code */
668 if (MSI_EvaluateConditionW(iap->package, cond) == MSICONDITION_FALSE)
670 TRACE("Skipping action: %s (condition is false)\n",
672 return ERROR_SUCCESS;
677 rc = ACTION_PerformUIAction(iap->package,action);
679 rc = ACTION_PerformAction(iap->package,action,FALSE);
681 msi_dialog_check_messages( NULL );
683 if (iap->package->CurrentInstallState != ERROR_SUCCESS )
684 rc = iap->package->CurrentInstallState;
686 if (rc == ERROR_FUNCTION_NOT_CALLED)
689 if (rc != ERROR_SUCCESS)
690 ERR("Execution halted due to error (%i)\n",rc);
695 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
699 static const WCHAR ExecSeqQuery[] =
700 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
701 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
702 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
703 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
704 'O','R','D','E','R',' ', 'B','Y',' ',
705 '`','S','e','q','u','e','n','c','e','`',0 };
707 static const WCHAR IVQuery[] =
708 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
709 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
710 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
711 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
712 ' ','\'', 'I','n','s','t','a','l','l',
713 'V','a','l','i','d','a','t','e','\'', 0};
715 iterate_action_param iap;
717 iap.package = package;
720 if (package->script->ExecuteSequenceRun)
722 TRACE("Execute Sequence already Run\n");
723 return ERROR_SUCCESS;
726 package->script->ExecuteSequenceRun = TRUE;
728 /* get the sequence number */
731 row = MSI_QueryGetRecord(package->db, IVQuery);
733 return ERROR_FUNCTION_FAILED;
734 seq = MSI_RecordGetInteger(row,1);
735 msiobj_release(&row->hdr);
738 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
739 if (rc == ERROR_SUCCESS)
741 TRACE("Running the actions\n");
743 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
744 msiobj_release(&view->hdr);
750 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
754 static const WCHAR ExecSeqQuery [] =
755 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
756 '`','I','n','s','t','a','l','l',
757 'U','I','S','e','q','u','e','n','c','e','`',
758 ' ','W','H','E','R','E',' ',
759 '`','S','e','q','u','e','n','c','e','`',' ',
760 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
761 '`','S','e','q','u','e','n','c','e','`',0};
762 iterate_action_param iap;
764 iap.package = package;
767 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
769 if (rc == ERROR_SUCCESS)
771 TRACE("Running the actions \n");
773 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
774 msiobj_release(&view->hdr);
780 /********************************************************
781 * ACTION helper functions and functions that perform the actions
782 *******************************************************/
783 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
784 UINT* rc, BOOL force )
790 if (!run && !package->script->CurrentlyScripting)
795 if (strcmpW(action,szInstallFinalize) == 0 ||
796 strcmpW(action,szInstallExecute) == 0 ||
797 strcmpW(action,szInstallExecuteAgain) == 0)
802 while (StandardActions[i].action != NULL)
804 if (strcmpW(StandardActions[i].action, action)==0)
808 ui_actioninfo(package, action, TRUE, 0);
809 *rc = schedule_action(package,INSTALL_SCRIPT,action);
810 ui_actioninfo(package, action, FALSE, *rc);
814 ui_actionstart(package, action);
815 if (StandardActions[i].handler)
817 *rc = StandardActions[i].handler(package);
821 FIXME("unhandled standard action %s\n",debugstr_w(action));
833 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
834 UINT* rc, BOOL force )
839 arc = ACTION_CustomAction(package,action, force);
841 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
850 * A lot of actions are really important even if they don't do anything
851 * explicit... Lots of properties are set at the beginning of the installation
852 * CostFinalize does a bunch of work to translate the directories and such
854 * But until I get write access to the database that is hard, so I am going to
855 * hack it to see if I can get something to run.
857 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
859 UINT rc = ERROR_SUCCESS;
862 TRACE("Performing action (%s)\n",debugstr_w(action));
864 handled = ACTION_HandleStandardAction(package, action, &rc, force);
867 handled = ACTION_HandleCustomAction(package, action, &rc, force);
871 FIXME("unhandled msi action %s\n",debugstr_w(action));
872 rc = ERROR_FUNCTION_NOT_CALLED;
878 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
880 UINT rc = ERROR_SUCCESS;
881 BOOL handled = FALSE;
883 TRACE("Performing action (%s)\n",debugstr_w(action));
885 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
888 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
890 if( !handled && ACTION_DialogBox(package,action) == ERROR_SUCCESS )
895 FIXME("unhandled msi action %s\n",debugstr_w(action));
896 rc = ERROR_FUNCTION_NOT_CALLED;
904 * Actual Action Handlers
907 static UINT ITERATE_CreateFolders(MSIRECORD *row, LPVOID param)
909 MSIPACKAGE *package = (MSIPACKAGE*)param;
915 dir = MSI_RecordGetString(row,1);
918 ERR("Unable to get folder id \n");
919 return ERROR_SUCCESS;
922 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
925 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
926 return ERROR_SUCCESS;
929 TRACE("Folder is %s\n",debugstr_w(full_path));
932 uirow = MSI_CreateRecord(1);
933 MSI_RecordSetStringW(uirow,1,full_path);
934 ui_actiondata(package,szCreateFolders,uirow);
935 msiobj_release( &uirow->hdr );
937 if (folder->State == 0)
938 create_full_pathW(full_path);
942 HeapFree(GetProcessHeap(),0,full_path);
943 return ERROR_SUCCESS;
948 * Also we cannot enable/disable components either, so for now I am just going
949 * to do all the directories for all the components.
951 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
953 static const WCHAR ExecSeqQuery[] =
954 {'S','E','L','E','C','T',' ',
955 '`','D','i','r','e','c','t','o','r','y','_','`',
956 ' ','F','R','O','M',' ',
957 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
961 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
962 if (rc != ERROR_SUCCESS)
963 return ERROR_SUCCESS;
965 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateFolders, package);
966 msiobj_release(&view->hdr);
971 static MSICOMPONENT* load_component( MSIRECORD * row )
976 comp = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSICOMPONENT) );
980 /* fill in the data */
981 sz = IDENTIFIER_SIZE;
982 MSI_RecordGetStringW(row,1,comp->Component,&sz);
984 TRACE("Loading Component %s\n",
985 debugstr_w(comp->Component));
988 if (!MSI_RecordIsNull(row,2))
989 MSI_RecordGetStringW(row,2,comp->ComponentId,&sz);
991 sz = IDENTIFIER_SIZE;
992 MSI_RecordGetStringW(row,3,comp->Directory,&sz);
994 comp->Attributes = MSI_RecordGetInteger(row,4);
996 comp->Condition = load_dynamic_stringW( row, 5 );
998 sz = IDENTIFIER_SIZE;
999 MSI_RecordGetStringW(row,6,comp->KeyPath,&sz);
1001 comp->Installed = INSTALLSTATE_ABSENT;
1002 comp->Action = INSTALLSTATE_UNKNOWN;
1003 comp->ActionRequest = INSTALLSTATE_UNKNOWN;
1005 comp->Enabled = TRUE;
1011 MSIPACKAGE *package;
1012 MSIFEATURE *feature;
1015 static UINT add_feature_component( MSIFEATURE *feature, MSICOMPONENT *comp )
1019 cl = HeapAlloc( GetProcessHeap(), 0, sizeof (*cl) );
1021 return ERROR_NOT_ENOUGH_MEMORY;
1022 cl->component = comp;
1023 list_add_tail( &feature->Components, &cl->entry );
1025 return ERROR_SUCCESS;
1028 static UINT iterate_component_check( MSIRECORD *row, LPVOID param )
1030 _ilfs* ilfs= (_ilfs*)param;
1031 MSIPACKAGE *package = ilfs->package;
1032 MSIFEATURE *feature = ilfs->feature;
1035 comp = load_component( row );
1037 return ERROR_FUNCTION_FAILED;
1039 list_add_tail( &package->components, &comp->entry );
1040 add_feature_component( feature, comp );
1042 TRACE("Loaded new component %p\n", comp);
1044 return ERROR_SUCCESS;
1047 static UINT iterate_load_featurecomponents(MSIRECORD *row, LPVOID param)
1049 _ilfs* ilfs= (_ilfs*)param;
1054 static const WCHAR Query[] =
1055 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1056 '`','C','o','m','p','o','n','e','n','t','`',' ',
1057 'W','H','E','R','E',' ',
1058 '`','C','o','m','p','o','n','e','n','t','`',' ',
1059 '=','\'','%','s','\'',0};
1061 component = MSI_RecordGetString(row,1);
1063 /* check to see if the component is already loaded */
1064 comp = get_loaded_component( ilfs->package, component );
1067 TRACE("Component %s already loaded\n", debugstr_w(component) );
1068 add_feature_component( ilfs->feature, comp );
1069 return ERROR_SUCCESS;
1072 rc = MSI_OpenQuery(ilfs->package->db, &view, Query, component);
1073 if (rc != ERROR_SUCCESS)
1074 return ERROR_SUCCESS;
1076 rc = MSI_IterateRecords(view, NULL, iterate_component_check, ilfs);
1077 msiobj_release( &view->hdr );
1079 return ERROR_SUCCESS;
1082 static UINT load_feature(MSIRECORD * row, LPVOID param)
1084 MSIPACKAGE* package = (MSIPACKAGE*)param;
1085 MSIFEATURE* feature;
1087 static const WCHAR Query1[] =
1088 {'S','E','L','E','C','T',' ',
1089 '`','C','o','m','p','o','n','e','n','t','_','`',
1090 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1091 'C','o','m','p','o','n','e','n','t','s','`',' ',
1092 'W','H','E','R','E',' ',
1093 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1098 /* fill in the data */
1100 feature = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFEATURE) );
1102 return ERROR_NOT_ENOUGH_MEMORY;
1104 list_init( &feature->Components );
1106 sz = IDENTIFIER_SIZE;
1107 MSI_RecordGetStringW(row,1,feature->Feature,&sz);
1109 TRACE("Loading feature %s\n",debugstr_w(feature->Feature));
1111 sz = IDENTIFIER_SIZE;
1112 if (!MSI_RecordIsNull(row,2))
1113 MSI_RecordGetStringW(row,2,feature->Feature_Parent,&sz);
1116 if (!MSI_RecordIsNull(row,3))
1117 MSI_RecordGetStringW(row,3,feature->Title,&sz);
1120 if (!MSI_RecordIsNull(row,4))
1121 MSI_RecordGetStringW(row,4,feature->Description,&sz);
1123 if (!MSI_RecordIsNull(row,5))
1124 feature->Display = MSI_RecordGetInteger(row,5);
1126 feature->Level= MSI_RecordGetInteger(row,6);
1128 sz = IDENTIFIER_SIZE;
1129 if (!MSI_RecordIsNull(row,7))
1130 MSI_RecordGetStringW(row,7,feature->Directory,&sz);
1132 feature->Attributes = MSI_RecordGetInteger(row,8);
1134 feature->Installed = INSTALLSTATE_ABSENT;
1135 feature->Action = INSTALLSTATE_UNKNOWN;
1136 feature->ActionRequest = INSTALLSTATE_UNKNOWN;
1138 list_add_tail( &package->features, &feature->entry );
1140 /* load feature components */
1142 rc = MSI_OpenQuery( package->db, &view, Query1, feature->Feature );
1143 if (rc != ERROR_SUCCESS)
1144 return ERROR_SUCCESS;
1146 ilfs.package = package;
1147 ilfs.feature = feature;
1149 MSI_IterateRecords(view, NULL, iterate_load_featurecomponents , &ilfs);
1150 msiobj_release(&view->hdr);
1152 return ERROR_SUCCESS;
1155 static UINT load_file(MSIRECORD *row, LPVOID param)
1157 MSIPACKAGE* package = (MSIPACKAGE*)param;
1161 /* fill in the data */
1163 file = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFILE) );
1165 return ERROR_NOT_ENOUGH_MEMORY;
1167 file->File = load_dynamic_stringW( row, 1 );
1169 component = MSI_RecordGetString( row, 2 );
1170 file->Component = get_loaded_component( package, component );
1172 if (!file->Component)
1173 ERR("Unfound Component %s\n",debugstr_w(component));
1175 file->FileName = load_dynamic_stringW( row, 3 );
1176 reduce_to_longfilename( file->FileName );
1178 file->ShortName = load_dynamic_stringW( row, 3 );
1179 reduce_to_shortfilename( file->ShortName );
1181 file->FileSize = MSI_RecordGetInteger( row, 4 );
1182 file->Version = load_dynamic_stringW( row, 5 );
1183 file->Language = load_dynamic_stringW( row, 6 );
1184 file->Attributes = MSI_RecordGetInteger( row, 7 );
1185 file->Sequence = MSI_RecordGetInteger( row, 8 );
1189 TRACE("File Loaded (%s)\n",debugstr_w(file->File));
1191 list_add_tail( &package->files, &file->entry );
1193 return ERROR_SUCCESS;
1196 static UINT load_all_files(MSIPACKAGE *package)
1200 static const WCHAR Query[] =
1201 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1202 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1203 '`','S','e','q','u','e','n','c','e','`', 0};
1206 return ERROR_INVALID_HANDLE;
1208 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1209 if (rc != ERROR_SUCCESS)
1210 return ERROR_SUCCESS;
1212 rc = MSI_IterateRecords(view, NULL, load_file, package);
1213 msiobj_release(&view->hdr);
1215 return ERROR_SUCCESS;
1220 * I am not doing any of the costing functionality yet.
1221 * Mostly looking at doing the Component and Feature loading
1223 * The native MSI does A LOT of modification to tables here. Mostly adding
1224 * a lot of temporary columns to the Feature and Component tables.
1226 * note: Native msi also tracks the short filename. But I am only going to
1227 * track the long ones. Also looking at this directory table
1228 * it appears that the directory table does not get the parents
1229 * resolved base on property only based on their entries in the
1232 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1236 static const WCHAR Query_all[] =
1237 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1238 '`','F','e','a','t','u','r','e','`',0};
1239 static const WCHAR szCosting[] =
1240 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1241 static const WCHAR szZero[] = { '0', 0 };
1245 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1247 return ERROR_SUCCESS;
1249 MSI_SetPropertyW(package, szCosting, szZero);
1250 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1252 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1253 if (rc != ERROR_SUCCESS)
1256 rc = MSI_IterateRecords(view, NULL, load_feature, package);
1257 msiobj_release(&view->hdr);
1259 load_all_files(package);
1261 return ERROR_SUCCESS;
1264 static UINT execute_script(MSIPACKAGE *package, UINT script )
1267 UINT rc = ERROR_SUCCESS;
1269 TRACE("Executing Script %i\n",script);
1271 for (i = 0; i < package->script->ActionCount[script]; i++)
1274 action = package->script->Actions[script][i];
1275 ui_actionstart(package, action);
1276 TRACE("Executing Action (%s)\n",debugstr_w(action));
1277 rc = ACTION_PerformAction(package, action, TRUE);
1278 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1279 if (rc != ERROR_SUCCESS)
1282 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1284 package->script->ActionCount[script] = 0;
1285 package->script->Actions[script] = NULL;
1289 static UINT ACTION_FileCost(MSIPACKAGE *package)
1291 return ERROR_SUCCESS;
1295 static MSIFOLDER *load_folder( MSIPACKAGE *package, LPCWSTR dir )
1297 static const WCHAR Query[] =
1298 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1299 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1300 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1301 ' ','=',' ','\'','%','s','\'',
1303 LPWSTR ptargetdir, targetdir, srcdir;
1305 LPWSTR shortname = NULL;
1306 MSIRECORD * row = 0;
1309 TRACE("Looking for dir %s\n",debugstr_w(dir));
1311 folder = get_loaded_folder( package, dir );
1315 TRACE("Working to load %s\n",debugstr_w(dir));
1317 folder = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFOLDER) );
1321 folder->Directory = strdupW(dir);
1323 row = MSI_QueryGetRecord(package->db, Query, dir);
1327 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1329 /* split src and target dir */
1330 if (strchrW(targetdir,':'))
1332 srcdir=strchrW(targetdir,':');
1339 /* for now only pick long filename versions */
1340 if (strchrW(targetdir,'|'))
1342 shortname = targetdir;
1343 targetdir = strchrW(targetdir,'|');
1347 /* for the sourcedir pick the short filename */
1348 if (srcdir && strchrW(srcdir,'|'))
1350 LPWSTR p = strchrW(srcdir,'|');
1354 /* now check for root dirs */
1355 if (targetdir[0] == '.' && targetdir[1] == 0)
1360 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1361 HeapFree(GetProcessHeap(),0, folder->TargetDefault);
1362 folder->TargetDefault = strdupW(targetdir);
1366 folder->SourceDefault = strdupW(srcdir);
1368 folder->SourceDefault = strdupW(shortname);
1370 folder->SourceDefault = strdupW(targetdir);
1371 HeapFree(GetProcessHeap(), 0, ptargetdir);
1372 TRACE(" SourceDefault = %s\n", debugstr_w( folder->SourceDefault ));
1374 parent = MSI_RecordGetString(row,2);
1377 folder->Parent = load_folder( package, parent );
1378 if ( folder->Parent )
1379 TRACE("loaded parent %p %s\n", folder->Parent,
1380 debugstr_w(folder->Parent->Directory));
1382 ERR("failed to load parent folder %s\n", debugstr_w(parent));
1385 folder->Property = load_dynamic_property( package, dir, NULL );
1387 msiobj_release(&row->hdr);
1389 list_add_tail( &package->folders, &folder->entry );
1391 TRACE("%s returning %p\n",debugstr_w(dir),folder);
1396 /* scan for and update current install states */
1397 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
1400 MSIFEATURE *feature;
1402 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1405 res = MsiGetComponentPathW( package->ProductCode,
1406 comp->ComponentId, NULL, NULL);
1408 res = INSTALLSTATE_ABSENT;
1409 comp->Installed = res;
1412 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1415 INSTALLSTATE res = -10;
1417 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1419 comp= cl->component;
1422 res = comp->Installed;
1425 if (res == comp->Installed)
1428 if (res != comp->Installed)
1429 res = INSTALLSTATE_INCOMPLETE;
1432 feature->Installed = res;
1436 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
1439 static const WCHAR all[]={'A','L','L',0};
1440 LPWSTR override = NULL;
1442 MSIFEATURE *feature;
1444 override = load_dynamic_property(package, property, NULL);
1448 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1450 if (strcmpiW(override,all)==0)
1452 feature->ActionRequest= state;
1453 feature->Action = state;
1457 LPWSTR ptr = override;
1458 LPWSTR ptr2 = strchrW(override,',');
1463 strncmpW(ptr,feature->Feature, ptr2-ptr)==0)
1464 || (!ptr2 && strcmpW(ptr,feature->Feature)==0))
1466 feature->ActionRequest= state;
1467 feature->Action = state;
1473 ptr2 = strchrW(ptr,',');
1480 HeapFree(GetProcessHeap(),0,override);
1486 static UINT SetFeatureStates(MSIPACKAGE *package)
1490 static const WCHAR szlevel[] =
1491 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1492 static const WCHAR szAddLocal[] =
1493 {'A','D','D','L','O','C','A','L',0};
1494 static const WCHAR szRemove[] =
1495 {'R','E','M','O','V','E',0};
1496 BOOL override = FALSE;
1497 MSICOMPONENT* component;
1498 MSIFEATURE *feature;
1501 /* I do not know if this is where it should happen.. but */
1503 TRACE("Checking Install Level\n");
1505 level = load_dynamic_property(package,szlevel,NULL);
1508 install_level = atoiW(level);
1509 HeapFree(GetProcessHeap(), 0, level);
1514 /* ok hereis the _real_ rub
1515 * all these activation/deactivation things happen in order and things
1516 * later on the list override things earlier on the list.
1517 * 1) INSTALLLEVEL processing
1527 * 11) FILEADDDEFAULT
1528 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1529 * ignored for all the features. seems strange, especially since it is not
1530 * documented anywhere, but it is how it works.
1532 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1533 * REMOVE are the big ones, since we don't handle administrative installs
1536 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
1537 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
1541 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1543 BOOL feature_state = ((feature->Level > 0) &&
1544 (feature->Level <= install_level));
1546 if ((feature_state) && (feature->Action == INSTALLSTATE_UNKNOWN))
1548 if (feature->Attributes & msidbFeatureAttributesFavorSource)
1550 feature->ActionRequest = INSTALLSTATE_SOURCE;
1551 feature->Action = INSTALLSTATE_SOURCE;
1553 else if (feature->Attributes & msidbFeatureAttributesFavorAdvertise)
1555 feature->ActionRequest = INSTALLSTATE_ADVERTISED;
1556 feature->Action = INSTALLSTATE_ADVERTISED;
1560 feature->ActionRequest = INSTALLSTATE_LOCAL;
1561 feature->Action = INSTALLSTATE_LOCAL;
1568 /* set the Preselected Property */
1569 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1570 static const WCHAR szOne[] = { '1', 0 };
1572 MSI_SetPropertyW(package,szPreselected,szOne);
1576 * now we want to enable or disable components base on feature
1579 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1583 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1584 debugstr_w(feature->Feature), feature->Installed, feature->Action,
1585 feature->ActionRequest);
1587 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1589 component = cl->component;
1591 if (!component->Enabled)
1593 component->Action = INSTALLSTATE_UNKNOWN;
1594 component->ActionRequest = INSTALLSTATE_UNKNOWN;
1598 if (feature->Action == INSTALLSTATE_LOCAL)
1600 component->Action = INSTALLSTATE_LOCAL;
1601 component->ActionRequest = INSTALLSTATE_LOCAL;
1603 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
1605 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1606 (component->Action == INSTALLSTATE_ABSENT) ||
1607 (component->Action == INSTALLSTATE_ADVERTISED))
1610 component->Action = INSTALLSTATE_SOURCE;
1611 component->ActionRequest = INSTALLSTATE_SOURCE;
1614 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
1616 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1617 (component->Action == INSTALLSTATE_ABSENT))
1620 component->Action = INSTALLSTATE_ADVERTISED;
1621 component->ActionRequest = INSTALLSTATE_ADVERTISED;
1624 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
1626 if (component->Action == INSTALLSTATE_UNKNOWN)
1628 component->Action = INSTALLSTATE_ABSENT;
1629 component->ActionRequest = INSTALLSTATE_ABSENT;
1636 LIST_FOR_EACH_ENTRY( component, &package->components, MSICOMPONENT, entry )
1638 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1639 debugstr_w(component->Component), component->Installed,
1640 component->Action, component->ActionRequest);
1644 return ERROR_SUCCESS;
1647 static UINT ITERATE_CostFinalizeDirectories(MSIRECORD *row, LPVOID param)
1649 MSIPACKAGE *package = (MSIPACKAGE*)param;
1653 name = MSI_RecordGetString(row,1);
1655 /* This helper function now does ALL the work */
1656 TRACE("Dir %s ...\n",debugstr_w(name));
1657 load_folder(package,name);
1658 path = resolve_folder(package,name,FALSE,TRUE,NULL);
1659 TRACE("resolves to %s\n",debugstr_w(path));
1660 HeapFree( GetProcessHeap(), 0, path);
1662 return ERROR_SUCCESS;
1665 static UINT ITERATE_CostFinalizeConditions(MSIRECORD *row, LPVOID param)
1667 MSIPACKAGE *package = (MSIPACKAGE*)param;
1669 MSIFEATURE *feature;
1671 name = MSI_RecordGetString( row, 1 );
1673 feature = get_loaded_feature( package, name );
1675 ERR("FAILED to find loaded feature %s\n",debugstr_w(name));
1679 Condition = MSI_RecordGetString(row,3);
1681 if (MSI_EvaluateConditionW(package,Condition) == MSICONDITION_TRUE)
1683 int level = MSI_RecordGetInteger(row,2);
1684 TRACE("Reseting feature %s to level %i\n", debugstr_w(name), level);
1685 feature->Level = level;
1688 return ERROR_SUCCESS;
1693 * A lot is done in this function aside from just the costing.
1694 * The costing needs to be implemented at some point but for now I am going
1695 * to focus on the directory building
1698 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
1700 static const WCHAR ExecSeqQuery[] =
1701 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1702 '`','D','i','r','e','c','t','o','r','y','`',0};
1703 static const WCHAR ConditionQuery[] =
1704 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1705 '`','C','o','n','d','i','t','i','o','n','`',0};
1706 static const WCHAR szCosting[] =
1707 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1708 static const WCHAR szlevel[] =
1709 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1710 static const WCHAR szOne[] = { '1', 0 };
1719 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1721 return ERROR_SUCCESS;
1723 TRACE("Building Directory properties\n");
1725 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1726 if (rc == ERROR_SUCCESS)
1728 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeDirectories,
1730 msiobj_release(&view->hdr);
1733 TRACE("File calculations\n");
1735 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
1737 MSICOMPONENT* comp = NULL;
1739 comp = file->Component;
1745 /* calculate target */
1746 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
1748 HeapFree(GetProcessHeap(),0,file->TargetPath);
1750 TRACE("file %s is named %s\n",
1751 debugstr_w(file->File),debugstr_w(file->FileName));
1753 file->TargetPath = build_directory_name(2, p, file->FileName);
1755 HeapFree(GetProcessHeap(),0,p);
1757 TRACE("file %s resolves to %s\n",
1758 debugstr_w(file->File),debugstr_w(file->TargetPath));
1760 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
1763 comp->Cost += file->FileSize;
1773 static const WCHAR name[] =
1775 static const WCHAR name_fmt[] =
1776 {'%','u','.','%','u','.','%','u','.','%','u',0};
1777 WCHAR filever[0x100];
1778 VS_FIXEDFILEINFO *lpVer;
1780 TRACE("Version comparison.. \n");
1781 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
1782 version = HeapAlloc(GetProcessHeap(),0,versize);
1783 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
1785 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
1787 sprintfW(filever,name_fmt,
1788 HIWORD(lpVer->dwFileVersionMS),
1789 LOWORD(lpVer->dwFileVersionMS),
1790 HIWORD(lpVer->dwFileVersionLS),
1791 LOWORD(lpVer->dwFileVersionLS));
1793 TRACE("new %s old %s\n", debugstr_w(file->Version),
1794 debugstr_w(filever));
1795 if (strcmpiW(filever,file->Version)<0)
1798 FIXME("cost should be diff in size\n");
1799 comp->Cost += file->FileSize;
1803 HeapFree(GetProcessHeap(),0,version);
1811 TRACE("Evaluating Condition Table\n");
1813 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
1814 if (rc == ERROR_SUCCESS)
1816 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeConditions,
1818 msiobj_release(&view->hdr);
1821 TRACE("Enabling or Disabling Components\n");
1822 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1824 if (comp->Condition)
1826 if (MSI_EvaluateConditionW(package,
1827 comp->Condition) == MSICONDITION_FALSE)
1829 TRACE("Disabling component %s\n", debugstr_w(comp->Component));
1830 comp->Enabled = FALSE;
1835 MSI_SetPropertyW(package,szCosting,szOne);
1836 /* set default run level if not set */
1837 level = load_dynamic_property(package,szlevel,NULL);
1839 MSI_SetPropertyW(package,szlevel, szOne);
1841 HeapFree(GetProcessHeap(),0,level);
1843 ACTION_UpdateInstallStates(package);
1845 return SetFeatureStates(package);
1848 /* OK this value is "interpreted" and then formatted based on the
1849 first few characters */
1850 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
1854 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
1860 LPWSTR deformated = NULL;
1863 deformat_string(package, &value[2], &deformated);
1865 /* binary value type */
1869 *size = (strlenW(ptr)/2)+1;
1871 *size = strlenW(ptr)/2;
1873 data = HeapAlloc(GetProcessHeap(),0,*size);
1879 /* if uneven pad with a zero in front */
1885 data[count] = (BYTE)strtol(byte,NULL,0);
1887 TRACE("Uneven byte count\n");
1895 data[count] = (BYTE)strtol(byte,NULL,0);
1898 HeapFree(GetProcessHeap(),0,deformated);
1900 TRACE("Data %li bytes(%i)\n",*size,count);
1907 deformat_string(package, &value[1], &deformated);
1910 *size = sizeof(DWORD);
1911 data = HeapAlloc(GetProcessHeap(),0,*size);
1917 if ( (*p < '0') || (*p > '9') )
1923 if (deformated[0] == '-')
1926 TRACE("DWORD %li\n",*(LPDWORD)data);
1928 HeapFree(GetProcessHeap(),0,deformated);
1933 static const WCHAR szMulti[] = {'[','~',']',0};
1942 *type=REG_EXPAND_SZ;
1950 if (strstrW(value,szMulti))
1951 *type = REG_MULTI_SZ;
1953 *size = deformat_string(package, ptr,(LPWSTR*)&data);
1958 static UINT ITERATE_WriteRegistryValues(MSIRECORD *row, LPVOID param)
1960 MSIPACKAGE *package = (MSIPACKAGE*)param;
1961 static const WCHAR szHCR[] =
1962 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1963 'R','O','O','T','\\',0};
1964 static const WCHAR szHCU[] =
1965 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1966 'U','S','E','R','\\',0};
1967 static const WCHAR szHLM[] =
1968 {'H','K','E','Y','_','L','O','C','A','L','_',
1969 'M','A','C','H','I','N','E','\\',0};
1970 static const WCHAR szHU[] =
1971 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1973 LPSTR value_data = NULL;
1974 HKEY root_key, hkey;
1977 LPCWSTR szRoot, component, name, key, value;
1982 BOOL check_first = FALSE;
1985 ui_progress(package,2,0,0,0);
1992 component = MSI_RecordGetString(row, 6);
1993 comp = get_loaded_component(package,component);
1995 return ERROR_SUCCESS;
1997 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
1999 TRACE("Skipping write due to disabled component %s\n",
2000 debugstr_w(component));
2002 comp->Action = comp->Installed;
2004 return ERROR_SUCCESS;
2007 comp->Action = INSTALLSTATE_LOCAL;
2009 name = MSI_RecordGetString(row, 4);
2010 if( MSI_RecordIsNull(row,5) && name )
2012 /* null values can have special meanings */
2013 if (name[0]=='-' && name[1] == 0)
2014 return ERROR_SUCCESS;
2015 else if ((name[0]=='+' && name[1] == 0) ||
2016 (name[0] == '*' && name[1] == 0))
2021 root = MSI_RecordGetInteger(row,2);
2022 key = MSI_RecordGetString(row, 3);
2024 /* get the root key */
2029 static const WCHAR szALLUSER[] = {'A','L','L','U','S','E','R','S',0};
2030 LPWSTR all_users = load_dynamic_property(package, szALLUSER, NULL);
2031 if (all_users && all_users[0] == '1')
2033 root_key = HKEY_LOCAL_MACHINE;
2038 root_key = HKEY_CURRENT_USER;
2041 HeapFree(GetProcessHeap(),0,all_users);
2044 case 0: root_key = HKEY_CLASSES_ROOT;
2047 case 1: root_key = HKEY_CURRENT_USER;
2050 case 2: root_key = HKEY_LOCAL_MACHINE;
2053 case 3: root_key = HKEY_USERS;
2057 ERR("Unknown root %i\n",root);
2063 return ERROR_SUCCESS;
2065 deformat_string(package, key , &deformated);
2066 size = strlenW(deformated) + strlenW(szRoot) + 1;
2067 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
2068 strcpyW(uikey,szRoot);
2069 strcatW(uikey,deformated);
2071 if (RegCreateKeyW( root_key, deformated, &hkey))
2073 ERR("Could not create key %s\n",debugstr_w(deformated));
2074 HeapFree(GetProcessHeap(),0,deformated);
2075 HeapFree(GetProcessHeap(),0,uikey);
2076 return ERROR_SUCCESS;
2078 HeapFree(GetProcessHeap(),0,deformated);
2080 value = MSI_RecordGetString(row,5);
2082 value_data = parse_value(package, value, &type, &size);
2085 static const WCHAR szEmpty[] = {0};
2086 value_data = (LPSTR)strdupW(szEmpty);
2091 deformat_string(package, name, &deformated);
2093 /* get the double nulls to terminate SZ_MULTI */
2094 if (type == REG_MULTI_SZ)
2095 size +=sizeof(WCHAR);
2099 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
2101 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE)value_data, size);
2106 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
2107 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2109 TRACE("value %s of %s checked already exists\n",
2110 debugstr_w(deformated), debugstr_w(uikey));
2114 TRACE("Checked and setting value %s of %s\n",
2115 debugstr_w(deformated), debugstr_w(uikey));
2116 if (deformated || size)
2117 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE) value_data, size);
2122 uirow = MSI_CreateRecord(3);
2123 MSI_RecordSetStringW(uirow,2,deformated);
2124 MSI_RecordSetStringW(uirow,1,uikey);
2127 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2129 MSI_RecordSetStringW(uirow,3,value);
2131 ui_actiondata(package,szWriteRegistryValues,uirow);
2132 msiobj_release( &uirow->hdr );
2134 HeapFree(GetProcessHeap(),0,value_data);
2135 HeapFree(GetProcessHeap(),0,deformated);
2136 HeapFree(GetProcessHeap(),0,uikey);
2138 return ERROR_SUCCESS;
2141 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2145 static const WCHAR ExecSeqQuery[] =
2146 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2147 '`','R','e','g','i','s','t','r','y','`',0 };
2150 return ERROR_INVALID_HANDLE;
2152 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2153 if (rc != ERROR_SUCCESS)
2154 return ERROR_SUCCESS;
2156 /* increment progress bar each time action data is sent */
2157 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
2159 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteRegistryValues, package);
2161 msiobj_release(&view->hdr);
2165 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
2167 package->script->CurrentlyScripting = TRUE;
2169 return ERROR_SUCCESS;
2173 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
2178 static const WCHAR q1[]=
2179 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2180 '`','R','e','g','i','s','t','r','y','`',0};
2183 MSIRECORD * row = 0;
2184 MSIFEATURE *feature;
2187 TRACE(" InstallValidate \n");
2189 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
2190 if (rc != ERROR_SUCCESS)
2191 return ERROR_SUCCESS;
2193 rc = MSI_ViewExecute(view, 0);
2194 if (rc != ERROR_SUCCESS)
2196 MSI_ViewClose(view);
2197 msiobj_release(&view->hdr);
2202 rc = MSI_ViewFetch(view,&row);
2203 if (rc != ERROR_SUCCESS)
2210 msiobj_release(&row->hdr);
2212 MSI_ViewClose(view);
2213 msiobj_release(&view->hdr);
2215 total = total + progress * REG_PROGRESS_VALUE;
2216 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2218 total += COMPONENT_PROGRESS_VALUE;
2220 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2222 total += file->FileSize;
2224 ui_progress(package,0,total,0,0);
2226 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2228 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2229 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2230 feature->ActionRequest);
2233 return ERROR_SUCCESS;
2236 static UINT ITERATE_LaunchConditions(MSIRECORD *row, LPVOID param)
2238 MSIPACKAGE* package = (MSIPACKAGE*)param;
2239 LPCWSTR cond = NULL;
2240 LPCWSTR message = NULL;
2241 static const WCHAR title[]=
2242 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2244 cond = MSI_RecordGetString(row,1);
2246 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
2249 message = MSI_RecordGetString(row,2);
2250 deformat_string(package,message,&deformated);
2251 MessageBoxW(NULL,deformated,title,MB_OK);
2252 HeapFree(GetProcessHeap(),0,deformated);
2253 return ERROR_FUNCTION_FAILED;
2256 return ERROR_SUCCESS;
2259 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
2262 MSIQUERY * view = NULL;
2263 static const WCHAR ExecSeqQuery[] =
2264 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2265 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2267 TRACE("Checking launch conditions\n");
2269 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2270 if (rc != ERROR_SUCCESS)
2271 return ERROR_SUCCESS;
2273 rc = MSI_IterateRecords(view, NULL, ITERATE_LaunchConditions, package);
2274 msiobj_release(&view->hdr);
2279 static LPWSTR resolve_keypath( MSIPACKAGE* package, MSICOMPONENT *cmp )
2282 if (cmp->KeyPath[0]==0)
2284 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
2287 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
2289 MSIRECORD * row = 0;
2291 LPWSTR deformated,buffer,deformated_name;
2293 static const WCHAR ExecSeqQuery[] =
2294 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2295 '`','R','e','g','i','s','t','r','y','`',' ',
2296 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2297 ' ','=',' ' ,'\'','%','s','\'',0 };
2298 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
2299 static const WCHAR fmt2[]=
2300 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2302 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
2306 root = MSI_RecordGetInteger(row,2);
2307 key = MSI_RecordGetString(row, 3);
2308 name = MSI_RecordGetString(row, 4);
2309 deformat_string(package, key , &deformated);
2310 deformat_string(package, name, &deformated_name);
2312 len = strlenW(deformated) + 6;
2313 if (deformated_name)
2314 len+=strlenW(deformated_name);
2316 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
2318 if (deformated_name)
2319 sprintfW(buffer,fmt2,root,deformated,deformated_name);
2321 sprintfW(buffer,fmt,root,deformated);
2323 HeapFree(GetProcessHeap(),0,deformated);
2324 HeapFree(GetProcessHeap(),0,deformated_name);
2325 msiobj_release(&row->hdr);
2329 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
2331 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2336 MSIFILE *file = get_loaded_file( package, cmp->KeyPath );
2339 return strdupW( file->TargetPath );
2344 static HKEY openSharedDLLsKey(void)
2347 static const WCHAR path[] =
2348 {'S','o','f','t','w','a','r','e','\\',
2349 'M','i','c','r','o','s','o','f','t','\\',
2350 'W','i','n','d','o','w','s','\\',
2351 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2352 'S','h','a','r','e','d','D','L','L','s',0};
2354 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
2358 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
2363 DWORD sz = sizeof(count);
2366 hkey = openSharedDLLsKey();
2367 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
2368 if (rc != ERROR_SUCCESS)
2374 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
2378 hkey = openSharedDLLsKey();
2380 RegSetValueExW(hkey,path,0,REG_DWORD,
2381 (LPBYTE)&count,sizeof(count));
2383 RegDeleteValueW(hkey,path);
2389 * Return TRUE if the count should be written out and FALSE if not
2391 static void ACTION_RefCountComponent( MSIPACKAGE* package, MSICOMPONENT *comp )
2393 MSIFEATURE *feature;
2397 /* only refcount DLLs */
2398 if (comp->KeyPath[0]==0 ||
2399 comp->Attributes & msidbComponentAttributesRegistryKeyPath ||
2400 comp->Attributes & msidbComponentAttributesODBCDataSource)
2404 count = ACTION_GetSharedDLLsCount( comp->FullKeypath);
2405 write = (count > 0);
2407 if (comp->Attributes & msidbComponentAttributesSharedDllRefCount)
2411 /* increment counts */
2412 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2416 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ))
2419 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2421 if ( cl->component == comp )
2426 /* decrement counts */
2427 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2431 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ABSENT ))
2434 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2436 if ( cl->component == comp )
2441 /* ref count all the files in the component */
2446 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2448 if (file->Component == comp)
2449 ACTION_WriteSharedDLLsCount( file->TargetPath, count );
2453 /* add a count for permenent */
2454 if (comp->Attributes & msidbComponentAttributesPermanent)
2457 comp->RefCount = count;
2460 ACTION_WriteSharedDLLsCount( comp->FullKeypath, comp->RefCount );
2464 * Ok further analysis makes me think that this work is
2465 * actually done in the PublishComponents and PublishFeatures
2466 * step, and not here. It appears like the keypath and all that is
2467 * resolved in this step, however actually written in the Publish steps.
2468 * But we will leave it here for now because it is unclear
2470 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
2472 WCHAR squished_pc[GUID_SIZE];
2473 WCHAR squished_cc[GUID_SIZE];
2476 HKEY hkey=0,hkey2=0;
2479 return ERROR_INVALID_HANDLE;
2481 /* writes the Component and Features values to the registry */
2483 rc = MSIREG_OpenComponents(&hkey);
2484 if (rc != ERROR_SUCCESS)
2487 squash_guid(package->ProductCode,squished_pc);
2488 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
2490 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2492 ui_progress(package,2,0,0,0);
2493 if (comp->ComponentId[0]!=0)
2495 WCHAR *keypath = NULL;
2498 squash_guid(comp->ComponentId,squished_cc);
2500 keypath = resolve_keypath( package, comp );
2501 comp->FullKeypath = keypath;
2503 /* do the refcounting */
2504 ACTION_RefCountComponent( package, comp );
2506 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2507 debugstr_w(comp->Component),
2508 debugstr_w(squished_cc),
2509 debugstr_w(comp->FullKeypath),
2512 * Write the keypath out if the component is to be registered
2513 * and delete the key if the component is to be deregistered
2515 if (ACTION_VerifyComponentForAction(package, comp,
2516 INSTALLSTATE_LOCAL))
2518 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
2519 if (rc != ERROR_SUCCESS)
2524 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPBYTE)keypath,
2525 (strlenW(keypath)+1)*sizeof(WCHAR));
2527 if (comp->Attributes & msidbComponentAttributesPermanent)
2529 static const WCHAR szPermKey[] =
2530 { '0','0','0','0','0','0','0','0','0','0','0','0',
2531 '0','0','0','0','0','0','0', '0','0','0','0','0',
2532 '0','0','0','0','0','0','0','0',0};
2534 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
2536 (strlenW(keypath)+1)*sizeof(WCHAR));
2542 uirow = MSI_CreateRecord(3);
2543 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2544 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2545 MSI_RecordSetStringW(uirow,3,keypath);
2546 ui_actiondata(package,szProcessComponents,uirow);
2547 msiobj_release( &uirow->hdr );
2550 else if (ACTION_VerifyComponentForAction(package, comp,
2551 INSTALLSTATE_ABSENT))
2555 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
2556 if (rc != ERROR_SUCCESS)
2559 RegDeleteValueW(hkey2,squished_pc);
2561 /* if the key is empty delete it */
2562 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
2564 if (res == ERROR_NO_MORE_ITEMS)
2565 RegDeleteKeyW(hkey,squished_cc);
2568 uirow = MSI_CreateRecord(2);
2569 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2570 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2571 ui_actiondata(package,szProcessComponents,uirow);
2572 msiobj_release( &uirow->hdr );
2589 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
2590 LPWSTR lpszName, LONG_PTR lParam)
2593 typelib_struct *tl_struct = (typelib_struct*) lParam;
2594 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
2598 if (!IS_INTRESOURCE(lpszName))
2600 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
2604 sz = strlenW(tl_struct->source)+4;
2605 sz *= sizeof(WCHAR);
2607 if ((INT)lpszName == 1)
2608 tl_struct->path = strdupW(tl_struct->source);
2611 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
2612 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
2615 TRACE("trying %s\n", debugstr_w(tl_struct->path));
2616 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
2617 if (!SUCCEEDED(res))
2619 HeapFree(GetProcessHeap(),0,tl_struct->path);
2620 tl_struct->path = NULL;
2625 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
2626 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
2628 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2632 HeapFree(GetProcessHeap(),0,tl_struct->path);
2633 tl_struct->path = NULL;
2635 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2636 ITypeLib_Release(tl_struct->ptLib);
2641 static UINT ITERATE_RegisterTypeLibraries(MSIRECORD *row, LPVOID param)
2643 MSIPACKAGE* package = (MSIPACKAGE*)param;
2647 typelib_struct tl_struct;
2649 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
2651 component = MSI_RecordGetString(row,3);
2652 comp = get_loaded_component(package,component);
2654 return ERROR_SUCCESS;
2656 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2658 TRACE("Skipping typelib reg due to disabled component\n");
2660 comp->Action = comp->Installed;
2662 return ERROR_SUCCESS;
2665 comp->Action = INSTALLSTATE_LOCAL;
2667 file = get_loaded_file( package, comp->KeyPath );
2669 return ERROR_SUCCESS;
2671 module = LoadLibraryExW( file->TargetPath, NULL, LOAD_LIBRARY_AS_DATAFILE );
2675 guid = load_dynamic_stringW(row,1);
2676 CLSIDFromString(guid, &tl_struct.clsid);
2677 HeapFree(GetProcessHeap(),0,guid);
2678 tl_struct.source = strdupW( file->TargetPath );
2679 tl_struct.path = NULL;
2681 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
2682 (LONG_PTR)&tl_struct);
2684 if (tl_struct.path != NULL)
2690 helpid = MSI_RecordGetString(row,6);
2693 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
2694 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
2695 HeapFree(GetProcessHeap(),0,help);
2697 if (!SUCCEEDED(res))
2698 ERR("Failed to register type library %s\n",
2699 debugstr_w(tl_struct.path));
2702 ui_actiondata(package,szRegisterTypeLibraries,row);
2704 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
2707 ITypeLib_Release(tl_struct.ptLib);
2708 HeapFree(GetProcessHeap(),0,tl_struct.path);
2711 ERR("Failed to load type library %s\n",
2712 debugstr_w(tl_struct.source));
2714 FreeLibrary(module);
2715 HeapFree(GetProcessHeap(),0,tl_struct.source);
2718 ERR("Could not load file! %s\n", debugstr_w(file->TargetPath));
2720 return ERROR_SUCCESS;
2723 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
2726 * OK this is a bit confusing.. I am given a _Component key and I believe
2727 * that the file that is being registered as a type library is the "key file
2728 * of that component" which I interpret to mean "The file in the KeyPath of
2733 static const WCHAR Query[] =
2734 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2735 '`','T','y','p','e','L','i','b','`',0};
2738 return ERROR_INVALID_HANDLE;
2740 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2741 if (rc != ERROR_SUCCESS)
2742 return ERROR_SUCCESS;
2744 rc = MSI_IterateRecords(view, NULL, ITERATE_RegisterTypeLibraries, package);
2745 msiobj_release(&view->hdr);
2749 static UINT ITERATE_CreateShortcuts(MSIRECORD *row, LPVOID param)
2751 MSIPACKAGE *package = (MSIPACKAGE*)param;
2752 LPWSTR target_file, target_folder;
2754 WCHAR filename[0x100];
2757 static const WCHAR szlnk[]={'.','l','n','k',0};
2762 buffer = MSI_RecordGetString(row,4);
2763 comp = get_loaded_component(package,buffer);
2765 return ERROR_SUCCESS;
2767 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2769 TRACE("Skipping shortcut creation due to disabled component\n");
2771 comp->Action = comp->Installed;
2773 return ERROR_SUCCESS;
2776 comp->Action = INSTALLSTATE_LOCAL;
2778 ui_actiondata(package,szCreateShortcuts,row);
2780 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2781 &IID_IShellLinkW, (LPVOID *) &sl );
2785 ERR("Is IID_IShellLink\n");
2786 return ERROR_SUCCESS;
2789 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
2792 ERR("Is IID_IPersistFile\n");
2793 return ERROR_SUCCESS;
2796 buffer = MSI_RecordGetString(row,2);
2797 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
2799 /* may be needed because of a bug somehwere else */
2800 create_full_pathW(target_folder);
2803 MSI_RecordGetStringW(row,3,filename,&sz);
2804 reduce_to_longfilename(filename);
2805 if (!strchrW(filename,'.') || strcmpiW(strchrW(filename,'.'),szlnk))
2806 strcatW(filename,szlnk);
2807 target_file = build_directory_name(2, target_folder, filename);
2808 HeapFree(GetProcessHeap(),0,target_folder);
2810 buffer = MSI_RecordGetString(row,5);
2811 if (strchrW(buffer,'['))
2814 deformat_string(package,buffer,&deformated);
2815 IShellLinkW_SetPath(sl,deformated);
2816 HeapFree(GetProcessHeap(),0,deformated);
2821 FIXME("poorly handled shortcut format, advertised shortcut\n");
2822 keypath = strdupW( comp->FullKeypath );
2823 IShellLinkW_SetPath(sl,keypath);
2824 HeapFree(GetProcessHeap(),0,keypath);
2827 if (!MSI_RecordIsNull(row,6))
2830 buffer = MSI_RecordGetString(row,6);
2831 deformat_string(package,buffer,&deformated);
2832 IShellLinkW_SetArguments(sl,deformated);
2833 HeapFree(GetProcessHeap(),0,deformated);
2836 if (!MSI_RecordIsNull(row,7))
2838 buffer = MSI_RecordGetString(row,7);
2839 IShellLinkW_SetDescription(sl,buffer);
2842 if (!MSI_RecordIsNull(row,8))
2843 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
2845 if (!MSI_RecordIsNull(row,9))
2850 buffer = MSI_RecordGetString(row,9);
2852 build_icon_path(package,buffer,&Path);
2853 index = MSI_RecordGetInteger(row,10);
2855 IShellLinkW_SetIconLocation(sl,Path,index);
2856 HeapFree(GetProcessHeap(),0,Path);
2859 if (!MSI_RecordIsNull(row,11))
2860 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
2862 if (!MSI_RecordIsNull(row,12))
2865 buffer = MSI_RecordGetString(row,12);
2866 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
2867 IShellLinkW_SetWorkingDirectory(sl,Path);
2868 HeapFree(GetProcessHeap(), 0, Path);
2871 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
2872 IPersistFile_Save(pf,target_file,FALSE);
2874 HeapFree(GetProcessHeap(),0,target_file);
2876 IPersistFile_Release( pf );
2877 IShellLinkW_Release( sl );
2879 return ERROR_SUCCESS;
2882 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
2887 static const WCHAR Query[] =
2888 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2889 '`','S','h','o','r','t','c','u','t','`',0};
2892 return ERROR_INVALID_HANDLE;
2894 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2895 if (rc != ERROR_SUCCESS)
2896 return ERROR_SUCCESS;
2898 res = CoInitialize( NULL );
2901 ERR("CoInitialize failed\n");
2902 return ERROR_FUNCTION_FAILED;
2905 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateShortcuts, package);
2906 msiobj_release(&view->hdr);
2913 static UINT ITERATE_PublishProduct(MSIRECORD *row, LPVOID param)
2915 MSIPACKAGE* package = (MSIPACKAGE*)param;
2917 LPWSTR FilePath=NULL;
2918 LPCWSTR FileName=NULL;
2923 FileName = MSI_RecordGetString(row,1);
2926 ERR("Unable to get FileName\n");
2927 return ERROR_SUCCESS;
2930 build_icon_path(package,FileName,&FilePath);
2932 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
2934 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2935 FILE_ATTRIBUTE_NORMAL, NULL);
2937 if (the_file == INVALID_HANDLE_VALUE)
2939 ERR("Unable to create file %s\n",debugstr_w(FilePath));
2940 HeapFree(GetProcessHeap(),0,FilePath);
2941 return ERROR_SUCCESS;
2948 rc = MSI_RecordReadStream(row,2,buffer,&sz);
2949 if (rc != ERROR_SUCCESS)
2951 ERR("Failed to get stream\n");
2952 CloseHandle(the_file);
2953 DeleteFileW(FilePath);
2956 WriteFile(the_file,buffer,sz,&write,NULL);
2957 } while (sz == 1024);
2959 HeapFree(GetProcessHeap(),0,FilePath);
2961 CloseHandle(the_file);
2962 return ERROR_SUCCESS;
2966 * 99% of the work done here is only done for
2967 * advertised installs. However this is where the
2968 * Icon table is processed and written out
2969 * so that is what I am going to do here.
2971 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
2975 static const WCHAR Query[]=
2976 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2977 '`','I','c','o','n','`',0};
2978 /* for registry stuff */
2981 static const WCHAR szProductLanguage[] =
2982 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
2983 static const WCHAR szARPProductIcon[] =
2984 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
2985 static const WCHAR szProductVersion[] =
2986 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
2990 MSIHANDLE hDb, hSumInfo;
2993 return ERROR_INVALID_HANDLE;
2995 /* write out icon files */
2997 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2998 if (rc == ERROR_SUCCESS)
3000 MSI_IterateRecords(view, NULL, ITERATE_PublishProduct, package);
3001 msiobj_release(&view->hdr);
3004 /* ok there is a lot more done here but i need to figure out what */
3006 rc = MSIREG_OpenProductsKey(package->ProductCode,&hkey,TRUE);
3007 if (rc != ERROR_SUCCESS)
3010 rc = MSIREG_OpenUserProductsKey(package->ProductCode,&hukey,TRUE);
3011 if (rc != ERROR_SUCCESS)
3015 buffer = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTNAMEW,NULL);
3016 size = strlenW(buffer)*sizeof(WCHAR);
3017 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTNAMEW,0,REG_SZ,
3018 (LPBYTE)buffer,size);
3019 HeapFree(GetProcessHeap(),0,buffer);
3021 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3022 size = sizeof(DWORD);
3023 langid = atoiW(buffer);
3024 RegSetValueExW(hukey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3025 (LPBYTE)&langid,size);
3026 HeapFree(GetProcessHeap(),0,buffer);
3028 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
3032 build_icon_path(package,buffer,&path);
3033 size = strlenW(path) * sizeof(WCHAR);
3034 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTICONW,0,REG_SZ,
3037 HeapFree(GetProcessHeap(),0,buffer);
3039 buffer = load_dynamic_property(package,szProductVersion,NULL);
3042 DWORD verdword = build_version_dword(buffer);
3043 size = sizeof(DWORD);
3044 RegSetValueExW(hukey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD, (LPBYTE
3047 HeapFree(GetProcessHeap(),0,buffer);
3049 FIXME("Need to write more keys to the user registry\n");
3051 hDb= alloc_msihandle( &package->db->hdr );
3052 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
3053 MsiCloseHandle(hDb);
3054 if (rc == ERROR_SUCCESS)
3056 WCHAR guidbuffer[0x200];
3058 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
3060 if (rc == ERROR_SUCCESS)
3062 WCHAR squashed[GUID_SIZE];
3063 /* for now we only care about the first guid */
3064 LPWSTR ptr = strchrW(guidbuffer,';');
3066 squash_guid(guidbuffer,squashed);
3067 size = strlenW(squashed)*sizeof(WCHAR);
3068 RegSetValueExW(hukey,INSTALLPROPERTY_PACKAGECODEW,0,REG_SZ,
3069 (LPBYTE)squashed, size);
3073 ERR("Unable to query Revision_Number... \n");
3076 MsiCloseHandle(hSumInfo);
3080 ERR("Unable to open Summary Information\n");
3092 static UINT ITERATE_WriteIniValues(MSIRECORD *row, LPVOID param)
3094 MSIPACKAGE *package = (MSIPACKAGE*)param;
3095 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
3096 LPWSTR deformated_section, deformated_key, deformated_value;
3097 LPWSTR folder, fullname = NULL;
3101 static const WCHAR szWindowsFolder[] =
3102 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3104 component = MSI_RecordGetString(row, 8);
3105 comp = get_loaded_component(package,component);
3107 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
3109 TRACE("Skipping ini file due to disabled component %s\n",
3110 debugstr_w(component));
3112 comp->Action = comp->Installed;
3114 return ERROR_SUCCESS;
3117 comp->Action = INSTALLSTATE_LOCAL;
3119 identifier = MSI_RecordGetString(row,1);
3120 filename = MSI_RecordGetString(row,2);
3121 dirproperty = MSI_RecordGetString(row,3);
3122 section = MSI_RecordGetString(row,4);
3123 key = MSI_RecordGetString(row,5);
3124 value = MSI_RecordGetString(row,6);
3125 action = MSI_RecordGetInteger(row,7);
3127 deformat_string(package,section,&deformated_section);
3128 deformat_string(package,key,&deformated_key);
3129 deformat_string(package,value,&deformated_value);
3133 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
3135 folder = load_dynamic_property(package,dirproperty,NULL);
3138 folder = load_dynamic_property(package, szWindowsFolder, NULL);
3142 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
3146 fullname = build_directory_name(2, folder, filename);
3150 TRACE("Adding value %s to section %s in %s\n",
3151 debugstr_w(deformated_key), debugstr_w(deformated_section),
3152 debugstr_w(fullname));
3153 WritePrivateProfileStringW(deformated_section, deformated_key,
3154 deformated_value, fullname);
3156 else if (action == 1)
3159 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
3160 returned, 10, fullname);
3161 if (returned[0] == 0)
3163 TRACE("Adding value %s to section %s in %s\n",
3164 debugstr_w(deformated_key), debugstr_w(deformated_section),
3165 debugstr_w(fullname));
3167 WritePrivateProfileStringW(deformated_section, deformated_key,
3168 deformated_value, fullname);
3171 else if (action == 3)
3172 FIXME("Append to existing section not yet implemented\n");
3174 uirow = MSI_CreateRecord(4);
3175 MSI_RecordSetStringW(uirow,1,identifier);
3176 MSI_RecordSetStringW(uirow,2,deformated_section);
3177 MSI_RecordSetStringW(uirow,3,deformated_key);
3178 MSI_RecordSetStringW(uirow,4,deformated_value);
3179 ui_actiondata(package,szWriteIniValues,uirow);
3180 msiobj_release( &uirow->hdr );
3182 HeapFree(GetProcessHeap(),0,fullname);
3183 HeapFree(GetProcessHeap(),0,folder);
3184 HeapFree(GetProcessHeap(),0,deformated_key);
3185 HeapFree(GetProcessHeap(),0,deformated_value);
3186 HeapFree(GetProcessHeap(),0,deformated_section);
3187 return ERROR_SUCCESS;
3190 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
3194 static const WCHAR ExecSeqQuery[] =
3195 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3196 '`','I','n','i','F','i','l','e','`',0};
3198 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3199 if (rc != ERROR_SUCCESS)
3201 TRACE("no IniFile table\n");
3202 return ERROR_SUCCESS;
3205 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteIniValues, package);
3206 msiobj_release(&view->hdr);
3210 static UINT ITERATE_SelfRegModules(MSIRECORD *row, LPVOID param)
3212 MSIPACKAGE *package = (MSIPACKAGE*)param;
3217 static const WCHAR ExeStr[] =
3218 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3219 static const WCHAR close[] = {'\"',0};
3221 PROCESS_INFORMATION info;
3224 memset(&si,0,sizeof(STARTUPINFOW));
3226 filename = MSI_RecordGetString(row,1);
3227 file = get_loaded_file( package, filename );
3231 ERR("Unable to find file id %s\n",debugstr_w(filename));
3232 return ERROR_SUCCESS;
3235 len = strlenW(ExeStr) + strlenW( file->TargetPath ) + 2;
3237 FullName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3238 strcpyW(FullName,ExeStr);
3239 strcatW( FullName, file->TargetPath );
3240 strcatW(FullName,close);
3242 TRACE("Registering %s\n",debugstr_w(FullName));
3243 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL, c_colon,
3247 msi_dialog_check_messages(info.hProcess);
3249 HeapFree(GetProcessHeap(),0,FullName);
3250 return ERROR_SUCCESS;
3253 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
3257 static const WCHAR ExecSeqQuery[] =
3258 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3259 '`','S','e','l','f','R','e','g','`',0};
3261 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3262 if (rc != ERROR_SUCCESS)
3264 TRACE("no SelfReg table\n");
3265 return ERROR_SUCCESS;
3268 MSI_IterateRecords(view, NULL, ITERATE_SelfRegModules, package);
3269 msiobj_release(&view->hdr);
3271 return ERROR_SUCCESS;
3274 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
3276 MSIFEATURE *feature;
3282 return ERROR_INVALID_HANDLE;
3284 rc = MSIREG_OpenFeaturesKey(package->ProductCode,&hkey,TRUE);
3285 if (rc != ERROR_SUCCESS)
3288 rc = MSIREG_OpenUserFeaturesKey(package->ProductCode,&hukey,TRUE);
3289 if (rc != ERROR_SUCCESS)
3292 /* here the guids are base 85 encoded */
3293 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
3299 BOOL absent = FALSE;
3301 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ) &&
3302 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_SOURCE ) &&
3303 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED ))
3307 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3311 if (feature->Feature_Parent[0])
3312 size += strlenW( feature->Feature_Parent )+2;
3314 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
3317 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3319 MSICOMPONENT* component = cl->component;
3322 memset(buf,0,sizeof(buf));
3323 if ( component->ComponentId[0] )
3325 TRACE("From %s\n",debugstr_w(component->ComponentId));
3326 CLSIDFromString(component->ComponentId, &clsid);
3327 encode_base85_guid(&clsid,buf);
3328 TRACE("to %s\n",debugstr_w(buf));
3332 if (feature->Feature_Parent[0])
3334 static const WCHAR sep[] = {'\2',0};
3336 strcatW(data,feature->Feature_Parent);
3339 size = (strlenW(data)+1)*sizeof(WCHAR);
3340 RegSetValueExW( hkey, feature->Feature, 0, REG_SZ, (LPBYTE)data,size );
3341 HeapFree(GetProcessHeap(),0,data);
3345 size = strlenW(feature->Feature_Parent)*sizeof(WCHAR);
3346 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3347 (LPBYTE)feature->Feature_Parent,size);
3351 size = (strlenW(feature->Feature_Parent)+2)* sizeof(WCHAR);
3352 data = HeapAlloc(GetProcessHeap(),0,size);
3354 strcpyW( &data[1], feature->Feature_Parent );
3355 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3357 HeapFree(GetProcessHeap(),0,data);
3367 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
3370 LPWSTR buffer = NULL;
3373 static WCHAR szNONE[] = {0};
3374 static const WCHAR szWindowsInstaler[] =
3375 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3376 static const WCHAR szPropKeys[][80] =
3378 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3379 {'A','R','P','C','O','N','T','A','C','T',0},
3380 {'A','R','P','C','O','M','M','E','N','T','S',0},
3381 {'P','r','o','d','u','c','t','N','a','m','e',0},
3382 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3383 {'A','R','P','H','E','L','P','L','I','N','K',0},
3384 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3385 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3386 {'S','o','u','r','c','e','D','i','r',0},
3387 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3388 {'A','R','P','R','E','A','D','M','E',0},
3389 {'A','R','P','S','I','Z','E',0},
3390 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3391 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3395 static const WCHAR szRegKeys[][80] =
3397 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3398 {'C','o','n','t','a','c','t',0},
3399 {'C','o','m','m','e','n','t','s',0},
3400 {'D','i','s','p','l','a','y','N','a','m','e',0},
3401 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3402 {'H','e','l','p','L','i','n','k',0},
3403 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3404 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3405 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3406 {'P','u','b','l','i','s','h','e','r',0},
3407 {'R','e','a','d','m','e',0},
3408 {'S','i','z','e',0},
3409 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3410 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3414 static const WCHAR installerPathFmt[] = {
3416 'I','n','s','t','a','l','l','e','r','\\',0};
3417 static const WCHAR fmt[] = {
3419 'I','n','s','t','a','l','l','e','r','\\',
3420 '%','x','.','m','s','i',0};
3421 static const WCHAR szUpgradeCode[] =
3422 {'U','p','g','r','a','d','e','C','o','d','e',0};
3423 static const WCHAR modpath_fmt[] =
3424 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3425 static const WCHAR szModifyPath[] =
3426 {'M','o','d','i','f','y','P','a','t','h',0};
3427 static const WCHAR szUninstallString[] =
3428 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3429 static const WCHAR szEstimatedSize[] =
3430 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3431 static const WCHAR szProductLanguage[] =
3432 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3433 static const WCHAR szProductVersion[] =
3434 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3437 static const WCHAR date_fmt[] = {'%','i','%','i','%','i',0};
3438 LPWSTR upgrade_code;
3439 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
3443 return ERROR_INVALID_HANDLE;
3445 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3446 if (rc != ERROR_SUCCESS)
3449 /* dump all the info i can grab */
3450 FIXME("Flesh out more information \n");
3453 while (szPropKeys[i][0]!=0)
3455 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3456 if (rc != ERROR_SUCCESS)
3458 size = strlenW(buffer)*sizeof(WCHAR);
3459 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3460 HeapFree(GetProcessHeap(),0,buffer);
3466 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPBYTE)&rc,size);
3468 /* copy the package locally */
3469 num = GetTickCount() & 0xffff;
3473 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
3474 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
3478 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
3479 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
3480 if (handle != INVALID_HANDLE_VALUE)
3482 CloseHandle(handle);
3485 if (GetLastError() != ERROR_FILE_EXISTS &&
3486 GetLastError() != ERROR_SHARING_VIOLATION)
3488 if (!(++num & 0xffff)) num = 1;
3489 sprintfW(packagefile,fmt,num);
3490 } while (num != start);
3492 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
3493 create_full_pathW(path);
3494 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
3495 if (!CopyFileW(package->msiFilePath,packagefile,FALSE))
3496 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3497 debugstr_w(package->msiFilePath), debugstr_w(packagefile),
3499 size = strlenW(packagefile)*sizeof(WCHAR);
3500 RegSetValueExW(hkey,INSTALLPROPERTY_LOCALPACKAGEW,0,REG_SZ,
3501 (LPBYTE)packagefile,size);
3503 /* do ModifyPath and UninstallString */
3504 size = deformat_string(package,modpath_fmt,&buffer);
3505 RegSetValueExW(hkey,szModifyPath,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3506 RegSetValueExW(hkey,szUninstallString,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3507 HeapFree(GetProcessHeap(),0,buffer);
3509 FIXME("Write real Estimated Size when we have it\n");
3511 RegSetValueExW(hkey,szEstimatedSize,0,REG_DWORD,(LPBYTE)&size,sizeof(DWORD));
3513 GetLocalTime(&systime);
3514 size = 9*sizeof(WCHAR);
3515 buffer= HeapAlloc(GetProcessHeap(),0,size);
3516 sprintfW(buffer,date_fmt,systime.wYear,systime.wMonth,systime.wDay);
3517 size = strlenW(buffer)*sizeof(WCHAR);
3518 RegSetValueExW(hkey,INSTALLPROPERTY_INSTALLDATEW,0,REG_SZ,
3519 (LPBYTE)buffer,size);
3520 HeapFree(GetProcessHeap(),0,buffer);
3522 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3523 size = atoiW(buffer);
3524 RegSetValueExW(hkey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3525 (LPBYTE)&size,sizeof(DWORD));
3526 HeapFree(GetProcessHeap(),1,buffer);
3528 buffer = load_dynamic_property(package,szProductVersion,NULL);
3531 DWORD verdword = build_version_dword(buffer);
3532 DWORD vermajor = verdword>>24;
3533 DWORD verminor = (verdword>>16)&0x00FF;
3534 size = sizeof(DWORD);
3535 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD,
3536 (LPBYTE)&verdword,size);
3537 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMAJORW,0,REG_DWORD,
3538 (LPBYTE)&vermajor,size);
3539 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMINORW,0,REG_DWORD,
3540 (LPBYTE)&verminor,size);
3542 HeapFree(GetProcessHeap(),0,buffer);
3544 /* Handle Upgrade Codes */
3545 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
3550 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3551 squash_guid(package->ProductCode,squashed);
3552 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3554 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3555 squash_guid(package->ProductCode,squashed);
3556 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3559 HeapFree(GetProcessHeap(),0,upgrade_code);
3565 return ERROR_SUCCESS;
3568 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
3573 return ERROR_INVALID_HANDLE;
3575 rc = execute_script(package,INSTALL_SCRIPT);
3580 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
3585 return ERROR_INVALID_HANDLE;
3587 /* turn off scheduleing */
3588 package->script->CurrentlyScripting= FALSE;
3590 /* first do the same as an InstallExecute */
3591 rc = ACTION_InstallExecute(package);
3592 if (rc != ERROR_SUCCESS)
3595 /* then handle Commit Actions */
3596 rc = execute_script(package,COMMIT_SCRIPT);
3601 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
3603 static const WCHAR RunOnce[] = {
3604 'S','o','f','t','w','a','r','e','\\',
3605 'M','i','c','r','o','s','o','f','t','\\',
3606 'W','i','n','d','o','w','s','\\',
3607 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3608 'R','u','n','O','n','c','e',0};
3609 static const WCHAR InstallRunOnce[] = {
3610 'S','o','f','t','w','a','r','e','\\',
3611 'M','i','c','r','o','s','o','f','t','\\',
3612 'W','i','n','d','o','w','s','\\',
3613 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3614 'I','n','s','t','a','l','l','e','r','\\',
3615 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3617 static const WCHAR msiexec_fmt[] = {
3619 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3620 '\"','%','s','\"',0};
3621 static const WCHAR install_fmt[] = {
3622 '/','I',' ','\"','%','s','\"',' ',
3623 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3624 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3625 WCHAR buffer[256], sysdir[MAX_PATH];
3627 WCHAR squished_pc[100];
3631 return ERROR_INVALID_HANDLE;
3633 squash_guid(package->ProductCode,squished_pc);
3635 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
3636 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
3637 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
3640 size = strlenW(buffer)*sizeof(WCHAR);
3641 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3644 TRACE("Reboot command %s\n",debugstr_w(buffer));
3646 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
3647 sprintfW(buffer,install_fmt,package->ProductCode,squished_pc);
3649 size = strlenW(buffer)*sizeof(WCHAR);
3650 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3653 return ERROR_INSTALL_SUSPEND;
3656 UINT ACTION_ResolveSource(MSIPACKAGE* package)
3661 * we are currently doing what should be done here in the top level Install
3662 * however for Adminastrative and uninstalls this step will be needed
3664 if (!package->PackagePath)
3665 return ERROR_SUCCESS;
3667 attrib = GetFileAttributesW(package->PackagePath);
3668 if (attrib == INVALID_FILE_ATTRIBUTES)
3674 rc = MsiSourceListGetInfoW(package->ProductCode, NULL,
3675 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3676 INSTALLPROPERTY_DISKPROMPTW,NULL,&size);
3677 if (rc == ERROR_MORE_DATA)
3679 prompt = HeapAlloc(GetProcessHeap(),0,size * sizeof(WCHAR));
3680 MsiSourceListGetInfoW(package->ProductCode, NULL,
3681 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3682 INSTALLPROPERTY_DISKPROMPTW,prompt,&size);
3685 prompt = strdupW(package->PackagePath);
3687 msg = generate_error_string(package,1302,1,prompt);
3688 while(attrib == INVALID_FILE_ATTRIBUTES)
3690 rc = MessageBoxW(NULL,msg,NULL,MB_OKCANCEL);
3693 rc = ERROR_INSTALL_USEREXIT;
3696 attrib = GetFileAttributesW(package->PackagePath);
3698 HeapFree(GetProcessHeap(),0,prompt);
3702 return ERROR_SUCCESS;
3707 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
3715 static const WCHAR szPropKeys[][80] =
3717 {'P','r','o','d','u','c','t','I','D',0},
3718 {'U','S','E','R','N','A','M','E',0},
3719 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3723 static const WCHAR szRegKeys[][80] =
3725 {'P','r','o','d','u','c','t','I','D',0},
3726 {'R','e','g','O','w','n','e','r',0},
3727 {'R','e','g','C','o','m','p','a','n','y',0},
3732 return ERROR_INVALID_HANDLE;
3734 productid = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTIDW,
3737 return ERROR_SUCCESS;
3739 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3740 if (rc != ERROR_SUCCESS)
3744 while (szPropKeys[i][0]!=0)
3746 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3747 if (rc == ERROR_SUCCESS)
3749 size = strlenW(buffer)*sizeof(WCHAR);
3750 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3753 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
3758 HeapFree(GetProcessHeap(),0,productid);
3761 return ERROR_SUCCESS;
3765 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
3767 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
3768 static const WCHAR szTwo[] = {'2',0};
3771 level = load_dynamic_property(package,szUILevel,NULL);
3773 MSI_SetPropertyW(package,szUILevel,szTwo);
3774 package->script->InWhatSequence |= SEQUENCE_EXEC;
3775 rc = ACTION_ProcessExecSequence(package,FALSE);
3776 MSI_SetPropertyW(package,szUILevel,level);
3777 HeapFree(GetProcessHeap(),0,level);
3783 * Code based off of code located here
3784 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3786 * Using string index 4 (full font name) instead of 1 (family name)
3788 static LPWSTR load_ttfname_from(LPCWSTR filename)
3794 typedef struct _tagTT_OFFSET_TABLE{
3795 USHORT uMajorVersion;
3796 USHORT uMinorVersion;
3797 USHORT uNumOfTables;
3798 USHORT uSearchRange;
3799 USHORT uEntrySelector;
3803 typedef struct _tagTT_TABLE_DIRECTORY{
3804 char szTag[4]; /* table name */
3805 ULONG uCheckSum; /* Check sum */
3806 ULONG uOffset; /* Offset from beginning of file */
3807 ULONG uLength; /* length of the table in bytes */
3808 }TT_TABLE_DIRECTORY;
3810 typedef struct _tagTT_NAME_TABLE_HEADER{
3811 USHORT uFSelector; /* format selector. Always 0 */
3812 USHORT uNRCount; /* Name Records count */
3813 USHORT uStorageOffset; /* Offset for strings storage,
3814 * from start of the table */
3815 }TT_NAME_TABLE_HEADER;
3817 typedef struct _tagTT_NAME_RECORD{
3822 USHORT uStringLength;
3823 USHORT uStringOffset; /* from start of storage area */
3826 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3827 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3829 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
3830 FILE_ATTRIBUTE_NORMAL, 0 );
3831 if (handle != INVALID_HANDLE_VALUE)
3833 TT_TABLE_DIRECTORY tblDir;
3834 BOOL bFound = FALSE;
3835 TT_OFFSET_TABLE ttOffsetTable;
3837 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
3838 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
3839 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
3840 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
3842 if (ttOffsetTable.uMajorVersion != 1 ||
3843 ttOffsetTable.uMinorVersion != 0)
3846 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
3848 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
3849 if (strncmp(tblDir.szTag,"name",4)==0)
3852 tblDir.uLength = SWAPLONG(tblDir.uLength);
3853 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
3860 TT_NAME_TABLE_HEADER ttNTHeader;
3861 TT_NAME_RECORD ttRecord;
3863 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
3864 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
3867 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
3868 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
3870 for(i=0; i<ttNTHeader.uNRCount; i++)
3872 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
3873 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
3874 /* 4 is the Full Font Name */
3875 if(ttRecord.uNameID == 4)
3879 static LPCSTR tt = " (TrueType)";
3881 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
3882 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
3883 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
3884 SetFilePointer(handle, tblDir.uOffset +
3885 ttRecord.uStringOffset +
3886 ttNTHeader.uStorageOffset,
3888 buf = HeapAlloc(GetProcessHeap(), 0,
3889 ttRecord.uStringLength + 1 + strlen(tt));
3890 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
3891 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
3892 if (strlen(buf) > 0)
3895 ret = strdupAtoW(buf);
3896 HeapFree(GetProcessHeap(),0,buf);
3900 HeapFree(GetProcessHeap(),0,buf);
3901 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
3905 CloseHandle(handle);
3908 ERR("Unable to open font file %s\n", debugstr_w(filename));
3910 TRACE("Returning fontname %s\n",debugstr_w(ret));
3914 static UINT ITERATE_RegisterFonts(MSIRECORD *row, LPVOID param)
3916 MSIPACKAGE *package = (MSIPACKAGE*)param;
3921 static const WCHAR regfont1[] =
3922 {'S','o','f','t','w','a','r','e','\\',
3923 'M','i','c','r','o','s','o','f','t','\\',
3924 'W','i','n','d','o','w','s',' ','N','T','\\',
3925 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3926 'F','o','n','t','s',0};
3927 static const WCHAR regfont2[] =
3928 {'S','o','f','t','w','a','r','e','\\',
3929 'M','i','c','r','o','s','o','f','t','\\',
3930 'W','i','n','d','o','w','s','\\',
3931 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3932 'F','o','n','t','s',0};
3936 filename = MSI_RecordGetString( row, 1 );
3937 file = get_loaded_file( package, filename );
3940 ERR("Unable to load file\n");
3941 return ERROR_SUCCESS;
3944 /* check to make sure that component is installed */
3945 if (!ACTION_VerifyComponentForAction(package,
3946 file->Component, INSTALLSTATE_LOCAL))
3948 TRACE("Skipping: Component not scheduled for install\n");
3949 return ERROR_SUCCESS;
3952 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
3953 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
3955 if (MSI_RecordIsNull(row,2))
3956 name = load_ttfname_from( file->TargetPath );
3958 name = load_dynamic_stringW(row,2);
3962 size = strlenW( file->FileName ) * sizeof(WCHAR);
3963 RegSetValueExW( hkey1, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3964 RegSetValueExW( hkey2, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3967 HeapFree(GetProcessHeap(),0,name);
3970 return ERROR_SUCCESS;
3973 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
3977 static const WCHAR ExecSeqQuery[] =
3978 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3979 '`','F','o','n','t','`',0};
3981 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3982 if (rc != ERROR_SUCCESS)
3984 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
3985 return ERROR_SUCCESS;
3988 MSI_IterateRecords(view, NULL, ITERATE_RegisterFonts, package);
3989 msiobj_release(&view->hdr);
3991 return ERROR_SUCCESS;
3994 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
3996 MSIPACKAGE *package = (MSIPACKAGE*)param;
3997 LPCWSTR compgroupid=NULL;
3998 LPCWSTR feature=NULL;
3999 LPCWSTR text = NULL;
4000 LPCWSTR qualifier = NULL;
4001 LPCWSTR component = NULL;
4002 LPWSTR advertise = NULL;
4003 LPWSTR output = NULL;
4005 UINT rc = ERROR_SUCCESS;
4009 component = MSI_RecordGetString(rec,3);
4010 comp = get_loaded_component(package,component);
4012 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL) &&
4013 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_SOURCE) &&
4014 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_ADVERTISED))
4016 TRACE("Skipping: Component %s not scheduled for install\n",
4017 debugstr_w(component));
4019 return ERROR_SUCCESS;
4022 compgroupid = MSI_RecordGetString(rec,1);
4024 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
4025 if (rc != ERROR_SUCCESS)
4028 text = MSI_RecordGetString(rec,4);
4029 qualifier = MSI_RecordGetString(rec,2);
4030 feature = MSI_RecordGetString(rec,5);
4032 advertise = create_component_advertise_string(package, comp, feature);
4034 sz = strlenW(advertise);
4037 sz += lstrlenW(text);
4040 sz *= sizeof(WCHAR);
4042 output = HeapAlloc(GetProcessHeap(),0,sz);
4043 memset(output,0,sz);
4044 strcpyW(output,advertise);
4047 strcatW(output,text);
4049 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
4050 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
4054 HeapFree(GetProcessHeap(),0,output);
4060 * At present I am ignorning the advertised components part of this and only
4061 * focusing on the qualified component sets
4063 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
4067 static const WCHAR ExecSeqQuery[] =
4068 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4069 '`','P','u','b','l','i','s','h',
4070 'C','o','m','p','o','n','e','n','t','`',0};
4072 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4073 if (rc != ERROR_SUCCESS)
4074 return ERROR_SUCCESS;
4076 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
4077 msiobj_release(&view->hdr);