2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004,2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
37 #include "wine/debug.h"
42 #include "wine/unicode.h"
46 #define REG_PROGRESS_VALUE 13200
47 #define COMPONENT_PROGRESS_VALUE 24000
49 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
54 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
);
55 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
);
56 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
);
61 typedef UINT (*STANDARDACTIONHANDLER
)(MSIPACKAGE
*);
63 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
);
64 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
);
65 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
);
66 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
);
67 static UINT
ACTION_FileCost(MSIPACKAGE
*package
);
68 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
);
69 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
);
70 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
);
71 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
);
72 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
);
73 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
);
74 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
);
75 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
);
76 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
);
77 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
);
78 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
);
79 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
);
80 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
);
81 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
);
82 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
);
83 static UINT
ACTION_ResolveSource(MSIPACKAGE
*package
);
84 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
);
85 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
);
86 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
);
89 * consts and values used
91 static const WCHAR c_colon
[] = {'C',':','\\',0};
93 const static WCHAR szCreateFolders
[] =
94 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
95 const static WCHAR szCostFinalize
[] =
96 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
97 const WCHAR szInstallFiles
[] =
98 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
99 const WCHAR szDuplicateFiles
[] =
100 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
101 const static WCHAR szWriteRegistryValues
[] =
102 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
103 'V','a','l','u','e','s',0};
104 const static WCHAR szCostInitialize
[] =
105 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
106 const static WCHAR szFileCost
[] =
107 {'F','i','l','e','C','o','s','t',0};
108 const static WCHAR szInstallInitialize
[] =
109 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
110 const static WCHAR szInstallValidate
[] =
111 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
112 const static WCHAR szLaunchConditions
[] =
113 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
114 const static WCHAR szProcessComponents
[] =
115 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
116 const static WCHAR szRegisterTypeLibraries
[] =
117 {'R','e','g','i','s','t','e','r','T','y','p','e',
118 'L','i','b','r','a','r','i','e','s',0};
119 const WCHAR szRegisterClassInfo
[] =
120 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
121 const WCHAR szRegisterProgIdInfo
[] =
122 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
123 const static WCHAR szCreateShortcuts
[] =
124 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
125 const static WCHAR szPublishProduct
[] =
126 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
127 const static WCHAR szWriteIniValues
[] =
128 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
129 const static WCHAR szSelfRegModules
[] =
130 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
131 const static WCHAR szPublishFeatures
[] =
132 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
133 const static WCHAR szRegisterProduct
[] =
134 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
135 const static WCHAR szInstallExecute
[] =
136 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
137 const static WCHAR szInstallExecuteAgain
[] =
138 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
139 'A','g','a','i','n',0};
140 const static WCHAR szInstallFinalize
[] =
141 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
142 const static WCHAR szForceReboot
[] =
143 {'F','o','r','c','e','R','e','b','o','o','t',0};
144 const static WCHAR szResolveSource
[] =
145 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
146 const WCHAR szAppSearch
[] =
147 {'A','p','p','S','e','a','r','c','h',0};
148 const static WCHAR szAllocateRegistrySpace
[] =
149 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
150 'S','p','a','c','e',0};
151 const static WCHAR szBindImage
[] =
152 {'B','i','n','d','I','m','a','g','e',0};
153 const static WCHAR szCCPSearch
[] =
154 {'C','C','P','S','e','a','r','c','h',0};
155 const static WCHAR szDeleteServices
[] =
156 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
157 const static WCHAR szDisableRollback
[] =
158 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
159 const static WCHAR szExecuteAction
[] =
160 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
161 const WCHAR szFindRelatedProducts
[] =
162 {'F','i','n','d','R','e','l','a','t','e','d',
163 'P','r','o','d','u','c','t','s',0};
164 const static WCHAR szInstallAdminPackage
[] =
165 {'I','n','s','t','a','l','l','A','d','m','i','n',
166 'P','a','c','k','a','g','e',0};
167 const static WCHAR szInstallSFPCatalogFile
[] =
168 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
170 const static WCHAR szIsolateComponents
[] =
171 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
172 const WCHAR szMigrateFeatureStates
[] =
173 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
174 'S','t','a','t','e','s',0};
175 const WCHAR szMoveFiles
[] =
176 {'M','o','v','e','F','i','l','e','s',0};
177 const static WCHAR szMsiPublishAssemblies
[] =
178 {'M','s','i','P','u','b','l','i','s','h',
179 'A','s','s','e','m','b','l','i','e','s',0};
180 const static WCHAR szMsiUnpublishAssemblies
[] =
181 {'M','s','i','U','n','p','u','b','l','i','s','h',
182 'A','s','s','e','m','b','l','i','e','s',0};
183 const static WCHAR szInstallODBC
[] =
184 {'I','n','s','t','a','l','l','O','D','B','C',0};
185 const static WCHAR szInstallServices
[] =
186 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
187 const WCHAR szPatchFiles
[] =
188 {'P','a','t','c','h','F','i','l','e','s',0};
189 const static WCHAR szPublishComponents
[] =
190 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
191 const static WCHAR szRegisterComPlus
[] =
192 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
193 const WCHAR szRegisterExtensionInfo
[] =
194 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
196 const static WCHAR szRegisterFonts
[] =
197 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
198 const WCHAR szRegisterMIMEInfo
[] =
199 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
200 const static WCHAR szRegisterUser
[] =
201 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
202 const WCHAR szRemoveDuplicateFiles
[] =
203 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
204 'F','i','l','e','s',0};
205 const static WCHAR szRemoveEnvironmentStrings
[] =
206 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
207 'S','t','r','i','n','g','s',0};
208 const WCHAR szRemoveExistingProducts
[] =
209 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
210 'P','r','o','d','u','c','t','s',0};
211 const WCHAR szRemoveFiles
[] =
212 {'R','e','m','o','v','e','F','i','l','e','s',0};
213 const static WCHAR szRemoveFolders
[] =
214 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
215 const static WCHAR szRemoveIniValues
[] =
216 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
217 const static WCHAR szRemoveODBC
[] =
218 {'R','e','m','o','v','e','O','D','B','C',0};
219 const static WCHAR szRemoveRegistryValues
[] =
220 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
221 'V','a','l','u','e','s',0};
222 const static WCHAR szRemoveShortcuts
[] =
223 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
224 const static WCHAR szRMCCPSearch
[] =
225 {'R','M','C','C','P','S','e','a','r','c','h',0};
226 const static WCHAR szScheduleReboot
[] =
227 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
228 const static WCHAR szSelfUnregModules
[] =
229 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
230 const static WCHAR szSetODBCFolders
[] =
231 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
232 const static WCHAR szStartServices
[] =
233 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
234 const static WCHAR szStopServices
[] =
235 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
236 const static WCHAR szUnpublishComponents
[] =
237 {'U','n','p','u','b','l','i','s','h',
238 'C','o','m','p','o','n','e','n','t','s',0};
239 const static WCHAR szUnpublishFeatures
[] =
240 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
241 const WCHAR szUnregisterClassInfo
[] =
242 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
244 const static WCHAR szUnregisterComPlus
[] =
245 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
246 const WCHAR szUnregisterExtensionInfo
[] =
247 {'U','n','r','e','g','i','s','t','e','r',
248 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
249 const static WCHAR szUnregisterFonts
[] =
250 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
251 const WCHAR szUnregisterMIMEInfo
[] =
252 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
253 const WCHAR szUnregisterProgIdInfo
[] =
254 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
256 const static WCHAR szUnregisterTypeLibraries
[] =
257 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
258 'L','i','b','r','a','r','i','e','s',0};
259 const static WCHAR szValidateProductID
[] =
260 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
261 const static WCHAR szWriteEnvironmentStrings
[] =
262 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
263 'S','t','r','i','n','g','s',0};
267 STANDARDACTIONHANDLER handler
;
270 static struct _actions StandardActions
[] = {
271 { szAllocateRegistrySpace
, NULL
},
272 { szAppSearch
, ACTION_AppSearch
},
273 { szBindImage
, NULL
},
274 { szCCPSearch
, NULL
},
275 { szCostFinalize
, ACTION_CostFinalize
},
276 { szCostInitialize
, ACTION_CostInitialize
},
277 { szCreateFolders
, ACTION_CreateFolders
},
278 { szCreateShortcuts
, ACTION_CreateShortcuts
},
279 { szDeleteServices
, NULL
},
280 { szDisableRollback
, NULL
},
281 { szDuplicateFiles
, ACTION_DuplicateFiles
},
282 { szExecuteAction
, ACTION_ExecuteAction
},
283 { szFileCost
, ACTION_FileCost
},
284 { szFindRelatedProducts
, ACTION_FindRelatedProducts
},
285 { szForceReboot
, ACTION_ForceReboot
},
286 { szInstallAdminPackage
, NULL
},
287 { szInstallExecute
, ACTION_InstallExecute
},
288 { szInstallExecuteAgain
, ACTION_InstallExecute
},
289 { szInstallFiles
, ACTION_InstallFiles
},
290 { szInstallFinalize
, ACTION_InstallFinalize
},
291 { szInstallInitialize
, ACTION_InstallInitialize
},
292 { szInstallSFPCatalogFile
, NULL
},
293 { szInstallValidate
, ACTION_InstallValidate
},
294 { szIsolateComponents
, NULL
},
295 { szLaunchConditions
, ACTION_LaunchConditions
},
296 { szMigrateFeatureStates
, NULL
},
297 { szMoveFiles
, NULL
},
298 { szMsiPublishAssemblies
, NULL
},
299 { szMsiUnpublishAssemblies
, NULL
},
300 { szInstallODBC
, NULL
},
301 { szInstallServices
, NULL
},
302 { szPatchFiles
, NULL
},
303 { szProcessComponents
, ACTION_ProcessComponents
},
304 { szPublishComponents
, ACTION_PublishComponents
},
305 { szPublishFeatures
, ACTION_PublishFeatures
},
306 { szPublishProduct
, ACTION_PublishProduct
},
307 { szRegisterClassInfo
, ACTION_RegisterClassInfo
},
308 { szRegisterComPlus
, NULL
},
309 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
},
310 { szRegisterFonts
, ACTION_RegisterFonts
},
311 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
},
312 { szRegisterProduct
, ACTION_RegisterProduct
},
313 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
},
314 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
},
315 { szRegisterUser
, ACTION_RegisterUser
},
316 { szRemoveDuplicateFiles
, NULL
},
317 { szRemoveEnvironmentStrings
, NULL
},
318 { szRemoveExistingProducts
, NULL
},
319 { szRemoveFiles
, NULL
},
320 { szRemoveFolders
, NULL
},
321 { szRemoveIniValues
, NULL
},
322 { szRemoveODBC
, NULL
},
323 { szRemoveRegistryValues
, NULL
},
324 { szRemoveShortcuts
, NULL
},
325 { szResolveSource
, ACTION_ResolveSource
},
326 { szRMCCPSearch
, NULL
},
327 { szScheduleReboot
, NULL
},
328 { szSelfRegModules
, ACTION_SelfRegModules
},
329 { szSelfUnregModules
, NULL
},
330 { szSetODBCFolders
, NULL
},
331 { szStartServices
, NULL
},
332 { szStopServices
, NULL
},
333 { szUnpublishComponents
, NULL
},
334 { szUnpublishFeatures
, NULL
},
335 { szUnregisterClassInfo
, NULL
},
336 { szUnregisterComPlus
, NULL
},
337 { szUnregisterExtensionInfo
, NULL
},
338 { szUnregisterFonts
, NULL
},
339 { szUnregisterMIMEInfo
, NULL
},
340 { szUnregisterProgIdInfo
, NULL
},
341 { szUnregisterTypeLibraries
, NULL
},
342 { szValidateProductID
, NULL
},
343 { szWriteEnvironmentStrings
, NULL
},
344 { szWriteIniValues
, ACTION_WriteIniValues
},
345 { szWriteRegistryValues
, ACTION_WriteRegistryValues
},
350 /********************************************************
352 ********************************************************/
354 static void ce_actiontext(MSIPACKAGE
* package
, LPCWSTR action
)
356 static const WCHAR szActionText
[] =
357 {'A','c','t','i','o','n','T','e','x','t',0};
360 row
= MSI_CreateRecord(1);
361 MSI_RecordSetStringW(row
,1,action
);
362 ControlEvent_FireSubscribedEvent(package
,szActionText
, row
);
363 msiobj_release(&row
->hdr
);
366 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
368 static const WCHAR template_s
[]=
369 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
371 static const WCHAR format
[] =
372 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
373 static const WCHAR Query_t
[] =
374 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
375 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
376 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
377 ' ','\'','%','s','\'',0};
384 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
386 row
= MSI_QueryGetRecord( package
->db
, Query_t
, action
);
390 ActionText
= MSI_RecordGetString(row
,2);
391 deformat_string(package
, ActionText
, &deformated
);
393 sprintfW(message
,template_s
,timet
,action
,deformated
);
394 ce_actiontext(package
, deformated
);
395 msiobj_release(&row
->hdr
);
397 row
= MSI_CreateRecord(1);
398 MSI_RecordSetStringW(row
,1,message
);
400 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
401 msiobj_release(&row
->hdr
);
402 HeapFree(GetProcessHeap(),0,deformated
);
405 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
409 static const WCHAR template_s
[]=
410 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
412 static const WCHAR template_e
[]=
413 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
414 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
416 static const WCHAR format
[] =
417 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
421 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
423 sprintfW(message
,template_s
,timet
,action
);
425 sprintfW(message
,template_e
,timet
,action
,rc
);
427 row
= MSI_CreateRecord(1);
428 MSI_RecordSetStringW(row
,1,message
);
430 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
431 msiobj_release(&row
->hdr
);
434 /****************************************************
435 * TOP level entry points
436 *****************************************************/
438 UINT
ACTION_DoTopLevelINSTALL(MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
439 LPCWSTR szCommandLine
, LPCWSTR msiFilePath
)
445 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
446 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
447 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
449 MSI_SetPropertyW(package
, szAction
, szInstall
);
451 package
->script
= HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT
));
452 memset(package
->script
,0,sizeof(MSISCRIPT
));
454 package
->script
->InWhatSequence
= SEQUENCE_INSTALL
;
456 package
->msiFilePath
= strdupW(msiFilePath
);
460 LPWSTR p
, check
, path
;
462 package
->PackagePath
= strdupW(szPackagePath
);
463 path
= strdupW(szPackagePath
);
464 p
= strrchrW(path
,'\\');
472 HeapFree(GetProcessHeap(),0,path
);
473 path
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
*sizeof(WCHAR
));
474 GetCurrentDirectoryW(MAX_PATH
,path
);
478 check
= load_dynamic_property(package
, cszSourceDir
,NULL
);
480 MSI_SetPropertyW(package
, cszSourceDir
, path
);
482 HeapFree(GetProcessHeap(), 0, check
);
484 HeapFree(GetProcessHeap(), 0, path
);
490 ptr
= (LPWSTR
)szCommandLine
;
497 TRACE("Looking at %s\n",debugstr_w(ptr
));
499 ptr2
= strchrW(ptr
,'=');
505 while (*ptr
== ' ') ptr
++;
507 prop
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
508 memcpy(prop
,ptr
,len
*sizeof(WCHAR
));
514 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
527 val
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
528 memcpy(val
,ptr2
,len
*sizeof(WCHAR
));
531 if (strlenW(prop
) > 0)
533 TRACE("Found commandline property (%s) = (%s)\n",
534 debugstr_w(prop
), debugstr_w(val
));
535 MSI_SetPropertyW(package
,prop
,val
);
537 HeapFree(GetProcessHeap(),0,val
);
538 HeapFree(GetProcessHeap(),0,prop
);
545 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
547 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
549 package
->script
->InWhatSequence
|= SEQUENCE_UI
;
550 rc
= ACTION_ProcessUISequence(package
);
552 if (rc
== ERROR_SUCCESS
)
554 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
555 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
559 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
562 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
566 /* install was halted but should be considered a success */
570 package
->script
->CurrentlyScripting
= FALSE
;
572 /* process the ending type action */
573 if (rc
== ERROR_SUCCESS
)
574 ACTION_PerformActionSequence(package
,-1,ui
);
575 else if (rc
== ERROR_INSTALL_USEREXIT
)
576 ACTION_PerformActionSequence(package
,-2,ui
);
577 else if (rc
== ERROR_INSTALL_SUSPEND
)
578 ACTION_PerformActionSequence(package
,-4,ui
);
580 ACTION_PerformActionSequence(package
,-3,ui
);
582 /* finish up running custom actions */
583 ACTION_FinishCustomActions(package
);
588 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
)
590 UINT rc
= ERROR_SUCCESS
;
592 static const WCHAR ExecSeqQuery
[] =
593 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
594 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
595 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
596 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
598 static const WCHAR UISeqQuery
[] =
599 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
600 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
601 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
602 ' ', '=',' ','%','i',0};
605 row
= MSI_QueryGetRecord(package
->db
, UISeqQuery
, seq
);
607 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, seq
);
611 LPCWSTR action
, cond
;
613 TRACE("Running the actions\n");
615 /* check conditions */
616 cond
= MSI_RecordGetString(row
,2);
619 /* this is a hack to skip errors in the condition code */
620 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
624 action
= MSI_RecordGetString(row
,1);
627 ERR("failed to fetch action\n");
628 rc
= ERROR_FUNCTION_FAILED
;
633 rc
= ACTION_PerformUIAction(package
,action
);
635 rc
= ACTION_PerformAction(package
,action
,FALSE
);
637 msiobj_release(&row
->hdr
);
648 } iterate_action_param
;
650 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
652 iterate_action_param
*iap
= (iterate_action_param
*)param
;
654 LPCWSTR cond
, action
;
656 action
= MSI_RecordGetString(row
,1);
659 ERR("Error is retrieving action name\n");
660 return ERROR_FUNCTION_FAILED
;
663 /* check conditions */
664 cond
= MSI_RecordGetString(row
,2);
667 /* this is a hack to skip errors in the condition code */
668 if (MSI_EvaluateConditionW(iap
->package
, cond
) == MSICONDITION_FALSE
)
670 TRACE("Skipping action: %s (condition is false)\n",
672 return ERROR_SUCCESS
;
677 rc
= ACTION_PerformUIAction(iap
->package
,action
);
679 rc
= ACTION_PerformAction(iap
->package
,action
,FALSE
);
681 msi_dialog_check_messages( NULL
);
683 if (iap
->package
->CurrentInstallState
!= ERROR_SUCCESS
)
684 rc
= iap
->package
->CurrentInstallState
;
686 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
689 if (rc
!= ERROR_SUCCESS
)
690 ERR("Execution halted due to error (%i)\n",rc
);
695 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
699 static const WCHAR ExecSeqQuery
[] =
700 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
701 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
702 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
703 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
704 'O','R','D','E','R',' ', 'B','Y',' ',
705 '`','S','e','q','u','e','n','c','e','`',0 };
707 static const WCHAR IVQuery
[] =
708 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
709 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
710 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
711 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
712 ' ','\'', 'I','n','s','t','a','l','l',
713 'V','a','l','i','d','a','t','e','\'', 0};
715 iterate_action_param iap
;
717 iap
.package
= package
;
720 if (package
->script
->ExecuteSequenceRun
)
722 TRACE("Execute Sequence already Run\n");
723 return ERROR_SUCCESS
;
726 package
->script
->ExecuteSequenceRun
= TRUE
;
728 /* get the sequence number */
731 row
= MSI_QueryGetRecord(package
->db
, IVQuery
);
733 return ERROR_FUNCTION_FAILED
;
734 seq
= MSI_RecordGetInteger(row
,1);
735 msiobj_release(&row
->hdr
);
738 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
739 if (rc
== ERROR_SUCCESS
)
741 TRACE("Running the actions\n");
743 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
744 msiobj_release(&view
->hdr
);
750 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
754 static const WCHAR ExecSeqQuery
[] =
755 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
756 '`','I','n','s','t','a','l','l',
757 'U','I','S','e','q','u','e','n','c','e','`',
758 ' ','W','H','E','R','E',' ',
759 '`','S','e','q','u','e','n','c','e','`',' ',
760 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
761 '`','S','e','q','u','e','n','c','e','`',0};
762 iterate_action_param iap
;
764 iap
.package
= package
;
767 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
769 if (rc
== ERROR_SUCCESS
)
771 TRACE("Running the actions \n");
773 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
774 msiobj_release(&view
->hdr
);
780 /********************************************************
781 * ACTION helper functions and functions that perform the actions
782 *******************************************************/
783 static BOOL
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
,
784 UINT
* rc
, BOOL force
)
790 if (!run
&& !package
->script
->CurrentlyScripting
)
795 if (strcmpW(action
,szInstallFinalize
) == 0 ||
796 strcmpW(action
,szInstallExecute
) == 0 ||
797 strcmpW(action
,szInstallExecuteAgain
) == 0)
802 while (StandardActions
[i
].action
!= NULL
)
804 if (strcmpW(StandardActions
[i
].action
, action
)==0)
808 ui_actioninfo(package
, action
, TRUE
, 0);
809 *rc
= schedule_action(package
,INSTALL_SCRIPT
,action
);
810 ui_actioninfo(package
, action
, FALSE
, *rc
);
814 ui_actionstart(package
, action
);
815 if (StandardActions
[i
].handler
)
817 *rc
= StandardActions
[i
].handler(package
);
821 FIXME("unhandled standard action %s\n",debugstr_w(action
));
833 static BOOL
ACTION_HandleCustomAction( MSIPACKAGE
* package
, LPCWSTR action
,
834 UINT
* rc
, BOOL force
)
839 arc
= ACTION_CustomAction(package
,action
, force
);
841 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
850 * A lot of actions are really important even if they don't do anything
851 * explicit... Lots of properties are set at the beginning of the installation
852 * CostFinalize does a bunch of work to translate the directories and such
854 * But until I get write access to the database that is hard, so I am going to
855 * hack it to see if I can get something to run.
857 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, BOOL force
)
859 UINT rc
= ERROR_SUCCESS
;
862 TRACE("Performing action (%s)\n",debugstr_w(action
));
864 handled
= ACTION_HandleStandardAction(package
, action
, &rc
, force
);
867 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, force
);
871 FIXME("unhandled msi action %s\n",debugstr_w(action
));
872 rc
= ERROR_FUNCTION_NOT_CALLED
;
878 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
)
880 UINT rc
= ERROR_SUCCESS
;
881 BOOL handled
= FALSE
;
883 TRACE("Performing action (%s)\n",debugstr_w(action
));
885 handled
= ACTION_HandleStandardAction(package
, action
, &rc
,TRUE
);
888 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, FALSE
);
890 if( !handled
&& ACTION_DialogBox(package
,action
) == ERROR_SUCCESS
)
895 FIXME("unhandled msi action %s\n",debugstr_w(action
));
896 rc
= ERROR_FUNCTION_NOT_CALLED
;
904 * Actual Action Handlers
907 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
909 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
915 dir
= MSI_RecordGetString(row
,1);
918 ERR("Unable to get folder id \n");
919 return ERROR_SUCCESS
;
922 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,&folder
);
925 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
926 return ERROR_SUCCESS
;
929 TRACE("Folder is %s\n",debugstr_w(full_path
));
932 uirow
= MSI_CreateRecord(1);
933 MSI_RecordSetStringW(uirow
,1,full_path
);
934 ui_actiondata(package
,szCreateFolders
,uirow
);
935 msiobj_release( &uirow
->hdr
);
937 if (folder
->State
== 0)
938 create_full_pathW(full_path
);
942 HeapFree(GetProcessHeap(),0,full_path
);
943 return ERROR_SUCCESS
;
948 * Also we cannot enable/disable components either, so for now I am just going
949 * to do all the directories for all the components.
951 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
953 static const WCHAR ExecSeqQuery
[] =
954 {'S','E','L','E','C','T',' ',
955 '`','D','i','r','e','c','t','o','r','y','_','`',
956 ' ','F','R','O','M',' ',
957 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
961 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
962 if (rc
!= ERROR_SUCCESS
)
963 return ERROR_SUCCESS
;
965 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
966 msiobj_release(&view
->hdr
);
971 static MSICOMPONENT
* load_component( MSIRECORD
* row
)
976 comp
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(MSICOMPONENT
) );
980 /* fill in the data */
981 sz
= IDENTIFIER_SIZE
;
982 MSI_RecordGetStringW(row
,1,comp
->Component
,&sz
);
984 TRACE("Loading Component %s\n",
985 debugstr_w(comp
->Component
));
988 if (!MSI_RecordIsNull(row
,2))
989 MSI_RecordGetStringW(row
,2,comp
->ComponentId
,&sz
);
991 sz
= IDENTIFIER_SIZE
;
992 MSI_RecordGetStringW(row
,3,comp
->Directory
,&sz
);
994 comp
->Attributes
= MSI_RecordGetInteger(row
,4);
997 MSI_RecordGetStringW(row
,5,comp
->Condition
,&sz
);
999 sz
= IDENTIFIER_SIZE
;
1000 MSI_RecordGetStringW(row
,6,comp
->KeyPath
,&sz
);
1002 comp
->Installed
= INSTALLSTATE_ABSENT
;
1003 comp
->Action
= INSTALLSTATE_UNKNOWN
;
1004 comp
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1006 comp
->Enabled
= TRUE
;
1012 MSIPACKAGE
*package
;
1013 MSIFEATURE
*feature
;
1016 static UINT
add_feature_component( MSIFEATURE
*feature
, MSICOMPONENT
*comp
)
1020 cl
= HeapAlloc( GetProcessHeap(), 0, sizeof (*cl
) );
1022 return ERROR_NOT_ENOUGH_MEMORY
;
1023 cl
->component
= comp
;
1024 list_add_tail( &feature
->Components
, &cl
->entry
);
1026 return ERROR_SUCCESS
;
1029 static UINT
iterate_component_check( MSIRECORD
*row
, LPVOID param
)
1031 _ilfs
* ilfs
= (_ilfs
*)param
;
1032 MSIPACKAGE
*package
= ilfs
->package
;
1033 MSIFEATURE
*feature
= ilfs
->feature
;
1036 comp
= load_component( row
);
1038 return ERROR_FUNCTION_FAILED
;
1040 list_add_tail( &package
->components
, &comp
->entry
);
1041 add_feature_component( feature
, comp
);
1043 TRACE("Loaded new component %p\n", comp
);
1045 return ERROR_SUCCESS
;
1048 static UINT
iterate_load_featurecomponents(MSIRECORD
*row
, LPVOID param
)
1050 _ilfs
* ilfs
= (_ilfs
*)param
;
1055 static const WCHAR Query
[] =
1056 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1057 '`','C','o','m','p','o','n','e','n','t','`',' ',
1058 'W','H','E','R','E',' ',
1059 '`','C','o','m','p','o','n','e','n','t','`',' ',
1060 '=','\'','%','s','\'',0};
1062 component
= MSI_RecordGetString(row
,1);
1064 /* check to see if the component is already loaded */
1065 comp
= get_loaded_component( ilfs
->package
, component
);
1068 TRACE("Component %s already loaded\n", debugstr_w(component
) );
1069 add_feature_component( ilfs
->feature
, comp
);
1070 return ERROR_SUCCESS
;
1073 rc
= MSI_OpenQuery(ilfs
->package
->db
, &view
, Query
, component
);
1074 if (rc
!= ERROR_SUCCESS
)
1075 return ERROR_SUCCESS
;
1077 rc
= MSI_IterateRecords(view
, NULL
, iterate_component_check
, ilfs
);
1078 msiobj_release( &view
->hdr
);
1080 return ERROR_SUCCESS
;
1083 static UINT
load_feature(MSIRECORD
* row
, LPVOID param
)
1085 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
1086 MSIFEATURE
* feature
;
1088 static const WCHAR Query1
[] =
1089 {'S','E','L','E','C','T',' ',
1090 '`','C','o','m','p','o','n','e','n','t','_','`',
1091 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1092 'C','o','m','p','o','n','e','n','t','s','`',' ',
1093 'W','H','E','R','E',' ',
1094 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1099 /* fill in the data */
1101 feature
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof (MSIFEATURE
) );
1103 return ERROR_NOT_ENOUGH_MEMORY
;
1105 list_init( &feature
->Components
);
1107 sz
= IDENTIFIER_SIZE
;
1108 MSI_RecordGetStringW(row
,1,feature
->Feature
,&sz
);
1110 TRACE("Loading feature %s\n",debugstr_w(feature
->Feature
));
1112 sz
= IDENTIFIER_SIZE
;
1113 if (!MSI_RecordIsNull(row
,2))
1114 MSI_RecordGetStringW(row
,2,feature
->Feature_Parent
,&sz
);
1117 if (!MSI_RecordIsNull(row
,3))
1118 MSI_RecordGetStringW(row
,3,feature
->Title
,&sz
);
1121 if (!MSI_RecordIsNull(row
,4))
1122 MSI_RecordGetStringW(row
,4,feature
->Description
,&sz
);
1124 if (!MSI_RecordIsNull(row
,5))
1125 feature
->Display
= MSI_RecordGetInteger(row
,5);
1127 feature
->Level
= MSI_RecordGetInteger(row
,6);
1129 sz
= IDENTIFIER_SIZE
;
1130 if (!MSI_RecordIsNull(row
,7))
1131 MSI_RecordGetStringW(row
,7,feature
->Directory
,&sz
);
1133 feature
->Attributes
= MSI_RecordGetInteger(row
,8);
1135 feature
->Installed
= INSTALLSTATE_ABSENT
;
1136 feature
->Action
= INSTALLSTATE_UNKNOWN
;
1137 feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1139 list_add_tail( &package
->features
, &feature
->entry
);
1141 /* load feature components */
1143 rc
= MSI_OpenQuery( package
->db
, &view
, Query1
, feature
->Feature
);
1144 if (rc
!= ERROR_SUCCESS
)
1145 return ERROR_SUCCESS
;
1147 ilfs
.package
= package
;
1148 ilfs
.feature
= feature
;
1150 MSI_IterateRecords(view
, NULL
, iterate_load_featurecomponents
, &ilfs
);
1151 msiobj_release(&view
->hdr
);
1153 return ERROR_SUCCESS
;
1156 static UINT
load_file(MSIRECORD
*row
, LPVOID param
)
1158 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
1162 /* fill in the data */
1164 file
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof (MSIFILE
) );
1166 return ERROR_NOT_ENOUGH_MEMORY
;
1168 file
->File
= load_dynamic_stringW( row
, 1 );
1170 component
= MSI_RecordGetString( row
, 2 );
1171 file
->Component
= get_loaded_component( package
, component
);
1173 if (!file
->Component
)
1174 ERR("Unfound Component %s\n",debugstr_w(component
));
1176 file
->FileName
= load_dynamic_stringW( row
, 3 );
1177 reduce_to_longfilename( file
->FileName
);
1179 file
->ShortName
= load_dynamic_stringW( row
, 3 );
1180 reduce_to_shortfilename( file
->ShortName
);
1182 file
->FileSize
= MSI_RecordGetInteger( row
, 4 );
1183 file
->Version
= load_dynamic_stringW( row
, 5 );
1184 file
->Language
= load_dynamic_stringW( row
, 6 );
1185 file
->Attributes
= MSI_RecordGetInteger( row
, 7 );
1186 file
->Sequence
= MSI_RecordGetInteger( row
, 8 );
1188 file
->Temporary
= FALSE
;
1191 TRACE("File Loaded (%s)\n",debugstr_w(file
->File
));
1193 list_add_tail( &package
->files
, &file
->entry
);
1195 return ERROR_SUCCESS
;
1198 static UINT
load_all_files(MSIPACKAGE
*package
)
1202 static const WCHAR Query
[] =
1203 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1204 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1205 '`','S','e','q','u','e','n','c','e','`', 0};
1208 return ERROR_INVALID_HANDLE
;
1210 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1211 if (rc
!= ERROR_SUCCESS
)
1212 return ERROR_SUCCESS
;
1214 rc
= MSI_IterateRecords(view
, NULL
, load_file
, package
);
1215 msiobj_release(&view
->hdr
);
1217 return ERROR_SUCCESS
;
1222 * I am not doing any of the costing functionality yet.
1223 * Mostly looking at doing the Component and Feature loading
1225 * The native MSI does A LOT of modification to tables here. Mostly adding
1226 * a lot of temporary columns to the Feature and Component tables.
1228 * note: Native msi also tracks the short filename. But I am only going to
1229 * track the long ones. Also looking at this directory table
1230 * it appears that the directory table does not get the parents
1231 * resolved base on property only based on their entries in the
1234 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1238 static const WCHAR Query_all
[] =
1239 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1240 '`','F','e','a','t','u','r','e','`',0};
1241 static const WCHAR szCosting
[] =
1242 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1243 static const WCHAR szZero
[] = { '0', 0 };
1247 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1249 return ERROR_SUCCESS
;
1251 MSI_SetPropertyW(package
, szCosting
, szZero
);
1252 MSI_SetPropertyW(package
, cszRootDrive
, c_colon
);
1254 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1255 if (rc
!= ERROR_SUCCESS
)
1258 rc
= MSI_IterateRecords(view
, NULL
, load_feature
, package
);
1259 msiobj_release(&view
->hdr
);
1261 load_all_files(package
);
1263 return ERROR_SUCCESS
;
1266 static UINT
execute_script(MSIPACKAGE
*package
, UINT script
)
1269 UINT rc
= ERROR_SUCCESS
;
1271 TRACE("Executing Script %i\n",script
);
1273 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
1276 action
= package
->script
->Actions
[script
][i
];
1277 ui_actionstart(package
, action
);
1278 TRACE("Executing Action (%s)\n",debugstr_w(action
));
1279 rc
= ACTION_PerformAction(package
, action
, TRUE
);
1280 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
][i
]);
1281 if (rc
!= ERROR_SUCCESS
)
1284 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
]);
1286 package
->script
->ActionCount
[script
] = 0;
1287 package
->script
->Actions
[script
] = NULL
;
1291 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1293 return ERROR_SUCCESS
;
1297 static MSIFOLDER
*load_folder( MSIPACKAGE
*package
, LPCWSTR dir
)
1299 static const WCHAR Query
[] =
1300 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1301 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1302 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1303 ' ','=',' ','\'','%','s','\'',
1305 LPWSTR ptargetdir
, targetdir
, srcdir
;
1307 LPWSTR shortname
= NULL
;
1308 MSIRECORD
* row
= 0;
1311 TRACE("Looking for dir %s\n",debugstr_w(dir
));
1313 folder
= get_loaded_folder( package
, dir
);
1317 TRACE("Working to load %s\n",debugstr_w(dir
));
1319 folder
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof (MSIFOLDER
) );
1323 folder
->Directory
= strdupW(dir
);
1325 row
= MSI_QueryGetRecord(package
->db
, Query
, dir
);
1329 ptargetdir
= targetdir
= load_dynamic_stringW(row
,3);
1331 /* split src and target dir */
1332 if (strchrW(targetdir
,':'))
1334 srcdir
=strchrW(targetdir
,':');
1341 /* for now only pick long filename versions */
1342 if (strchrW(targetdir
,'|'))
1344 shortname
= targetdir
;
1345 targetdir
= strchrW(targetdir
,'|');
1349 /* for the sourcedir pick the short filename */
1350 if (srcdir
&& strchrW(srcdir
,'|'))
1352 LPWSTR p
= strchrW(srcdir
,'|');
1356 /* now check for root dirs */
1357 if (targetdir
[0] == '.' && targetdir
[1] == 0)
1362 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir
));
1363 HeapFree(GetProcessHeap(),0, folder
->TargetDefault
);
1364 folder
->TargetDefault
= strdupW(targetdir
);
1368 folder
->SourceDefault
= strdupW(srcdir
);
1370 folder
->SourceDefault
= strdupW(shortname
);
1372 folder
->SourceDefault
= strdupW(targetdir
);
1373 HeapFree(GetProcessHeap(), 0, ptargetdir
);
1374 TRACE(" SourceDefault = %s\n", debugstr_w( folder
->SourceDefault
));
1376 parent
= MSI_RecordGetString(row
,2);
1379 folder
->Parent
= load_folder( package
, parent
);
1380 if ( folder
->Parent
)
1381 TRACE("loaded parent %p %s\n", folder
->Parent
,
1382 debugstr_w(folder
->Parent
->Directory
));
1384 ERR("failed to load parent folder %s\n", debugstr_w(parent
));
1387 folder
->Property
= load_dynamic_property( package
, dir
, NULL
);
1389 msiobj_release(&row
->hdr
);
1391 list_add_tail( &package
->folders
, &folder
->entry
);
1393 TRACE("%s returning %p\n",debugstr_w(dir
),folder
);
1398 /* scan for and update current install states */
1399 static void ACTION_UpdateInstallStates(MSIPACKAGE
*package
)
1402 MSIFEATURE
*feature
;
1404 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1407 res
= MsiGetComponentPathW( package
->ProductCode
,
1408 comp
->ComponentId
, NULL
, NULL
);
1410 res
= INSTALLSTATE_ABSENT
;
1411 comp
->Installed
= res
;
1414 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1417 INSTALLSTATE res
= -10;
1419 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1421 comp
= cl
->component
;
1424 res
= comp
->Installed
;
1427 if (res
== comp
->Installed
)
1430 if (res
!= comp
->Installed
)
1431 res
= INSTALLSTATE_INCOMPLETE
;
1434 feature
->Installed
= res
;
1438 static BOOL
process_state_property (MSIPACKAGE
* package
, LPCWSTR property
,
1441 static const WCHAR all
[]={'A','L','L',0};
1442 LPWSTR override
= NULL
;
1444 MSIFEATURE
*feature
;
1446 override
= load_dynamic_property(package
, property
, NULL
);
1450 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1452 if (strcmpiW(override
,all
)==0)
1454 feature
->ActionRequest
= state
;
1455 feature
->Action
= state
;
1459 LPWSTR ptr
= override
;
1460 LPWSTR ptr2
= strchrW(override
,',');
1465 strncmpW(ptr
,feature
->Feature
, ptr2
-ptr
)==0)
1466 || (!ptr2
&& strcmpW(ptr
,feature
->Feature
)==0))
1468 feature
->ActionRequest
= state
;
1469 feature
->Action
= state
;
1475 ptr2
= strchrW(ptr
,',');
1482 HeapFree(GetProcessHeap(),0,override
);
1488 static UINT
SetFeatureStates(MSIPACKAGE
*package
)
1492 static const WCHAR szlevel
[] =
1493 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1494 static const WCHAR szAddLocal
[] =
1495 {'A','D','D','L','O','C','A','L',0};
1496 static const WCHAR szRemove
[] =
1497 {'R','E','M','O','V','E',0};
1498 BOOL override
= FALSE
;
1499 MSICOMPONENT
* component
;
1500 MSIFEATURE
*feature
;
1503 /* I do not know if this is where it should happen.. but */
1505 TRACE("Checking Install Level\n");
1507 level
= load_dynamic_property(package
,szlevel
,NULL
);
1510 install_level
= atoiW(level
);
1511 HeapFree(GetProcessHeap(), 0, level
);
1516 /* ok hereis the _real_ rub
1517 * all these activation/deactivation things happen in order and things
1518 * later on the list override things earlier on the list.
1519 * 1) INSTALLLEVEL processing
1529 * 11) FILEADDDEFAULT
1530 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1531 * ignored for all the features. seems strange, especially since it is not
1532 * documented anywhere, but it is how it works.
1534 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1535 * REMOVE are the big ones, since we don't handle administrative installs
1538 override
|= process_state_property(package
,szAddLocal
,INSTALLSTATE_LOCAL
);
1539 override
|= process_state_property(package
,szRemove
,INSTALLSTATE_ABSENT
);
1543 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1545 BOOL feature_state
= ((feature
->Level
> 0) &&
1546 (feature
->Level
<= install_level
));
1548 if ((feature_state
) && (feature
->Action
== INSTALLSTATE_UNKNOWN
))
1550 if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1552 feature
->ActionRequest
= INSTALLSTATE_SOURCE
;
1553 feature
->Action
= INSTALLSTATE_SOURCE
;
1555 else if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1557 feature
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1558 feature
->Action
= INSTALLSTATE_ADVERTISED
;
1562 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1563 feature
->Action
= INSTALLSTATE_LOCAL
;
1570 /* set the Preselected Property */
1571 static const WCHAR szPreselected
[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1572 static const WCHAR szOne
[] = { '1', 0 };
1574 MSI_SetPropertyW(package
,szPreselected
,szOne
);
1578 * now we want to enable or disable components base on feature
1581 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1585 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1586 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
1587 feature
->ActionRequest
);
1589 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1591 component
= cl
->component
;
1593 if (!component
->Enabled
)
1595 component
->Action
= INSTALLSTATE_UNKNOWN
;
1596 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1600 if (feature
->Action
== INSTALLSTATE_LOCAL
)
1602 component
->Action
= INSTALLSTATE_LOCAL
;
1603 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1605 else if (feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1607 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1608 (component
->Action
== INSTALLSTATE_ABSENT
) ||
1609 (component
->Action
== INSTALLSTATE_ADVERTISED
))
1612 component
->Action
= INSTALLSTATE_SOURCE
;
1613 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1616 else if (feature
->ActionRequest
== INSTALLSTATE_ADVERTISED
)
1618 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1619 (component
->Action
== INSTALLSTATE_ABSENT
))
1622 component
->Action
= INSTALLSTATE_ADVERTISED
;
1623 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1626 else if (feature
->ActionRequest
== INSTALLSTATE_ABSENT
)
1628 if (component
->Action
== INSTALLSTATE_UNKNOWN
)
1630 component
->Action
= INSTALLSTATE_ABSENT
;
1631 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
1638 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1640 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1641 debugstr_w(component
->Component
), component
->Installed
,
1642 component
->Action
, component
->ActionRequest
);
1646 return ERROR_SUCCESS
;
1649 static UINT
ITERATE_CostFinalizeDirectories(MSIRECORD
*row
, LPVOID param
)
1651 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1655 name
= MSI_RecordGetString(row
,1);
1657 /* This helper function now does ALL the work */
1658 TRACE("Dir %s ...\n",debugstr_w(name
));
1659 load_folder(package
,name
);
1660 path
= resolve_folder(package
,name
,FALSE
,TRUE
,NULL
);
1661 TRACE("resolves to %s\n",debugstr_w(path
));
1662 HeapFree( GetProcessHeap(), 0, path
);
1664 return ERROR_SUCCESS
;
1667 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1669 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1671 MSIFEATURE
*feature
;
1673 name
= MSI_RecordGetString( row
, 1 );
1675 feature
= get_loaded_feature( package
, name
);
1677 ERR("FAILED to find loaded feature %s\n",debugstr_w(name
));
1681 Condition
= MSI_RecordGetString(row
,3);
1683 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
1685 int level
= MSI_RecordGetInteger(row
,2);
1686 TRACE("Reseting feature %s to level %i\n", debugstr_w(name
), level
);
1687 feature
->Level
= level
;
1690 return ERROR_SUCCESS
;
1695 * A lot is done in this function aside from just the costing.
1696 * The costing needs to be implemented at some point but for now I am going
1697 * to focus on the directory building
1700 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
1702 static const WCHAR ExecSeqQuery
[] =
1703 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1704 '`','D','i','r','e','c','t','o','r','y','`',0};
1705 static const WCHAR ConditionQuery
[] =
1706 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1707 '`','C','o','n','d','i','t','i','o','n','`',0};
1708 static const WCHAR szCosting
[] =
1709 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1710 static const WCHAR szlevel
[] =
1711 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1712 static const WCHAR szOne
[] = { '1', 0 };
1721 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1723 return ERROR_SUCCESS
;
1725 TRACE("Building Directory properties\n");
1727 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1728 if (rc
== ERROR_SUCCESS
)
1730 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeDirectories
,
1732 msiobj_release(&view
->hdr
);
1735 TRACE("File calculations\n");
1737 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
1739 MSICOMPONENT
* comp
= NULL
;
1741 comp
= file
->Component
;
1743 if (file
->Temporary
== TRUE
)
1750 /* calculate target */
1751 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
1753 HeapFree(GetProcessHeap(),0,file
->TargetPath
);
1755 TRACE("file %s is named %s\n",
1756 debugstr_w(file
->File
),debugstr_w(file
->FileName
));
1758 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
1760 HeapFree(GetProcessHeap(),0,p
);
1762 TRACE("file %s resolves to %s\n",
1763 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
1765 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
1768 comp
->Cost
+= file
->FileSize
;
1778 static const WCHAR name
[] =
1780 static const WCHAR name_fmt
[] =
1781 {'%','u','.','%','u','.','%','u','.','%','u',0};
1782 WCHAR filever
[0x100];
1783 VS_FIXEDFILEINFO
*lpVer
;
1785 TRACE("Version comparison.. \n");
1786 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
1787 version
= HeapAlloc(GetProcessHeap(),0,versize
);
1788 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
1790 VerQueryValueW(version
, name
, (LPVOID
*)&lpVer
, &sz
);
1792 sprintfW(filever
,name_fmt
,
1793 HIWORD(lpVer
->dwFileVersionMS
),
1794 LOWORD(lpVer
->dwFileVersionMS
),
1795 HIWORD(lpVer
->dwFileVersionLS
),
1796 LOWORD(lpVer
->dwFileVersionLS
));
1798 TRACE("new %s old %s\n", debugstr_w(file
->Version
),
1799 debugstr_w(filever
));
1800 if (strcmpiW(filever
,file
->Version
)<0)
1803 FIXME("cost should be diff in size\n");
1804 comp
->Cost
+= file
->FileSize
;
1808 HeapFree(GetProcessHeap(),0,version
);
1816 TRACE("Evaluating Condition Table\n");
1818 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
1819 if (rc
== ERROR_SUCCESS
)
1821 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeConditions
,
1823 msiobj_release(&view
->hdr
);
1826 TRACE("Enabling or Disabling Components\n");
1827 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1829 if (comp
->Condition
[0])
1831 if (MSI_EvaluateConditionW(package
,
1832 comp
->Condition
) == MSICONDITION_FALSE
)
1834 TRACE("Disabling component %s\n", debugstr_w(comp
->Component
));
1835 comp
->Enabled
= FALSE
;
1840 MSI_SetPropertyW(package
,szCosting
,szOne
);
1841 /* set default run level if not set */
1842 level
= load_dynamic_property(package
,szlevel
,NULL
);
1844 MSI_SetPropertyW(package
,szlevel
, szOne
);
1846 HeapFree(GetProcessHeap(),0,level
);
1848 ACTION_UpdateInstallStates(package
);
1850 return SetFeatureStates(package
);
1853 /* OK this value is "interpreted" and then formatted based on the
1854 first few characters */
1855 static LPSTR
parse_value(MSIPACKAGE
*package
, LPCWSTR value
, DWORD
*type
,
1859 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
1865 LPWSTR deformated
= NULL
;
1868 deformat_string(package
, &value
[2], &deformated
);
1870 /* binary value type */
1874 *size
= (strlenW(ptr
)/2)+1;
1876 *size
= strlenW(ptr
)/2;
1878 data
= HeapAlloc(GetProcessHeap(),0,*size
);
1884 /* if uneven pad with a zero in front */
1890 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1892 TRACE("Uneven byte count\n");
1900 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1903 HeapFree(GetProcessHeap(),0,deformated
);
1905 TRACE("Data %li bytes(%i)\n",*size
,count
);
1912 deformat_string(package
, &value
[1], &deformated
);
1915 *size
= sizeof(DWORD
);
1916 data
= HeapAlloc(GetProcessHeap(),0,*size
);
1922 if ( (*p
< '0') || (*p
> '9') )
1928 if (deformated
[0] == '-')
1931 TRACE("DWORD %li\n",*(LPDWORD
)data
);
1933 HeapFree(GetProcessHeap(),0,deformated
);
1938 static const WCHAR szMulti
[] = {'[','~',']',0};
1947 *type
=REG_EXPAND_SZ
;
1955 if (strstrW(value
,szMulti
))
1956 *type
= REG_MULTI_SZ
;
1958 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
1963 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
1965 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1966 static const WCHAR szHCR
[] =
1967 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1968 'R','O','O','T','\\',0};
1969 static const WCHAR szHCU
[] =
1970 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1971 'U','S','E','R','\\',0};
1972 static const WCHAR szHLM
[] =
1973 {'H','K','E','Y','_','L','O','C','A','L','_',
1974 'M','A','C','H','I','N','E','\\',0};
1975 static const WCHAR szHU
[] =
1976 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1978 LPSTR value_data
= NULL
;
1979 HKEY root_key
, hkey
;
1982 LPCWSTR szRoot
, component
, name
, key
, value
;
1987 BOOL check_first
= FALSE
;
1990 ui_progress(package
,2,0,0,0);
1997 component
= MSI_RecordGetString(row
, 6);
1998 comp
= get_loaded_component(package
,component
);
2000 return ERROR_SUCCESS
;
2002 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
2004 TRACE("Skipping write due to disabled component %s\n",
2005 debugstr_w(component
));
2007 comp
->Action
= comp
->Installed
;
2009 return ERROR_SUCCESS
;
2012 comp
->Action
= INSTALLSTATE_LOCAL
;
2014 name
= MSI_RecordGetString(row
, 4);
2015 if( MSI_RecordIsNull(row
,5) && name
)
2017 /* null values can have special meanings */
2018 if (name
[0]=='-' && name
[1] == 0)
2019 return ERROR_SUCCESS
;
2020 else if ((name
[0]=='+' && name
[1] == 0) ||
2021 (name
[0] == '*' && name
[1] == 0))
2026 root
= MSI_RecordGetInteger(row
,2);
2027 key
= MSI_RecordGetString(row
, 3);
2029 /* get the root key */
2034 static const WCHAR szALLUSER
[] = {'A','L','L','U','S','E','R','S',0};
2035 LPWSTR all_users
= load_dynamic_property(package
, szALLUSER
, NULL
);
2036 if (all_users
&& all_users
[0] == '1')
2038 root_key
= HKEY_LOCAL_MACHINE
;
2043 root_key
= HKEY_CURRENT_USER
;
2046 HeapFree(GetProcessHeap(),0,all_users
);
2049 case 0: root_key
= HKEY_CLASSES_ROOT
;
2052 case 1: root_key
= HKEY_CURRENT_USER
;
2055 case 2: root_key
= HKEY_LOCAL_MACHINE
;
2058 case 3: root_key
= HKEY_USERS
;
2062 ERR("Unknown root %i\n",root
);
2068 return ERROR_SUCCESS
;
2070 deformat_string(package
, key
, &deformated
);
2071 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
2072 uikey
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(WCHAR
));
2073 strcpyW(uikey
,szRoot
);
2074 strcatW(uikey
,deformated
);
2076 if (RegCreateKeyW( root_key
, deformated
, &hkey
))
2078 ERR("Could not create key %s\n",debugstr_w(deformated
));
2079 HeapFree(GetProcessHeap(),0,deformated
);
2080 HeapFree(GetProcessHeap(),0,uikey
);
2081 return ERROR_SUCCESS
;
2083 HeapFree(GetProcessHeap(),0,deformated
);
2085 value
= MSI_RecordGetString(row
,5);
2087 value_data
= parse_value(package
, value
, &type
, &size
);
2090 static const WCHAR szEmpty
[] = {0};
2091 value_data
= (LPSTR
)strdupW(szEmpty
);
2096 deformat_string(package
, name
, &deformated
);
2098 /* get the double nulls to terminate SZ_MULTI */
2099 if (type
== REG_MULTI_SZ
)
2100 size
+=sizeof(WCHAR
);
2104 TRACE("Setting value %s of %s\n",debugstr_w(deformated
),
2106 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
)value_data
, size
);
2111 rc
= RegQueryValueExW(hkey
, deformated
, NULL
, NULL
, NULL
, &sz
);
2112 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
2114 TRACE("value %s of %s checked already exists\n",
2115 debugstr_w(deformated
), debugstr_w(uikey
));
2119 TRACE("Checked and setting value %s of %s\n",
2120 debugstr_w(deformated
), debugstr_w(uikey
));
2121 if (deformated
|| size
)
2122 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
) value_data
, size
);
2127 uirow
= MSI_CreateRecord(3);
2128 MSI_RecordSetStringW(uirow
,2,deformated
);
2129 MSI_RecordSetStringW(uirow
,1,uikey
);
2132 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2134 MSI_RecordSetStringW(uirow
,3,value
);
2136 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2137 msiobj_release( &uirow
->hdr
);
2139 HeapFree(GetProcessHeap(),0,value_data
);
2140 HeapFree(GetProcessHeap(),0,deformated
);
2141 HeapFree(GetProcessHeap(),0,uikey
);
2143 return ERROR_SUCCESS
;
2146 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2150 static const WCHAR ExecSeqQuery
[] =
2151 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2152 '`','R','e','g','i','s','t','r','y','`',0 };
2155 return ERROR_INVALID_HANDLE
;
2157 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2158 if (rc
!= ERROR_SUCCESS
)
2159 return ERROR_SUCCESS
;
2161 /* increment progress bar each time action data is sent */
2162 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
2164 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2166 msiobj_release(&view
->hdr
);
2170 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
2172 package
->script
->CurrentlyScripting
= TRUE
;
2174 return ERROR_SUCCESS
;
2178 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
2183 static const WCHAR q1
[]=
2184 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2185 '`','R','e','g','i','s','t','r','y','`',0};
2188 MSIRECORD
* row
= 0;
2189 MSIFEATURE
*feature
;
2192 TRACE(" InstallValidate \n");
2194 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
2195 if (rc
!= ERROR_SUCCESS
)
2196 return ERROR_SUCCESS
;
2198 rc
= MSI_ViewExecute(view
, 0);
2199 if (rc
!= ERROR_SUCCESS
)
2201 MSI_ViewClose(view
);
2202 msiobj_release(&view
->hdr
);
2207 rc
= MSI_ViewFetch(view
,&row
);
2208 if (rc
!= ERROR_SUCCESS
)
2215 msiobj_release(&row
->hdr
);
2217 MSI_ViewClose(view
);
2218 msiobj_release(&view
->hdr
);
2220 total
= total
+ progress
* REG_PROGRESS_VALUE
;
2221 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2223 total
+= COMPONENT_PROGRESS_VALUE
;
2225 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2227 total
+= file
->FileSize
;
2229 ui_progress(package
,0,total
,0,0);
2231 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2233 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2234 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
2235 feature
->ActionRequest
);
2238 return ERROR_SUCCESS
;
2241 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
2243 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2244 LPCWSTR cond
= NULL
;
2245 LPCWSTR message
= NULL
;
2246 static const WCHAR title
[]=
2247 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2249 cond
= MSI_RecordGetString(row
,1);
2251 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
2254 message
= MSI_RecordGetString(row
,2);
2255 deformat_string(package
,message
,&deformated
);
2256 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
2257 HeapFree(GetProcessHeap(),0,deformated
);
2258 return ERROR_FUNCTION_FAILED
;
2261 return ERROR_SUCCESS
;
2264 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
2267 MSIQUERY
* view
= NULL
;
2268 static const WCHAR ExecSeqQuery
[] =
2269 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2270 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2272 TRACE("Checking launch conditions\n");
2274 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2275 if (rc
!= ERROR_SUCCESS
)
2276 return ERROR_SUCCESS
;
2278 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
2279 msiobj_release(&view
->hdr
);
2284 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, MSICOMPONENT
*cmp
)
2287 if (cmp
->KeyPath
[0]==0)
2289 LPWSTR p
= resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,NULL
);
2292 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
2294 MSIRECORD
* row
= 0;
2296 LPWSTR deformated
,buffer
,deformated_name
;
2298 static const WCHAR ExecSeqQuery
[] =
2299 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2300 '`','R','e','g','i','s','t','r','y','`',' ',
2301 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2302 ' ','=',' ' ,'\'','%','s','\'',0 };
2303 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
2304 static const WCHAR fmt2
[]=
2305 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2307 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
,cmp
->KeyPath
);
2311 root
= MSI_RecordGetInteger(row
,2);
2312 key
= MSI_RecordGetString(row
, 3);
2313 name
= MSI_RecordGetString(row
, 4);
2314 deformat_string(package
, key
, &deformated
);
2315 deformat_string(package
, name
, &deformated_name
);
2317 len
= strlenW(deformated
) + 6;
2318 if (deformated_name
)
2319 len
+=strlenW(deformated_name
);
2321 buffer
= HeapAlloc(GetProcessHeap(),0, len
*sizeof(WCHAR
));
2323 if (deformated_name
)
2324 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
2326 sprintfW(buffer
,fmt
,root
,deformated
);
2328 HeapFree(GetProcessHeap(),0,deformated
);
2329 HeapFree(GetProcessHeap(),0,deformated_name
);
2330 msiobj_release(&row
->hdr
);
2334 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2336 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2341 MSIFILE
*file
= get_loaded_file( package
, cmp
->KeyPath
);
2344 return strdupW( file
->TargetPath
);
2349 static HKEY
openSharedDLLsKey(void)
2352 static const WCHAR path
[] =
2353 {'S','o','f','t','w','a','r','e','\\',
2354 'M','i','c','r','o','s','o','f','t','\\',
2355 'W','i','n','d','o','w','s','\\',
2356 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2357 'S','h','a','r','e','d','D','L','L','s',0};
2359 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
2363 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
2368 DWORD sz
= sizeof(count
);
2371 hkey
= openSharedDLLsKey();
2372 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
2373 if (rc
!= ERROR_SUCCESS
)
2379 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
2383 hkey
= openSharedDLLsKey();
2385 RegSetValueExW(hkey
,path
,0,REG_DWORD
,
2386 (LPBYTE
)&count
,sizeof(count
));
2388 RegDeleteValueW(hkey
,path
);
2394 * Return TRUE if the count should be written out and FALSE if not
2396 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, MSICOMPONENT
*comp
)
2398 MSIFEATURE
*feature
;
2402 /* only refcount DLLs */
2403 if (comp
->KeyPath
[0]==0 ||
2404 comp
->Attributes
& msidbComponentAttributesRegistryKeyPath
||
2405 comp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2409 count
= ACTION_GetSharedDLLsCount( comp
->FullKeypath
);
2410 write
= (count
> 0);
2412 if (comp
->Attributes
& msidbComponentAttributesSharedDllRefCount
)
2416 /* increment counts */
2417 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2421 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_LOCAL
))
2424 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
2426 if ( cl
->component
== comp
)
2431 /* decrement counts */
2432 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2436 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_ABSENT
))
2439 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
2441 if ( cl
->component
== comp
)
2446 /* ref count all the files in the component */
2451 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2453 if (file
->Temporary
)
2455 if (file
->Component
== comp
)
2456 ACTION_WriteSharedDLLsCount( file
->TargetPath
, count
);
2460 /* add a count for permenent */
2461 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
2464 comp
->RefCount
= count
;
2467 ACTION_WriteSharedDLLsCount( comp
->FullKeypath
, comp
->RefCount
);
2471 * Ok further analysis makes me think that this work is
2472 * actually done in the PublishComponents and PublishFeatures
2473 * step, and not here. It appears like the keypath and all that is
2474 * resolved in this step, however actually written in the Publish steps.
2475 * But we will leave it here for now because it is unclear
2477 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
2479 WCHAR squished_pc
[GUID_SIZE
];
2480 WCHAR squished_cc
[GUID_SIZE
];
2483 HKEY hkey
=0,hkey2
=0;
2486 return ERROR_INVALID_HANDLE
;
2488 /* writes the Component and Features values to the registry */
2490 rc
= MSIREG_OpenComponents(&hkey
);
2491 if (rc
!= ERROR_SUCCESS
)
2494 squash_guid(package
->ProductCode
,squished_pc
);
2495 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
2497 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2499 ui_progress(package
,2,0,0,0);
2500 if (comp
->ComponentId
[0]!=0)
2502 WCHAR
*keypath
= NULL
;
2505 squash_guid(comp
->ComponentId
,squished_cc
);
2507 keypath
= resolve_keypath( package
, comp
);
2508 comp
->FullKeypath
= keypath
;
2510 /* do the refcounting */
2511 ACTION_RefCountComponent( package
, comp
);
2513 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2514 debugstr_w(comp
->Component
),
2515 debugstr_w(squished_cc
),
2516 debugstr_w(comp
->FullKeypath
),
2519 * Write the keypath out if the component is to be registered
2520 * and delete the key if the component is to be deregistered
2522 if (ACTION_VerifyComponentForAction(package
, comp
,
2523 INSTALLSTATE_LOCAL
))
2525 rc
= RegCreateKeyW(hkey
,squished_cc
,&hkey2
);
2526 if (rc
!= ERROR_SUCCESS
)
2531 RegSetValueExW(hkey2
,squished_pc
,0,REG_SZ
,(LPBYTE
)keypath
,
2532 (strlenW(keypath
)+1)*sizeof(WCHAR
));
2534 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
2536 static const WCHAR szPermKey
[] =
2537 { '0','0','0','0','0','0','0','0','0','0','0','0',
2538 '0','0','0','0','0','0','0', '0','0','0','0','0',
2539 '0','0','0','0','0','0','0','0',0};
2541 RegSetValueExW(hkey2
,szPermKey
,0,REG_SZ
,
2543 (strlenW(keypath
)+1)*sizeof(WCHAR
));
2549 uirow
= MSI_CreateRecord(3);
2550 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
2551 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
2552 MSI_RecordSetStringW(uirow
,3,keypath
);
2553 ui_actiondata(package
,szProcessComponents
,uirow
);
2554 msiobj_release( &uirow
->hdr
);
2557 else if (ACTION_VerifyComponentForAction(package
, comp
,
2558 INSTALLSTATE_ABSENT
))
2562 rc
= RegOpenKeyW(hkey
,squished_cc
,&hkey2
);
2563 if (rc
!= ERROR_SUCCESS
)
2566 RegDeleteValueW(hkey2
,squished_pc
);
2568 /* if the key is empty delete it */
2569 res
= RegEnumKeyExW(hkey2
,0,NULL
,0,0,NULL
,0,NULL
);
2571 if (res
== ERROR_NO_MORE_ITEMS
)
2572 RegDeleteKeyW(hkey
,squished_cc
);
2575 uirow
= MSI_CreateRecord(2);
2576 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
2577 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
2578 ui_actiondata(package
,szProcessComponents
,uirow
);
2579 msiobj_release( &uirow
->hdr
);
2596 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
2597 LPWSTR lpszName
, LONG_PTR lParam
)
2600 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
2601 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
2605 if (!IS_INTRESOURCE(lpszName
))
2607 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
2611 sz
= strlenW(tl_struct
->source
)+4;
2612 sz
*= sizeof(WCHAR
);
2614 if ((INT
)lpszName
== 1)
2615 tl_struct
->path
= strdupW(tl_struct
->source
);
2618 tl_struct
->path
= HeapAlloc(GetProcessHeap(),0,sz
);
2619 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
2622 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
2623 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
2624 if (!SUCCEEDED(res
))
2626 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
2627 tl_struct
->path
= NULL
;
2632 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
2633 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
2635 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2639 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
2640 tl_struct
->path
= NULL
;
2642 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2643 ITypeLib_Release(tl_struct
->ptLib
);
2648 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
2650 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2654 typelib_struct tl_struct
;
2656 static const WCHAR szTYPELIB
[] = {'T','Y','P','E','L','I','B',0};
2658 component
= MSI_RecordGetString(row
,3);
2659 comp
= get_loaded_component(package
,component
);
2661 return ERROR_SUCCESS
;
2663 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
2665 TRACE("Skipping typelib reg due to disabled component\n");
2667 comp
->Action
= comp
->Installed
;
2669 return ERROR_SUCCESS
;
2672 comp
->Action
= INSTALLSTATE_LOCAL
;
2674 file
= get_loaded_file( package
, comp
->KeyPath
);
2676 return ERROR_SUCCESS
;
2678 module
= LoadLibraryExW( file
->TargetPath
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
2682 guid
= load_dynamic_stringW(row
,1);
2683 CLSIDFromString(guid
, &tl_struct
.clsid
);
2684 HeapFree(GetProcessHeap(),0,guid
);
2685 tl_struct
.source
= strdupW( file
->TargetPath
);
2686 tl_struct
.path
= NULL
;
2688 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
2689 (LONG_PTR
)&tl_struct
);
2691 if (tl_struct
.path
!= NULL
)
2697 helpid
= MSI_RecordGetString(row
,6);
2700 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,NULL
);
2701 res
= RegisterTypeLib(tl_struct
.ptLib
,tl_struct
.path
,help
);
2702 HeapFree(GetProcessHeap(),0,help
);
2704 if (!SUCCEEDED(res
))
2705 ERR("Failed to register type library %s\n",
2706 debugstr_w(tl_struct
.path
));
2709 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
2711 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
2714 ITypeLib_Release(tl_struct
.ptLib
);
2715 HeapFree(GetProcessHeap(),0,tl_struct
.path
);
2718 ERR("Failed to load type library %s\n",
2719 debugstr_w(tl_struct
.source
));
2721 FreeLibrary(module
);
2722 HeapFree(GetProcessHeap(),0,tl_struct
.source
);
2725 ERR("Could not load file! %s\n", debugstr_w(file
->TargetPath
));
2727 return ERROR_SUCCESS
;
2730 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
2733 * OK this is a bit confusing.. I am given a _Component key and I believe
2734 * that the file that is being registered as a type library is the "key file
2735 * of that component" which I interpret to mean "The file in the KeyPath of
2740 static const WCHAR Query
[] =
2741 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2742 '`','T','y','p','e','L','i','b','`',0};
2745 return ERROR_INVALID_HANDLE
;
2747 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2748 if (rc
!= ERROR_SUCCESS
)
2749 return ERROR_SUCCESS
;
2751 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
2752 msiobj_release(&view
->hdr
);
2756 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
2758 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
2759 LPWSTR target_file
, target_folder
;
2761 WCHAR filename
[0x100];
2764 static const WCHAR szlnk
[]={'.','l','n','k',0};
2769 buffer
= MSI_RecordGetString(row
,4);
2770 comp
= get_loaded_component(package
,buffer
);
2772 return ERROR_SUCCESS
;
2774 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
2776 TRACE("Skipping shortcut creation due to disabled component\n");
2778 comp
->Action
= comp
->Installed
;
2780 return ERROR_SUCCESS
;
2783 comp
->Action
= INSTALLSTATE_LOCAL
;
2785 ui_actiondata(package
,szCreateShortcuts
,row
);
2787 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
2788 &IID_IShellLinkW
, (LPVOID
*) &sl
);
2792 ERR("Is IID_IShellLink\n");
2793 return ERROR_SUCCESS
;
2796 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
2799 ERR("Is IID_IPersistFile\n");
2800 return ERROR_SUCCESS
;
2803 buffer
= MSI_RecordGetString(row
,2);
2804 target_folder
= resolve_folder(package
, buffer
,FALSE
,FALSE
,NULL
);
2806 /* may be needed because of a bug somehwere else */
2807 create_full_pathW(target_folder
);
2810 MSI_RecordGetStringW(row
,3,filename
,&sz
);
2811 reduce_to_longfilename(filename
);
2812 if (!strchrW(filename
,'.') || strcmpiW(strchrW(filename
,'.'),szlnk
))
2813 strcatW(filename
,szlnk
);
2814 target_file
= build_directory_name(2, target_folder
, filename
);
2815 HeapFree(GetProcessHeap(),0,target_folder
);
2817 buffer
= MSI_RecordGetString(row
,5);
2818 if (strchrW(buffer
,'['))
2821 deformat_string(package
,buffer
,&deformated
);
2822 IShellLinkW_SetPath(sl
,deformated
);
2823 HeapFree(GetProcessHeap(),0,deformated
);
2828 FIXME("poorly handled shortcut format, advertised shortcut\n");
2829 keypath
= strdupW( comp
->FullKeypath
);
2830 IShellLinkW_SetPath(sl
,keypath
);
2831 HeapFree(GetProcessHeap(),0,keypath
);
2834 if (!MSI_RecordIsNull(row
,6))
2837 buffer
= MSI_RecordGetString(row
,6);
2838 deformat_string(package
,buffer
,&deformated
);
2839 IShellLinkW_SetArguments(sl
,deformated
);
2840 HeapFree(GetProcessHeap(),0,deformated
);
2843 if (!MSI_RecordIsNull(row
,7))
2845 buffer
= MSI_RecordGetString(row
,7);
2846 IShellLinkW_SetDescription(sl
,buffer
);
2849 if (!MSI_RecordIsNull(row
,8))
2850 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
2852 if (!MSI_RecordIsNull(row
,9))
2857 buffer
= MSI_RecordGetString(row
,9);
2859 build_icon_path(package
,buffer
,&Path
);
2860 index
= MSI_RecordGetInteger(row
,10);
2862 IShellLinkW_SetIconLocation(sl
,Path
,index
);
2863 HeapFree(GetProcessHeap(),0,Path
);
2866 if (!MSI_RecordIsNull(row
,11))
2867 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
2869 if (!MSI_RecordIsNull(row
,12))
2872 buffer
= MSI_RecordGetString(row
,12);
2873 Path
= resolve_folder(package
, buffer
, FALSE
, FALSE
, NULL
);
2874 IShellLinkW_SetWorkingDirectory(sl
,Path
);
2875 HeapFree(GetProcessHeap(), 0, Path
);
2878 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
2879 IPersistFile_Save(pf
,target_file
,FALSE
);
2881 HeapFree(GetProcessHeap(),0,target_file
);
2883 IPersistFile_Release( pf
);
2884 IShellLinkW_Release( sl
);
2886 return ERROR_SUCCESS
;
2889 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
2894 static const WCHAR Query
[] =
2895 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2896 '`','S','h','o','r','t','c','u','t','`',0};
2899 return ERROR_INVALID_HANDLE
;
2901 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2902 if (rc
!= ERROR_SUCCESS
)
2903 return ERROR_SUCCESS
;
2905 res
= CoInitialize( NULL
);
2908 ERR("CoInitialize failed\n");
2909 return ERROR_FUNCTION_FAILED
;
2912 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
2913 msiobj_release(&view
->hdr
);
2920 static UINT
ITERATE_PublishProduct(MSIRECORD
*row
, LPVOID param
)
2922 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2924 LPWSTR FilePath
=NULL
;
2925 LPCWSTR FileName
=NULL
;
2930 FileName
= MSI_RecordGetString(row
,1);
2933 ERR("Unable to get FileName\n");
2934 return ERROR_SUCCESS
;
2937 build_icon_path(package
,FileName
,&FilePath
);
2939 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
2941 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2942 FILE_ATTRIBUTE_NORMAL
, NULL
);
2944 if (the_file
== INVALID_HANDLE_VALUE
)
2946 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
2947 HeapFree(GetProcessHeap(),0,FilePath
);
2948 return ERROR_SUCCESS
;
2955 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
2956 if (rc
!= ERROR_SUCCESS
)
2958 ERR("Failed to get stream\n");
2959 CloseHandle(the_file
);
2960 DeleteFileW(FilePath
);
2963 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
2964 } while (sz
== 1024);
2966 HeapFree(GetProcessHeap(),0,FilePath
);
2968 CloseHandle(the_file
);
2969 return ERROR_SUCCESS
;
2973 * 99% of the work done here is only done for
2974 * advertised installs. However this is where the
2975 * Icon table is processed and written out
2976 * so that is what I am going to do here.
2978 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
2982 static const WCHAR Query
[]=
2983 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2984 '`','I','c','o','n','`',0};
2985 /* for registry stuff */
2988 static const WCHAR szProductLanguage
[] =
2989 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
2990 static const WCHAR szARPProductIcon
[] =
2991 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
2992 static const WCHAR szProductVersion
[] =
2993 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
2997 MSIHANDLE hDb
, hSumInfo
;
3000 return ERROR_INVALID_HANDLE
;
3002 /* write out icon files */
3004 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3005 if (rc
== ERROR_SUCCESS
)
3007 MSI_IterateRecords(view
, NULL
, ITERATE_PublishProduct
, package
);
3008 msiobj_release(&view
->hdr
);
3011 /* ok there is a lot more done here but i need to figure out what */
3013 rc
= MSIREG_OpenProductsKey(package
->ProductCode
,&hkey
,TRUE
);
3014 if (rc
!= ERROR_SUCCESS
)
3017 rc
= MSIREG_OpenUserProductsKey(package
->ProductCode
,&hukey
,TRUE
);
3018 if (rc
!= ERROR_SUCCESS
)
3022 buffer
= load_dynamic_property(package
,INSTALLPROPERTY_PRODUCTNAMEW
,NULL
);
3023 size
= strlenW(buffer
)*sizeof(WCHAR
);
3024 RegSetValueExW(hukey
,INSTALLPROPERTY_PRODUCTNAMEW
,0,REG_SZ
,
3025 (LPBYTE
)buffer
,size
);
3026 HeapFree(GetProcessHeap(),0,buffer
);
3028 buffer
= load_dynamic_property(package
,szProductLanguage
,NULL
);
3029 size
= sizeof(DWORD
);
3030 langid
= atoiW(buffer
);
3031 RegSetValueExW(hukey
,INSTALLPROPERTY_LANGUAGEW
,0,REG_DWORD
,
3032 (LPBYTE
)&langid
,size
);
3033 HeapFree(GetProcessHeap(),0,buffer
);
3035 buffer
= load_dynamic_property(package
,szARPProductIcon
,NULL
);
3039 build_icon_path(package
,buffer
,&path
);
3040 size
= strlenW(path
) * sizeof(WCHAR
);
3041 RegSetValueExW(hukey
,INSTALLPROPERTY_PRODUCTICONW
,0,REG_SZ
,
3044 HeapFree(GetProcessHeap(),0,buffer
);
3046 buffer
= load_dynamic_property(package
,szProductVersion
,NULL
);
3049 DWORD verdword
= build_version_dword(buffer
);
3050 size
= sizeof(DWORD
);
3051 RegSetValueExW(hukey
,INSTALLPROPERTY_VERSIONW
,0,REG_DWORD
, (LPBYTE
3054 HeapFree(GetProcessHeap(),0,buffer
);
3056 FIXME("Need to write more keys to the user registry\n");
3058 hDb
= alloc_msihandle( &package
->db
->hdr
);
3059 rc
= MsiGetSummaryInformationW(hDb
, NULL
, 0, &hSumInfo
);
3060 MsiCloseHandle(hDb
);
3061 if (rc
== ERROR_SUCCESS
)
3063 WCHAR guidbuffer
[0x200];
3065 rc
= MsiSummaryInfoGetPropertyW(hSumInfo
, 9, NULL
, NULL
, NULL
,
3067 if (rc
== ERROR_SUCCESS
)
3069 WCHAR squashed
[GUID_SIZE
];
3070 /* for now we only care about the first guid */
3071 LPWSTR ptr
= strchrW(guidbuffer
,';');
3073 squash_guid(guidbuffer
,squashed
);
3074 size
= strlenW(squashed
)*sizeof(WCHAR
);
3075 RegSetValueExW(hukey
,INSTALLPROPERTY_PACKAGECODEW
,0,REG_SZ
,
3076 (LPBYTE
)squashed
, size
);
3080 ERR("Unable to query Revision_Number... \n");
3083 MsiCloseHandle(hSumInfo
);
3087 ERR("Unable to open Summary Information\n");
3099 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
3101 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3102 LPCWSTR component
,section
,key
,value
,identifier
,filename
,dirproperty
;
3103 LPWSTR deformated_section
, deformated_key
, deformated_value
;
3104 LPWSTR folder
, fullname
= NULL
;
3108 static const WCHAR szWindowsFolder
[] =
3109 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3111 component
= MSI_RecordGetString(row
, 8);
3112 comp
= get_loaded_component(package
,component
);
3114 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
3116 TRACE("Skipping ini file due to disabled component %s\n",
3117 debugstr_w(component
));
3119 comp
->Action
= comp
->Installed
;
3121 return ERROR_SUCCESS
;
3124 comp
->Action
= INSTALLSTATE_LOCAL
;
3126 identifier
= MSI_RecordGetString(row
,1);
3127 filename
= MSI_RecordGetString(row
,2);
3128 dirproperty
= MSI_RecordGetString(row
,3);
3129 section
= MSI_RecordGetString(row
,4);
3130 key
= MSI_RecordGetString(row
,5);
3131 value
= MSI_RecordGetString(row
,6);
3132 action
= MSI_RecordGetInteger(row
,7);
3134 deformat_string(package
,section
,&deformated_section
);
3135 deformat_string(package
,key
,&deformated_key
);
3136 deformat_string(package
,value
,&deformated_value
);
3140 folder
= resolve_folder(package
, dirproperty
, FALSE
, FALSE
, NULL
);
3142 folder
= load_dynamic_property(package
,dirproperty
,NULL
);
3145 folder
= load_dynamic_property(package
, szWindowsFolder
, NULL
);
3149 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty
));
3153 fullname
= build_directory_name(2, folder
, filename
);
3157 TRACE("Adding value %s to section %s in %s\n",
3158 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3159 debugstr_w(fullname
));
3160 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3161 deformated_value
, fullname
);
3163 else if (action
== 1)
3166 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
3167 returned
, 10, fullname
);
3168 if (returned
[0] == 0)
3170 TRACE("Adding value %s to section %s in %s\n",
3171 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3172 debugstr_w(fullname
));
3174 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3175 deformated_value
, fullname
);
3178 else if (action
== 3)
3179 FIXME("Append to existing section not yet implemented\n");
3181 uirow
= MSI_CreateRecord(4);
3182 MSI_RecordSetStringW(uirow
,1,identifier
);
3183 MSI_RecordSetStringW(uirow
,2,deformated_section
);
3184 MSI_RecordSetStringW(uirow
,3,deformated_key
);
3185 MSI_RecordSetStringW(uirow
,4,deformated_value
);
3186 ui_actiondata(package
,szWriteIniValues
,uirow
);
3187 msiobj_release( &uirow
->hdr
);
3189 HeapFree(GetProcessHeap(),0,fullname
);
3190 HeapFree(GetProcessHeap(),0,folder
);
3191 HeapFree(GetProcessHeap(),0,deformated_key
);
3192 HeapFree(GetProcessHeap(),0,deformated_value
);
3193 HeapFree(GetProcessHeap(),0,deformated_section
);
3194 return ERROR_SUCCESS
;
3197 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
3201 static const WCHAR ExecSeqQuery
[] =
3202 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3203 '`','I','n','i','F','i','l','e','`',0};
3205 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3206 if (rc
!= ERROR_SUCCESS
)
3208 TRACE("no IniFile table\n");
3209 return ERROR_SUCCESS
;
3212 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
3213 msiobj_release(&view
->hdr
);
3217 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
3219 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3224 static const WCHAR ExeStr
[] =
3225 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3226 static const WCHAR close
[] = {'\"',0};
3228 PROCESS_INFORMATION info
;
3231 memset(&si
,0,sizeof(STARTUPINFOW
));
3233 filename
= MSI_RecordGetString(row
,1);
3234 file
= get_loaded_file( package
, filename
);
3238 ERR("Unable to find file id %s\n",debugstr_w(filename
));
3239 return ERROR_SUCCESS
;
3242 len
= strlenW(ExeStr
) + strlenW( file
->TargetPath
) + 2;
3244 FullName
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
3245 strcpyW(FullName
,ExeStr
);
3246 strcatW( FullName
, file
->TargetPath
);
3247 strcatW(FullName
,close
);
3249 TRACE("Registering %s\n",debugstr_w(FullName
));
3250 brc
= CreateProcessW(NULL
, FullName
, NULL
, NULL
, FALSE
, 0, NULL
, c_colon
,
3254 msi_dialog_check_messages(info
.hProcess
);
3256 HeapFree(GetProcessHeap(),0,FullName
);
3257 return ERROR_SUCCESS
;
3260 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
3264 static const WCHAR ExecSeqQuery
[] =
3265 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3266 '`','S','e','l','f','R','e','g','`',0};
3268 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3269 if (rc
!= ERROR_SUCCESS
)
3271 TRACE("no SelfReg table\n");
3272 return ERROR_SUCCESS
;
3275 MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
3276 msiobj_release(&view
->hdr
);
3278 return ERROR_SUCCESS
;
3281 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
3283 MSIFEATURE
*feature
;
3289 return ERROR_INVALID_HANDLE
;
3291 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
,&hkey
,TRUE
);
3292 if (rc
!= ERROR_SUCCESS
)
3295 rc
= MSIREG_OpenUserFeaturesKey(package
->ProductCode
,&hukey
,TRUE
);
3296 if (rc
!= ERROR_SUCCESS
)
3299 /* here the guids are base 85 encoded */
3300 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3306 BOOL absent
= FALSE
;
3308 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_LOCAL
) &&
3309 !ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_SOURCE
) &&
3310 !ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_ADVERTISED
))
3314 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3318 if (feature
->Feature_Parent
[0])
3319 size
+= strlenW( feature
->Feature_Parent
)+2;
3321 data
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
3324 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3326 MSICOMPONENT
* component
= cl
->component
;
3329 memset(buf
,0,sizeof(buf
));
3330 if ( component
->ComponentId
[0] )
3332 TRACE("From %s\n",debugstr_w(component
->ComponentId
));
3333 CLSIDFromString(component
->ComponentId
, &clsid
);
3334 encode_base85_guid(&clsid
,buf
);
3335 TRACE("to %s\n",debugstr_w(buf
));
3339 if (feature
->Feature_Parent
[0])
3341 static const WCHAR sep
[] = {'\2',0};
3343 strcatW(data
,feature
->Feature_Parent
);
3346 size
= (strlenW(data
)+1)*sizeof(WCHAR
);
3347 RegSetValueExW( hkey
, feature
->Feature
, 0, REG_SZ
, (LPBYTE
)data
,size
);
3348 HeapFree(GetProcessHeap(),0,data
);
3352 size
= strlenW(feature
->Feature_Parent
)*sizeof(WCHAR
);
3353 RegSetValueExW(hukey
,feature
->Feature
,0,REG_SZ
,
3354 (LPBYTE
)feature
->Feature_Parent
,size
);
3358 size
= (strlenW(feature
->Feature_Parent
)+2)* sizeof(WCHAR
);
3359 data
= HeapAlloc(GetProcessHeap(),0,size
);
3361 strcpyW( &data
[1], feature
->Feature_Parent
);
3362 RegSetValueExW(hukey
,feature
->Feature
,0,REG_SZ
,
3364 HeapFree(GetProcessHeap(),0,data
);
3374 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
3377 LPWSTR buffer
= NULL
;
3380 static WCHAR szNONE
[] = {0};
3381 static const WCHAR szWindowsInstaler
[] =
3382 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3383 static const WCHAR szPropKeys
[][80] =
3385 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3386 {'A','R','P','C','O','N','T','A','C','T',0},
3387 {'A','R','P','C','O','M','M','E','N','T','S',0},
3388 {'P','r','o','d','u','c','t','N','a','m','e',0},
3389 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3390 {'A','R','P','H','E','L','P','L','I','N','K',0},
3391 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3392 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3393 {'S','o','u','r','c','e','D','i','r',0},
3394 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3395 {'A','R','P','R','E','A','D','M','E',0},
3396 {'A','R','P','S','I','Z','E',0},
3397 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3398 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3402 static const WCHAR szRegKeys
[][80] =
3404 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3405 {'C','o','n','t','a','c','t',0},
3406 {'C','o','m','m','e','n','t','s',0},
3407 {'D','i','s','p','l','a','y','N','a','m','e',0},
3408 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3409 {'H','e','l','p','L','i','n','k',0},
3410 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3411 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3412 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3413 {'P','u','b','l','i','s','h','e','r',0},
3414 {'R','e','a','d','m','e',0},
3415 {'S','i','z','e',0},
3416 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3417 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3421 static const WCHAR installerPathFmt
[] = {
3423 'I','n','s','t','a','l','l','e','r','\\',0};
3424 static const WCHAR fmt
[] = {
3426 'I','n','s','t','a','l','l','e','r','\\',
3427 '%','x','.','m','s','i',0};
3428 static const WCHAR szUpgradeCode
[] =
3429 {'U','p','g','r','a','d','e','C','o','d','e',0};
3430 static const WCHAR modpath_fmt
[] =
3431 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3432 static const WCHAR szModifyPath
[] =
3433 {'M','o','d','i','f','y','P','a','t','h',0};
3434 static const WCHAR szUninstallString
[] =
3435 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3436 static const WCHAR szEstimatedSize
[] =
3437 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3438 static const WCHAR szProductLanguage
[] =
3439 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3440 static const WCHAR szProductVersion
[] =
3441 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3444 static const WCHAR date_fmt
[] = {'%','i','%','i','%','i',0};
3445 LPWSTR upgrade_code
;
3446 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], packagefile
[MAX_PATH
];
3450 return ERROR_INVALID_HANDLE
;
3452 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
,&hkey
,TRUE
);
3453 if (rc
!= ERROR_SUCCESS
)
3456 /* dump all the info i can grab */
3457 FIXME("Flesh out more information \n");
3460 while (szPropKeys
[i
][0]!=0)
3462 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
3463 if (rc
!= ERROR_SUCCESS
)
3465 size
= strlenW(buffer
)*sizeof(WCHAR
);
3466 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPBYTE
)buffer
,size
);
3467 HeapFree(GetProcessHeap(),0,buffer
);
3473 RegSetValueExW(hkey
,szWindowsInstaler
,0,REG_DWORD
,(LPBYTE
)&rc
,size
);
3475 /* copy the package locally */
3476 num
= GetTickCount() & 0xffff;
3480 GetWindowsDirectoryW(windir
, sizeof(windir
) / sizeof(windir
[0]));
3481 snprintfW(packagefile
,sizeof(packagefile
)/sizeof(packagefile
[0]),fmt
,
3485 HANDLE handle
= CreateFileW(packagefile
,GENERIC_WRITE
, 0, NULL
,
3486 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
3487 if (handle
!= INVALID_HANDLE_VALUE
)
3489 CloseHandle(handle
);
3492 if (GetLastError() != ERROR_FILE_EXISTS
&&
3493 GetLastError() != ERROR_SHARING_VIOLATION
)
3495 if (!(++num
& 0xffff)) num
= 1;
3496 sprintfW(packagefile
,fmt
,num
);
3497 } while (num
!= start
);
3499 snprintfW(path
,sizeof(path
)/sizeof(path
[0]),installerPathFmt
,windir
);
3500 create_full_pathW(path
);
3501 TRACE("Copying to local package %s\n",debugstr_w(packagefile
));
3502 if (!CopyFileW(package
->msiFilePath
,packagefile
,FALSE
))
3503 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3504 debugstr_w(package
->msiFilePath
), debugstr_w(packagefile
),
3506 size
= strlenW(packagefile
)*sizeof(WCHAR
);
3507 RegSetValueExW(hkey
,INSTALLPROPERTY_LOCALPACKAGEW
,0,REG_SZ
,
3508 (LPBYTE
)packagefile
,size
);
3510 /* do ModifyPath and UninstallString */
3511 size
= deformat_string(package
,modpath_fmt
,&buffer
);
3512 RegSetValueExW(hkey
,szModifyPath
,0,REG_EXPAND_SZ
,(LPBYTE
)buffer
,size
);
3513 RegSetValueExW(hkey
,szUninstallString
,0,REG_EXPAND_SZ
,(LPBYTE
)buffer
,size
);
3514 HeapFree(GetProcessHeap(),0,buffer
);
3516 FIXME("Write real Estimated Size when we have it\n");
3518 RegSetValueExW(hkey
,szEstimatedSize
,0,REG_DWORD
,(LPBYTE
)&size
,sizeof(DWORD
));
3520 GetLocalTime(&systime
);
3521 size
= 9*sizeof(WCHAR
);
3522 buffer
= HeapAlloc(GetProcessHeap(),0,size
);
3523 sprintfW(buffer
,date_fmt
,systime
.wYear
,systime
.wMonth
,systime
.wDay
);
3524 size
= strlenW(buffer
)*sizeof(WCHAR
);
3525 RegSetValueExW(hkey
,INSTALLPROPERTY_INSTALLDATEW
,0,REG_SZ
,
3526 (LPBYTE
)buffer
,size
);
3527 HeapFree(GetProcessHeap(),0,buffer
);
3529 buffer
= load_dynamic_property(package
,szProductLanguage
,NULL
);
3530 size
= atoiW(buffer
);
3531 RegSetValueExW(hkey
,INSTALLPROPERTY_LANGUAGEW
,0,REG_DWORD
,
3532 (LPBYTE
)&size
,sizeof(DWORD
));
3533 HeapFree(GetProcessHeap(),1,buffer
);
3535 buffer
= load_dynamic_property(package
,szProductVersion
,NULL
);
3538 DWORD verdword
= build_version_dword(buffer
);
3539 DWORD vermajor
= verdword
>>24;
3540 DWORD verminor
= (verdword
>>16)&0x00FF;
3541 size
= sizeof(DWORD
);
3542 RegSetValueExW(hkey
,INSTALLPROPERTY_VERSIONW
,0,REG_DWORD
,
3543 (LPBYTE
)&verdword
,size
);
3544 RegSetValueExW(hkey
,INSTALLPROPERTY_VERSIONMAJORW
,0,REG_DWORD
,
3545 (LPBYTE
)&vermajor
,size
);
3546 RegSetValueExW(hkey
,INSTALLPROPERTY_VERSIONMINORW
,0,REG_DWORD
,
3547 (LPBYTE
)&verminor
,size
);
3549 HeapFree(GetProcessHeap(),0,buffer
);
3551 /* Handle Upgrade Codes */
3552 upgrade_code
= load_dynamic_property(package
,szUpgradeCode
, NULL
);
3557 MSIREG_OpenUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3558 squash_guid(package
->ProductCode
,squashed
);
3559 RegSetValueExW(hkey2
, squashed
, 0,REG_SZ
,NULL
,0);
3561 MSIREG_OpenUserUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3562 squash_guid(package
->ProductCode
,squashed
);
3563 RegSetValueExW(hkey2
, squashed
, 0,REG_SZ
,NULL
,0);
3566 HeapFree(GetProcessHeap(),0,upgrade_code
);
3572 return ERROR_SUCCESS
;
3575 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
3580 return ERROR_INVALID_HANDLE
;
3582 rc
= execute_script(package
,INSTALL_SCRIPT
);
3587 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
3592 return ERROR_INVALID_HANDLE
;
3594 /* turn off scheduleing */
3595 package
->script
->CurrentlyScripting
= FALSE
;
3597 /* first do the same as an InstallExecute */
3598 rc
= ACTION_InstallExecute(package
);
3599 if (rc
!= ERROR_SUCCESS
)
3602 /* then handle Commit Actions */
3603 rc
= execute_script(package
,COMMIT_SCRIPT
);
3608 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
3610 static const WCHAR RunOnce
[] = {
3611 'S','o','f','t','w','a','r','e','\\',
3612 'M','i','c','r','o','s','o','f','t','\\',
3613 'W','i','n','d','o','w','s','\\',
3614 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3615 'R','u','n','O','n','c','e',0};
3616 static const WCHAR InstallRunOnce
[] = {
3617 'S','o','f','t','w','a','r','e','\\',
3618 'M','i','c','r','o','s','o','f','t','\\',
3619 'W','i','n','d','o','w','s','\\',
3620 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3621 'I','n','s','t','a','l','l','e','r','\\',
3622 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3624 static const WCHAR msiexec_fmt
[] = {
3626 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3627 '\"','%','s','\"',0};
3628 static const WCHAR install_fmt
[] = {
3629 '/','I',' ','\"','%','s','\"',' ',
3630 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3631 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3632 WCHAR buffer
[256], sysdir
[MAX_PATH
];
3634 WCHAR squished_pc
[100];
3638 return ERROR_INVALID_HANDLE
;
3640 squash_guid(package
->ProductCode
,squished_pc
);
3642 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
3643 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
3644 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
3647 size
= strlenW(buffer
)*sizeof(WCHAR
);
3648 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPBYTE
)buffer
,size
);
3651 TRACE("Reboot command %s\n",debugstr_w(buffer
));
3653 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
3654 sprintfW(buffer
,install_fmt
,package
->ProductCode
,squished_pc
);
3656 size
= strlenW(buffer
)*sizeof(WCHAR
);
3657 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPBYTE
)buffer
,size
);
3660 return ERROR_INSTALL_SUSPEND
;
3663 UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
3668 * we are currently doing what should be done here in the top level Install
3669 * however for Adminastrative and uninstalls this step will be needed
3671 if (!package
->PackagePath
)
3672 return ERROR_SUCCESS
;
3674 attrib
= GetFileAttributesW(package
->PackagePath
);
3675 if (attrib
== INVALID_FILE_ATTRIBUTES
)
3681 rc
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
3682 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
,
3683 INSTALLPROPERTY_DISKPROMPTW
,NULL
,&size
);
3684 if (rc
== ERROR_MORE_DATA
)
3686 prompt
= HeapAlloc(GetProcessHeap(),0,size
* sizeof(WCHAR
));
3687 MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
3688 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
,
3689 INSTALLPROPERTY_DISKPROMPTW
,prompt
,&size
);
3692 prompt
= strdupW(package
->PackagePath
);
3694 msg
= generate_error_string(package
,1302,1,prompt
);
3695 while(attrib
== INVALID_FILE_ATTRIBUTES
)
3697 rc
= MessageBoxW(NULL
,msg
,NULL
,MB_OKCANCEL
);
3700 rc
= ERROR_INSTALL_USEREXIT
;
3703 attrib
= GetFileAttributesW(package
->PackagePath
);
3705 HeapFree(GetProcessHeap(),0,prompt
);
3709 return ERROR_SUCCESS
;
3714 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
3722 static const WCHAR szPropKeys
[][80] =
3724 {'P','r','o','d','u','c','t','I','D',0},
3725 {'U','S','E','R','N','A','M','E',0},
3726 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3730 static const WCHAR szRegKeys
[][80] =
3732 {'P','r','o','d','u','c','t','I','D',0},
3733 {'R','e','g','O','w','n','e','r',0},
3734 {'R','e','g','C','o','m','p','a','n','y',0},
3739 return ERROR_INVALID_HANDLE
;
3741 productid
= load_dynamic_property(package
,INSTALLPROPERTY_PRODUCTIDW
,
3744 return ERROR_SUCCESS
;
3746 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
,&hkey
,TRUE
);
3747 if (rc
!= ERROR_SUCCESS
)
3751 while (szPropKeys
[i
][0]!=0)
3753 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
3754 if (rc
== ERROR_SUCCESS
)
3756 size
= strlenW(buffer
)*sizeof(WCHAR
);
3757 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPBYTE
)buffer
,size
);
3760 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,NULL
,0);
3765 HeapFree(GetProcessHeap(),0,productid
);
3768 return ERROR_SUCCESS
;
3772 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
3774 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
3775 static const WCHAR szTwo
[] = {'2',0};
3778 level
= load_dynamic_property(package
,szUILevel
,NULL
);
3780 MSI_SetPropertyW(package
,szUILevel
,szTwo
);
3781 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
3782 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
3783 MSI_SetPropertyW(package
,szUILevel
,level
);
3784 HeapFree(GetProcessHeap(),0,level
);
3790 * Code based off of code located here
3791 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3793 * Using string index 4 (full font name) instead of 1 (family name)
3795 static LPWSTR
load_ttfname_from(LPCWSTR filename
)
3801 typedef struct _tagTT_OFFSET_TABLE
{
3802 USHORT uMajorVersion
;
3803 USHORT uMinorVersion
;
3804 USHORT uNumOfTables
;
3805 USHORT uSearchRange
;
3806 USHORT uEntrySelector
;
3810 typedef struct _tagTT_TABLE_DIRECTORY
{
3811 char szTag
[4]; /* table name */
3812 ULONG uCheckSum
; /* Check sum */
3813 ULONG uOffset
; /* Offset from beginning of file */
3814 ULONG uLength
; /* length of the table in bytes */
3815 }TT_TABLE_DIRECTORY
;
3817 typedef struct _tagTT_NAME_TABLE_HEADER
{
3818 USHORT uFSelector
; /* format selector. Always 0 */
3819 USHORT uNRCount
; /* Name Records count */
3820 USHORT uStorageOffset
; /* Offset for strings storage,
3821 * from start of the table */
3822 }TT_NAME_TABLE_HEADER
;
3824 typedef struct _tagTT_NAME_RECORD
{
3829 USHORT uStringLength
;
3830 USHORT uStringOffset
; /* from start of storage area */
3833 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3834 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3836 handle
= CreateFileW(filename
,GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
3837 FILE_ATTRIBUTE_NORMAL
, 0 );
3838 if (handle
!= INVALID_HANDLE_VALUE
)
3840 TT_TABLE_DIRECTORY tblDir
;
3841 BOOL bFound
= FALSE
;
3842 TT_OFFSET_TABLE ttOffsetTable
;
3844 ReadFile(handle
,&ttOffsetTable
, sizeof(TT_OFFSET_TABLE
),NULL
,NULL
);
3845 ttOffsetTable
.uNumOfTables
= SWAPWORD(ttOffsetTable
.uNumOfTables
);
3846 ttOffsetTable
.uMajorVersion
= SWAPWORD(ttOffsetTable
.uMajorVersion
);
3847 ttOffsetTable
.uMinorVersion
= SWAPWORD(ttOffsetTable
.uMinorVersion
);
3849 if (ttOffsetTable
.uMajorVersion
!= 1 ||
3850 ttOffsetTable
.uMinorVersion
!= 0)
3853 for (i
=0; i
< ttOffsetTable
.uNumOfTables
; i
++)
3855 ReadFile(handle
,&tblDir
, sizeof(TT_TABLE_DIRECTORY
),NULL
,NULL
);
3856 if (strncmp(tblDir
.szTag
,"name",4)==0)
3859 tblDir
.uLength
= SWAPLONG(tblDir
.uLength
);
3860 tblDir
.uOffset
= SWAPLONG(tblDir
.uOffset
);
3867 TT_NAME_TABLE_HEADER ttNTHeader
;
3868 TT_NAME_RECORD ttRecord
;
3870 SetFilePointer(handle
, tblDir
.uOffset
, NULL
, FILE_BEGIN
);
3871 ReadFile(handle
,&ttNTHeader
, sizeof(TT_NAME_TABLE_HEADER
),
3874 ttNTHeader
.uNRCount
= SWAPWORD(ttNTHeader
.uNRCount
);
3875 ttNTHeader
.uStorageOffset
= SWAPWORD(ttNTHeader
.uStorageOffset
);
3877 for(i
=0; i
<ttNTHeader
.uNRCount
; i
++)
3879 ReadFile(handle
,&ttRecord
, sizeof(TT_NAME_RECORD
),NULL
,NULL
);
3880 ttRecord
.uNameID
= SWAPWORD(ttRecord
.uNameID
);
3881 /* 4 is the Full Font Name */
3882 if(ttRecord
.uNameID
== 4)
3886 static LPCSTR tt
= " (TrueType)";
3888 ttRecord
.uStringLength
= SWAPWORD(ttRecord
.uStringLength
);
3889 ttRecord
.uStringOffset
= SWAPWORD(ttRecord
.uStringOffset
);
3890 nPos
= SetFilePointer(handle
, 0, NULL
, FILE_CURRENT
);
3891 SetFilePointer(handle
, tblDir
.uOffset
+
3892 ttRecord
.uStringOffset
+
3893 ttNTHeader
.uStorageOffset
,
3895 buf
= HeapAlloc(GetProcessHeap(), 0,
3896 ttRecord
.uStringLength
+ 1 + strlen(tt
));
3897 memset(buf
, 0, ttRecord
.uStringLength
+ 1 + strlen(tt
));
3898 ReadFile(handle
, buf
, ttRecord
.uStringLength
, NULL
, NULL
);
3899 if (strlen(buf
) > 0)
3902 ret
= strdupAtoW(buf
);
3903 HeapFree(GetProcessHeap(),0,buf
);
3907 HeapFree(GetProcessHeap(),0,buf
);
3908 SetFilePointer(handle
,nPos
, NULL
, FILE_BEGIN
);
3912 CloseHandle(handle
);
3915 ERR("Unable to open font file %s\n", debugstr_w(filename
));
3917 TRACE("Returning fontname %s\n",debugstr_w(ret
));
3921 static UINT
ITERATE_RegisterFonts(MSIRECORD
*row
, LPVOID param
)
3923 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3928 static const WCHAR regfont1
[] =
3929 {'S','o','f','t','w','a','r','e','\\',
3930 'M','i','c','r','o','s','o','f','t','\\',
3931 'W','i','n','d','o','w','s',' ','N','T','\\',
3932 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3933 'F','o','n','t','s',0};
3934 static const WCHAR regfont2
[] =
3935 {'S','o','f','t','w','a','r','e','\\',
3936 'M','i','c','r','o','s','o','f','t','\\',
3937 'W','i','n','d','o','w','s','\\',
3938 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3939 'F','o','n','t','s',0};
3943 filename
= MSI_RecordGetString( row
, 1 );
3944 file
= get_loaded_file( package
, filename
);
3947 ERR("Unable to load file\n");
3948 return ERROR_SUCCESS
;
3951 /* check to make sure that component is installed */
3952 if (!ACTION_VerifyComponentForAction(package
,
3953 file
->Component
, INSTALLSTATE_LOCAL
))
3955 TRACE("Skipping: Component not scheduled for install\n");
3956 return ERROR_SUCCESS
;
3959 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont1
,&hkey1
);
3960 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont2
,&hkey2
);
3962 if (MSI_RecordIsNull(row
,2))
3963 name
= load_ttfname_from( file
->TargetPath
);
3965 name
= load_dynamic_stringW(row
,2);
3969 size
= strlenW( file
->FileName
) * sizeof(WCHAR
);
3970 RegSetValueExW( hkey1
, name
, 0, REG_SZ
, (LPBYTE
)file
->FileName
, size
);
3971 RegSetValueExW( hkey2
, name
, 0, REG_SZ
, (LPBYTE
)file
->FileName
, size
);
3974 HeapFree(GetProcessHeap(),0,name
);
3977 return ERROR_SUCCESS
;
3980 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
)
3984 static const WCHAR ExecSeqQuery
[] =
3985 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3986 '`','F','o','n','t','`',0};
3988 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3989 if (rc
!= ERROR_SUCCESS
)
3991 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc
);
3992 return ERROR_SUCCESS
;
3995 MSI_IterateRecords(view
, NULL
, ITERATE_RegisterFonts
, package
);
3996 msiobj_release(&view
->hdr
);
3998 return ERROR_SUCCESS
;
4001 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
4003 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
4004 LPCWSTR compgroupid
=NULL
;
4005 LPCWSTR feature
=NULL
;
4006 LPCWSTR text
= NULL
;
4007 LPCWSTR qualifier
= NULL
;
4008 LPCWSTR component
= NULL
;
4009 LPWSTR advertise
= NULL
;
4010 LPWSTR output
= NULL
;
4012 UINT rc
= ERROR_SUCCESS
;
4016 component
= MSI_RecordGetString(rec
,3);
4017 comp
= get_loaded_component(package
,component
);
4019 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
) &&
4020 !ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_SOURCE
) &&
4021 !ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_ADVERTISED
))
4023 TRACE("Skipping: Component %s not scheduled for install\n",
4024 debugstr_w(component
));
4026 return ERROR_SUCCESS
;
4029 compgroupid
= MSI_RecordGetString(rec
,1);
4031 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
4032 if (rc
!= ERROR_SUCCESS
)
4035 text
= MSI_RecordGetString(rec
,4);
4036 qualifier
= MSI_RecordGetString(rec
,2);
4037 feature
= MSI_RecordGetString(rec
,5);
4039 advertise
= create_component_advertise_string(package
, comp
, feature
);
4041 sz
= strlenW(advertise
);
4044 sz
+= lstrlenW(text
);
4047 sz
*= sizeof(WCHAR
);
4049 output
= HeapAlloc(GetProcessHeap(),0,sz
);
4050 memset(output
,0,sz
);
4051 strcpyW(output
,advertise
);
4054 strcatW(output
,text
);
4056 sz
= (lstrlenW(output
)+2) * sizeof(WCHAR
);
4057 RegSetValueExW(hkey
, qualifier
,0,REG_MULTI_SZ
, (LPBYTE
)output
, sz
);
4061 HeapFree(GetProcessHeap(),0,output
);
4067 * At present I am ignorning the advertised components part of this and only
4068 * focusing on the qualified component sets
4070 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
4074 static const WCHAR ExecSeqQuery
[] =
4075 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4076 '`','P','u','b','l','i','s','h',
4077 'C','o','m','p','o','n','e','n','t','`',0};
4079 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4080 if (rc
!= ERROR_SUCCESS
)
4081 return ERROR_SUCCESS
;
4083 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
4084 msiobj_release(&view
->hdr
);