Rework CostFinalize to use MSI_IterateRecords.
[wine/multimedia.git] / dlls / msi / action.c
blobaf345ffa67afac3682bb6ae90be607e2549119ac
1 /*
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
22 * Pages I need
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
29 #include <stdarg.h>
31 #define COBJMACROS
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winerror.h"
36 #include "winreg.h"
37 #include "wine/debug.h"
38 #include "msidefs.h"
39 #include "msipriv.h"
40 #include "winuser.h"
41 #include "shlobj.h"
42 #include "wine/unicode.h"
43 #include "winver.h"
44 #include "action.h"
46 #define REG_PROGRESS_VALUE 13200
47 #define COMPONENT_PROGRESS_VALUE 24000
49 WINE_DEFAULT_DEBUG_CHANNEL(msi);
52 * Prototypes
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);
58 /*
59 * action handlers
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',
169 'F','i','l','e',0};
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',
195 'I','n','f','o',0};
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',
243 'I','n','f','o',0};
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',
255 'I','n','f','o',0};
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};
265 struct _actions {
266 LPCWSTR action;
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},
346 { NULL, NULL},
350 /********************************************************
351 * helper functions
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};
358 MSIRECORD *row;
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',
370 '.',0};
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};
378 WCHAR message[1024];
379 WCHAR timet[0x100];
380 MSIRECORD * row = 0;
381 LPCWSTR ActionText;
383 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
385 row = MSI_QueryGetRecord( package->db, Query_t, action );
386 if (!row)
387 return;
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,
402 UINT rc)
404 MSIRECORD * row;
405 static const WCHAR template_s[]=
406 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
407 '%','s', '.',0};
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',' ',
411 '%','i','.',0};
412 static const WCHAR format[] =
413 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
414 WCHAR message[1024];
415 WCHAR timet[0x100];
417 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
418 if (start)
419 sprintfW(message,template_s,timet,action);
420 else
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)
437 DWORD sz;
438 WCHAR buffer[10];
439 UINT rc;
440 BOOL ui = FALSE;
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 if (szPackagePath)
452 LPWSTR p, check, path;
454 package->PackagePath = strdupW(szPackagePath);
455 path = strdupW(szPackagePath);
456 p = strrchrW(path,'\\');
457 if (p)
459 p++;
460 *p=0;
462 else
464 HeapFree(GetProcessHeap(),0,path);
465 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
466 GetCurrentDirectoryW(MAX_PATH,path);
467 strcatW(path,cszbs);
470 check = load_dynamic_property(package, cszSourceDir,NULL);
471 if (!check)
472 MSI_SetPropertyW(package, cszSourceDir, path);
473 else
474 HeapFree(GetProcessHeap(), 0, check);
476 HeapFree(GetProcessHeap(), 0, path);
479 if (szCommandLine)
481 LPWSTR ptr,ptr2;
482 ptr = (LPWSTR)szCommandLine;
484 while (*ptr)
486 WCHAR *prop = NULL;
487 WCHAR *val = NULL;
489 TRACE("Looking at %s\n",debugstr_w(ptr));
491 ptr2 = strchrW(ptr,'=');
492 if (ptr2)
494 BOOL quote=FALSE;
495 DWORD len = 0;
497 while (*ptr == ' ') ptr++;
498 len = ptr2-ptr;
499 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
500 memcpy(prop,ptr,len*sizeof(WCHAR));
501 prop[len]=0;
502 ptr2++;
504 len = 0;
505 ptr = ptr2;
506 while (*ptr && (quote || (!quote && *ptr!=' ')))
508 if (*ptr == '"')
509 quote = !quote;
510 ptr++;
511 len++;
514 if (*ptr2=='"')
516 ptr2++;
517 len -= 2;
519 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
520 memcpy(val,ptr2,len*sizeof(WCHAR));
521 val[len] = 0;
523 if (strlenW(prop) > 0)
525 TRACE("Found commandline property (%s) = (%s)\n",
526 debugstr_w(prop), debugstr_w(val));
527 MSI_SetPropertyW(package,prop,val);
529 HeapFree(GetProcessHeap(),0,val);
530 HeapFree(GetProcessHeap(),0,prop);
532 ptr++;
536 sz = 10;
537 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
539 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
541 rc = ACTION_ProcessUISequence(package);
542 ui = TRUE;
543 if (rc == ERROR_SUCCESS)
544 rc = ACTION_ProcessExecSequence(package,TRUE);
546 else
547 rc = ACTION_ProcessExecSequence(package,FALSE);
549 else
550 rc = ACTION_ProcessExecSequence(package,FALSE);
552 if (rc == -1)
554 /* install was halted but should be considered a success */
555 rc = ERROR_SUCCESS;
558 package->script->CurrentlyScripting= FALSE;
560 /* process the ending type action */
561 if (rc == ERROR_SUCCESS)
562 ACTION_PerformActionSequence(package,-1,ui);
563 else if (rc == ERROR_INSTALL_USEREXIT)
564 ACTION_PerformActionSequence(package,-2,ui);
565 else if (rc == ERROR_INSTALL_SUSPEND)
566 ACTION_PerformActionSequence(package,-4,ui);
567 else /* failed */
568 ACTION_PerformActionSequence(package,-3,ui);
570 /* finish up running custom actions */
571 ACTION_FinishCustomActions(package);
573 return rc;
576 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
578 UINT rc = ERROR_SUCCESS;
579 MSIRECORD * row = 0;
580 static const WCHAR ExecSeqQuery[] =
581 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
582 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
583 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
584 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
586 static const WCHAR UISeqQuery[] =
587 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
588 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
589 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
590 ' ', '=',' ','%','i',0};
592 if (UI)
593 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
594 else
595 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
597 if (row)
599 LPCWSTR action, cond;
601 TRACE("Running the actions\n");
603 /* check conditions */
604 cond = MSI_RecordGetString(row,2);
605 if (cond)
607 /* this is a hack to skip errors in the condition code */
608 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
609 goto end;
612 action = MSI_RecordGetString(row,1);
613 if (!action)
615 ERR("failed to fetch action\n");
616 rc = ERROR_FUNCTION_FAILED;
617 goto end;
620 if (UI)
621 rc = ACTION_PerformUIAction(package,action);
622 else
623 rc = ACTION_PerformAction(package,action,FALSE);
624 end:
625 msiobj_release(&row->hdr);
627 else
628 rc = ERROR_SUCCESS;
630 return rc;
633 typedef struct {
634 MSIPACKAGE* package;
635 BOOL UI;
636 } iterate_action_param;
638 static UINT ITERATE_Actions(MSIRECORD *row, LPVOID param)
640 iterate_action_param *iap= (iterate_action_param*)param;
641 UINT rc;
642 LPCWSTR cond, action;
644 action = MSI_RecordGetString(row,1);
645 if (!action)
647 ERR("Error is retrieving action name\n");
648 return ERROR_FUNCTION_FAILED;
651 /* check conditions */
652 cond = MSI_RecordGetString(row,2);
653 if (cond)
655 /* this is a hack to skip errors in the condition code */
656 if (MSI_EvaluateConditionW(iap->package, cond) == MSICONDITION_FALSE)
658 TRACE("Skipping action: %s (condition is false)\n",
659 debugstr_w(action));
660 return ERROR_SUCCESS;
664 if (iap->UI)
665 rc = ACTION_PerformUIAction(iap->package,action);
666 else
667 rc = ACTION_PerformAction(iap->package,action,FALSE);
669 if (rc == ERROR_FUNCTION_NOT_CALLED)
670 rc = ERROR_SUCCESS;
672 if (rc != ERROR_SUCCESS)
673 ERR("Execution halted due to error (%i)\n",rc);
675 return rc;
678 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
680 MSIQUERY * view;
681 UINT rc;
682 static const WCHAR ExecSeqQuery[] =
683 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
684 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
685 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
686 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
687 'O','R','D','E','R',' ', 'B','Y',' ',
688 '`','S','e','q','u','e','n','c','e','`',0 };
689 MSIRECORD * row = 0;
690 static const WCHAR IVQuery[] =
691 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
692 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
693 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
694 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
695 ' ','\'', 'I','n','s','t','a','l','l',
696 'V','a','l','i','d','a','t','e','\'', 0};
697 INT seq = 0;
698 iterate_action_param iap;
700 iap.package = package;
701 iap.UI = FALSE;
703 if (package->script->ExecuteSequenceRun)
705 TRACE("Execute Sequence already Run\n");
706 return ERROR_SUCCESS;
709 package->script->ExecuteSequenceRun = TRUE;
711 /* get the sequence number */
712 if (UIran)
714 row = MSI_QueryGetRecord(package->db, IVQuery);
715 if( !row )
716 return ERROR_FUNCTION_FAILED;
717 seq = MSI_RecordGetInteger(row,1);
718 msiobj_release(&row->hdr);
721 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
722 if (rc == ERROR_SUCCESS)
724 TRACE("Running the actions\n");
726 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
727 msiobj_release(&view->hdr);
730 return rc;
733 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
735 MSIQUERY * view;
736 UINT rc;
737 static const WCHAR ExecSeqQuery [] =
738 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
739 '`','I','n','s','t','a','l','l',
740 'U','I','S','e','q','u','e','n','c','e','`',
741 ' ','W','H','E','R','E',' ',
742 '`','S','e','q','u','e','n','c','e','`',' ',
743 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
744 '`','S','e','q','u','e','n','c','e','`',0};
745 iterate_action_param iap;
747 iap.package = package;
748 iap.UI = TRUE;
750 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
752 if (rc == ERROR_SUCCESS)
754 TRACE("Running the actions \n");
756 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
757 msiobj_release(&view->hdr);
760 return rc;
763 /********************************************************
764 * ACTION helper functions and functions that perform the actions
765 *******************************************************/
766 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
767 UINT* rc, BOOL force )
769 BOOL ret = FALSE;
770 BOOL run = force;
771 int i;
773 if (!run && !package->script->CurrentlyScripting)
774 run = TRUE;
776 if (!run)
778 if (strcmpW(action,szInstallFinalize) == 0 ||
779 strcmpW(action,szInstallExecute) == 0 ||
780 strcmpW(action,szInstallExecuteAgain) == 0)
781 run = TRUE;
784 i = 0;
785 while (StandardActions[i].action != NULL)
787 if (strcmpW(StandardActions[i].action, action)==0)
789 ce_actiontext(package, action);
790 if (!run)
792 ui_actioninfo(package, action, TRUE, 0);
793 *rc = schedule_action(package,INSTALL_SCRIPT,action);
794 ui_actioninfo(package, action, FALSE, *rc);
796 else
798 ui_actionstart(package, action);
799 if (StandardActions[i].handler)
801 *rc = StandardActions[i].handler(package);
803 else
805 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
806 *rc = ERROR_SUCCESS;
809 ret = TRUE;
810 break;
812 i++;
814 return ret;
817 static BOOL ACTION_HandleDialogBox( MSIPACKAGE *package, LPCWSTR dialog, UINT* rc )
819 BOOL ret = FALSE;
821 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
823 *rc = package->CurrentInstallState;
824 ret = TRUE;
826 return ret;
829 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
830 UINT* rc, BOOL force )
832 BOOL ret=FALSE;
833 UINT arc;
835 arc = ACTION_CustomAction(package,action, force);
837 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
839 *rc = arc;
840 ret = TRUE;
842 return ret;
846 * A lot of actions are really important even if they don't do anything
847 * explicit... Lots of properties are set at the beginning of the installation
848 * CostFinalize does a bunch of work to translate the directories and such
850 * But until I get write access to the database that is hard, so I am going to
851 * hack it to see if I can get something to run.
853 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
855 UINT rc = ERROR_SUCCESS;
856 BOOL handled;
858 TRACE("Performing action (%s)\n",debugstr_w(action));
860 handled = ACTION_HandleStandardAction(package, action, &rc, force);
862 if (!handled)
863 handled = ACTION_HandleCustomAction(package, action, &rc, force);
865 if (!handled)
867 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
868 rc = ERROR_FUNCTION_NOT_CALLED;
871 package->CurrentInstallState = rc;
872 return rc;
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);
884 if (!handled)
885 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
887 if (!handled)
888 handled = ACTION_HandleDialogBox(package, action, &rc);
890 msi_dialog_check_messages( NULL );
892 if (!handled)
894 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
895 rc = ERROR_FUNCTION_NOT_CALLED;
898 package->CurrentInstallState = rc;
899 return rc;
904 * Actual Action Handlers
907 static UINT ITERATE_CreateFolders(MSIRECORD *row, LPVOID param)
909 MSIPACKAGE *package = (MSIPACKAGE*)param;
910 LPCWSTR dir;
911 LPWSTR full_path;
912 MSIRECORD *uirow;
913 MSIFOLDER *folder;
915 dir = MSI_RecordGetString(row,1);
916 if (!dir)
918 ERR("Unable to get folder id \n");
919 return ERROR_SUCCESS;
922 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
923 if (!full_path)
925 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
926 return ERROR_SUCCESS;
929 TRACE("Folder is %s\n",debugstr_w(full_path));
931 /* UI stuff */
932 uirow = MSI_CreateRecord(1);
933 MSI_RecordSetStringW(uirow,1,full_path);
934 ui_actiondata(package,szCreateFolders,uirow);
935 msiobj_release( &uirow->hdr );
937 if (folder->State == 0)
938 create_full_pathW(full_path);
940 folder->State = 3;
942 HeapFree(GetProcessHeap(),0,full_path);
943 return ERROR_SUCCESS;
948 * Also we cannot enable/disable components either, so for now I am just going
949 * to do all the directories for all the components.
951 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
953 static const WCHAR ExecSeqQuery[] =
954 {'S','E','L','E','C','T',' ',
955 '`','D','i','r','e','c','t','o','r','y','_','`',
956 ' ','F','R','O','M',' ',
957 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
958 UINT rc;
959 MSIQUERY *view;
961 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
962 if (rc != ERROR_SUCCESS)
963 return ERROR_SUCCESS;
965 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateFolders, package);
966 msiobj_release(&view->hdr);
968 return rc;
971 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
973 int index = package->loaded_components;
974 DWORD sz;
976 /* fill in the data */
978 package->loaded_components++;
979 if (package->loaded_components == 1)
980 package->components = HeapAlloc(GetProcessHeap(),0,
981 sizeof(MSICOMPONENT));
982 else
983 package->components = HeapReAlloc(GetProcessHeap(),0,
984 package->components, package->loaded_components *
985 sizeof(MSICOMPONENT));
987 memset(&package->components[index],0,sizeof(MSICOMPONENT));
989 sz = IDENTIFIER_SIZE;
990 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
992 TRACE("Loading Component %s\n",
993 debugstr_w(package->components[index].Component));
995 sz = 0x100;
996 if (!MSI_RecordIsNull(row,2))
997 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
999 sz = IDENTIFIER_SIZE;
1000 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1002 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1004 sz = 0x100;
1005 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1007 sz = IDENTIFIER_SIZE;
1008 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1010 package->components[index].Installed = INSTALLSTATE_ABSENT;
1011 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1012 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1014 package->components[index].Enabled = TRUE;
1016 return index;
1019 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1021 int index = package->loaded_features;
1022 DWORD sz;
1023 static const WCHAR Query1[] =
1024 {'S','E','L','E','C','T',' ',
1025 '`','C','o','m','p','o','n','e','n','t','_','`',
1026 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1027 'C','o','m','p','o','n','e','n','t','s','`',' ',
1028 'W','H','E','R','E',' ',
1029 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1030 static const WCHAR Query2[] =
1031 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1032 '`','C','o','m','p','o','n','e','n','t','`',' ',
1033 'W','H','E','R','E',' ',
1034 '`','C','o','m','p','o','n','e','n','t','`',' ',
1035 '=','\'','%','s','\'',0};
1036 MSIQUERY * view;
1037 MSIQUERY * view2;
1038 MSIRECORD * row2;
1039 MSIRECORD * row3;
1040 UINT rc;
1042 /* fill in the data */
1044 package->loaded_features ++;
1045 if (package->loaded_features == 1)
1046 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1047 else
1048 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1049 package->loaded_features * sizeof(MSIFEATURE));
1051 memset(&package->features[index],0,sizeof(MSIFEATURE));
1053 sz = IDENTIFIER_SIZE;
1054 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1056 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1058 sz = IDENTIFIER_SIZE;
1059 if (!MSI_RecordIsNull(row,2))
1060 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1062 sz = 0x100;
1063 if (!MSI_RecordIsNull(row,3))
1064 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1066 sz = 0x100;
1067 if (!MSI_RecordIsNull(row,4))
1068 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1070 if (!MSI_RecordIsNull(row,5))
1071 package->features[index].Display = MSI_RecordGetInteger(row,5);
1073 package->features[index].Level= MSI_RecordGetInteger(row,6);
1075 sz = IDENTIFIER_SIZE;
1076 if (!MSI_RecordIsNull(row,7))
1077 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1079 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1081 package->features[index].Installed = INSTALLSTATE_ABSENT;
1082 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1083 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1085 /* load feature components */
1087 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1088 if (rc != ERROR_SUCCESS)
1089 return;
1090 rc = MSI_ViewExecute(view,0);
1091 if (rc != ERROR_SUCCESS)
1093 MSI_ViewClose(view);
1094 msiobj_release(&view->hdr);
1095 return;
1097 while (1)
1099 LPCWSTR component;
1100 DWORD rc;
1101 INT c_indx;
1102 INT cnt = package->features[index].ComponentCount;
1104 rc = MSI_ViewFetch(view,&row2);
1105 if (rc != ERROR_SUCCESS)
1106 break;
1108 component = MSI_RecordGetString(row2,1);
1110 /* check to see if the component is already loaded */
1111 c_indx = get_loaded_component(package,component);
1112 if (c_indx != -1)
1114 TRACE("Component %s already loaded at %i\n", debugstr_w(component),
1115 c_indx);
1116 package->features[index].Components[cnt] = c_indx;
1117 package->features[index].ComponentCount ++;
1118 msiobj_release( &row2->hdr );
1119 continue;
1122 rc = MSI_OpenQuery(package->db, &view2, Query2, component);
1123 if (rc != ERROR_SUCCESS)
1125 msiobj_release( &row2->hdr );
1126 continue;
1128 rc = MSI_ViewExecute(view2,0);
1129 if (rc != ERROR_SUCCESS)
1131 msiobj_release( &row2->hdr );
1132 MSI_ViewClose(view2);
1133 msiobj_release( &view2->hdr );
1134 continue;
1136 while (1)
1138 DWORD rc;
1140 rc = MSI_ViewFetch(view2,&row3);
1141 if (rc != ERROR_SUCCESS)
1142 break;
1143 c_indx = load_component(package,row3);
1144 msiobj_release( &row3->hdr );
1146 package->features[index].Components[cnt] = c_indx;
1147 package->features[index].ComponentCount ++;
1148 TRACE("Loaded new component to index %i\n",c_indx);
1150 MSI_ViewClose(view2);
1151 msiobj_release( &view2->hdr );
1152 msiobj_release( &row2->hdr );
1154 MSI_ViewClose(view);
1155 msiobj_release(&view->hdr);
1158 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1160 DWORD index = package->loaded_files;
1161 LPCWSTR component;
1163 /* fill in the data */
1165 package->loaded_files++;
1166 if (package->loaded_files== 1)
1167 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1168 else
1169 package->files = HeapReAlloc(GetProcessHeap(),0,
1170 package->files , package->loaded_files * sizeof(MSIFILE));
1172 memset(&package->files[index],0,sizeof(MSIFILE));
1174 package->files[index].File = load_dynamic_stringW(row, 1);
1176 component = MSI_RecordGetString(row, 2);
1177 package->files[index].ComponentIndex = get_loaded_component(package,
1178 component);
1180 if (package->files[index].ComponentIndex == -1)
1181 ERR("Unfound Component %s\n",debugstr_w(component));
1183 package->files[index].FileName = load_dynamic_stringW(row,3);
1184 reduce_to_longfilename(package->files[index].FileName);
1186 package->files[index].ShortName = load_dynamic_stringW(row,3);
1187 reduce_to_shortfilename(package->files[index].ShortName);
1189 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1190 package->files[index].Version = load_dynamic_stringW(row, 5);
1191 package->files[index].Language = load_dynamic_stringW(row, 6);
1192 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1193 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1195 package->files[index].Temporary = FALSE;
1196 package->files[index].State = 0;
1198 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1200 return ERROR_SUCCESS;
1203 static UINT load_all_files(MSIPACKAGE *package)
1205 MSIQUERY * view;
1206 MSIRECORD * row;
1207 UINT rc;
1208 static const WCHAR Query[] =
1209 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1210 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1211 '`','S','e','q','u','e','n','c','e','`', 0};
1213 if (!package)
1214 return ERROR_INVALID_HANDLE;
1216 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1217 if (rc != ERROR_SUCCESS)
1218 return ERROR_SUCCESS;
1220 rc = MSI_ViewExecute(view, 0);
1221 if (rc != ERROR_SUCCESS)
1223 MSI_ViewClose(view);
1224 msiobj_release(&view->hdr);
1225 return ERROR_SUCCESS;
1228 while (1)
1230 rc = MSI_ViewFetch(view,&row);
1231 if (rc != ERROR_SUCCESS)
1233 rc = ERROR_SUCCESS;
1234 break;
1236 load_file(package,row);
1237 msiobj_release(&row->hdr);
1239 MSI_ViewClose(view);
1240 msiobj_release(&view->hdr);
1242 return ERROR_SUCCESS;
1247 * I am not doing any of the costing functionality yet.
1248 * Mostly looking at doing the Component and Feature loading
1250 * The native MSI does A LOT of modification to tables here. Mostly adding
1251 * a lot of temporary columns to the Feature and Component tables.
1253 * note: Native msi also tracks the short filename. But I am only going to
1254 * track the long ones. Also looking at this directory table
1255 * it appears that the directory table does not get the parents
1256 * resolved base on property only based on their entries in the
1257 * directory table.
1259 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1261 MSIQUERY * view;
1262 MSIRECORD * row;
1263 UINT rc;
1264 static const WCHAR Query_all[] =
1265 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1266 '`','F','e','a','t','u','r','e','`',0};
1267 static const WCHAR szCosting[] =
1268 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1269 static const WCHAR szZero[] = { '0', 0 };
1270 WCHAR buffer[3];
1271 DWORD sz = 3;
1273 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1274 if (buffer[0]=='1')
1275 return ERROR_SUCCESS;
1277 MSI_SetPropertyW(package, szCosting, szZero);
1278 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1280 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1281 if (rc != ERROR_SUCCESS)
1282 return rc;
1283 rc = MSI_ViewExecute(view,0);
1284 if (rc != ERROR_SUCCESS)
1286 MSI_ViewClose(view);
1287 msiobj_release(&view->hdr);
1288 return rc;
1290 while (1)
1292 DWORD rc;
1294 rc = MSI_ViewFetch(view,&row);
1295 if (rc != ERROR_SUCCESS)
1296 break;
1298 load_feature(package,row);
1299 msiobj_release(&row->hdr);
1301 MSI_ViewClose(view);
1302 msiobj_release(&view->hdr);
1304 load_all_files(package);
1306 return ERROR_SUCCESS;
1309 static UINT execute_script(MSIPACKAGE *package, UINT script )
1311 int i;
1312 UINT rc = ERROR_SUCCESS;
1314 TRACE("Executing Script %i\n",script);
1316 for (i = 0; i < package->script->ActionCount[script]; i++)
1318 LPWSTR action;
1319 action = package->script->Actions[script][i];
1320 ui_actionstart(package, action);
1321 TRACE("Executing Action (%s)\n",debugstr_w(action));
1322 rc = ACTION_PerformAction(package, action, TRUE);
1323 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1324 if (rc != ERROR_SUCCESS)
1325 break;
1327 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1329 package->script->ActionCount[script] = 0;
1330 package->script->Actions[script] = NULL;
1331 return rc;
1334 static UINT ACTION_FileCost(MSIPACKAGE *package)
1336 return ERROR_SUCCESS;
1340 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1342 static const WCHAR Query[] =
1343 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1344 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1345 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1346 ' ','=',' ','\'','%','s','\'',
1348 LPWSTR ptargetdir, targetdir, srcdir;
1349 LPCWSTR parent;
1350 LPWSTR shortname = NULL;
1351 MSIRECORD * row = 0;
1352 INT index = -1;
1353 DWORD i;
1355 TRACE("Looking for dir %s\n",debugstr_w(dir));
1357 for (i = 0; i < package->loaded_folders; i++)
1359 if (strcmpW(package->folders[i].Directory,dir)==0)
1361 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1362 return i;
1366 TRACE("Working to load %s\n",debugstr_w(dir));
1368 index = package->loaded_folders++;
1369 if (package->loaded_folders==1)
1370 package->folders = HeapAlloc(GetProcessHeap(),0,
1371 sizeof(MSIFOLDER));
1372 else
1373 package->folders= HeapReAlloc(GetProcessHeap(),0,
1374 package->folders, package->loaded_folders*
1375 sizeof(MSIFOLDER));
1377 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1379 package->folders[index].Directory = strdupW(dir);
1381 row = MSI_QueryGetRecord(package->db, Query, dir);
1382 if (!row)
1383 return -1;
1385 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1387 /* split src and target dir */
1388 if (strchrW(targetdir,':'))
1390 srcdir=strchrW(targetdir,':');
1391 *srcdir=0;
1392 srcdir ++;
1394 else
1395 srcdir=NULL;
1397 /* for now only pick long filename versions */
1398 if (strchrW(targetdir,'|'))
1400 shortname = targetdir;
1401 targetdir = strchrW(targetdir,'|');
1402 *targetdir = 0;
1403 targetdir ++;
1405 /* for the sourcedir pick the short filename */
1406 if (srcdir && strchrW(srcdir,'|'))
1408 LPWSTR p = strchrW(srcdir,'|');
1409 *p = 0;
1412 /* now check for root dirs */
1413 if (targetdir[0] == '.' && targetdir[1] == 0)
1414 targetdir = NULL;
1416 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1417 srcdir = NULL;
1419 if (targetdir)
1421 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1422 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
1423 package->folders[index].TargetDefault = strdupW(targetdir);
1426 if (srcdir)
1427 package->folders[index].SourceDefault = strdupW(srcdir);
1428 else if (shortname)
1429 package->folders[index].SourceDefault = strdupW(shortname);
1430 else if (targetdir)
1431 package->folders[index].SourceDefault = strdupW(targetdir);
1432 HeapFree(GetProcessHeap(), 0, ptargetdir);
1433 TRACE(" SourceDefault = %s\n",debugstr_w(package->folders[index].SourceDefault));
1435 parent = MSI_RecordGetString(row,2);
1436 if (parent)
1438 i = load_folder(package,parent);
1439 package->folders[index].ParentIndex = i;
1440 TRACE("Parent is index %i... %s %s\n",
1441 package->folders[index].ParentIndex,
1442 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1443 debugstr_w(parent));
1445 else
1446 package->folders[index].ParentIndex = -2;
1448 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
1450 msiobj_release(&row->hdr);
1451 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1452 return index;
1455 /* scan for and update current install states */
1456 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
1458 int i;
1459 LPWSTR productcode;
1461 productcode = load_dynamic_property(package,szProductCode,NULL);
1463 for (i = 0; i < package->loaded_components; i++)
1465 INSTALLSTATE res;
1466 res = MsiGetComponentPathW(productcode,
1467 package->components[i].ComponentId , NULL, NULL);
1468 if (res < 0)
1469 res = INSTALLSTATE_ABSENT;
1470 package->components[i].Installed = res;
1473 for (i = 0; i < package->loaded_features; i++)
1475 INSTALLSTATE res = -10;
1476 int j;
1477 for (j = 0; j < package->features[i].ComponentCount; j++)
1479 MSICOMPONENT* component = &package->components[package->features[i].
1480 Components[j]];
1481 if (res == -10)
1482 res = component->Installed;
1483 else
1485 if (res == component->Installed)
1486 continue;
1488 if (res != component->Installed)
1489 res = INSTALLSTATE_INCOMPLETE;
1495 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
1496 INSTALLSTATE state)
1498 static const WCHAR all[]={'A','L','L',0};
1499 LPWSTR override = NULL;
1500 INT i;
1501 BOOL rc = FALSE;
1503 override = load_dynamic_property(package, property, NULL);
1504 if (override)
1506 rc = TRUE;
1507 for(i = 0; i < package->loaded_features; i++)
1509 if (strcmpiW(override,all)==0)
1511 package->features[i].ActionRequest= state;
1512 package->features[i].Action = state;
1514 else
1516 LPWSTR ptr = override;
1517 LPWSTR ptr2 = strchrW(override,',');
1519 while (ptr)
1521 if ((ptr2 &&
1522 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
1523 || (!ptr2 &&
1524 strcmpW(ptr,package->features[i].Feature)==0))
1526 package->features[i].ActionRequest= state;
1527 package->features[i].Action = state;
1528 break;
1530 if (ptr2)
1532 ptr=ptr2+1;
1533 ptr2 = strchrW(ptr,',');
1535 else
1536 break;
1540 HeapFree(GetProcessHeap(),0,override);
1543 return rc;
1546 static UINT SetFeatureStates(MSIPACKAGE *package)
1548 LPWSTR level;
1549 INT install_level;
1550 DWORD i;
1551 INT j;
1552 static const WCHAR szlevel[] =
1553 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1554 static const WCHAR szAddLocal[] =
1555 {'A','D','D','L','O','C','A','L',0};
1556 static const WCHAR szRemove[] =
1557 {'R','E','M','O','V','E',0};
1558 BOOL override = FALSE;
1560 /* I do not know if this is where it should happen.. but */
1562 TRACE("Checking Install Level\n");
1564 level = load_dynamic_property(package,szlevel,NULL);
1565 if (level)
1567 install_level = atoiW(level);
1568 HeapFree(GetProcessHeap(), 0, level);
1570 else
1571 install_level = 1;
1573 /* ok hereis the _real_ rub
1574 * all these activation/deactivation things happen in order and things
1575 * later on the list override things earlier on the list.
1576 * 1) INSTALLLEVEL processing
1577 * 2) ADDLOCAL
1578 * 3) REMOVE
1579 * 4) ADDSOURCE
1580 * 5) ADDDEFAULT
1581 * 6) REINSTALL
1582 * 7) COMPADDLOCAL
1583 * 8) COMPADDSOURCE
1584 * 9) FILEADDLOCAL
1585 * 10) FILEADDSOURCE
1586 * 11) FILEADDDEFAULT
1587 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1588 * ignored for all the features. seems strange, especially since it is not
1589 * documented anywhere, but it is how it works.
1591 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1592 * REMOVE are the big ones, since we don't handle administrative installs
1593 * yet anyway.
1595 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
1596 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
1598 if (!override)
1600 for(i = 0; i < package->loaded_features; i++)
1602 BOOL feature_state = ((package->features[i].Level > 0) &&
1603 (package->features[i].Level <= install_level));
1605 if ((feature_state) &&
1606 (package->features[i].Action == INSTALLSTATE_UNKNOWN))
1608 if (package->features[i].Attributes &
1609 msidbFeatureAttributesFavorSource)
1611 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
1612 package->features[i].Action = INSTALLSTATE_SOURCE;
1614 else if (package->features[i].Attributes &
1615 msidbFeatureAttributesFavorAdvertise)
1617 package->features[i].ActionRequest =INSTALLSTATE_ADVERTISED;
1618 package->features[i].Action =INSTALLSTATE_ADVERTISED;
1620 else
1622 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
1623 package->features[i].Action = INSTALLSTATE_LOCAL;
1628 else
1630 /* set the Preselected Property */
1631 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1632 static const WCHAR szOne[] = { '1', 0 };
1634 MSI_SetPropertyW(package,szPreselected,szOne);
1638 * now we want to enable or disable components base on feature
1641 for(i = 0; i < package->loaded_features; i++)
1643 MSIFEATURE* feature = &package->features[i];
1644 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1645 debugstr_w(feature->Feature), feature->Installed, feature->Action,
1646 feature->ActionRequest);
1648 for( j = 0; j < feature->ComponentCount; j++)
1650 MSICOMPONENT* component = &package->components[
1651 feature->Components[j]];
1653 if (!component->Enabled)
1655 component->Action = INSTALLSTATE_UNKNOWN;
1656 component->ActionRequest = INSTALLSTATE_UNKNOWN;
1658 else
1660 if (feature->Action == INSTALLSTATE_LOCAL)
1662 component->Action = INSTALLSTATE_LOCAL;
1663 component->ActionRequest = INSTALLSTATE_LOCAL;
1665 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
1667 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1668 (component->Action == INSTALLSTATE_ABSENT) ||
1669 (component->Action == INSTALLSTATE_ADVERTISED))
1672 component->Action = INSTALLSTATE_SOURCE;
1673 component->ActionRequest = INSTALLSTATE_SOURCE;
1676 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
1678 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
1679 (component->Action == INSTALLSTATE_ABSENT))
1682 component->Action = INSTALLSTATE_ADVERTISED;
1683 component->ActionRequest = INSTALLSTATE_ADVERTISED;
1686 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
1688 if (component->Action == INSTALLSTATE_UNKNOWN)
1690 component->Action = INSTALLSTATE_ABSENT;
1691 component->ActionRequest = INSTALLSTATE_ABSENT;
1698 for(i = 0; i < package->loaded_components; i++)
1700 MSICOMPONENT* component= &package->components[i];
1702 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1703 debugstr_w(component->Component), component->Installed,
1704 component->Action, component->ActionRequest);
1708 return ERROR_SUCCESS;
1711 static UINT ITERATE_CostFinalizeDirectories(MSIRECORD *row, LPVOID param)
1713 MSIPACKAGE *package = (MSIPACKAGE*)param;
1714 LPCWSTR name;
1715 LPWSTR path;
1717 name = MSI_RecordGetString(row,1);
1719 /* This helper function now does ALL the work */
1720 TRACE("Dir %s ...\n",debugstr_w(name));
1721 load_folder(package,name);
1722 path = resolve_folder(package,name,FALSE,TRUE,NULL);
1723 TRACE("resolves to %s\n",debugstr_w(path));
1724 HeapFree( GetProcessHeap(), 0, path);
1726 return ERROR_SUCCESS;
1729 static UINT ITERATE_CostFinalizeConditions(MSIRECORD *row, LPVOID param)
1731 MSIPACKAGE *package = (MSIPACKAGE*)param;
1732 LPCWSTR Feature;
1733 int feature_index;
1735 Feature = MSI_RecordGetString(row,1);
1737 feature_index = get_loaded_feature(package,Feature);
1738 if (feature_index < 0)
1739 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
1740 else
1742 LPCWSTR Condition;
1743 Condition = MSI_RecordGetString(row,3);
1745 if (MSI_EvaluateConditionW(package,Condition) ==
1746 MSICONDITION_TRUE)
1748 int level = MSI_RecordGetInteger(row,2);
1749 TRACE("Reseting feature %s to level %i\n",
1750 debugstr_w(Feature), level);
1751 package->features[feature_index].Level = level;
1754 return ERROR_SUCCESS;
1759 * A lot is done in this function aside from just the costing.
1760 * The costing needs to be implemented at some point but for now I am going
1761 * to focus on the directory building
1764 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
1766 static const WCHAR ExecSeqQuery[] =
1767 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1768 '`','D','i','r','e','c','t','o','r','y','`',0};
1769 static const WCHAR ConditionQuery[] =
1770 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1771 '`','C','o','n','d','i','t','i','o','n','`',0};
1772 static const WCHAR szCosting[] =
1773 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1774 static const WCHAR szlevel[] =
1775 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1776 static const WCHAR szOne[] = { '1', 0 };
1777 UINT rc;
1778 MSIQUERY * view;
1779 DWORD i;
1780 LPWSTR level;
1781 DWORD sz = 3;
1782 WCHAR buffer[3];
1784 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1785 if (buffer[0]=='1')
1786 return ERROR_SUCCESS;
1788 TRACE("Building Directory properties\n");
1790 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1791 if (rc == ERROR_SUCCESS)
1793 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeDirectories,
1794 package);
1795 msiobj_release(&view->hdr);
1798 TRACE("File calculations %i files\n",package->loaded_files);
1800 for (i = 0; i < package->loaded_files; i++)
1802 MSICOMPONENT* comp = NULL;
1803 MSIFILE* file= NULL;
1805 file = &package->files[i];
1806 if (file->ComponentIndex >= 0)
1807 comp = &package->components[file->ComponentIndex];
1809 if (file->Temporary == TRUE)
1810 continue;
1812 if (comp)
1814 LPWSTR p;
1816 /* calculate target */
1817 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
1819 HeapFree(GetProcessHeap(),0,file->TargetPath);
1821 TRACE("file %s is named %s\n",
1822 debugstr_w(file->File),debugstr_w(file->FileName));
1824 file->TargetPath = build_directory_name(2, p, file->FileName);
1826 HeapFree(GetProcessHeap(),0,p);
1828 TRACE("file %s resolves to %s\n",
1829 debugstr_w(file->File),debugstr_w(file->TargetPath));
1831 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
1833 file->State = 1;
1834 comp->Cost += file->FileSize;
1836 else
1838 if (file->Version)
1840 DWORD handle;
1841 DWORD versize;
1842 UINT sz;
1843 LPVOID version;
1844 static const WCHAR name[] =
1845 {'\\',0};
1846 static const WCHAR name_fmt[] =
1847 {'%','u','.','%','u','.','%','u','.','%','u',0};
1848 WCHAR filever[0x100];
1849 VS_FIXEDFILEINFO *lpVer;
1851 TRACE("Version comparison.. \n");
1852 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
1853 version = HeapAlloc(GetProcessHeap(),0,versize);
1854 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
1856 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
1858 sprintfW(filever,name_fmt,
1859 HIWORD(lpVer->dwFileVersionMS),
1860 LOWORD(lpVer->dwFileVersionMS),
1861 HIWORD(lpVer->dwFileVersionLS),
1862 LOWORD(lpVer->dwFileVersionLS));
1864 TRACE("new %s old %s\n", debugstr_w(file->Version),
1865 debugstr_w(filever));
1866 if (strcmpiW(filever,file->Version)<0)
1868 file->State = 2;
1869 FIXME("cost should be diff in size\n");
1870 comp->Cost += file->FileSize;
1872 else
1873 file->State = 3;
1874 HeapFree(GetProcessHeap(),0,version);
1876 else
1877 file->State = 3;
1882 TRACE("Evaluating Condition Table\n");
1884 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
1885 if (rc == ERROR_SUCCESS)
1887 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeConditions,
1888 package);
1889 msiobj_release(&view->hdr);
1892 TRACE("Enabling or Disabling Components\n");
1893 for (i = 0; i < package->loaded_components; i++)
1895 if (package->components[i].Condition[0])
1897 if (MSI_EvaluateConditionW(package,
1898 package->components[i].Condition) == MSICONDITION_FALSE)
1900 TRACE("Disabling component %s\n",
1901 debugstr_w(package->components[i].Component));
1902 package->components[i].Enabled = FALSE;
1907 MSI_SetPropertyW(package,szCosting,szOne);
1908 /* set default run level if not set */
1909 level = load_dynamic_property(package,szlevel,NULL);
1910 if (!level)
1911 MSI_SetPropertyW(package,szlevel, szOne);
1912 else
1913 HeapFree(GetProcessHeap(),0,level);
1915 ACTION_UpdateInstallStates(package);
1917 return SetFeatureStates(package);
1922 /* OK this value is "interpreted" and then formatted based on the
1923 first few characters */
1924 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
1925 DWORD *size)
1927 LPSTR data = NULL;
1928 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
1930 if (value[1]=='x')
1932 LPWSTR ptr;
1933 CHAR byte[5];
1934 LPWSTR deformated = NULL;
1935 int count;
1937 deformat_string(package, &value[2], &deformated);
1939 /* binary value type */
1940 ptr = deformated;
1941 *type = REG_BINARY;
1942 if (strlenW(ptr)%2)
1943 *size = (strlenW(ptr)/2)+1;
1944 else
1945 *size = strlenW(ptr)/2;
1947 data = HeapAlloc(GetProcessHeap(),0,*size);
1949 byte[0] = '0';
1950 byte[1] = 'x';
1951 byte[4] = 0;
1952 count = 0;
1953 /* if uneven pad with a zero in front */
1954 if (strlenW(ptr)%2)
1956 byte[2]= '0';
1957 byte[3]= *ptr;
1958 ptr++;
1959 data[count] = (BYTE)strtol(byte,NULL,0);
1960 count ++;
1961 TRACE("Uneven byte count\n");
1963 while (*ptr)
1965 byte[2]= *ptr;
1966 ptr++;
1967 byte[3]= *ptr;
1968 ptr++;
1969 data[count] = (BYTE)strtol(byte,NULL,0);
1970 count ++;
1972 HeapFree(GetProcessHeap(),0,deformated);
1974 TRACE("Data %li bytes(%i)\n",*size,count);
1976 else
1978 LPWSTR deformated;
1979 LPWSTR p;
1980 DWORD d = 0;
1981 deformat_string(package, &value[1], &deformated);
1983 *type=REG_DWORD;
1984 *size = sizeof(DWORD);
1985 data = HeapAlloc(GetProcessHeap(),0,*size);
1986 p = deformated;
1987 if (*p == '-')
1988 p++;
1989 while (*p)
1991 if ( (*p < '0') || (*p > '9') )
1992 break;
1993 d *= 10;
1994 d += (*p - '0');
1995 p++;
1997 if (deformated[0] == '-')
1998 d = -d;
1999 *(LPDWORD)data = d;
2000 TRACE("DWORD %li\n",*(LPDWORD)data);
2002 HeapFree(GetProcessHeap(),0,deformated);
2005 else
2007 static const WCHAR szMulti[] = {'[','~',']',0};
2008 LPCWSTR ptr;
2009 *type=REG_SZ;
2011 if (value[0]=='#')
2013 if (value[1]=='%')
2015 ptr = &value[2];
2016 *type=REG_EXPAND_SZ;
2018 else
2019 ptr = &value[1];
2021 else
2022 ptr=value;
2024 if (strstrW(value,szMulti))
2025 *type = REG_MULTI_SZ;
2027 *size = deformat_string(package, ptr,(LPWSTR*)&data);
2029 return data;
2032 static UINT ITERATE_WriteRegistryValues(MSIRECORD *row, LPVOID param)
2034 MSIPACKAGE *package = (MSIPACKAGE*)param;
2035 static const WCHAR szHCR[] =
2036 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
2037 'R','O','O','T','\\',0};
2038 static const WCHAR szHCU[] =
2039 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
2040 'U','S','E','R','\\',0};
2041 static const WCHAR szHLM[] =
2042 {'H','K','E','Y','_','L','O','C','A','L','_',
2043 'M','A','C','H','I','N','E','\\',0};
2044 static const WCHAR szHU[] =
2045 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2047 LPSTR value_data = NULL;
2048 HKEY root_key, hkey;
2049 DWORD type,size;
2050 LPWSTR deformated;
2051 LPCWSTR szRoot, component, name, key, value;
2052 INT component_index;
2053 MSIRECORD * uirow;
2054 LPWSTR uikey;
2055 INT root;
2056 BOOL check_first = FALSE;
2057 UINT rc;
2059 ui_progress(package,2,0,0,0);
2061 value = NULL;
2062 key = NULL;
2063 uikey = NULL;
2064 name = NULL;
2066 component = MSI_RecordGetString(row, 6);
2067 component_index = get_loaded_component(package,component);
2069 if (!ACTION_VerifyComponentForAction(package, component_index,
2070 INSTALLSTATE_LOCAL))
2072 TRACE("Skipping write due to disabled component %s\n",
2073 debugstr_w(component));
2075 package->components[component_index].Action =
2076 package->components[component_index].Installed;
2078 return ERROR_SUCCESS;
2081 package->components[component_index].Action = INSTALLSTATE_LOCAL;
2083 name = MSI_RecordGetString(row, 4);
2084 if( MSI_RecordIsNull(row,5) && name )
2086 /* null values can have special meanings */
2087 if (name[0]=='-' && name[1] == 0)
2088 return ERROR_SUCCESS;
2089 else if ((name[0]=='+' && name[1] == 0) ||
2090 (name[0] == '*' && name[1] == 0))
2091 name = NULL;
2092 check_first = TRUE;
2095 root = MSI_RecordGetInteger(row,2);
2096 key = MSI_RecordGetString(row, 3);
2098 /* get the root key */
2099 switch (root)
2101 case 0: root_key = HKEY_CLASSES_ROOT;
2102 szRoot = szHCR;
2103 break;
2104 case 1: root_key = HKEY_CURRENT_USER;
2105 szRoot = szHCU;
2106 break;
2107 case 2: root_key = HKEY_LOCAL_MACHINE;
2108 szRoot = szHLM;
2109 break;
2110 case 3: root_key = HKEY_USERS;
2111 szRoot = szHU;
2112 break;
2113 default:
2114 ERR("Unknown root %i\n",root);
2115 root_key=NULL;
2116 szRoot = NULL;
2117 break;
2119 if (!root_key)
2120 return ERROR_SUCCESS;
2122 deformat_string(package, key , &deformated);
2123 size = strlenW(deformated) + strlenW(szRoot) + 1;
2124 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
2125 strcpyW(uikey,szRoot);
2126 strcatW(uikey,deformated);
2128 if (RegCreateKeyW( root_key, deformated, &hkey))
2130 ERR("Could not create key %s\n",debugstr_w(deformated));
2131 HeapFree(GetProcessHeap(),0,deformated);
2132 HeapFree(GetProcessHeap(),0,uikey);
2133 return ERROR_SUCCESS;
2135 HeapFree(GetProcessHeap(),0,deformated);
2137 value = MSI_RecordGetString(row,5);
2138 if (value)
2139 value_data = parse_value(package, value, &type, &size);
2140 else
2142 static const WCHAR szEmpty[] = {0};
2143 value_data = (LPSTR)strdupW(szEmpty);
2144 size = 0;
2145 type = REG_SZ;
2148 deformat_string(package, name, &deformated);
2150 /* get the double nulls to terminate SZ_MULTI */
2151 if (type == REG_MULTI_SZ)
2152 size +=sizeof(WCHAR);
2154 if (!check_first)
2156 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
2157 debugstr_w(uikey));
2158 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
2160 else
2162 DWORD sz = 0;
2163 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
2164 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2166 TRACE("value %s of %s checked already exists\n",
2167 debugstr_w(deformated), debugstr_w(uikey));
2169 else
2171 TRACE("Checked and setting value %s of %s\n",
2172 debugstr_w(deformated), debugstr_w(uikey));
2173 if (deformated || size)
2174 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
2177 RegCloseKey(hkey);
2179 uirow = MSI_CreateRecord(3);
2180 MSI_RecordSetStringW(uirow,2,deformated);
2181 MSI_RecordSetStringW(uirow,1,uikey);
2183 if (type == REG_SZ)
2184 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2185 else
2186 MSI_RecordSetStringW(uirow,3,value);
2188 ui_actiondata(package,szWriteRegistryValues,uirow);
2189 msiobj_release( &uirow->hdr );
2191 HeapFree(GetProcessHeap(),0,value_data);
2192 HeapFree(GetProcessHeap(),0,deformated);
2193 HeapFree(GetProcessHeap(),0,uikey);
2195 return ERROR_SUCCESS;
2198 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2200 UINT rc;
2201 MSIQUERY * view;
2202 static const WCHAR ExecSeqQuery[] =
2203 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2204 '`','R','e','g','i','s','t','r','y','`',0 };
2206 if (!package)
2207 return ERROR_INVALID_HANDLE;
2209 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2210 if (rc != ERROR_SUCCESS)
2211 return ERROR_SUCCESS;
2213 /* increment progress bar each time action data is sent */
2214 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
2216 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteRegistryValues, package);
2218 msiobj_release(&view->hdr);
2219 return rc;
2222 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
2224 package->script->CurrentlyScripting = TRUE;
2226 return ERROR_SUCCESS;
2230 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
2232 DWORD progress = 0;
2233 DWORD total = 0;
2234 static const WCHAR q1[]=
2235 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2236 '`','R','e','g','i','s','t','r','y','`',0};
2237 UINT rc;
2238 MSIQUERY * view;
2239 MSIRECORD * row = 0;
2240 int i;
2242 TRACE(" InstallValidate \n");
2244 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
2245 if (rc != ERROR_SUCCESS)
2246 return ERROR_SUCCESS;
2248 rc = MSI_ViewExecute(view, 0);
2249 if (rc != ERROR_SUCCESS)
2251 MSI_ViewClose(view);
2252 msiobj_release(&view->hdr);
2253 return rc;
2255 while (1)
2257 rc = MSI_ViewFetch(view,&row);
2258 if (rc != ERROR_SUCCESS)
2260 rc = ERROR_SUCCESS;
2261 break;
2263 progress +=1;
2265 msiobj_release(&row->hdr);
2267 MSI_ViewClose(view);
2268 msiobj_release(&view->hdr);
2270 total = total + progress * REG_PROGRESS_VALUE;
2271 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
2272 for (i=0; i < package->loaded_files; i++)
2273 total += package->files[i].FileSize;
2274 ui_progress(package,0,total,0,0);
2276 for(i = 0; i < package->loaded_features; i++)
2278 MSIFEATURE* feature = &package->features[i];
2279 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2280 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2281 feature->ActionRequest);
2284 return ERROR_SUCCESS;
2287 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
2289 UINT rc;
2290 MSIQUERY * view = NULL;
2291 MSIRECORD * row = 0;
2292 static const WCHAR ExecSeqQuery[] =
2293 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2294 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2295 static const WCHAR title[]=
2296 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2298 TRACE("Checking launch conditions\n");
2300 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2301 if (rc != ERROR_SUCCESS)
2302 return ERROR_SUCCESS;
2304 rc = MSI_ViewExecute(view, 0);
2305 if (rc != ERROR_SUCCESS)
2307 MSI_ViewClose(view);
2308 msiobj_release(&view->hdr);
2309 return rc;
2312 rc = ERROR_SUCCESS;
2313 while (rc == ERROR_SUCCESS)
2315 LPCWSTR cond = NULL;
2316 LPCWSTR message = NULL;
2318 rc = MSI_ViewFetch(view,&row);
2319 if (rc != ERROR_SUCCESS)
2321 rc = ERROR_SUCCESS;
2322 break;
2325 cond = MSI_RecordGetString(row,1);
2327 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
2329 LPWSTR deformated;
2330 message = MSI_RecordGetString(row,2);
2331 deformat_string(package,message,&deformated);
2332 MessageBoxW(NULL,deformated,title,MB_OK);
2333 HeapFree(GetProcessHeap(),0,deformated);
2334 rc = ERROR_FUNCTION_FAILED;
2336 msiobj_release(&row->hdr);
2338 MSI_ViewClose(view);
2339 msiobj_release(&view->hdr);
2340 return rc;
2343 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
2344 component_index)
2346 MSICOMPONENT* cmp = &package->components[component_index];
2348 if (cmp->KeyPath[0]==0)
2350 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
2351 return p;
2353 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
2355 MSIRECORD * row = 0;
2356 UINT root,len;
2357 LPWSTR deformated,buffer,deformated_name;
2358 LPCWSTR key,name;
2359 static const WCHAR ExecSeqQuery[] =
2360 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2361 '`','R','e','g','i','s','t','r','y','`',' ',
2362 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2363 ' ','=',' ' ,'\'','%','s','\'',0 };
2364 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
2365 static const WCHAR fmt2[]=
2366 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2368 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
2369 if (!row)
2370 return NULL;
2372 root = MSI_RecordGetInteger(row,2);
2373 key = MSI_RecordGetString(row, 3);
2374 name = MSI_RecordGetString(row, 4);
2375 deformat_string(package, key , &deformated);
2376 deformat_string(package, name, &deformated_name);
2378 len = strlenW(deformated) + 6;
2379 if (deformated_name)
2380 len+=strlenW(deformated_name);
2382 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
2384 if (deformated_name)
2385 sprintfW(buffer,fmt2,root,deformated,deformated_name);
2386 else
2387 sprintfW(buffer,fmt,root,deformated);
2389 HeapFree(GetProcessHeap(),0,deformated);
2390 HeapFree(GetProcessHeap(),0,deformated_name);
2391 msiobj_release(&row->hdr);
2393 return buffer;
2395 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
2397 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2398 return NULL;
2400 else
2402 int j;
2403 j = get_loaded_file(package,cmp->KeyPath);
2405 if (j>=0)
2407 LPWSTR p = strdupW(package->files[j].TargetPath);
2408 return p;
2411 return NULL;
2414 static HKEY openSharedDLLsKey(void)
2416 HKEY hkey=0;
2417 static const WCHAR path[] =
2418 {'S','o','f','t','w','a','r','e','\\',
2419 'M','i','c','r','o','s','o','f','t','\\',
2420 'W','i','n','d','o','w','s','\\',
2421 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2422 'S','h','a','r','e','d','D','L','L','s',0};
2424 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
2425 return hkey;
2428 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
2430 HKEY hkey;
2431 DWORD count=0;
2432 DWORD type;
2433 DWORD sz = sizeof(count);
2434 DWORD rc;
2436 hkey = openSharedDLLsKey();
2437 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
2438 if (rc != ERROR_SUCCESS)
2439 count = 0;
2440 RegCloseKey(hkey);
2441 return count;
2444 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
2446 HKEY hkey;
2448 hkey = openSharedDLLsKey();
2449 if (count > 0)
2450 RegSetValueExW(hkey,path,0,REG_DWORD,
2451 (LPBYTE)&count,sizeof(count));
2452 else
2453 RegDeleteValueW(hkey,path);
2454 RegCloseKey(hkey);
2455 return count;
2459 * Return TRUE if the count should be written out and FALSE if not
2461 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
2463 INT count = 0;
2464 BOOL write = FALSE;
2465 INT j;
2467 /* only refcount DLLs */
2468 if (package->components[index].KeyPath[0]==0 ||
2469 package->components[index].Attributes &
2470 msidbComponentAttributesRegistryKeyPath ||
2471 package->components[index].Attributes &
2472 msidbComponentAttributesODBCDataSource)
2473 write = FALSE;
2474 else
2476 count = ACTION_GetSharedDLLsCount(package->components[index].
2477 FullKeypath);
2478 write = (count > 0);
2480 if (package->components[index].Attributes &
2481 msidbComponentAttributesSharedDllRefCount)
2482 write = TRUE;
2485 /* increment counts */
2486 for (j = 0; j < package->loaded_features; j++)
2488 int i;
2490 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
2491 continue;
2493 for (i = 0; i < package->features[j].ComponentCount; i++)
2495 if (package->features[j].Components[i] == index)
2496 count++;
2499 /* decrement counts */
2500 for (j = 0; j < package->loaded_features; j++)
2502 int i;
2503 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
2504 continue;
2506 for (i = 0; i < package->features[j].ComponentCount; i++)
2508 if (package->features[j].Components[i] == index)
2509 count--;
2513 /* ref count all the files in the component */
2514 if (write)
2515 for (j = 0; j < package->loaded_files; j++)
2517 if (package->files[j].Temporary)
2518 continue;
2519 if (package->files[j].ComponentIndex == index)
2520 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
2523 /* add a count for permenent */
2524 if (package->components[index].Attributes &
2525 msidbComponentAttributesPermanent)
2526 count ++;
2528 package->components[index].RefCount = count;
2530 if (write)
2531 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
2532 package->components[index].RefCount);
2536 * Ok further analysis makes me think that this work is
2537 * actually done in the PublishComponents and PublishFeatures
2538 * step, and not here. It appears like the keypath and all that is
2539 * resolved in this step, however actually written in the Publish steps.
2540 * But we will leave it here for now because it is unclear
2542 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
2544 LPWSTR productcode;
2545 WCHAR squished_pc[GUID_SIZE];
2546 WCHAR squished_cc[GUID_SIZE];
2547 UINT rc;
2548 DWORD i;
2549 HKEY hkey=0,hkey2=0;
2551 if (!package)
2552 return ERROR_INVALID_HANDLE;
2554 /* writes the Component and Features values to the registry */
2555 productcode = load_dynamic_property(package,szProductCode,&rc);
2556 if (!productcode)
2557 return rc;
2559 rc = MSIREG_OpenComponents(&hkey);
2560 if (rc != ERROR_SUCCESS)
2561 goto end;
2563 squash_guid(productcode,squished_pc);
2564 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
2565 for (i = 0; i < package->loaded_components; i++)
2567 ui_progress(package,2,0,0,0);
2568 if (package->components[i].ComponentId[0]!=0)
2570 WCHAR *keypath = NULL;
2571 MSIRECORD * uirow;
2573 squash_guid(package->components[i].ComponentId,squished_cc);
2575 keypath = resolve_keypath(package,i);
2576 package->components[i].FullKeypath = keypath;
2578 /* do the refcounting */
2579 ACTION_RefCountComponent( package, i);
2581 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2582 debugstr_w(package->components[i].Component),
2583 debugstr_w(squished_cc),
2584 debugstr_w(package->components[i].FullKeypath),
2585 package->components[i].RefCount);
2587 * Write the keypath out if the component is to be registered
2588 * and delete the key if the component is to be deregistered
2590 if (ACTION_VerifyComponentForAction(package, i,
2591 INSTALLSTATE_LOCAL))
2593 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
2594 if (rc != ERROR_SUCCESS)
2595 continue;
2597 if (keypath)
2599 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
2600 (strlenW(keypath)+1)*sizeof(WCHAR));
2602 if (package->components[i].Attributes &
2603 msidbComponentAttributesPermanent)
2605 static const WCHAR szPermKey[] =
2606 { '0','0','0','0','0','0','0','0','0','0','0','0',
2607 '0','0','0','0','0','0','0', '0','0','0','0','0',
2608 '0','0','0','0','0','0','0','0',0};
2610 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
2611 (LPVOID)keypath,
2612 (strlenW(keypath)+1)*sizeof(WCHAR));
2615 RegCloseKey(hkey2);
2617 /* UI stuff */
2618 uirow = MSI_CreateRecord(3);
2619 MSI_RecordSetStringW(uirow,1,productcode);
2620 MSI_RecordSetStringW(uirow,2,package->components[i].
2621 ComponentId);
2622 MSI_RecordSetStringW(uirow,3,keypath);
2623 ui_actiondata(package,szProcessComponents,uirow);
2624 msiobj_release( &uirow->hdr );
2627 else if (ACTION_VerifyComponentForAction(package, i,
2628 INSTALLSTATE_ABSENT))
2630 DWORD res;
2632 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
2633 if (rc != ERROR_SUCCESS)
2634 continue;
2636 RegDeleteValueW(hkey2,squished_pc);
2638 /* if the key is empty delete it */
2639 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
2640 RegCloseKey(hkey2);
2641 if (res == ERROR_NO_MORE_ITEMS)
2642 RegDeleteKeyW(hkey,squished_cc);
2644 /* UI stuff */
2645 uirow = MSI_CreateRecord(2);
2646 MSI_RecordSetStringW(uirow,1,productcode);
2647 MSI_RecordSetStringW(uirow,2,package->components[i].
2648 ComponentId);
2649 ui_actiondata(package,szProcessComponents,uirow);
2650 msiobj_release( &uirow->hdr );
2654 end:
2655 HeapFree(GetProcessHeap(), 0, productcode);
2656 RegCloseKey(hkey);
2657 return rc;
2660 typedef struct {
2661 CLSID clsid;
2662 LPWSTR source;
2664 LPWSTR path;
2665 ITypeLib *ptLib;
2666 } typelib_struct;
2668 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
2669 LPWSTR lpszName, LONG_PTR lParam)
2671 TLIBATTR *attr;
2672 typelib_struct *tl_struct = (typelib_struct*) lParam;
2673 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
2674 int sz;
2675 HRESULT res;
2677 if (!IS_INTRESOURCE(lpszName))
2679 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
2680 return TRUE;
2683 sz = strlenW(tl_struct->source)+4;
2684 sz *= sizeof(WCHAR);
2686 if ((INT)lpszName == 1)
2687 tl_struct->path = strdupW(tl_struct->source);
2688 else
2690 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
2691 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
2694 TRACE("trying %s\n", debugstr_w(tl_struct->path));
2695 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
2696 if (!SUCCEEDED(res))
2698 HeapFree(GetProcessHeap(),0,tl_struct->path);
2699 tl_struct->path = NULL;
2701 return TRUE;
2704 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
2705 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
2707 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2708 return FALSE;
2711 HeapFree(GetProcessHeap(),0,tl_struct->path);
2712 tl_struct->path = NULL;
2714 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2715 ITypeLib_Release(tl_struct->ptLib);
2717 return TRUE;
2720 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
2723 * OK this is a bit confusing.. I am given a _Component key and I believe
2724 * that the file that is being registered as a type library is the "key file
2725 * of that component" which I interpret to mean "The file in the KeyPath of
2726 * that component".
2728 UINT rc;
2729 MSIQUERY * view;
2730 MSIRECORD * row = 0;
2731 static const WCHAR Query[] =
2732 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2733 '`','T','y','p','e','L','i','b','`',0};
2735 if (!package)
2736 return ERROR_INVALID_HANDLE;
2738 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2739 if (rc != ERROR_SUCCESS)
2740 return ERROR_SUCCESS;
2742 rc = MSI_ViewExecute(view, 0);
2743 if (rc != ERROR_SUCCESS)
2745 MSI_ViewClose(view);
2746 msiobj_release(&view->hdr);
2747 return rc;
2750 while (1)
2752 LPCWSTR component;
2753 INT index;
2754 typelib_struct tl_struct;
2755 HMODULE module;
2756 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
2758 rc = MSI_ViewFetch(view,&row);
2759 if (rc != ERROR_SUCCESS)
2761 rc = ERROR_SUCCESS;
2762 break;
2765 component = MSI_RecordGetString(row,3);
2766 index = get_loaded_component(package,component);
2767 if (index < 0)
2769 msiobj_release(&row->hdr);
2770 continue;
2773 if (!ACTION_VerifyComponentForAction(package, index,
2774 INSTALLSTATE_LOCAL))
2776 TRACE("Skipping typelib reg due to disabled component\n");
2777 msiobj_release(&row->hdr);
2779 package->components[index].Action =
2780 package->components[index].Installed;
2782 continue;
2785 package->components[index].Action = INSTALLSTATE_LOCAL;
2787 index = get_loaded_file(package,package->components[index].KeyPath);
2789 if (index < 0)
2791 msiobj_release(&row->hdr);
2792 continue;
2795 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
2796 LOAD_LIBRARY_AS_DATAFILE);
2797 if (module != NULL)
2799 LPWSTR guid;
2800 guid = load_dynamic_stringW(row,1);
2801 CLSIDFromString(guid, &tl_struct.clsid);
2802 HeapFree(GetProcessHeap(),0,guid);
2803 tl_struct.source = strdupW(package->files[index].TargetPath);
2804 tl_struct.path = NULL;
2806 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
2807 (LONG_PTR)&tl_struct);
2809 if (tl_struct.path != NULL)
2811 LPWSTR help = NULL;
2812 LPCWSTR helpid;
2813 HRESULT res;
2815 helpid = MSI_RecordGetString(row,6);
2817 if (helpid)
2818 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
2819 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
2820 HeapFree(GetProcessHeap(),0,help);
2822 if (!SUCCEEDED(res))
2823 ERR("Failed to register type library %s\n",
2824 debugstr_w(tl_struct.path));
2825 else
2827 ui_actiondata(package,szRegisterTypeLibraries,row);
2829 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
2832 ITypeLib_Release(tl_struct.ptLib);
2833 HeapFree(GetProcessHeap(),0,tl_struct.path);
2835 else
2836 ERR("Failed to load type library %s\n",
2837 debugstr_w(tl_struct.source));
2839 FreeLibrary(module);
2840 HeapFree(GetProcessHeap(),0,tl_struct.source);
2842 else
2843 ERR("Could not load file! %s\n",
2844 debugstr_w(package->files[index].TargetPath));
2845 msiobj_release(&row->hdr);
2847 MSI_ViewClose(view);
2848 msiobj_release(&view->hdr);
2849 return rc;
2852 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
2854 UINT rc;
2855 MSIQUERY * view;
2856 MSIRECORD * row = 0;
2857 static const WCHAR Query[] =
2858 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2859 '`','S','h','o','r','t','c','u','t','`',0};
2860 IShellLinkW *sl;
2861 IPersistFile *pf;
2862 HRESULT res;
2864 if (!package)
2865 return ERROR_INVALID_HANDLE;
2867 res = CoInitialize( NULL );
2868 if (FAILED (res))
2870 ERR("CoInitialize failed\n");
2871 return ERROR_FUNCTION_FAILED;
2874 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2875 if (rc != ERROR_SUCCESS)
2876 return ERROR_SUCCESS;
2878 rc = MSI_ViewExecute(view, 0);
2879 if (rc != ERROR_SUCCESS)
2881 MSI_ViewClose(view);
2882 msiobj_release(&view->hdr);
2883 return rc;
2886 while (1)
2888 LPWSTR target_file, target_folder;
2889 LPCWSTR buffer;
2890 WCHAR filename[0x100];
2891 DWORD sz;
2892 DWORD index;
2893 static const WCHAR szlnk[]={'.','l','n','k',0};
2895 rc = MSI_ViewFetch(view,&row);
2896 if (rc != ERROR_SUCCESS)
2898 rc = ERROR_SUCCESS;
2899 break;
2902 buffer = MSI_RecordGetString(row,4);
2903 index = get_loaded_component(package,buffer);
2905 if (index < 0)
2907 msiobj_release(&row->hdr);
2908 continue;
2911 if (!ACTION_VerifyComponentForAction(package, index,
2912 INSTALLSTATE_LOCAL))
2914 TRACE("Skipping shortcut creation due to disabled component\n");
2915 msiobj_release(&row->hdr);
2917 package->components[index].Action =
2918 package->components[index].Installed;
2920 continue;
2923 package->components[index].Action = INSTALLSTATE_LOCAL;
2925 ui_actiondata(package,szCreateShortcuts,row);
2927 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2928 &IID_IShellLinkW, (LPVOID *) &sl );
2930 if (FAILED(res))
2932 ERR("Is IID_IShellLink\n");
2933 msiobj_release(&row->hdr);
2934 continue;
2937 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
2938 if( FAILED( res ) )
2940 ERR("Is IID_IPersistFile\n");
2941 msiobj_release(&row->hdr);
2942 continue;
2945 buffer = MSI_RecordGetString(row,2);
2946 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
2948 /* may be needed because of a bug somehwere else */
2949 create_full_pathW(target_folder);
2951 sz = 0x100;
2952 MSI_RecordGetStringW(row,3,filename,&sz);
2953 reduce_to_longfilename(filename);
2954 if (!strchrW(filename,'.') || strcmpiW(strchrW(filename,'.'),szlnk))
2955 strcatW(filename,szlnk);
2956 target_file = build_directory_name(2, target_folder, filename);
2957 HeapFree(GetProcessHeap(),0,target_folder);
2959 buffer = MSI_RecordGetString(row,5);
2960 if (strchrW(buffer,'['))
2962 LPWSTR deformated;
2963 deformat_string(package,buffer,&deformated);
2964 IShellLinkW_SetPath(sl,deformated);
2965 HeapFree(GetProcessHeap(),0,deformated);
2967 else
2969 LPWSTR keypath;
2970 FIXME("poorly handled shortcut format, advertised shortcut\n");
2971 keypath = strdupW(package->components[index].FullKeypath);
2972 IShellLinkW_SetPath(sl,keypath);
2973 HeapFree(GetProcessHeap(),0,keypath);
2976 if (!MSI_RecordIsNull(row,6))
2978 LPWSTR deformated;
2979 buffer = MSI_RecordGetString(row,6);
2980 deformat_string(package,buffer,&deformated);
2981 IShellLinkW_SetArguments(sl,deformated);
2982 HeapFree(GetProcessHeap(),0,deformated);
2985 if (!MSI_RecordIsNull(row,7))
2987 buffer = MSI_RecordGetString(row,7);
2988 IShellLinkW_SetDescription(sl,buffer);
2991 if (!MSI_RecordIsNull(row,8))
2992 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
2994 if (!MSI_RecordIsNull(row,9))
2996 WCHAR *Path = NULL;
2997 INT index;
2999 buffer = MSI_RecordGetString(row,9);
3001 build_icon_path(package,buffer,&Path);
3002 index = MSI_RecordGetInteger(row,10);
3004 IShellLinkW_SetIconLocation(sl,Path,index);
3005 HeapFree(GetProcessHeap(),0,Path);
3008 if (!MSI_RecordIsNull(row,11))
3009 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
3011 if (!MSI_RecordIsNull(row,12))
3013 LPWSTR Path;
3014 buffer = MSI_RecordGetString(row,12);
3015 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
3016 IShellLinkW_SetWorkingDirectory(sl,Path);
3017 HeapFree(GetProcessHeap(), 0, Path);
3020 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
3021 IPersistFile_Save(pf,target_file,FALSE);
3023 HeapFree(GetProcessHeap(),0,target_file);
3025 IPersistFile_Release( pf );
3026 IShellLinkW_Release( sl );
3028 msiobj_release(&row->hdr);
3030 MSI_ViewClose(view);
3031 msiobj_release(&view->hdr);
3034 CoUninitialize();
3036 return rc;
3041 * 99% of the work done here is only done for
3042 * advertised installs. However this is where the
3043 * Icon table is processed and written out
3044 * so that is what I am going to do here.
3046 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
3048 UINT rc;
3049 MSIQUERY * view;
3050 MSIRECORD * row = 0;
3051 static const WCHAR Query[]=
3052 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3053 '`','I','c','o','n','`',0};
3054 DWORD sz;
3055 /* for registry stuff */
3056 LPWSTR productcode;
3057 HKEY hkey=0;
3058 HKEY hukey=0;
3059 static const WCHAR szProductName[] =
3060 {'P','r','o','d','u','c','t','N','a','m','e',0};
3061 static const WCHAR szPackageCode[] =
3062 {'P','a','c','k','a','g','e','C','o','d','e',0};
3063 static const WCHAR szLanguage[] =
3064 {'L','a','n','g','u','a','g','e',0};
3065 static const WCHAR szProductLanguage[] =
3066 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3067 static const WCHAR szProductIcon[] =
3068 {'P','r','o','d','u','c','t','I','c','o','n',0};
3069 static const WCHAR szARPProductIcon[] =
3070 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
3071 static const WCHAR szProductVersion[] =
3072 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3073 static const WCHAR szVersion[] =
3074 {'V','e','r','s','i','o','n',0};
3075 DWORD langid;
3076 LPWSTR buffer;
3077 DWORD size;
3078 MSIHANDLE hDb, hSumInfo;
3080 if (!package)
3081 return ERROR_INVALID_HANDLE;
3083 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3084 if (rc != ERROR_SUCCESS)
3085 goto next;
3087 rc = MSI_ViewExecute(view, 0);
3088 if (rc != ERROR_SUCCESS)
3090 MSI_ViewClose(view);
3091 msiobj_release(&view->hdr);
3092 goto next;
3095 while (1)
3097 HANDLE the_file;
3098 LPWSTR FilePath=NULL;
3099 LPCWSTR FileName=NULL;
3100 CHAR buffer[1024];
3102 rc = MSI_ViewFetch(view,&row);
3103 if (rc != ERROR_SUCCESS)
3105 rc = ERROR_SUCCESS;
3106 break;
3109 FileName = MSI_RecordGetString(row,1);
3110 if (!FileName)
3112 ERR("Unable to get FileName\n");
3113 msiobj_release(&row->hdr);
3114 continue;
3117 build_icon_path(package,FileName,&FilePath);
3119 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
3121 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
3122 FILE_ATTRIBUTE_NORMAL, NULL);
3124 if (the_file == INVALID_HANDLE_VALUE)
3126 ERR("Unable to create file %s\n",debugstr_w(FilePath));
3127 msiobj_release(&row->hdr);
3128 HeapFree(GetProcessHeap(),0,FilePath);
3129 continue;
3134 DWORD write;
3135 sz = 1024;
3136 rc = MSI_RecordReadStream(row,2,buffer,&sz);
3137 if (rc != ERROR_SUCCESS)
3139 ERR("Failed to get stream\n");
3140 CloseHandle(the_file);
3141 DeleteFileW(FilePath);
3142 break;
3144 WriteFile(the_file,buffer,sz,&write,NULL);
3145 } while (sz == 1024);
3147 HeapFree(GetProcessHeap(),0,FilePath);
3149 CloseHandle(the_file);
3150 msiobj_release(&row->hdr);
3152 MSI_ViewClose(view);
3153 msiobj_release(&view->hdr);
3155 next:
3156 /* ok there is a lot more done here but i need to figure out what */
3157 productcode = load_dynamic_property(package,szProductCode,&rc);
3158 if (!productcode)
3159 return rc;
3161 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
3162 if (rc != ERROR_SUCCESS)
3163 goto end;
3165 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
3166 if (rc != ERROR_SUCCESS)
3167 goto end;
3170 buffer = load_dynamic_property(package,szProductName,NULL);
3171 size = strlenW(buffer)*sizeof(WCHAR);
3172 RegSetValueExW(hukey,szProductName,0,REG_SZ, (BYTE *)buffer,size);
3173 HeapFree(GetProcessHeap(),0,buffer);
3175 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3176 size = sizeof(DWORD);
3177 langid = atoiW(buffer);
3178 RegSetValueExW(hukey,szLanguage,0,REG_DWORD, (BYTE *)&langid,size);
3179 HeapFree(GetProcessHeap(),0,buffer);
3181 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
3182 if (buffer)
3184 LPWSTR path;
3185 build_icon_path(package,buffer,&path);
3186 size = strlenW(path) * sizeof(WCHAR);
3187 RegSetValueExW(hukey,szProductIcon,0,REG_SZ, (BYTE *)path,size);
3189 HeapFree(GetProcessHeap(),0,buffer);
3191 buffer = load_dynamic_property(package,szProductVersion,NULL);
3192 if (buffer)
3194 DWORD verdword = build_version_dword(buffer);
3195 size = sizeof(DWORD);
3196 RegSetValueExW(hukey,szVersion,0,REG_DWORD, (BYTE *)&verdword,size);
3198 HeapFree(GetProcessHeap(),0,buffer);
3200 FIXME("Need to write more keys to the user registry\n");
3202 hDb= alloc_msihandle( &package->db->hdr );
3203 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
3204 MsiCloseHandle(hDb);
3205 if (rc == ERROR_SUCCESS)
3207 WCHAR guidbuffer[0x200];
3208 size = 0x200;
3209 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
3210 guidbuffer, &size);
3211 if (rc == ERROR_SUCCESS)
3213 WCHAR squashed[GUID_SIZE];
3214 /* for now we only care about the first guid */
3215 LPWSTR ptr = strchrW(guidbuffer,';');
3216 if (ptr) *ptr = 0;
3217 squash_guid(guidbuffer,squashed);
3218 size = strlenW(squashed)*sizeof(WCHAR);
3219 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
3220 size);
3222 else
3224 ERR("Unable to query Revision_Number... \n");
3225 rc = ERROR_SUCCESS;
3227 MsiCloseHandle(hSumInfo);
3229 else
3231 ERR("Unable to open Summary Information\n");
3232 rc = ERROR_SUCCESS;
3235 end:
3237 HeapFree(GetProcessHeap(),0,productcode);
3238 RegCloseKey(hkey);
3239 RegCloseKey(hukey);
3241 return rc;
3244 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
3246 UINT rc;
3247 MSIQUERY * view;
3248 MSIRECORD * row = 0;
3249 static const WCHAR ExecSeqQuery[] =
3250 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3251 '`','I','n','i','F','i','l','e','`',0};
3252 static const WCHAR szWindowsFolder[] =
3253 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3255 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3256 if (rc != ERROR_SUCCESS)
3258 TRACE("no IniFile table\n");
3259 return ERROR_SUCCESS;
3262 rc = MSI_ViewExecute(view, 0);
3263 if (rc != ERROR_SUCCESS)
3265 MSI_ViewClose(view);
3266 msiobj_release(&view->hdr);
3267 return rc;
3270 while (1)
3272 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
3273 LPWSTR deformated_section, deformated_key, deformated_value;
3274 LPWSTR folder, fullname = NULL;
3275 MSIRECORD * uirow;
3276 INT component_index,action;
3278 rc = MSI_ViewFetch(view,&row);
3279 if (rc != ERROR_SUCCESS)
3281 rc = ERROR_SUCCESS;
3282 break;
3285 component = MSI_RecordGetString(row, 8);
3286 component_index = get_loaded_component(package,component);
3288 if (!ACTION_VerifyComponentForAction(package, component_index,
3289 INSTALLSTATE_LOCAL))
3291 TRACE("Skipping ini file due to disabled component %s\n",
3292 debugstr_w(component));
3293 msiobj_release(&row->hdr);
3295 package->components[component_index].Action =
3296 package->components[component_index].Installed;
3298 continue;
3301 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3303 identifier = MSI_RecordGetString(row,1);
3304 filename = MSI_RecordGetString(row,2);
3305 dirproperty = MSI_RecordGetString(row,3);
3306 section = MSI_RecordGetString(row,4);
3307 key = MSI_RecordGetString(row,5);
3308 value = MSI_RecordGetString(row,6);
3309 action = MSI_RecordGetInteger(row,7);
3311 deformat_string(package,section,&deformated_section);
3312 deformat_string(package,key,&deformated_key);
3313 deformat_string(package,value,&deformated_value);
3315 if (dirproperty)
3317 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
3318 if (!folder)
3319 folder = load_dynamic_property(package,dirproperty,NULL);
3321 else
3322 folder = load_dynamic_property(package, szWindowsFolder, NULL);
3324 if (!folder)
3326 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
3327 goto cleanup;
3330 fullname = build_directory_name(3, folder, filename, NULL);
3332 if (action == 0)
3334 TRACE("Adding value %s to section %s in %s\n",
3335 debugstr_w(deformated_key), debugstr_w(deformated_section),
3336 debugstr_w(fullname));
3337 WritePrivateProfileStringW(deformated_section, deformated_key,
3338 deformated_value, fullname);
3340 else if (action == 1)
3342 WCHAR returned[10];
3343 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
3344 returned, 10, fullname);
3345 if (returned[0] == 0)
3347 TRACE("Adding value %s to section %s in %s\n",
3348 debugstr_w(deformated_key), debugstr_w(deformated_section),
3349 debugstr_w(fullname));
3351 WritePrivateProfileStringW(deformated_section, deformated_key,
3352 deformated_value, fullname);
3355 else if (action == 3)
3357 FIXME("Append to existing section not yet implemented\n");
3360 uirow = MSI_CreateRecord(4);
3361 MSI_RecordSetStringW(uirow,1,identifier);
3362 MSI_RecordSetStringW(uirow,2,deformated_section);
3363 MSI_RecordSetStringW(uirow,3,deformated_key);
3364 MSI_RecordSetStringW(uirow,4,deformated_value);
3365 ui_actiondata(package,szWriteIniValues,uirow);
3366 msiobj_release( &uirow->hdr );
3367 cleanup:
3368 HeapFree(GetProcessHeap(),0,fullname);
3369 HeapFree(GetProcessHeap(),0,folder);
3370 HeapFree(GetProcessHeap(),0,deformated_key);
3371 HeapFree(GetProcessHeap(),0,deformated_value);
3372 HeapFree(GetProcessHeap(),0,deformated_section);
3373 msiobj_release(&row->hdr);
3375 MSI_ViewClose(view);
3376 msiobj_release(&view->hdr);
3377 return rc;
3380 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
3382 UINT rc;
3383 MSIQUERY * view;
3384 MSIRECORD * row = 0;
3385 static const WCHAR ExecSeqQuery[] =
3386 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3387 '`','S','e','l','f','R','e','g','`',0};
3389 static const WCHAR ExeStr[] =
3390 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3391 static const WCHAR close[] = {'\"',0};
3392 STARTUPINFOW si;
3393 PROCESS_INFORMATION info;
3394 BOOL brc;
3396 memset(&si,0,sizeof(STARTUPINFOW));
3398 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3399 if (rc != ERROR_SUCCESS)
3401 TRACE("no SelfReg table\n");
3402 return ERROR_SUCCESS;
3405 rc = MSI_ViewExecute(view, 0);
3406 if (rc != ERROR_SUCCESS)
3408 MSI_ViewClose(view);
3409 msiobj_release(&view->hdr);
3410 return rc;
3413 while (1)
3415 LPCWSTR filename;
3416 LPWSTR FullName;
3417 INT index;
3418 DWORD len;
3420 rc = MSI_ViewFetch(view,&row);
3421 if (rc != ERROR_SUCCESS)
3423 rc = ERROR_SUCCESS;
3424 break;
3427 filename = MSI_RecordGetString(row,1);
3428 index = get_loaded_file(package,filename);
3430 if (index < 0)
3432 ERR("Unable to find file id %s\n",debugstr_w(filename));
3433 msiobj_release(&row->hdr);
3434 continue;
3437 len = strlenW(ExeStr);
3438 len += strlenW(package->files[index].TargetPath);
3439 len +=2;
3441 FullName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3442 strcpyW(FullName,ExeStr);
3443 strcatW(FullName,package->files[index].TargetPath);
3444 strcatW(FullName,close);
3446 TRACE("Registering %s\n",debugstr_w(FullName));
3447 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL,
3448 c_colon, &si, &info);
3450 if (brc)
3451 msi_dialog_check_messages(info.hProcess);
3453 HeapFree(GetProcessHeap(),0,FullName);
3454 msiobj_release(&row->hdr);
3456 MSI_ViewClose(view);
3457 msiobj_release(&view->hdr);
3458 return rc;
3461 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
3463 LPWSTR productcode;
3464 UINT rc;
3465 DWORD i;
3466 HKEY hkey=0;
3467 HKEY hukey=0;
3469 if (!package)
3470 return ERROR_INVALID_HANDLE;
3472 productcode = load_dynamic_property(package,szProductCode,&rc);
3473 if (!productcode)
3474 return rc;
3476 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
3477 if (rc != ERROR_SUCCESS)
3478 goto end;
3480 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
3481 if (rc != ERROR_SUCCESS)
3482 goto end;
3484 /* here the guids are base 85 encoded */
3485 for (i = 0; i < package->loaded_features; i++)
3487 LPWSTR data = NULL;
3488 GUID clsid;
3489 int j;
3490 INT size;
3491 BOOL absent = FALSE;
3493 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL) &&
3494 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_SOURCE) &&
3495 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_ADVERTISED))
3496 absent = TRUE;
3498 size = package->features[i].ComponentCount*21;
3499 size +=1;
3500 if (package->features[i].Feature_Parent[0])
3501 size += strlenW(package->features[i].Feature_Parent)+2;
3503 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
3505 data[0] = 0;
3506 for (j = 0; j < package->features[i].ComponentCount; j++)
3508 WCHAR buf[21];
3509 memset(buf,0,sizeof(buf));
3510 if (package->components
3511 [package->features[i].Components[j]].ComponentId[0]!=0)
3513 TRACE("From %s\n",debugstr_w(package->components
3514 [package->features[i].Components[j]].ComponentId));
3515 CLSIDFromString(package->components
3516 [package->features[i].Components[j]].ComponentId,
3517 &clsid);
3518 encode_base85_guid(&clsid,buf);
3519 TRACE("to %s\n",debugstr_w(buf));
3520 strcatW(data,buf);
3523 if (package->features[i].Feature_Parent[0])
3525 static const WCHAR sep[] = {'\2',0};
3526 strcatW(data,sep);
3527 strcatW(data,package->features[i].Feature_Parent);
3530 size = (strlenW(data)+1)*sizeof(WCHAR);
3531 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
3532 (LPSTR)data,size);
3533 HeapFree(GetProcessHeap(),0,data);
3535 if (!absent)
3537 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
3538 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
3539 (LPSTR)package->features[i].Feature_Parent,size);
3541 else
3543 size = (strlenW(package->features[i].Feature_Parent)+2)*
3544 sizeof(WCHAR);
3545 data = HeapAlloc(GetProcessHeap(),0,size);
3546 data[0] = 0x6;
3547 strcpyW(&data[1],package->features[i].Feature_Parent);
3548 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
3549 (LPSTR)data,size);
3550 HeapFree(GetProcessHeap(),0,data);
3554 end:
3555 RegCloseKey(hkey);
3556 RegCloseKey(hukey);
3557 HeapFree(GetProcessHeap(), 0, productcode);
3558 return rc;
3561 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
3563 HKEY hkey=0;
3564 LPWSTR buffer = NULL;
3565 LPWSTR productcode;
3566 UINT rc,i;
3567 DWORD size;
3568 static WCHAR szNONE[] = {0};
3569 static const WCHAR szWindowsInstaler[] =
3570 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3571 static const WCHAR szPropKeys[][80] =
3573 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3574 {'A','R','P','C','O','N','T','A','C','T',0},
3575 {'A','R','P','C','O','M','M','E','N','T','S',0},
3576 {'P','r','o','d','u','c','t','N','a','m','e',0},
3577 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3578 {'A','R','P','H','E','L','P','L','I','N','K',0},
3579 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3580 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3581 {'S','o','u','r','c','e','D','i','r',0},
3582 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3583 {'A','R','P','R','E','A','D','M','E',0},
3584 {'A','R','P','S','I','Z','E',0},
3585 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3586 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3587 {0},
3590 static const WCHAR szRegKeys[][80] =
3592 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3593 {'C','o','n','t','a','c','t',0},
3594 {'C','o','m','m','e','n','t','s',0},
3595 {'D','i','s','p','l','a','y','N','a','m','e',0},
3596 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3597 {'H','e','l','p','L','i','n','k',0},
3598 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3599 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3600 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3601 {'P','u','b','l','i','s','h','e','r',0},
3602 {'R','e','a','d','m','e',0},
3603 {'S','i','z','e',0},
3604 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3605 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3606 {0},
3609 static const WCHAR installerPathFmt[] = {
3610 '%','s','\\',
3611 'I','n','s','t','a','l','l','e','r','\\',0};
3612 static const WCHAR fmt[] = {
3613 '%','s','\\',
3614 'I','n','s','t','a','l','l','e','r','\\',
3615 '%','x','.','m','s','i',0};
3616 static const WCHAR szLocalPackage[]=
3617 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
3618 static const WCHAR szUpgradeCode[] =
3619 {'U','p','g','r','a','d','e','C','o','d','e',0};
3620 static const WCHAR modpath_fmt[] =
3621 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3622 static const WCHAR szModifyPath[] =
3623 {'M','o','d','i','f','y','P','a','t','h',0};
3624 static const WCHAR szUninstallString[] =
3625 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3626 static const WCHAR szEstimatedSize[] =
3627 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3628 static const WCHAR szInstallDate[] =
3629 {'I','n','s','t','a','l','l','D','a','t','e',0};
3630 static const WCHAR szLanguage[] =
3631 {'L','a','n','g','u','a','g','e',0};
3632 static const WCHAR szProductLanguage[] =
3633 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3634 static const WCHAR szProductVersion[] =
3635 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3636 static const WCHAR szVersion[] =
3637 {'V','e','r','s','i','o','n',0};
3638 static const WCHAR szVersionMajor[] =
3639 {'V','e','r','s','i','o','n','M','a','j','o','r',0};
3640 static const WCHAR szVersionMinor[] =
3641 {'V','e','r','s','i','o','n','M','i','n','o','r',0};
3643 SYSTEMTIME systime;
3644 static const WCHAR date_fmt[] = {'%','i','%','i','%','i',0};
3645 LPWSTR upgrade_code;
3646 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
3647 INT num,start;
3649 if (!package)
3650 return ERROR_INVALID_HANDLE;
3652 productcode = load_dynamic_property(package,szProductCode,&rc);
3653 if (!productcode)
3654 return rc;
3656 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
3657 if (rc != ERROR_SUCCESS)
3658 goto end;
3660 /* dump all the info i can grab */
3661 FIXME("Flesh out more information \n");
3663 i = 0;
3664 while (szPropKeys[i][0]!=0)
3666 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3667 if (rc != ERROR_SUCCESS)
3668 buffer = szNONE;
3669 size = strlenW(buffer)*sizeof(WCHAR);
3670 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
3671 HeapFree(GetProcessHeap(),0,buffer);
3672 i++;
3675 rc = 0x1;
3676 size = sizeof(rc);
3677 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
3679 /* copy the package locally */
3680 num = GetTickCount() & 0xffff;
3681 if (!num)
3682 num = 1;
3683 start = num;
3684 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
3685 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
3686 windir,num);
3689 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
3690 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
3691 if (handle != INVALID_HANDLE_VALUE)
3693 CloseHandle(handle);
3694 break;
3696 if (GetLastError() != ERROR_FILE_EXISTS &&
3697 GetLastError() != ERROR_SHARING_VIOLATION)
3698 break;
3699 if (!(++num & 0xffff)) num = 1;
3700 sprintfW(packagefile,fmt,num);
3701 } while (num != start);
3703 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
3704 create_full_pathW(path);
3705 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
3706 if (!CopyFileW(package->PackagePath,packagefile,FALSE))
3707 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3708 debugstr_w(package->PackagePath), debugstr_w(packagefile),
3709 GetLastError());
3710 size = strlenW(packagefile)*sizeof(WCHAR);
3711 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
3713 /* do ModifyPath and UninstallString */
3714 size = deformat_string(package,modpath_fmt,&buffer);
3715 RegSetValueExW(hkey,szModifyPath,0,REG_EXPAND_SZ,(LPSTR)buffer,size);
3716 RegSetValueExW(hkey,szUninstallString,0,REG_EXPAND_SZ,(LPSTR)buffer,size);
3717 HeapFree(GetProcessHeap(),0,buffer);
3719 FIXME("Write real Estimated Size when we have it\n");
3720 size = 0;
3721 RegSetValueExW(hkey,szEstimatedSize,0,REG_DWORD,(LPSTR)&size,sizeof(DWORD));
3723 GetLocalTime(&systime);
3724 size = 9*sizeof(WCHAR);
3725 buffer= HeapAlloc(GetProcessHeap(),0,size);
3726 sprintfW(buffer,date_fmt,systime.wYear,systime.wMonth,systime.wDay);
3727 size = strlenW(buffer)*sizeof(WCHAR);
3728 RegSetValueExW(hkey,szInstallDate,0,REG_SZ,(LPSTR)buffer,size);
3729 HeapFree(GetProcessHeap(),0,buffer);
3731 buffer = load_dynamic_property(package,szProductLanguage,NULL);
3732 size = atoiW(buffer);
3733 RegSetValueExW(hkey,szLanguage,0,REG_DWORD, (LPSTR)&size,sizeof(DWORD));
3734 HeapFree(GetProcessHeap(),1,buffer);
3736 buffer = load_dynamic_property(package,szProductVersion,NULL);
3737 if (buffer)
3739 DWORD verdword = build_version_dword(buffer);
3740 DWORD vermajor = verdword>>24;
3741 DWORD verminor = (verdword>>16)&0x00FF;
3742 size = sizeof(DWORD);
3743 RegSetValueExW(hkey,szVersion,0,REG_DWORD,(LPSTR)&verdword,size);
3744 RegSetValueExW(hkey,szVersionMajor,0,REG_DWORD,(LPSTR)&vermajor,size);
3745 RegSetValueExW(hkey,szVersionMinor,0,REG_DWORD,(LPSTR)&verminor,size);
3747 HeapFree(GetProcessHeap(),0,buffer);
3749 /* Handle Upgrade Codes */
3750 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
3751 if (upgrade_code)
3753 HKEY hkey2;
3754 WCHAR squashed[33];
3755 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3756 squash_guid(productcode,squashed);
3757 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3758 RegCloseKey(hkey2);
3759 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
3760 squash_guid(productcode,squashed);
3761 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
3762 RegCloseKey(hkey2);
3764 HeapFree(GetProcessHeap(),0,upgrade_code);
3767 end:
3768 HeapFree(GetProcessHeap(),0,productcode);
3769 RegCloseKey(hkey);
3771 return ERROR_SUCCESS;
3774 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
3776 UINT rc;
3778 if (!package)
3779 return ERROR_INVALID_HANDLE;
3781 rc = execute_script(package,INSTALL_SCRIPT);
3783 return rc;
3786 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
3788 UINT rc;
3790 if (!package)
3791 return ERROR_INVALID_HANDLE;
3793 /* turn off scheduleing */
3794 package->script->CurrentlyScripting= FALSE;
3796 /* first do the same as an InstallExecute */
3797 rc = ACTION_InstallExecute(package);
3798 if (rc != ERROR_SUCCESS)
3799 return rc;
3801 /* then handle Commit Actions */
3802 rc = execute_script(package,COMMIT_SCRIPT);
3804 return rc;
3807 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
3809 static const WCHAR RunOnce[] = {
3810 'S','o','f','t','w','a','r','e','\\',
3811 'M','i','c','r','o','s','o','f','t','\\',
3812 'W','i','n','d','o','w','s','\\',
3813 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3814 'R','u','n','O','n','c','e',0};
3815 static const WCHAR InstallRunOnce[] = {
3816 'S','o','f','t','w','a','r','e','\\',
3817 'M','i','c','r','o','s','o','f','t','\\',
3818 'W','i','n','d','o','w','s','\\',
3819 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3820 'I','n','s','t','a','l','l','e','r','\\',
3821 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3823 static const WCHAR msiexec_fmt[] = {
3824 '%','s',
3825 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3826 '\"','%','s','\"',0};
3827 static const WCHAR install_fmt[] = {
3828 '/','I',' ','\"','%','s','\"',' ',
3829 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3830 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3831 WCHAR buffer[256], sysdir[MAX_PATH];
3832 HKEY hkey,hukey;
3833 LPWSTR productcode;
3834 WCHAR squished_pc[100];
3835 INT rc;
3836 DWORD size;
3837 static const WCHAR szLUS[] = {
3838 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
3839 static const WCHAR szSourceList[] = {
3840 'S','o','u','r','c','e','L','i','s','t',0};
3841 static const WCHAR szPackageName[] = {
3842 'P','a','c','k','a','g','e','N','a','m','e',0};
3844 if (!package)
3845 return ERROR_INVALID_HANDLE;
3847 productcode = load_dynamic_property(package,szProductCode,&rc);
3848 if (!productcode)
3849 return rc;
3851 squash_guid(productcode,squished_pc);
3853 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
3854 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
3855 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
3856 squished_pc);
3858 size = strlenW(buffer)*sizeof(WCHAR);
3859 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
3860 RegCloseKey(hkey);
3862 TRACE("Reboot command %s\n",debugstr_w(buffer));
3864 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
3865 sprintfW(buffer,install_fmt,productcode,squished_pc);
3867 size = strlenW(buffer)*sizeof(WCHAR);
3868 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
3869 RegCloseKey(hkey);
3871 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
3872 if (rc == ERROR_SUCCESS)
3874 HKEY hukey2;
3875 LPWSTR buf;
3876 RegCreateKeyW(hukey, szSourceList, &hukey2);
3877 buf = load_dynamic_property(package,cszSourceDir,NULL);
3878 size = strlenW(buf)*sizeof(WCHAR);
3879 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
3880 HeapFree(GetProcessHeap(),0,buf);
3882 buf = strrchrW(package->PackagePath,'\\');
3883 if (buf)
3885 buf++;
3886 size = strlenW(buf)*sizeof(WCHAR);
3887 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
3890 RegCloseKey(hukey2);
3892 HeapFree(GetProcessHeap(),0,productcode);
3894 return ERROR_INSTALL_SUSPEND;
3897 UINT ACTION_ResolveSource(MSIPACKAGE* package)
3900 * we are currently doing what should be done here in the top level Install
3901 * however for Adminastrative and uninstalls this step will be needed
3903 return ERROR_SUCCESS;
3906 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
3908 static const WCHAR szProductID[]=
3909 {'P','r','o','d','u','c','t','I','D',0};
3910 HKEY hkey=0;
3911 LPWSTR buffer;
3912 LPWSTR productcode;
3913 LPWSTR productid;
3914 UINT rc,i;
3915 DWORD size;
3917 static const WCHAR szPropKeys[][80] =
3919 {'P','r','o','d','u','c','t','I','D',0},
3920 {'U','S','E','R','N','A','M','E',0},
3921 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3922 {0},
3925 static const WCHAR szRegKeys[][80] =
3927 {'P','r','o','d','u','c','t','I','D',0},
3928 {'R','e','g','O','w','n','e','r',0},
3929 {'R','e','g','C','o','m','p','a','n','y',0},
3930 {0},
3933 if (!package)
3934 return ERROR_INVALID_HANDLE;
3936 productid = load_dynamic_property(package,szProductID,&rc);
3937 if (!productid)
3938 return ERROR_SUCCESS;
3940 productcode = load_dynamic_property(package,szProductCode,&rc);
3941 if (!productcode)
3942 return rc;
3944 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
3945 if (rc != ERROR_SUCCESS)
3946 goto end;
3948 i = 0;
3949 while (szPropKeys[i][0]!=0)
3951 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
3952 if (rc == ERROR_SUCCESS)
3954 size = strlenW(buffer)*sizeof(WCHAR);
3955 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
3957 else
3958 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
3959 i++;
3962 end:
3963 HeapFree(GetProcessHeap(),0,productcode);
3964 HeapFree(GetProcessHeap(),0,productid);
3965 RegCloseKey(hkey);
3967 return ERROR_SUCCESS;
3971 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
3973 UINT rc;
3974 rc = ACTION_ProcessExecSequence(package,FALSE);
3975 return rc;
3980 * Code based off of code located here
3981 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3983 * Using string index 4 (full font name) instead of 1 (family name)
3985 static LPWSTR load_ttfname_from(LPCWSTR filename)
3987 HANDLE handle;
3988 LPWSTR ret = NULL;
3989 int i;
3991 typedef struct _tagTT_OFFSET_TABLE{
3992 USHORT uMajorVersion;
3993 USHORT uMinorVersion;
3994 USHORT uNumOfTables;
3995 USHORT uSearchRange;
3996 USHORT uEntrySelector;
3997 USHORT uRangeShift;
3998 }TT_OFFSET_TABLE;
4000 typedef struct _tagTT_TABLE_DIRECTORY{
4001 char szTag[4]; /* table name */
4002 ULONG uCheckSum; /* Check sum */
4003 ULONG uOffset; /* Offset from beginning of file */
4004 ULONG uLength; /* length of the table in bytes */
4005 }TT_TABLE_DIRECTORY;
4007 typedef struct _tagTT_NAME_TABLE_HEADER{
4008 USHORT uFSelector; /* format selector. Always 0 */
4009 USHORT uNRCount; /* Name Records count */
4010 USHORT uStorageOffset; /* Offset for strings storage,
4011 * from start of the table */
4012 }TT_NAME_TABLE_HEADER;
4014 typedef struct _tagTT_NAME_RECORD{
4015 USHORT uPlatformID;
4016 USHORT uEncodingID;
4017 USHORT uLanguageID;
4018 USHORT uNameID;
4019 USHORT uStringLength;
4020 USHORT uStringOffset; /* from start of storage area */
4021 }TT_NAME_RECORD;
4023 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
4024 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
4026 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
4027 FILE_ATTRIBUTE_NORMAL, 0 );
4028 if (handle != INVALID_HANDLE_VALUE)
4030 TT_TABLE_DIRECTORY tblDir;
4031 BOOL bFound = FALSE;
4032 TT_OFFSET_TABLE ttOffsetTable;
4034 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
4035 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
4036 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
4037 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
4039 if (ttOffsetTable.uMajorVersion != 1 ||
4040 ttOffsetTable.uMinorVersion != 0)
4041 return NULL;
4043 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
4045 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
4046 if (strncmp(tblDir.szTag,"name",4)==0)
4048 bFound = TRUE;
4049 tblDir.uLength = SWAPLONG(tblDir.uLength);
4050 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
4051 break;
4055 if (bFound)
4057 TT_NAME_TABLE_HEADER ttNTHeader;
4058 TT_NAME_RECORD ttRecord;
4060 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
4061 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
4062 NULL,NULL);
4064 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
4065 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
4066 bFound = FALSE;
4067 for(i=0; i<ttNTHeader.uNRCount; i++)
4069 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
4070 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
4071 /* 4 is the Full Font Name */
4072 if(ttRecord.uNameID == 4)
4074 int nPos;
4075 LPSTR buf;
4076 static LPCSTR tt = " (TrueType)";
4078 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
4079 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
4080 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
4081 SetFilePointer(handle, tblDir.uOffset +
4082 ttRecord.uStringOffset +
4083 ttNTHeader.uStorageOffset,
4084 NULL, FILE_BEGIN);
4085 buf = HeapAlloc(GetProcessHeap(), 0,
4086 ttRecord.uStringLength + 1 + strlen(tt));
4087 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
4088 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
4089 if (strlen(buf) > 0)
4091 strcat(buf,tt);
4092 ret = strdupAtoW(buf);
4093 HeapFree(GetProcessHeap(),0,buf);
4094 break;
4097 HeapFree(GetProcessHeap(),0,buf);
4098 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
4102 CloseHandle(handle);
4104 else
4105 ERR("Unable to open font file %s\n", debugstr_w(filename));
4107 TRACE("Returning fontname %s\n",debugstr_w(ret));
4108 return ret;
4111 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
4113 UINT rc;
4114 MSIQUERY * view;
4115 MSIRECORD * row = 0;
4116 static const WCHAR ExecSeqQuery[] =
4117 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4118 '`','F','o','n','t','`',0};
4119 static const WCHAR regfont1[] =
4120 {'S','o','f','t','w','a','r','e','\\',
4121 'M','i','c','r','o','s','o','f','t','\\',
4122 'W','i','n','d','o','w','s',' ','N','T','\\',
4123 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4124 'F','o','n','t','s',0};
4125 static const WCHAR regfont2[] =
4126 {'S','o','f','t','w','a','r','e','\\',
4127 'M','i','c','r','o','s','o','f','t','\\',
4128 'W','i','n','d','o','w','s','\\',
4129 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4130 'F','o','n','t','s',0};
4131 HKEY hkey1;
4132 HKEY hkey2;
4134 TRACE("%p\n", package);
4136 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4137 if (rc != ERROR_SUCCESS)
4139 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
4140 return ERROR_SUCCESS;
4143 rc = MSI_ViewExecute(view, 0);
4144 if (rc != ERROR_SUCCESS)
4146 MSI_ViewClose(view);
4147 msiobj_release(&view->hdr);
4148 TRACE("MSI_ViewExecute returned %d\n", rc);
4149 return ERROR_SUCCESS;
4152 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
4153 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
4155 while (1)
4157 LPWSTR name;
4158 LPCWSTR file;
4159 UINT index;
4160 DWORD size;
4162 rc = MSI_ViewFetch(view,&row);
4163 if (rc != ERROR_SUCCESS)
4165 rc = ERROR_SUCCESS;
4166 break;
4169 file = MSI_RecordGetString(row,1);
4170 index = get_loaded_file(package,file);
4171 if (index < 0)
4173 ERR("Unable to load file\n");
4174 continue;
4177 /* check to make sure that component is installed */
4178 if (!ACTION_VerifyComponentForAction(package,
4179 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
4181 TRACE("Skipping: Component not scheduled for install\n");
4183 msiobj_release(&row->hdr);
4185 continue;
4188 if (MSI_RecordIsNull(row,2))
4189 name = load_ttfname_from(package->files[index].TargetPath);
4190 else
4191 name = load_dynamic_stringW(row,2);
4193 if (name)
4195 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
4196 RegSetValueExW(hkey1,name,0,REG_SZ,
4197 (LPBYTE)package->files[index].FileName,size);
4198 RegSetValueExW(hkey2,name,0,REG_SZ,
4199 (LPBYTE)package->files[index].FileName,size);
4202 HeapFree(GetProcessHeap(),0,name);
4203 msiobj_release(&row->hdr);
4205 MSI_ViewClose(view);
4206 msiobj_release(&view->hdr);
4208 RegCloseKey(hkey1);
4209 RegCloseKey(hkey2);
4211 TRACE("returning %d\n", rc);
4212 return rc;
4215 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
4217 MSIPACKAGE *package = (MSIPACKAGE*)param;
4218 LPCWSTR compgroupid=NULL;
4219 LPCWSTR feature=NULL;
4220 LPCWSTR text = NULL;
4221 LPCWSTR qualifier = NULL;
4222 LPCWSTR component = NULL;
4223 LPWSTR advertise = NULL;
4224 LPWSTR output = NULL;
4225 HKEY hkey;
4226 UINT rc = ERROR_SUCCESS;
4227 UINT index;
4228 DWORD sz = 0;
4230 component = MSI_RecordGetString(rec,3);
4231 index = get_loaded_component(package,component);
4233 if (!ACTION_VerifyComponentForAction(package, index,
4234 INSTALLSTATE_LOCAL) &&
4235 !ACTION_VerifyComponentForAction(package, index,
4236 INSTALLSTATE_SOURCE) &&
4237 !ACTION_VerifyComponentForAction(package, index,
4238 INSTALLSTATE_ADVERTISED))
4240 TRACE("Skipping: Component %s not scheduled for install\n",
4241 debugstr_w(component));
4243 return ERROR_SUCCESS;
4246 compgroupid = MSI_RecordGetString(rec,1);
4248 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
4249 if (rc != ERROR_SUCCESS)
4250 goto end;
4252 text = MSI_RecordGetString(rec,4);
4253 qualifier = MSI_RecordGetString(rec,2);
4254 feature = MSI_RecordGetString(rec,5);
4256 advertise = create_component_advertise_string(package,
4257 &package->components[index], feature);
4259 sz = strlenW(advertise);
4261 if (text)
4262 sz += lstrlenW(text);
4264 sz+=3;
4265 sz *= sizeof(WCHAR);
4267 output = HeapAlloc(GetProcessHeap(),0,sz);
4268 memset(output,0,sz);
4269 strcpyW(output,advertise);
4271 if (text)
4272 strcatW(output,text);
4274 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
4275 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
4277 end:
4278 RegCloseKey(hkey);
4279 HeapFree(GetProcessHeap(),0,output);
4281 return rc;
4285 * At present I am ignorning the advertised components part of this and only
4286 * focusing on the qualified component sets
4288 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
4290 UINT rc;
4291 MSIQUERY * view;
4292 static const WCHAR ExecSeqQuery[] =
4293 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4294 '`','P','u','b','l','i','s','h',
4295 'C','o','m','p','o','n','e','n','t','`',0};
4297 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4298 if (rc != ERROR_SUCCESS)
4299 return ERROR_SUCCESS;
4301 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
4302 msiobj_release(&view->hdr);
4304 return rc;