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);
1114 if (!MSI_RecordIsNull(row,3))
1115 MSI_RecordGetStringW(row,3,feature->Title,&sz);
1118 if (!MSI_RecordIsNull(row,4))
1119 MSI_RecordGetStringW(row,4,feature->Description,&sz);
1121 if (!MSI_RecordIsNull(row,5))
1122 feature->Display = MSI_RecordGetInteger(row,5);
1124 feature->Level= MSI_RecordGetInteger(row,6);
1126 sz = IDENTIFIER_SIZE;
1127 if (!MSI_RecordIsNull(row,7))
1128 MSI_RecordGetStringW(row,7,feature->Directory,&sz);
1130 feature->Attributes = MSI_RecordGetInteger(row,8);
1132 feature->Installed = INSTALLSTATE_ABSENT;
1133 feature->Action = INSTALLSTATE_UNKNOWN;
1134 feature->ActionRequest = INSTALLSTATE_UNKNOWN;
1136 list_add_tail( &package->features, &feature->entry );
1138 /* load feature components */
1140 rc = MSI_OpenQuery( package->db, &view, Query1, feature->Feature );
1141 if (rc != ERROR_SUCCESS)
1142 return ERROR_SUCCESS;
1144 ilfs.package = package;
1145 ilfs.feature = feature;
1147 MSI_IterateRecords(view, NULL, iterate_load_featurecomponents , &ilfs);
1148 msiobj_release(&view->hdr);
1150 return ERROR_SUCCESS;
1153 static UINT load_file(MSIRECORD *row, LPVOID param)
1155 MSIPACKAGE* package = (MSIPACKAGE*)param;
1159 /* fill in the data */
1161 file = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFILE) );
1163 return ERROR_NOT_ENOUGH_MEMORY;
1165 file->File = load_dynamic_stringW( row, 1 );
1167 component = MSI_RecordGetString( row, 2 );
1168 file->Component = get_loaded_component( package, component );
1170 if (!file->Component)
1171 ERR("Unfound Component %s\n",debugstr_w(component));
1173 file->FileName = load_dynamic_stringW( row, 3 );
1174 reduce_to_longfilename( file->FileName );
1176 file->ShortName = load_dynamic_stringW( row, 3 );
1177 reduce_to_shortfilename( file->ShortName );
1179 file->FileSize = MSI_RecordGetInteger( row, 4 );
1180 file->Version = load_dynamic_stringW( row, 5 );
1181 file->Language = load_dynamic_stringW( row, 6 );
1182 file->Attributes = MSI_RecordGetInteger( row, 7 );
1183 file->Sequence = MSI_RecordGetInteger( row, 8 );
1187 TRACE("File Loaded (%s)\n",debugstr_w(file->File));
1189 list_add_tail( &package->files, &file->entry );
1191 return ERROR_SUCCESS;
1194 static UINT load_all_files(MSIPACKAGE *package)
1198 static const WCHAR Query[] =
1199 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1200 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1201 '`','S','e','q','u','e','n','c','e','`', 0};
1204 return ERROR_INVALID_HANDLE;
1206 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1207 if (rc != ERROR_SUCCESS)
1208 return ERROR_SUCCESS;
1210 rc = MSI_IterateRecords(view, NULL, load_file, package);
1211 msiobj_release(&view->hdr);
1213 return ERROR_SUCCESS;
1218 * I am not doing any of the costing functionality yet.
1219 * Mostly looking at doing the Component and Feature loading
1221 * The native MSI does A LOT of modification to tables here. Mostly adding
1222 * a lot of temporary columns to the Feature and Component tables.
1224 * note: Native msi also tracks the short filename. But I am only going to
1225 * track the long ones. Also looking at this directory table
1226 * it appears that the directory table does not get the parents
1227 * resolved base on property only based on their entries in the
1230 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1234 static const WCHAR Query_all[] =
1235 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1236 '`','F','e','a','t','u','r','e','`',0};
1237 static const WCHAR szCosting[] =
1238 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1239 static const WCHAR szZero[] = { '0', 0 };
1243 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1245 return ERROR_SUCCESS;
1247 MSI_SetPropertyW(package, szCosting, szZero);
1248 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1250 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1251 if (rc != ERROR_SUCCESS)
1254 rc = MSI_IterateRecords(view, NULL, load_feature, package);
1255 msiobj_release(&view->hdr);
1257 load_all_files(package);
1259 return ERROR_SUCCESS;
1262 static UINT execute_script(MSIPACKAGE *package, UINT script )
1265 UINT rc = ERROR_SUCCESS;
1267 TRACE("Executing Script %i\n",script);
1269 for (i = 0; i < package->script->ActionCount[script]; i++)
1272 action = package->script->Actions[script][i];
1273 ui_actionstart(package, action);
1274 TRACE("Executing Action (%s)\n",debugstr_w(action));
1275 rc = ACTION_PerformAction(package, action, TRUE);
1276 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1277 if (rc != ERROR_SUCCESS)
1280 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1282 package->script->ActionCount[script] = 0;
1283 package->script->Actions[script] = NULL;
1287 static UINT ACTION_FileCost(MSIPACKAGE *package)
1289 return ERROR_SUCCESS;
1293 static MSIFOLDER *load_folder( MSIPACKAGE *package, LPCWSTR dir )
1295 static const WCHAR Query[] =
1296 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1297 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1298 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1299 ' ','=',' ','\'','%','s','\'',
1301 LPWSTR ptargetdir, targetdir, srcdir;
1303 LPWSTR shortname = NULL;
1304 MSIRECORD * row = 0;
1307 TRACE("Looking for dir %s\n",debugstr_w(dir));
1309 folder = get_loaded_folder( package, dir );
1313 TRACE("Working to load %s\n",debugstr_w(dir));
1315 folder = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (MSIFOLDER) );
1319 folder->Directory = strdupW(dir);
1321 row = MSI_QueryGetRecord(package->db, Query, dir);
1325 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1327 /* split src and target dir */
1328 if (strchrW(targetdir,':'))
1330 srcdir=strchrW(targetdir,':');
1337 /* for now only pick long filename versions */
1338 if (strchrW(targetdir,'|'))
1340 shortname = targetdir;
1341 targetdir = strchrW(targetdir,'|');
1345 /* for the sourcedir pick the short filename */
1346 if (srcdir && strchrW(srcdir,'|'))
1348 LPWSTR p = strchrW(srcdir,'|');
1352 /* now check for root dirs */
1353 if (targetdir[0] == '.' && targetdir[1] == 0)
1358 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1359 HeapFree(GetProcessHeap(),0, folder->TargetDefault);
1360 folder->TargetDefault = strdupW(targetdir);
1364 folder->SourceDefault = strdupW(srcdir);
1366 folder->SourceDefault = strdupW(shortname);
1368 folder->SourceDefault = strdupW(targetdir);
1369 HeapFree(GetProcessHeap(), 0, ptargetdir);
1370 TRACE(" SourceDefault = %s\n", debugstr_w( folder->SourceDefault ));
1372 parent = MSI_RecordGetString(row,2);
1375 folder->Parent = load_folder( package, parent );
1376 if ( folder->Parent )
1377 TRACE("loaded parent %p %s\n", folder->Parent,
1378 debugstr_w(folder->Parent->Directory));
1380 ERR("failed to load parent folder %s\n", debugstr_w(parent));
1383 folder->Property = load_dynamic_property( package, dir, NULL );
1385 msiobj_release(&row->hdr);
1387 list_add_tail( &package->folders, &folder->entry );
1389 TRACE("%s returning %p\n",debugstr_w(dir),folder);
1394 /* scan for and update current install states */
1395 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
1398 MSIFEATURE *feature;
1400 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1403 res = MsiGetComponentPathW( package->ProductCode,
1404 comp->ComponentId, NULL, NULL);
1406 res = INSTALLSTATE_ABSENT;
1407 comp->Installed = res;
1410 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1413 INSTALLSTATE res = -10;
1415 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1417 comp= cl->component;
1420 res = comp->Installed;
1423 if (res == comp->Installed)
1426 if (res != comp->Installed)
1427 res = INSTALLSTATE_INCOMPLETE;
1430 feature->Installed = res;
1434 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
1437 static const WCHAR all[]={'A','L','L',0};
1439 MSIFEATURE *feature;
1441 override = load_dynamic_property(package, property, NULL);
1445 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1447 if (strcmpiW(override,all)==0)
1449 feature->ActionRequest= state;
1450 feature->Action = state;
1454 LPWSTR ptr = override;
1455 LPWSTR ptr2 = strchrW(override,',');
1459 if ((ptr2 && strncmpW(ptr,feature->Feature, ptr2-ptr)==0)
1460 || (!ptr2 && strcmpW(ptr,feature->Feature)==0))
1462 feature->ActionRequest= state;
1463 feature->Action = state;
1469 ptr2 = strchrW(ptr,',');
1476 HeapFree(GetProcessHeap(),0,override);
1481 static UINT SetFeatureStates(MSIPACKAGE *package)
1485 static const WCHAR szlevel[] =
1486 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1487 static const WCHAR szAddLocal[] =
1488 {'A','D','D','L','O','C','A','L',0};
1489 static const WCHAR szRemove[] =
1490 {'R','E','M','O','V','E',0};
1491 BOOL override = FALSE;
1492 MSICOMPONENT* component;
1493 MSIFEATURE *feature;
1496 /* I do not know if this is where it should happen.. but */
1498 TRACE("Checking Install Level\n");
1500 level = load_dynamic_property(package,szlevel,NULL);
1503 install_level = atoiW(level);
1504 HeapFree(GetProcessHeap(), 0, level);
1509 /* ok hereis the _real_ rub
1510 * all these activation/deactivation things happen in order and things
1511 * later on the list override things earlier on the list.
1512 * 1) INSTALLLEVEL processing
1522 * 11) FILEADDDEFAULT
1523 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1524 * ignored for all the features. seems strange, especially since it is not
1525 * documented anywhere, but it is how it works.
1527 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1528 * REMOVE are the big ones, since we don't handle administrative installs
1531 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
1532 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
1536 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1538 BOOL feature_state = ((feature->Level > 0) &&
1539 (feature->Level <= install_level));
1541 if ((feature_state) && (feature->Action == INSTALLSTATE_UNKNOWN))
1543 if (feature->Attributes & msidbFeatureAttributesFavorSource)
1545 feature->ActionRequest = INSTALLSTATE_SOURCE;
1546 feature->Action = INSTALLSTATE_SOURCE;
1548 else if (feature->Attributes & msidbFeatureAttributesFavorAdvertise)
1550 feature->ActionRequest = INSTALLSTATE_ADVERTISED;
1551 feature->Action = INSTALLSTATE_ADVERTISED;
1555 feature->ActionRequest = INSTALLSTATE_LOCAL;
1556 feature->Action = INSTALLSTATE_LOCAL;
1563 /* set the Preselected Property */
1564 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1565 static const WCHAR szOne[] = { '1', 0 };
1567 MSI_SetPropertyW(package,szPreselected,szOne);
1571 * now we want to enable or disable components base on feature
1574 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1578 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1579 debugstr_w(feature->Feature), feature->Installed, feature->Action,
1580 feature->ActionRequest);
1582 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1584 component = cl->component;
1586 if (!component->Enabled)
1588 component->Action = INSTALLSTATE_UNKNOWN;
1589 component->ActionRequest = INSTALLSTATE_UNKNOWN;
1593 if (feature->Action == INSTALLSTATE_LOCAL)
1595 component->Action = INSTALLSTATE_LOCAL;
1596 component->ActionRequest = INSTALLSTATE_LOCAL;
1598 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
1600 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1601 (component->Action == INSTALLSTATE_ABSENT) ||
1602 (component->Action == INSTALLSTATE_ADVERTISED))
1605 component->Action = INSTALLSTATE_SOURCE;
1606 component->ActionRequest = INSTALLSTATE_SOURCE;
1609 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
1611 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1612 (component->Action == INSTALLSTATE_ABSENT))
1615 component->Action = INSTALLSTATE_ADVERTISED;
1616 component->ActionRequest = INSTALLSTATE_ADVERTISED;
1619 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
1621 if (component->Action == INSTALLSTATE_UNKNOWN)
1623 component->Action = INSTALLSTATE_ABSENT;
1624 component->ActionRequest = INSTALLSTATE_ABSENT;
1631 LIST_FOR_EACH_ENTRY( component, &package->components, MSICOMPONENT, entry )
1633 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1634 debugstr_w(component->Component), component->Installed,
1635 component->Action, component->ActionRequest);
1639 return ERROR_SUCCESS;
1642 static UINT ITERATE_CostFinalizeDirectories(MSIRECORD *row, LPVOID param)
1644 MSIPACKAGE *package = (MSIPACKAGE*)param;
1648 name = MSI_RecordGetString(row,1);
1650 /* This helper function now does ALL the work */
1651 TRACE("Dir %s ...\n",debugstr_w(name));
1652 load_folder(package,name);
1653 path = resolve_folder(package,name,FALSE,TRUE,NULL);
1654 TRACE("resolves to %s\n",debugstr_w(path));
1655 HeapFree( GetProcessHeap(), 0, path);
1657 return ERROR_SUCCESS;
1660 static UINT ITERATE_CostFinalizeConditions(MSIRECORD *row, LPVOID param)
1662 MSIPACKAGE *package = (MSIPACKAGE*)param;
1664 MSIFEATURE *feature;
1666 name = MSI_RecordGetString( row, 1 );
1668 feature = get_loaded_feature( package, name );
1670 ERR("FAILED to find loaded feature %s\n",debugstr_w(name));
1674 Condition = MSI_RecordGetString(row,3);
1676 if (MSI_EvaluateConditionW(package,Condition) == MSICONDITION_TRUE)
1678 int level = MSI_RecordGetInteger(row,2);
1679 TRACE("Reseting feature %s to level %i\n", debugstr_w(name), level);
1680 feature->Level = level;
1683 return ERROR_SUCCESS;
1688 * A lot is done in this function aside from just the costing.
1689 * The costing needs to be implemented at some point but for now I am going
1690 * to focus on the directory building
1693 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
1695 static const WCHAR ExecSeqQuery[] =
1696 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1697 '`','D','i','r','e','c','t','o','r','y','`',0};
1698 static const WCHAR ConditionQuery[] =
1699 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1700 '`','C','o','n','d','i','t','i','o','n','`',0};
1701 static const WCHAR szCosting[] =
1702 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1703 static const WCHAR szlevel[] =
1704 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1705 static const WCHAR szOne[] = { '1', 0 };
1714 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1716 return ERROR_SUCCESS;
1718 TRACE("Building Directory properties\n");
1720 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1721 if (rc == ERROR_SUCCESS)
1723 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeDirectories,
1725 msiobj_release(&view->hdr);
1728 TRACE("File calculations\n");
1730 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
1732 MSICOMPONENT* comp = NULL;
1734 comp = file->Component;
1740 /* calculate target */
1741 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
1743 HeapFree(GetProcessHeap(),0,file->TargetPath);
1745 TRACE("file %s is named %s\n",
1746 debugstr_w(file->File),debugstr_w(file->FileName));
1748 file->TargetPath = build_directory_name(2, p, file->FileName);
1750 HeapFree(GetProcessHeap(),0,p);
1752 TRACE("file %s resolves to %s\n",
1753 debugstr_w(file->File),debugstr_w(file->TargetPath));
1755 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
1758 comp->Cost += file->FileSize;
1768 static const WCHAR name[] =
1770 static const WCHAR name_fmt[] =
1771 {'%','u','.','%','u','.','%','u','.','%','u',0};
1772 WCHAR filever[0x100];
1773 VS_FIXEDFILEINFO *lpVer;
1775 TRACE("Version comparison.. \n");
1776 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
1777 version = HeapAlloc(GetProcessHeap(),0,versize);
1778 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
1780 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
1782 sprintfW(filever,name_fmt,
1783 HIWORD(lpVer->dwFileVersionMS),
1784 LOWORD(lpVer->dwFileVersionMS),
1785 HIWORD(lpVer->dwFileVersionLS),
1786 LOWORD(lpVer->dwFileVersionLS));
1788 TRACE("new %s old %s\n", debugstr_w(file->Version),
1789 debugstr_w(filever));
1790 if (strcmpiW(filever,file->Version)<0)
1793 FIXME("cost should be diff in size\n");
1794 comp->Cost += file->FileSize;
1798 HeapFree(GetProcessHeap(),0,version);
1806 TRACE("Evaluating Condition Table\n");
1808 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
1809 if (rc == ERROR_SUCCESS)
1811 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeConditions,
1813 msiobj_release(&view->hdr);
1816 TRACE("Enabling or Disabling Components\n");
1817 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1819 if (comp->Condition)
1821 if (MSI_EvaluateConditionW(package,
1822 comp->Condition) == MSICONDITION_FALSE)
1824 TRACE("Disabling component %s\n", debugstr_w(comp->Component));
1825 comp->Enabled = FALSE;
1830 MSI_SetPropertyW(package,szCosting,szOne);
1831 /* set default run level if not set */
1832 level = load_dynamic_property(package,szlevel,NULL);
1834 MSI_SetPropertyW(package,szlevel, szOne);
1835 HeapFree(GetProcessHeap(),0,level);
1837 ACTION_UpdateInstallStates(package);
1839 return SetFeatureStates(package);
1842 /* OK this value is "interpreted" and then formatted based on the
1843 first few characters */
1844 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
1848 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
1854 LPWSTR deformated = NULL;
1857 deformat_string(package, &value[2], &deformated);
1859 /* binary value type */
1863 *size = (strlenW(ptr)/2)+1;
1865 *size = strlenW(ptr)/2;
1867 data = HeapAlloc(GetProcessHeap(),0,*size);
1873 /* if uneven pad with a zero in front */
1879 data[count] = (BYTE)strtol(byte,NULL,0);
1881 TRACE("Uneven byte count\n");
1889 data[count] = (BYTE)strtol(byte,NULL,0);
1892 HeapFree(GetProcessHeap(),0,deformated);
1894 TRACE("Data %li bytes(%i)\n",*size,count);
1901 deformat_string(package, &value[1], &deformated);
1904 *size = sizeof(DWORD);
1905 data = HeapAlloc(GetProcessHeap(),0,*size);
1911 if ( (*p < '0') || (*p > '9') )
1917 if (deformated[0] == '-')
1920 TRACE("DWORD %li\n",*(LPDWORD)data);
1922 HeapFree(GetProcessHeap(),0,deformated);
1927 static const WCHAR szMulti[] = {'[','~',']',0};
1936 *type=REG_EXPAND_SZ;
1944 if (strstrW(value,szMulti))
1945 *type = REG_MULTI_SZ;
1947 *size = deformat_string(package, ptr,(LPWSTR*)&data);
1952 static UINT ITERATE_WriteRegistryValues(MSIRECORD *row, LPVOID param)
1954 MSIPACKAGE *package = (MSIPACKAGE*)param;
1955 static const WCHAR szHCR[] =
1956 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1957 'R','O','O','T','\\',0};
1958 static const WCHAR szHCU[] =
1959 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1960 'U','S','E','R','\\',0};
1961 static const WCHAR szHLM[] =
1962 {'H','K','E','Y','_','L','O','C','A','L','_',
1963 'M','A','C','H','I','N','E','\\',0};
1964 static const WCHAR szHU[] =
1965 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1967 LPSTR value_data = NULL;
1968 HKEY root_key, hkey;
1971 LPCWSTR szRoot, component, name, key, value;
1976 BOOL check_first = FALSE;
1979 ui_progress(package,2,0,0,0);
1986 component = MSI_RecordGetString(row, 6);
1987 comp = get_loaded_component(package,component);
1989 return ERROR_SUCCESS;
1991 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
1993 TRACE("Skipping write due to disabled component %s\n",
1994 debugstr_w(component));
1996 comp->Action = comp->Installed;
1998 return ERROR_SUCCESS;
2001 comp->Action = INSTALLSTATE_LOCAL;
2003 name = MSI_RecordGetString(row, 4);
2004 if( MSI_RecordIsNull(row,5) && name )
2006 /* null values can have special meanings */
2007 if (name[0]=='-' && name[1] == 0)
2008 return ERROR_SUCCESS;
2009 else if ((name[0]=='+' && name[1] == 0) ||
2010 (name[0] == '*' && name[1] == 0))
2015 root = MSI_RecordGetInteger(row,2);
2016 key = MSI_RecordGetString(row, 3);
2018 /* get the root key */
2023 static const WCHAR szALLUSER[] = {'A','L','L','U','S','E','R','S',0};
2024 LPWSTR all_users = load_dynamic_property(package, szALLUSER, NULL);
2025 if (all_users && all_users[0] == '1')
2027 root_key = HKEY_LOCAL_MACHINE;
2032 root_key = HKEY_CURRENT_USER;
2035 HeapFree(GetProcessHeap(),0,all_users);
2038 case 0: root_key = HKEY_CLASSES_ROOT;
2041 case 1: root_key = HKEY_CURRENT_USER;
2044 case 2: root_key = HKEY_LOCAL_MACHINE;
2047 case 3: root_key = HKEY_USERS;
2051 ERR("Unknown root %i\n",root);
2057 return ERROR_SUCCESS;
2059 deformat_string(package, key , &deformated);
2060 size = strlenW(deformated) + strlenW(szRoot) + 1;
2061 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
2062 strcpyW(uikey,szRoot);
2063 strcatW(uikey,deformated);
2065 if (RegCreateKeyW( root_key, deformated, &hkey))
2067 ERR("Could not create key %s\n",debugstr_w(deformated));
2068 HeapFree(GetProcessHeap(),0,deformated);
2069 HeapFree(GetProcessHeap(),0,uikey);
2070 return ERROR_SUCCESS;
2072 HeapFree(GetProcessHeap(),0,deformated);
2074 value = MSI_RecordGetString(row,5);
2076 value_data = parse_value(package, value, &type, &size);
2079 static const WCHAR szEmpty[] = {0};
2080 value_data = (LPSTR)strdupW(szEmpty);
2085 deformat_string(package, name, &deformated);
2087 /* get the double nulls to terminate SZ_MULTI */
2088 if (type == REG_MULTI_SZ)
2089 size +=sizeof(WCHAR);
2093 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
2095 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE)value_data, size);
2100 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
2101 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2103 TRACE("value %s of %s checked already exists\n",
2104 debugstr_w(deformated), debugstr_w(uikey));
2108 TRACE("Checked and setting value %s of %s\n",
2109 debugstr_w(deformated), debugstr_w(uikey));
2110 if (deformated || size)
2111 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE) value_data, size);
2116 uirow = MSI_CreateRecord(3);
2117 MSI_RecordSetStringW(uirow,2,deformated);
2118 MSI_RecordSetStringW(uirow,1,uikey);
2121 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2123 MSI_RecordSetStringW(uirow,3,value);
2125 ui_actiondata(package,szWriteRegistryValues,uirow);
2126 msiobj_release( &uirow->hdr );
2128 HeapFree(GetProcessHeap(),0,value_data);
2129 HeapFree(GetProcessHeap(),0,deformated);
2130 HeapFree(GetProcessHeap(),0,uikey);
2132 return ERROR_SUCCESS;
2135 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2139 static const WCHAR ExecSeqQuery[] =
2140 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2141 '`','R','e','g','i','s','t','r','y','`',0 };
2144 return ERROR_INVALID_HANDLE;
2146 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2147 if (rc != ERROR_SUCCESS)
2148 return ERROR_SUCCESS;
2150 /* increment progress bar each time action data is sent */
2151 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
2153 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteRegistryValues, package);
2155 msiobj_release(&view->hdr);
2159 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
2161 package->script->CurrentlyScripting = TRUE;
2163 return ERROR_SUCCESS;
2167 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
2172 static const WCHAR q1[]=
2173 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2174 '`','R','e','g','i','s','t','r','y','`',0};
2177 MSIRECORD * row = 0;
2178 MSIFEATURE *feature;
2181 TRACE(" InstallValidate \n");
2183 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
2184 if (rc != ERROR_SUCCESS)
2185 return ERROR_SUCCESS;
2187 rc = MSI_ViewExecute(view, 0);
2188 if (rc != ERROR_SUCCESS)
2190 MSI_ViewClose(view);
2191 msiobj_release(&view->hdr);
2196 rc = MSI_ViewFetch(view,&row);
2197 if (rc != ERROR_SUCCESS)
2204 msiobj_release(&row->hdr);
2206 MSI_ViewClose(view);
2207 msiobj_release(&view->hdr);
2209 total = total + progress * REG_PROGRESS_VALUE;
2210 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2212 total += COMPONENT_PROGRESS_VALUE;
2214 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2216 total += file->FileSize;
2218 ui_progress(package,0,total,0,0);
2220 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2222 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2223 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2224 feature->ActionRequest);
2227 return ERROR_SUCCESS;
2230 static UINT ITERATE_LaunchConditions(MSIRECORD *row, LPVOID param)
2232 MSIPACKAGE* package = (MSIPACKAGE*)param;
2233 LPCWSTR cond = NULL;
2234 LPCWSTR message = NULL;
2235 static const WCHAR title[]=
2236 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2238 cond = MSI_RecordGetString(row,1);
2240 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
2243 message = MSI_RecordGetString(row,2);
2244 deformat_string(package,message,&deformated);
2245 MessageBoxW(NULL,deformated,title,MB_OK);
2246 HeapFree(GetProcessHeap(),0,deformated);
2247 return ERROR_FUNCTION_FAILED;
2250 return ERROR_SUCCESS;
2253 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
2256 MSIQUERY * view = NULL;
2257 static const WCHAR ExecSeqQuery[] =
2258 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2259 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2261 TRACE("Checking launch conditions\n");
2263 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2264 if (rc != ERROR_SUCCESS)
2265 return ERROR_SUCCESS;
2267 rc = MSI_IterateRecords(view, NULL, ITERATE_LaunchConditions, package);
2268 msiobj_release(&view->hdr);
2273 static LPWSTR resolve_keypath( MSIPACKAGE* package, MSICOMPONENT *cmp )
2276 if (cmp->KeyPath[0]==0)
2278 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
2281 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
2283 MSIRECORD * row = 0;
2285 LPWSTR deformated,buffer,deformated_name;
2287 static const WCHAR ExecSeqQuery[] =
2288 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2289 '`','R','e','g','i','s','t','r','y','`',' ',
2290 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2291 ' ','=',' ' ,'\'','%','s','\'',0 };
2292 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
2293 static const WCHAR fmt2[]=
2294 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2296 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
2300 root = MSI_RecordGetInteger(row,2);
2301 key = MSI_RecordGetString(row, 3);
2302 name = MSI_RecordGetString(row, 4);
2303 deformat_string(package, key , &deformated);
2304 deformat_string(package, name, &deformated_name);
2306 len = strlenW(deformated) + 6;
2307 if (deformated_name)
2308 len+=strlenW(deformated_name);
2310 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
2312 if (deformated_name)
2313 sprintfW(buffer,fmt2,root,deformated,deformated_name);
2315 sprintfW(buffer,fmt,root,deformated);
2317 HeapFree(GetProcessHeap(),0,deformated);
2318 HeapFree(GetProcessHeap(),0,deformated_name);
2319 msiobj_release(&row->hdr);
2323 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
2325 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2330 MSIFILE *file = get_loaded_file( package, cmp->KeyPath );
2333 return strdupW( file->TargetPath );
2338 static HKEY openSharedDLLsKey(void)
2341 static const WCHAR path[] =
2342 {'S','o','f','t','w','a','r','e','\\',
2343 'M','i','c','r','o','s','o','f','t','\\',
2344 'W','i','n','d','o','w','s','\\',
2345 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2346 'S','h','a','r','e','d','D','L','L','s',0};
2348 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
2352 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
2357 DWORD sz = sizeof(count);
2360 hkey = openSharedDLLsKey();
2361 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
2362 if (rc != ERROR_SUCCESS)
2368 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
2372 hkey = openSharedDLLsKey();
2374 RegSetValueExW(hkey,path,0,REG_DWORD,
2375 (LPBYTE)&count,sizeof(count));
2377 RegDeleteValueW(hkey,path);
2383 * Return TRUE if the count should be written out and FALSE if not
2385 static void ACTION_RefCountComponent( MSIPACKAGE* package, MSICOMPONENT *comp )
2387 MSIFEATURE *feature;
2391 /* only refcount DLLs */
2392 if (comp->KeyPath[0]==0 ||
2393 comp->Attributes & msidbComponentAttributesRegistryKeyPath ||
2394 comp->Attributes & msidbComponentAttributesODBCDataSource)
2398 count = ACTION_GetSharedDLLsCount( comp->FullKeypath);
2399 write = (count > 0);
2401 if (comp->Attributes & msidbComponentAttributesSharedDllRefCount)
2405 /* increment counts */
2406 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2410 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ))
2413 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2415 if ( cl->component == comp )
2420 /* decrement counts */
2421 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2425 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ABSENT ))
2428 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2430 if ( cl->component == comp )
2435 /* ref count all the files in the component */
2440 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2442 if (file->Component == comp)
2443 ACTION_WriteSharedDLLsCount( file->TargetPath, count );
2447 /* add a count for permenent */
2448 if (comp->Attributes & msidbComponentAttributesPermanent)
2451 comp->RefCount = count;
2454 ACTION_WriteSharedDLLsCount( comp->FullKeypath, comp->RefCount );
2458 * Ok further analysis makes me think that this work is
2459 * actually done in the PublishComponents and PublishFeatures
2460 * step, and not here. It appears like the keypath and all that is
2461 * resolved in this step, however actually written in the Publish steps.
2462 * But we will leave it here for now because it is unclear
2464 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
2466 WCHAR squished_pc[GUID_SIZE];
2467 WCHAR squished_cc[GUID_SIZE];
2470 HKEY hkey=0,hkey2=0;
2473 return ERROR_INVALID_HANDLE;
2475 /* writes the Component and Features values to the registry */
2477 rc = MSIREG_OpenComponents(&hkey);
2478 if (rc != ERROR_SUCCESS)
2481 squash_guid(package->ProductCode,squished_pc);
2482 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
2484 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2486 ui_progress(package,2,0,0,0);
2487 if (comp->ComponentId[0]!=0)
2489 WCHAR *keypath = NULL;
2492 squash_guid(comp->ComponentId,squished_cc);
2494 keypath = resolve_keypath( package, comp );
2495 comp->FullKeypath = keypath;
2497 /* do the refcounting */
2498 ACTION_RefCountComponent( package, comp );
2500 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2501 debugstr_w(comp->Component),
2502 debugstr_w(squished_cc),
2503 debugstr_w(comp->FullKeypath),
2506 * Write the keypath out if the component is to be registered
2507 * and delete the key if the component is to be deregistered
2509 if (ACTION_VerifyComponentForAction(package, comp,
2510 INSTALLSTATE_LOCAL))
2512 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
2513 if (rc != ERROR_SUCCESS)
2518 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPBYTE)keypath,
2519 (strlenW(keypath)+1)*sizeof(WCHAR));
2521 if (comp->Attributes & msidbComponentAttributesPermanent)
2523 static const WCHAR szPermKey[] =
2524 { '0','0','0','0','0','0','0','0','0','0','0','0',
2525 '0','0','0','0','0','0','0', '0','0','0','0','0',
2526 '0','0','0','0','0','0','0','0',0};
2528 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
2530 (strlenW(keypath)+1)*sizeof(WCHAR));
2536 uirow = MSI_CreateRecord(3);
2537 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2538 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2539 MSI_RecordSetStringW(uirow,3,keypath);
2540 ui_actiondata(package,szProcessComponents,uirow);
2541 msiobj_release( &uirow->hdr );
2544 else if (ACTION_VerifyComponentForAction(package, comp,
2545 INSTALLSTATE_ABSENT))
2549 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
2550 if (rc != ERROR_SUCCESS)
2553 RegDeleteValueW(hkey2,squished_pc);
2555 /* if the key is empty delete it */
2556 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
2558 if (res == ERROR_NO_MORE_ITEMS)
2559 RegDeleteKeyW(hkey,squished_cc);
2562 uirow = MSI_CreateRecord(2);
2563 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2564 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2565 ui_actiondata(package,szProcessComponents,uirow);
2566 msiobj_release( &uirow->hdr );
2583 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
2584 LPWSTR lpszName, LONG_PTR lParam)
2587 typelib_struct *tl_struct = (typelib_struct*) lParam;
2588 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
2592 if (!IS_INTRESOURCE(lpszName))
2594 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
2598 sz = strlenW(tl_struct->source)+4;
2599 sz *= sizeof(WCHAR);
2601 if ((INT)lpszName == 1)
2602 tl_struct->path = strdupW(tl_struct->source);
2605 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
2606 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
2609 TRACE("trying %s\n", debugstr_w(tl_struct->path));
2610 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
2611 if (!SUCCEEDED(res))
2613 HeapFree(GetProcessHeap(),0,tl_struct->path);
2614 tl_struct->path = NULL;
2619 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
2620 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
2622 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2626 HeapFree(GetProcessHeap(),0,tl_struct->path);
2627 tl_struct->path = NULL;
2629 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2630 ITypeLib_Release(tl_struct->ptLib);
2635 static UINT ITERATE_RegisterTypeLibraries(MSIRECORD *row, LPVOID param)
2637 MSIPACKAGE* package = (MSIPACKAGE*)param;
2641 typelib_struct tl_struct;
2643 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
2645 component = MSI_RecordGetString(row,3);
2646 comp = get_loaded_component(package,component);
2648 return ERROR_SUCCESS;
2650 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2652 TRACE("Skipping typelib reg due to disabled component\n");
2654 comp->Action = comp->Installed;
2656 return ERROR_SUCCESS;
2659 comp->Action = INSTALLSTATE_LOCAL;
2661 file = get_loaded_file( package, comp->KeyPath );
2663 return ERROR_SUCCESS;
2665 module = LoadLibraryExW( file->TargetPath, NULL, LOAD_LIBRARY_AS_DATAFILE );
2669 guid = load_dynamic_stringW(row,1);
2670 CLSIDFromString(guid, &tl_struct.clsid);
2671 HeapFree(GetProcessHeap(),0,guid);
2672 tl_struct.source = strdupW( file->TargetPath );
2673 tl_struct.path = NULL;
2675 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
2676 (LONG_PTR)&tl_struct);
2678 if (tl_struct.path != NULL)
2684 helpid = MSI_RecordGetString(row,6);
2687 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
2688 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
2689 HeapFree(GetProcessHeap(),0,help);
2691 if (!SUCCEEDED(res))
2692 ERR("Failed to register type library %s\n",
2693 debugstr_w(tl_struct.path));
2696 ui_actiondata(package,szRegisterTypeLibraries,row);
2698 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
2701 ITypeLib_Release(tl_struct.ptLib);
2702 HeapFree(GetProcessHeap(),0,tl_struct.path);
2705 ERR("Failed to load type library %s\n",
2706 debugstr_w(tl_struct.source));
2708 FreeLibrary(module);
2709 HeapFree(GetProcessHeap(),0,tl_struct.source);
2712 ERR("Could not load file! %s\n", debugstr_w(file->TargetPath));
2714 return ERROR_SUCCESS;
2717 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
2720 * OK this is a bit confusing.. I am given a _Component key and I believe
2721 * that the file that is being registered as a type library is the "key file
2722 * of that component" which I interpret to mean "The file in the KeyPath of
2727 static const WCHAR Query[] =
2728 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2729 '`','T','y','p','e','L','i','b','`',0};
2732 return ERROR_INVALID_HANDLE;
2734 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2735 if (rc != ERROR_SUCCESS)
2736 return ERROR_SUCCESS;
2738 rc = MSI_IterateRecords(view, NULL, ITERATE_RegisterTypeLibraries, package);
2739 msiobj_release(&view->hdr);
2743 static UINT ITERATE_CreateShortcuts(MSIRECORD *row, LPVOID param)
2745 MSIPACKAGE *package = (MSIPACKAGE*)param;
2746 LPWSTR target_file, target_folder;
2748 WCHAR filename[0x100];
2751 static const WCHAR szlnk[]={'.','l','n','k',0};
2756 buffer = MSI_RecordGetString(row,4);
2757 comp = get_loaded_component(package,buffer);
2759 return ERROR_SUCCESS;
2761 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2763 TRACE("Skipping shortcut creation due to disabled component\n");
2765 comp->Action = comp->Installed;
2767 return ERROR_SUCCESS;
2770 comp->Action = INSTALLSTATE_LOCAL;
2772 ui_actiondata(package,szCreateShortcuts,row);
2774 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2775 &IID_IShellLinkW, (LPVOID *) &sl );
2779 ERR("Is IID_IShellLink\n");
2780 return ERROR_SUCCESS;
2783 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
2786 ERR("Is IID_IPersistFile\n");
2787 return ERROR_SUCCESS;
2790 buffer = MSI_RecordGetString(row,2);
2791 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
2793 /* may be needed because of a bug somehwere else */
2794 create_full_pathW(target_folder);
2797 MSI_RecordGetStringW(row,3,filename,&sz);
2798 reduce_to_longfilename(filename);
2799 if (!strchrW(filename,'.') || strcmpiW(strchrW(filename,'.'),szlnk))
2800 strcatW(filename,szlnk);
2801 target_file = build_directory_name(2, target_folder, filename);
2802 HeapFree(GetProcessHeap(),0,target_folder);
2804 buffer = MSI_RecordGetString(row,5);
2805 if (strchrW(buffer,'['))
2808 deformat_string(package,buffer,&deformated);
2809 IShellLinkW_SetPath(sl,deformated);
2810 HeapFree(GetProcessHeap(),0,deformated);
2815 FIXME("poorly handled shortcut format, advertised shortcut\n");
2816 keypath = strdupW( comp->FullKeypath );
2817 IShellLinkW_SetPath(sl,keypath);
2818 HeapFree(GetProcessHeap(),0,keypath);
2821 if (!MSI_RecordIsNull(row,6))
2824 buffer = MSI_RecordGetString(row,6);
2825 deformat_string(package,buffer,&deformated);
2826 IShellLinkW_SetArguments(sl,deformated);
2827 HeapFree(GetProcessHeap(),0,deformated);
2830 if (!MSI_RecordIsNull(row,7))
2832 buffer = MSI_RecordGetString(row,7);
2833 IShellLinkW_SetDescription(sl,buffer);
2836 if (!MSI_RecordIsNull(row,8))
2837 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
2839 if (!MSI_RecordIsNull(row,9))
2844 buffer = MSI_RecordGetString(row,9);
2846 build_icon_path(package,buffer,&Path);
2847 index = MSI_RecordGetInteger(row,10);
2849 IShellLinkW_SetIconLocation(sl,Path,index);
2850 HeapFree(GetProcessHeap(),0,Path);
2853 if (!MSI_RecordIsNull(row,11))
2854 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
2856 if (!MSI_RecordIsNull(row,12))
2859 buffer = MSI_RecordGetString(row,12);
2860 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
2861 IShellLinkW_SetWorkingDirectory(sl,Path);
2862 HeapFree(GetProcessHeap(), 0, Path);
2865 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
2866 IPersistFile_Save(pf,target_file,FALSE);
2868 HeapFree(GetProcessHeap(),0,target_file);
2870 IPersistFile_Release( pf );
2871 IShellLinkW_Release( sl );
2873 return ERROR_SUCCESS;
2876 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
2881 static const WCHAR Query[] =
2882 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2883 '`','S','h','o','r','t','c','u','t','`',0};
2886 return ERROR_INVALID_HANDLE;
2888 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2889 if (rc != ERROR_SUCCESS)
2890 return ERROR_SUCCESS;
2892 res = CoInitialize( NULL );
2895 ERR("CoInitialize failed\n");
2896 return ERROR_FUNCTION_FAILED;
2899 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateShortcuts, package);
2900 msiobj_release(&view->hdr);
2907 static UINT ITERATE_PublishProduct(MSIRECORD *row, LPVOID param)
2909 MSIPACKAGE* package = (MSIPACKAGE*)param;
2911 LPWSTR FilePath=NULL;
2912 LPCWSTR FileName=NULL;
2917 FileName = MSI_RecordGetString(row,1);
2920 ERR("Unable to get FileName\n");
2921 return ERROR_SUCCESS;
2924 build_icon_path(package,FileName,&FilePath);
2926 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
2928 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2929 FILE_ATTRIBUTE_NORMAL, NULL);
2931 if (the_file == INVALID_HANDLE_VALUE)
2933 ERR("Unable to create file %s\n",debugstr_w(FilePath));
2934 HeapFree(GetProcessHeap(),0,FilePath);
2935 return ERROR_SUCCESS;
2942 rc = MSI_RecordReadStream(row,2,buffer,&sz);
2943 if (rc != ERROR_SUCCESS)
2945 ERR("Failed to get stream\n");
2946 CloseHandle(the_file);
2947 DeleteFileW(FilePath);
2950 WriteFile(the_file,buffer,sz,&write,NULL);
2951 } while (sz == 1024);
2953 HeapFree(GetProcessHeap(),0,FilePath);
2955 CloseHandle(the_file);
2956 return ERROR_SUCCESS;
2960 * 99% of the work done here is only done for
2961 * advertised installs. However this is where the
2962 * Icon table is processed and written out
2963 * so that is what I am going to do here.
2965 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
2969 static const WCHAR Query[]=
2970 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2971 '`','I','c','o','n','`',0};
2972 /* for registry stuff */
2975 static const WCHAR szProductLanguage[] =
2976 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
2977 static const WCHAR szARPProductIcon[] =
2978 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
2979 static const WCHAR szProductVersion[] =
2980 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
2984 MSIHANDLE hDb, hSumInfo;
2987 return ERROR_INVALID_HANDLE;
2989 /* write out icon files */
2991 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2992 if (rc == ERROR_SUCCESS)
2994 MSI_IterateRecords(view, NULL, ITERATE_PublishProduct, package);
2995 msiobj_release(&view->hdr);
2998 /* ok there is a lot more done here but i need to figure out what */
3000 rc = MSIREG_OpenProductsKey(package->ProductCode,&hkey,TRUE);
3001 if (rc != ERROR_SUCCESS)
3004 rc = MSIREG_OpenUserProductsKey(package->ProductCode,&hukey,TRUE);
3005 if (rc != ERROR_SUCCESS)
3009 buffer = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTNAMEW,NULL);
3010 size = strlenW(buffer)*sizeof(WCHAR);
3011 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTNAMEW,0,REG_SZ,
3012 (LPBYTE)buffer,size);
3013 HeapFree(GetProcessHeap(),0,buffer);
3015 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3016 size = sizeof(DWORD);
3017 langid = atoiW(buffer);
3018 RegSetValueExW(hukey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3019 (LPBYTE)&langid,size);
3020 HeapFree(GetProcessHeap(),0,buffer);
3022 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
3026 build_icon_path(package,buffer,&path);
3027 size = strlenW(path) * sizeof(WCHAR);
3028 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTICONW,0,REG_SZ,
3031 HeapFree(GetProcessHeap(),0,buffer);
3033 buffer = load_dynamic_property(package,szProductVersion,NULL);
3036 DWORD verdword = build_version_dword(buffer);
3037 size = sizeof(DWORD);
3038 RegSetValueExW(hukey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD, (LPBYTE
3041 HeapFree(GetProcessHeap(),0,buffer);
3043 FIXME("Need to write more keys to the user registry\n");
3045 hDb= alloc_msihandle( &package->db->hdr );
3046 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
3047 MsiCloseHandle(hDb);
3048 if (rc == ERROR_SUCCESS)
3050 WCHAR guidbuffer[0x200];
3052 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
3054 if (rc == ERROR_SUCCESS)
3056 WCHAR squashed[GUID_SIZE];
3057 /* for now we only care about the first guid */
3058 LPWSTR ptr = strchrW(guidbuffer,';');
3060 squash_guid(guidbuffer,squashed);
3061 size = strlenW(squashed)*sizeof(WCHAR);
3062 RegSetValueExW(hukey,INSTALLPROPERTY_PACKAGECODEW,0,REG_SZ,
3063 (LPBYTE)squashed, size);
3067 ERR("Unable to query Revision_Number... \n");
3070 MsiCloseHandle(hSumInfo);
3074 ERR("Unable to open Summary Information\n");
3086 static UINT ITERATE_WriteIniValues(MSIRECORD *row, LPVOID param)
3088 MSIPACKAGE *package = (MSIPACKAGE*)param;
3089 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
3090 LPWSTR deformated_section, deformated_key, deformated_value;
3091 LPWSTR folder, fullname = NULL;
3095 static const WCHAR szWindowsFolder[] =
3096 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3098 component = MSI_RecordGetString(row, 8);
3099 comp = get_loaded_component(package,component);
3101 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
3103 TRACE("Skipping ini file due to disabled component %s\n",
3104 debugstr_w(component));
3106 comp->Action = comp->Installed;
3108 return ERROR_SUCCESS;
3111 comp->Action = INSTALLSTATE_LOCAL;
3113 identifier = MSI_RecordGetString(row,1);
3114 filename = MSI_RecordGetString(row,2);
3115 dirproperty = MSI_RecordGetString(row,3);
3116 section = MSI_RecordGetString(row,4);
3117 key = MSI_RecordGetString(row,5);
3118 value = MSI_RecordGetString(row,6);
3119 action = MSI_RecordGetInteger(row,7);
3121 deformat_string(package,section,&deformated_section);
3122 deformat_string(package,key,&deformated_key);
3123 deformat_string(package,value,&deformated_value);
3127 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
3129 folder = load_dynamic_property(package,dirproperty,NULL);
3132 folder = load_dynamic_property(package, szWindowsFolder, NULL);
3136 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
3140 fullname = build_directory_name(2, folder, filename);
3144 TRACE("Adding value %s to section %s in %s\n",
3145 debugstr_w(deformated_key), debugstr_w(deformated_section),
3146 debugstr_w(fullname));
3147 WritePrivateProfileStringW(deformated_section, deformated_key,
3148 deformated_value, fullname);
3150 else if (action == 1)
3153 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
3154 returned, 10, fullname);
3155 if (returned[0] == 0)
3157 TRACE("Adding value %s to section %s in %s\n",
3158 debugstr_w(deformated_key), debugstr_w(deformated_section),
3159 debugstr_w(fullname));
3161 WritePrivateProfileStringW(deformated_section, deformated_key,
3162 deformated_value, fullname);
3165 else if (action == 3)
3166 FIXME("Append to existing section not yet implemented\n");
3168 uirow = MSI_CreateRecord(4);
3169 MSI_RecordSetStringW(uirow,1,identifier);
3170 MSI_RecordSetStringW(uirow,2,deformated_section);
3171 MSI_RecordSetStringW(uirow,3,deformated_key);
3172 MSI_RecordSetStringW(uirow,4,deformated_value);
3173 ui_actiondata(package,szWriteIniValues,uirow);
3174 msiobj_release( &uirow->hdr );
3176 HeapFree(GetProcessHeap(),0,fullname);
3177 HeapFree(GetProcessHeap(),0,folder);
3178 HeapFree(GetProcessHeap(),0,deformated_key);
3179 HeapFree(GetProcessHeap(),0,deformated_value);
3180 HeapFree(GetProcessHeap(),0,deformated_section);
3181 return ERROR_SUCCESS;
3184 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
3188 static const WCHAR ExecSeqQuery[] =
3189 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3190 '`','I','n','i','F','i','l','e','`',0};
3192 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3193 if (rc != ERROR_SUCCESS)
3195 TRACE("no IniFile table\n");
3196 return ERROR_SUCCESS;
3199 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteIniValues, package);
3200 msiobj_release(&view->hdr);
3204 static UINT ITERATE_SelfRegModules(MSIRECORD *row, LPVOID param)
3206 MSIPACKAGE *package = (MSIPACKAGE*)param;
3211 static const WCHAR ExeStr[] =
3212 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3213 static const WCHAR close[] = {'\"',0};
3215 PROCESS_INFORMATION info;
3218 memset(&si,0,sizeof(STARTUPINFOW));
3220 filename = MSI_RecordGetString(row,1);
3221 file = get_loaded_file( package, filename );
3225 ERR("Unable to find file id %s\n",debugstr_w(filename));
3226 return ERROR_SUCCESS;
3229 len = strlenW(ExeStr) + strlenW( file->TargetPath ) + 2;
3231 FullName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3232 strcpyW(FullName,ExeStr);
3233 strcatW( FullName, file->TargetPath );
3234 strcatW(FullName,close);
3236 TRACE("Registering %s\n",debugstr_w(FullName));
3237 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL, c_colon,
3241 msi_dialog_check_messages(info.hProcess);
3243 HeapFree(GetProcessHeap(),0,FullName);
3244 return ERROR_SUCCESS;
3247 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
3251 static const WCHAR ExecSeqQuery[] =
3252 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3253 '`','S','e','l','f','R','e','g','`',0};
3255 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3256 if (rc != ERROR_SUCCESS)
3258 TRACE("no SelfReg table\n");
3259 return ERROR_SUCCESS;
3262 MSI_IterateRecords(view, NULL, ITERATE_SelfRegModules, package);
3263 msiobj_release(&view->hdr);
3265 return ERROR_SUCCESS;
3268 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
3270 MSIFEATURE *feature;
3276 return ERROR_INVALID_HANDLE;
3278 rc = MSIREG_OpenFeaturesKey(package->ProductCode,&hkey,TRUE);
3279 if (rc != ERROR_SUCCESS)
3282 rc = MSIREG_OpenUserFeaturesKey(package->ProductCode,&hukey,TRUE);
3283 if (rc != ERROR_SUCCESS)
3286 /* here the guids are base 85 encoded */
3287 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
3293 BOOL absent = FALSE;
3295 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ) &&
3296 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_SOURCE ) &&
3297 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED ))
3301 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3305 if (feature->Feature_Parent[0])
3306 size += strlenW( feature->Feature_Parent )+2;
3308 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
3311 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3313 MSICOMPONENT* component = cl->component;
3316 memset(buf,0,sizeof(buf));
3317 if ( component->ComponentId[0] )
3319 TRACE("From %s\n",debugstr_w(component->ComponentId));
3320 CLSIDFromString(component->ComponentId, &clsid);
3321 encode_base85_guid(&clsid,buf);
3322 TRACE("to %s\n",debugstr_w(buf));
3326 if (feature->Feature_Parent[0])
3328 static const WCHAR sep[] = {'\2',0};
3330 strcatW(data,feature->Feature_Parent);
3333 size = (strlenW(data)+1)*sizeof(WCHAR);
3334 RegSetValueExW( hkey, feature->Feature, 0, REG_SZ, (LPBYTE)data,size );
3335 HeapFree(GetProcessHeap(),0,data);
3339 size = strlenW(feature->Feature_Parent)*sizeof(WCHAR);
3340 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3341 (LPBYTE)feature->Feature_Parent,size);
3345 size = (strlenW(feature->Feature_Parent)+2)* sizeof(WCHAR);
3346 data = HeapAlloc(GetProcessHeap(),0,size);
3348 strcpyW( &data[1], feature->Feature_Parent );
3349 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3351 HeapFree(GetProcessHeap(),0,data);
3361 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
3364 LPWSTR buffer = NULL;
3367 static WCHAR szNONE[] = {0};
3368 static const WCHAR szWindowsInstaler[] =
3369 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3370 static const WCHAR szPropKeys[][80] =
3372 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3373 {'A','R','P','C','O','N','T','A','C','T',0},
3374 {'A','R','P','C','O','M','M','E','N','T','S',0},
3375 {'P','r','o','d','u','c','t','N','a','m','e',0},
3376 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3377 {'A','R','P','H','E','L','P','L','I','N','K',0},
3378 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3379 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3380 {'S','o','u','r','c','e','D','i','r',0},
3381 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3382 {'A','R','P','R','E','A','D','M','E',0},
3383 {'A','R','P','S','I','Z','E',0},
3384 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3385 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3389 static const WCHAR szRegKeys[][80] =
3391 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3392 {'C','o','n','t','a','c','t',0},
3393 {'C','o','m','m','e','n','t','s',0},
3394 {'D','i','s','p','l','a','y','N','a','m','e',0},
3395 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3396 {'H','e','l','p','L','i','n','k',0},
3397 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3398 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3399 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3400 {'P','u','b','l','i','s','h','e','r',0},
3401 {'R','e','a','d','m','e',0},
3402 {'S','i','z','e',0},
3403 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3404 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3408 static const WCHAR installerPathFmt[] = {
3410 'I','n','s','t','a','l','l','e','r','\\',0};
3411 static const WCHAR fmt[] = {
3413 'I','n','s','t','a','l','l','e','r','\\',
3414 '%','x','.','m','s','i',0};
3415 static const WCHAR szUpgradeCode[] =
3416 {'U','p','g','r','a','d','e','C','o','d','e',0};
3417 static const WCHAR modpath_fmt[] =
3418 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3419 static const WCHAR szModifyPath[] =
3420 {'M','o','d','i','f','y','P','a','t','h',0};
3421 static const WCHAR szUninstallString[] =
3422 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3423 static const WCHAR szEstimatedSize[] =
3424 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3425 static const WCHAR szProductLanguage[] =
3426 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3427 static const WCHAR szProductVersion[] =
3428 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3431 static const WCHAR date_fmt[] = {'%','i','%','i','%','i',0};
3432 LPWSTR upgrade_code;
3433 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
3437 return ERROR_INVALID_HANDLE;
3439 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3440 if (rc != ERROR_SUCCESS)
3443 /* dump all the info i can grab */
3444 FIXME("Flesh out more information \n");
3447 while (szPropKeys[i][0]!=0)
3449 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3450 if (rc != ERROR_SUCCESS)
3452 size = strlenW(buffer)*sizeof(WCHAR);
3453 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3454 HeapFree(GetProcessHeap(),0,buffer);
3460 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPBYTE)&rc,size);
3462 /* copy the package locally */
3463 num = GetTickCount() & 0xffff;
3467 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
3468 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
3472 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
3473 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
3474 if (handle != INVALID_HANDLE_VALUE)
3476 CloseHandle(handle);
3479 if (GetLastError() != ERROR_FILE_EXISTS &&
3480 GetLastError() != ERROR_SHARING_VIOLATION)
3482 if (!(++num & 0xffff)) num = 1;
3483 sprintfW(packagefile,fmt,num);
3484 } while (num != start);
3486 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
3487 create_full_pathW(path);
3488 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
3489 if (!CopyFileW(package->msiFilePath,packagefile,FALSE))
3490 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3491 debugstr_w(package->msiFilePath), debugstr_w(packagefile),
3493 size = strlenW(packagefile)*sizeof(WCHAR);
3494 RegSetValueExW(hkey,INSTALLPROPERTY_LOCALPACKAGEW,0,REG_SZ,
3495 (LPBYTE)packagefile,size);
3497 /* do ModifyPath and UninstallString */
3498 size = deformat_string(package,modpath_fmt,&buffer);
3499 RegSetValueExW(hkey,szModifyPath,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3500 RegSetValueExW(hkey,szUninstallString,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3501 HeapFree(GetProcessHeap(),0,buffer);
3503 FIXME("Write real Estimated Size when we have it\n");
3505 RegSetValueExW(hkey,szEstimatedSize,0,REG_DWORD,(LPBYTE)&size,sizeof(DWORD));
3507 GetLocalTime(&systime);
3508 size = 9*sizeof(WCHAR);
3509 buffer= HeapAlloc(GetProcessHeap(),0,size);
3510 sprintfW(buffer,date_fmt,systime.wYear,systime.wMonth,systime.wDay);
3511 size = strlenW(buffer)*sizeof(WCHAR);
3512 RegSetValueExW(hkey,INSTALLPROPERTY_INSTALLDATEW,0,REG_SZ,
3513 (LPBYTE)buffer,size);
3514 HeapFree(GetProcessHeap(),0,buffer);
3516 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3517 size = atoiW(buffer);
3518 RegSetValueExW(hkey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3519 (LPBYTE)&size,sizeof(DWORD));
3520 HeapFree(GetProcessHeap(),1,buffer);
3522 buffer = load_dynamic_property(package,szProductVersion,NULL);
3525 DWORD verdword = build_version_dword(buffer);
3526 DWORD vermajor = verdword>>24;
3527 DWORD verminor = (verdword>>16)&0x00FF;
3528 size = sizeof(DWORD);
3529 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD,
3530 (LPBYTE)&verdword,size);
3531 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMAJORW,0,REG_DWORD,
3532 (LPBYTE)&vermajor,size);
3533 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMINORW,0,REG_DWORD,
3534 (LPBYTE)&verminor,size);
3536 HeapFree(GetProcessHeap(),0,buffer);
3538 /* Handle Upgrade Codes */
3539 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
3544 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3545 squash_guid(package->ProductCode,squashed);
3546 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3548 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3549 squash_guid(package->ProductCode,squashed);
3550 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3553 HeapFree(GetProcessHeap(),0,upgrade_code);
3559 return ERROR_SUCCESS;
3562 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
3567 return ERROR_INVALID_HANDLE;
3569 rc = execute_script(package,INSTALL_SCRIPT);
3574 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
3579 return ERROR_INVALID_HANDLE;
3581 /* turn off scheduleing */
3582 package->script->CurrentlyScripting= FALSE;
3584 /* first do the same as an InstallExecute */
3585 rc = ACTION_InstallExecute(package);
3586 if (rc != ERROR_SUCCESS)
3589 /* then handle Commit Actions */
3590 rc = execute_script(package,COMMIT_SCRIPT);
3595 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
3597 static const WCHAR RunOnce[] = {
3598 'S','o','f','t','w','a','r','e','\\',
3599 'M','i','c','r','o','s','o','f','t','\\',
3600 'W','i','n','d','o','w','s','\\',
3601 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3602 'R','u','n','O','n','c','e',0};
3603 static const WCHAR InstallRunOnce[] = {
3604 'S','o','f','t','w','a','r','e','\\',
3605 'M','i','c','r','o','s','o','f','t','\\',
3606 'W','i','n','d','o','w','s','\\',
3607 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3608 'I','n','s','t','a','l','l','e','r','\\',
3609 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3611 static const WCHAR msiexec_fmt[] = {
3613 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3614 '\"','%','s','\"',0};
3615 static const WCHAR install_fmt[] = {
3616 '/','I',' ','\"','%','s','\"',' ',
3617 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3618 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3619 WCHAR buffer[256], sysdir[MAX_PATH];
3621 WCHAR squished_pc[100];
3625 return ERROR_INVALID_HANDLE;
3627 squash_guid(package->ProductCode,squished_pc);
3629 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
3630 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
3631 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
3634 size = strlenW(buffer)*sizeof(WCHAR);
3635 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3638 TRACE("Reboot command %s\n",debugstr_w(buffer));
3640 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
3641 sprintfW(buffer,install_fmt,package->ProductCode,squished_pc);
3643 size = strlenW(buffer)*sizeof(WCHAR);
3644 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3647 return ERROR_INSTALL_SUSPEND;
3650 UINT ACTION_ResolveSource(MSIPACKAGE* package)
3655 * we are currently doing what should be done here in the top level Install
3656 * however for Adminastrative and uninstalls this step will be needed
3658 if (!package->PackagePath)
3659 return ERROR_SUCCESS;
3661 attrib = GetFileAttributesW(package->PackagePath);
3662 if (attrib == INVALID_FILE_ATTRIBUTES)
3668 rc = MsiSourceListGetInfoW(package->ProductCode, NULL,
3669 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3670 INSTALLPROPERTY_DISKPROMPTW,NULL,&size);
3671 if (rc == ERROR_MORE_DATA)
3673 prompt = HeapAlloc(GetProcessHeap(),0,size * sizeof(WCHAR));
3674 MsiSourceListGetInfoW(package->ProductCode, NULL,
3675 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3676 INSTALLPROPERTY_DISKPROMPTW,prompt,&size);
3679 prompt = strdupW(package->PackagePath);
3681 msg = generate_error_string(package,1302,1,prompt);
3682 while(attrib == INVALID_FILE_ATTRIBUTES)
3684 rc = MessageBoxW(NULL,msg,NULL,MB_OKCANCEL);
3687 rc = ERROR_INSTALL_USEREXIT;
3690 attrib = GetFileAttributesW(package->PackagePath);
3692 HeapFree(GetProcessHeap(),0,prompt);
3696 return ERROR_SUCCESS;
3701 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
3709 static const WCHAR szPropKeys[][80] =
3711 {'P','r','o','d','u','c','t','I','D',0},
3712 {'U','S','E','R','N','A','M','E',0},
3713 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3717 static const WCHAR szRegKeys[][80] =
3719 {'P','r','o','d','u','c','t','I','D',0},
3720 {'R','e','g','O','w','n','e','r',0},
3721 {'R','e','g','C','o','m','p','a','n','y',0},
3726 return ERROR_INVALID_HANDLE;
3728 productid = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTIDW, &rc);
3730 return ERROR_SUCCESS;
3732 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3733 if (rc != ERROR_SUCCESS)
3737 while (szPropKeys[i][0]!=0)
3739 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3740 if (rc == ERROR_SUCCESS)
3742 size = strlenW(buffer)*sizeof(WCHAR);
3743 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3746 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
3751 HeapFree(GetProcessHeap(),0,productid);
3754 return ERROR_SUCCESS;
3758 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
3760 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
3761 static const WCHAR szTwo[] = {'2',0};
3764 level = load_dynamic_property(package,szUILevel,NULL);
3766 MSI_SetPropertyW(package,szUILevel,szTwo);
3767 package->script->InWhatSequence |= SEQUENCE_EXEC;
3768 rc = ACTION_ProcessExecSequence(package,FALSE);
3769 MSI_SetPropertyW(package,szUILevel,level);
3770 HeapFree(GetProcessHeap(),0,level);
3776 * Code based off of code located here
3777 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3779 * Using string index 4 (full font name) instead of 1 (family name)
3781 static LPWSTR load_ttfname_from(LPCWSTR filename)
3787 typedef struct _tagTT_OFFSET_TABLE{
3788 USHORT uMajorVersion;
3789 USHORT uMinorVersion;
3790 USHORT uNumOfTables;
3791 USHORT uSearchRange;
3792 USHORT uEntrySelector;
3796 typedef struct _tagTT_TABLE_DIRECTORY{
3797 char szTag[4]; /* table name */
3798 ULONG uCheckSum; /* Check sum */
3799 ULONG uOffset; /* Offset from beginning of file */
3800 ULONG uLength; /* length of the table in bytes */
3801 }TT_TABLE_DIRECTORY;
3803 typedef struct _tagTT_NAME_TABLE_HEADER{
3804 USHORT uFSelector; /* format selector. Always 0 */
3805 USHORT uNRCount; /* Name Records count */
3806 USHORT uStorageOffset; /* Offset for strings storage,
3807 * from start of the table */
3808 }TT_NAME_TABLE_HEADER;
3810 typedef struct _tagTT_NAME_RECORD{
3815 USHORT uStringLength;
3816 USHORT uStringOffset; /* from start of storage area */
3819 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3820 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3822 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
3823 FILE_ATTRIBUTE_NORMAL, 0 );
3824 if (handle != INVALID_HANDLE_VALUE)
3826 TT_TABLE_DIRECTORY tblDir;
3827 BOOL bFound = FALSE;
3828 TT_OFFSET_TABLE ttOffsetTable;
3830 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
3831 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
3832 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
3833 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
3835 if (ttOffsetTable.uMajorVersion != 1 ||
3836 ttOffsetTable.uMinorVersion != 0)
3839 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
3841 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
3842 if (strncmp(tblDir.szTag,"name",4)==0)
3845 tblDir.uLength = SWAPLONG(tblDir.uLength);
3846 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
3853 TT_NAME_TABLE_HEADER ttNTHeader;
3854 TT_NAME_RECORD ttRecord;
3856 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
3857 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
3860 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
3861 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
3863 for(i=0; i<ttNTHeader.uNRCount; i++)
3865 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
3866 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
3867 /* 4 is the Full Font Name */
3868 if(ttRecord.uNameID == 4)
3872 static LPCSTR tt = " (TrueType)";
3874 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
3875 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
3876 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
3877 SetFilePointer(handle, tblDir.uOffset +
3878 ttRecord.uStringOffset +
3879 ttNTHeader.uStorageOffset,
3881 buf = HeapAlloc(GetProcessHeap(), 0,
3882 ttRecord.uStringLength + 1 + strlen(tt));
3883 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
3884 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
3885 if (strlen(buf) > 0)
3888 ret = strdupAtoW(buf);
3889 HeapFree(GetProcessHeap(),0,buf);
3893 HeapFree(GetProcessHeap(),0,buf);
3894 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
3898 CloseHandle(handle);
3901 ERR("Unable to open font file %s\n", debugstr_w(filename));
3903 TRACE("Returning fontname %s\n",debugstr_w(ret));
3907 static UINT ITERATE_RegisterFonts(MSIRECORD *row, LPVOID param)
3909 MSIPACKAGE *package = (MSIPACKAGE*)param;
3914 static const WCHAR regfont1[] =
3915 {'S','o','f','t','w','a','r','e','\\',
3916 'M','i','c','r','o','s','o','f','t','\\',
3917 'W','i','n','d','o','w','s',' ','N','T','\\',
3918 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3919 'F','o','n','t','s',0};
3920 static const WCHAR regfont2[] =
3921 {'S','o','f','t','w','a','r','e','\\',
3922 'M','i','c','r','o','s','o','f','t','\\',
3923 'W','i','n','d','o','w','s','\\',
3924 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3925 'F','o','n','t','s',0};
3929 filename = MSI_RecordGetString( row, 1 );
3930 file = get_loaded_file( package, filename );
3933 ERR("Unable to load file\n");
3934 return ERROR_SUCCESS;
3937 /* check to make sure that component is installed */
3938 if (!ACTION_VerifyComponentForAction(package,
3939 file->Component, INSTALLSTATE_LOCAL))
3941 TRACE("Skipping: Component not scheduled for install\n");
3942 return ERROR_SUCCESS;
3945 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
3946 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
3948 if (MSI_RecordIsNull(row,2))
3949 name = load_ttfname_from( file->TargetPath );
3951 name = load_dynamic_stringW(row,2);
3955 size = strlenW( file->FileName ) * sizeof(WCHAR);
3956 RegSetValueExW( hkey1, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3957 RegSetValueExW( hkey2, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3960 HeapFree(GetProcessHeap(),0,name);
3963 return ERROR_SUCCESS;
3966 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
3970 static const WCHAR ExecSeqQuery[] =
3971 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3972 '`','F','o','n','t','`',0};
3974 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3975 if (rc != ERROR_SUCCESS)
3977 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
3978 return ERROR_SUCCESS;
3981 MSI_IterateRecords(view, NULL, ITERATE_RegisterFonts, package);
3982 msiobj_release(&view->hdr);
3984 return ERROR_SUCCESS;
3987 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
3989 MSIPACKAGE *package = (MSIPACKAGE*)param;
3990 LPCWSTR compgroupid=NULL;
3991 LPCWSTR feature=NULL;
3992 LPCWSTR text = NULL;
3993 LPCWSTR qualifier = NULL;
3994 LPCWSTR component = NULL;
3995 LPWSTR advertise = NULL;
3996 LPWSTR output = NULL;
3998 UINT rc = ERROR_SUCCESS;
4002 component = MSI_RecordGetString(rec,3);
4003 comp = get_loaded_component(package,component);
4005 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL) &&
4006 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_SOURCE) &&
4007 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_ADVERTISED))
4009 TRACE("Skipping: Component %s not scheduled for install\n",
4010 debugstr_w(component));
4012 return ERROR_SUCCESS;
4015 compgroupid = MSI_RecordGetString(rec,1);
4017 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
4018 if (rc != ERROR_SUCCESS)
4021 text = MSI_RecordGetString(rec,4);
4022 qualifier = MSI_RecordGetString(rec,2);
4023 feature = MSI_RecordGetString(rec,5);
4025 advertise = create_component_advertise_string(package, comp, feature);
4027 sz = strlenW(advertise);
4030 sz += lstrlenW(text);
4033 sz *= sizeof(WCHAR);
4035 output = HeapAlloc(GetProcessHeap(),0,sz);
4036 memset(output,0,sz);
4037 strcpyW(output,advertise);
4040 strcatW(output,text);
4042 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
4043 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
4047 HeapFree(GetProcessHeap(),0,output);
4053 * At present I am ignorning the advertised components part of this and only
4054 * focusing on the qualified component sets
4056 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
4060 static const WCHAR ExecSeqQuery[] =
4061 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4062 '`','P','u','b','l','i','s','h',
4063 'C','o','m','p','o','n','e','n','t','`',0};
4065 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4066 if (rc != ERROR_SUCCESS)
4067 return ERROR_SUCCESS;
4069 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
4070 msiobj_release(&view->hdr);