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);
481 HeapFree(GetProcessHeap(), 0, check);
482 HeapFree(GetProcessHeap(), 0, path);
488 ptr = (LPWSTR)szCommandLine;
495 TRACE("Looking at %s\n",debugstr_w(ptr));
497 ptr2 = strchrW(ptr,'=');
503 while (*ptr == ' ') ptr++;
505 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
506 memcpy(prop,ptr,len*sizeof(WCHAR));
512 while (*ptr && (quote || (!quote && *ptr!=' ')))
525 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
526 memcpy(val,ptr2,len*sizeof(WCHAR));
529 if (strlenW(prop) > 0)
531 TRACE("Found commandline property (%s) = (%s)\n",
532 debugstr_w(prop), debugstr_w(val));
533 MSI_SetPropertyW(package,prop,val);
535 HeapFree(GetProcessHeap(),0,val);
536 HeapFree(GetProcessHeap(),0,prop);
543 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
545 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
547 package->script->InWhatSequence |= SEQUENCE_UI;
548 rc = ACTION_ProcessUISequence(package);
550 if (rc == ERROR_SUCCESS)
552 package->script->InWhatSequence |= SEQUENCE_EXEC;
553 rc = ACTION_ProcessExecSequence(package,TRUE);
557 rc = ACTION_ProcessExecSequence(package,FALSE);
560 rc = ACTION_ProcessExecSequence(package,FALSE);
564 /* install was halted but should be considered a success */
568 package->script->CurrentlyScripting= FALSE;
570 /* process the ending type action */
571 if (rc == ERROR_SUCCESS)
572 ACTION_PerformActionSequence(package,-1,ui);
573 else if (rc == ERROR_INSTALL_USEREXIT)
574 ACTION_PerformActionSequence(package,-2,ui);
575 else if (rc == ERROR_INSTALL_SUSPEND)
576 ACTION_PerformActionSequence(package,-4,ui);
578 ACTION_PerformActionSequence(package,-3,ui);
580 /* finish up running custom actions */
581 ACTION_FinishCustomActions(package);
586 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
588 UINT rc = ERROR_SUCCESS;
590 static const WCHAR ExecSeqQuery[] =
591 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
592 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
593 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
594 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
596 static const WCHAR UISeqQuery[] =
597 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
598 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
599 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
600 ' ', '=',' ','%','i',0};
603 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
605 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
609 LPCWSTR action, cond;
611 TRACE("Running the actions\n");
613 /* check conditions */
614 cond = MSI_RecordGetString(row,2);
617 /* this is a hack to skip errors in the condition code */
618 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
622 action = MSI_RecordGetString(row,1);
625 ERR("failed to fetch action\n");
626 rc = ERROR_FUNCTION_FAILED;
631 rc = ACTION_PerformUIAction(package,action);
633 rc = ACTION_PerformAction(package,action,FALSE);
635 msiobj_release(&row->hdr);
646 } iterate_action_param;
648 static UINT ITERATE_Actions(MSIRECORD *row, LPVOID param)
650 iterate_action_param *iap= (iterate_action_param*)param;
652 LPCWSTR cond, action;
654 action = MSI_RecordGetString(row,1);
657 ERR("Error is retrieving action name\n");
658 return ERROR_FUNCTION_FAILED;
661 /* check conditions */
662 cond = MSI_RecordGetString(row,2);
665 /* this is a hack to skip errors in the condition code */
666 if (MSI_EvaluateConditionW(iap->package, cond) == MSICONDITION_FALSE)
668 TRACE("Skipping action: %s (condition is false)\n",
670 return ERROR_SUCCESS;
675 rc = ACTION_PerformUIAction(iap->package,action);
677 rc = ACTION_PerformAction(iap->package,action,FALSE);
679 msi_dialog_check_messages( NULL );
681 if (iap->package->CurrentInstallState != ERROR_SUCCESS )
682 rc = iap->package->CurrentInstallState;
684 if (rc == ERROR_FUNCTION_NOT_CALLED)
687 if (rc != ERROR_SUCCESS)
688 ERR("Execution halted due to error (%i)\n",rc);
693 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
697 static const WCHAR ExecSeqQuery[] =
698 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
699 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
700 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
701 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
702 'O','R','D','E','R',' ', 'B','Y',' ',
703 '`','S','e','q','u','e','n','c','e','`',0 };
705 static const WCHAR IVQuery[] =
706 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
707 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
708 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
709 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
710 ' ','\'', 'I','n','s','t','a','l','l',
711 'V','a','l','i','d','a','t','e','\'', 0};
713 iterate_action_param iap;
715 iap.package = package;
718 if (package->script->ExecuteSequenceRun)
720 TRACE("Execute Sequence already Run\n");
721 return ERROR_SUCCESS;
724 package->script->ExecuteSequenceRun = TRUE;
726 /* get the sequence number */
729 row = MSI_QueryGetRecord(package->db, IVQuery);
731 return ERROR_FUNCTION_FAILED;
732 seq = MSI_RecordGetInteger(row,1);
733 msiobj_release(&row->hdr);
736 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
737 if (rc == ERROR_SUCCESS)
739 TRACE("Running the actions\n");
741 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
742 msiobj_release(&view->hdr);
748 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
752 static const WCHAR ExecSeqQuery [] =
753 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
754 '`','I','n','s','t','a','l','l',
755 'U','I','S','e','q','u','e','n','c','e','`',
756 ' ','W','H','E','R','E',' ',
757 '`','S','e','q','u','e','n','c','e','`',' ',
758 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
759 '`','S','e','q','u','e','n','c','e','`',0};
760 iterate_action_param iap;
762 iap.package = package;
765 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
767 if (rc == ERROR_SUCCESS)
769 TRACE("Running the actions \n");
771 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
772 msiobj_release(&view->hdr);
778 /********************************************************
779 * ACTION helper functions and functions that perform the actions
780 *******************************************************/
781 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
782 UINT* rc, BOOL force )
788 if (!run && !package->script->CurrentlyScripting)
793 if (strcmpW(action,szInstallFinalize) == 0 ||
794 strcmpW(action,szInstallExecute) == 0 ||
795 strcmpW(action,szInstallExecuteAgain) == 0)
800 while (StandardActions[i].action != NULL)
802 if (strcmpW(StandardActions[i].action, action)==0)
806 ui_actioninfo(package, action, TRUE, 0);
807 *rc = schedule_action(package,INSTALL_SCRIPT,action);
808 ui_actioninfo(package, action, FALSE, *rc);
812 ui_actionstart(package, action);
813 if (StandardActions[i].handler)
815 *rc = StandardActions[i].handler(package);
819 FIXME("unhandled standard action %s\n",debugstr_w(action));
831 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
832 UINT* rc, BOOL force )
837 arc = ACTION_CustomAction(package,action, force);
839 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
848 * A lot of actions are really important even if they don't do anything
849 * explicit... Lots of properties are set at the beginning of the installation
850 * CostFinalize does a bunch of work to translate the directories and such
852 * But until I get write access to the database that is hard, so I am going to
853 * hack it to see if I can get something to run.
855 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
857 UINT rc = ERROR_SUCCESS;
860 TRACE("Performing action (%s)\n",debugstr_w(action));
862 handled = ACTION_HandleStandardAction(package, action, &rc, force);
865 handled = ACTION_HandleCustomAction(package, action, &rc, force);
869 FIXME("unhandled msi action %s\n",debugstr_w(action));
870 rc = ERROR_FUNCTION_NOT_CALLED;
876 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
878 UINT rc = ERROR_SUCCESS;
879 BOOL handled = FALSE;
881 TRACE("Performing action (%s)\n",debugstr_w(action));
883 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
886 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
888 if( !handled && ACTION_DialogBox(package,action) == ERROR_SUCCESS )
893 FIXME("unhandled msi action %s\n",debugstr_w(action));
894 rc = ERROR_FUNCTION_NOT_CALLED;
902 * Actual Action Handlers
905 static UINT ITERATE_CreateFolders(MSIRECORD *row, LPVOID param)
907 MSIPACKAGE *package = (MSIPACKAGE*)param;
913 dir = MSI_RecordGetString(row,1);
916 ERR("Unable to get folder id \n");
917 return ERROR_SUCCESS;
920 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
923 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
924 return ERROR_SUCCESS;
927 TRACE("Folder is %s\n",debugstr_w(full_path));
930 uirow = MSI_CreateRecord(1);
931 MSI_RecordSetStringW(uirow,1,full_path);
932 ui_actiondata(package,szCreateFolders,uirow);
933 msiobj_release( &uirow->hdr );
935 if (folder->State == 0)
936 create_full_pathW(full_path);
940 HeapFree(GetProcessHeap(),0,full_path);
941 return ERROR_SUCCESS;
946 * Also we cannot enable/disable components either, so for now I am just going
947 * to do all the directories for all the components.
949 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
951 static const WCHAR ExecSeqQuery[] =
952 {'S','E','L','E','C','T',' ',
953 '`','D','i','r','e','c','t','o','r','y','_','`',
954 ' ','F','R','O','M',' ',
955 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
959 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
960 if (rc != ERROR_SUCCESS)
961 return ERROR_SUCCESS;
963 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateFolders, package);
964 msiobj_release(&view->hdr);
969 static MSICOMPONENT* load_component( MSIRECORD * row )
974 comp = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSICOMPONENT) );
978 /* fill in the data */
979 sz = IDENTIFIER_SIZE;
980 MSI_RecordGetStringW(row,1,comp->Component,&sz);
982 TRACE("Loading Component %s\n",
983 debugstr_w(comp->Component));
986 if (!MSI_RecordIsNull(row,2))
987 MSI_RecordGetStringW(row,2,comp->ComponentId,&sz);
989 sz = IDENTIFIER_SIZE;
990 MSI_RecordGetStringW(row,3,comp->Directory,&sz);
992 comp->Attributes = MSI_RecordGetInteger(row,4);
994 comp->Condition = load_dynamic_stringW( row, 5 );
996 sz = IDENTIFIER_SIZE;
997 MSI_RecordGetStringW(row,6,comp->KeyPath,&sz);
999 comp->Installed = INSTALLSTATE_ABSENT;
1000 comp->Action = INSTALLSTATE_UNKNOWN;
1001 comp->ActionRequest = INSTALLSTATE_UNKNOWN;
1003 comp->Enabled = TRUE;
1009 MSIPACKAGE *package;
1010 MSIFEATURE *feature;
1013 static UINT add_feature_component( MSIFEATURE *feature, MSICOMPONENT *comp )
1017 cl = HeapAlloc( GetProcessHeap(), 0, sizeof (*cl) );
1019 return ERROR_NOT_ENOUGH_MEMORY;
1020 cl->component = comp;
1021 list_add_tail( &feature->Components, &cl->entry );
1023 return ERROR_SUCCESS;
1026 static UINT iterate_component_check( MSIRECORD *row, LPVOID param )
1028 _ilfs* ilfs= (_ilfs*)param;
1029 MSIPACKAGE *package = ilfs->package;
1030 MSIFEATURE *feature = ilfs->feature;
1033 comp = load_component( row );
1035 return ERROR_FUNCTION_FAILED;
1037 list_add_tail( &package->components, &comp->entry );
1038 add_feature_component( feature, comp );
1040 TRACE("Loaded new component %p\n", comp);
1042 return ERROR_SUCCESS;
1045 static UINT iterate_load_featurecomponents(MSIRECORD *row, LPVOID param)
1047 _ilfs* ilfs= (_ilfs*)param;
1052 static const WCHAR Query[] =
1053 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1054 '`','C','o','m','p','o','n','e','n','t','`',' ',
1055 'W','H','E','R','E',' ',
1056 '`','C','o','m','p','o','n','e','n','t','`',' ',
1057 '=','\'','%','s','\'',0};
1059 component = MSI_RecordGetString(row,1);
1061 /* check to see if the component is already loaded */
1062 comp = get_loaded_component( ilfs->package, component );
1065 TRACE("Component %s already loaded\n", debugstr_w(component) );
1066 add_feature_component( ilfs->feature, comp );
1067 return ERROR_SUCCESS;
1070 rc = MSI_OpenQuery(ilfs->package->db, &view, Query, component);
1071 if (rc != ERROR_SUCCESS)
1072 return ERROR_SUCCESS;
1074 rc = MSI_IterateRecords(view, NULL, iterate_component_check, ilfs);
1075 msiobj_release( &view->hdr );
1077 return ERROR_SUCCESS;
1080 static UINT load_feature(MSIRECORD * row, LPVOID param)
1082 MSIPACKAGE* package = (MSIPACKAGE*)param;
1083 MSIFEATURE* feature;
1085 static const WCHAR Query1[] =
1086 {'S','E','L','E','C','T',' ',
1087 '`','C','o','m','p','o','n','e','n','t','_','`',
1088 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1089 'C','o','m','p','o','n','e','n','t','s','`',' ',
1090 'W','H','E','R','E',' ',
1091 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1096 /* fill in the data */
1098 feature = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFEATURE) );
1100 return ERROR_NOT_ENOUGH_MEMORY;
1102 list_init( &feature->Components );
1104 sz = IDENTIFIER_SIZE;
1105 MSI_RecordGetStringW(row,1,feature->Feature,&sz);
1107 TRACE("Loading feature %s\n",debugstr_w(feature->Feature));
1109 sz = IDENTIFIER_SIZE;
1110 if (!MSI_RecordIsNull(row,2))
1111 MSI_RecordGetStringW(row,2,feature->Feature_Parent,&sz);
1113 feature->Title = load_dynamic_stringW( row, 3 );
1114 feature->Description = load_dynamic_stringW( row, 4 );
1116 if (!MSI_RecordIsNull(row,5))
1117 feature->Display = MSI_RecordGetInteger(row,5);
1119 feature->Level= MSI_RecordGetInteger(row,6);
1121 sz = IDENTIFIER_SIZE;
1122 if (!MSI_RecordIsNull(row,7))
1123 MSI_RecordGetStringW(row,7,feature->Directory,&sz);
1125 feature->Attributes = MSI_RecordGetInteger(row,8);
1127 feature->Installed = INSTALLSTATE_ABSENT;
1128 feature->Action = INSTALLSTATE_UNKNOWN;
1129 feature->ActionRequest = INSTALLSTATE_UNKNOWN;
1131 list_add_tail( &package->features, &feature->entry );
1133 /* load feature components */
1135 rc = MSI_OpenQuery( package->db, &view, Query1, feature->Feature );
1136 if (rc != ERROR_SUCCESS)
1137 return ERROR_SUCCESS;
1139 ilfs.package = package;
1140 ilfs.feature = feature;
1142 MSI_IterateRecords(view, NULL, iterate_load_featurecomponents , &ilfs);
1143 msiobj_release(&view->hdr);
1145 return ERROR_SUCCESS;
1148 static UINT load_file(MSIRECORD *row, LPVOID param)
1150 MSIPACKAGE* package = (MSIPACKAGE*)param;
1154 /* fill in the data */
1156 file = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFILE) );
1158 return ERROR_NOT_ENOUGH_MEMORY;
1160 file->File = load_dynamic_stringW( row, 1 );
1162 component = MSI_RecordGetString( row, 2 );
1163 file->Component = get_loaded_component( package, component );
1165 if (!file->Component)
1166 ERR("Unfound Component %s\n",debugstr_w(component));
1168 file->FileName = load_dynamic_stringW( row, 3 );
1169 reduce_to_longfilename( file->FileName );
1171 file->ShortName = load_dynamic_stringW( row, 3 );
1172 reduce_to_shortfilename( file->ShortName );
1174 file->FileSize = MSI_RecordGetInteger( row, 4 );
1175 file->Version = load_dynamic_stringW( row, 5 );
1176 file->Language = load_dynamic_stringW( row, 6 );
1177 file->Attributes = MSI_RecordGetInteger( row, 7 );
1178 file->Sequence = MSI_RecordGetInteger( row, 8 );
1182 TRACE("File Loaded (%s)\n",debugstr_w(file->File));
1184 list_add_tail( &package->files, &file->entry );
1186 return ERROR_SUCCESS;
1189 static UINT load_all_files(MSIPACKAGE *package)
1193 static const WCHAR Query[] =
1194 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1195 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1196 '`','S','e','q','u','e','n','c','e','`', 0};
1199 return ERROR_INVALID_HANDLE;
1201 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1202 if (rc != ERROR_SUCCESS)
1203 return ERROR_SUCCESS;
1205 rc = MSI_IterateRecords(view, NULL, load_file, package);
1206 msiobj_release(&view->hdr);
1208 return ERROR_SUCCESS;
1213 * I am not doing any of the costing functionality yet.
1214 * Mostly looking at doing the Component and Feature loading
1216 * The native MSI does A LOT of modification to tables here. Mostly adding
1217 * a lot of temporary columns to the Feature and Component tables.
1219 * note: Native msi also tracks the short filename. But I am only going to
1220 * track the long ones. Also looking at this directory table
1221 * it appears that the directory table does not get the parents
1222 * resolved base on property only based on their entries in the
1225 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1229 static const WCHAR Query_all[] =
1230 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1231 '`','F','e','a','t','u','r','e','`',0};
1232 static const WCHAR szCosting[] =
1233 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1234 static const WCHAR szZero[] = { '0', 0 };
1238 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1240 return ERROR_SUCCESS;
1242 MSI_SetPropertyW(package, szCosting, szZero);
1243 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1245 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1246 if (rc != ERROR_SUCCESS)
1249 rc = MSI_IterateRecords(view, NULL, load_feature, package);
1250 msiobj_release(&view->hdr);
1252 load_all_files(package);
1254 return ERROR_SUCCESS;
1257 static UINT execute_script(MSIPACKAGE *package, UINT script )
1260 UINT rc = ERROR_SUCCESS;
1262 TRACE("Executing Script %i\n",script);
1264 for (i = 0; i < package->script->ActionCount[script]; i++)
1267 action = package->script->Actions[script][i];
1268 ui_actionstart(package, action);
1269 TRACE("Executing Action (%s)\n",debugstr_w(action));
1270 rc = ACTION_PerformAction(package, action, TRUE);
1271 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1272 if (rc != ERROR_SUCCESS)
1275 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1277 package->script->ActionCount[script] = 0;
1278 package->script->Actions[script] = NULL;
1282 static UINT ACTION_FileCost(MSIPACKAGE *package)
1284 return ERROR_SUCCESS;
1288 static MSIFOLDER *load_folder( MSIPACKAGE *package, LPCWSTR dir )
1290 static const WCHAR Query[] =
1291 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1292 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1293 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1294 ' ','=',' ','\'','%','s','\'',
1296 LPWSTR ptargetdir, targetdir, srcdir;
1298 LPWSTR shortname = NULL;
1299 MSIRECORD * row = 0;
1302 TRACE("Looking for dir %s\n",debugstr_w(dir));
1304 folder = get_loaded_folder( package, dir );
1308 TRACE("Working to load %s\n",debugstr_w(dir));
1310 folder = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFOLDER) );
1314 folder->Directory = strdupW(dir);
1316 row = MSI_QueryGetRecord(package->db, Query, dir);
1320 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1322 /* split src and target dir */
1323 if (strchrW(targetdir,':'))
1325 srcdir=strchrW(targetdir,':');
1332 /* for now only pick long filename versions */
1333 if (strchrW(targetdir,'|'))
1335 shortname = targetdir;
1336 targetdir = strchrW(targetdir,'|');
1340 /* for the sourcedir pick the short filename */
1341 if (srcdir && strchrW(srcdir,'|'))
1343 LPWSTR p = strchrW(srcdir,'|');
1347 /* now check for root dirs */
1348 if (targetdir[0] == '.' && targetdir[1] == 0)
1353 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1354 HeapFree(GetProcessHeap(),0, folder->TargetDefault);
1355 folder->TargetDefault = strdupW(targetdir);
1359 folder->SourceDefault = strdupW(srcdir);
1361 folder->SourceDefault = strdupW(shortname);
1363 folder->SourceDefault = strdupW(targetdir);
1364 HeapFree(GetProcessHeap(), 0, ptargetdir);
1365 TRACE(" SourceDefault = %s\n", debugstr_w( folder->SourceDefault ));
1367 parent = MSI_RecordGetString(row,2);
1370 folder->Parent = load_folder( package, parent );
1371 if ( folder->Parent )
1372 TRACE("loaded parent %p %s\n", folder->Parent,
1373 debugstr_w(folder->Parent->Directory));
1375 ERR("failed to load parent folder %s\n", debugstr_w(parent));
1378 folder->Property = load_dynamic_property( package, dir, NULL );
1380 msiobj_release(&row->hdr);
1382 list_add_tail( &package->folders, &folder->entry );
1384 TRACE("%s returning %p\n",debugstr_w(dir),folder);
1389 /* scan for and update current install states */
1390 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
1393 MSIFEATURE *feature;
1395 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1398 res = MsiGetComponentPathW( package->ProductCode,
1399 comp->ComponentId, NULL, NULL);
1401 res = INSTALLSTATE_ABSENT;
1402 comp->Installed = res;
1405 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1408 INSTALLSTATE res = -10;
1410 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1412 comp= cl->component;
1415 res = comp->Installed;
1418 if (res == comp->Installed)
1421 if (res != comp->Installed)
1422 res = INSTALLSTATE_INCOMPLETE;
1425 feature->Installed = res;
1429 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
1432 static const WCHAR all[]={'A','L','L',0};
1434 MSIFEATURE *feature;
1436 override = load_dynamic_property(package, property, NULL);
1440 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1442 if (strcmpiW(override,all)==0)
1444 feature->ActionRequest= state;
1445 feature->Action = state;
1449 LPWSTR ptr = override;
1450 LPWSTR ptr2 = strchrW(override,',');
1454 if ((ptr2 && strncmpW(ptr,feature->Feature, ptr2-ptr)==0)
1455 || (!ptr2 && strcmpW(ptr,feature->Feature)==0))
1457 feature->ActionRequest= state;
1458 feature->Action = state;
1464 ptr2 = strchrW(ptr,',');
1471 HeapFree(GetProcessHeap(),0,override);
1476 static UINT SetFeatureStates(MSIPACKAGE *package)
1480 static const WCHAR szlevel[] =
1481 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1482 static const WCHAR szAddLocal[] =
1483 {'A','D','D','L','O','C','A','L',0};
1484 static const WCHAR szRemove[] =
1485 {'R','E','M','O','V','E',0};
1486 BOOL override = FALSE;
1487 MSICOMPONENT* component;
1488 MSIFEATURE *feature;
1491 /* I do not know if this is where it should happen.. but */
1493 TRACE("Checking Install Level\n");
1495 level = load_dynamic_property(package,szlevel,NULL);
1498 install_level = atoiW(level);
1499 HeapFree(GetProcessHeap(), 0, level);
1504 /* ok hereis the _real_ rub
1505 * all these activation/deactivation things happen in order and things
1506 * later on the list override things earlier on the list.
1507 * 1) INSTALLLEVEL processing
1517 * 11) FILEADDDEFAULT
1518 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1519 * ignored for all the features. seems strange, especially since it is not
1520 * documented anywhere, but it is how it works.
1522 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1523 * REMOVE are the big ones, since we don't handle administrative installs
1526 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
1527 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
1531 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1533 BOOL feature_state = ((feature->Level > 0) &&
1534 (feature->Level <= install_level));
1536 if ((feature_state) && (feature->Action == INSTALLSTATE_UNKNOWN))
1538 if (feature->Attributes & msidbFeatureAttributesFavorSource)
1540 feature->ActionRequest = INSTALLSTATE_SOURCE;
1541 feature->Action = INSTALLSTATE_SOURCE;
1543 else if (feature->Attributes & msidbFeatureAttributesFavorAdvertise)
1545 feature->ActionRequest = INSTALLSTATE_ADVERTISED;
1546 feature->Action = INSTALLSTATE_ADVERTISED;
1550 feature->ActionRequest = INSTALLSTATE_LOCAL;
1551 feature->Action = INSTALLSTATE_LOCAL;
1558 /* set the Preselected Property */
1559 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1560 static const WCHAR szOne[] = { '1', 0 };
1562 MSI_SetPropertyW(package,szPreselected,szOne);
1566 * now we want to enable or disable components base on feature
1569 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1573 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1574 debugstr_w(feature->Feature), feature->Installed, feature->Action,
1575 feature->ActionRequest);
1577 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1579 component = cl->component;
1581 if (!component->Enabled)
1583 component->Action = INSTALLSTATE_UNKNOWN;
1584 component->ActionRequest = INSTALLSTATE_UNKNOWN;
1588 if (feature->Action == INSTALLSTATE_LOCAL)
1590 component->Action = INSTALLSTATE_LOCAL;
1591 component->ActionRequest = INSTALLSTATE_LOCAL;
1593 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
1595 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1596 (component->Action == INSTALLSTATE_ABSENT) ||
1597 (component->Action == INSTALLSTATE_ADVERTISED))
1600 component->Action = INSTALLSTATE_SOURCE;
1601 component->ActionRequest = INSTALLSTATE_SOURCE;
1604 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
1606 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1607 (component->Action == INSTALLSTATE_ABSENT))
1610 component->Action = INSTALLSTATE_ADVERTISED;
1611 component->ActionRequest = INSTALLSTATE_ADVERTISED;
1614 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
1616 if (component->Action == INSTALLSTATE_UNKNOWN)
1618 component->Action = INSTALLSTATE_ABSENT;
1619 component->ActionRequest = INSTALLSTATE_ABSENT;
1626 LIST_FOR_EACH_ENTRY( component, &package->components, MSICOMPONENT, entry )
1628 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1629 debugstr_w(component->Component), component->Installed,
1630 component->Action, component->ActionRequest);
1634 return ERROR_SUCCESS;
1637 static UINT ITERATE_CostFinalizeDirectories(MSIRECORD *row, LPVOID param)
1639 MSIPACKAGE *package = (MSIPACKAGE*)param;
1643 name = MSI_RecordGetString(row,1);
1645 /* This helper function now does ALL the work */
1646 TRACE("Dir %s ...\n",debugstr_w(name));
1647 load_folder(package,name);
1648 path = resolve_folder(package,name,FALSE,TRUE,NULL);
1649 TRACE("resolves to %s\n",debugstr_w(path));
1650 HeapFree( GetProcessHeap(), 0, path);
1652 return ERROR_SUCCESS;
1655 static UINT ITERATE_CostFinalizeConditions(MSIRECORD *row, LPVOID param)
1657 MSIPACKAGE *package = (MSIPACKAGE*)param;
1659 MSIFEATURE *feature;
1661 name = MSI_RecordGetString( row, 1 );
1663 feature = get_loaded_feature( package, name );
1665 ERR("FAILED to find loaded feature %s\n",debugstr_w(name));
1669 Condition = MSI_RecordGetString(row,3);
1671 if (MSI_EvaluateConditionW(package,Condition) == MSICONDITION_TRUE)
1673 int level = MSI_RecordGetInteger(row,2);
1674 TRACE("Reseting feature %s to level %i\n", debugstr_w(name), level);
1675 feature->Level = level;
1678 return ERROR_SUCCESS;
1683 * A lot is done in this function aside from just the costing.
1684 * The costing needs to be implemented at some point but for now I am going
1685 * to focus on the directory building
1688 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
1690 static const WCHAR ExecSeqQuery[] =
1691 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1692 '`','D','i','r','e','c','t','o','r','y','`',0};
1693 static const WCHAR ConditionQuery[] =
1694 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1695 '`','C','o','n','d','i','t','i','o','n','`',0};
1696 static const WCHAR szCosting[] =
1697 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1698 static const WCHAR szlevel[] =
1699 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1700 static const WCHAR szOne[] = { '1', 0 };
1709 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1711 return ERROR_SUCCESS;
1713 TRACE("Building Directory properties\n");
1715 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1716 if (rc == ERROR_SUCCESS)
1718 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeDirectories,
1720 msiobj_release(&view->hdr);
1723 TRACE("File calculations\n");
1725 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
1727 MSICOMPONENT* comp = file->Component;
1733 /* calculate target */
1734 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
1736 HeapFree(GetProcessHeap(),0,file->TargetPath);
1738 TRACE("file %s is named %s\n",
1739 debugstr_w(file->File),debugstr_w(file->FileName));
1741 file->TargetPath = build_directory_name(2, p, file->FileName);
1743 HeapFree(GetProcessHeap(),0,p);
1745 TRACE("file %s resolves to %s\n",
1746 debugstr_w(file->File),debugstr_w(file->TargetPath));
1748 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
1751 comp->Cost += file->FileSize;
1761 static const WCHAR name[] =
1763 static const WCHAR name_fmt[] =
1764 {'%','u','.','%','u','.','%','u','.','%','u',0};
1765 WCHAR filever[0x100];
1766 VS_FIXEDFILEINFO *lpVer;
1768 TRACE("Version comparison.. \n");
1769 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
1770 version = HeapAlloc(GetProcessHeap(),0,versize);
1771 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
1773 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
1775 sprintfW(filever,name_fmt,
1776 HIWORD(lpVer->dwFileVersionMS),
1777 LOWORD(lpVer->dwFileVersionMS),
1778 HIWORD(lpVer->dwFileVersionLS),
1779 LOWORD(lpVer->dwFileVersionLS));
1781 TRACE("new %s old %s\n", debugstr_w(file->Version),
1782 debugstr_w(filever));
1783 if (strcmpiW(filever,file->Version)<0)
1786 FIXME("cost should be diff in size\n");
1787 comp->Cost += file->FileSize;
1791 HeapFree(GetProcessHeap(),0,version);
1797 TRACE("Evaluating Condition Table\n");
1799 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
1800 if (rc == ERROR_SUCCESS)
1802 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeConditions,
1804 msiobj_release(&view->hdr);
1807 TRACE("Enabling or Disabling Components\n");
1808 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1810 if (comp->Condition)
1812 if (MSI_EvaluateConditionW(package,
1813 comp->Condition) == MSICONDITION_FALSE)
1815 TRACE("Disabling component %s\n", debugstr_w(comp->Component));
1816 comp->Enabled = FALSE;
1821 MSI_SetPropertyW(package,szCosting,szOne);
1822 /* set default run level if not set */
1823 level = load_dynamic_property(package,szlevel,NULL);
1825 MSI_SetPropertyW(package,szlevel, szOne);
1826 HeapFree(GetProcessHeap(),0,level);
1828 ACTION_UpdateInstallStates(package);
1830 return SetFeatureStates(package);
1833 /* OK this value is "interpreted" and then formatted based on the
1834 first few characters */
1835 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
1839 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
1845 LPWSTR deformated = NULL;
1848 deformat_string(package, &value[2], &deformated);
1850 /* binary value type */
1854 *size = (strlenW(ptr)/2)+1;
1856 *size = strlenW(ptr)/2;
1858 data = HeapAlloc(GetProcessHeap(),0,*size);
1864 /* if uneven pad with a zero in front */
1870 data[count] = (BYTE)strtol(byte,NULL,0);
1872 TRACE("Uneven byte count\n");
1880 data[count] = (BYTE)strtol(byte,NULL,0);
1883 HeapFree(GetProcessHeap(),0,deformated);
1885 TRACE("Data %li bytes(%i)\n",*size,count);
1892 deformat_string(package, &value[1], &deformated);
1895 *size = sizeof(DWORD);
1896 data = HeapAlloc(GetProcessHeap(),0,*size);
1902 if ( (*p < '0') || (*p > '9') )
1908 if (deformated[0] == '-')
1911 TRACE("DWORD %li\n",*(LPDWORD)data);
1913 HeapFree(GetProcessHeap(),0,deformated);
1918 static const WCHAR szMulti[] = {'[','~',']',0};
1927 *type=REG_EXPAND_SZ;
1935 if (strstrW(value,szMulti))
1936 *type = REG_MULTI_SZ;
1938 *size = deformat_string(package, ptr,(LPWSTR*)&data);
1943 static UINT ITERATE_WriteRegistryValues(MSIRECORD *row, LPVOID param)
1945 MSIPACKAGE *package = (MSIPACKAGE*)param;
1946 static const WCHAR szHCR[] =
1947 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1948 'R','O','O','T','\\',0};
1949 static const WCHAR szHCU[] =
1950 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1951 'U','S','E','R','\\',0};
1952 static const WCHAR szHLM[] =
1953 {'H','K','E','Y','_','L','O','C','A','L','_',
1954 'M','A','C','H','I','N','E','\\',0};
1955 static const WCHAR szHU[] =
1956 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1958 LPSTR value_data = NULL;
1959 HKEY root_key, hkey;
1962 LPCWSTR szRoot, component, name, key, value;
1967 BOOL check_first = FALSE;
1970 ui_progress(package,2,0,0,0);
1977 component = MSI_RecordGetString(row, 6);
1978 comp = get_loaded_component(package,component);
1980 return ERROR_SUCCESS;
1982 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
1984 TRACE("Skipping write due to disabled component %s\n",
1985 debugstr_w(component));
1987 comp->Action = comp->Installed;
1989 return ERROR_SUCCESS;
1992 comp->Action = INSTALLSTATE_LOCAL;
1994 name = MSI_RecordGetString(row, 4);
1995 if( MSI_RecordIsNull(row,5) && name )
1997 /* null values can have special meanings */
1998 if (name[0]=='-' && name[1] == 0)
1999 return ERROR_SUCCESS;
2000 else if ((name[0]=='+' && name[1] == 0) ||
2001 (name[0] == '*' && name[1] == 0))
2006 root = MSI_RecordGetInteger(row,2);
2007 key = MSI_RecordGetString(row, 3);
2009 /* get the root key */
2014 static const WCHAR szALLUSER[] = {'A','L','L','U','S','E','R','S',0};
2015 LPWSTR all_users = load_dynamic_property(package, szALLUSER, NULL);
2016 if (all_users && all_users[0] == '1')
2018 root_key = HKEY_LOCAL_MACHINE;
2023 root_key = HKEY_CURRENT_USER;
2026 HeapFree(GetProcessHeap(),0,all_users);
2029 case 0: root_key = HKEY_CLASSES_ROOT;
2032 case 1: root_key = HKEY_CURRENT_USER;
2035 case 2: root_key = HKEY_LOCAL_MACHINE;
2038 case 3: root_key = HKEY_USERS;
2042 ERR("Unknown root %i\n",root);
2048 return ERROR_SUCCESS;
2050 deformat_string(package, key , &deformated);
2051 size = strlenW(deformated) + strlenW(szRoot) + 1;
2052 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
2053 strcpyW(uikey,szRoot);
2054 strcatW(uikey,deformated);
2056 if (RegCreateKeyW( root_key, deformated, &hkey))
2058 ERR("Could not create key %s\n",debugstr_w(deformated));
2059 HeapFree(GetProcessHeap(),0,deformated);
2060 HeapFree(GetProcessHeap(),0,uikey);
2061 return ERROR_SUCCESS;
2063 HeapFree(GetProcessHeap(),0,deformated);
2065 value = MSI_RecordGetString(row,5);
2067 value_data = parse_value(package, value, &type, &size);
2070 static const WCHAR szEmpty[] = {0};
2071 value_data = (LPSTR)strdupW(szEmpty);
2076 deformat_string(package, name, &deformated);
2078 /* get the double nulls to terminate SZ_MULTI */
2079 if (type == REG_MULTI_SZ)
2080 size +=sizeof(WCHAR);
2084 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
2086 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE)value_data, size);
2091 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
2092 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2094 TRACE("value %s of %s checked already exists\n",
2095 debugstr_w(deformated), debugstr_w(uikey));
2099 TRACE("Checked and setting value %s of %s\n",
2100 debugstr_w(deformated), debugstr_w(uikey));
2101 if (deformated || size)
2102 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE) value_data, size);
2107 uirow = MSI_CreateRecord(3);
2108 MSI_RecordSetStringW(uirow,2,deformated);
2109 MSI_RecordSetStringW(uirow,1,uikey);
2112 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2114 MSI_RecordSetStringW(uirow,3,value);
2116 ui_actiondata(package,szWriteRegistryValues,uirow);
2117 msiobj_release( &uirow->hdr );
2119 HeapFree(GetProcessHeap(),0,value_data);
2120 HeapFree(GetProcessHeap(),0,deformated);
2121 HeapFree(GetProcessHeap(),0,uikey);
2123 return ERROR_SUCCESS;
2126 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2130 static const WCHAR ExecSeqQuery[] =
2131 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2132 '`','R','e','g','i','s','t','r','y','`',0 };
2135 return ERROR_INVALID_HANDLE;
2137 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2138 if (rc != ERROR_SUCCESS)
2139 return ERROR_SUCCESS;
2141 /* increment progress bar each time action data is sent */
2142 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
2144 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteRegistryValues, package);
2146 msiobj_release(&view->hdr);
2150 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
2152 package->script->CurrentlyScripting = TRUE;
2154 return ERROR_SUCCESS;
2158 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
2163 static const WCHAR q1[]=
2164 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2165 '`','R','e','g','i','s','t','r','y','`',0};
2168 MSIRECORD * row = 0;
2169 MSIFEATURE *feature;
2172 TRACE(" InstallValidate \n");
2174 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
2175 if (rc != ERROR_SUCCESS)
2176 return ERROR_SUCCESS;
2178 rc = MSI_ViewExecute(view, 0);
2179 if (rc != ERROR_SUCCESS)
2181 MSI_ViewClose(view);
2182 msiobj_release(&view->hdr);
2187 rc = MSI_ViewFetch(view,&row);
2188 if (rc != ERROR_SUCCESS)
2195 msiobj_release(&row->hdr);
2197 MSI_ViewClose(view);
2198 msiobj_release(&view->hdr);
2200 total = total + progress * REG_PROGRESS_VALUE;
2201 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2203 total += COMPONENT_PROGRESS_VALUE;
2205 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2207 total += file->FileSize;
2209 ui_progress(package,0,total,0,0);
2211 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2213 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2214 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2215 feature->ActionRequest);
2218 return ERROR_SUCCESS;
2221 static UINT ITERATE_LaunchConditions(MSIRECORD *row, LPVOID param)
2223 MSIPACKAGE* package = (MSIPACKAGE*)param;
2224 LPCWSTR cond = NULL;
2225 LPCWSTR message = NULL;
2226 static const WCHAR title[]=
2227 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2229 cond = MSI_RecordGetString(row,1);
2231 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
2234 message = MSI_RecordGetString(row,2);
2235 deformat_string(package,message,&deformated);
2236 MessageBoxW(NULL,deformated,title,MB_OK);
2237 HeapFree(GetProcessHeap(),0,deformated);
2238 return ERROR_FUNCTION_FAILED;
2241 return ERROR_SUCCESS;
2244 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
2247 MSIQUERY * view = NULL;
2248 static const WCHAR ExecSeqQuery[] =
2249 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2250 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2252 TRACE("Checking launch conditions\n");
2254 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2255 if (rc != ERROR_SUCCESS)
2256 return ERROR_SUCCESS;
2258 rc = MSI_IterateRecords(view, NULL, ITERATE_LaunchConditions, package);
2259 msiobj_release(&view->hdr);
2264 static LPWSTR resolve_keypath( MSIPACKAGE* package, MSICOMPONENT *cmp )
2267 if (cmp->KeyPath[0]==0)
2269 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
2272 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
2274 MSIRECORD * row = 0;
2276 LPWSTR deformated,buffer,deformated_name;
2278 static const WCHAR ExecSeqQuery[] =
2279 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2280 '`','R','e','g','i','s','t','r','y','`',' ',
2281 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2282 ' ','=',' ' ,'\'','%','s','\'',0 };
2283 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
2284 static const WCHAR fmt2[]=
2285 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2287 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
2291 root = MSI_RecordGetInteger(row,2);
2292 key = MSI_RecordGetString(row, 3);
2293 name = MSI_RecordGetString(row, 4);
2294 deformat_string(package, key , &deformated);
2295 deformat_string(package, name, &deformated_name);
2297 len = strlenW(deformated) + 6;
2298 if (deformated_name)
2299 len+=strlenW(deformated_name);
2301 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
2303 if (deformated_name)
2304 sprintfW(buffer,fmt2,root,deformated,deformated_name);
2306 sprintfW(buffer,fmt,root,deformated);
2308 HeapFree(GetProcessHeap(),0,deformated);
2309 HeapFree(GetProcessHeap(),0,deformated_name);
2310 msiobj_release(&row->hdr);
2314 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
2316 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2321 MSIFILE *file = get_loaded_file( package, cmp->KeyPath );
2324 return strdupW( file->TargetPath );
2329 static HKEY openSharedDLLsKey(void)
2332 static const WCHAR path[] =
2333 {'S','o','f','t','w','a','r','e','\\',
2334 'M','i','c','r','o','s','o','f','t','\\',
2335 'W','i','n','d','o','w','s','\\',
2336 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2337 'S','h','a','r','e','d','D','L','L','s',0};
2339 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
2343 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
2348 DWORD sz = sizeof(count);
2351 hkey = openSharedDLLsKey();
2352 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
2353 if (rc != ERROR_SUCCESS)
2359 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
2363 hkey = openSharedDLLsKey();
2365 RegSetValueExW(hkey,path,0,REG_DWORD,
2366 (LPBYTE)&count,sizeof(count));
2368 RegDeleteValueW(hkey,path);
2374 * Return TRUE if the count should be written out and FALSE if not
2376 static void ACTION_RefCountComponent( MSIPACKAGE* package, MSICOMPONENT *comp )
2378 MSIFEATURE *feature;
2382 /* only refcount DLLs */
2383 if (comp->KeyPath[0]==0 ||
2384 comp->Attributes & msidbComponentAttributesRegistryKeyPath ||
2385 comp->Attributes & msidbComponentAttributesODBCDataSource)
2389 count = ACTION_GetSharedDLLsCount( comp->FullKeypath);
2390 write = (count > 0);
2392 if (comp->Attributes & msidbComponentAttributesSharedDllRefCount)
2396 /* increment counts */
2397 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2401 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ))
2404 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2406 if ( cl->component == comp )
2411 /* decrement counts */
2412 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2416 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ABSENT ))
2419 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2421 if ( cl->component == comp )
2426 /* ref count all the files in the component */
2431 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2433 if (file->Component == comp)
2434 ACTION_WriteSharedDLLsCount( file->TargetPath, count );
2438 /* add a count for permenent */
2439 if (comp->Attributes & msidbComponentAttributesPermanent)
2442 comp->RefCount = count;
2445 ACTION_WriteSharedDLLsCount( comp->FullKeypath, comp->RefCount );
2449 * Ok further analysis makes me think that this work is
2450 * actually done in the PublishComponents and PublishFeatures
2451 * step, and not here. It appears like the keypath and all that is
2452 * resolved in this step, however actually written in the Publish steps.
2453 * But we will leave it here for now because it is unclear
2455 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
2457 WCHAR squished_pc[GUID_SIZE];
2458 WCHAR squished_cc[GUID_SIZE];
2461 HKEY hkey=0,hkey2=0;
2464 return ERROR_INVALID_HANDLE;
2466 /* writes the Component and Features values to the registry */
2468 rc = MSIREG_OpenComponents(&hkey);
2469 if (rc != ERROR_SUCCESS)
2472 squash_guid(package->ProductCode,squished_pc);
2473 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
2475 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2477 ui_progress(package,2,0,0,0);
2478 if (comp->ComponentId[0]!=0)
2480 WCHAR *keypath = NULL;
2483 squash_guid(comp->ComponentId,squished_cc);
2485 keypath = resolve_keypath( package, comp );
2486 comp->FullKeypath = keypath;
2488 /* do the refcounting */
2489 ACTION_RefCountComponent( package, comp );
2491 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2492 debugstr_w(comp->Component),
2493 debugstr_w(squished_cc),
2494 debugstr_w(comp->FullKeypath),
2497 * Write the keypath out if the component is to be registered
2498 * and delete the key if the component is to be deregistered
2500 if (ACTION_VerifyComponentForAction(package, comp,
2501 INSTALLSTATE_LOCAL))
2503 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
2504 if (rc != ERROR_SUCCESS)
2509 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPBYTE)keypath,
2510 (strlenW(keypath)+1)*sizeof(WCHAR));
2512 if (comp->Attributes & msidbComponentAttributesPermanent)
2514 static const WCHAR szPermKey[] =
2515 { '0','0','0','0','0','0','0','0','0','0','0','0',
2516 '0','0','0','0','0','0','0', '0','0','0','0','0',
2517 '0','0','0','0','0','0','0','0',0};
2519 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
2521 (strlenW(keypath)+1)*sizeof(WCHAR));
2527 uirow = MSI_CreateRecord(3);
2528 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2529 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2530 MSI_RecordSetStringW(uirow,3,keypath);
2531 ui_actiondata(package,szProcessComponents,uirow);
2532 msiobj_release( &uirow->hdr );
2535 else if (ACTION_VerifyComponentForAction(package, comp,
2536 INSTALLSTATE_ABSENT))
2540 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
2541 if (rc != ERROR_SUCCESS)
2544 RegDeleteValueW(hkey2,squished_pc);
2546 /* if the key is empty delete it */
2547 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
2549 if (res == ERROR_NO_MORE_ITEMS)
2550 RegDeleteKeyW(hkey,squished_cc);
2553 uirow = MSI_CreateRecord(2);
2554 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2555 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2556 ui_actiondata(package,szProcessComponents,uirow);
2557 msiobj_release( &uirow->hdr );
2574 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
2575 LPWSTR lpszName, LONG_PTR lParam)
2578 typelib_struct *tl_struct = (typelib_struct*) lParam;
2579 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
2583 if (!IS_INTRESOURCE(lpszName))
2585 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
2589 sz = strlenW(tl_struct->source)+4;
2590 sz *= sizeof(WCHAR);
2592 if ((INT)lpszName == 1)
2593 tl_struct->path = strdupW(tl_struct->source);
2596 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
2597 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
2600 TRACE("trying %s\n", debugstr_w(tl_struct->path));
2601 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
2602 if (!SUCCEEDED(res))
2604 HeapFree(GetProcessHeap(),0,tl_struct->path);
2605 tl_struct->path = NULL;
2610 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
2611 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
2613 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2617 HeapFree(GetProcessHeap(),0,tl_struct->path);
2618 tl_struct->path = NULL;
2620 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2621 ITypeLib_Release(tl_struct->ptLib);
2626 static UINT ITERATE_RegisterTypeLibraries(MSIRECORD *row, LPVOID param)
2628 MSIPACKAGE* package = (MSIPACKAGE*)param;
2632 typelib_struct tl_struct;
2634 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
2636 component = MSI_RecordGetString(row,3);
2637 comp = get_loaded_component(package,component);
2639 return ERROR_SUCCESS;
2641 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2643 TRACE("Skipping typelib reg due to disabled component\n");
2645 comp->Action = comp->Installed;
2647 return ERROR_SUCCESS;
2650 comp->Action = INSTALLSTATE_LOCAL;
2652 file = get_loaded_file( package, comp->KeyPath );
2654 return ERROR_SUCCESS;
2656 module = LoadLibraryExW( file->TargetPath, NULL, LOAD_LIBRARY_AS_DATAFILE );
2660 guid = load_dynamic_stringW(row,1);
2661 CLSIDFromString(guid, &tl_struct.clsid);
2662 HeapFree(GetProcessHeap(),0,guid);
2663 tl_struct.source = strdupW( file->TargetPath );
2664 tl_struct.path = NULL;
2666 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
2667 (LONG_PTR)&tl_struct);
2669 if (tl_struct.path != NULL)
2675 helpid = MSI_RecordGetString(row,6);
2678 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
2679 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
2680 HeapFree(GetProcessHeap(),0,help);
2682 if (!SUCCEEDED(res))
2683 ERR("Failed to register type library %s\n",
2684 debugstr_w(tl_struct.path));
2687 ui_actiondata(package,szRegisterTypeLibraries,row);
2689 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
2692 ITypeLib_Release(tl_struct.ptLib);
2693 HeapFree(GetProcessHeap(),0,tl_struct.path);
2696 ERR("Failed to load type library %s\n",
2697 debugstr_w(tl_struct.source));
2699 FreeLibrary(module);
2700 HeapFree(GetProcessHeap(),0,tl_struct.source);
2703 ERR("Could not load file! %s\n", debugstr_w(file->TargetPath));
2705 return ERROR_SUCCESS;
2708 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
2711 * OK this is a bit confusing.. I am given a _Component key and I believe
2712 * that the file that is being registered as a type library is the "key file
2713 * of that component" which I interpret to mean "The file in the KeyPath of
2718 static const WCHAR Query[] =
2719 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2720 '`','T','y','p','e','L','i','b','`',0};
2723 return ERROR_INVALID_HANDLE;
2725 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2726 if (rc != ERROR_SUCCESS)
2727 return ERROR_SUCCESS;
2729 rc = MSI_IterateRecords(view, NULL, ITERATE_RegisterTypeLibraries, package);
2730 msiobj_release(&view->hdr);
2734 static UINT ITERATE_CreateShortcuts(MSIRECORD *row, LPVOID param)
2736 MSIPACKAGE *package = (MSIPACKAGE*)param;
2737 LPWSTR target_file, target_folder;
2739 WCHAR filename[0x100];
2742 static const WCHAR szlnk[]={'.','l','n','k',0};
2747 buffer = MSI_RecordGetString(row,4);
2748 comp = get_loaded_component(package,buffer);
2750 return ERROR_SUCCESS;
2752 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2754 TRACE("Skipping shortcut creation due to disabled component\n");
2756 comp->Action = comp->Installed;
2758 return ERROR_SUCCESS;
2761 comp->Action = INSTALLSTATE_LOCAL;
2763 ui_actiondata(package,szCreateShortcuts,row);
2765 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2766 &IID_IShellLinkW, (LPVOID *) &sl );
2770 ERR("Is IID_IShellLink\n");
2771 return ERROR_SUCCESS;
2774 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
2777 ERR("Is IID_IPersistFile\n");
2778 return ERROR_SUCCESS;
2781 buffer = MSI_RecordGetString(row,2);
2782 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
2784 /* may be needed because of a bug somehwere else */
2785 create_full_pathW(target_folder);
2788 MSI_RecordGetStringW(row,3,filename,&sz);
2789 reduce_to_longfilename(filename);
2790 if (!strchrW(filename,'.') || strcmpiW(strchrW(filename,'.'),szlnk))
2791 strcatW(filename,szlnk);
2792 target_file = build_directory_name(2, target_folder, filename);
2793 HeapFree(GetProcessHeap(),0,target_folder);
2795 buffer = MSI_RecordGetString(row,5);
2796 if (strchrW(buffer,'['))
2799 deformat_string(package,buffer,&deformated);
2800 IShellLinkW_SetPath(sl,deformated);
2801 HeapFree(GetProcessHeap(),0,deformated);
2806 FIXME("poorly handled shortcut format, advertised shortcut\n");
2807 keypath = strdupW( comp->FullKeypath );
2808 IShellLinkW_SetPath(sl,keypath);
2809 HeapFree(GetProcessHeap(),0,keypath);
2812 if (!MSI_RecordIsNull(row,6))
2815 buffer = MSI_RecordGetString(row,6);
2816 deformat_string(package,buffer,&deformated);
2817 IShellLinkW_SetArguments(sl,deformated);
2818 HeapFree(GetProcessHeap(),0,deformated);
2821 if (!MSI_RecordIsNull(row,7))
2823 buffer = MSI_RecordGetString(row,7);
2824 IShellLinkW_SetDescription(sl,buffer);
2827 if (!MSI_RecordIsNull(row,8))
2828 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
2830 if (!MSI_RecordIsNull(row,9))
2835 buffer = MSI_RecordGetString(row,9);
2837 build_icon_path(package,buffer,&Path);
2838 index = MSI_RecordGetInteger(row,10);
2840 IShellLinkW_SetIconLocation(sl,Path,index);
2841 HeapFree(GetProcessHeap(),0,Path);
2844 if (!MSI_RecordIsNull(row,11))
2845 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
2847 if (!MSI_RecordIsNull(row,12))
2850 buffer = MSI_RecordGetString(row,12);
2851 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
2852 IShellLinkW_SetWorkingDirectory(sl,Path);
2853 HeapFree(GetProcessHeap(), 0, Path);
2856 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
2857 IPersistFile_Save(pf,target_file,FALSE);
2859 HeapFree(GetProcessHeap(),0,target_file);
2861 IPersistFile_Release( pf );
2862 IShellLinkW_Release( sl );
2864 return ERROR_SUCCESS;
2867 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
2872 static const WCHAR Query[] =
2873 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2874 '`','S','h','o','r','t','c','u','t','`',0};
2877 return ERROR_INVALID_HANDLE;
2879 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2880 if (rc != ERROR_SUCCESS)
2881 return ERROR_SUCCESS;
2883 res = CoInitialize( NULL );
2886 ERR("CoInitialize failed\n");
2887 return ERROR_FUNCTION_FAILED;
2890 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateShortcuts, package);
2891 msiobj_release(&view->hdr);
2898 static UINT ITERATE_PublishProduct(MSIRECORD *row, LPVOID param)
2900 MSIPACKAGE* package = (MSIPACKAGE*)param;
2902 LPWSTR FilePath=NULL;
2903 LPCWSTR FileName=NULL;
2908 FileName = MSI_RecordGetString(row,1);
2911 ERR("Unable to get FileName\n");
2912 return ERROR_SUCCESS;
2915 build_icon_path(package,FileName,&FilePath);
2917 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
2919 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2920 FILE_ATTRIBUTE_NORMAL, NULL);
2922 if (the_file == INVALID_HANDLE_VALUE)
2924 ERR("Unable to create file %s\n",debugstr_w(FilePath));
2925 HeapFree(GetProcessHeap(),0,FilePath);
2926 return ERROR_SUCCESS;
2933 rc = MSI_RecordReadStream(row,2,buffer,&sz);
2934 if (rc != ERROR_SUCCESS)
2936 ERR("Failed to get stream\n");
2937 CloseHandle(the_file);
2938 DeleteFileW(FilePath);
2941 WriteFile(the_file,buffer,sz,&write,NULL);
2942 } while (sz == 1024);
2944 HeapFree(GetProcessHeap(),0,FilePath);
2946 CloseHandle(the_file);
2947 return ERROR_SUCCESS;
2951 * 99% of the work done here is only done for
2952 * advertised installs. However this is where the
2953 * Icon table is processed and written out
2954 * so that is what I am going to do here.
2956 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
2960 static const WCHAR Query[]=
2961 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2962 '`','I','c','o','n','`',0};
2963 /* for registry stuff */
2966 static const WCHAR szProductLanguage[] =
2967 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
2968 static const WCHAR szARPProductIcon[] =
2969 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
2970 static const WCHAR szProductVersion[] =
2971 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
2975 MSIHANDLE hDb, hSumInfo;
2978 return ERROR_INVALID_HANDLE;
2980 /* write out icon files */
2982 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2983 if (rc == ERROR_SUCCESS)
2985 MSI_IterateRecords(view, NULL, ITERATE_PublishProduct, package);
2986 msiobj_release(&view->hdr);
2989 /* ok there is a lot more done here but i need to figure out what */
2991 rc = MSIREG_OpenProductsKey(package->ProductCode,&hkey,TRUE);
2992 if (rc != ERROR_SUCCESS)
2995 rc = MSIREG_OpenUserProductsKey(package->ProductCode,&hukey,TRUE);
2996 if (rc != ERROR_SUCCESS)
3000 buffer = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTNAMEW,NULL);
3001 size = strlenW(buffer)*sizeof(WCHAR);
3002 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTNAMEW,0,REG_SZ,
3003 (LPBYTE)buffer,size);
3004 HeapFree(GetProcessHeap(),0,buffer);
3006 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3007 size = sizeof(DWORD);
3008 langid = atoiW(buffer);
3009 RegSetValueExW(hukey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3010 (LPBYTE)&langid,size);
3011 HeapFree(GetProcessHeap(),0,buffer);
3013 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
3017 build_icon_path(package,buffer,&path);
3018 size = strlenW(path) * sizeof(WCHAR);
3019 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTICONW,0,REG_SZ,
3022 HeapFree(GetProcessHeap(),0,buffer);
3024 buffer = load_dynamic_property(package,szProductVersion,NULL);
3027 DWORD verdword = build_version_dword(buffer);
3028 size = sizeof(DWORD);
3029 RegSetValueExW(hukey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD, (LPBYTE
3032 HeapFree(GetProcessHeap(),0,buffer);
3034 FIXME("Need to write more keys to the user registry\n");
3036 hDb= alloc_msihandle( &package->db->hdr );
3037 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
3038 MsiCloseHandle(hDb);
3039 if (rc == ERROR_SUCCESS)
3041 WCHAR guidbuffer[0x200];
3043 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
3045 if (rc == ERROR_SUCCESS)
3047 WCHAR squashed[GUID_SIZE];
3048 /* for now we only care about the first guid */
3049 LPWSTR ptr = strchrW(guidbuffer,';');
3051 squash_guid(guidbuffer,squashed);
3052 size = strlenW(squashed)*sizeof(WCHAR);
3053 RegSetValueExW(hukey,INSTALLPROPERTY_PACKAGECODEW,0,REG_SZ,
3054 (LPBYTE)squashed, size);
3058 ERR("Unable to query Revision_Number... \n");
3061 MsiCloseHandle(hSumInfo);
3065 ERR("Unable to open Summary Information\n");
3077 static UINT ITERATE_WriteIniValues(MSIRECORD *row, LPVOID param)
3079 MSIPACKAGE *package = (MSIPACKAGE*)param;
3080 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
3081 LPWSTR deformated_section, deformated_key, deformated_value;
3082 LPWSTR folder, fullname = NULL;
3086 static const WCHAR szWindowsFolder[] =
3087 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3089 component = MSI_RecordGetString(row, 8);
3090 comp = get_loaded_component(package,component);
3092 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
3094 TRACE("Skipping ini file due to disabled component %s\n",
3095 debugstr_w(component));
3097 comp->Action = comp->Installed;
3099 return ERROR_SUCCESS;
3102 comp->Action = INSTALLSTATE_LOCAL;
3104 identifier = MSI_RecordGetString(row,1);
3105 filename = MSI_RecordGetString(row,2);
3106 dirproperty = MSI_RecordGetString(row,3);
3107 section = MSI_RecordGetString(row,4);
3108 key = MSI_RecordGetString(row,5);
3109 value = MSI_RecordGetString(row,6);
3110 action = MSI_RecordGetInteger(row,7);
3112 deformat_string(package,section,&deformated_section);
3113 deformat_string(package,key,&deformated_key);
3114 deformat_string(package,value,&deformated_value);
3118 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
3120 folder = load_dynamic_property(package,dirproperty,NULL);
3123 folder = load_dynamic_property(package, szWindowsFolder, NULL);
3127 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
3131 fullname = build_directory_name(2, folder, filename);
3135 TRACE("Adding value %s to section %s in %s\n",
3136 debugstr_w(deformated_key), debugstr_w(deformated_section),
3137 debugstr_w(fullname));
3138 WritePrivateProfileStringW(deformated_section, deformated_key,
3139 deformated_value, fullname);
3141 else if (action == 1)
3144 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
3145 returned, 10, fullname);
3146 if (returned[0] == 0)
3148 TRACE("Adding value %s to section %s in %s\n",
3149 debugstr_w(deformated_key), debugstr_w(deformated_section),
3150 debugstr_w(fullname));
3152 WritePrivateProfileStringW(deformated_section, deformated_key,
3153 deformated_value, fullname);
3156 else if (action == 3)
3157 FIXME("Append to existing section not yet implemented\n");
3159 uirow = MSI_CreateRecord(4);
3160 MSI_RecordSetStringW(uirow,1,identifier);
3161 MSI_RecordSetStringW(uirow,2,deformated_section);
3162 MSI_RecordSetStringW(uirow,3,deformated_key);
3163 MSI_RecordSetStringW(uirow,4,deformated_value);
3164 ui_actiondata(package,szWriteIniValues,uirow);
3165 msiobj_release( &uirow->hdr );
3167 HeapFree(GetProcessHeap(),0,fullname);
3168 HeapFree(GetProcessHeap(),0,folder);
3169 HeapFree(GetProcessHeap(),0,deformated_key);
3170 HeapFree(GetProcessHeap(),0,deformated_value);
3171 HeapFree(GetProcessHeap(),0,deformated_section);
3172 return ERROR_SUCCESS;
3175 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
3179 static const WCHAR ExecSeqQuery[] =
3180 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3181 '`','I','n','i','F','i','l','e','`',0};
3183 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3184 if (rc != ERROR_SUCCESS)
3186 TRACE("no IniFile table\n");
3187 return ERROR_SUCCESS;
3190 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteIniValues, package);
3191 msiobj_release(&view->hdr);
3195 static UINT ITERATE_SelfRegModules(MSIRECORD *row, LPVOID param)
3197 MSIPACKAGE *package = (MSIPACKAGE*)param;
3202 static const WCHAR ExeStr[] =
3203 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3204 static const WCHAR close[] = {'\"',0};
3206 PROCESS_INFORMATION info;
3209 memset(&si,0,sizeof(STARTUPINFOW));
3211 filename = MSI_RecordGetString(row,1);
3212 file = get_loaded_file( package, filename );
3216 ERR("Unable to find file id %s\n",debugstr_w(filename));
3217 return ERROR_SUCCESS;
3220 len = strlenW(ExeStr) + strlenW( file->TargetPath ) + 2;
3222 FullName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3223 strcpyW(FullName,ExeStr);
3224 strcatW( FullName, file->TargetPath );
3225 strcatW(FullName,close);
3227 TRACE("Registering %s\n",debugstr_w(FullName));
3228 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL, c_colon,
3232 msi_dialog_check_messages(info.hProcess);
3234 HeapFree(GetProcessHeap(),0,FullName);
3235 return ERROR_SUCCESS;
3238 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
3242 static const WCHAR ExecSeqQuery[] =
3243 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3244 '`','S','e','l','f','R','e','g','`',0};
3246 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3247 if (rc != ERROR_SUCCESS)
3249 TRACE("no SelfReg table\n");
3250 return ERROR_SUCCESS;
3253 MSI_IterateRecords(view, NULL, ITERATE_SelfRegModules, package);
3254 msiobj_release(&view->hdr);
3256 return ERROR_SUCCESS;
3259 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
3261 MSIFEATURE *feature;
3267 return ERROR_INVALID_HANDLE;
3269 rc = MSIREG_OpenFeaturesKey(package->ProductCode,&hkey,TRUE);
3270 if (rc != ERROR_SUCCESS)
3273 rc = MSIREG_OpenUserFeaturesKey(package->ProductCode,&hukey,TRUE);
3274 if (rc != ERROR_SUCCESS)
3277 /* here the guids are base 85 encoded */
3278 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
3284 BOOL absent = FALSE;
3286 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ) &&
3287 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_SOURCE ) &&
3288 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED ))
3292 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3296 if (feature->Feature_Parent[0])
3297 size += strlenW( feature->Feature_Parent )+2;
3299 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
3302 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3304 MSICOMPONENT* component = cl->component;
3307 memset(buf,0,sizeof(buf));
3308 if ( component->ComponentId[0] )
3310 TRACE("From %s\n",debugstr_w(component->ComponentId));
3311 CLSIDFromString(component->ComponentId, &clsid);
3312 encode_base85_guid(&clsid,buf);
3313 TRACE("to %s\n",debugstr_w(buf));
3317 if (feature->Feature_Parent[0])
3319 static const WCHAR sep[] = {'\2',0};
3321 strcatW(data,feature->Feature_Parent);
3324 size = (strlenW(data)+1)*sizeof(WCHAR);
3325 RegSetValueExW( hkey, feature->Feature, 0, REG_SZ, (LPBYTE)data,size );
3326 HeapFree(GetProcessHeap(),0,data);
3330 size = strlenW(feature->Feature_Parent)*sizeof(WCHAR);
3331 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3332 (LPBYTE)feature->Feature_Parent,size);
3336 size = (strlenW(feature->Feature_Parent)+2)* sizeof(WCHAR);
3337 data = HeapAlloc(GetProcessHeap(),0,size);
3339 strcpyW( &data[1], feature->Feature_Parent );
3340 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3342 HeapFree(GetProcessHeap(),0,data);
3352 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
3355 LPWSTR buffer = NULL;
3358 static WCHAR szNONE[] = {0};
3359 static const WCHAR szWindowsInstaler[] =
3360 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3361 static const WCHAR szPropKeys[][80] =
3363 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3364 {'A','R','P','C','O','N','T','A','C','T',0},
3365 {'A','R','P','C','O','M','M','E','N','T','S',0},
3366 {'P','r','o','d','u','c','t','N','a','m','e',0},
3367 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3368 {'A','R','P','H','E','L','P','L','I','N','K',0},
3369 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3370 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3371 {'S','o','u','r','c','e','D','i','r',0},
3372 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3373 {'A','R','P','R','E','A','D','M','E',0},
3374 {'A','R','P','S','I','Z','E',0},
3375 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3376 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3380 static const WCHAR szRegKeys[][80] =
3382 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3383 {'C','o','n','t','a','c','t',0},
3384 {'C','o','m','m','e','n','t','s',0},
3385 {'D','i','s','p','l','a','y','N','a','m','e',0},
3386 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3387 {'H','e','l','p','L','i','n','k',0},
3388 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3389 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3390 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3391 {'P','u','b','l','i','s','h','e','r',0},
3392 {'R','e','a','d','m','e',0},
3393 {'S','i','z','e',0},
3394 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3395 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3399 static const WCHAR installerPathFmt[] = {
3401 'I','n','s','t','a','l','l','e','r','\\',0};
3402 static const WCHAR fmt[] = {
3404 'I','n','s','t','a','l','l','e','r','\\',
3405 '%','x','.','m','s','i',0};
3406 static const WCHAR szUpgradeCode[] =
3407 {'U','p','g','r','a','d','e','C','o','d','e',0};
3408 static const WCHAR modpath_fmt[] =
3409 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3410 static const WCHAR szModifyPath[] =
3411 {'M','o','d','i','f','y','P','a','t','h',0};
3412 static const WCHAR szUninstallString[] =
3413 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3414 static const WCHAR szEstimatedSize[] =
3415 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3416 static const WCHAR szProductLanguage[] =
3417 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3418 static const WCHAR szProductVersion[] =
3419 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3422 static const WCHAR date_fmt[] = {'%','i','%','i','%','i',0};
3423 LPWSTR upgrade_code;
3424 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
3428 return ERROR_INVALID_HANDLE;
3430 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3431 if (rc != ERROR_SUCCESS)
3434 /* dump all the info i can grab */
3435 FIXME("Flesh out more information \n");
3438 while (szPropKeys[i][0]!=0)
3440 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3441 if (rc != ERROR_SUCCESS)
3443 size = strlenW(buffer)*sizeof(WCHAR);
3444 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3445 HeapFree(GetProcessHeap(),0,buffer);
3451 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPBYTE)&rc,size);
3453 /* copy the package locally */
3454 num = GetTickCount() & 0xffff;
3458 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
3459 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
3463 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
3464 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
3465 if (handle != INVALID_HANDLE_VALUE)
3467 CloseHandle(handle);
3470 if (GetLastError() != ERROR_FILE_EXISTS &&
3471 GetLastError() != ERROR_SHARING_VIOLATION)
3473 if (!(++num & 0xffff)) num = 1;
3474 sprintfW(packagefile,fmt,num);
3475 } while (num != start);
3477 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
3478 create_full_pathW(path);
3479 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
3480 if (!CopyFileW(package->msiFilePath,packagefile,FALSE))
3481 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3482 debugstr_w(package->msiFilePath), debugstr_w(packagefile),
3484 size = strlenW(packagefile)*sizeof(WCHAR);
3485 RegSetValueExW(hkey,INSTALLPROPERTY_LOCALPACKAGEW,0,REG_SZ,
3486 (LPBYTE)packagefile,size);
3488 /* do ModifyPath and UninstallString */
3489 size = deformat_string(package,modpath_fmt,&buffer);
3490 RegSetValueExW(hkey,szModifyPath,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3491 RegSetValueExW(hkey,szUninstallString,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3492 HeapFree(GetProcessHeap(),0,buffer);
3494 FIXME("Write real Estimated Size when we have it\n");
3496 RegSetValueExW(hkey,szEstimatedSize,0,REG_DWORD,(LPBYTE)&size,sizeof(DWORD));
3498 GetLocalTime(&systime);
3499 size = 9*sizeof(WCHAR);
3500 buffer= HeapAlloc(GetProcessHeap(),0,size);
3501 sprintfW(buffer,date_fmt,systime.wYear,systime.wMonth,systime.wDay);
3502 size = strlenW(buffer)*sizeof(WCHAR);
3503 RegSetValueExW(hkey,INSTALLPROPERTY_INSTALLDATEW,0,REG_SZ,
3504 (LPBYTE)buffer,size);
3505 HeapFree(GetProcessHeap(),0,buffer);
3507 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3508 size = atoiW(buffer);
3509 RegSetValueExW(hkey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3510 (LPBYTE)&size,sizeof(DWORD));
3511 HeapFree(GetProcessHeap(),1,buffer);
3513 buffer = load_dynamic_property(package,szProductVersion,NULL);
3516 DWORD verdword = build_version_dword(buffer);
3517 DWORD vermajor = verdword>>24;
3518 DWORD verminor = (verdword>>16)&0x00FF;
3519 size = sizeof(DWORD);
3520 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD,
3521 (LPBYTE)&verdword,size);
3522 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMAJORW,0,REG_DWORD,
3523 (LPBYTE)&vermajor,size);
3524 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMINORW,0,REG_DWORD,
3525 (LPBYTE)&verminor,size);
3527 HeapFree(GetProcessHeap(),0,buffer);
3529 /* Handle Upgrade Codes */
3530 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
3535 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3536 squash_guid(package->ProductCode,squashed);
3537 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3539 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3540 squash_guid(package->ProductCode,squashed);
3541 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3544 HeapFree(GetProcessHeap(),0,upgrade_code);
3550 return ERROR_SUCCESS;
3553 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
3558 return ERROR_INVALID_HANDLE;
3560 rc = execute_script(package,INSTALL_SCRIPT);
3565 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
3570 return ERROR_INVALID_HANDLE;
3572 /* turn off scheduleing */
3573 package->script->CurrentlyScripting= FALSE;
3575 /* first do the same as an InstallExecute */
3576 rc = ACTION_InstallExecute(package);
3577 if (rc != ERROR_SUCCESS)
3580 /* then handle Commit Actions */
3581 rc = execute_script(package,COMMIT_SCRIPT);
3586 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
3588 static const WCHAR RunOnce[] = {
3589 'S','o','f','t','w','a','r','e','\\',
3590 'M','i','c','r','o','s','o','f','t','\\',
3591 'W','i','n','d','o','w','s','\\',
3592 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3593 'R','u','n','O','n','c','e',0};
3594 static const WCHAR InstallRunOnce[] = {
3595 'S','o','f','t','w','a','r','e','\\',
3596 'M','i','c','r','o','s','o','f','t','\\',
3597 'W','i','n','d','o','w','s','\\',
3598 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3599 'I','n','s','t','a','l','l','e','r','\\',
3600 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3602 static const WCHAR msiexec_fmt[] = {
3604 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3605 '\"','%','s','\"',0};
3606 static const WCHAR install_fmt[] = {
3607 '/','I',' ','\"','%','s','\"',' ',
3608 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3609 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3610 WCHAR buffer[256], sysdir[MAX_PATH];
3612 WCHAR squished_pc[100];
3616 return ERROR_INVALID_HANDLE;
3618 squash_guid(package->ProductCode,squished_pc);
3620 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
3621 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
3622 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
3625 size = strlenW(buffer)*sizeof(WCHAR);
3626 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3629 TRACE("Reboot command %s\n",debugstr_w(buffer));
3631 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
3632 sprintfW(buffer,install_fmt,package->ProductCode,squished_pc);
3634 size = strlenW(buffer)*sizeof(WCHAR);
3635 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3638 return ERROR_INSTALL_SUSPEND;
3641 UINT ACTION_ResolveSource(MSIPACKAGE* package)
3646 * we are currently doing what should be done here in the top level Install
3647 * however for Adminastrative and uninstalls this step will be needed
3649 if (!package->PackagePath)
3650 return ERROR_SUCCESS;
3652 attrib = GetFileAttributesW(package->PackagePath);
3653 if (attrib == INVALID_FILE_ATTRIBUTES)
3659 rc = MsiSourceListGetInfoW(package->ProductCode, NULL,
3660 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3661 INSTALLPROPERTY_DISKPROMPTW,NULL,&size);
3662 if (rc == ERROR_MORE_DATA)
3664 prompt = HeapAlloc(GetProcessHeap(),0,size * sizeof(WCHAR));
3665 MsiSourceListGetInfoW(package->ProductCode, NULL,
3666 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3667 INSTALLPROPERTY_DISKPROMPTW,prompt,&size);
3670 prompt = strdupW(package->PackagePath);
3672 msg = generate_error_string(package,1302,1,prompt);
3673 while(attrib == INVALID_FILE_ATTRIBUTES)
3675 rc = MessageBoxW(NULL,msg,NULL,MB_OKCANCEL);
3678 rc = ERROR_INSTALL_USEREXIT;
3681 attrib = GetFileAttributesW(package->PackagePath);
3683 HeapFree(GetProcessHeap(),0,prompt);
3687 return ERROR_SUCCESS;
3692 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
3700 static const WCHAR szPropKeys[][80] =
3702 {'P','r','o','d','u','c','t','I','D',0},
3703 {'U','S','E','R','N','A','M','E',0},
3704 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3708 static const WCHAR szRegKeys[][80] =
3710 {'P','r','o','d','u','c','t','I','D',0},
3711 {'R','e','g','O','w','n','e','r',0},
3712 {'R','e','g','C','o','m','p','a','n','y',0},
3717 return ERROR_INVALID_HANDLE;
3719 productid = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTIDW, &rc);
3721 return ERROR_SUCCESS;
3723 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3724 if (rc != ERROR_SUCCESS)
3728 while (szPropKeys[i][0]!=0)
3730 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3731 if (rc == ERROR_SUCCESS)
3733 size = strlenW(buffer)*sizeof(WCHAR);
3734 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3737 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
3742 HeapFree(GetProcessHeap(),0,productid);
3745 return ERROR_SUCCESS;
3749 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
3751 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
3752 static const WCHAR szTwo[] = {'2',0};
3755 level = load_dynamic_property(package,szUILevel,NULL);
3757 MSI_SetPropertyW(package,szUILevel,szTwo);
3758 package->script->InWhatSequence |= SEQUENCE_EXEC;
3759 rc = ACTION_ProcessExecSequence(package,FALSE);
3760 MSI_SetPropertyW(package,szUILevel,level);
3761 HeapFree(GetProcessHeap(),0,level);
3767 * Code based off of code located here
3768 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3770 * Using string index 4 (full font name) instead of 1 (family name)
3772 static LPWSTR load_ttfname_from(LPCWSTR filename)
3778 typedef struct _tagTT_OFFSET_TABLE{
3779 USHORT uMajorVersion;
3780 USHORT uMinorVersion;
3781 USHORT uNumOfTables;
3782 USHORT uSearchRange;
3783 USHORT uEntrySelector;
3787 typedef struct _tagTT_TABLE_DIRECTORY{
3788 char szTag[4]; /* table name */
3789 ULONG uCheckSum; /* Check sum */
3790 ULONG uOffset; /* Offset from beginning of file */
3791 ULONG uLength; /* length of the table in bytes */
3792 }TT_TABLE_DIRECTORY;
3794 typedef struct _tagTT_NAME_TABLE_HEADER{
3795 USHORT uFSelector; /* format selector. Always 0 */
3796 USHORT uNRCount; /* Name Records count */
3797 USHORT uStorageOffset; /* Offset for strings storage,
3798 * from start of the table */
3799 }TT_NAME_TABLE_HEADER;
3801 typedef struct _tagTT_NAME_RECORD{
3806 USHORT uStringLength;
3807 USHORT uStringOffset; /* from start of storage area */
3810 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3811 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3813 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
3814 FILE_ATTRIBUTE_NORMAL, 0 );
3815 if (handle != INVALID_HANDLE_VALUE)
3817 TT_TABLE_DIRECTORY tblDir;
3818 BOOL bFound = FALSE;
3819 TT_OFFSET_TABLE ttOffsetTable;
3821 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
3822 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
3823 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
3824 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
3826 if (ttOffsetTable.uMajorVersion != 1 ||
3827 ttOffsetTable.uMinorVersion != 0)
3830 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
3832 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
3833 if (strncmp(tblDir.szTag,"name",4)==0)
3836 tblDir.uLength = SWAPLONG(tblDir.uLength);
3837 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
3844 TT_NAME_TABLE_HEADER ttNTHeader;
3845 TT_NAME_RECORD ttRecord;
3847 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
3848 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
3851 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
3852 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
3854 for(i=0; i<ttNTHeader.uNRCount; i++)
3856 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
3857 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
3858 /* 4 is the Full Font Name */
3859 if(ttRecord.uNameID == 4)
3863 static LPCSTR tt = " (TrueType)";
3865 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
3866 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
3867 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
3868 SetFilePointer(handle, tblDir.uOffset +
3869 ttRecord.uStringOffset +
3870 ttNTHeader.uStorageOffset,
3872 buf = HeapAlloc(GetProcessHeap(), 0,
3873 ttRecord.uStringLength + 1 + strlen(tt));
3874 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
3875 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
3876 if (strlen(buf) > 0)
3879 ret = strdupAtoW(buf);
3880 HeapFree(GetProcessHeap(),0,buf);
3884 HeapFree(GetProcessHeap(),0,buf);
3885 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
3889 CloseHandle(handle);
3892 ERR("Unable to open font file %s\n", debugstr_w(filename));
3894 TRACE("Returning fontname %s\n",debugstr_w(ret));
3898 static UINT ITERATE_RegisterFonts(MSIRECORD *row, LPVOID param)
3900 MSIPACKAGE *package = (MSIPACKAGE*)param;
3905 static const WCHAR regfont1[] =
3906 {'S','o','f','t','w','a','r','e','\\',
3907 'M','i','c','r','o','s','o','f','t','\\',
3908 'W','i','n','d','o','w','s',' ','N','T','\\',
3909 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3910 'F','o','n','t','s',0};
3911 static const WCHAR regfont2[] =
3912 {'S','o','f','t','w','a','r','e','\\',
3913 'M','i','c','r','o','s','o','f','t','\\',
3914 'W','i','n','d','o','w','s','\\',
3915 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3916 'F','o','n','t','s',0};
3920 filename = MSI_RecordGetString( row, 1 );
3921 file = get_loaded_file( package, filename );
3924 ERR("Unable to load file\n");
3925 return ERROR_SUCCESS;
3928 /* check to make sure that component is installed */
3929 if (!ACTION_VerifyComponentForAction(package,
3930 file->Component, INSTALLSTATE_LOCAL))
3932 TRACE("Skipping: Component not scheduled for install\n");
3933 return ERROR_SUCCESS;
3936 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
3937 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
3939 if (MSI_RecordIsNull(row,2))
3940 name = load_ttfname_from( file->TargetPath );
3942 name = load_dynamic_stringW(row,2);
3946 size = strlenW( file->FileName ) * sizeof(WCHAR);
3947 RegSetValueExW( hkey1, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3948 RegSetValueExW( hkey2, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3951 HeapFree(GetProcessHeap(),0,name);
3954 return ERROR_SUCCESS;
3957 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
3961 static const WCHAR ExecSeqQuery[] =
3962 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3963 '`','F','o','n','t','`',0};
3965 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3966 if (rc != ERROR_SUCCESS)
3968 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
3969 return ERROR_SUCCESS;
3972 MSI_IterateRecords(view, NULL, ITERATE_RegisterFonts, package);
3973 msiobj_release(&view->hdr);
3975 return ERROR_SUCCESS;
3978 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
3980 MSIPACKAGE *package = (MSIPACKAGE*)param;
3981 LPCWSTR compgroupid=NULL;
3982 LPCWSTR feature=NULL;
3983 LPCWSTR text = NULL;
3984 LPCWSTR qualifier = NULL;
3985 LPCWSTR component = NULL;
3986 LPWSTR advertise = NULL;
3987 LPWSTR output = NULL;
3989 UINT rc = ERROR_SUCCESS;
3993 component = MSI_RecordGetString(rec,3);
3994 comp = get_loaded_component(package,component);
3996 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL) &&
3997 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_SOURCE) &&
3998 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_ADVERTISED))
4000 TRACE("Skipping: Component %s not scheduled for install\n",
4001 debugstr_w(component));
4003 return ERROR_SUCCESS;
4006 compgroupid = MSI_RecordGetString(rec,1);
4008 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
4009 if (rc != ERROR_SUCCESS)
4012 text = MSI_RecordGetString(rec,4);
4013 qualifier = MSI_RecordGetString(rec,2);
4014 feature = MSI_RecordGetString(rec,5);
4016 advertise = create_component_advertise_string(package, comp, feature);
4018 sz = strlenW(advertise);
4021 sz += lstrlenW(text);
4024 sz *= sizeof(WCHAR);
4026 output = HeapAlloc(GetProcessHeap(),0,sz);
4027 memset(output,0,sz);
4028 strcpyW(output,advertise);
4031 strcatW(output,text);
4033 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
4034 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
4038 HeapFree(GetProcessHeap(),0,output);
4044 * At present I am ignorning the advertised components part of this and only
4045 * focusing on the qualified component sets
4047 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
4051 static const WCHAR ExecSeqQuery[] =
4052 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4053 '`','P','u','b','l','i','s','h',
4054 'C','o','m','p','o','n','e','n','t','`',0};
4056 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4057 if (rc != ERROR_SUCCESS)
4058 return ERROR_SUCCESS;
4060 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
4061 msiobj_release(&view->hdr);