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};
383 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
385 row = MSI_QueryGetRecord( package->db, Query_t, action );
389 ActionText = MSI_RecordGetString(row,2);
391 sprintfW(message,template_s,timet,action,ActionText);
392 msiobj_release(&row->hdr);
394 row = MSI_CreateRecord(1);
395 MSI_RecordSetStringW(row,1,message);
397 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
398 msiobj_release(&row->hdr);
401 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
405 static const WCHAR template_s[]=
406 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
408 static const WCHAR template_e[]=
409 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
410 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
412 static const WCHAR format[] =
413 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
417 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
419 sprintfW(message,template_s,timet,action);
421 sprintfW(message,template_e,timet,action,rc);
423 row = MSI_CreateRecord(1);
424 MSI_RecordSetStringW(row,1,message);
426 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
427 msiobj_release(&row->hdr);
430 /****************************************************
431 * TOP level entry points
432 *****************************************************/
434 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
435 LPCWSTR szCommandLine, LPCWSTR msiFilePath)
441 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
442 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
443 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
445 MSI_SetPropertyW(package, szAction, szInstall);
447 package->script = HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT));
448 memset(package->script,0,sizeof(MSISCRIPT));
450 package->script->InWhatSequence = SEQUENCE_INSTALL;
452 package->msiFilePath= strdupW(msiFilePath);
456 LPWSTR p, check, path;
458 package->PackagePath = strdupW(szPackagePath);
459 path = strdupW(szPackagePath);
460 p = strrchrW(path,'\\');
468 HeapFree(GetProcessHeap(),0,path);
469 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
470 GetCurrentDirectoryW(MAX_PATH,path);
474 check = load_dynamic_property(package, cszSourceDir,NULL);
476 MSI_SetPropertyW(package, cszSourceDir, path);
478 HeapFree(GetProcessHeap(), 0, check);
480 HeapFree(GetProcessHeap(), 0, path);
486 ptr = (LPWSTR)szCommandLine;
493 TRACE("Looking at %s\n",debugstr_w(ptr));
495 ptr2 = strchrW(ptr,'=');
501 while (*ptr == ' ') ptr++;
503 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
504 memcpy(prop,ptr,len*sizeof(WCHAR));
510 while (*ptr && (quote || (!quote && *ptr!=' ')))
523 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
524 memcpy(val,ptr2,len*sizeof(WCHAR));
527 if (strlenW(prop) > 0)
529 TRACE("Found commandline property (%s) = (%s)\n",
530 debugstr_w(prop), debugstr_w(val));
531 MSI_SetPropertyW(package,prop,val);
533 HeapFree(GetProcessHeap(),0,val);
534 HeapFree(GetProcessHeap(),0,prop);
541 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
543 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
545 package->script->InWhatSequence |= SEQUENCE_UI;
546 rc = ACTION_ProcessUISequence(package);
548 if (rc == ERROR_SUCCESS)
550 package->script->InWhatSequence |= SEQUENCE_EXEC;
551 rc = ACTION_ProcessExecSequence(package,TRUE);
555 rc = ACTION_ProcessExecSequence(package,FALSE);
558 rc = ACTION_ProcessExecSequence(package,FALSE);
562 /* install was halted but should be considered a success */
566 package->script->CurrentlyScripting= FALSE;
568 /* process the ending type action */
569 if (rc == ERROR_SUCCESS)
570 ACTION_PerformActionSequence(package,-1,ui);
571 else if (rc == ERROR_INSTALL_USEREXIT)
572 ACTION_PerformActionSequence(package,-2,ui);
573 else if (rc == ERROR_INSTALL_SUSPEND)
574 ACTION_PerformActionSequence(package,-4,ui);
576 ACTION_PerformActionSequence(package,-3,ui);
578 /* finish up running custom actions */
579 ACTION_FinishCustomActions(package);
584 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
586 UINT rc = ERROR_SUCCESS;
588 static const WCHAR ExecSeqQuery[] =
589 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
590 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
591 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
592 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
594 static const WCHAR UISeqQuery[] =
595 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
596 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
597 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
598 ' ', '=',' ','%','i',0};
601 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
603 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
607 LPCWSTR action, cond;
609 TRACE("Running the actions\n");
611 /* check conditions */
612 cond = MSI_RecordGetString(row,2);
615 /* this is a hack to skip errors in the condition code */
616 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
620 action = MSI_RecordGetString(row,1);
623 ERR("failed to fetch action\n");
624 rc = ERROR_FUNCTION_FAILED;
629 rc = ACTION_PerformUIAction(package,action);
631 rc = ACTION_PerformAction(package,action,FALSE);
633 msiobj_release(&row->hdr);
644 } iterate_action_param;
646 static UINT ITERATE_Actions(MSIRECORD *row, LPVOID param)
648 iterate_action_param *iap= (iterate_action_param*)param;
650 LPCWSTR cond, action;
652 action = MSI_RecordGetString(row,1);
655 ERR("Error is retrieving action name\n");
656 return ERROR_FUNCTION_FAILED;
659 /* check conditions */
660 cond = MSI_RecordGetString(row,2);
663 /* this is a hack to skip errors in the condition code */
664 if (MSI_EvaluateConditionW(iap->package, cond) == MSICONDITION_FALSE)
666 TRACE("Skipping action: %s (condition is false)\n",
668 return ERROR_SUCCESS;
673 rc = ACTION_PerformUIAction(iap->package,action);
675 rc = ACTION_PerformAction(iap->package,action,FALSE);
677 msi_dialog_check_messages( NULL );
679 if (iap->package->CurrentInstallState != ERROR_SUCCESS )
680 rc = iap->package->CurrentInstallState;
682 if (rc == ERROR_FUNCTION_NOT_CALLED)
685 if (rc != ERROR_SUCCESS)
686 ERR("Execution halted due to error (%i)\n",rc);
691 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
695 static const WCHAR ExecSeqQuery[] =
696 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
697 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
698 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
699 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
700 'O','R','D','E','R',' ', 'B','Y',' ',
701 '`','S','e','q','u','e','n','c','e','`',0 };
703 static const WCHAR IVQuery[] =
704 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
705 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
706 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
707 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
708 ' ','\'', 'I','n','s','t','a','l','l',
709 'V','a','l','i','d','a','t','e','\'', 0};
711 iterate_action_param iap;
713 iap.package = package;
716 if (package->script->ExecuteSequenceRun)
718 TRACE("Execute Sequence already Run\n");
719 return ERROR_SUCCESS;
722 package->script->ExecuteSequenceRun = TRUE;
724 /* get the sequence number */
727 row = MSI_QueryGetRecord(package->db, IVQuery);
729 return ERROR_FUNCTION_FAILED;
730 seq = MSI_RecordGetInteger(row,1);
731 msiobj_release(&row->hdr);
734 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
735 if (rc == ERROR_SUCCESS)
737 TRACE("Running the actions\n");
739 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
740 msiobj_release(&view->hdr);
746 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
750 static const WCHAR ExecSeqQuery [] =
751 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
752 '`','I','n','s','t','a','l','l',
753 'U','I','S','e','q','u','e','n','c','e','`',
754 ' ','W','H','E','R','E',' ',
755 '`','S','e','q','u','e','n','c','e','`',' ',
756 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
757 '`','S','e','q','u','e','n','c','e','`',0};
758 iterate_action_param iap;
760 iap.package = package;
763 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
765 if (rc == ERROR_SUCCESS)
767 TRACE("Running the actions \n");
769 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
770 msiobj_release(&view->hdr);
776 /********************************************************
777 * ACTION helper functions and functions that perform the actions
778 *******************************************************/
779 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
780 UINT* rc, BOOL force )
786 if (!run && !package->script->CurrentlyScripting)
791 if (strcmpW(action,szInstallFinalize) == 0 ||
792 strcmpW(action,szInstallExecute) == 0 ||
793 strcmpW(action,szInstallExecuteAgain) == 0)
798 while (StandardActions[i].action != NULL)
800 if (strcmpW(StandardActions[i].action, action)==0)
802 ce_actiontext(package, action);
805 ui_actioninfo(package, action, TRUE, 0);
806 *rc = schedule_action(package,INSTALL_SCRIPT,action);
807 ui_actioninfo(package, action, FALSE, *rc);
811 ui_actionstart(package, action);
812 if (StandardActions[i].handler)
814 *rc = StandardActions[i].handler(package);
818 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
830 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
831 UINT* rc, BOOL force )
836 arc = ACTION_CustomAction(package,action, force);
838 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
847 * A lot of actions are really important even if they don't do anything
848 * explicit... Lots of properties are set at the beginning of the installation
849 * CostFinalize does a bunch of work to translate the directories and such
851 * But until I get write access to the database that is hard, so I am going to
852 * hack it to see if I can get something to run.
854 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
856 UINT rc = ERROR_SUCCESS;
859 TRACE("Performing action (%s)\n",debugstr_w(action));
861 handled = ACTION_HandleStandardAction(package, action, &rc, force);
864 handled = ACTION_HandleCustomAction(package, action, &rc, force);
868 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
869 rc = ERROR_FUNCTION_NOT_CALLED;
875 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
877 UINT rc = ERROR_SUCCESS;
878 BOOL handled = FALSE;
880 TRACE("Performing action (%s)\n",debugstr_w(action));
882 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
885 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
887 if( !handled && ACTION_DialogBox(package,action) == ERROR_SUCCESS )
892 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
893 rc = ERROR_FUNCTION_NOT_CALLED;
901 * Actual Action Handlers
904 static UINT ITERATE_CreateFolders(MSIRECORD *row, LPVOID param)
906 MSIPACKAGE *package = (MSIPACKAGE*)param;
912 dir = MSI_RecordGetString(row,1);
915 ERR("Unable to get folder id \n");
916 return ERROR_SUCCESS;
919 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
922 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
923 return ERROR_SUCCESS;
926 TRACE("Folder is %s\n",debugstr_w(full_path));
929 uirow = MSI_CreateRecord(1);
930 MSI_RecordSetStringW(uirow,1,full_path);
931 ui_actiondata(package,szCreateFolders,uirow);
932 msiobj_release( &uirow->hdr );
934 if (folder->State == 0)
935 create_full_pathW(full_path);
939 HeapFree(GetProcessHeap(),0,full_path);
940 return ERROR_SUCCESS;
945 * Also we cannot enable/disable components either, so for now I am just going
946 * to do all the directories for all the components.
948 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
950 static const WCHAR ExecSeqQuery[] =
951 {'S','E','L','E','C','T',' ',
952 '`','D','i','r','e','c','t','o','r','y','_','`',
953 ' ','F','R','O','M',' ',
954 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
958 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
959 if (rc != ERROR_SUCCESS)
960 return ERROR_SUCCESS;
962 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateFolders, package);
963 msiobj_release(&view->hdr);
968 static MSICOMPONENT* load_component( MSIRECORD * row )
973 comp = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSICOMPONENT) );
977 /* fill in the data */
978 sz = IDENTIFIER_SIZE;
979 MSI_RecordGetStringW(row,1,comp->Component,&sz);
981 TRACE("Loading Component %s\n",
982 debugstr_w(comp->Component));
985 if (!MSI_RecordIsNull(row,2))
986 MSI_RecordGetStringW(row,2,comp->ComponentId,&sz);
988 sz = IDENTIFIER_SIZE;
989 MSI_RecordGetStringW(row,3,comp->Directory,&sz);
991 comp->Attributes = MSI_RecordGetInteger(row,4);
994 MSI_RecordGetStringW(row,5,comp->Condition,&sz);
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 );
1185 file->Temporary = FALSE;
1188 TRACE("File Loaded (%s)\n",debugstr_w(file->File));
1190 list_add_tail( &package->files, &file->entry );
1192 return ERROR_SUCCESS;
1195 static UINT load_all_files(MSIPACKAGE *package)
1199 static const WCHAR Query[] =
1200 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1201 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1202 '`','S','e','q','u','e','n','c','e','`', 0};
1205 return ERROR_INVALID_HANDLE;
1207 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1208 if (rc != ERROR_SUCCESS)
1209 return ERROR_SUCCESS;
1211 rc = MSI_IterateRecords(view, NULL, load_file, package);
1212 msiobj_release(&view->hdr);
1214 return ERROR_SUCCESS;
1219 * I am not doing any of the costing functionality yet.
1220 * Mostly looking at doing the Component and Feature loading
1222 * The native MSI does A LOT of modification to tables here. Mostly adding
1223 * a lot of temporary columns to the Feature and Component tables.
1225 * note: Native msi also tracks the short filename. But I am only going to
1226 * track the long ones. Also looking at this directory table
1227 * it appears that the directory table does not get the parents
1228 * resolved base on property only based on their entries in the
1231 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1235 static const WCHAR Query_all[] =
1236 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1237 '`','F','e','a','t','u','r','e','`',0};
1238 static const WCHAR szCosting[] =
1239 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1240 static const WCHAR szZero[] = { '0', 0 };
1244 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1246 return ERROR_SUCCESS;
1248 MSI_SetPropertyW(package, szCosting, szZero);
1249 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1251 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1252 if (rc != ERROR_SUCCESS)
1255 rc = MSI_IterateRecords(view, NULL, load_feature, package);
1256 msiobj_release(&view->hdr);
1258 load_all_files(package);
1260 return ERROR_SUCCESS;
1263 static UINT execute_script(MSIPACKAGE *package, UINT script )
1266 UINT rc = ERROR_SUCCESS;
1268 TRACE("Executing Script %i\n",script);
1270 for (i = 0; i < package->script->ActionCount[script]; i++)
1273 action = package->script->Actions[script][i];
1274 ui_actionstart(package, action);
1275 TRACE("Executing Action (%s)\n",debugstr_w(action));
1276 rc = ACTION_PerformAction(package, action, TRUE);
1277 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1278 if (rc != ERROR_SUCCESS)
1281 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1283 package->script->ActionCount[script] = 0;
1284 package->script->Actions[script] = NULL;
1288 static UINT ACTION_FileCost(MSIPACKAGE *package)
1290 return ERROR_SUCCESS;
1294 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1296 static const WCHAR Query[] =
1297 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1298 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1299 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1300 ' ','=',' ','\'','%','s','\'',
1302 LPWSTR ptargetdir, targetdir, srcdir;
1304 LPWSTR shortname = NULL;
1305 MSIRECORD * row = 0;
1309 TRACE("Looking for dir %s\n",debugstr_w(dir));
1311 for (i = 0; i < package->loaded_folders; i++)
1313 if (strcmpW(package->folders[i].Directory,dir)==0)
1315 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1320 TRACE("Working to load %s\n",debugstr_w(dir));
1322 index = package->loaded_folders++;
1323 if (package->loaded_folders==1)
1324 package->folders = HeapAlloc(GetProcessHeap(),0,
1327 package->folders= HeapReAlloc(GetProcessHeap(),0,
1328 package->folders, package->loaded_folders*
1331 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1333 package->folders[index].Directory = strdupW(dir);
1335 row = MSI_QueryGetRecord(package->db, Query, dir);
1339 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1341 /* split src and target dir */
1342 if (strchrW(targetdir,':'))
1344 srcdir=strchrW(targetdir,':');
1351 /* for now only pick long filename versions */
1352 if (strchrW(targetdir,'|'))
1354 shortname = targetdir;
1355 targetdir = strchrW(targetdir,'|');
1359 /* for the sourcedir pick the short filename */
1360 if (srcdir && strchrW(srcdir,'|'))
1362 LPWSTR p = strchrW(srcdir,'|');
1366 /* now check for root dirs */
1367 if (targetdir[0] == '.' && targetdir[1] == 0)
1372 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1373 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
1374 package->folders[index].TargetDefault = strdupW(targetdir);
1378 package->folders[index].SourceDefault = strdupW(srcdir);
1380 package->folders[index].SourceDefault = strdupW(shortname);
1382 package->folders[index].SourceDefault = strdupW(targetdir);
1383 HeapFree(GetProcessHeap(), 0, ptargetdir);
1384 TRACE(" SourceDefault = %s\n",debugstr_w(package->folders[index].SourceDefault));
1386 parent = MSI_RecordGetString(row,2);
1389 i = load_folder(package,parent);
1390 package->folders[index].ParentIndex = i;
1391 TRACE("Parent is index %i... %s %s\n",
1392 package->folders[index].ParentIndex,
1393 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1394 debugstr_w(parent));
1397 package->folders[index].ParentIndex = -2;
1399 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
1401 msiobj_release(&row->hdr);
1402 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1406 /* scan for and update current install states */
1407 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
1410 MSIFEATURE *feature;
1412 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1415 res = MsiGetComponentPathW( package->ProductCode,
1416 comp->ComponentId, NULL, NULL);
1418 res = INSTALLSTATE_ABSENT;
1419 comp->Installed = res;
1422 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1425 INSTALLSTATE res = -10;
1427 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1429 comp= cl->component;
1432 res = comp->Installed;
1435 if (res == comp->Installed)
1438 if (res != comp->Installed)
1439 res = INSTALLSTATE_INCOMPLETE;
1445 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
1448 static const WCHAR all[]={'A','L','L',0};
1449 LPWSTR override = NULL;
1451 MSIFEATURE *feature;
1453 override = load_dynamic_property(package, property, NULL);
1457 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1459 if (strcmpiW(override,all)==0)
1461 feature->ActionRequest= state;
1462 feature->Action = state;
1466 LPWSTR ptr = override;
1467 LPWSTR ptr2 = strchrW(override,',');
1472 strncmpW(ptr,feature->Feature, ptr2-ptr)==0)
1473 || (!ptr2 && strcmpW(ptr,feature->Feature)==0))
1475 feature->ActionRequest= state;
1476 feature->Action = state;
1482 ptr2 = strchrW(ptr,',');
1489 HeapFree(GetProcessHeap(),0,override);
1495 static UINT SetFeatureStates(MSIPACKAGE *package)
1499 static const WCHAR szlevel[] =
1500 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1501 static const WCHAR szAddLocal[] =
1502 {'A','D','D','L','O','C','A','L',0};
1503 static const WCHAR szRemove[] =
1504 {'R','E','M','O','V','E',0};
1505 BOOL override = FALSE;
1506 MSICOMPONENT* component;
1507 MSIFEATURE *feature;
1510 /* I do not know if this is where it should happen.. but */
1512 TRACE("Checking Install Level\n");
1514 level = load_dynamic_property(package,szlevel,NULL);
1517 install_level = atoiW(level);
1518 HeapFree(GetProcessHeap(), 0, level);
1523 /* ok hereis the _real_ rub
1524 * all these activation/deactivation things happen in order and things
1525 * later on the list override things earlier on the list.
1526 * 1) INSTALLLEVEL processing
1536 * 11) FILEADDDEFAULT
1537 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1538 * ignored for all the features. seems strange, especially since it is not
1539 * documented anywhere, but it is how it works.
1541 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1542 * REMOVE are the big ones, since we don't handle administrative installs
1545 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
1546 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
1550 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1552 BOOL feature_state = ((feature->Level > 0) &&
1553 (feature->Level <= install_level));
1555 if ((feature_state) && (feature->Action == INSTALLSTATE_UNKNOWN))
1557 if (feature->Attributes & msidbFeatureAttributesFavorSource)
1559 feature->ActionRequest = INSTALLSTATE_SOURCE;
1560 feature->Action = INSTALLSTATE_SOURCE;
1562 else if (feature->Attributes & msidbFeatureAttributesFavorAdvertise)
1564 feature->ActionRequest = INSTALLSTATE_ADVERTISED;
1565 feature->Action = INSTALLSTATE_ADVERTISED;
1569 feature->ActionRequest = INSTALLSTATE_LOCAL;
1570 feature->Action = INSTALLSTATE_LOCAL;
1577 /* set the Preselected Property */
1578 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1579 static const WCHAR szOne[] = { '1', 0 };
1581 MSI_SetPropertyW(package,szPreselected,szOne);
1585 * now we want to enable or disable components base on feature
1588 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1592 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1593 debugstr_w(feature->Feature), feature->Installed, feature->Action,
1594 feature->ActionRequest);
1596 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1598 component = cl->component;
1600 if (!component->Enabled)
1602 component->Action = INSTALLSTATE_UNKNOWN;
1603 component->ActionRequest = INSTALLSTATE_UNKNOWN;
1607 if (feature->Action == INSTALLSTATE_LOCAL)
1609 component->Action = INSTALLSTATE_LOCAL;
1610 component->ActionRequest = INSTALLSTATE_LOCAL;
1612 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
1614 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1615 (component->Action == INSTALLSTATE_ABSENT) ||
1616 (component->Action == INSTALLSTATE_ADVERTISED))
1619 component->Action = INSTALLSTATE_SOURCE;
1620 component->ActionRequest = INSTALLSTATE_SOURCE;
1623 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
1625 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1626 (component->Action == INSTALLSTATE_ABSENT))
1629 component->Action = INSTALLSTATE_ADVERTISED;
1630 component->ActionRequest = INSTALLSTATE_ADVERTISED;
1633 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
1635 if (component->Action == INSTALLSTATE_UNKNOWN)
1637 component->Action = INSTALLSTATE_ABSENT;
1638 component->ActionRequest = INSTALLSTATE_ABSENT;
1645 LIST_FOR_EACH_ENTRY( component, &package->components, MSICOMPONENT, entry )
1647 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1648 debugstr_w(component->Component), component->Installed,
1649 component->Action, component->ActionRequest);
1653 return ERROR_SUCCESS;
1656 static UINT ITERATE_CostFinalizeDirectories(MSIRECORD *row, LPVOID param)
1658 MSIPACKAGE *package = (MSIPACKAGE*)param;
1662 name = MSI_RecordGetString(row,1);
1664 /* This helper function now does ALL the work */
1665 TRACE("Dir %s ...\n",debugstr_w(name));
1666 load_folder(package,name);
1667 path = resolve_folder(package,name,FALSE,TRUE,NULL);
1668 TRACE("resolves to %s\n",debugstr_w(path));
1669 HeapFree( GetProcessHeap(), 0, path);
1671 return ERROR_SUCCESS;
1674 static UINT ITERATE_CostFinalizeConditions(MSIRECORD *row, LPVOID param)
1676 MSIPACKAGE *package = (MSIPACKAGE*)param;
1678 MSIFEATURE *feature;
1680 name = MSI_RecordGetString( row, 1 );
1682 feature = get_loaded_feature( package, name );
1684 ERR("FAILED to find loaded feature %s\n",debugstr_w(name));
1688 Condition = MSI_RecordGetString(row,3);
1690 if (MSI_EvaluateConditionW(package,Condition) == MSICONDITION_TRUE)
1692 int level = MSI_RecordGetInteger(row,2);
1693 TRACE("Reseting feature %s to level %i\n", debugstr_w(name), level);
1694 feature->Level = level;
1697 return ERROR_SUCCESS;
1702 * A lot is done in this function aside from just the costing.
1703 * The costing needs to be implemented at some point but for now I am going
1704 * to focus on the directory building
1707 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
1709 static const WCHAR ExecSeqQuery[] =
1710 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1711 '`','D','i','r','e','c','t','o','r','y','`',0};
1712 static const WCHAR ConditionQuery[] =
1713 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1714 '`','C','o','n','d','i','t','i','o','n','`',0};
1715 static const WCHAR szCosting[] =
1716 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1717 static const WCHAR szlevel[] =
1718 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1719 static const WCHAR szOne[] = { '1', 0 };
1728 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1730 return ERROR_SUCCESS;
1732 TRACE("Building Directory properties\n");
1734 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1735 if (rc == ERROR_SUCCESS)
1737 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeDirectories,
1739 msiobj_release(&view->hdr);
1742 TRACE("File calculations\n");
1744 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
1746 MSICOMPONENT* comp = NULL;
1748 comp = file->Component;
1750 if (file->Temporary == TRUE)
1757 /* calculate target */
1758 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
1760 HeapFree(GetProcessHeap(),0,file->TargetPath);
1762 TRACE("file %s is named %s\n",
1763 debugstr_w(file->File),debugstr_w(file->FileName));
1765 file->TargetPath = build_directory_name(2, p, file->FileName);
1767 HeapFree(GetProcessHeap(),0,p);
1769 TRACE("file %s resolves to %s\n",
1770 debugstr_w(file->File),debugstr_w(file->TargetPath));
1772 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
1775 comp->Cost += file->FileSize;
1785 static const WCHAR name[] =
1787 static const WCHAR name_fmt[] =
1788 {'%','u','.','%','u','.','%','u','.','%','u',0};
1789 WCHAR filever[0x100];
1790 VS_FIXEDFILEINFO *lpVer;
1792 TRACE("Version comparison.. \n");
1793 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
1794 version = HeapAlloc(GetProcessHeap(),0,versize);
1795 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
1797 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
1799 sprintfW(filever,name_fmt,
1800 HIWORD(lpVer->dwFileVersionMS),
1801 LOWORD(lpVer->dwFileVersionMS),
1802 HIWORD(lpVer->dwFileVersionLS),
1803 LOWORD(lpVer->dwFileVersionLS));
1805 TRACE("new %s old %s\n", debugstr_w(file->Version),
1806 debugstr_w(filever));
1807 if (strcmpiW(filever,file->Version)<0)
1810 FIXME("cost should be diff in size\n");
1811 comp->Cost += file->FileSize;
1815 HeapFree(GetProcessHeap(),0,version);
1823 TRACE("Evaluating Condition Table\n");
1825 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
1826 if (rc == ERROR_SUCCESS)
1828 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeConditions,
1830 msiobj_release(&view->hdr);
1833 TRACE("Enabling or Disabling Components\n");
1834 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1836 if (comp->Condition[0])
1838 if (MSI_EvaluateConditionW(package,
1839 comp->Condition) == MSICONDITION_FALSE)
1841 TRACE("Disabling component %s\n", debugstr_w(comp->Component));
1842 comp->Enabled = FALSE;
1847 MSI_SetPropertyW(package,szCosting,szOne);
1848 /* set default run level if not set */
1849 level = load_dynamic_property(package,szlevel,NULL);
1851 MSI_SetPropertyW(package,szlevel, szOne);
1853 HeapFree(GetProcessHeap(),0,level);
1855 ACTION_UpdateInstallStates(package);
1857 return SetFeatureStates(package);
1860 /* OK this value is "interpreted" and then formatted based on the
1861 first few characters */
1862 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
1866 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
1872 LPWSTR deformated = NULL;
1875 deformat_string(package, &value[2], &deformated);
1877 /* binary value type */
1881 *size = (strlenW(ptr)/2)+1;
1883 *size = strlenW(ptr)/2;
1885 data = HeapAlloc(GetProcessHeap(),0,*size);
1891 /* if uneven pad with a zero in front */
1897 data[count] = (BYTE)strtol(byte,NULL,0);
1899 TRACE("Uneven byte count\n");
1907 data[count] = (BYTE)strtol(byte,NULL,0);
1910 HeapFree(GetProcessHeap(),0,deformated);
1912 TRACE("Data %li bytes(%i)\n",*size,count);
1919 deformat_string(package, &value[1], &deformated);
1922 *size = sizeof(DWORD);
1923 data = HeapAlloc(GetProcessHeap(),0,*size);
1929 if ( (*p < '0') || (*p > '9') )
1935 if (deformated[0] == '-')
1938 TRACE("DWORD %li\n",*(LPDWORD)data);
1940 HeapFree(GetProcessHeap(),0,deformated);
1945 static const WCHAR szMulti[] = {'[','~',']',0};
1954 *type=REG_EXPAND_SZ;
1962 if (strstrW(value,szMulti))
1963 *type = REG_MULTI_SZ;
1965 *size = deformat_string(package, ptr,(LPWSTR*)&data);
1970 static UINT ITERATE_WriteRegistryValues(MSIRECORD *row, LPVOID param)
1972 MSIPACKAGE *package = (MSIPACKAGE*)param;
1973 static const WCHAR szHCR[] =
1974 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1975 'R','O','O','T','\\',0};
1976 static const WCHAR szHCU[] =
1977 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1978 'U','S','E','R','\\',0};
1979 static const WCHAR szHLM[] =
1980 {'H','K','E','Y','_','L','O','C','A','L','_',
1981 'M','A','C','H','I','N','E','\\',0};
1982 static const WCHAR szHU[] =
1983 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1985 LPSTR value_data = NULL;
1986 HKEY root_key, hkey;
1989 LPCWSTR szRoot, component, name, key, value;
1994 BOOL check_first = FALSE;
1997 ui_progress(package,2,0,0,0);
2004 component = MSI_RecordGetString(row, 6);
2005 comp = get_loaded_component(package,component);
2007 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2009 TRACE("Skipping write due to disabled component %s\n",
2010 debugstr_w(component));
2012 comp->Action = comp->Installed;
2014 return ERROR_SUCCESS;
2017 comp->Action = INSTALLSTATE_LOCAL;
2019 name = MSI_RecordGetString(row, 4);
2020 if( MSI_RecordIsNull(row,5) && name )
2022 /* null values can have special meanings */
2023 if (name[0]=='-' && name[1] == 0)
2024 return ERROR_SUCCESS;
2025 else if ((name[0]=='+' && name[1] == 0) ||
2026 (name[0] == '*' && name[1] == 0))
2031 root = MSI_RecordGetInteger(row,2);
2032 key = MSI_RecordGetString(row, 3);
2034 /* get the root key */
2039 static const WCHAR szALLUSER[] = {'A','L','L','U','S','E','R','S',0};
2040 LPWSTR all_users = load_dynamic_property(package, szALLUSER, NULL);
2041 if (all_users && all_users[0] == '1')
2043 root_key = HKEY_LOCAL_MACHINE;
2048 root_key = HKEY_CURRENT_USER;
2051 HeapFree(GetProcessHeap(),0,all_users);
2054 case 0: root_key = HKEY_CLASSES_ROOT;
2057 case 1: root_key = HKEY_CURRENT_USER;
2060 case 2: root_key = HKEY_LOCAL_MACHINE;
2063 case 3: root_key = HKEY_USERS;
2067 ERR("Unknown root %i\n",root);
2073 return ERROR_SUCCESS;
2075 deformat_string(package, key , &deformated);
2076 size = strlenW(deformated) + strlenW(szRoot) + 1;
2077 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
2078 strcpyW(uikey,szRoot);
2079 strcatW(uikey,deformated);
2081 if (RegCreateKeyW( root_key, deformated, &hkey))
2083 ERR("Could not create key %s\n",debugstr_w(deformated));
2084 HeapFree(GetProcessHeap(),0,deformated);
2085 HeapFree(GetProcessHeap(),0,uikey);
2086 return ERROR_SUCCESS;
2088 HeapFree(GetProcessHeap(),0,deformated);
2090 value = MSI_RecordGetString(row,5);
2092 value_data = parse_value(package, value, &type, &size);
2095 static const WCHAR szEmpty[] = {0};
2096 value_data = (LPSTR)strdupW(szEmpty);
2101 deformat_string(package, name, &deformated);
2103 /* get the double nulls to terminate SZ_MULTI */
2104 if (type == REG_MULTI_SZ)
2105 size +=sizeof(WCHAR);
2109 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
2111 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE)value_data, size);
2116 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
2117 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2119 TRACE("value %s of %s checked already exists\n",
2120 debugstr_w(deformated), debugstr_w(uikey));
2124 TRACE("Checked and setting value %s of %s\n",
2125 debugstr_w(deformated), debugstr_w(uikey));
2126 if (deformated || size)
2127 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE) value_data, size);
2132 uirow = MSI_CreateRecord(3);
2133 MSI_RecordSetStringW(uirow,2,deformated);
2134 MSI_RecordSetStringW(uirow,1,uikey);
2137 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2139 MSI_RecordSetStringW(uirow,3,value);
2141 ui_actiondata(package,szWriteRegistryValues,uirow);
2142 msiobj_release( &uirow->hdr );
2144 HeapFree(GetProcessHeap(),0,value_data);
2145 HeapFree(GetProcessHeap(),0,deformated);
2146 HeapFree(GetProcessHeap(),0,uikey);
2148 return ERROR_SUCCESS;
2151 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2155 static const WCHAR ExecSeqQuery[] =
2156 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2157 '`','R','e','g','i','s','t','r','y','`',0 };
2160 return ERROR_INVALID_HANDLE;
2162 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2163 if (rc != ERROR_SUCCESS)
2164 return ERROR_SUCCESS;
2166 /* increment progress bar each time action data is sent */
2167 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
2169 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteRegistryValues, package);
2171 msiobj_release(&view->hdr);
2175 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
2177 package->script->CurrentlyScripting = TRUE;
2179 return ERROR_SUCCESS;
2183 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
2188 static const WCHAR q1[]=
2189 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2190 '`','R','e','g','i','s','t','r','y','`',0};
2193 MSIRECORD * row = 0;
2194 MSIFEATURE *feature;
2197 TRACE(" InstallValidate \n");
2199 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
2200 if (rc != ERROR_SUCCESS)
2201 return ERROR_SUCCESS;
2203 rc = MSI_ViewExecute(view, 0);
2204 if (rc != ERROR_SUCCESS)
2206 MSI_ViewClose(view);
2207 msiobj_release(&view->hdr);
2212 rc = MSI_ViewFetch(view,&row);
2213 if (rc != ERROR_SUCCESS)
2220 msiobj_release(&row->hdr);
2222 MSI_ViewClose(view);
2223 msiobj_release(&view->hdr);
2225 total = total + progress * REG_PROGRESS_VALUE;
2226 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2228 total += COMPONENT_PROGRESS_VALUE;
2230 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2232 total += file->FileSize;
2234 ui_progress(package,0,total,0,0);
2236 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2238 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2239 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2240 feature->ActionRequest);
2243 return ERROR_SUCCESS;
2246 static UINT ITERATE_LaunchConditions(MSIRECORD *row, LPVOID param)
2248 MSIPACKAGE* package = (MSIPACKAGE*)param;
2249 LPCWSTR cond = NULL;
2250 LPCWSTR message = NULL;
2251 static const WCHAR title[]=
2252 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2254 cond = MSI_RecordGetString(row,1);
2256 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
2259 message = MSI_RecordGetString(row,2);
2260 deformat_string(package,message,&deformated);
2261 MessageBoxW(NULL,deformated,title,MB_OK);
2262 HeapFree(GetProcessHeap(),0,deformated);
2263 return ERROR_FUNCTION_FAILED;
2266 return ERROR_SUCCESS;
2269 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
2272 MSIQUERY * view = NULL;
2273 static const WCHAR ExecSeqQuery[] =
2274 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2275 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2277 TRACE("Checking launch conditions\n");
2279 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2280 if (rc != ERROR_SUCCESS)
2281 return ERROR_SUCCESS;
2283 rc = MSI_IterateRecords(view, NULL, ITERATE_LaunchConditions, package);
2284 msiobj_release(&view->hdr);
2289 static LPWSTR resolve_keypath( MSIPACKAGE* package, MSICOMPONENT *cmp )
2292 if (cmp->KeyPath[0]==0)
2294 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
2297 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
2299 MSIRECORD * row = 0;
2301 LPWSTR deformated,buffer,deformated_name;
2303 static const WCHAR ExecSeqQuery[] =
2304 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2305 '`','R','e','g','i','s','t','r','y','`',' ',
2306 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2307 ' ','=',' ' ,'\'','%','s','\'',0 };
2308 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
2309 static const WCHAR fmt2[]=
2310 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2312 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
2316 root = MSI_RecordGetInteger(row,2);
2317 key = MSI_RecordGetString(row, 3);
2318 name = MSI_RecordGetString(row, 4);
2319 deformat_string(package, key , &deformated);
2320 deformat_string(package, name, &deformated_name);
2322 len = strlenW(deformated) + 6;
2323 if (deformated_name)
2324 len+=strlenW(deformated_name);
2326 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
2328 if (deformated_name)
2329 sprintfW(buffer,fmt2,root,deformated,deformated_name);
2331 sprintfW(buffer,fmt,root,deformated);
2333 HeapFree(GetProcessHeap(),0,deformated);
2334 HeapFree(GetProcessHeap(),0,deformated_name);
2335 msiobj_release(&row->hdr);
2339 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
2341 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2346 MSIFILE *file = get_loaded_file( package, cmp->KeyPath );
2349 return strdupW( file->TargetPath );
2354 static HKEY openSharedDLLsKey(void)
2357 static const WCHAR path[] =
2358 {'S','o','f','t','w','a','r','e','\\',
2359 'M','i','c','r','o','s','o','f','t','\\',
2360 'W','i','n','d','o','w','s','\\',
2361 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2362 'S','h','a','r','e','d','D','L','L','s',0};
2364 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
2368 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
2373 DWORD sz = sizeof(count);
2376 hkey = openSharedDLLsKey();
2377 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
2378 if (rc != ERROR_SUCCESS)
2384 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
2388 hkey = openSharedDLLsKey();
2390 RegSetValueExW(hkey,path,0,REG_DWORD,
2391 (LPBYTE)&count,sizeof(count));
2393 RegDeleteValueW(hkey,path);
2399 * Return TRUE if the count should be written out and FALSE if not
2401 static void ACTION_RefCountComponent( MSIPACKAGE* package, MSICOMPONENT *comp )
2403 MSIFEATURE *feature;
2407 /* only refcount DLLs */
2408 if (comp->KeyPath[0]==0 ||
2409 comp->Attributes & msidbComponentAttributesRegistryKeyPath ||
2410 comp->Attributes & msidbComponentAttributesODBCDataSource)
2414 count = ACTION_GetSharedDLLsCount( comp->FullKeypath);
2415 write = (count > 0);
2417 if (comp->Attributes & msidbComponentAttributesSharedDllRefCount)
2421 /* increment counts */
2422 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2426 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ))
2429 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2431 if ( cl->component == comp )
2436 /* decrement counts */
2437 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2441 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ABSENT ))
2444 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2446 if ( cl->component == comp )
2451 /* ref count all the files in the component */
2456 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2458 if (file->Temporary)
2460 if (file->Component == comp)
2461 ACTION_WriteSharedDLLsCount( file->TargetPath, count );
2465 /* add a count for permenent */
2466 if (comp->Attributes & msidbComponentAttributesPermanent)
2469 comp->RefCount = count;
2472 ACTION_WriteSharedDLLsCount( comp->FullKeypath, comp->RefCount );
2476 * Ok further analysis makes me think that this work is
2477 * actually done in the PublishComponents and PublishFeatures
2478 * step, and not here. It appears like the keypath and all that is
2479 * resolved in this step, however actually written in the Publish steps.
2480 * But we will leave it here for now because it is unclear
2482 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
2484 WCHAR squished_pc[GUID_SIZE];
2485 WCHAR squished_cc[GUID_SIZE];
2488 HKEY hkey=0,hkey2=0;
2491 return ERROR_INVALID_HANDLE;
2493 /* writes the Component and Features values to the registry */
2495 rc = MSIREG_OpenComponents(&hkey);
2496 if (rc != ERROR_SUCCESS)
2499 squash_guid(package->ProductCode,squished_pc);
2500 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
2502 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2504 ui_progress(package,2,0,0,0);
2505 if (comp->ComponentId[0]!=0)
2507 WCHAR *keypath = NULL;
2510 squash_guid(comp->ComponentId,squished_cc);
2512 keypath = resolve_keypath( package, comp );
2513 comp->FullKeypath = keypath;
2515 /* do the refcounting */
2516 ACTION_RefCountComponent( package, comp );
2518 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2519 debugstr_w(comp->Component),
2520 debugstr_w(squished_cc),
2521 debugstr_w(comp->FullKeypath),
2524 * Write the keypath out if the component is to be registered
2525 * and delete the key if the component is to be deregistered
2527 if (ACTION_VerifyComponentForAction(package, comp,
2528 INSTALLSTATE_LOCAL))
2530 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
2531 if (rc != ERROR_SUCCESS)
2536 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPBYTE)keypath,
2537 (strlenW(keypath)+1)*sizeof(WCHAR));
2539 if (comp->Attributes & msidbComponentAttributesPermanent)
2541 static const WCHAR szPermKey[] =
2542 { '0','0','0','0','0','0','0','0','0','0','0','0',
2543 '0','0','0','0','0','0','0', '0','0','0','0','0',
2544 '0','0','0','0','0','0','0','0',0};
2546 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
2548 (strlenW(keypath)+1)*sizeof(WCHAR));
2554 uirow = MSI_CreateRecord(3);
2555 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2556 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2557 MSI_RecordSetStringW(uirow,3,keypath);
2558 ui_actiondata(package,szProcessComponents,uirow);
2559 msiobj_release( &uirow->hdr );
2562 else if (ACTION_VerifyComponentForAction(package, comp,
2563 INSTALLSTATE_ABSENT))
2567 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
2568 if (rc != ERROR_SUCCESS)
2571 RegDeleteValueW(hkey2,squished_pc);
2573 /* if the key is empty delete it */
2574 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
2576 if (res == ERROR_NO_MORE_ITEMS)
2577 RegDeleteKeyW(hkey,squished_cc);
2580 uirow = MSI_CreateRecord(2);
2581 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2582 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2583 ui_actiondata(package,szProcessComponents,uirow);
2584 msiobj_release( &uirow->hdr );
2601 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
2602 LPWSTR lpszName, LONG_PTR lParam)
2605 typelib_struct *tl_struct = (typelib_struct*) lParam;
2606 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
2610 if (!IS_INTRESOURCE(lpszName))
2612 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
2616 sz = strlenW(tl_struct->source)+4;
2617 sz *= sizeof(WCHAR);
2619 if ((INT)lpszName == 1)
2620 tl_struct->path = strdupW(tl_struct->source);
2623 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
2624 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
2627 TRACE("trying %s\n", debugstr_w(tl_struct->path));
2628 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
2629 if (!SUCCEEDED(res))
2631 HeapFree(GetProcessHeap(),0,tl_struct->path);
2632 tl_struct->path = NULL;
2637 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
2638 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
2640 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2644 HeapFree(GetProcessHeap(),0,tl_struct->path);
2645 tl_struct->path = NULL;
2647 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2648 ITypeLib_Release(tl_struct->ptLib);
2653 static UINT ITERATE_RegisterTypeLibraries(MSIRECORD *row, LPVOID param)
2655 MSIPACKAGE* package = (MSIPACKAGE*)param;
2659 typelib_struct tl_struct;
2661 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
2663 component = MSI_RecordGetString(row,3);
2664 comp = get_loaded_component(package,component);
2666 return ERROR_SUCCESS;
2668 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2670 TRACE("Skipping typelib reg due to disabled component\n");
2672 comp->Action = comp->Installed;
2674 return ERROR_SUCCESS;
2677 comp->Action = INSTALLSTATE_LOCAL;
2679 file = get_loaded_file( package, comp->KeyPath );
2681 return ERROR_SUCCESS;
2683 module = LoadLibraryExW( file->TargetPath, NULL, LOAD_LIBRARY_AS_DATAFILE );
2687 guid = load_dynamic_stringW(row,1);
2688 CLSIDFromString(guid, &tl_struct.clsid);
2689 HeapFree(GetProcessHeap(),0,guid);
2690 tl_struct.source = strdupW( file->TargetPath );
2691 tl_struct.path = NULL;
2693 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
2694 (LONG_PTR)&tl_struct);
2696 if (tl_struct.path != NULL)
2702 helpid = MSI_RecordGetString(row,6);
2705 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
2706 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
2707 HeapFree(GetProcessHeap(),0,help);
2709 if (!SUCCEEDED(res))
2710 ERR("Failed to register type library %s\n",
2711 debugstr_w(tl_struct.path));
2714 ui_actiondata(package,szRegisterTypeLibraries,row);
2716 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
2719 ITypeLib_Release(tl_struct.ptLib);
2720 HeapFree(GetProcessHeap(),0,tl_struct.path);
2723 ERR("Failed to load type library %s\n",
2724 debugstr_w(tl_struct.source));
2726 FreeLibrary(module);
2727 HeapFree(GetProcessHeap(),0,tl_struct.source);
2730 ERR("Could not load file! %s\n", debugstr_w(file->TargetPath));
2732 return ERROR_SUCCESS;
2735 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
2738 * OK this is a bit confusing.. I am given a _Component key and I believe
2739 * that the file that is being registered as a type library is the "key file
2740 * of that component" which I interpret to mean "The file in the KeyPath of
2745 static const WCHAR Query[] =
2746 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2747 '`','T','y','p','e','L','i','b','`',0};
2750 return ERROR_INVALID_HANDLE;
2752 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2753 if (rc != ERROR_SUCCESS)
2754 return ERROR_SUCCESS;
2756 rc = MSI_IterateRecords(view, NULL, ITERATE_RegisterTypeLibraries, package);
2757 msiobj_release(&view->hdr);
2761 static UINT ITERATE_CreateShortcuts(MSIRECORD *row, LPVOID param)
2763 MSIPACKAGE *package = (MSIPACKAGE*)param;
2764 LPWSTR target_file, target_folder;
2766 WCHAR filename[0x100];
2769 static const WCHAR szlnk[]={'.','l','n','k',0};
2774 buffer = MSI_RecordGetString(row,4);
2775 comp = get_loaded_component(package,buffer);
2777 return ERROR_SUCCESS;
2779 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
2781 TRACE("Skipping shortcut creation due to disabled component\n");
2783 comp->Action = comp->Installed;
2785 return ERROR_SUCCESS;
2788 comp->Action = INSTALLSTATE_LOCAL;
2790 ui_actiondata(package,szCreateShortcuts,row);
2792 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2793 &IID_IShellLinkW, (LPVOID *) &sl );
2797 ERR("Is IID_IShellLink\n");
2798 return ERROR_SUCCESS;
2801 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
2804 ERR("Is IID_IPersistFile\n");
2805 return ERROR_SUCCESS;
2808 buffer = MSI_RecordGetString(row,2);
2809 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
2811 /* may be needed because of a bug somehwere else */
2812 create_full_pathW(target_folder);
2815 MSI_RecordGetStringW(row,3,filename,&sz);
2816 reduce_to_longfilename(filename);
2817 if (!strchrW(filename,'.') || strcmpiW(strchrW(filename,'.'),szlnk))
2818 strcatW(filename,szlnk);
2819 target_file = build_directory_name(2, target_folder, filename);
2820 HeapFree(GetProcessHeap(),0,target_folder);
2822 buffer = MSI_RecordGetString(row,5);
2823 if (strchrW(buffer,'['))
2826 deformat_string(package,buffer,&deformated);
2827 IShellLinkW_SetPath(sl,deformated);
2828 HeapFree(GetProcessHeap(),0,deformated);
2833 FIXME("poorly handled shortcut format, advertised shortcut\n");
2834 keypath = strdupW( comp->FullKeypath );
2835 IShellLinkW_SetPath(sl,keypath);
2836 HeapFree(GetProcessHeap(),0,keypath);
2839 if (!MSI_RecordIsNull(row,6))
2842 buffer = MSI_RecordGetString(row,6);
2843 deformat_string(package,buffer,&deformated);
2844 IShellLinkW_SetArguments(sl,deformated);
2845 HeapFree(GetProcessHeap(),0,deformated);
2848 if (!MSI_RecordIsNull(row,7))
2850 buffer = MSI_RecordGetString(row,7);
2851 IShellLinkW_SetDescription(sl,buffer);
2854 if (!MSI_RecordIsNull(row,8))
2855 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
2857 if (!MSI_RecordIsNull(row,9))
2862 buffer = MSI_RecordGetString(row,9);
2864 build_icon_path(package,buffer,&Path);
2865 index = MSI_RecordGetInteger(row,10);
2867 IShellLinkW_SetIconLocation(sl,Path,index);
2868 HeapFree(GetProcessHeap(),0,Path);
2871 if (!MSI_RecordIsNull(row,11))
2872 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
2874 if (!MSI_RecordIsNull(row,12))
2877 buffer = MSI_RecordGetString(row,12);
2878 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
2879 IShellLinkW_SetWorkingDirectory(sl,Path);
2880 HeapFree(GetProcessHeap(), 0, Path);
2883 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
2884 IPersistFile_Save(pf,target_file,FALSE);
2886 HeapFree(GetProcessHeap(),0,target_file);
2888 IPersistFile_Release( pf );
2889 IShellLinkW_Release( sl );
2891 return ERROR_SUCCESS;
2894 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
2899 static const WCHAR Query[] =
2900 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2901 '`','S','h','o','r','t','c','u','t','`',0};
2904 return ERROR_INVALID_HANDLE;
2906 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2907 if (rc != ERROR_SUCCESS)
2908 return ERROR_SUCCESS;
2910 res = CoInitialize( NULL );
2913 ERR("CoInitialize failed\n");
2914 return ERROR_FUNCTION_FAILED;
2917 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateShortcuts, package);
2918 msiobj_release(&view->hdr);
2925 static UINT ITERATE_PublishProduct(MSIRECORD *row, LPVOID param)
2927 MSIPACKAGE* package = (MSIPACKAGE*)param;
2929 LPWSTR FilePath=NULL;
2930 LPCWSTR FileName=NULL;
2935 FileName = MSI_RecordGetString(row,1);
2938 ERR("Unable to get FileName\n");
2939 return ERROR_SUCCESS;
2942 build_icon_path(package,FileName,&FilePath);
2944 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
2946 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2947 FILE_ATTRIBUTE_NORMAL, NULL);
2949 if (the_file == INVALID_HANDLE_VALUE)
2951 ERR("Unable to create file %s\n",debugstr_w(FilePath));
2952 HeapFree(GetProcessHeap(),0,FilePath);
2953 return ERROR_SUCCESS;
2960 rc = MSI_RecordReadStream(row,2,buffer,&sz);
2961 if (rc != ERROR_SUCCESS)
2963 ERR("Failed to get stream\n");
2964 CloseHandle(the_file);
2965 DeleteFileW(FilePath);
2968 WriteFile(the_file,buffer,sz,&write,NULL);
2969 } while (sz == 1024);
2971 HeapFree(GetProcessHeap(),0,FilePath);
2973 CloseHandle(the_file);
2974 return ERROR_SUCCESS;
2978 * 99% of the work done here is only done for
2979 * advertised installs. However this is where the
2980 * Icon table is processed and written out
2981 * so that is what I am going to do here.
2983 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
2987 static const WCHAR Query[]=
2988 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2989 '`','I','c','o','n','`',0};
2990 /* for registry stuff */
2993 static const WCHAR szProductLanguage[] =
2994 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
2995 static const WCHAR szARPProductIcon[] =
2996 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
2997 static const WCHAR szProductVersion[] =
2998 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3002 MSIHANDLE hDb, hSumInfo;
3005 return ERROR_INVALID_HANDLE;
3007 /* write out icon files */
3009 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3010 if (rc == ERROR_SUCCESS)
3012 MSI_IterateRecords(view, NULL, ITERATE_PublishProduct, package);
3013 msiobj_release(&view->hdr);
3016 /* ok there is a lot more done here but i need to figure out what */
3018 rc = MSIREG_OpenProductsKey(package->ProductCode,&hkey,TRUE);
3019 if (rc != ERROR_SUCCESS)
3022 rc = MSIREG_OpenUserProductsKey(package->ProductCode,&hukey,TRUE);
3023 if (rc != ERROR_SUCCESS)
3027 buffer = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTNAMEW,NULL);
3028 size = strlenW(buffer)*sizeof(WCHAR);
3029 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTNAMEW,0,REG_SZ,
3030 (LPBYTE)buffer,size);
3031 HeapFree(GetProcessHeap(),0,buffer);
3033 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3034 size = sizeof(DWORD);
3035 langid = atoiW(buffer);
3036 RegSetValueExW(hukey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3037 (LPBYTE)&langid,size);
3038 HeapFree(GetProcessHeap(),0,buffer);
3040 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
3044 build_icon_path(package,buffer,&path);
3045 size = strlenW(path) * sizeof(WCHAR);
3046 RegSetValueExW(hukey,INSTALLPROPERTY_PRODUCTICONW,0,REG_SZ,
3049 HeapFree(GetProcessHeap(),0,buffer);
3051 buffer = load_dynamic_property(package,szProductVersion,NULL);
3054 DWORD verdword = build_version_dword(buffer);
3055 size = sizeof(DWORD);
3056 RegSetValueExW(hukey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD, (LPBYTE
3059 HeapFree(GetProcessHeap(),0,buffer);
3061 FIXME("Need to write more keys to the user registry\n");
3063 hDb= alloc_msihandle( &package->db->hdr );
3064 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
3065 MsiCloseHandle(hDb);
3066 if (rc == ERROR_SUCCESS)
3068 WCHAR guidbuffer[0x200];
3070 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
3072 if (rc == ERROR_SUCCESS)
3074 WCHAR squashed[GUID_SIZE];
3075 /* for now we only care about the first guid */
3076 LPWSTR ptr = strchrW(guidbuffer,';');
3078 squash_guid(guidbuffer,squashed);
3079 size = strlenW(squashed)*sizeof(WCHAR);
3080 RegSetValueExW(hukey,INSTALLPROPERTY_PACKAGECODEW,0,REG_SZ,
3081 (LPBYTE)squashed, size);
3085 ERR("Unable to query Revision_Number... \n");
3088 MsiCloseHandle(hSumInfo);
3092 ERR("Unable to open Summary Information\n");
3104 static UINT ITERATE_WriteIniValues(MSIRECORD *row, LPVOID param)
3106 MSIPACKAGE *package = (MSIPACKAGE*)param;
3107 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
3108 LPWSTR deformated_section, deformated_key, deformated_value;
3109 LPWSTR folder, fullname = NULL;
3113 static const WCHAR szWindowsFolder[] =
3114 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3116 component = MSI_RecordGetString(row, 8);
3117 comp = get_loaded_component(package,component);
3119 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL))
3121 TRACE("Skipping ini file due to disabled component %s\n",
3122 debugstr_w(component));
3124 comp->Action = comp->Installed;
3126 return ERROR_SUCCESS;
3129 comp->Action = INSTALLSTATE_LOCAL;
3131 identifier = MSI_RecordGetString(row,1);
3132 filename = MSI_RecordGetString(row,2);
3133 dirproperty = MSI_RecordGetString(row,3);
3134 section = MSI_RecordGetString(row,4);
3135 key = MSI_RecordGetString(row,5);
3136 value = MSI_RecordGetString(row,6);
3137 action = MSI_RecordGetInteger(row,7);
3139 deformat_string(package,section,&deformated_section);
3140 deformat_string(package,key,&deformated_key);
3141 deformat_string(package,value,&deformated_value);
3145 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
3147 folder = load_dynamic_property(package,dirproperty,NULL);
3150 folder = load_dynamic_property(package, szWindowsFolder, NULL);
3154 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
3158 fullname = build_directory_name(2, folder, filename);
3162 TRACE("Adding value %s to section %s in %s\n",
3163 debugstr_w(deformated_key), debugstr_w(deformated_section),
3164 debugstr_w(fullname));
3165 WritePrivateProfileStringW(deformated_section, deformated_key,
3166 deformated_value, fullname);
3168 else if (action == 1)
3171 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
3172 returned, 10, fullname);
3173 if (returned[0] == 0)
3175 TRACE("Adding value %s to section %s in %s\n",
3176 debugstr_w(deformated_key), debugstr_w(deformated_section),
3177 debugstr_w(fullname));
3179 WritePrivateProfileStringW(deformated_section, deformated_key,
3180 deformated_value, fullname);
3183 else if (action == 3)
3184 FIXME("Append to existing section not yet implemented\n");
3186 uirow = MSI_CreateRecord(4);
3187 MSI_RecordSetStringW(uirow,1,identifier);
3188 MSI_RecordSetStringW(uirow,2,deformated_section);
3189 MSI_RecordSetStringW(uirow,3,deformated_key);
3190 MSI_RecordSetStringW(uirow,4,deformated_value);
3191 ui_actiondata(package,szWriteIniValues,uirow);
3192 msiobj_release( &uirow->hdr );
3194 HeapFree(GetProcessHeap(),0,fullname);
3195 HeapFree(GetProcessHeap(),0,folder);
3196 HeapFree(GetProcessHeap(),0,deformated_key);
3197 HeapFree(GetProcessHeap(),0,deformated_value);
3198 HeapFree(GetProcessHeap(),0,deformated_section);
3199 return ERROR_SUCCESS;
3202 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
3206 static const WCHAR ExecSeqQuery[] =
3207 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3208 '`','I','n','i','F','i','l','e','`',0};
3210 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3211 if (rc != ERROR_SUCCESS)
3213 TRACE("no IniFile table\n");
3214 return ERROR_SUCCESS;
3217 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteIniValues, package);
3218 msiobj_release(&view->hdr);
3222 static UINT ITERATE_SelfRegModules(MSIRECORD *row, LPVOID param)
3224 MSIPACKAGE *package = (MSIPACKAGE*)param;
3229 static const WCHAR ExeStr[] =
3230 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3231 static const WCHAR close[] = {'\"',0};
3233 PROCESS_INFORMATION info;
3236 memset(&si,0,sizeof(STARTUPINFOW));
3238 filename = MSI_RecordGetString(row,1);
3239 file = get_loaded_file( package, filename );
3243 ERR("Unable to find file id %s\n",debugstr_w(filename));
3244 return ERROR_SUCCESS;
3247 len = strlenW(ExeStr) + strlenW( file->TargetPath ) + 2;
3249 FullName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3250 strcpyW(FullName,ExeStr);
3251 strcatW( FullName, file->TargetPath );
3252 strcatW(FullName,close);
3254 TRACE("Registering %s\n",debugstr_w(FullName));
3255 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL, c_colon,
3259 msi_dialog_check_messages(info.hProcess);
3261 HeapFree(GetProcessHeap(),0,FullName);
3262 return ERROR_SUCCESS;
3265 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
3269 static const WCHAR ExecSeqQuery[] =
3270 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3271 '`','S','e','l','f','R','e','g','`',0};
3273 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3274 if (rc != ERROR_SUCCESS)
3276 TRACE("no SelfReg table\n");
3277 return ERROR_SUCCESS;
3280 MSI_IterateRecords(view, NULL, ITERATE_SelfRegModules, package);
3281 msiobj_release(&view->hdr);
3283 return ERROR_SUCCESS;
3286 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
3288 MSIFEATURE *feature;
3294 return ERROR_INVALID_HANDLE;
3296 rc = MSIREG_OpenFeaturesKey(package->ProductCode,&hkey,TRUE);
3297 if (rc != ERROR_SUCCESS)
3300 rc = MSIREG_OpenUserFeaturesKey(package->ProductCode,&hukey,TRUE);
3301 if (rc != ERROR_SUCCESS)
3304 /* here the guids are base 85 encoded */
3305 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
3311 BOOL absent = FALSE;
3313 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ) &&
3314 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_SOURCE ) &&
3315 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED ))
3319 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3323 if (feature->Feature_Parent[0])
3324 size += strlenW( feature->Feature_Parent )+2;
3326 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
3329 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3331 MSICOMPONENT* component = cl->component;
3334 memset(buf,0,sizeof(buf));
3335 if ( component->ComponentId[0] )
3337 TRACE("From %s\n",debugstr_w(component->ComponentId));
3338 CLSIDFromString(component->ComponentId, &clsid);
3339 encode_base85_guid(&clsid,buf);
3340 TRACE("to %s\n",debugstr_w(buf));
3344 if (feature->Feature_Parent[0])
3346 static const WCHAR sep[] = {'\2',0};
3348 strcatW(data,feature->Feature_Parent);
3351 size = (strlenW(data)+1)*sizeof(WCHAR);
3352 RegSetValueExW( hkey, feature->Feature, 0, REG_SZ, (LPBYTE)data,size );
3353 HeapFree(GetProcessHeap(),0,data);
3357 size = strlenW(feature->Feature_Parent)*sizeof(WCHAR);
3358 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3359 (LPBYTE)feature->Feature_Parent,size);
3363 size = (strlenW(feature->Feature_Parent)+2)* sizeof(WCHAR);
3364 data = HeapAlloc(GetProcessHeap(),0,size);
3366 strcpyW( &data[1], feature->Feature_Parent );
3367 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3369 HeapFree(GetProcessHeap(),0,data);
3379 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
3382 LPWSTR buffer = NULL;
3385 static WCHAR szNONE[] = {0};
3386 static const WCHAR szWindowsInstaler[] =
3387 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3388 static const WCHAR szPropKeys[][80] =
3390 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3391 {'A','R','P','C','O','N','T','A','C','T',0},
3392 {'A','R','P','C','O','M','M','E','N','T','S',0},
3393 {'P','r','o','d','u','c','t','N','a','m','e',0},
3394 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3395 {'A','R','P','H','E','L','P','L','I','N','K',0},
3396 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3397 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3398 {'S','o','u','r','c','e','D','i','r',0},
3399 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3400 {'A','R','P','R','E','A','D','M','E',0},
3401 {'A','R','P','S','I','Z','E',0},
3402 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3403 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3407 static const WCHAR szRegKeys[][80] =
3409 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3410 {'C','o','n','t','a','c','t',0},
3411 {'C','o','m','m','e','n','t','s',0},
3412 {'D','i','s','p','l','a','y','N','a','m','e',0},
3413 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3414 {'H','e','l','p','L','i','n','k',0},
3415 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3416 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3417 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3418 {'P','u','b','l','i','s','h','e','r',0},
3419 {'R','e','a','d','m','e',0},
3420 {'S','i','z','e',0},
3421 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3422 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3426 static const WCHAR installerPathFmt[] = {
3428 'I','n','s','t','a','l','l','e','r','\\',0};
3429 static const WCHAR fmt[] = {
3431 'I','n','s','t','a','l','l','e','r','\\',
3432 '%','x','.','m','s','i',0};
3433 static const WCHAR szUpgradeCode[] =
3434 {'U','p','g','r','a','d','e','C','o','d','e',0};
3435 static const WCHAR modpath_fmt[] =
3436 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3437 static const WCHAR szModifyPath[] =
3438 {'M','o','d','i','f','y','P','a','t','h',0};
3439 static const WCHAR szUninstallString[] =
3440 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3441 static const WCHAR szEstimatedSize[] =
3442 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3443 static const WCHAR szProductLanguage[] =
3444 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3445 static const WCHAR szProductVersion[] =
3446 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3449 static const WCHAR date_fmt[] = {'%','i','%','i','%','i',0};
3450 LPWSTR upgrade_code;
3451 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
3455 return ERROR_INVALID_HANDLE;
3457 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3458 if (rc != ERROR_SUCCESS)
3461 /* dump all the info i can grab */
3462 FIXME("Flesh out more information \n");
3465 while (szPropKeys[i][0]!=0)
3467 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3468 if (rc != ERROR_SUCCESS)
3470 size = strlenW(buffer)*sizeof(WCHAR);
3471 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3472 HeapFree(GetProcessHeap(),0,buffer);
3478 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPBYTE)&rc,size);
3480 /* copy the package locally */
3481 num = GetTickCount() & 0xffff;
3485 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
3486 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
3490 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
3491 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
3492 if (handle != INVALID_HANDLE_VALUE)
3494 CloseHandle(handle);
3497 if (GetLastError() != ERROR_FILE_EXISTS &&
3498 GetLastError() != ERROR_SHARING_VIOLATION)
3500 if (!(++num & 0xffff)) num = 1;
3501 sprintfW(packagefile,fmt,num);
3502 } while (num != start);
3504 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
3505 create_full_pathW(path);
3506 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
3507 if (!CopyFileW(package->msiFilePath,packagefile,FALSE))
3508 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3509 debugstr_w(package->msiFilePath), debugstr_w(packagefile),
3511 size = strlenW(packagefile)*sizeof(WCHAR);
3512 RegSetValueExW(hkey,INSTALLPROPERTY_LOCALPACKAGEW,0,REG_SZ,
3513 (LPBYTE)packagefile,size);
3515 /* do ModifyPath and UninstallString */
3516 size = deformat_string(package,modpath_fmt,&buffer);
3517 RegSetValueExW(hkey,szModifyPath,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3518 RegSetValueExW(hkey,szUninstallString,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
3519 HeapFree(GetProcessHeap(),0,buffer);
3521 FIXME("Write real Estimated Size when we have it\n");
3523 RegSetValueExW(hkey,szEstimatedSize,0,REG_DWORD,(LPBYTE)&size,sizeof(DWORD));
3525 GetLocalTime(&systime);
3526 size = 9*sizeof(WCHAR);
3527 buffer= HeapAlloc(GetProcessHeap(),0,size);
3528 sprintfW(buffer,date_fmt,systime.wYear,systime.wMonth,systime.wDay);
3529 size = strlenW(buffer)*sizeof(WCHAR);
3530 RegSetValueExW(hkey,INSTALLPROPERTY_INSTALLDATEW,0,REG_SZ,
3531 (LPBYTE)buffer,size);
3532 HeapFree(GetProcessHeap(),0,buffer);
3534 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3535 size = atoiW(buffer);
3536 RegSetValueExW(hkey,INSTALLPROPERTY_LANGUAGEW,0,REG_DWORD,
3537 (LPBYTE)&size,sizeof(DWORD));
3538 HeapFree(GetProcessHeap(),1,buffer);
3540 buffer = load_dynamic_property(package,szProductVersion,NULL);
3543 DWORD verdword = build_version_dword(buffer);
3544 DWORD vermajor = verdword>>24;
3545 DWORD verminor = (verdword>>16)&0x00FF;
3546 size = sizeof(DWORD);
3547 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONW,0,REG_DWORD,
3548 (LPBYTE)&verdword,size);
3549 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMAJORW,0,REG_DWORD,
3550 (LPBYTE)&vermajor,size);
3551 RegSetValueExW(hkey,INSTALLPROPERTY_VERSIONMINORW,0,REG_DWORD,
3552 (LPBYTE)&verminor,size);
3554 HeapFree(GetProcessHeap(),0,buffer);
3556 /* Handle Upgrade Codes */
3557 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
3562 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3563 squash_guid(package->ProductCode,squashed);
3564 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3566 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3567 squash_guid(package->ProductCode,squashed);
3568 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3571 HeapFree(GetProcessHeap(),0,upgrade_code);
3577 return ERROR_SUCCESS;
3580 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
3585 return ERROR_INVALID_HANDLE;
3587 rc = execute_script(package,INSTALL_SCRIPT);
3592 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
3597 return ERROR_INVALID_HANDLE;
3599 /* turn off scheduleing */
3600 package->script->CurrentlyScripting= FALSE;
3602 /* first do the same as an InstallExecute */
3603 rc = ACTION_InstallExecute(package);
3604 if (rc != ERROR_SUCCESS)
3607 /* then handle Commit Actions */
3608 rc = execute_script(package,COMMIT_SCRIPT);
3613 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
3615 static const WCHAR RunOnce[] = {
3616 'S','o','f','t','w','a','r','e','\\',
3617 'M','i','c','r','o','s','o','f','t','\\',
3618 'W','i','n','d','o','w','s','\\',
3619 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3620 'R','u','n','O','n','c','e',0};
3621 static const WCHAR InstallRunOnce[] = {
3622 'S','o','f','t','w','a','r','e','\\',
3623 'M','i','c','r','o','s','o','f','t','\\',
3624 'W','i','n','d','o','w','s','\\',
3625 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3626 'I','n','s','t','a','l','l','e','r','\\',
3627 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3629 static const WCHAR msiexec_fmt[] = {
3631 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3632 '\"','%','s','\"',0};
3633 static const WCHAR install_fmt[] = {
3634 '/','I',' ','\"','%','s','\"',' ',
3635 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3636 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3637 WCHAR buffer[256], sysdir[MAX_PATH];
3639 WCHAR squished_pc[100];
3643 return ERROR_INVALID_HANDLE;
3645 squash_guid(package->ProductCode,squished_pc);
3647 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
3648 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
3649 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
3652 size = strlenW(buffer)*sizeof(WCHAR);
3653 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3656 TRACE("Reboot command %s\n",debugstr_w(buffer));
3658 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
3659 sprintfW(buffer,install_fmt,package->ProductCode,squished_pc);
3661 size = strlenW(buffer)*sizeof(WCHAR);
3662 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPBYTE)buffer,size);
3665 return ERROR_INSTALL_SUSPEND;
3668 UINT ACTION_ResolveSource(MSIPACKAGE* package)
3673 * we are currently doing what should be done here in the top level Install
3674 * however for Adminastrative and uninstalls this step will be needed
3676 if (!package->PackagePath)
3677 return ERROR_SUCCESS;
3679 attrib = GetFileAttributesW(package->PackagePath);
3680 if (attrib == INVALID_FILE_ATTRIBUTES)
3686 rc = MsiSourceListGetInfoW(package->ProductCode, NULL,
3687 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3688 INSTALLPROPERTY_DISKPROMPTW,NULL,&size);
3689 if (rc == ERROR_MORE_DATA)
3691 prompt = HeapAlloc(GetProcessHeap(),0,size * sizeof(WCHAR));
3692 MsiSourceListGetInfoW(package->ProductCode, NULL,
3693 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
3694 INSTALLPROPERTY_DISKPROMPTW,prompt,&size);
3697 prompt = strdupW(package->PackagePath);
3699 msg = generate_error_string(package,1302,1,prompt);
3700 while(attrib == INVALID_FILE_ATTRIBUTES)
3702 rc = MessageBoxW(NULL,msg,NULL,MB_OKCANCEL);
3705 rc = ERROR_INSTALL_USEREXIT;
3708 attrib = GetFileAttributesW(package->PackagePath);
3710 HeapFree(GetProcessHeap(),0,prompt);
3714 return ERROR_SUCCESS;
3719 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
3727 static const WCHAR szPropKeys[][80] =
3729 {'P','r','o','d','u','c','t','I','D',0},
3730 {'U','S','E','R','N','A','M','E',0},
3731 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3735 static const WCHAR szRegKeys[][80] =
3737 {'P','r','o','d','u','c','t','I','D',0},
3738 {'R','e','g','O','w','n','e','r',0},
3739 {'R','e','g','C','o','m','p','a','n','y',0},
3744 return ERROR_INVALID_HANDLE;
3746 productid = load_dynamic_property(package,INSTALLPROPERTY_PRODUCTIDW,
3749 return ERROR_SUCCESS;
3751 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
3752 if (rc != ERROR_SUCCESS)
3756 while (szPropKeys[i][0]!=0)
3758 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3759 if (rc == ERROR_SUCCESS)
3761 size = strlenW(buffer)*sizeof(WCHAR);
3762 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPBYTE)buffer,size);
3765 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
3770 HeapFree(GetProcessHeap(),0,productid);
3773 return ERROR_SUCCESS;
3777 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
3779 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
3780 static const WCHAR szTwo[] = {'2',0};
3783 level = load_dynamic_property(package,szUILevel,NULL);
3785 MSI_SetPropertyW(package,szUILevel,szTwo);
3786 package->script->InWhatSequence |= SEQUENCE_EXEC;
3787 rc = ACTION_ProcessExecSequence(package,FALSE);
3788 MSI_SetPropertyW(package,szUILevel,level);
3789 HeapFree(GetProcessHeap(),0,level);
3795 * Code based off of code located here
3796 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3798 * Using string index 4 (full font name) instead of 1 (family name)
3800 static LPWSTR load_ttfname_from(LPCWSTR filename)
3806 typedef struct _tagTT_OFFSET_TABLE{
3807 USHORT uMajorVersion;
3808 USHORT uMinorVersion;
3809 USHORT uNumOfTables;
3810 USHORT uSearchRange;
3811 USHORT uEntrySelector;
3815 typedef struct _tagTT_TABLE_DIRECTORY{
3816 char szTag[4]; /* table name */
3817 ULONG uCheckSum; /* Check sum */
3818 ULONG uOffset; /* Offset from beginning of file */
3819 ULONG uLength; /* length of the table in bytes */
3820 }TT_TABLE_DIRECTORY;
3822 typedef struct _tagTT_NAME_TABLE_HEADER{
3823 USHORT uFSelector; /* format selector. Always 0 */
3824 USHORT uNRCount; /* Name Records count */
3825 USHORT uStorageOffset; /* Offset for strings storage,
3826 * from start of the table */
3827 }TT_NAME_TABLE_HEADER;
3829 typedef struct _tagTT_NAME_RECORD{
3834 USHORT uStringLength;
3835 USHORT uStringOffset; /* from start of storage area */
3838 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3839 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3841 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
3842 FILE_ATTRIBUTE_NORMAL, 0 );
3843 if (handle != INVALID_HANDLE_VALUE)
3845 TT_TABLE_DIRECTORY tblDir;
3846 BOOL bFound = FALSE;
3847 TT_OFFSET_TABLE ttOffsetTable;
3849 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
3850 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
3851 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
3852 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
3854 if (ttOffsetTable.uMajorVersion != 1 ||
3855 ttOffsetTable.uMinorVersion != 0)
3858 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
3860 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
3861 if (strncmp(tblDir.szTag,"name",4)==0)
3864 tblDir.uLength = SWAPLONG(tblDir.uLength);
3865 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
3872 TT_NAME_TABLE_HEADER ttNTHeader;
3873 TT_NAME_RECORD ttRecord;
3875 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
3876 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
3879 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
3880 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
3882 for(i=0; i<ttNTHeader.uNRCount; i++)
3884 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
3885 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
3886 /* 4 is the Full Font Name */
3887 if(ttRecord.uNameID == 4)
3891 static LPCSTR tt = " (TrueType)";
3893 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
3894 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
3895 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
3896 SetFilePointer(handle, tblDir.uOffset +
3897 ttRecord.uStringOffset +
3898 ttNTHeader.uStorageOffset,
3900 buf = HeapAlloc(GetProcessHeap(), 0,
3901 ttRecord.uStringLength + 1 + strlen(tt));
3902 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
3903 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
3904 if (strlen(buf) > 0)
3907 ret = strdupAtoW(buf);
3908 HeapFree(GetProcessHeap(),0,buf);
3912 HeapFree(GetProcessHeap(),0,buf);
3913 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
3917 CloseHandle(handle);
3920 ERR("Unable to open font file %s\n", debugstr_w(filename));
3922 TRACE("Returning fontname %s\n",debugstr_w(ret));
3926 static UINT ITERATE_RegisterFonts(MSIRECORD *row, LPVOID param)
3928 MSIPACKAGE *package = (MSIPACKAGE*)param;
3933 static const WCHAR regfont1[] =
3934 {'S','o','f','t','w','a','r','e','\\',
3935 'M','i','c','r','o','s','o','f','t','\\',
3936 'W','i','n','d','o','w','s',' ','N','T','\\',
3937 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3938 'F','o','n','t','s',0};
3939 static const WCHAR regfont2[] =
3940 {'S','o','f','t','w','a','r','e','\\',
3941 'M','i','c','r','o','s','o','f','t','\\',
3942 'W','i','n','d','o','w','s','\\',
3943 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3944 'F','o','n','t','s',0};
3948 filename = MSI_RecordGetString( row, 1 );
3949 file = get_loaded_file( package, filename );
3952 ERR("Unable to load file\n");
3953 return ERROR_SUCCESS;
3956 /* check to make sure that component is installed */
3957 if (!ACTION_VerifyComponentForAction(package,
3958 file->Component, INSTALLSTATE_LOCAL))
3960 TRACE("Skipping: Component not scheduled for install\n");
3961 return ERROR_SUCCESS;
3964 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
3965 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
3967 if (MSI_RecordIsNull(row,2))
3968 name = load_ttfname_from( file->TargetPath );
3970 name = load_dynamic_stringW(row,2);
3974 size = strlenW( file->FileName ) * sizeof(WCHAR);
3975 RegSetValueExW( hkey1, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3976 RegSetValueExW( hkey2, name, 0, REG_SZ, (LPBYTE)file->FileName, size );
3979 HeapFree(GetProcessHeap(),0,name);
3982 return ERROR_SUCCESS;
3985 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
3989 static const WCHAR ExecSeqQuery[] =
3990 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3991 '`','F','o','n','t','`',0};
3993 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3994 if (rc != ERROR_SUCCESS)
3996 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
3997 return ERROR_SUCCESS;
4000 MSI_IterateRecords(view, NULL, ITERATE_RegisterFonts, package);
4001 msiobj_release(&view->hdr);
4003 return ERROR_SUCCESS;
4006 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
4008 MSIPACKAGE *package = (MSIPACKAGE*)param;
4009 LPCWSTR compgroupid=NULL;
4010 LPCWSTR feature=NULL;
4011 LPCWSTR text = NULL;
4012 LPCWSTR qualifier = NULL;
4013 LPCWSTR component = NULL;
4014 LPWSTR advertise = NULL;
4015 LPWSTR output = NULL;
4017 UINT rc = ERROR_SUCCESS;
4021 component = MSI_RecordGetString(rec,3);
4022 comp = get_loaded_component(package,component);
4024 if (!ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_LOCAL) &&
4025 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_SOURCE) &&
4026 !ACTION_VerifyComponentForAction(package, comp, INSTALLSTATE_ADVERTISED))
4028 TRACE("Skipping: Component %s not scheduled for install\n",
4029 debugstr_w(component));
4031 return ERROR_SUCCESS;
4034 compgroupid = MSI_RecordGetString(rec,1);
4036 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
4037 if (rc != ERROR_SUCCESS)
4040 text = MSI_RecordGetString(rec,4);
4041 qualifier = MSI_RecordGetString(rec,2);
4042 feature = MSI_RecordGetString(rec,5);
4044 advertise = create_component_advertise_string(package, comp, feature);
4046 sz = strlenW(advertise);
4049 sz += lstrlenW(text);
4052 sz *= sizeof(WCHAR);
4054 output = HeapAlloc(GetProcessHeap(),0,sz);
4055 memset(output,0,sz);
4056 strcpyW(output,advertise);
4059 strcatW(output,text);
4061 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
4062 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
4066 HeapFree(GetProcessHeap(),0,output);
4072 * At present I am ignorning the advertised components part of this and only
4073 * focusing on the qualified component sets
4075 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
4079 static const WCHAR ExecSeqQuery[] =
4080 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4081 '`','P','u','b','l','i','s','h',
4082 'C','o','m','p','o','n','e','n','t','`',0};
4084 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4085 if (rc != ERROR_SUCCESS)
4086 return ERROR_SUCCESS;
4088 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
4089 msiobj_release(&view->hdr);