2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004,2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
37 #include "wine/debug.h"
42 #include "wine/unicode.h"
46 #define REG_PROGRESS_VALUE 13200
47 #define COMPONENT_PROGRESS_VALUE 24000
49 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
54 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
);
55 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
);
56 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
);
61 typedef UINT (*STANDARDACTIONHANDLER
)(MSIPACKAGE
*);
63 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
);
64 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
);
65 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
);
66 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
);
67 static UINT
ACTION_FileCost(MSIPACKAGE
*package
);
68 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
);
69 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
);
70 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
);
71 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
);
72 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
);
73 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
);
74 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
);
75 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
);
76 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
);
77 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
);
78 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
);
79 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
);
80 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
);
81 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
);
82 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
);
83 static UINT
ACTION_ResolveSource(MSIPACKAGE
*package
);
84 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
);
85 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
);
86 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
);
89 * consts and values used
91 static const WCHAR c_colon
[] = {'C',':','\\',0};
93 const static WCHAR szCreateFolders
[] =
94 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
95 const static WCHAR szCostFinalize
[] =
96 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
97 const WCHAR szInstallFiles
[] =
98 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
99 const WCHAR szDuplicateFiles
[] =
100 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
101 const static WCHAR szWriteRegistryValues
[] =
102 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
103 'V','a','l','u','e','s',0};
104 const static WCHAR szCostInitialize
[] =
105 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
106 const static WCHAR szFileCost
[] =
107 {'F','i','l','e','C','o','s','t',0};
108 const static WCHAR szInstallInitialize
[] =
109 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
110 const static WCHAR szInstallValidate
[] =
111 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
112 const static WCHAR szLaunchConditions
[] =
113 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
114 const static WCHAR szProcessComponents
[] =
115 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
116 const static WCHAR szRegisterTypeLibraries
[] =
117 {'R','e','g','i','s','t','e','r','T','y','p','e',
118 'L','i','b','r','a','r','i','e','s',0};
119 const WCHAR szRegisterClassInfo
[] =
120 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
121 const WCHAR szRegisterProgIdInfo
[] =
122 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
123 const static WCHAR szCreateShortcuts
[] =
124 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
125 const static WCHAR szPublishProduct
[] =
126 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
127 const static WCHAR szWriteIniValues
[] =
128 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
129 const static WCHAR szSelfRegModules
[] =
130 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
131 const static WCHAR szPublishFeatures
[] =
132 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
133 const static WCHAR szRegisterProduct
[] =
134 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
135 const static WCHAR szInstallExecute
[] =
136 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
137 const static WCHAR szInstallExecuteAgain
[] =
138 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
139 'A','g','a','i','n',0};
140 const static WCHAR szInstallFinalize
[] =
141 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
142 const static WCHAR szForceReboot
[] =
143 {'F','o','r','c','e','R','e','b','o','o','t',0};
144 const static WCHAR szResolveSource
[] =
145 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
146 const WCHAR szAppSearch
[] =
147 {'A','p','p','S','e','a','r','c','h',0};
148 const static WCHAR szAllocateRegistrySpace
[] =
149 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
150 'S','p','a','c','e',0};
151 const static WCHAR szBindImage
[] =
152 {'B','i','n','d','I','m','a','g','e',0};
153 const static WCHAR szCCPSearch
[] =
154 {'C','C','P','S','e','a','r','c','h',0};
155 const static WCHAR szDeleteServices
[] =
156 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
157 const static WCHAR szDisableRollback
[] =
158 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
159 const static WCHAR szExecuteAction
[] =
160 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
161 const WCHAR szFindRelatedProducts
[] =
162 {'F','i','n','d','R','e','l','a','t','e','d',
163 'P','r','o','d','u','c','t','s',0};
164 const static WCHAR szInstallAdminPackage
[] =
165 {'I','n','s','t','a','l','l','A','d','m','i','n',
166 'P','a','c','k','a','g','e',0};
167 const static WCHAR szInstallSFPCatalogFile
[] =
168 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
170 const static WCHAR szIsolateComponents
[] =
171 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
172 const WCHAR szMigrateFeatureStates
[] =
173 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
174 'S','t','a','t','e','s',0};
175 const WCHAR szMoveFiles
[] =
176 {'M','o','v','e','F','i','l','e','s',0};
177 const static WCHAR szMsiPublishAssemblies
[] =
178 {'M','s','i','P','u','b','l','i','s','h',
179 'A','s','s','e','m','b','l','i','e','s',0};
180 const static WCHAR szMsiUnpublishAssemblies
[] =
181 {'M','s','i','U','n','p','u','b','l','i','s','h',
182 'A','s','s','e','m','b','l','i','e','s',0};
183 const static WCHAR szInstallODBC
[] =
184 {'I','n','s','t','a','l','l','O','D','B','C',0};
185 const static WCHAR szInstallServices
[] =
186 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
187 const WCHAR szPatchFiles
[] =
188 {'P','a','t','c','h','F','i','l','e','s',0};
189 const static WCHAR szPublishComponents
[] =
190 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
191 const static WCHAR szRegisterComPlus
[] =
192 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
193 const WCHAR szRegisterExtensionInfo
[] =
194 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
196 const static WCHAR szRegisterFonts
[] =
197 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
198 const WCHAR szRegisterMIMEInfo
[] =
199 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
200 const static WCHAR szRegisterUser
[] =
201 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
202 const WCHAR szRemoveDuplicateFiles
[] =
203 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
204 'F','i','l','e','s',0};
205 const static WCHAR szRemoveEnvironmentStrings
[] =
206 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
207 'S','t','r','i','n','g','s',0};
208 const WCHAR szRemoveExistingProducts
[] =
209 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
210 'P','r','o','d','u','c','t','s',0};
211 const WCHAR szRemoveFiles
[] =
212 {'R','e','m','o','v','e','F','i','l','e','s',0};
213 const static WCHAR szRemoveFolders
[] =
214 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
215 const static WCHAR szRemoveIniValues
[] =
216 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
217 const static WCHAR szRemoveODBC
[] =
218 {'R','e','m','o','v','e','O','D','B','C',0};
219 const static WCHAR szRemoveRegistryValues
[] =
220 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
221 'V','a','l','u','e','s',0};
222 const static WCHAR szRemoveShortcuts
[] =
223 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
224 const static WCHAR szRMCCPSearch
[] =
225 {'R','M','C','C','P','S','e','a','r','c','h',0};
226 const static WCHAR szScheduleReboot
[] =
227 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
228 const static WCHAR szSelfUnregModules
[] =
229 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
230 const static WCHAR szSetODBCFolders
[] =
231 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
232 const static WCHAR szStartServices
[] =
233 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
234 const static WCHAR szStopServices
[] =
235 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
236 const static WCHAR szUnpublishComponents
[] =
237 {'U','n','p','u','b','l','i','s','h',
238 'C','o','m','p','o','n','e','n','t','s',0};
239 const static WCHAR szUnpublishFeatures
[] =
240 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
241 const WCHAR szUnregisterClassInfo
[] =
242 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
244 const static WCHAR szUnregisterComPlus
[] =
245 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
246 const WCHAR szUnregisterExtensionInfo
[] =
247 {'U','n','r','e','g','i','s','t','e','r',
248 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
249 const static WCHAR szUnregisterFonts
[] =
250 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
251 const WCHAR szUnregisterMIMEInfo
[] =
252 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
253 const WCHAR szUnregisterProgIdInfo
[] =
254 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
256 const static WCHAR szUnregisterTypeLibraries
[] =
257 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
258 'L','i','b','r','a','r','i','e','s',0};
259 const static WCHAR szValidateProductID
[] =
260 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
261 const static WCHAR szWriteEnvironmentStrings
[] =
262 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
263 'S','t','r','i','n','g','s',0};
267 STANDARDACTIONHANDLER handler
;
270 static struct _actions StandardActions
[] = {
271 { szAllocateRegistrySpace
, NULL
},
272 { szAppSearch
, ACTION_AppSearch
},
273 { szBindImage
, NULL
},
274 { szCCPSearch
, NULL
},
275 { szCostFinalize
, ACTION_CostFinalize
},
276 { szCostInitialize
, ACTION_CostInitialize
},
277 { szCreateFolders
, ACTION_CreateFolders
},
278 { szCreateShortcuts
, ACTION_CreateShortcuts
},
279 { szDeleteServices
, NULL
},
280 { szDisableRollback
, NULL
},
281 { szDuplicateFiles
, ACTION_DuplicateFiles
},
282 { szExecuteAction
, ACTION_ExecuteAction
},
283 { szFileCost
, ACTION_FileCost
},
284 { szFindRelatedProducts
, ACTION_FindRelatedProducts
},
285 { szForceReboot
, ACTION_ForceReboot
},
286 { szInstallAdminPackage
, NULL
},
287 { szInstallExecute
, ACTION_InstallExecute
},
288 { szInstallExecuteAgain
, ACTION_InstallExecute
},
289 { szInstallFiles
, ACTION_InstallFiles
},
290 { szInstallFinalize
, ACTION_InstallFinalize
},
291 { szInstallInitialize
, ACTION_InstallInitialize
},
292 { szInstallSFPCatalogFile
, NULL
},
293 { szInstallValidate
, ACTION_InstallValidate
},
294 { szIsolateComponents
, NULL
},
295 { szLaunchConditions
, ACTION_LaunchConditions
},
296 { szMigrateFeatureStates
, NULL
},
297 { szMoveFiles
, NULL
},
298 { szMsiPublishAssemblies
, NULL
},
299 { szMsiUnpublishAssemblies
, NULL
},
300 { szInstallODBC
, NULL
},
301 { szInstallServices
, NULL
},
302 { szPatchFiles
, NULL
},
303 { szProcessComponents
, ACTION_ProcessComponents
},
304 { szPublishComponents
, ACTION_PublishComponents
},
305 { szPublishFeatures
, ACTION_PublishFeatures
},
306 { szPublishProduct
, ACTION_PublishProduct
},
307 { szRegisterClassInfo
, ACTION_RegisterClassInfo
},
308 { szRegisterComPlus
, NULL
},
309 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
},
310 { szRegisterFonts
, ACTION_RegisterFonts
},
311 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
},
312 { szRegisterProduct
, ACTION_RegisterProduct
},
313 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
},
314 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
},
315 { szRegisterUser
, ACTION_RegisterUser
},
316 { szRemoveDuplicateFiles
, NULL
},
317 { szRemoveEnvironmentStrings
, NULL
},
318 { szRemoveExistingProducts
, NULL
},
319 { szRemoveFiles
, NULL
},
320 { szRemoveFolders
, NULL
},
321 { szRemoveIniValues
, NULL
},
322 { szRemoveODBC
, NULL
},
323 { szRemoveRegistryValues
, NULL
},
324 { szRemoveShortcuts
, NULL
},
325 { szResolveSource
, ACTION_ResolveSource
},
326 { szRMCCPSearch
, NULL
},
327 { szScheduleReboot
, NULL
},
328 { szSelfRegModules
, ACTION_SelfRegModules
},
329 { szSelfUnregModules
, NULL
},
330 { szSetODBCFolders
, NULL
},
331 { szStartServices
, NULL
},
332 { szStopServices
, NULL
},
333 { szUnpublishComponents
, NULL
},
334 { szUnpublishFeatures
, NULL
},
335 { szUnregisterClassInfo
, NULL
},
336 { szUnregisterComPlus
, NULL
},
337 { szUnregisterExtensionInfo
, NULL
},
338 { szUnregisterFonts
, NULL
},
339 { szUnregisterMIMEInfo
, NULL
},
340 { szUnregisterProgIdInfo
, NULL
},
341 { szUnregisterTypeLibraries
, NULL
},
342 { szValidateProductID
, NULL
},
343 { szWriteEnvironmentStrings
, NULL
},
344 { szWriteIniValues
, ACTION_WriteIniValues
},
345 { szWriteRegistryValues
, ACTION_WriteRegistryValues
},
350 /********************************************************
352 ********************************************************/
354 static void ce_actiontext(MSIPACKAGE
* package
, LPCWSTR action
)
356 static const WCHAR szActionText
[] =
357 {'A','c','t','i','o','n','T','e','x','t',0};
360 row
= MSI_CreateRecord(1);
361 MSI_RecordSetStringW(row
,1,action
);
362 ControlEvent_FireSubscribedEvent(package
,szActionText
, row
);
363 msiobj_release(&row
->hdr
);
366 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
368 static const WCHAR template_s
[]=
369 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
371 static const WCHAR format
[] =
372 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
373 static const WCHAR Query_t
[] =
374 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
375 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
376 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
377 ' ','\'','%','s','\'',0};
384 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
386 row
= MSI_QueryGetRecord( package
->db
, Query_t
, action
);
390 ActionText
= MSI_RecordGetString(row
,2);
391 deformat_string(package
, ActionText
, &deformated
);
393 sprintfW(message
,template_s
,timet
,action
,deformated
);
394 ce_actiontext(package
, deformated
);
395 msiobj_release(&row
->hdr
);
397 row
= MSI_CreateRecord(1);
398 MSI_RecordSetStringW(row
,1,message
);
400 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
401 msiobj_release(&row
->hdr
);
402 HeapFree(GetProcessHeap(),0,deformated
);
405 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
409 static const WCHAR template_s
[]=
410 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
412 static const WCHAR template_e
[]=
413 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
414 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
416 static const WCHAR format
[] =
417 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
421 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
423 sprintfW(message
,template_s
,timet
,action
);
425 sprintfW(message
,template_e
,timet
,action
,rc
);
427 row
= MSI_CreateRecord(1);
428 MSI_RecordSetStringW(row
,1,message
);
430 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
431 msiobj_release(&row
->hdr
);
434 /****************************************************
435 * TOP level entry points
436 *****************************************************/
438 UINT
ACTION_DoTopLevelINSTALL(MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
439 LPCWSTR szCommandLine
, LPCWSTR msiFilePath
)
445 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
446 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
447 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
449 MSI_SetPropertyW(package
, szAction
, szInstall
);
451 package
->script
= HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT
));
452 memset(package
->script
,0,sizeof(MSISCRIPT
));
454 package
->script
->InWhatSequence
= SEQUENCE_INSTALL
;
456 package
->msiFilePath
= strdupW(msiFilePath
);
460 LPWSTR p
, check
, path
;
462 package
->PackagePath
= strdupW(szPackagePath
);
463 path
= strdupW(szPackagePath
);
464 p
= strrchrW(path
,'\\');
472 HeapFree(GetProcessHeap(),0,path
);
473 path
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
*sizeof(WCHAR
));
474 GetCurrentDirectoryW(MAX_PATH
,path
);
478 check
= msi_dup_property( package
, cszSourceDir
);
480 MSI_SetPropertyW(package
, cszSourceDir
, path
);
481 HeapFree(GetProcessHeap(), 0, check
);
482 HeapFree(GetProcessHeap(), 0, path
);
488 ptr
= (LPWSTR
)szCommandLine
;
495 TRACE("Looking at %s\n",debugstr_w(ptr
));
497 ptr2
= strchrW(ptr
,'=');
503 while (*ptr
== ' ') ptr
++;
505 prop
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
506 memcpy(prop
,ptr
,len
*sizeof(WCHAR
));
512 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
525 val
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
526 memcpy(val
,ptr2
,len
*sizeof(WCHAR
));
529 if (strlenW(prop
) > 0)
531 TRACE("Found commandline property (%s) = (%s)\n",
532 debugstr_w(prop
), debugstr_w(val
));
533 MSI_SetPropertyW(package
,prop
,val
);
535 HeapFree(GetProcessHeap(),0,val
);
536 HeapFree(GetProcessHeap(),0,prop
);
543 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
545 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
547 package
->script
->InWhatSequence
|= SEQUENCE_UI
;
548 rc
= ACTION_ProcessUISequence(package
);
550 if (rc
== ERROR_SUCCESS
)
552 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
553 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
557 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
560 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
564 /* install was halted but should be considered a success */
568 package
->script
->CurrentlyScripting
= FALSE
;
570 /* process the ending type action */
571 if (rc
== ERROR_SUCCESS
)
572 ACTION_PerformActionSequence(package
,-1,ui
);
573 else if (rc
== ERROR_INSTALL_USEREXIT
)
574 ACTION_PerformActionSequence(package
,-2,ui
);
575 else if (rc
== ERROR_INSTALL_SUSPEND
)
576 ACTION_PerformActionSequence(package
,-4,ui
);
578 ACTION_PerformActionSequence(package
,-3,ui
);
580 /* finish up running custom actions */
581 ACTION_FinishCustomActions(package
);
586 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
)
588 UINT rc
= ERROR_SUCCESS
;
590 static const WCHAR ExecSeqQuery
[] =
591 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
592 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
593 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
594 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
596 static const WCHAR UISeqQuery
[] =
597 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
598 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
599 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
600 ' ', '=',' ','%','i',0};
603 row
= MSI_QueryGetRecord(package
->db
, UISeqQuery
, seq
);
605 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, seq
);
609 LPCWSTR action
, cond
;
611 TRACE("Running the actions\n");
613 /* check conditions */
614 cond
= MSI_RecordGetString(row
,2);
617 /* this is a hack to skip errors in the condition code */
618 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
622 action
= MSI_RecordGetString(row
,1);
625 ERR("failed to fetch action\n");
626 rc
= ERROR_FUNCTION_FAILED
;
631 rc
= ACTION_PerformUIAction(package
,action
);
633 rc
= ACTION_PerformAction(package
,action
,FALSE
);
635 msiobj_release(&row
->hdr
);
646 } iterate_action_param
;
648 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
650 iterate_action_param
*iap
= (iterate_action_param
*)param
;
652 LPCWSTR cond
, action
;
654 action
= MSI_RecordGetString(row
,1);
657 ERR("Error is retrieving action name\n");
658 return ERROR_FUNCTION_FAILED
;
661 /* check conditions */
662 cond
= MSI_RecordGetString(row
,2);
665 /* this is a hack to skip errors in the condition code */
666 if (MSI_EvaluateConditionW(iap
->package
, cond
) == MSICONDITION_FALSE
)
668 TRACE("Skipping action: %s (condition is false)\n",
670 return ERROR_SUCCESS
;
675 rc
= ACTION_PerformUIAction(iap
->package
,action
);
677 rc
= ACTION_PerformAction(iap
->package
,action
,FALSE
);
679 msi_dialog_check_messages( NULL
);
681 if (iap
->package
->CurrentInstallState
!= ERROR_SUCCESS
)
682 rc
= iap
->package
->CurrentInstallState
;
684 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
687 if (rc
!= ERROR_SUCCESS
)
688 ERR("Execution halted due to error (%i)\n",rc
);
693 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
697 static const WCHAR ExecSeqQuery
[] =
698 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
699 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
700 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
701 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
702 'O','R','D','E','R',' ', 'B','Y',' ',
703 '`','S','e','q','u','e','n','c','e','`',0 };
705 static const WCHAR IVQuery
[] =
706 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
707 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
708 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
709 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
710 ' ','\'', 'I','n','s','t','a','l','l',
711 'V','a','l','i','d','a','t','e','\'', 0};
713 iterate_action_param iap
;
715 iap
.package
= package
;
718 if (package
->script
->ExecuteSequenceRun
)
720 TRACE("Execute Sequence already Run\n");
721 return ERROR_SUCCESS
;
724 package
->script
->ExecuteSequenceRun
= TRUE
;
726 /* get the sequence number */
729 row
= MSI_QueryGetRecord(package
->db
, IVQuery
);
731 return ERROR_FUNCTION_FAILED
;
732 seq
= MSI_RecordGetInteger(row
,1);
733 msiobj_release(&row
->hdr
);
736 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
737 if (rc
== ERROR_SUCCESS
)
739 TRACE("Running the actions\n");
741 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
742 msiobj_release(&view
->hdr
);
748 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
752 static const WCHAR ExecSeqQuery
[] =
753 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
754 '`','I','n','s','t','a','l','l',
755 'U','I','S','e','q','u','e','n','c','e','`',
756 ' ','W','H','E','R','E',' ',
757 '`','S','e','q','u','e','n','c','e','`',' ',
758 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
759 '`','S','e','q','u','e','n','c','e','`',0};
760 iterate_action_param iap
;
762 iap
.package
= package
;
765 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
767 if (rc
== ERROR_SUCCESS
)
769 TRACE("Running the actions \n");
771 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
772 msiobj_release(&view
->hdr
);
778 /********************************************************
779 * ACTION helper functions and functions that perform the actions
780 *******************************************************/
781 static BOOL
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
,
782 UINT
* rc
, BOOL force
)
788 if (!run
&& !package
->script
->CurrentlyScripting
)
793 if (strcmpW(action
,szInstallFinalize
) == 0 ||
794 strcmpW(action
,szInstallExecute
) == 0 ||
795 strcmpW(action
,szInstallExecuteAgain
) == 0)
800 while (StandardActions
[i
].action
!= NULL
)
802 if (strcmpW(StandardActions
[i
].action
, action
)==0)
806 ui_actioninfo(package
, action
, TRUE
, 0);
807 *rc
= schedule_action(package
,INSTALL_SCRIPT
,action
);
808 ui_actioninfo(package
, action
, FALSE
, *rc
);
812 ui_actionstart(package
, action
);
813 if (StandardActions
[i
].handler
)
815 *rc
= StandardActions
[i
].handler(package
);
819 FIXME("unhandled standard action %s\n",debugstr_w(action
));
831 static BOOL
ACTION_HandleCustomAction( MSIPACKAGE
* package
, LPCWSTR action
,
832 UINT
* rc
, BOOL force
)
837 arc
= ACTION_CustomAction(package
,action
, force
);
839 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
848 * A lot of actions are really important even if they don't do anything
849 * explicit... Lots of properties are set at the beginning of the installation
850 * CostFinalize does a bunch of work to translate the directories and such
852 * But until I get write access to the database that is hard, so I am going to
853 * hack it to see if I can get something to run.
855 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, BOOL force
)
857 UINT rc
= ERROR_SUCCESS
;
860 TRACE("Performing action (%s)\n",debugstr_w(action
));
862 handled
= ACTION_HandleStandardAction(package
, action
, &rc
, force
);
865 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, force
);
869 FIXME("unhandled msi action %s\n",debugstr_w(action
));
870 rc
= ERROR_FUNCTION_NOT_CALLED
;
876 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
)
878 UINT rc
= ERROR_SUCCESS
;
879 BOOL handled
= FALSE
;
881 TRACE("Performing action (%s)\n",debugstr_w(action
));
883 handled
= ACTION_HandleStandardAction(package
, action
, &rc
,TRUE
);
886 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, FALSE
);
888 if( !handled
&& ACTION_DialogBox(package
,action
) == ERROR_SUCCESS
)
893 FIXME("unhandled msi action %s\n",debugstr_w(action
));
894 rc
= ERROR_FUNCTION_NOT_CALLED
;
902 * Actual Action Handlers
905 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
907 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
913 dir
= MSI_RecordGetString(row
,1);
916 ERR("Unable to get folder id \n");
917 return ERROR_SUCCESS
;
920 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,&folder
);
923 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
924 return ERROR_SUCCESS
;
927 TRACE("Folder is %s\n",debugstr_w(full_path
));
930 uirow
= MSI_CreateRecord(1);
931 MSI_RecordSetStringW(uirow
,1,full_path
);
932 ui_actiondata(package
,szCreateFolders
,uirow
);
933 msiobj_release( &uirow
->hdr
);
935 if (folder
->State
== 0)
936 create_full_pathW(full_path
);
940 HeapFree(GetProcessHeap(),0,full_path
);
941 return ERROR_SUCCESS
;
946 * Also we cannot enable/disable components either, so for now I am just going
947 * to do all the directories for all the components.
949 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
951 static const WCHAR ExecSeqQuery
[] =
952 {'S','E','L','E','C','T',' ',
953 '`','D','i','r','e','c','t','o','r','y','_','`',
954 ' ','F','R','O','M',' ',
955 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
959 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
960 if (rc
!= ERROR_SUCCESS
)
961 return ERROR_SUCCESS
;
963 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
964 msiobj_release(&view
->hdr
);
969 static MSICOMPONENT
* load_component( MSIRECORD
* row
)
973 comp
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MSICOMPONENT
) );
977 /* fill in the data */
978 comp
->Component
= load_dynamic_stringW( row
, 1 );
980 TRACE("Loading Component %s\n", debugstr_w(comp
->Component
));
982 comp
->ComponentId
= load_dynamic_stringW( row
, 2 );
983 comp
->Directory
= load_dynamic_stringW( row
, 3 );
984 comp
->Attributes
= MSI_RecordGetInteger(row
,4);
985 comp
->Condition
= load_dynamic_stringW( row
, 5 );
986 comp
->KeyPath
= load_dynamic_stringW( row
, 6 );
988 comp
->Installed
= INSTALLSTATE_ABSENT
;
989 comp
->Action
= INSTALLSTATE_UNKNOWN
;
990 comp
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
992 comp
->Enabled
= TRUE
;
1002 static UINT
add_feature_component( MSIFEATURE
*feature
, MSICOMPONENT
*comp
)
1006 cl
= HeapAlloc( GetProcessHeap(), 0, sizeof (*cl
) );
1008 return ERROR_NOT_ENOUGH_MEMORY
;
1009 cl
->component
= comp
;
1010 list_add_tail( &feature
->Components
, &cl
->entry
);
1012 return ERROR_SUCCESS
;
1015 static UINT
iterate_component_check( MSIRECORD
*row
, LPVOID param
)
1017 _ilfs
* ilfs
= (_ilfs
*)param
;
1018 MSIPACKAGE
*package
= ilfs
->package
;
1019 MSIFEATURE
*feature
= ilfs
->feature
;
1022 comp
= load_component( row
);
1024 return ERROR_FUNCTION_FAILED
;
1026 list_add_tail( &package
->components
, &comp
->entry
);
1027 add_feature_component( feature
, comp
);
1029 TRACE("Loaded new component %p\n", comp
);
1031 return ERROR_SUCCESS
;
1034 static UINT
iterate_load_featurecomponents(MSIRECORD
*row
, LPVOID param
)
1036 _ilfs
* ilfs
= (_ilfs
*)param
;
1041 static const WCHAR Query
[] =
1042 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1043 '`','C','o','m','p','o','n','e','n','t','`',' ',
1044 'W','H','E','R','E',' ',
1045 '`','C','o','m','p','o','n','e','n','t','`',' ',
1046 '=','\'','%','s','\'',0};
1048 component
= MSI_RecordGetString(row
,1);
1050 /* check to see if the component is already loaded */
1051 comp
= get_loaded_component( ilfs
->package
, component
);
1054 TRACE("Component %s already loaded\n", debugstr_w(component
) );
1055 add_feature_component( ilfs
->feature
, comp
);
1056 return ERROR_SUCCESS
;
1059 rc
= MSI_OpenQuery(ilfs
->package
->db
, &view
, Query
, component
);
1060 if (rc
!= ERROR_SUCCESS
)
1061 return ERROR_SUCCESS
;
1063 rc
= MSI_IterateRecords(view
, NULL
, iterate_component_check
, ilfs
);
1064 msiobj_release( &view
->hdr
);
1066 return ERROR_SUCCESS
;
1069 static UINT
load_feature(MSIRECORD
* row
, LPVOID param
)
1071 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
1072 MSIFEATURE
* feature
;
1073 static const WCHAR Query1
[] =
1074 {'S','E','L','E','C','T',' ',
1075 '`','C','o','m','p','o','n','e','n','t','_','`',
1076 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1077 'C','o','m','p','o','n','e','n','t','s','`',' ',
1078 'W','H','E','R','E',' ',
1079 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1084 /* fill in the data */
1086 feature
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof (MSIFEATURE
) );
1088 return ERROR_NOT_ENOUGH_MEMORY
;
1090 list_init( &feature
->Components
);
1092 feature
->Feature
= load_dynamic_stringW( row
, 1 );
1094 TRACE("Loading feature %s\n",debugstr_w(feature
->Feature
));
1096 feature
->Feature_Parent
= load_dynamic_stringW( row
, 2 );
1097 feature
->Title
= load_dynamic_stringW( row
, 3 );
1098 feature
->Description
= load_dynamic_stringW( row
, 4 );
1100 if (!MSI_RecordIsNull(row
,5))
1101 feature
->Display
= MSI_RecordGetInteger(row
,5);
1103 feature
->Level
= MSI_RecordGetInteger(row
,6);
1104 feature
->Directory
= load_dynamic_stringW( row
, 7 );
1105 feature
->Attributes
= MSI_RecordGetInteger(row
,8);
1107 feature
->Installed
= INSTALLSTATE_ABSENT
;
1108 feature
->Action
= INSTALLSTATE_UNKNOWN
;
1109 feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1111 list_add_tail( &package
->features
, &feature
->entry
);
1113 /* load feature components */
1115 rc
= MSI_OpenQuery( package
->db
, &view
, Query1
, feature
->Feature
);
1116 if (rc
!= ERROR_SUCCESS
)
1117 return ERROR_SUCCESS
;
1119 ilfs
.package
= package
;
1120 ilfs
.feature
= feature
;
1122 MSI_IterateRecords(view
, NULL
, iterate_load_featurecomponents
, &ilfs
);
1123 msiobj_release(&view
->hdr
);
1125 return ERROR_SUCCESS
;
1128 static UINT
load_file(MSIRECORD
*row
, LPVOID param
)
1130 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
1134 /* fill in the data */
1136 file
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof (MSIFILE
) );
1138 return ERROR_NOT_ENOUGH_MEMORY
;
1140 file
->File
= load_dynamic_stringW( row
, 1 );
1142 component
= MSI_RecordGetString( row
, 2 );
1143 file
->Component
= get_loaded_component( package
, component
);
1145 if (!file
->Component
)
1146 ERR("Unfound Component %s\n",debugstr_w(component
));
1148 file
->FileName
= load_dynamic_stringW( row
, 3 );
1149 reduce_to_longfilename( file
->FileName
);
1151 file
->ShortName
= load_dynamic_stringW( row
, 3 );
1152 reduce_to_shortfilename( file
->ShortName
);
1154 file
->FileSize
= MSI_RecordGetInteger( row
, 4 );
1155 file
->Version
= load_dynamic_stringW( row
, 5 );
1156 file
->Language
= load_dynamic_stringW( row
, 6 );
1157 file
->Attributes
= MSI_RecordGetInteger( row
, 7 );
1158 file
->Sequence
= MSI_RecordGetInteger( row
, 8 );
1162 TRACE("File Loaded (%s)\n",debugstr_w(file
->File
));
1164 list_add_tail( &package
->files
, &file
->entry
);
1166 return ERROR_SUCCESS
;
1169 static UINT
load_all_files(MSIPACKAGE
*package
)
1173 static const WCHAR Query
[] =
1174 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1175 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1176 '`','S','e','q','u','e','n','c','e','`', 0};
1179 return ERROR_INVALID_HANDLE
;
1181 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1182 if (rc
!= ERROR_SUCCESS
)
1183 return ERROR_SUCCESS
;
1185 rc
= MSI_IterateRecords(view
, NULL
, load_file
, package
);
1186 msiobj_release(&view
->hdr
);
1188 return ERROR_SUCCESS
;
1193 * I am not doing any of the costing functionality yet.
1194 * Mostly looking at doing the Component and Feature loading
1196 * The native MSI does A LOT of modification to tables here. Mostly adding
1197 * a lot of temporary columns to the Feature and Component tables.
1199 * note: Native msi also tracks the short filename. But I am only going to
1200 * track the long ones. Also looking at this directory table
1201 * it appears that the directory table does not get the parents
1202 * resolved base on property only based on their entries in the
1205 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1209 static const WCHAR Query_all
[] =
1210 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1211 '`','F','e','a','t','u','r','e','`',0};
1212 static const WCHAR szCosting
[] =
1213 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1214 static const WCHAR szZero
[] = { '0', 0 };
1218 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1220 return ERROR_SUCCESS
;
1222 MSI_SetPropertyW(package
, szCosting
, szZero
);
1223 MSI_SetPropertyW(package
, cszRootDrive
, c_colon
);
1225 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1226 if (rc
!= ERROR_SUCCESS
)
1229 rc
= MSI_IterateRecords(view
, NULL
, load_feature
, package
);
1230 msiobj_release(&view
->hdr
);
1232 load_all_files(package
);
1234 return ERROR_SUCCESS
;
1237 static UINT
execute_script(MSIPACKAGE
*package
, UINT script
)
1240 UINT rc
= ERROR_SUCCESS
;
1242 TRACE("Executing Script %i\n",script
);
1244 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
1247 action
= package
->script
->Actions
[script
][i
];
1248 ui_actionstart(package
, action
);
1249 TRACE("Executing Action (%s)\n",debugstr_w(action
));
1250 rc
= ACTION_PerformAction(package
, action
, TRUE
);
1251 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
][i
]);
1252 if (rc
!= ERROR_SUCCESS
)
1255 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
]);
1257 package
->script
->ActionCount
[script
] = 0;
1258 package
->script
->Actions
[script
] = NULL
;
1262 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1264 return ERROR_SUCCESS
;
1268 static MSIFOLDER
*load_folder( MSIPACKAGE
*package
, LPCWSTR dir
)
1270 static const WCHAR Query
[] =
1271 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1272 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1273 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1274 ' ','=',' ','\'','%','s','\'',
1276 LPWSTR ptargetdir
, targetdir
, srcdir
;
1278 LPWSTR shortname
= NULL
;
1279 MSIRECORD
* row
= 0;
1282 TRACE("Looking for dir %s\n",debugstr_w(dir
));
1284 folder
= get_loaded_folder( package
, dir
);
1288 TRACE("Working to load %s\n",debugstr_w(dir
));
1290 folder
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof (MSIFOLDER
) );
1294 folder
->Directory
= strdupW(dir
);
1296 row
= MSI_QueryGetRecord(package
->db
, Query
, dir
);
1300 ptargetdir
= targetdir
= load_dynamic_stringW(row
,3);
1302 /* split src and target dir */
1303 if (strchrW(targetdir
,':'))
1305 srcdir
=strchrW(targetdir
,':');
1312 /* for now only pick long filename versions */
1313 if (strchrW(targetdir
,'|'))
1315 shortname
= targetdir
;
1316 targetdir
= strchrW(targetdir
,'|');
1320 /* for the sourcedir pick the short filename */
1321 if (srcdir
&& strchrW(srcdir
,'|'))
1323 LPWSTR p
= strchrW(srcdir
,'|');
1327 /* now check for root dirs */
1328 if (targetdir
[0] == '.' && targetdir
[1] == 0)
1333 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir
));
1334 HeapFree(GetProcessHeap(),0, folder
->TargetDefault
);
1335 folder
->TargetDefault
= strdupW(targetdir
);
1339 folder
->SourceDefault
= strdupW(srcdir
);
1341 folder
->SourceDefault
= strdupW(shortname
);
1343 folder
->SourceDefault
= strdupW(targetdir
);
1344 HeapFree(GetProcessHeap(), 0, ptargetdir
);
1345 TRACE(" SourceDefault = %s\n", debugstr_w( folder
->SourceDefault
));
1347 parent
= MSI_RecordGetString(row
,2);
1350 folder
->Parent
= load_folder( package
, parent
);
1351 if ( folder
->Parent
)
1352 TRACE("loaded parent %p %s\n", folder
->Parent
,
1353 debugstr_w(folder
->Parent
->Directory
));
1355 ERR("failed to load parent folder %s\n", debugstr_w(parent
));
1358 folder
->Property
= msi_dup_property( package
, dir
);
1360 msiobj_release(&row
->hdr
);
1362 list_add_tail( &package
->folders
, &folder
->entry
);
1364 TRACE("%s returning %p\n",debugstr_w(dir
),folder
);
1369 /* scan for and update current install states */
1370 static void ACTION_UpdateInstallStates(MSIPACKAGE
*package
)
1373 MSIFEATURE
*feature
;
1375 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1378 res
= MsiGetComponentPathW( package
->ProductCode
,
1379 comp
->ComponentId
, NULL
, NULL
);
1381 res
= INSTALLSTATE_ABSENT
;
1382 comp
->Installed
= res
;
1385 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1388 INSTALLSTATE res
= -10;
1390 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1392 comp
= cl
->component
;
1395 res
= comp
->Installed
;
1398 if (res
== comp
->Installed
)
1401 if (res
!= comp
->Installed
)
1402 res
= INSTALLSTATE_INCOMPLETE
;
1405 feature
->Installed
= res
;
1409 static BOOL
process_state_property (MSIPACKAGE
* package
, LPCWSTR property
,
1412 static const WCHAR all
[]={'A','L','L',0};
1414 MSIFEATURE
*feature
;
1416 override
= msi_dup_property( package
, property
);
1420 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1422 if (strcmpiW(override
,all
)==0)
1424 feature
->ActionRequest
= state
;
1425 feature
->Action
= state
;
1429 LPWSTR ptr
= override
;
1430 LPWSTR ptr2
= strchrW(override
,',');
1434 if ((ptr2
&& strncmpW(ptr
,feature
->Feature
, ptr2
-ptr
)==0)
1435 || (!ptr2
&& strcmpW(ptr
,feature
->Feature
)==0))
1437 feature
->ActionRequest
= state
;
1438 feature
->Action
= state
;
1444 ptr2
= strchrW(ptr
,',');
1451 HeapFree(GetProcessHeap(),0,override
);
1456 static UINT
SetFeatureStates(MSIPACKAGE
*package
)
1460 static const WCHAR szlevel
[] =
1461 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1462 static const WCHAR szAddLocal
[] =
1463 {'A','D','D','L','O','C','A','L',0};
1464 static const WCHAR szRemove
[] =
1465 {'R','E','M','O','V','E',0};
1466 BOOL override
= FALSE
;
1467 MSICOMPONENT
* component
;
1468 MSIFEATURE
*feature
;
1471 /* I do not know if this is where it should happen.. but */
1473 TRACE("Checking Install Level\n");
1475 level
= msi_dup_property( package
, szlevel
);
1478 install_level
= atoiW(level
);
1479 HeapFree(GetProcessHeap(), 0, level
);
1484 /* ok hereis the _real_ rub
1485 * all these activation/deactivation things happen in order and things
1486 * later on the list override things earlier on the list.
1487 * 1) INSTALLLEVEL processing
1497 * 11) FILEADDDEFAULT
1498 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1499 * ignored for all the features. seems strange, especially since it is not
1500 * documented anywhere, but it is how it works.
1502 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1503 * REMOVE are the big ones, since we don't handle administrative installs
1506 override
|= process_state_property(package
,szAddLocal
,INSTALLSTATE_LOCAL
);
1507 override
|= process_state_property(package
,szRemove
,INSTALLSTATE_ABSENT
);
1511 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1513 BOOL feature_state
= ((feature
->Level
> 0) &&
1514 (feature
->Level
<= install_level
));
1516 if ((feature_state
) && (feature
->Action
== INSTALLSTATE_UNKNOWN
))
1518 if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1520 feature
->ActionRequest
= INSTALLSTATE_SOURCE
;
1521 feature
->Action
= INSTALLSTATE_SOURCE
;
1523 else if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1525 feature
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1526 feature
->Action
= INSTALLSTATE_ADVERTISED
;
1530 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1531 feature
->Action
= INSTALLSTATE_LOCAL
;
1538 /* set the Preselected Property */
1539 static const WCHAR szPreselected
[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1540 static const WCHAR szOne
[] = { '1', 0 };
1542 MSI_SetPropertyW(package
,szPreselected
,szOne
);
1546 * now we want to enable or disable components base on feature
1549 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1553 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1554 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
1555 feature
->ActionRequest
);
1557 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1559 component
= cl
->component
;
1561 if (!component
->Enabled
)
1563 component
->Action
= INSTALLSTATE_UNKNOWN
;
1564 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1568 if (feature
->Action
== INSTALLSTATE_LOCAL
)
1570 component
->Action
= INSTALLSTATE_LOCAL
;
1571 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1573 else if (feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1575 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1576 (component
->Action
== INSTALLSTATE_ABSENT
) ||
1577 (component
->Action
== INSTALLSTATE_ADVERTISED
))
1580 component
->Action
= INSTALLSTATE_SOURCE
;
1581 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1584 else if (feature
->ActionRequest
== INSTALLSTATE_ADVERTISED
)
1586 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1587 (component
->Action
== INSTALLSTATE_ABSENT
))
1590 component
->Action
= INSTALLSTATE_ADVERTISED
;
1591 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1594 else if (feature
->ActionRequest
== INSTALLSTATE_ABSENT
)
1596 if (component
->Action
== INSTALLSTATE_UNKNOWN
)
1598 component
->Action
= INSTALLSTATE_ABSENT
;
1599 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
1606 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1608 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1609 debugstr_w(component
->Component
), component
->Installed
,
1610 component
->Action
, component
->ActionRequest
);
1614 return ERROR_SUCCESS
;
1617 static UINT
ITERATE_CostFinalizeDirectories(MSIRECORD
*row
, LPVOID param
)
1619 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1623 name
= MSI_RecordGetString(row
,1);
1625 /* This helper function now does ALL the work */
1626 TRACE("Dir %s ...\n",debugstr_w(name
));
1627 load_folder(package
,name
);
1628 path
= resolve_folder(package
,name
,FALSE
,TRUE
,NULL
);
1629 TRACE("resolves to %s\n",debugstr_w(path
));
1630 HeapFree( GetProcessHeap(), 0, path
);
1632 return ERROR_SUCCESS
;
1635 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1637 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1639 MSIFEATURE
*feature
;
1641 name
= MSI_RecordGetString( row
, 1 );
1643 feature
= get_loaded_feature( package
, name
);
1645 ERR("FAILED to find loaded feature %s\n",debugstr_w(name
));
1649 Condition
= MSI_RecordGetString(row
,3);
1651 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
1653 int level
= MSI_RecordGetInteger(row
,2);
1654 TRACE("Reseting feature %s to level %i\n", debugstr_w(name
), level
);
1655 feature
->Level
= level
;
1658 return ERROR_SUCCESS
;
1663 * A lot is done in this function aside from just the costing.
1664 * The costing needs to be implemented at some point but for now I am going
1665 * to focus on the directory building
1668 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
1670 static const WCHAR ExecSeqQuery
[] =
1671 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1672 '`','D','i','r','e','c','t','o','r','y','`',0};
1673 static const WCHAR ConditionQuery
[] =
1674 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1675 '`','C','o','n','d','i','t','i','o','n','`',0};
1676 static const WCHAR szCosting
[] =
1677 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1678 static const WCHAR szlevel
[] =
1679 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1680 static const WCHAR szOne
[] = { '1', 0 };
1689 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1691 return ERROR_SUCCESS
;
1693 TRACE("Building Directory properties\n");
1695 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1696 if (rc
== ERROR_SUCCESS
)
1698 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeDirectories
,
1700 msiobj_release(&view
->hdr
);
1703 TRACE("File calculations\n");
1705 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
1707 MSICOMPONENT
* comp
= file
->Component
;
1713 /* calculate target */
1714 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
1716 HeapFree(GetProcessHeap(),0,file
->TargetPath
);
1718 TRACE("file %s is named %s\n",
1719 debugstr_w(file
->File
),debugstr_w(file
->FileName
));
1721 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
1723 HeapFree(GetProcessHeap(),0,p
);
1725 TRACE("file %s resolves to %s\n",
1726 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
1728 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
1731 comp
->Cost
+= file
->FileSize
;
1741 static const WCHAR name
[] =
1743 static const WCHAR name_fmt
[] =
1744 {'%','u','.','%','u','.','%','u','.','%','u',0};
1745 WCHAR filever
[0x100];
1746 VS_FIXEDFILEINFO
*lpVer
;
1748 TRACE("Version comparison.. \n");
1749 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
1750 version
= HeapAlloc(GetProcessHeap(),0,versize
);
1751 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
1753 VerQueryValueW(version
, name
, (LPVOID
*)&lpVer
, &sz
);
1755 sprintfW(filever
,name_fmt
,
1756 HIWORD(lpVer
->dwFileVersionMS
),
1757 LOWORD(lpVer
->dwFileVersionMS
),
1758 HIWORD(lpVer
->dwFileVersionLS
),
1759 LOWORD(lpVer
->dwFileVersionLS
));
1761 TRACE("new %s old %s\n", debugstr_w(file
->Version
),
1762 debugstr_w(filever
));
1763 if (strcmpiW(filever
,file
->Version
)<0)
1766 FIXME("cost should be diff in size\n");
1767 comp
->Cost
+= file
->FileSize
;
1771 HeapFree(GetProcessHeap(),0,version
);
1777 TRACE("Evaluating Condition Table\n");
1779 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
1780 if (rc
== ERROR_SUCCESS
)
1782 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeConditions
,
1784 msiobj_release(&view
->hdr
);
1787 TRACE("Enabling or Disabling Components\n");
1788 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1790 if (comp
->Condition
)
1792 if (MSI_EvaluateConditionW(package
,
1793 comp
->Condition
) == MSICONDITION_FALSE
)
1795 TRACE("Disabling component %s\n", debugstr_w(comp
->Component
));
1796 comp
->Enabled
= FALSE
;
1801 MSI_SetPropertyW(package
,szCosting
,szOne
);
1802 /* set default run level if not set */
1803 level
= msi_dup_property( package
, szlevel
);
1805 MSI_SetPropertyW(package
,szlevel
, szOne
);
1806 HeapFree(GetProcessHeap(),0,level
);
1808 ACTION_UpdateInstallStates(package
);
1810 return SetFeatureStates(package
);
1813 /* OK this value is "interpreted" and then formatted based on the
1814 first few characters */
1815 static LPSTR
parse_value(MSIPACKAGE
*package
, LPCWSTR value
, DWORD
*type
,
1819 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
1825 LPWSTR deformated
= NULL
;
1828 deformat_string(package
, &value
[2], &deformated
);
1830 /* binary value type */
1834 *size
= (strlenW(ptr
)/2)+1;
1836 *size
= strlenW(ptr
)/2;
1838 data
= HeapAlloc(GetProcessHeap(),0,*size
);
1844 /* if uneven pad with a zero in front */
1850 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1852 TRACE("Uneven byte count\n");
1860 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1863 HeapFree(GetProcessHeap(),0,deformated
);
1865 TRACE("Data %li bytes(%i)\n",*size
,count
);
1872 deformat_string(package
, &value
[1], &deformated
);
1875 *size
= sizeof(DWORD
);
1876 data
= HeapAlloc(GetProcessHeap(),0,*size
);
1882 if ( (*p
< '0') || (*p
> '9') )
1888 if (deformated
[0] == '-')
1891 TRACE("DWORD %li\n",*(LPDWORD
)data
);
1893 HeapFree(GetProcessHeap(),0,deformated
);
1898 static const WCHAR szMulti
[] = {'[','~',']',0};
1907 *type
=REG_EXPAND_SZ
;
1915 if (strstrW(value
,szMulti
))
1916 *type
= REG_MULTI_SZ
;
1918 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
1923 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
1925 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1926 static const WCHAR szHCR
[] =
1927 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1928 'R','O','O','T','\\',0};
1929 static const WCHAR szHCU
[] =
1930 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1931 'U','S','E','R','\\',0};
1932 static const WCHAR szHLM
[] =
1933 {'H','K','E','Y','_','L','O','C','A','L','_',
1934 'M','A','C','H','I','N','E','\\',0};
1935 static const WCHAR szHU
[] =
1936 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1938 LPSTR value_data
= NULL
;
1939 HKEY root_key
, hkey
;
1942 LPCWSTR szRoot
, component
, name
, key
, value
;
1947 BOOL check_first
= FALSE
;
1950 ui_progress(package
,2,0,0,0);
1957 component
= MSI_RecordGetString(row
, 6);
1958 comp
= get_loaded_component(package
,component
);
1960 return ERROR_SUCCESS
;
1962 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
1964 TRACE("Skipping write due to disabled component %s\n",
1965 debugstr_w(component
));
1967 comp
->Action
= comp
->Installed
;
1969 return ERROR_SUCCESS
;
1972 comp
->Action
= INSTALLSTATE_LOCAL
;
1974 name
= MSI_RecordGetString(row
, 4);
1975 if( MSI_RecordIsNull(row
,5) && name
)
1977 /* null values can have special meanings */
1978 if (name
[0]=='-' && name
[1] == 0)
1979 return ERROR_SUCCESS
;
1980 else if ((name
[0]=='+' && name
[1] == 0) ||
1981 (name
[0] == '*' && name
[1] == 0))
1986 root
= MSI_RecordGetInteger(row
,2);
1987 key
= MSI_RecordGetString(row
, 3);
1989 /* get the root key */
1994 static const WCHAR szALLUSER
[] = {'A','L','L','U','S','E','R','S',0};
1995 LPWSTR all_users
= msi_dup_property( package
, szALLUSER
);
1996 if (all_users
&& all_users
[0] == '1')
1998 root_key
= HKEY_LOCAL_MACHINE
;
2003 root_key
= HKEY_CURRENT_USER
;
2006 HeapFree(GetProcessHeap(),0,all_users
);
2009 case 0: root_key
= HKEY_CLASSES_ROOT
;
2012 case 1: root_key
= HKEY_CURRENT_USER
;
2015 case 2: root_key
= HKEY_LOCAL_MACHINE
;
2018 case 3: root_key
= HKEY_USERS
;
2022 ERR("Unknown root %i\n",root
);
2028 return ERROR_SUCCESS
;
2030 deformat_string(package
, key
, &deformated
);
2031 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
2032 uikey
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(WCHAR
));
2033 strcpyW(uikey
,szRoot
);
2034 strcatW(uikey
,deformated
);
2036 if (RegCreateKeyW( root_key
, deformated
, &hkey
))
2038 ERR("Could not create key %s\n",debugstr_w(deformated
));
2039 HeapFree(GetProcessHeap(),0,deformated
);
2040 HeapFree(GetProcessHeap(),0,uikey
);
2041 return ERROR_SUCCESS
;
2043 HeapFree(GetProcessHeap(),0,deformated
);
2045 value
= MSI_RecordGetString(row
,5);
2047 value_data
= parse_value(package
, value
, &type
, &size
);
2050 static const WCHAR szEmpty
[] = {0};
2051 value_data
= (LPSTR
)strdupW(szEmpty
);
2056 deformat_string(package
, name
, &deformated
);
2058 /* get the double nulls to terminate SZ_MULTI */
2059 if (type
== REG_MULTI_SZ
)
2060 size
+=sizeof(WCHAR
);
2064 TRACE("Setting value %s of %s\n",debugstr_w(deformated
),
2066 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
)value_data
, size
);
2071 rc
= RegQueryValueExW(hkey
, deformated
, NULL
, NULL
, NULL
, &sz
);
2072 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
2074 TRACE("value %s of %s checked already exists\n",
2075 debugstr_w(deformated
), debugstr_w(uikey
));
2079 TRACE("Checked and setting value %s of %s\n",
2080 debugstr_w(deformated
), debugstr_w(uikey
));
2081 if (deformated
|| size
)
2082 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
) value_data
, size
);
2087 uirow
= MSI_CreateRecord(3);
2088 MSI_RecordSetStringW(uirow
,2,deformated
);
2089 MSI_RecordSetStringW(uirow
,1,uikey
);
2092 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2094 MSI_RecordSetStringW(uirow
,3,value
);
2096 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2097 msiobj_release( &uirow
->hdr
);
2099 HeapFree(GetProcessHeap(),0,value_data
);
2100 HeapFree(GetProcessHeap(),0,deformated
);
2101 HeapFree(GetProcessHeap(),0,uikey
);
2103 return ERROR_SUCCESS
;
2106 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2110 static const WCHAR ExecSeqQuery
[] =
2111 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2112 '`','R','e','g','i','s','t','r','y','`',0 };
2115 return ERROR_INVALID_HANDLE
;
2117 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2118 if (rc
!= ERROR_SUCCESS
)
2119 return ERROR_SUCCESS
;
2121 /* increment progress bar each time action data is sent */
2122 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
2124 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2126 msiobj_release(&view
->hdr
);
2130 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
2132 package
->script
->CurrentlyScripting
= TRUE
;
2134 return ERROR_SUCCESS
;
2138 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
2143 static const WCHAR q1
[]=
2144 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2145 '`','R','e','g','i','s','t','r','y','`',0};
2148 MSIRECORD
* row
= 0;
2149 MSIFEATURE
*feature
;
2152 TRACE(" InstallValidate \n");
2154 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
2155 if (rc
!= ERROR_SUCCESS
)
2156 return ERROR_SUCCESS
;
2158 rc
= MSI_ViewExecute(view
, 0);
2159 if (rc
!= ERROR_SUCCESS
)
2161 MSI_ViewClose(view
);
2162 msiobj_release(&view
->hdr
);
2167 rc
= MSI_ViewFetch(view
,&row
);
2168 if (rc
!= ERROR_SUCCESS
)
2175 msiobj_release(&row
->hdr
);
2177 MSI_ViewClose(view
);
2178 msiobj_release(&view
->hdr
);
2180 total
= total
+ progress
* REG_PROGRESS_VALUE
;
2181 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2183 total
+= COMPONENT_PROGRESS_VALUE
;
2185 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2187 total
+= file
->FileSize
;
2189 ui_progress(package
,0,total
,0,0);
2191 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2193 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2194 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
2195 feature
->ActionRequest
);
2198 return ERROR_SUCCESS
;
2201 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
2203 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2204 LPCWSTR cond
= NULL
;
2205 LPCWSTR message
= NULL
;
2206 static const WCHAR title
[]=
2207 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2209 cond
= MSI_RecordGetString(row
,1);
2211 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
2214 message
= MSI_RecordGetString(row
,2);
2215 deformat_string(package
,message
,&deformated
);
2216 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
2217 HeapFree(GetProcessHeap(),0,deformated
);
2218 return ERROR_FUNCTION_FAILED
;
2221 return ERROR_SUCCESS
;
2224 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
2227 MSIQUERY
* view
= NULL
;
2228 static const WCHAR ExecSeqQuery
[] =
2229 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2230 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2232 TRACE("Checking launch conditions\n");
2234 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2235 if (rc
!= ERROR_SUCCESS
)
2236 return ERROR_SUCCESS
;
2238 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
2239 msiobj_release(&view
->hdr
);
2244 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, MSICOMPONENT
*cmp
)
2248 return resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,NULL
);
2250 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
2252 MSIRECORD
* row
= 0;
2254 LPWSTR deformated
,buffer
,deformated_name
;
2256 static const WCHAR ExecSeqQuery
[] =
2257 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2258 '`','R','e','g','i','s','t','r','y','`',' ',
2259 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2260 ' ','=',' ' ,'\'','%','s','\'',0 };
2261 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
2262 static const WCHAR fmt2
[]=
2263 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2265 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
,cmp
->KeyPath
);
2269 root
= MSI_RecordGetInteger(row
,2);
2270 key
= MSI_RecordGetString(row
, 3);
2271 name
= MSI_RecordGetString(row
, 4);
2272 deformat_string(package
, key
, &deformated
);
2273 deformat_string(package
, name
, &deformated_name
);
2275 len
= strlenW(deformated
) + 6;
2276 if (deformated_name
)
2277 len
+=strlenW(deformated_name
);
2279 buffer
= HeapAlloc(GetProcessHeap(),0, len
*sizeof(WCHAR
));
2281 if (deformated_name
)
2282 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
2284 sprintfW(buffer
,fmt
,root
,deformated
);
2286 HeapFree(GetProcessHeap(),0,deformated
);
2287 HeapFree(GetProcessHeap(),0,deformated_name
);
2288 msiobj_release(&row
->hdr
);
2292 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2294 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2299 MSIFILE
*file
= get_loaded_file( package
, cmp
->KeyPath
);
2302 return strdupW( file
->TargetPath
);
2307 static HKEY
openSharedDLLsKey(void)
2310 static const WCHAR path
[] =
2311 {'S','o','f','t','w','a','r','e','\\',
2312 'M','i','c','r','o','s','o','f','t','\\',
2313 'W','i','n','d','o','w','s','\\',
2314 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2315 'S','h','a','r','e','d','D','L','L','s',0};
2317 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
2321 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
2326 DWORD sz
= sizeof(count
);
2329 hkey
= openSharedDLLsKey();
2330 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
2331 if (rc
!= ERROR_SUCCESS
)
2337 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
2341 hkey
= openSharedDLLsKey();
2343 msi_reg_set_val_dword( hkey
, path
, count
);
2345 RegDeleteValueW(hkey
,path
);
2351 * Return TRUE if the count should be written out and FALSE if not
2353 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, MSICOMPONENT
*comp
)
2355 MSIFEATURE
*feature
;
2359 /* only refcount DLLs */
2360 if (comp
->KeyPath
== NULL
||
2361 comp
->Attributes
& msidbComponentAttributesRegistryKeyPath
||
2362 comp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2366 count
= ACTION_GetSharedDLLsCount( comp
->FullKeypath
);
2367 write
= (count
> 0);
2369 if (comp
->Attributes
& msidbComponentAttributesSharedDllRefCount
)
2373 /* increment counts */
2374 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2378 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_LOCAL
))
2381 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
2383 if ( cl
->component
== comp
)
2388 /* decrement counts */
2389 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2393 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_ABSENT
))
2396 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
2398 if ( cl
->component
== comp
)
2403 /* ref count all the files in the component */
2408 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2410 if (file
->Component
== comp
)
2411 ACTION_WriteSharedDLLsCount( file
->TargetPath
, count
);
2415 /* add a count for permenent */
2416 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
2419 comp
->RefCount
= count
;
2422 ACTION_WriteSharedDLLsCount( comp
->FullKeypath
, comp
->RefCount
);
2426 * Ok further analysis makes me think that this work is
2427 * actually done in the PublishComponents and PublishFeatures
2428 * step, and not here. It appears like the keypath and all that is
2429 * resolved in this step, however actually written in the Publish steps.
2430 * But we will leave it here for now because it is unclear
2432 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
2434 WCHAR squished_pc
[GUID_SIZE
];
2435 WCHAR squished_cc
[GUID_SIZE
];
2438 HKEY hkey
=0,hkey2
=0;
2441 return ERROR_INVALID_HANDLE
;
2443 /* writes the Component and Features values to the registry */
2445 rc
= MSIREG_OpenComponents(&hkey
);
2446 if (rc
!= ERROR_SUCCESS
)
2449 squash_guid(package
->ProductCode
,squished_pc
);
2450 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
2452 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2454 ui_progress(package
,2,0,0,0);
2455 if (comp
->ComponentId
)
2457 WCHAR
*keypath
= NULL
;
2460 squash_guid(comp
->ComponentId
,squished_cc
);
2462 keypath
= resolve_keypath( package
, comp
);
2463 comp
->FullKeypath
= keypath
;
2465 /* do the refcounting */
2466 ACTION_RefCountComponent( package
, comp
);
2468 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2469 debugstr_w(comp
->Component
),
2470 debugstr_w(squished_cc
),
2471 debugstr_w(comp
->FullKeypath
),
2474 * Write the keypath out if the component is to be registered
2475 * and delete the key if the component is to be deregistered
2477 if (ACTION_VerifyComponentForAction(package
, comp
,
2478 INSTALLSTATE_LOCAL
))
2480 rc
= RegCreateKeyW(hkey
,squished_cc
,&hkey2
);
2481 if (rc
!= ERROR_SUCCESS
)
2486 msi_reg_set_val_str( hkey2
, squished_pc
, keypath
);
2488 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
2490 static const WCHAR szPermKey
[] =
2491 { '0','0','0','0','0','0','0','0','0','0','0','0',
2492 '0','0','0','0','0','0','0','0','0','0','0','0',
2493 '0','0','0','0','0','0','0','0',0};
2495 msi_reg_set_val_str( hkey2
, szPermKey
, keypath
);
2501 uirow
= MSI_CreateRecord(3);
2502 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
2503 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
2504 MSI_RecordSetStringW(uirow
,3,keypath
);
2505 ui_actiondata(package
,szProcessComponents
,uirow
);
2506 msiobj_release( &uirow
->hdr
);
2509 else if (ACTION_VerifyComponentForAction(package
, comp
,
2510 INSTALLSTATE_ABSENT
))
2514 rc
= RegOpenKeyW(hkey
,squished_cc
,&hkey2
);
2515 if (rc
!= ERROR_SUCCESS
)
2518 RegDeleteValueW(hkey2
,squished_pc
);
2520 /* if the key is empty delete it */
2521 res
= RegEnumKeyExW(hkey2
,0,NULL
,0,0,NULL
,0,NULL
);
2523 if (res
== ERROR_NO_MORE_ITEMS
)
2524 RegDeleteKeyW(hkey
,squished_cc
);
2527 uirow
= MSI_CreateRecord(2);
2528 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
2529 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
2530 ui_actiondata(package
,szProcessComponents
,uirow
);
2531 msiobj_release( &uirow
->hdr
);
2548 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
2549 LPWSTR lpszName
, LONG_PTR lParam
)
2552 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
2553 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
2557 if (!IS_INTRESOURCE(lpszName
))
2559 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
2563 sz
= strlenW(tl_struct
->source
)+4;
2564 sz
*= sizeof(WCHAR
);
2566 if ((INT
)lpszName
== 1)
2567 tl_struct
->path
= strdupW(tl_struct
->source
);
2570 tl_struct
->path
= HeapAlloc(GetProcessHeap(),0,sz
);
2571 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
2574 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
2575 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
2576 if (!SUCCEEDED(res
))
2578 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
2579 tl_struct
->path
= NULL
;
2584 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
2585 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
2587 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2591 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
2592 tl_struct
->path
= NULL
;
2594 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2595 ITypeLib_Release(tl_struct
->ptLib
);
2600 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
2602 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2606 typelib_struct tl_struct
;
2608 static const WCHAR szTYPELIB
[] = {'T','Y','P','E','L','I','B',0};
2610 component
= MSI_RecordGetString(row
,3);
2611 comp
= get_loaded_component(package
,component
);
2613 return ERROR_SUCCESS
;
2615 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
2617 TRACE("Skipping typelib reg due to disabled component\n");
2619 comp
->Action
= comp
->Installed
;
2621 return ERROR_SUCCESS
;
2624 comp
->Action
= INSTALLSTATE_LOCAL
;
2626 file
= get_loaded_file( package
, comp
->KeyPath
);
2628 return ERROR_SUCCESS
;
2630 module
= LoadLibraryExW( file
->TargetPath
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
2634 guid
= load_dynamic_stringW(row
,1);
2635 CLSIDFromString(guid
, &tl_struct
.clsid
);
2636 HeapFree(GetProcessHeap(),0,guid
);
2637 tl_struct
.source
= strdupW( file
->TargetPath
);
2638 tl_struct
.path
= NULL
;
2640 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
2641 (LONG_PTR
)&tl_struct
);
2643 if (tl_struct
.path
!= NULL
)
2649 helpid
= MSI_RecordGetString(row
,6);
2652 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,NULL
);
2653 res
= RegisterTypeLib(tl_struct
.ptLib
,tl_struct
.path
,help
);
2654 HeapFree(GetProcessHeap(),0,help
);
2656 if (!SUCCEEDED(res
))
2657 ERR("Failed to register type library %s\n",
2658 debugstr_w(tl_struct
.path
));
2661 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
2663 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
2666 ITypeLib_Release(tl_struct
.ptLib
);
2667 HeapFree(GetProcessHeap(),0,tl_struct
.path
);
2670 ERR("Failed to load type library %s\n",
2671 debugstr_w(tl_struct
.source
));
2673 FreeLibrary(module
);
2674 HeapFree(GetProcessHeap(),0,tl_struct
.source
);
2677 ERR("Could not load file! %s\n", debugstr_w(file
->TargetPath
));
2679 return ERROR_SUCCESS
;
2682 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
2685 * OK this is a bit confusing.. I am given a _Component key and I believe
2686 * that the file that is being registered as a type library is the "key file
2687 * of that component" which I interpret to mean "The file in the KeyPath of
2692 static const WCHAR Query
[] =
2693 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2694 '`','T','y','p','e','L','i','b','`',0};
2697 return ERROR_INVALID_HANDLE
;
2699 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2700 if (rc
!= ERROR_SUCCESS
)
2701 return ERROR_SUCCESS
;
2703 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
2704 msiobj_release(&view
->hdr
);
2708 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
2710 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
2711 LPWSTR target_file
, target_folder
;
2713 WCHAR filename
[0x100];
2716 static const WCHAR szlnk
[]={'.','l','n','k',0};
2721 buffer
= MSI_RecordGetString(row
,4);
2722 comp
= get_loaded_component(package
,buffer
);
2724 return ERROR_SUCCESS
;
2726 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
2728 TRACE("Skipping shortcut creation due to disabled component\n");
2730 comp
->Action
= comp
->Installed
;
2732 return ERROR_SUCCESS
;
2735 comp
->Action
= INSTALLSTATE_LOCAL
;
2737 ui_actiondata(package
,szCreateShortcuts
,row
);
2739 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
2740 &IID_IShellLinkW
, (LPVOID
*) &sl
);
2744 ERR("Is IID_IShellLink\n");
2745 return ERROR_SUCCESS
;
2748 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
2751 ERR("Is IID_IPersistFile\n");
2752 return ERROR_SUCCESS
;
2755 buffer
= MSI_RecordGetString(row
,2);
2756 target_folder
= resolve_folder(package
, buffer
,FALSE
,FALSE
,NULL
);
2758 /* may be needed because of a bug somehwere else */
2759 create_full_pathW(target_folder
);
2762 MSI_RecordGetStringW(row
,3,filename
,&sz
);
2763 reduce_to_longfilename(filename
);
2764 if (!strchrW(filename
,'.') || strcmpiW(strchrW(filename
,'.'),szlnk
))
2765 strcatW(filename
,szlnk
);
2766 target_file
= build_directory_name(2, target_folder
, filename
);
2767 HeapFree(GetProcessHeap(),0,target_folder
);
2769 buffer
= MSI_RecordGetString(row
,5);
2770 if (strchrW(buffer
,'['))
2773 deformat_string(package
,buffer
,&deformated
);
2774 IShellLinkW_SetPath(sl
,deformated
);
2775 HeapFree(GetProcessHeap(),0,deformated
);
2780 FIXME("poorly handled shortcut format, advertised shortcut\n");
2781 keypath
= strdupW( comp
->FullKeypath
);
2782 IShellLinkW_SetPath(sl
,keypath
);
2783 HeapFree(GetProcessHeap(),0,keypath
);
2786 if (!MSI_RecordIsNull(row
,6))
2789 buffer
= MSI_RecordGetString(row
,6);
2790 deformat_string(package
,buffer
,&deformated
);
2791 IShellLinkW_SetArguments(sl
,deformated
);
2792 HeapFree(GetProcessHeap(),0,deformated
);
2795 if (!MSI_RecordIsNull(row
,7))
2797 buffer
= MSI_RecordGetString(row
,7);
2798 IShellLinkW_SetDescription(sl
,buffer
);
2801 if (!MSI_RecordIsNull(row
,8))
2802 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
2804 if (!MSI_RecordIsNull(row
,9))
2809 buffer
= MSI_RecordGetString(row
,9);
2811 build_icon_path(package
,buffer
,&Path
);
2812 index
= MSI_RecordGetInteger(row
,10);
2814 IShellLinkW_SetIconLocation(sl
,Path
,index
);
2815 HeapFree(GetProcessHeap(),0,Path
);
2818 if (!MSI_RecordIsNull(row
,11))
2819 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
2821 if (!MSI_RecordIsNull(row
,12))
2824 buffer
= MSI_RecordGetString(row
,12);
2825 Path
= resolve_folder(package
, buffer
, FALSE
, FALSE
, NULL
);
2826 IShellLinkW_SetWorkingDirectory(sl
,Path
);
2827 HeapFree(GetProcessHeap(), 0, Path
);
2830 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
2831 IPersistFile_Save(pf
,target_file
,FALSE
);
2833 HeapFree(GetProcessHeap(),0,target_file
);
2835 IPersistFile_Release( pf
);
2836 IShellLinkW_Release( sl
);
2838 return ERROR_SUCCESS
;
2841 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
2846 static const WCHAR Query
[] =
2847 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2848 '`','S','h','o','r','t','c','u','t','`',0};
2851 return ERROR_INVALID_HANDLE
;
2853 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2854 if (rc
!= ERROR_SUCCESS
)
2855 return ERROR_SUCCESS
;
2857 res
= CoInitialize( NULL
);
2860 ERR("CoInitialize failed\n");
2861 return ERROR_FUNCTION_FAILED
;
2864 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
2865 msiobj_release(&view
->hdr
);
2872 static UINT
ITERATE_PublishProduct(MSIRECORD
*row
, LPVOID param
)
2874 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2876 LPWSTR FilePath
=NULL
;
2877 LPCWSTR FileName
=NULL
;
2882 FileName
= MSI_RecordGetString(row
,1);
2885 ERR("Unable to get FileName\n");
2886 return ERROR_SUCCESS
;
2889 build_icon_path(package
,FileName
,&FilePath
);
2891 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
2893 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2894 FILE_ATTRIBUTE_NORMAL
, NULL
);
2896 if (the_file
== INVALID_HANDLE_VALUE
)
2898 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
2899 HeapFree(GetProcessHeap(),0,FilePath
);
2900 return ERROR_SUCCESS
;
2907 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
2908 if (rc
!= ERROR_SUCCESS
)
2910 ERR("Failed to get stream\n");
2911 CloseHandle(the_file
);
2912 DeleteFileW(FilePath
);
2915 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
2916 } while (sz
== 1024);
2918 HeapFree(GetProcessHeap(),0,FilePath
);
2920 CloseHandle(the_file
);
2921 return ERROR_SUCCESS
;
2925 * 99% of the work done here is only done for
2926 * advertised installs. However this is where the
2927 * Icon table is processed and written out
2928 * so that is what I am going to do here.
2930 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
2934 static const WCHAR Query
[]=
2935 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2936 '`','I','c','o','n','`',0};
2937 /* for registry stuff */
2940 static const WCHAR szProductLanguage
[] =
2941 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
2942 static const WCHAR szARPProductIcon
[] =
2943 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
2944 static const WCHAR szProductVersion
[] =
2945 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
2949 MSIHANDLE hDb
, hSumInfo
;
2952 return ERROR_INVALID_HANDLE
;
2954 /* write out icon files */
2956 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2957 if (rc
== ERROR_SUCCESS
)
2959 MSI_IterateRecords(view
, NULL
, ITERATE_PublishProduct
, package
);
2960 msiobj_release(&view
->hdr
);
2963 /* ok there is a lot more done here but i need to figure out what */
2965 rc
= MSIREG_OpenProductsKey(package
->ProductCode
,&hkey
,TRUE
);
2966 if (rc
!= ERROR_SUCCESS
)
2969 rc
= MSIREG_OpenUserProductsKey(package
->ProductCode
,&hukey
,TRUE
);
2970 if (rc
!= ERROR_SUCCESS
)
2974 buffer
= msi_dup_property( package
, INSTALLPROPERTY_PRODUCTNAMEW
);
2975 msi_reg_set_val_str( hukey
, INSTALLPROPERTY_PRODUCTNAMEW
, buffer
);
2976 HeapFree(GetProcessHeap(),0,buffer
);
2978 buffer
= msi_dup_property( package
, szProductLanguage
);
2979 langid
= atoiW(buffer
);
2980 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
2981 HeapFree(GetProcessHeap(),0,buffer
);
2983 buffer
= msi_dup_property( package
, szARPProductIcon
);
2987 build_icon_path(package
,buffer
,&path
);
2988 msi_reg_set_val_str( hukey
, INSTALLPROPERTY_PRODUCTICONW
, path
);
2990 HeapFree(GetProcessHeap(),0,buffer
);
2992 buffer
= msi_dup_property( package
, szProductVersion
);
2995 DWORD verdword
= build_version_dword(buffer
);
2996 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
2998 HeapFree(GetProcessHeap(),0,buffer
);
3000 FIXME("Need to write more keys to the user registry\n");
3002 hDb
= alloc_msihandle( &package
->db
->hdr
);
3003 rc
= MsiGetSummaryInformationW(hDb
, NULL
, 0, &hSumInfo
);
3004 MsiCloseHandle(hDb
);
3005 if (rc
== ERROR_SUCCESS
)
3007 WCHAR guidbuffer
[0x200];
3009 rc
= MsiSummaryInfoGetPropertyW(hSumInfo
, 9, NULL
, NULL
, NULL
,
3011 if (rc
== ERROR_SUCCESS
)
3013 WCHAR squashed
[GUID_SIZE
];
3014 /* for now we only care about the first guid */
3015 LPWSTR ptr
= strchrW(guidbuffer
,';');
3017 squash_guid(guidbuffer
,squashed
);
3018 msi_reg_set_val_str( hukey
, INSTALLPROPERTY_PACKAGECODEW
, squashed
);
3022 ERR("Unable to query Revision_Number... \n");
3025 MsiCloseHandle(hSumInfo
);
3029 ERR("Unable to open Summary Information\n");
3041 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
3043 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3044 LPCWSTR component
,section
,key
,value
,identifier
,filename
,dirproperty
;
3045 LPWSTR deformated_section
, deformated_key
, deformated_value
;
3046 LPWSTR folder
, fullname
= NULL
;
3050 static const WCHAR szWindowsFolder
[] =
3051 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3053 component
= MSI_RecordGetString(row
, 8);
3054 comp
= get_loaded_component(package
,component
);
3056 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
3058 TRACE("Skipping ini file due to disabled component %s\n",
3059 debugstr_w(component
));
3061 comp
->Action
= comp
->Installed
;
3063 return ERROR_SUCCESS
;
3066 comp
->Action
= INSTALLSTATE_LOCAL
;
3068 identifier
= MSI_RecordGetString(row
,1);
3069 filename
= MSI_RecordGetString(row
,2);
3070 dirproperty
= MSI_RecordGetString(row
,3);
3071 section
= MSI_RecordGetString(row
,4);
3072 key
= MSI_RecordGetString(row
,5);
3073 value
= MSI_RecordGetString(row
,6);
3074 action
= MSI_RecordGetInteger(row
,7);
3076 deformat_string(package
,section
,&deformated_section
);
3077 deformat_string(package
,key
,&deformated_key
);
3078 deformat_string(package
,value
,&deformated_value
);
3082 folder
= resolve_folder(package
, dirproperty
, FALSE
, FALSE
, NULL
);
3084 folder
= msi_dup_property( package
, dirproperty
);
3087 folder
= msi_dup_property( package
, szWindowsFolder
);
3091 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty
));
3095 fullname
= build_directory_name(2, folder
, filename
);
3099 TRACE("Adding value %s to section %s in %s\n",
3100 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3101 debugstr_w(fullname
));
3102 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3103 deformated_value
, fullname
);
3105 else if (action
== 1)
3108 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
3109 returned
, 10, fullname
);
3110 if (returned
[0] == 0)
3112 TRACE("Adding value %s to section %s in %s\n",
3113 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3114 debugstr_w(fullname
));
3116 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3117 deformated_value
, fullname
);
3120 else if (action
== 3)
3121 FIXME("Append to existing section not yet implemented\n");
3123 uirow
= MSI_CreateRecord(4);
3124 MSI_RecordSetStringW(uirow
,1,identifier
);
3125 MSI_RecordSetStringW(uirow
,2,deformated_section
);
3126 MSI_RecordSetStringW(uirow
,3,deformated_key
);
3127 MSI_RecordSetStringW(uirow
,4,deformated_value
);
3128 ui_actiondata(package
,szWriteIniValues
,uirow
);
3129 msiobj_release( &uirow
->hdr
);
3131 HeapFree(GetProcessHeap(),0,fullname
);
3132 HeapFree(GetProcessHeap(),0,folder
);
3133 HeapFree(GetProcessHeap(),0,deformated_key
);
3134 HeapFree(GetProcessHeap(),0,deformated_value
);
3135 HeapFree(GetProcessHeap(),0,deformated_section
);
3136 return ERROR_SUCCESS
;
3139 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
3143 static const WCHAR ExecSeqQuery
[] =
3144 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3145 '`','I','n','i','F','i','l','e','`',0};
3147 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3148 if (rc
!= ERROR_SUCCESS
)
3150 TRACE("no IniFile table\n");
3151 return ERROR_SUCCESS
;
3154 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
3155 msiobj_release(&view
->hdr
);
3159 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
3161 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3166 static const WCHAR ExeStr
[] =
3167 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3168 static const WCHAR close
[] = {'\"',0};
3170 PROCESS_INFORMATION info
;
3173 memset(&si
,0,sizeof(STARTUPINFOW
));
3175 filename
= MSI_RecordGetString(row
,1);
3176 file
= get_loaded_file( package
, filename
);
3180 ERR("Unable to find file id %s\n",debugstr_w(filename
));
3181 return ERROR_SUCCESS
;
3184 len
= strlenW(ExeStr
) + strlenW( file
->TargetPath
) + 2;
3186 FullName
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
3187 strcpyW(FullName
,ExeStr
);
3188 strcatW( FullName
, file
->TargetPath
);
3189 strcatW(FullName
,close
);
3191 TRACE("Registering %s\n",debugstr_w(FullName
));
3192 brc
= CreateProcessW(NULL
, FullName
, NULL
, NULL
, FALSE
, 0, NULL
, c_colon
,
3196 msi_dialog_check_messages(info
.hProcess
);
3198 HeapFree(GetProcessHeap(),0,FullName
);
3199 return ERROR_SUCCESS
;
3202 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
3206 static const WCHAR ExecSeqQuery
[] =
3207 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3208 '`','S','e','l','f','R','e','g','`',0};
3210 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3211 if (rc
!= ERROR_SUCCESS
)
3213 TRACE("no SelfReg table\n");
3214 return ERROR_SUCCESS
;
3217 MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
3218 msiobj_release(&view
->hdr
);
3220 return ERROR_SUCCESS
;
3223 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
3225 MSIFEATURE
*feature
;
3231 return ERROR_INVALID_HANDLE
;
3233 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
,&hkey
,TRUE
);
3234 if (rc
!= ERROR_SUCCESS
)
3237 rc
= MSIREG_OpenUserFeaturesKey(package
->ProductCode
,&hukey
,TRUE
);
3238 if (rc
!= ERROR_SUCCESS
)
3241 /* here the guids are base 85 encoded */
3242 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3248 BOOL absent
= FALSE
;
3250 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_LOCAL
) &&
3251 !ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_SOURCE
) &&
3252 !ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_ADVERTISED
))
3256 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3260 if (feature
->Feature_Parent
)
3261 size
+= strlenW( feature
->Feature_Parent
)+2;
3263 data
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
3266 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3268 MSICOMPONENT
* component
= cl
->component
;
3271 memset(buf
,0,sizeof(buf
));
3272 if (component
->ComponentId
)
3274 TRACE("From %s\n",debugstr_w(component
->ComponentId
));
3275 CLSIDFromString(component
->ComponentId
, &clsid
);
3276 encode_base85_guid(&clsid
,buf
);
3277 TRACE("to %s\n",debugstr_w(buf
));
3281 if (feature
->Feature_Parent
)
3283 static const WCHAR sep
[] = {'\2',0};
3285 strcatW(data
,feature
->Feature_Parent
);
3288 msi_reg_set_val_str( hkey
, feature
->Feature
, data
);
3289 HeapFree(GetProcessHeap(),0,data
);
3292 if (feature
->Feature_Parent
)
3293 size
= strlenW(feature
->Feature_Parent
)*sizeof(WCHAR
);
3296 RegSetValueExW(hukey
,feature
->Feature
,0,REG_SZ
,
3297 (LPBYTE
)feature
->Feature_Parent
,size
);
3301 size
+= 2*sizeof(WCHAR
);
3302 data
= HeapAlloc(GetProcessHeap(),0,size
);
3305 if (feature
->Feature_Parent
)
3306 strcpyW( &data
[1], feature
->Feature_Parent
);
3307 RegSetValueExW(hukey
,feature
->Feature
,0,REG_SZ
,
3309 HeapFree(GetProcessHeap(),0,data
);
3319 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
3322 LPWSTR buffer
= NULL
;
3325 static const WCHAR szWindowsInstaller
[] =
3326 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3327 static const WCHAR szPropKeys
[][80] =
3329 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3330 {'A','R','P','C','O','N','T','A','C','T',0},
3331 {'A','R','P','C','O','M','M','E','N','T','S',0},
3332 {'P','r','o','d','u','c','t','N','a','m','e',0},
3333 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3334 {'A','R','P','H','E','L','P','L','I','N','K',0},
3335 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3336 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3337 {'S','o','u','r','c','e','D','i','r',0},
3338 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3339 {'A','R','P','R','E','A','D','M','E',0},
3340 {'A','R','P','S','I','Z','E',0},
3341 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3342 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3346 static const WCHAR szRegKeys
[][80] =
3348 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3349 {'C','o','n','t','a','c','t',0},
3350 {'C','o','m','m','e','n','t','s',0},
3351 {'D','i','s','p','l','a','y','N','a','m','e',0},
3352 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3353 {'H','e','l','p','L','i','n','k',0},
3354 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3355 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3356 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3357 {'P','u','b','l','i','s','h','e','r',0},
3358 {'R','e','a','d','m','e',0},
3359 {'S','i','z','e',0},
3360 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3361 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3365 static const WCHAR installerPathFmt
[] = {
3367 'I','n','s','t','a','l','l','e','r','\\',0};
3368 static const WCHAR fmt
[] = {
3370 'I','n','s','t','a','l','l','e','r','\\',
3371 '%','x','.','m','s','i',0};
3372 static const WCHAR szUpgradeCode
[] =
3373 {'U','p','g','r','a','d','e','C','o','d','e',0};
3374 static const WCHAR modpath_fmt
[] =
3375 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3376 static const WCHAR szModifyPath
[] =
3377 {'M','o','d','i','f','y','P','a','t','h',0};
3378 static const WCHAR szUninstallString
[] =
3379 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3380 static const WCHAR szEstimatedSize
[] =
3381 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3382 static const WCHAR szProductLanguage
[] =
3383 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3384 static const WCHAR szProductVersion
[] =
3385 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3388 static const WCHAR date_fmt
[] = {'%','i','%','i','%','i',0};
3389 LPWSTR upgrade_code
;
3390 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], packagefile
[MAX_PATH
];
3394 return ERROR_INVALID_HANDLE
;
3396 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
,&hkey
,TRUE
);
3397 if (rc
!= ERROR_SUCCESS
)
3400 /* dump all the info i can grab */
3401 FIXME("Flesh out more information \n");
3403 for( i
=0; szPropKeys
[i
][0]; i
++ )
3405 buffer
= msi_dup_property( package
, szPropKeys
[i
] );
3406 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
3407 HeapFree(GetProcessHeap(),0,buffer
);
3411 msi_reg_set_val_dword( hkey
, szWindowsInstaller
, 1 );
3413 /* copy the package locally */
3414 num
= GetTickCount() & 0xffff;
3418 GetWindowsDirectoryW(windir
, sizeof(windir
) / sizeof(windir
[0]));
3419 snprintfW(packagefile
,sizeof(packagefile
)/sizeof(packagefile
[0]),fmt
,
3423 HANDLE handle
= CreateFileW(packagefile
,GENERIC_WRITE
, 0, NULL
,
3424 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
3425 if (handle
!= INVALID_HANDLE_VALUE
)
3427 CloseHandle(handle
);
3430 if (GetLastError() != ERROR_FILE_EXISTS
&&
3431 GetLastError() != ERROR_SHARING_VIOLATION
)
3433 if (!(++num
& 0xffff)) num
= 1;
3434 sprintfW(packagefile
,fmt
,num
);
3435 } while (num
!= start
);
3437 snprintfW(path
,sizeof(path
)/sizeof(path
[0]),installerPathFmt
,windir
);
3438 create_full_pathW(path
);
3439 TRACE("Copying to local package %s\n",debugstr_w(packagefile
));
3440 if (!CopyFileW(package
->msiFilePath
,packagefile
,FALSE
))
3441 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3442 debugstr_w(package
->msiFilePath
), debugstr_w(packagefile
),
3444 msi_reg_set_val_str( hkey
, INSTALLPROPERTY_LOCALPACKAGEW
, packagefile
);
3446 /* do ModifyPath and UninstallString */
3447 size
= deformat_string(package
,modpath_fmt
,&buffer
);
3448 RegSetValueExW(hkey
,szModifyPath
,0,REG_EXPAND_SZ
,(LPBYTE
)buffer
,size
);
3449 RegSetValueExW(hkey
,szUninstallString
,0,REG_EXPAND_SZ
,(LPBYTE
)buffer
,size
);
3450 HeapFree(GetProcessHeap(),0,buffer
);
3452 FIXME("Write real Estimated Size when we have it\n");
3453 msi_reg_set_val_dword( hkey
, szEstimatedSize
, 0 );
3455 GetLocalTime(&systime
);
3456 size
= 9*sizeof(WCHAR
);
3457 buffer
= HeapAlloc(GetProcessHeap(),0,size
);
3458 sprintfW(buffer
,date_fmt
,systime
.wYear
,systime
.wMonth
,systime
.wDay
);
3459 msi_reg_set_val_str( hkey
, INSTALLPROPERTY_INSTALLDATEW
, buffer
);
3460 HeapFree(GetProcessHeap(),0,buffer
);
3462 buffer
= msi_dup_property( package
, szProductLanguage
);
3463 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_LANGUAGEW
, atoiW(buffer
) );
3464 HeapFree(GetProcessHeap(),1,buffer
);
3466 buffer
= msi_dup_property( package
, szProductVersion
);
3469 DWORD verdword
= build_version_dword(buffer
);
3471 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
3472 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_VERSIONMAJORW
, verdword
>>24 );
3473 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_VERSIONMINORW
, (verdword
>>16)&0x00FF );
3475 HeapFree(GetProcessHeap(),0,buffer
);
3477 /* Handle Upgrade Codes */
3478 upgrade_code
= msi_dup_property( package
, szUpgradeCode
);
3483 MSIREG_OpenUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3484 squash_guid(package
->ProductCode
,squashed
);
3485 msi_reg_set_val_str( hkey2
, squashed
, NULL
);
3487 MSIREG_OpenUserUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3488 squash_guid(package
->ProductCode
,squashed
);
3489 msi_reg_set_val_str( hkey2
, squashed
, NULL
);
3492 HeapFree(GetProcessHeap(),0,upgrade_code
);
3498 return ERROR_SUCCESS
;
3501 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
3506 return ERROR_INVALID_HANDLE
;
3508 rc
= execute_script(package
,INSTALL_SCRIPT
);
3513 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
3518 return ERROR_INVALID_HANDLE
;
3520 /* turn off scheduleing */
3521 package
->script
->CurrentlyScripting
= FALSE
;
3523 /* first do the same as an InstallExecute */
3524 rc
= ACTION_InstallExecute(package
);
3525 if (rc
!= ERROR_SUCCESS
)
3528 /* then handle Commit Actions */
3529 rc
= execute_script(package
,COMMIT_SCRIPT
);
3534 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
3536 static const WCHAR RunOnce
[] = {
3537 'S','o','f','t','w','a','r','e','\\',
3538 'M','i','c','r','o','s','o','f','t','\\',
3539 'W','i','n','d','o','w','s','\\',
3540 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3541 'R','u','n','O','n','c','e',0};
3542 static const WCHAR InstallRunOnce
[] = {
3543 'S','o','f','t','w','a','r','e','\\',
3544 'M','i','c','r','o','s','o','f','t','\\',
3545 'W','i','n','d','o','w','s','\\',
3546 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3547 'I','n','s','t','a','l','l','e','r','\\',
3548 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3550 static const WCHAR msiexec_fmt
[] = {
3552 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3553 '\"','%','s','\"',0};
3554 static const WCHAR install_fmt
[] = {
3555 '/','I',' ','\"','%','s','\"',' ',
3556 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3557 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3558 WCHAR buffer
[256], sysdir
[MAX_PATH
];
3560 WCHAR squished_pc
[100];
3563 return ERROR_INVALID_HANDLE
;
3565 squash_guid(package
->ProductCode
,squished_pc
);
3567 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
3568 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
3569 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
3572 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
3575 TRACE("Reboot command %s\n",debugstr_w(buffer
));
3577 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
3578 sprintfW(buffer
,install_fmt
,package
->ProductCode
,squished_pc
);
3580 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
3583 return ERROR_INSTALL_SUSPEND
;
3586 UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
3591 * we are currently doing what should be done here in the top level Install
3592 * however for Adminastrative and uninstalls this step will be needed
3594 if (!package
->PackagePath
)
3595 return ERROR_SUCCESS
;
3597 attrib
= GetFileAttributesW(package
->PackagePath
);
3598 if (attrib
== INVALID_FILE_ATTRIBUTES
)
3604 rc
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
3605 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
,
3606 INSTALLPROPERTY_DISKPROMPTW
,NULL
,&size
);
3607 if (rc
== ERROR_MORE_DATA
)
3609 prompt
= HeapAlloc(GetProcessHeap(),0,size
* sizeof(WCHAR
));
3610 MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
3611 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
,
3612 INSTALLPROPERTY_DISKPROMPTW
,prompt
,&size
);
3615 prompt
= strdupW(package
->PackagePath
);
3617 msg
= generate_error_string(package
,1302,1,prompt
);
3618 while(attrib
== INVALID_FILE_ATTRIBUTES
)
3620 rc
= MessageBoxW(NULL
,msg
,NULL
,MB_OKCANCEL
);
3623 rc
= ERROR_INSTALL_USEREXIT
;
3626 attrib
= GetFileAttributesW(package
->PackagePath
);
3628 HeapFree(GetProcessHeap(),0,prompt
);
3632 return ERROR_SUCCESS
;
3637 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
3644 static const WCHAR szPropKeys
[][80] =
3646 {'P','r','o','d','u','c','t','I','D',0},
3647 {'U','S','E','R','N','A','M','E',0},
3648 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3652 static const WCHAR szRegKeys
[][80] =
3654 {'P','r','o','d','u','c','t','I','D',0},
3655 {'R','e','g','O','w','n','e','r',0},
3656 {'R','e','g','C','o','m','p','a','n','y',0},
3661 return ERROR_INVALID_HANDLE
;
3663 productid
= msi_dup_property( package
, INSTALLPROPERTY_PRODUCTIDW
);
3665 return ERROR_SUCCESS
;
3667 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
,&hkey
,TRUE
);
3668 if (rc
!= ERROR_SUCCESS
)
3672 while (szPropKeys
[i
][0]!=0)
3674 buffer
= msi_dup_property( package
, szPropKeys
[i
] );
3675 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
3680 HeapFree(GetProcessHeap(),0,productid
);
3683 return ERROR_SUCCESS
;
3687 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
3689 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
3690 static const WCHAR szTwo
[] = {'2',0};
3693 level
= msi_dup_property( package
, szUILevel
);
3695 MSI_SetPropertyW(package
,szUILevel
,szTwo
);
3696 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
3697 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
3698 MSI_SetPropertyW(package
,szUILevel
,level
);
3699 HeapFree(GetProcessHeap(),0,level
);
3705 * Code based off of code located here
3706 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3708 * Using string index 4 (full font name) instead of 1 (family name)
3710 static LPWSTR
load_ttfname_from(LPCWSTR filename
)
3716 typedef struct _tagTT_OFFSET_TABLE
{
3717 USHORT uMajorVersion
;
3718 USHORT uMinorVersion
;
3719 USHORT uNumOfTables
;
3720 USHORT uSearchRange
;
3721 USHORT uEntrySelector
;
3725 typedef struct _tagTT_TABLE_DIRECTORY
{
3726 char szTag
[4]; /* table name */
3727 ULONG uCheckSum
; /* Check sum */
3728 ULONG uOffset
; /* Offset from beginning of file */
3729 ULONG uLength
; /* length of the table in bytes */
3730 }TT_TABLE_DIRECTORY
;
3732 typedef struct _tagTT_NAME_TABLE_HEADER
{
3733 USHORT uFSelector
; /* format selector. Always 0 */
3734 USHORT uNRCount
; /* Name Records count */
3735 USHORT uStorageOffset
; /* Offset for strings storage,
3736 * from start of the table */
3737 }TT_NAME_TABLE_HEADER
;
3739 typedef struct _tagTT_NAME_RECORD
{
3744 USHORT uStringLength
;
3745 USHORT uStringOffset
; /* from start of storage area */
3748 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3749 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3751 handle
= CreateFileW(filename
,GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
3752 FILE_ATTRIBUTE_NORMAL
, 0 );
3753 if (handle
!= INVALID_HANDLE_VALUE
)
3755 TT_TABLE_DIRECTORY tblDir
;
3756 BOOL bFound
= FALSE
;
3757 TT_OFFSET_TABLE ttOffsetTable
;
3759 ReadFile(handle
,&ttOffsetTable
, sizeof(TT_OFFSET_TABLE
),NULL
,NULL
);
3760 ttOffsetTable
.uNumOfTables
= SWAPWORD(ttOffsetTable
.uNumOfTables
);
3761 ttOffsetTable
.uMajorVersion
= SWAPWORD(ttOffsetTable
.uMajorVersion
);
3762 ttOffsetTable
.uMinorVersion
= SWAPWORD(ttOffsetTable
.uMinorVersion
);
3764 if (ttOffsetTable
.uMajorVersion
!= 1 ||
3765 ttOffsetTable
.uMinorVersion
!= 0)
3768 for (i
=0; i
< ttOffsetTable
.uNumOfTables
; i
++)
3770 ReadFile(handle
,&tblDir
, sizeof(TT_TABLE_DIRECTORY
),NULL
,NULL
);
3771 if (strncmp(tblDir
.szTag
,"name",4)==0)
3774 tblDir
.uLength
= SWAPLONG(tblDir
.uLength
);
3775 tblDir
.uOffset
= SWAPLONG(tblDir
.uOffset
);
3782 TT_NAME_TABLE_HEADER ttNTHeader
;
3783 TT_NAME_RECORD ttRecord
;
3785 SetFilePointer(handle
, tblDir
.uOffset
, NULL
, FILE_BEGIN
);
3786 ReadFile(handle
,&ttNTHeader
, sizeof(TT_NAME_TABLE_HEADER
),
3789 ttNTHeader
.uNRCount
= SWAPWORD(ttNTHeader
.uNRCount
);
3790 ttNTHeader
.uStorageOffset
= SWAPWORD(ttNTHeader
.uStorageOffset
);
3792 for(i
=0; i
<ttNTHeader
.uNRCount
; i
++)
3794 ReadFile(handle
,&ttRecord
, sizeof(TT_NAME_RECORD
),NULL
,NULL
);
3795 ttRecord
.uNameID
= SWAPWORD(ttRecord
.uNameID
);
3796 /* 4 is the Full Font Name */
3797 if(ttRecord
.uNameID
== 4)
3801 static LPCSTR tt
= " (TrueType)";
3803 ttRecord
.uStringLength
= SWAPWORD(ttRecord
.uStringLength
);
3804 ttRecord
.uStringOffset
= SWAPWORD(ttRecord
.uStringOffset
);
3805 nPos
= SetFilePointer(handle
, 0, NULL
, FILE_CURRENT
);
3806 SetFilePointer(handle
, tblDir
.uOffset
+
3807 ttRecord
.uStringOffset
+
3808 ttNTHeader
.uStorageOffset
,
3810 buf
= HeapAlloc(GetProcessHeap(), 0,
3811 ttRecord
.uStringLength
+ 1 + strlen(tt
));
3812 memset(buf
, 0, ttRecord
.uStringLength
+ 1 + strlen(tt
));
3813 ReadFile(handle
, buf
, ttRecord
.uStringLength
, NULL
, NULL
);
3814 if (strlen(buf
) > 0)
3817 ret
= strdupAtoW(buf
);
3818 HeapFree(GetProcessHeap(),0,buf
);
3822 HeapFree(GetProcessHeap(),0,buf
);
3823 SetFilePointer(handle
,nPos
, NULL
, FILE_BEGIN
);
3827 CloseHandle(handle
);
3830 ERR("Unable to open font file %s\n", debugstr_w(filename
));
3832 TRACE("Returning fontname %s\n",debugstr_w(ret
));
3836 static UINT
ITERATE_RegisterFonts(MSIRECORD
*row
, LPVOID param
)
3838 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3842 static const WCHAR regfont1
[] =
3843 {'S','o','f','t','w','a','r','e','\\',
3844 'M','i','c','r','o','s','o','f','t','\\',
3845 'W','i','n','d','o','w','s',' ','N','T','\\',
3846 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3847 'F','o','n','t','s',0};
3848 static const WCHAR regfont2
[] =
3849 {'S','o','f','t','w','a','r','e','\\',
3850 'M','i','c','r','o','s','o','f','t','\\',
3851 'W','i','n','d','o','w','s','\\',
3852 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3853 'F','o','n','t','s',0};
3857 filename
= MSI_RecordGetString( row
, 1 );
3858 file
= get_loaded_file( package
, filename
);
3861 ERR("Unable to load file\n");
3862 return ERROR_SUCCESS
;
3865 /* check to make sure that component is installed */
3866 if (!ACTION_VerifyComponentForAction(package
,
3867 file
->Component
, INSTALLSTATE_LOCAL
))
3869 TRACE("Skipping: Component not scheduled for install\n");
3870 return ERROR_SUCCESS
;
3873 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont1
,&hkey1
);
3874 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont2
,&hkey2
);
3876 if (MSI_RecordIsNull(row
,2))
3877 name
= load_ttfname_from( file
->TargetPath
);
3879 name
= load_dynamic_stringW(row
,2);
3883 msi_reg_set_val_str( hkey1
, name
, file
->FileName
);
3884 msi_reg_set_val_str( hkey2
, name
, file
->FileName
);
3887 HeapFree(GetProcessHeap(),0,name
);
3890 return ERROR_SUCCESS
;
3893 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
)
3897 static const WCHAR ExecSeqQuery
[] =
3898 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3899 '`','F','o','n','t','`',0};
3901 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3902 if (rc
!= ERROR_SUCCESS
)
3904 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc
);
3905 return ERROR_SUCCESS
;
3908 MSI_IterateRecords(view
, NULL
, ITERATE_RegisterFonts
, package
);
3909 msiobj_release(&view
->hdr
);
3911 return ERROR_SUCCESS
;
3914 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
3916 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3917 LPCWSTR compgroupid
=NULL
;
3918 LPCWSTR feature
=NULL
;
3919 LPCWSTR text
= NULL
;
3920 LPCWSTR qualifier
= NULL
;
3921 LPCWSTR component
= NULL
;
3922 LPWSTR advertise
= NULL
;
3923 LPWSTR output
= NULL
;
3925 UINT rc
= ERROR_SUCCESS
;
3929 component
= MSI_RecordGetString(rec
,3);
3930 comp
= get_loaded_component(package
,component
);
3932 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
) &&
3933 !ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_SOURCE
) &&
3934 !ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_ADVERTISED
))
3936 TRACE("Skipping: Component %s not scheduled for install\n",
3937 debugstr_w(component
));
3939 return ERROR_SUCCESS
;
3942 compgroupid
= MSI_RecordGetString(rec
,1);
3944 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
3945 if (rc
!= ERROR_SUCCESS
)
3948 text
= MSI_RecordGetString(rec
,4);
3949 qualifier
= MSI_RecordGetString(rec
,2);
3950 feature
= MSI_RecordGetString(rec
,5);
3952 advertise
= create_component_advertise_string(package
, comp
, feature
);
3954 sz
= strlenW(advertise
);
3957 sz
+= lstrlenW(text
);
3960 sz
*= sizeof(WCHAR
);
3962 output
= HeapAlloc(GetProcessHeap(),0,sz
);
3963 memset(output
,0,sz
);
3964 strcpyW(output
,advertise
);
3967 strcatW(output
,text
);
3969 msi_reg_set_val_multi_str( hkey
, qualifier
, output
);
3973 HeapFree(GetProcessHeap(),0,output
);
3979 * At present I am ignorning the advertised components part of this and only
3980 * focusing on the qualified component sets
3982 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
3986 static const WCHAR ExecSeqQuery
[] =
3987 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3988 '`','P','u','b','l','i','s','h',
3989 'C','o','m','p','o','n','e','n','t','`',0};
3991 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3992 if (rc
!= ERROR_SUCCESS
)
3993 return ERROR_SUCCESS
;
3995 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
3996 msiobj_release(&view
->hdr
);