2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004,2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
37 #include "wine/debug.h"
42 #include "wine/unicode.h"
46 #define REG_PROGRESS_VALUE 13200
47 #define COMPONENT_PROGRESS_VALUE 24000
49 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
54 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
);
55 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
);
56 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
);
61 typedef UINT (*STANDARDACTIONHANDLER
)(MSIPACKAGE
*);
63 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
);
64 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
);
65 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
);
66 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
);
67 static UINT
ACTION_FileCost(MSIPACKAGE
*package
);
68 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
);
69 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
);
70 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
);
71 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
);
72 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
);
73 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
);
74 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
);
75 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
);
76 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
);
77 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
);
78 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
);
79 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
);
80 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
);
81 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
);
82 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
);
83 static UINT
ACTION_ResolveSource(MSIPACKAGE
*package
);
84 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
);
85 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
);
86 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
);
89 * consts and values used
91 static const WCHAR c_colon
[] = {'C',':','\\',0};
93 const static WCHAR szCreateFolders
[] =
94 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
95 const static WCHAR szCostFinalize
[] =
96 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
97 const WCHAR szInstallFiles
[] =
98 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
99 const WCHAR szDuplicateFiles
[] =
100 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
101 const static WCHAR szWriteRegistryValues
[] =
102 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
103 'V','a','l','u','e','s',0};
104 const static WCHAR szCostInitialize
[] =
105 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
106 const static WCHAR szFileCost
[] =
107 {'F','i','l','e','C','o','s','t',0};
108 const static WCHAR szInstallInitialize
[] =
109 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
110 const static WCHAR szInstallValidate
[] =
111 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
112 const static WCHAR szLaunchConditions
[] =
113 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
114 const static WCHAR szProcessComponents
[] =
115 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
116 const static WCHAR szRegisterTypeLibraries
[] =
117 {'R','e','g','i','s','t','e','r','T','y','p','e',
118 'L','i','b','r','a','r','i','e','s',0};
119 const WCHAR szRegisterClassInfo
[] =
120 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
121 const WCHAR szRegisterProgIdInfo
[] =
122 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
123 const static WCHAR szCreateShortcuts
[] =
124 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
125 const static WCHAR szPublishProduct
[] =
126 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
127 const static WCHAR szWriteIniValues
[] =
128 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
129 const static WCHAR szSelfRegModules
[] =
130 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
131 const static WCHAR szPublishFeatures
[] =
132 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
133 const static WCHAR szRegisterProduct
[] =
134 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
135 const static WCHAR szInstallExecute
[] =
136 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
137 const static WCHAR szInstallExecuteAgain
[] =
138 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
139 'A','g','a','i','n',0};
140 const static WCHAR szInstallFinalize
[] =
141 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
142 const static WCHAR szForceReboot
[] =
143 {'F','o','r','c','e','R','e','b','o','o','t',0};
144 const static WCHAR szResolveSource
[] =
145 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
146 const WCHAR szAppSearch
[] =
147 {'A','p','p','S','e','a','r','c','h',0};
148 const static WCHAR szAllocateRegistrySpace
[] =
149 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
150 'S','p','a','c','e',0};
151 const static WCHAR szBindImage
[] =
152 {'B','i','n','d','I','m','a','g','e',0};
153 const static WCHAR szCCPSearch
[] =
154 {'C','C','P','S','e','a','r','c','h',0};
155 const static WCHAR szDeleteServices
[] =
156 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
157 const static WCHAR szDisableRollback
[] =
158 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
159 const static WCHAR szExecuteAction
[] =
160 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
161 const WCHAR szFindRelatedProducts
[] =
162 {'F','i','n','d','R','e','l','a','t','e','d',
163 'P','r','o','d','u','c','t','s',0};
164 const static WCHAR szInstallAdminPackage
[] =
165 {'I','n','s','t','a','l','l','A','d','m','i','n',
166 'P','a','c','k','a','g','e',0};
167 const static WCHAR szInstallSFPCatalogFile
[] =
168 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
170 const static WCHAR szIsolateComponents
[] =
171 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
172 const WCHAR szMigrateFeatureStates
[] =
173 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
174 'S','t','a','t','e','s',0};
175 const WCHAR szMoveFiles
[] =
176 {'M','o','v','e','F','i','l','e','s',0};
177 const static WCHAR szMsiPublishAssemblies
[] =
178 {'M','s','i','P','u','b','l','i','s','h',
179 'A','s','s','e','m','b','l','i','e','s',0};
180 const static WCHAR szMsiUnpublishAssemblies
[] =
181 {'M','s','i','U','n','p','u','b','l','i','s','h',
182 'A','s','s','e','m','b','l','i','e','s',0};
183 const static WCHAR szInstallODBC
[] =
184 {'I','n','s','t','a','l','l','O','D','B','C',0};
185 const static WCHAR szInstallServices
[] =
186 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
187 const WCHAR szPatchFiles
[] =
188 {'P','a','t','c','h','F','i','l','e','s',0};
189 const static WCHAR szPublishComponents
[] =
190 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
191 const static WCHAR szRegisterComPlus
[] =
192 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
193 const WCHAR szRegisterExtensionInfo
[] =
194 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
196 const static WCHAR szRegisterFonts
[] =
197 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
198 const WCHAR szRegisterMIMEInfo
[] =
199 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
200 const static WCHAR szRegisterUser
[] =
201 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
202 const WCHAR szRemoveDuplicateFiles
[] =
203 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
204 'F','i','l','e','s',0};
205 const static WCHAR szRemoveEnvironmentStrings
[] =
206 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
207 'S','t','r','i','n','g','s',0};
208 const WCHAR szRemoveExistingProducts
[] =
209 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
210 'P','r','o','d','u','c','t','s',0};
211 const WCHAR szRemoveFiles
[] =
212 {'R','e','m','o','v','e','F','i','l','e','s',0};
213 const static WCHAR szRemoveFolders
[] =
214 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
215 const static WCHAR szRemoveIniValues
[] =
216 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
217 const static WCHAR szRemoveODBC
[] =
218 {'R','e','m','o','v','e','O','D','B','C',0};
219 const static WCHAR szRemoveRegistryValues
[] =
220 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
221 'V','a','l','u','e','s',0};
222 const static WCHAR szRemoveShortcuts
[] =
223 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
224 const static WCHAR szRMCCPSearch
[] =
225 {'R','M','C','C','P','S','e','a','r','c','h',0};
226 const static WCHAR szScheduleReboot
[] =
227 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
228 const static WCHAR szSelfUnregModules
[] =
229 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
230 const static WCHAR szSetODBCFolders
[] =
231 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
232 const static WCHAR szStartServices
[] =
233 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
234 const static WCHAR szStopServices
[] =
235 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
236 const static WCHAR szUnpublishComponents
[] =
237 {'U','n','p','u','b','l','i','s','h',
238 'C','o','m','p','o','n','e','n','t','s',0};
239 const static WCHAR szUnpublishFeatures
[] =
240 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
241 const WCHAR szUnregisterClassInfo
[] =
242 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
244 const static WCHAR szUnregisterComPlus
[] =
245 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
246 const WCHAR szUnregisterExtensionInfo
[] =
247 {'U','n','r','e','g','i','s','t','e','r',
248 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
249 const static WCHAR szUnregisterFonts
[] =
250 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
251 const WCHAR szUnregisterMIMEInfo
[] =
252 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
253 const WCHAR szUnregisterProgIdInfo
[] =
254 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
256 const static WCHAR szUnregisterTypeLibraries
[] =
257 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
258 'L','i','b','r','a','r','i','e','s',0};
259 const static WCHAR szValidateProductID
[] =
260 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
261 const static WCHAR szWriteEnvironmentStrings
[] =
262 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
263 'S','t','r','i','n','g','s',0};
267 STANDARDACTIONHANDLER handler
;
270 static struct _actions StandardActions
[] = {
271 { szAllocateRegistrySpace
, NULL
},
272 { szAppSearch
, ACTION_AppSearch
},
273 { szBindImage
, NULL
},
274 { szCCPSearch
, NULL
},
275 { szCostFinalize
, ACTION_CostFinalize
},
276 { szCostInitialize
, ACTION_CostInitialize
},
277 { szCreateFolders
, ACTION_CreateFolders
},
278 { szCreateShortcuts
, ACTION_CreateShortcuts
},
279 { szDeleteServices
, NULL
},
280 { szDisableRollback
, NULL
},
281 { szDuplicateFiles
, ACTION_DuplicateFiles
},
282 { szExecuteAction
, ACTION_ExecuteAction
},
283 { szFileCost
, ACTION_FileCost
},
284 { szFindRelatedProducts
, ACTION_FindRelatedProducts
},
285 { szForceReboot
, ACTION_ForceReboot
},
286 { szInstallAdminPackage
, NULL
},
287 { szInstallExecute
, ACTION_InstallExecute
},
288 { szInstallExecuteAgain
, ACTION_InstallExecute
},
289 { szInstallFiles
, ACTION_InstallFiles
},
290 { szInstallFinalize
, ACTION_InstallFinalize
},
291 { szInstallInitialize
, ACTION_InstallInitialize
},
292 { szInstallSFPCatalogFile
, NULL
},
293 { szInstallValidate
, ACTION_InstallValidate
},
294 { szIsolateComponents
, NULL
},
295 { szLaunchConditions
, ACTION_LaunchConditions
},
296 { szMigrateFeatureStates
, NULL
},
297 { szMoveFiles
, NULL
},
298 { szMsiPublishAssemblies
, NULL
},
299 { szMsiUnpublishAssemblies
, NULL
},
300 { szInstallODBC
, NULL
},
301 { szInstallServices
, NULL
},
302 { szPatchFiles
, NULL
},
303 { szProcessComponents
, ACTION_ProcessComponents
},
304 { szPublishComponents
, ACTION_PublishComponents
},
305 { szPublishFeatures
, ACTION_PublishFeatures
},
306 { szPublishProduct
, ACTION_PublishProduct
},
307 { szRegisterClassInfo
, ACTION_RegisterClassInfo
},
308 { szRegisterComPlus
, NULL
},
309 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
},
310 { szRegisterFonts
, ACTION_RegisterFonts
},
311 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
},
312 { szRegisterProduct
, ACTION_RegisterProduct
},
313 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
},
314 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
},
315 { szRegisterUser
, ACTION_RegisterUser
},
316 { szRemoveDuplicateFiles
, NULL
},
317 { szRemoveEnvironmentStrings
, NULL
},
318 { szRemoveExistingProducts
, NULL
},
319 { szRemoveFiles
, NULL
},
320 { szRemoveFolders
, NULL
},
321 { szRemoveIniValues
, NULL
},
322 { szRemoveODBC
, NULL
},
323 { szRemoveRegistryValues
, NULL
},
324 { szRemoveShortcuts
, NULL
},
325 { szResolveSource
, ACTION_ResolveSource
},
326 { szRMCCPSearch
, NULL
},
327 { szScheduleReboot
, NULL
},
328 { szSelfRegModules
, ACTION_SelfRegModules
},
329 { szSelfUnregModules
, NULL
},
330 { szSetODBCFolders
, NULL
},
331 { szStartServices
, NULL
},
332 { szStopServices
, NULL
},
333 { szUnpublishComponents
, NULL
},
334 { szUnpublishFeatures
, NULL
},
335 { szUnregisterClassInfo
, NULL
},
336 { szUnregisterComPlus
, NULL
},
337 { szUnregisterExtensionInfo
, NULL
},
338 { szUnregisterFonts
, NULL
},
339 { szUnregisterMIMEInfo
, NULL
},
340 { szUnregisterProgIdInfo
, NULL
},
341 { szUnregisterTypeLibraries
, NULL
},
342 { szValidateProductID
, NULL
},
343 { szWriteEnvironmentStrings
, NULL
},
344 { szWriteIniValues
, ACTION_WriteIniValues
},
345 { szWriteRegistryValues
, ACTION_WriteRegistryValues
},
350 /********************************************************
352 ********************************************************/
354 static void ce_actiontext(MSIPACKAGE
* package
, LPCWSTR action
)
356 static const WCHAR szActionText
[] =
357 {'A','c','t','i','o','n','T','e','x','t',0};
360 row
= MSI_CreateRecord(1);
361 MSI_RecordSetStringW(row
,1,action
);
362 ControlEvent_FireSubscribedEvent(package
,szActionText
, row
);
363 msiobj_release(&row
->hdr
);
366 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
368 static const WCHAR template_s
[]=
369 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
371 static const WCHAR format
[] =
372 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
373 static const WCHAR Query_t
[] =
374 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
375 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
376 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
377 ' ','\'','%','s','\'',0};
383 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
385 row
= MSI_QueryGetRecord( package
->db
, Query_t
, action
);
389 ActionText
= MSI_RecordGetString(row
,2);
391 sprintfW(message
,template_s
,timet
,action
,ActionText
);
392 msiobj_release(&row
->hdr
);
394 row
= MSI_CreateRecord(1);
395 MSI_RecordSetStringW(row
,1,message
);
397 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
398 msiobj_release(&row
->hdr
);
401 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
405 static const WCHAR template_s
[]=
406 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
408 static const WCHAR template_e
[]=
409 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
410 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
412 static const WCHAR format
[] =
413 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
417 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
419 sprintfW(message
,template_s
,timet
,action
);
421 sprintfW(message
,template_e
,timet
,action
,rc
);
423 row
= MSI_CreateRecord(1);
424 MSI_RecordSetStringW(row
,1,message
);
426 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
427 msiobj_release(&row
->hdr
);
430 /****************************************************
431 * TOP level entry points
432 *****************************************************/
434 UINT
ACTION_DoTopLevelINSTALL(MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
435 LPCWSTR szCommandLine
, LPCWSTR msiFilePath
)
441 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
442 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
443 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
445 MSI_SetPropertyW(package
, szAction
, szInstall
);
447 package
->script
= HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT
));
448 memset(package
->script
,0,sizeof(MSISCRIPT
));
450 package
->script
->InWhatSequence
= SEQUENCE_INSTALL
;
452 package
->msiFilePath
= strdupW(msiFilePath
);
456 LPWSTR p
, check
, path
;
458 package
->PackagePath
= strdupW(szPackagePath
);
459 path
= strdupW(szPackagePath
);
460 p
= strrchrW(path
,'\\');
468 HeapFree(GetProcessHeap(),0,path
);
469 path
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
*sizeof(WCHAR
));
470 GetCurrentDirectoryW(MAX_PATH
,path
);
474 check
= load_dynamic_property(package
, cszSourceDir
,NULL
);
476 MSI_SetPropertyW(package
, cszSourceDir
, path
);
478 HeapFree(GetProcessHeap(), 0, check
);
480 HeapFree(GetProcessHeap(), 0, path
);
486 ptr
= (LPWSTR
)szCommandLine
;
493 TRACE("Looking at %s\n",debugstr_w(ptr
));
495 ptr2
= strchrW(ptr
,'=');
501 while (*ptr
== ' ') ptr
++;
503 prop
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
504 memcpy(prop
,ptr
,len
*sizeof(WCHAR
));
510 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
523 val
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
524 memcpy(val
,ptr2
,len
*sizeof(WCHAR
));
527 if (strlenW(prop
) > 0)
529 TRACE("Found commandline property (%s) = (%s)\n",
530 debugstr_w(prop
), debugstr_w(val
));
531 MSI_SetPropertyW(package
,prop
,val
);
533 HeapFree(GetProcessHeap(),0,val
);
534 HeapFree(GetProcessHeap(),0,prop
);
541 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
543 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
545 package
->script
->InWhatSequence
|= SEQUENCE_UI
;
546 rc
= ACTION_ProcessUISequence(package
);
548 if (rc
== ERROR_SUCCESS
)
550 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
551 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
555 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
558 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
562 /* install was halted but should be considered a success */
566 package
->script
->CurrentlyScripting
= FALSE
;
568 /* process the ending type action */
569 if (rc
== ERROR_SUCCESS
)
570 ACTION_PerformActionSequence(package
,-1,ui
);
571 else if (rc
== ERROR_INSTALL_USEREXIT
)
572 ACTION_PerformActionSequence(package
,-2,ui
);
573 else if (rc
== ERROR_INSTALL_SUSPEND
)
574 ACTION_PerformActionSequence(package
,-4,ui
);
576 ACTION_PerformActionSequence(package
,-3,ui
);
578 /* finish up running custom actions */
579 ACTION_FinishCustomActions(package
);
584 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
)
586 UINT rc
= ERROR_SUCCESS
;
588 static const WCHAR ExecSeqQuery
[] =
589 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
590 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
591 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
592 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
594 static const WCHAR UISeqQuery
[] =
595 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
596 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
597 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
598 ' ', '=',' ','%','i',0};
601 row
= MSI_QueryGetRecord(package
->db
, UISeqQuery
, seq
);
603 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, seq
);
607 LPCWSTR action
, cond
;
609 TRACE("Running the actions\n");
611 /* check conditions */
612 cond
= MSI_RecordGetString(row
,2);
615 /* this is a hack to skip errors in the condition code */
616 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
620 action
= MSI_RecordGetString(row
,1);
623 ERR("failed to fetch action\n");
624 rc
= ERROR_FUNCTION_FAILED
;
629 rc
= ACTION_PerformUIAction(package
,action
);
631 rc
= ACTION_PerformAction(package
,action
,FALSE
);
633 msiobj_release(&row
->hdr
);
644 } iterate_action_param
;
646 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
648 iterate_action_param
*iap
= (iterate_action_param
*)param
;
650 LPCWSTR cond
, action
;
652 action
= MSI_RecordGetString(row
,1);
655 ERR("Error is retrieving action name\n");
656 return ERROR_FUNCTION_FAILED
;
659 /* check conditions */
660 cond
= MSI_RecordGetString(row
,2);
663 /* this is a hack to skip errors in the condition code */
664 if (MSI_EvaluateConditionW(iap
->package
, cond
) == MSICONDITION_FALSE
)
666 TRACE("Skipping action: %s (condition is false)\n",
668 return ERROR_SUCCESS
;
673 rc
= ACTION_PerformUIAction(iap
->package
,action
);
675 rc
= ACTION_PerformAction(iap
->package
,action
,FALSE
);
677 msi_dialog_check_messages( NULL
);
679 if (iap
->package
->CurrentInstallState
!= ERROR_SUCCESS
)
680 rc
= iap
->package
->CurrentInstallState
;
682 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
685 if (rc
!= ERROR_SUCCESS
)
686 ERR("Execution halted due to error (%i)\n",rc
);
691 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
695 static const WCHAR ExecSeqQuery
[] =
696 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
697 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
698 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
699 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
700 'O','R','D','E','R',' ', 'B','Y',' ',
701 '`','S','e','q','u','e','n','c','e','`',0 };
703 static const WCHAR IVQuery
[] =
704 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
705 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
706 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
707 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
708 ' ','\'', 'I','n','s','t','a','l','l',
709 'V','a','l','i','d','a','t','e','\'', 0};
711 iterate_action_param iap
;
713 iap
.package
= package
;
716 if (package
->script
->ExecuteSequenceRun
)
718 TRACE("Execute Sequence already Run\n");
719 return ERROR_SUCCESS
;
722 package
->script
->ExecuteSequenceRun
= TRUE
;
724 /* get the sequence number */
727 row
= MSI_QueryGetRecord(package
->db
, IVQuery
);
729 return ERROR_FUNCTION_FAILED
;
730 seq
= MSI_RecordGetInteger(row
,1);
731 msiobj_release(&row
->hdr
);
734 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
735 if (rc
== ERROR_SUCCESS
)
737 TRACE("Running the actions\n");
739 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
740 msiobj_release(&view
->hdr
);
746 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
750 static const WCHAR ExecSeqQuery
[] =
751 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
752 '`','I','n','s','t','a','l','l',
753 'U','I','S','e','q','u','e','n','c','e','`',
754 ' ','W','H','E','R','E',' ',
755 '`','S','e','q','u','e','n','c','e','`',' ',
756 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
757 '`','S','e','q','u','e','n','c','e','`',0};
758 iterate_action_param iap
;
760 iap
.package
= package
;
763 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
765 if (rc
== ERROR_SUCCESS
)
767 TRACE("Running the actions \n");
769 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
770 msiobj_release(&view
->hdr
);
776 /********************************************************
777 * ACTION helper functions and functions that perform the actions
778 *******************************************************/
779 static BOOL
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
,
780 UINT
* rc
, BOOL force
)
786 if (!run
&& !package
->script
->CurrentlyScripting
)
791 if (strcmpW(action
,szInstallFinalize
) == 0 ||
792 strcmpW(action
,szInstallExecute
) == 0 ||
793 strcmpW(action
,szInstallExecuteAgain
) == 0)
798 while (StandardActions
[i
].action
!= NULL
)
800 if (strcmpW(StandardActions
[i
].action
, action
)==0)
802 ce_actiontext(package
, action
);
805 ui_actioninfo(package
, action
, TRUE
, 0);
806 *rc
= schedule_action(package
,INSTALL_SCRIPT
,action
);
807 ui_actioninfo(package
, action
, FALSE
, *rc
);
811 ui_actionstart(package
, action
);
812 if (StandardActions
[i
].handler
)
814 *rc
= StandardActions
[i
].handler(package
);
818 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action
));
830 static BOOL
ACTION_HandleCustomAction( MSIPACKAGE
* package
, LPCWSTR action
,
831 UINT
* rc
, BOOL force
)
836 arc
= ACTION_CustomAction(package
,action
, force
);
838 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
847 * A lot of actions are really important even if they don't do anything
848 * explicit... Lots of properties are set at the beginning of the installation
849 * CostFinalize does a bunch of work to translate the directories and such
851 * But until I get write access to the database that is hard, so I am going to
852 * hack it to see if I can get something to run.
854 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, BOOL force
)
856 UINT rc
= ERROR_SUCCESS
;
859 TRACE("Performing action (%s)\n",debugstr_w(action
));
861 handled
= ACTION_HandleStandardAction(package
, action
, &rc
, force
);
864 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, force
);
868 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
869 rc
= ERROR_FUNCTION_NOT_CALLED
;
875 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
)
877 UINT rc
= ERROR_SUCCESS
;
878 BOOL handled
= FALSE
;
880 TRACE("Performing action (%s)\n",debugstr_w(action
));
882 handled
= ACTION_HandleStandardAction(package
, action
, &rc
,TRUE
);
885 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, FALSE
);
887 if( !handled
&& ACTION_DialogBox(package
,action
) == ERROR_SUCCESS
)
892 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
893 rc
= ERROR_FUNCTION_NOT_CALLED
;
901 * Actual Action Handlers
904 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
906 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
912 dir
= MSI_RecordGetString(row
,1);
915 ERR("Unable to get folder id \n");
916 return ERROR_SUCCESS
;
919 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,&folder
);
922 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
923 return ERROR_SUCCESS
;
926 TRACE("Folder is %s\n",debugstr_w(full_path
));
929 uirow
= MSI_CreateRecord(1);
930 MSI_RecordSetStringW(uirow
,1,full_path
);
931 ui_actiondata(package
,szCreateFolders
,uirow
);
932 msiobj_release( &uirow
->hdr
);
934 if (folder
->State
== 0)
935 create_full_pathW(full_path
);
939 HeapFree(GetProcessHeap(),0,full_path
);
940 return ERROR_SUCCESS
;
945 * Also we cannot enable/disable components either, so for now I am just going
946 * to do all the directories for all the components.
948 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
950 static const WCHAR ExecSeqQuery
[] =
951 {'S','E','L','E','C','T',' ',
952 '`','D','i','r','e','c','t','o','r','y','_','`',
953 ' ','F','R','O','M',' ',
954 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
958 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
959 if (rc
!= ERROR_SUCCESS
)
960 return ERROR_SUCCESS
;
962 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
963 msiobj_release(&view
->hdr
);
968 static int load_component(MSIPACKAGE
* package
, MSIRECORD
* row
)
970 int index
= package
->loaded_components
;
973 /* fill in the data */
975 package
->loaded_components
++;
976 if (package
->loaded_components
== 1)
977 package
->components
= HeapAlloc(GetProcessHeap(),0,
978 sizeof(MSICOMPONENT
));
980 package
->components
= HeapReAlloc(GetProcessHeap(),0,
981 package
->components
, package
->loaded_components
*
982 sizeof(MSICOMPONENT
));
984 memset(&package
->components
[index
],0,sizeof(MSICOMPONENT
));
986 sz
= IDENTIFIER_SIZE
;
987 MSI_RecordGetStringW(row
,1,package
->components
[index
].Component
,&sz
);
989 TRACE("Loading Component %s\n",
990 debugstr_w(package
->components
[index
].Component
));
993 if (!MSI_RecordIsNull(row
,2))
994 MSI_RecordGetStringW(row
,2,package
->components
[index
].ComponentId
,&sz
);
996 sz
= IDENTIFIER_SIZE
;
997 MSI_RecordGetStringW(row
,3,package
->components
[index
].Directory
,&sz
);
999 package
->components
[index
].Attributes
= MSI_RecordGetInteger(row
,4);
1002 MSI_RecordGetStringW(row
,5,package
->components
[index
].Condition
,&sz
);
1004 sz
= IDENTIFIER_SIZE
;
1005 MSI_RecordGetStringW(row
,6,package
->components
[index
].KeyPath
,&sz
);
1007 package
->components
[index
].Installed
= INSTALLSTATE_ABSENT
;
1008 package
->components
[index
].Action
= INSTALLSTATE_UNKNOWN
;
1009 package
->components
[index
].ActionRequest
= INSTALLSTATE_UNKNOWN
;
1011 package
->components
[index
].Enabled
= TRUE
;
1017 MSIPACKAGE
*package
;
1022 static UINT
iterate_component_check(MSIRECORD
*row
, LPVOID param
)
1024 _ilfs
* ilfs
= (_ilfs
*)param
;
1027 c_indx
= load_component(ilfs
->package
,row
);
1029 ilfs
->package
->features
[ilfs
->index
].Components
[ilfs
->cnt
] = c_indx
;
1030 ilfs
->package
->features
[ilfs
->index
].ComponentCount
++;
1031 TRACE("Loaded new component to index %i\n",c_indx
);
1033 return ERROR_SUCCESS
;
1036 static UINT
iterate_load_featurecomponents(MSIRECORD
*row
, LPVOID param
)
1038 _ilfs
* ilfs
= (_ilfs
*)param
;
1042 INT cnt
= ilfs
->package
->features
[ilfs
->index
].ComponentCount
;
1044 static const WCHAR Query
[] =
1045 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1046 '`','C','o','m','p','o','n','e','n','t','`',' ',
1047 'W','H','E','R','E',' ',
1048 '`','C','o','m','p','o','n','e','n','t','`',' ',
1049 '=','\'','%','s','\'',0};
1051 component
= MSI_RecordGetString(row
,1);
1053 /* check to see if the component is already loaded */
1054 c_indx
= get_loaded_component(ilfs
->package
,component
);
1057 TRACE("Component %s already loaded at %i\n", debugstr_w(component
),
1059 ilfs
->package
->features
[ilfs
->index
].Components
[cnt
] = c_indx
;
1060 ilfs
->package
->features
[ilfs
->index
].ComponentCount
++;
1061 return ERROR_SUCCESS
;
1064 rc
= MSI_OpenQuery(ilfs
->package
->db
, &view
, Query
, component
);
1065 if (rc
!= ERROR_SUCCESS
)
1066 return ERROR_SUCCESS
;
1069 rc
= MSI_IterateRecords(view
, NULL
, iterate_component_check
, ilfs
);
1070 msiobj_release( &view
->hdr
);
1072 return ERROR_SUCCESS
;
1075 static UINT
load_feature(MSIRECORD
* row
, LPVOID param
)
1077 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
1078 int index
= package
->loaded_features
;
1080 static const WCHAR Query1
[] =
1081 {'S','E','L','E','C','T',' ',
1082 '`','C','o','m','p','o','n','e','n','t','_','`',
1083 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1084 'C','o','m','p','o','n','e','n','t','s','`',' ',
1085 'W','H','E','R','E',' ',
1086 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1091 ilfs
.package
= package
;
1094 /* fill in the data */
1096 package
->loaded_features
++;
1097 if (package
->loaded_features
== 1)
1098 package
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE
));
1100 package
->features
= HeapReAlloc(GetProcessHeap(),0,package
->features
,
1101 package
->loaded_features
* sizeof(MSIFEATURE
));
1103 memset(&package
->features
[index
],0,sizeof(MSIFEATURE
));
1105 sz
= IDENTIFIER_SIZE
;
1106 MSI_RecordGetStringW(row
,1,package
->features
[index
].Feature
,&sz
);
1108 TRACE("Loading feature %s\n",debugstr_w(package
->features
[index
].Feature
));
1110 sz
= IDENTIFIER_SIZE
;
1111 if (!MSI_RecordIsNull(row
,2))
1112 MSI_RecordGetStringW(row
,2,package
->features
[index
].Feature_Parent
,&sz
);
1115 if (!MSI_RecordIsNull(row
,3))
1116 MSI_RecordGetStringW(row
,3,package
->features
[index
].Title
,&sz
);
1119 if (!MSI_RecordIsNull(row
,4))
1120 MSI_RecordGetStringW(row
,4,package
->features
[index
].Description
,&sz
);
1122 if (!MSI_RecordIsNull(row
,5))
1123 package
->features
[index
].Display
= MSI_RecordGetInteger(row
,5);
1125 package
->features
[index
].Level
= MSI_RecordGetInteger(row
,6);
1127 sz
= IDENTIFIER_SIZE
;
1128 if (!MSI_RecordIsNull(row
,7))
1129 MSI_RecordGetStringW(row
,7,package
->features
[index
].Directory
,&sz
);
1131 package
->features
[index
].Attributes
= MSI_RecordGetInteger(row
,8);
1133 package
->features
[index
].Installed
= INSTALLSTATE_ABSENT
;
1134 package
->features
[index
].Action
= INSTALLSTATE_UNKNOWN
;
1135 package
->features
[index
].ActionRequest
= INSTALLSTATE_UNKNOWN
;
1137 /* load feature components */
1139 rc
= MSI_OpenQuery(package
->db
, &view
, Query1
,
1140 package
->features
[index
].Feature
);
1141 if (rc
!= ERROR_SUCCESS
)
1142 return ERROR_SUCCESS
;
1144 MSI_IterateRecords(view
, NULL
, iterate_load_featurecomponents
, &ilfs
);
1145 msiobj_release(&view
->hdr
);
1147 return ERROR_SUCCESS
;
1150 static UINT
load_file(MSIRECORD
*row
, LPVOID param
)
1152 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
1153 DWORD index
= package
->loaded_files
;
1156 /* fill in the data */
1158 package
->loaded_files
++;
1159 if (package
->loaded_files
== 1)
1160 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
1162 package
->files
= HeapReAlloc(GetProcessHeap(),0,
1163 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
1165 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
1167 package
->files
[index
].File
= load_dynamic_stringW(row
, 1);
1169 component
= MSI_RecordGetString(row
, 2);
1170 package
->files
[index
].ComponentIndex
= get_loaded_component(package
,
1173 if (package
->files
[index
].ComponentIndex
== -1)
1174 ERR("Unfound Component %s\n",debugstr_w(component
));
1176 package
->files
[index
].FileName
= load_dynamic_stringW(row
,3);
1177 reduce_to_longfilename(package
->files
[index
].FileName
);
1179 package
->files
[index
].ShortName
= load_dynamic_stringW(row
,3);
1180 reduce_to_shortfilename(package
->files
[index
].ShortName
);
1182 package
->files
[index
].FileSize
= MSI_RecordGetInteger(row
,4);
1183 package
->files
[index
].Version
= load_dynamic_stringW(row
, 5);
1184 package
->files
[index
].Language
= load_dynamic_stringW(row
, 6);
1185 package
->files
[index
].Attributes
= MSI_RecordGetInteger(row
,7);
1186 package
->files
[index
].Sequence
= MSI_RecordGetInteger(row
,8);
1188 package
->files
[index
].Temporary
= FALSE
;
1189 package
->files
[index
].State
= 0;
1191 TRACE("File Loaded (%s)\n",debugstr_w(package
->files
[index
].File
));
1193 return ERROR_SUCCESS
;
1196 static UINT
load_all_files(MSIPACKAGE
*package
)
1200 static const WCHAR Query
[] =
1201 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1202 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1203 '`','S','e','q','u','e','n','c','e','`', 0};
1206 return ERROR_INVALID_HANDLE
;
1208 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1209 if (rc
!= ERROR_SUCCESS
)
1210 return ERROR_SUCCESS
;
1212 rc
= MSI_IterateRecords(view
, NULL
, load_file
, package
);
1213 msiobj_release(&view
->hdr
);
1215 return ERROR_SUCCESS
;
1220 * I am not doing any of the costing functionality yet.
1221 * Mostly looking at doing the Component and Feature loading
1223 * The native MSI does A LOT of modification to tables here. Mostly adding
1224 * a lot of temporary columns to the Feature and Component tables.
1226 * note: Native msi also tracks the short filename. But I am only going to
1227 * track the long ones. Also looking at this directory table
1228 * it appears that the directory table does not get the parents
1229 * resolved base on property only based on their entries in the
1232 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1236 static const WCHAR Query_all
[] =
1237 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1238 '`','F','e','a','t','u','r','e','`',0};
1239 static const WCHAR szCosting
[] =
1240 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1241 static const WCHAR szZero
[] = { '0', 0 };
1245 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1247 return ERROR_SUCCESS
;
1249 MSI_SetPropertyW(package
, szCosting
, szZero
);
1250 MSI_SetPropertyW(package
, cszRootDrive
, c_colon
);
1252 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1253 if (rc
!= ERROR_SUCCESS
)
1256 rc
= MSI_IterateRecords(view
, NULL
, load_feature
, package
);
1257 msiobj_release(&view
->hdr
);
1259 load_all_files(package
);
1261 return ERROR_SUCCESS
;
1264 static UINT
execute_script(MSIPACKAGE
*package
, UINT script
)
1267 UINT rc
= ERROR_SUCCESS
;
1269 TRACE("Executing Script %i\n",script
);
1271 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
1274 action
= package
->script
->Actions
[script
][i
];
1275 ui_actionstart(package
, action
);
1276 TRACE("Executing Action (%s)\n",debugstr_w(action
));
1277 rc
= ACTION_PerformAction(package
, action
, TRUE
);
1278 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
][i
]);
1279 if (rc
!= ERROR_SUCCESS
)
1282 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
]);
1284 package
->script
->ActionCount
[script
] = 0;
1285 package
->script
->Actions
[script
] = NULL
;
1289 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1291 return ERROR_SUCCESS
;
1295 static INT
load_folder(MSIPACKAGE
*package
, const WCHAR
* dir
)
1297 static const WCHAR Query
[] =
1298 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1299 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1300 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1301 ' ','=',' ','\'','%','s','\'',
1303 LPWSTR ptargetdir
, targetdir
, srcdir
;
1305 LPWSTR shortname
= NULL
;
1306 MSIRECORD
* row
= 0;
1310 TRACE("Looking for dir %s\n",debugstr_w(dir
));
1312 for (i
= 0; i
< package
->loaded_folders
; i
++)
1314 if (strcmpW(package
->folders
[i
].Directory
,dir
)==0)
1316 TRACE(" %s retuning on index %lu\n",debugstr_w(dir
),i
);
1321 TRACE("Working to load %s\n",debugstr_w(dir
));
1323 index
= package
->loaded_folders
++;
1324 if (package
->loaded_folders
==1)
1325 package
->folders
= HeapAlloc(GetProcessHeap(),0,
1328 package
->folders
= HeapReAlloc(GetProcessHeap(),0,
1329 package
->folders
, package
->loaded_folders
*
1332 memset(&package
->folders
[index
],0,sizeof(MSIFOLDER
));
1334 package
->folders
[index
].Directory
= strdupW(dir
);
1336 row
= MSI_QueryGetRecord(package
->db
, Query
, dir
);
1340 ptargetdir
= targetdir
= load_dynamic_stringW(row
,3);
1342 /* split src and target dir */
1343 if (strchrW(targetdir
,':'))
1345 srcdir
=strchrW(targetdir
,':');
1352 /* for now only pick long filename versions */
1353 if (strchrW(targetdir
,'|'))
1355 shortname
= targetdir
;
1356 targetdir
= strchrW(targetdir
,'|');
1360 /* for the sourcedir pick the short filename */
1361 if (srcdir
&& strchrW(srcdir
,'|'))
1363 LPWSTR p
= strchrW(srcdir
,'|');
1367 /* now check for root dirs */
1368 if (targetdir
[0] == '.' && targetdir
[1] == 0)
1373 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir
));
1374 HeapFree(GetProcessHeap(),0, package
->folders
[index
].TargetDefault
);
1375 package
->folders
[index
].TargetDefault
= strdupW(targetdir
);
1379 package
->folders
[index
].SourceDefault
= strdupW(srcdir
);
1381 package
->folders
[index
].SourceDefault
= strdupW(shortname
);
1383 package
->folders
[index
].SourceDefault
= strdupW(targetdir
);
1384 HeapFree(GetProcessHeap(), 0, ptargetdir
);
1385 TRACE(" SourceDefault = %s\n",debugstr_w(package
->folders
[index
].SourceDefault
));
1387 parent
= MSI_RecordGetString(row
,2);
1390 i
= load_folder(package
,parent
);
1391 package
->folders
[index
].ParentIndex
= i
;
1392 TRACE("Parent is index %i... %s %s\n",
1393 package
->folders
[index
].ParentIndex
,
1394 debugstr_w(package
->folders
[package
->folders
[index
].ParentIndex
].Directory
),
1395 debugstr_w(parent
));
1398 package
->folders
[index
].ParentIndex
= -2;
1400 package
->folders
[index
].Property
= load_dynamic_property(package
, dir
,NULL
);
1402 msiobj_release(&row
->hdr
);
1403 TRACE(" %s retuning on index %i\n",debugstr_w(dir
),index
);
1407 /* scan for and update current install states */
1408 static void ACTION_UpdateInstallStates(MSIPACKAGE
*package
)
1412 for (i
= 0; i
< package
->loaded_components
; i
++)
1415 res
= MsiGetComponentPathW(package
->ProductCode
,
1416 package
->components
[i
].ComponentId
, NULL
, NULL
);
1418 res
= INSTALLSTATE_ABSENT
;
1419 package
->components
[i
].Installed
= res
;
1422 for (i
= 0; i
< package
->loaded_features
; i
++)
1424 INSTALLSTATE res
= -10;
1426 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
1428 MSICOMPONENT
* component
= &package
->components
[package
->features
[i
].
1431 res
= component
->Installed
;
1434 if (res
== component
->Installed
)
1437 if (res
!= component
->Installed
)
1438 res
= INSTALLSTATE_INCOMPLETE
;
1444 static BOOL
process_state_property (MSIPACKAGE
* package
, LPCWSTR property
,
1447 static const WCHAR all
[]={'A','L','L',0};
1448 LPWSTR override
= NULL
;
1452 override
= load_dynamic_property(package
, property
, NULL
);
1456 for(i
= 0; i
< package
->loaded_features
; i
++)
1458 if (strcmpiW(override
,all
)==0)
1460 package
->features
[i
].ActionRequest
= state
;
1461 package
->features
[i
].Action
= state
;
1465 LPWSTR ptr
= override
;
1466 LPWSTR ptr2
= strchrW(override
,',');
1471 strncmpW(ptr
,package
->features
[i
].Feature
, ptr2
-ptr
)==0)
1473 strcmpW(ptr
,package
->features
[i
].Feature
)==0))
1475 package
->features
[i
].ActionRequest
= state
;
1476 package
->features
[i
].Action
= state
;
1482 ptr2
= strchrW(ptr
,',');
1489 HeapFree(GetProcessHeap(),0,override
);
1495 static UINT
SetFeatureStates(MSIPACKAGE
*package
)
1501 static const WCHAR szlevel
[] =
1502 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1503 static const WCHAR szAddLocal
[] =
1504 {'A','D','D','L','O','C','A','L',0};
1505 static const WCHAR szRemove
[] =
1506 {'R','E','M','O','V','E',0};
1507 BOOL override
= FALSE
;
1509 /* I do not know if this is where it should happen.. but */
1511 TRACE("Checking Install Level\n");
1513 level
= load_dynamic_property(package
,szlevel
,NULL
);
1516 install_level
= atoiW(level
);
1517 HeapFree(GetProcessHeap(), 0, level
);
1522 /* ok hereis the _real_ rub
1523 * all these activation/deactivation things happen in order and things
1524 * later on the list override things earlier on the list.
1525 * 1) INSTALLLEVEL processing
1535 * 11) FILEADDDEFAULT
1536 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1537 * ignored for all the features. seems strange, especially since it is not
1538 * documented anywhere, but it is how it works.
1540 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1541 * REMOVE are the big ones, since we don't handle administrative installs
1544 override
|= process_state_property(package
,szAddLocal
,INSTALLSTATE_LOCAL
);
1545 override
|= process_state_property(package
,szRemove
,INSTALLSTATE_ABSENT
);
1549 for(i
= 0; i
< package
->loaded_features
; i
++)
1551 BOOL feature_state
= ((package
->features
[i
].Level
> 0) &&
1552 (package
->features
[i
].Level
<= install_level
));
1554 if ((feature_state
) &&
1555 (package
->features
[i
].Action
== INSTALLSTATE_UNKNOWN
))
1557 if (package
->features
[i
].Attributes
&
1558 msidbFeatureAttributesFavorSource
)
1560 package
->features
[i
].ActionRequest
= INSTALLSTATE_SOURCE
;
1561 package
->features
[i
].Action
= INSTALLSTATE_SOURCE
;
1563 else if (package
->features
[i
].Attributes
&
1564 msidbFeatureAttributesFavorAdvertise
)
1566 package
->features
[i
].ActionRequest
=INSTALLSTATE_ADVERTISED
;
1567 package
->features
[i
].Action
=INSTALLSTATE_ADVERTISED
;
1571 package
->features
[i
].ActionRequest
= INSTALLSTATE_LOCAL
;
1572 package
->features
[i
].Action
= INSTALLSTATE_LOCAL
;
1579 /* set the Preselected Property */
1580 static const WCHAR szPreselected
[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1581 static const WCHAR szOne
[] = { '1', 0 };
1583 MSI_SetPropertyW(package
,szPreselected
,szOne
);
1587 * now we want to enable or disable components base on feature
1590 for(i
= 0; i
< package
->loaded_features
; i
++)
1592 MSIFEATURE
* feature
= &package
->features
[i
];
1593 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1594 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
1595 feature
->ActionRequest
);
1597 for( j
= 0; j
< feature
->ComponentCount
; j
++)
1599 MSICOMPONENT
* component
= &package
->components
[
1600 feature
->Components
[j
]];
1602 if (!component
->Enabled
)
1604 component
->Action
= INSTALLSTATE_UNKNOWN
;
1605 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1609 if (feature
->Action
== INSTALLSTATE_LOCAL
)
1611 component
->Action
= INSTALLSTATE_LOCAL
;
1612 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1614 else if (feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1616 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1617 (component
->Action
== INSTALLSTATE_ABSENT
) ||
1618 (component
->Action
== INSTALLSTATE_ADVERTISED
))
1621 component
->Action
= INSTALLSTATE_SOURCE
;
1622 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1625 else if (feature
->ActionRequest
== INSTALLSTATE_ADVERTISED
)
1627 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1628 (component
->Action
== INSTALLSTATE_ABSENT
))
1631 component
->Action
= INSTALLSTATE_ADVERTISED
;
1632 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1635 else if (feature
->ActionRequest
== INSTALLSTATE_ABSENT
)
1637 if (component
->Action
== INSTALLSTATE_UNKNOWN
)
1639 component
->Action
= INSTALLSTATE_ABSENT
;
1640 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
1647 for(i
= 0; i
< package
->loaded_components
; i
++)
1649 MSICOMPONENT
* component
= &package
->components
[i
];
1651 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1652 debugstr_w(component
->Component
), component
->Installed
,
1653 component
->Action
, component
->ActionRequest
);
1657 return ERROR_SUCCESS
;
1660 static UINT
ITERATE_CostFinalizeDirectories(MSIRECORD
*row
, LPVOID param
)
1662 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1666 name
= MSI_RecordGetString(row
,1);
1668 /* This helper function now does ALL the work */
1669 TRACE("Dir %s ...\n",debugstr_w(name
));
1670 load_folder(package
,name
);
1671 path
= resolve_folder(package
,name
,FALSE
,TRUE
,NULL
);
1672 TRACE("resolves to %s\n",debugstr_w(path
));
1673 HeapFree( GetProcessHeap(), 0, path
);
1675 return ERROR_SUCCESS
;
1678 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1680 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1684 Feature
= MSI_RecordGetString(row
,1);
1686 feature_index
= get_loaded_feature(package
,Feature
);
1687 if (feature_index
< 0)
1688 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature
));
1692 Condition
= MSI_RecordGetString(row
,3);
1694 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
1696 int level
= MSI_RecordGetInteger(row
,2);
1697 TRACE("Reseting feature %s to level %i\n", debugstr_w(Feature
),
1699 package
->features
[feature_index
].Level
= level
;
1702 return ERROR_SUCCESS
;
1707 * A lot is done in this function aside from just the costing.
1708 * The costing needs to be implemented at some point but for now I am going
1709 * to focus on the directory building
1712 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
1714 static const WCHAR ExecSeqQuery
[] =
1715 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1716 '`','D','i','r','e','c','t','o','r','y','`',0};
1717 static const WCHAR ConditionQuery
[] =
1718 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1719 '`','C','o','n','d','i','t','i','o','n','`',0};
1720 static const WCHAR szCosting
[] =
1721 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1722 static const WCHAR szlevel
[] =
1723 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1724 static const WCHAR szOne
[] = { '1', 0 };
1732 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1734 return ERROR_SUCCESS
;
1736 TRACE("Building Directory properties\n");
1738 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1739 if (rc
== ERROR_SUCCESS
)
1741 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeDirectories
,
1743 msiobj_release(&view
->hdr
);
1746 TRACE("File calculations %i files\n",package
->loaded_files
);
1748 for (i
= 0; i
< package
->loaded_files
; i
++)
1750 MSICOMPONENT
* comp
= NULL
;
1751 MSIFILE
* file
= NULL
;
1753 file
= &package
->files
[i
];
1754 if (file
->ComponentIndex
>= 0)
1755 comp
= &package
->components
[file
->ComponentIndex
];
1757 if (file
->Temporary
== TRUE
)
1764 /* calculate target */
1765 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
1767 HeapFree(GetProcessHeap(),0,file
->TargetPath
);
1769 TRACE("file %s is named %s\n",
1770 debugstr_w(file
->File
),debugstr_w(file
->FileName
));
1772 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
1774 HeapFree(GetProcessHeap(),0,p
);
1776 TRACE("file %s resolves to %s\n",
1777 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
1779 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
1782 comp
->Cost
+= file
->FileSize
;
1792 static const WCHAR name
[] =
1794 static const WCHAR name_fmt
[] =
1795 {'%','u','.','%','u','.','%','u','.','%','u',0};
1796 WCHAR filever
[0x100];
1797 VS_FIXEDFILEINFO
*lpVer
;
1799 TRACE("Version comparison.. \n");
1800 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
1801 version
= HeapAlloc(GetProcessHeap(),0,versize
);
1802 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
1804 VerQueryValueW(version
, name
, (LPVOID
*)&lpVer
, &sz
);
1806 sprintfW(filever
,name_fmt
,
1807 HIWORD(lpVer
->dwFileVersionMS
),
1808 LOWORD(lpVer
->dwFileVersionMS
),
1809 HIWORD(lpVer
->dwFileVersionLS
),
1810 LOWORD(lpVer
->dwFileVersionLS
));
1812 TRACE("new %s old %s\n", debugstr_w(file
->Version
),
1813 debugstr_w(filever
));
1814 if (strcmpiW(filever
,file
->Version
)<0)
1817 FIXME("cost should be diff in size\n");
1818 comp
->Cost
+= file
->FileSize
;
1822 HeapFree(GetProcessHeap(),0,version
);
1830 TRACE("Evaluating Condition Table\n");
1832 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
1833 if (rc
== ERROR_SUCCESS
)
1835 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeConditions
,
1837 msiobj_release(&view
->hdr
);
1840 TRACE("Enabling or Disabling Components\n");
1841 for (i
= 0; i
< package
->loaded_components
; i
++)
1843 if (package
->components
[i
].Condition
[0])
1845 if (MSI_EvaluateConditionW(package
,
1846 package
->components
[i
].Condition
) == MSICONDITION_FALSE
)
1848 TRACE("Disabling component %s\n",
1849 debugstr_w(package
->components
[i
].Component
));
1850 package
->components
[i
].Enabled
= FALSE
;
1855 MSI_SetPropertyW(package
,szCosting
,szOne
);
1856 /* set default run level if not set */
1857 level
= load_dynamic_property(package
,szlevel
,NULL
);
1859 MSI_SetPropertyW(package
,szlevel
, szOne
);
1861 HeapFree(GetProcessHeap(),0,level
);
1863 ACTION_UpdateInstallStates(package
);
1865 return SetFeatureStates(package
);
1868 /* OK this value is "interpreted" and then formatted based on the
1869 first few characters */
1870 static LPSTR
parse_value(MSIPACKAGE
*package
, LPCWSTR value
, DWORD
*type
,
1874 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
1880 LPWSTR deformated
= NULL
;
1883 deformat_string(package
, &value
[2], &deformated
);
1885 /* binary value type */
1889 *size
= (strlenW(ptr
)/2)+1;
1891 *size
= strlenW(ptr
)/2;
1893 data
= HeapAlloc(GetProcessHeap(),0,*size
);
1899 /* if uneven pad with a zero in front */
1905 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1907 TRACE("Uneven byte count\n");
1915 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1918 HeapFree(GetProcessHeap(),0,deformated
);
1920 TRACE("Data %li bytes(%i)\n",*size
,count
);
1927 deformat_string(package
, &value
[1], &deformated
);
1930 *size
= sizeof(DWORD
);
1931 data
= HeapAlloc(GetProcessHeap(),0,*size
);
1937 if ( (*p
< '0') || (*p
> '9') )
1943 if (deformated
[0] == '-')
1946 TRACE("DWORD %li\n",*(LPDWORD
)data
);
1948 HeapFree(GetProcessHeap(),0,deformated
);
1953 static const WCHAR szMulti
[] = {'[','~',']',0};
1962 *type
=REG_EXPAND_SZ
;
1970 if (strstrW(value
,szMulti
))
1971 *type
= REG_MULTI_SZ
;
1973 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
1978 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
1980 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1981 static const WCHAR szHCR
[] =
1982 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1983 'R','O','O','T','\\',0};
1984 static const WCHAR szHCU
[] =
1985 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1986 'U','S','E','R','\\',0};
1987 static const WCHAR szHLM
[] =
1988 {'H','K','E','Y','_','L','O','C','A','L','_',
1989 'M','A','C','H','I','N','E','\\',0};
1990 static const WCHAR szHU
[] =
1991 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1993 LPSTR value_data
= NULL
;
1994 HKEY root_key
, hkey
;
1997 LPCWSTR szRoot
, component
, name
, key
, value
;
1998 INT component_index
;
2002 BOOL check_first
= FALSE
;
2005 ui_progress(package
,2,0,0,0);
2012 component
= MSI_RecordGetString(row
, 6);
2013 component_index
= get_loaded_component(package
,component
);
2015 if (!ACTION_VerifyComponentForAction(package
, component_index
,
2016 INSTALLSTATE_LOCAL
))
2018 TRACE("Skipping write due to disabled component %s\n",
2019 debugstr_w(component
));
2021 package
->components
[component_index
].Action
=
2022 package
->components
[component_index
].Installed
;
2024 return ERROR_SUCCESS
;
2027 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
2029 name
= MSI_RecordGetString(row
, 4);
2030 if( MSI_RecordIsNull(row
,5) && name
)
2032 /* null values can have special meanings */
2033 if (name
[0]=='-' && name
[1] == 0)
2034 return ERROR_SUCCESS
;
2035 else if ((name
[0]=='+' && name
[1] == 0) ||
2036 (name
[0] == '*' && name
[1] == 0))
2041 root
= MSI_RecordGetInteger(row
,2);
2042 key
= MSI_RecordGetString(row
, 3);
2044 /* get the root key */
2049 static const WCHAR szALLUSER
[] = {'A','L','L','U','S','E','R','S',0};
2050 LPWSTR all_users
= load_dynamic_property(package
, szALLUSER
, NULL
);
2051 if (all_users
&& all_users
[0] == '1')
2053 root_key
= HKEY_LOCAL_MACHINE
;
2058 root_key
= HKEY_CURRENT_USER
;
2061 HeapFree(GetProcessHeap(),0,all_users
);
2064 case 0: root_key
= HKEY_CLASSES_ROOT
;
2067 case 1: root_key
= HKEY_CURRENT_USER
;
2070 case 2: root_key
= HKEY_LOCAL_MACHINE
;
2073 case 3: root_key
= HKEY_USERS
;
2077 ERR("Unknown root %i\n",root
);
2083 return ERROR_SUCCESS
;
2085 deformat_string(package
, key
, &deformated
);
2086 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
2087 uikey
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(WCHAR
));
2088 strcpyW(uikey
,szRoot
);
2089 strcatW(uikey
,deformated
);
2091 if (RegCreateKeyW( root_key
, deformated
, &hkey
))
2093 ERR("Could not create key %s\n",debugstr_w(deformated
));
2094 HeapFree(GetProcessHeap(),0,deformated
);
2095 HeapFree(GetProcessHeap(),0,uikey
);
2096 return ERROR_SUCCESS
;
2098 HeapFree(GetProcessHeap(),0,deformated
);
2100 value
= MSI_RecordGetString(row
,5);
2102 value_data
= parse_value(package
, value
, &type
, &size
);
2105 static const WCHAR szEmpty
[] = {0};
2106 value_data
= (LPSTR
)strdupW(szEmpty
);
2111 deformat_string(package
, name
, &deformated
);
2113 /* get the double nulls to terminate SZ_MULTI */
2114 if (type
== REG_MULTI_SZ
)
2115 size
+=sizeof(WCHAR
);
2119 TRACE("Setting value %s of %s\n",debugstr_w(deformated
),
2121 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
)value_data
, size
);
2126 rc
= RegQueryValueExW(hkey
, deformated
, NULL
, NULL
, NULL
, &sz
);
2127 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
2129 TRACE("value %s of %s checked already exists\n",
2130 debugstr_w(deformated
), debugstr_w(uikey
));
2134 TRACE("Checked and setting value %s of %s\n",
2135 debugstr_w(deformated
), debugstr_w(uikey
));
2136 if (deformated
|| size
)
2137 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
) value_data
, size
);
2142 uirow
= MSI_CreateRecord(3);
2143 MSI_RecordSetStringW(uirow
,2,deformated
);
2144 MSI_RecordSetStringW(uirow
,1,uikey
);
2147 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2149 MSI_RecordSetStringW(uirow
,3,value
);
2151 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2152 msiobj_release( &uirow
->hdr
);
2154 HeapFree(GetProcessHeap(),0,value_data
);
2155 HeapFree(GetProcessHeap(),0,deformated
);
2156 HeapFree(GetProcessHeap(),0,uikey
);
2158 return ERROR_SUCCESS
;
2161 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2165 static const WCHAR ExecSeqQuery
[] =
2166 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2167 '`','R','e','g','i','s','t','r','y','`',0 };
2170 return ERROR_INVALID_HANDLE
;
2172 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2173 if (rc
!= ERROR_SUCCESS
)
2174 return ERROR_SUCCESS
;
2176 /* increment progress bar each time action data is sent */
2177 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
2179 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2181 msiobj_release(&view
->hdr
);
2185 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
2187 package
->script
->CurrentlyScripting
= TRUE
;
2189 return ERROR_SUCCESS
;
2193 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
2197 static const WCHAR q1
[]=
2198 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2199 '`','R','e','g','i','s','t','r','y','`',0};
2202 MSIRECORD
* row
= 0;
2205 TRACE(" InstallValidate \n");
2207 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
2208 if (rc
!= ERROR_SUCCESS
)
2209 return ERROR_SUCCESS
;
2211 rc
= MSI_ViewExecute(view
, 0);
2212 if (rc
!= ERROR_SUCCESS
)
2214 MSI_ViewClose(view
);
2215 msiobj_release(&view
->hdr
);
2220 rc
= MSI_ViewFetch(view
,&row
);
2221 if (rc
!= ERROR_SUCCESS
)
2228 msiobj_release(&row
->hdr
);
2230 MSI_ViewClose(view
);
2231 msiobj_release(&view
->hdr
);
2233 total
= total
+ progress
* REG_PROGRESS_VALUE
;
2234 total
= total
+ package
->loaded_components
* COMPONENT_PROGRESS_VALUE
;
2235 for (i
=0; i
< package
->loaded_files
; i
++)
2236 total
+= package
->files
[i
].FileSize
;
2237 ui_progress(package
,0,total
,0,0);
2239 for(i
= 0; i
< package
->loaded_features
; i
++)
2241 MSIFEATURE
* feature
= &package
->features
[i
];
2242 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2243 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
2244 feature
->ActionRequest
);
2247 return ERROR_SUCCESS
;
2250 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
2252 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2253 LPCWSTR cond
= NULL
;
2254 LPCWSTR message
= NULL
;
2255 static const WCHAR title
[]=
2256 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2258 cond
= MSI_RecordGetString(row
,1);
2260 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
2263 message
= MSI_RecordGetString(row
,2);
2264 deformat_string(package
,message
,&deformated
);
2265 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
2266 HeapFree(GetProcessHeap(),0,deformated
);
2267 return ERROR_FUNCTION_FAILED
;
2270 return ERROR_SUCCESS
;
2273 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
2276 MSIQUERY
* view
= NULL
;
2277 static const WCHAR ExecSeqQuery
[] =
2278 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2279 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2281 TRACE("Checking launch conditions\n");
2283 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2284 if (rc
!= ERROR_SUCCESS
)
2285 return ERROR_SUCCESS
;
2287 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
2288 msiobj_release(&view
->hdr
);
2293 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, INT
2296 MSICOMPONENT
* cmp
= &package
->components
[component_index
];
2298 if (cmp
->KeyPath
[0]==0)
2300 LPWSTR p
= resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,NULL
);
2303 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
2305 MSIRECORD
* row
= 0;
2307 LPWSTR deformated
,buffer
,deformated_name
;
2309 static const WCHAR ExecSeqQuery
[] =
2310 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2311 '`','R','e','g','i','s','t','r','y','`',' ',
2312 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2313 ' ','=',' ' ,'\'','%','s','\'',0 };
2314 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
2315 static const WCHAR fmt2
[]=
2316 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2318 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
,cmp
->KeyPath
);
2322 root
= MSI_RecordGetInteger(row
,2);
2323 key
= MSI_RecordGetString(row
, 3);
2324 name
= MSI_RecordGetString(row
, 4);
2325 deformat_string(package
, key
, &deformated
);
2326 deformat_string(package
, name
, &deformated_name
);
2328 len
= strlenW(deformated
) + 6;
2329 if (deformated_name
)
2330 len
+=strlenW(deformated_name
);
2332 buffer
= HeapAlloc(GetProcessHeap(),0, len
*sizeof(WCHAR
));
2334 if (deformated_name
)
2335 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
2337 sprintfW(buffer
,fmt
,root
,deformated
);
2339 HeapFree(GetProcessHeap(),0,deformated
);
2340 HeapFree(GetProcessHeap(),0,deformated_name
);
2341 msiobj_release(&row
->hdr
);
2345 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2347 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2353 j
= get_loaded_file(package
,cmp
->KeyPath
);
2357 LPWSTR p
= strdupW(package
->files
[j
].TargetPath
);
2364 static HKEY
openSharedDLLsKey(void)
2367 static const WCHAR path
[] =
2368 {'S','o','f','t','w','a','r','e','\\',
2369 'M','i','c','r','o','s','o','f','t','\\',
2370 'W','i','n','d','o','w','s','\\',
2371 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2372 'S','h','a','r','e','d','D','L','L','s',0};
2374 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
2378 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
2383 DWORD sz
= sizeof(count
);
2386 hkey
= openSharedDLLsKey();
2387 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
2388 if (rc
!= ERROR_SUCCESS
)
2394 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
2398 hkey
= openSharedDLLsKey();
2400 RegSetValueExW(hkey
,path
,0,REG_DWORD
,
2401 (LPBYTE
)&count
,sizeof(count
));
2403 RegDeleteValueW(hkey
,path
);
2409 * Return TRUE if the count should be written out and FALSE if not
2411 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, UINT index
)
2417 /* only refcount DLLs */
2418 if (package
->components
[index
].KeyPath
[0]==0 ||
2419 package
->components
[index
].Attributes
&
2420 msidbComponentAttributesRegistryKeyPath
||
2421 package
->components
[index
].Attributes
&
2422 msidbComponentAttributesODBCDataSource
)
2426 count
= ACTION_GetSharedDLLsCount(package
->components
[index
].
2428 write
= (count
> 0);
2430 if (package
->components
[index
].Attributes
&
2431 msidbComponentAttributesSharedDllRefCount
)
2435 /* increment counts */
2436 for (j
= 0; j
< package
->loaded_features
; j
++)
2440 if (!ACTION_VerifyFeatureForAction(package
,j
,INSTALLSTATE_LOCAL
))
2443 for (i
= 0; i
< package
->features
[j
].ComponentCount
; i
++)
2445 if (package
->features
[j
].Components
[i
] == index
)
2449 /* decrement counts */
2450 for (j
= 0; j
< package
->loaded_features
; j
++)
2453 if (!ACTION_VerifyFeatureForAction(package
,j
,INSTALLSTATE_ABSENT
))
2456 for (i
= 0; i
< package
->features
[j
].ComponentCount
; i
++)
2458 if (package
->features
[j
].Components
[i
] == index
)
2463 /* ref count all the files in the component */
2465 for (j
= 0; j
< package
->loaded_files
; j
++)
2467 if (package
->files
[j
].Temporary
)
2469 if (package
->files
[j
].ComponentIndex
== index
)
2470 ACTION_WriteSharedDLLsCount(package
->files
[j
].TargetPath
,count
);
2473 /* add a count for permenent */
2474 if (package
->components
[index
].Attributes
&
2475 msidbComponentAttributesPermanent
)
2478 package
->components
[index
].RefCount
= count
;
2481 ACTION_WriteSharedDLLsCount(package
->components
[index
].FullKeypath
,
2482 package
->components
[index
].RefCount
);
2486 * Ok further analysis makes me think that this work is
2487 * actually done in the PublishComponents and PublishFeatures
2488 * step, and not here. It appears like the keypath and all that is
2489 * resolved in this step, however actually written in the Publish steps.
2490 * But we will leave it here for now because it is unclear
2492 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
2494 WCHAR squished_pc
[GUID_SIZE
];
2495 WCHAR squished_cc
[GUID_SIZE
];
2498 HKEY hkey
=0,hkey2
=0;
2501 return ERROR_INVALID_HANDLE
;
2503 /* writes the Component and Features values to the registry */
2505 rc
= MSIREG_OpenComponents(&hkey
);
2506 if (rc
!= ERROR_SUCCESS
)
2509 squash_guid(package
->ProductCode
,squished_pc
);
2510 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
2511 for (i
= 0; i
< package
->loaded_components
; i
++)
2513 ui_progress(package
,2,0,0,0);
2514 if (package
->components
[i
].ComponentId
[0]!=0)
2516 WCHAR
*keypath
= NULL
;
2519 squash_guid(package
->components
[i
].ComponentId
,squished_cc
);
2521 keypath
= resolve_keypath(package
,i
);
2522 package
->components
[i
].FullKeypath
= keypath
;
2524 /* do the refcounting */
2525 ACTION_RefCountComponent( package
, i
);
2527 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2528 debugstr_w(package
->components
[i
].Component
),
2529 debugstr_w(squished_cc
),
2530 debugstr_w(package
->components
[i
].FullKeypath
),
2531 package
->components
[i
].RefCount
);
2533 * Write the keypath out if the component is to be registered
2534 * and delete the key if the component is to be deregistered
2536 if (ACTION_VerifyComponentForAction(package
, i
,
2537 INSTALLSTATE_LOCAL
))
2539 rc
= RegCreateKeyW(hkey
,squished_cc
,&hkey2
);
2540 if (rc
!= ERROR_SUCCESS
)
2545 RegSetValueExW(hkey2
,squished_pc
,0,REG_SZ
,(LPBYTE
)keypath
,
2546 (strlenW(keypath
)+1)*sizeof(WCHAR
));
2548 if (package
->components
[i
].Attributes
&
2549 msidbComponentAttributesPermanent
)
2551 static const WCHAR szPermKey
[] =
2552 { '0','0','0','0','0','0','0','0','0','0','0','0',
2553 '0','0','0','0','0','0','0', '0','0','0','0','0',
2554 '0','0','0','0','0','0','0','0',0};
2556 RegSetValueExW(hkey2
,szPermKey
,0,REG_SZ
,
2558 (strlenW(keypath
)+1)*sizeof(WCHAR
));
2564 uirow
= MSI_CreateRecord(3);
2565 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
2566 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].
2568 MSI_RecordSetStringW(uirow
,3,keypath
);
2569 ui_actiondata(package
,szProcessComponents
,uirow
);
2570 msiobj_release( &uirow
->hdr
);
2573 else if (ACTION_VerifyComponentForAction(package
, i
,
2574 INSTALLSTATE_ABSENT
))
2578 rc
= RegOpenKeyW(hkey
,squished_cc
,&hkey2
);
2579 if (rc
!= ERROR_SUCCESS
)
2582 RegDeleteValueW(hkey2
,squished_pc
);
2584 /* if the key is empty delete it */
2585 res
= RegEnumKeyExW(hkey2
,0,NULL
,0,0,NULL
,0,NULL
);
2587 if (res
== ERROR_NO_MORE_ITEMS
)
2588 RegDeleteKeyW(hkey
,squished_cc
);
2591 uirow
= MSI_CreateRecord(2);
2592 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
2593 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].
2595 ui_actiondata(package
,szProcessComponents
,uirow
);
2596 msiobj_release( &uirow
->hdr
);
2613 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
2614 LPWSTR lpszName
, LONG_PTR lParam
)
2617 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
2618 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
2622 if (!IS_INTRESOURCE(lpszName
))
2624 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
2628 sz
= strlenW(tl_struct
->source
)+4;
2629 sz
*= sizeof(WCHAR
);
2631 if ((INT
)lpszName
== 1)
2632 tl_struct
->path
= strdupW(tl_struct
->source
);
2635 tl_struct
->path
= HeapAlloc(GetProcessHeap(),0,sz
);
2636 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
2639 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
2640 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
2641 if (!SUCCEEDED(res
))
2643 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
2644 tl_struct
->path
= NULL
;
2649 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
2650 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
2652 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2656 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
2657 tl_struct
->path
= NULL
;
2659 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2660 ITypeLib_Release(tl_struct
->ptLib
);
2665 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
2667 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2670 typelib_struct tl_struct
;
2672 static const WCHAR szTYPELIB
[] = {'T','Y','P','E','L','I','B',0};
2674 component
= MSI_RecordGetString(row
,3);
2675 index
= get_loaded_component(package
,component
);
2677 return ERROR_SUCCESS
;
2679 if (!ACTION_VerifyComponentForAction(package
, index
, INSTALLSTATE_LOCAL
))
2681 TRACE("Skipping typelib reg due to disabled component\n");
2683 package
->components
[index
].Action
=
2684 package
->components
[index
].Installed
;
2686 return ERROR_SUCCESS
;
2689 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
2691 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
2694 return ERROR_SUCCESS
;
2696 module
= LoadLibraryExW(package
->files
[index
].TargetPath
, NULL
,
2697 LOAD_LIBRARY_AS_DATAFILE
);
2701 guid
= load_dynamic_stringW(row
,1);
2702 CLSIDFromString(guid
, &tl_struct
.clsid
);
2703 HeapFree(GetProcessHeap(),0,guid
);
2704 tl_struct
.source
= strdupW(package
->files
[index
].TargetPath
);
2705 tl_struct
.path
= NULL
;
2707 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
2708 (LONG_PTR
)&tl_struct
);
2710 if (tl_struct
.path
!= NULL
)
2716 helpid
= MSI_RecordGetString(row
,6);
2719 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,NULL
);
2720 res
= RegisterTypeLib(tl_struct
.ptLib
,tl_struct
.path
,help
);
2721 HeapFree(GetProcessHeap(),0,help
);
2723 if (!SUCCEEDED(res
))
2724 ERR("Failed to register type library %s\n",
2725 debugstr_w(tl_struct
.path
));
2728 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
2730 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
2733 ITypeLib_Release(tl_struct
.ptLib
);
2734 HeapFree(GetProcessHeap(),0,tl_struct
.path
);
2737 ERR("Failed to load type library %s\n",
2738 debugstr_w(tl_struct
.source
));
2740 FreeLibrary(module
);
2741 HeapFree(GetProcessHeap(),0,tl_struct
.source
);
2744 ERR("Could not load file! %s\n",
2745 debugstr_w(package
->files
[index
].TargetPath
));
2747 return ERROR_SUCCESS
;
2750 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
2753 * OK this is a bit confusing.. I am given a _Component key and I believe
2754 * that the file that is being registered as a type library is the "key file
2755 * of that component" which I interpret to mean "The file in the KeyPath of
2760 static const WCHAR Query
[] =
2761 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2762 '`','T','y','p','e','L','i','b','`',0};
2765 return ERROR_INVALID_HANDLE
;
2767 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2768 if (rc
!= ERROR_SUCCESS
)
2769 return ERROR_SUCCESS
;
2771 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
2772 msiobj_release(&view
->hdr
);
2776 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
2778 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
2779 LPWSTR target_file
, target_folder
;
2781 WCHAR filename
[0x100];
2784 static const WCHAR szlnk
[]={'.','l','n','k',0};
2789 buffer
= MSI_RecordGetString(row
,4);
2790 index
= get_loaded_component(package
,buffer
);
2793 return ERROR_SUCCESS
;
2795 if (!ACTION_VerifyComponentForAction(package
, index
, INSTALLSTATE_LOCAL
))
2797 TRACE("Skipping shortcut creation due to disabled component\n");
2799 package
->components
[index
].Action
=
2800 package
->components
[index
].Installed
;
2802 return ERROR_SUCCESS
;
2805 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
2807 ui_actiondata(package
,szCreateShortcuts
,row
);
2809 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
2810 &IID_IShellLinkW
, (LPVOID
*) &sl
);
2814 ERR("Is IID_IShellLink\n");
2815 return ERROR_SUCCESS
;
2818 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
2821 ERR("Is IID_IPersistFile\n");
2822 return ERROR_SUCCESS
;
2825 buffer
= MSI_RecordGetString(row
,2);
2826 target_folder
= resolve_folder(package
, buffer
,FALSE
,FALSE
,NULL
);
2828 /* may be needed because of a bug somehwere else */
2829 create_full_pathW(target_folder
);
2832 MSI_RecordGetStringW(row
,3,filename
,&sz
);
2833 reduce_to_longfilename(filename
);
2834 if (!strchrW(filename
,'.') || strcmpiW(strchrW(filename
,'.'),szlnk
))
2835 strcatW(filename
,szlnk
);
2836 target_file
= build_directory_name(2, target_folder
, filename
);
2837 HeapFree(GetProcessHeap(),0,target_folder
);
2839 buffer
= MSI_RecordGetString(row
,5);
2840 if (strchrW(buffer
,'['))
2843 deformat_string(package
,buffer
,&deformated
);
2844 IShellLinkW_SetPath(sl
,deformated
);
2845 HeapFree(GetProcessHeap(),0,deformated
);
2850 FIXME("poorly handled shortcut format, advertised shortcut\n");
2851 keypath
= strdupW(package
->components
[index
].FullKeypath
);
2852 IShellLinkW_SetPath(sl
,keypath
);
2853 HeapFree(GetProcessHeap(),0,keypath
);
2856 if (!MSI_RecordIsNull(row
,6))
2859 buffer
= MSI_RecordGetString(row
,6);
2860 deformat_string(package
,buffer
,&deformated
);
2861 IShellLinkW_SetArguments(sl
,deformated
);
2862 HeapFree(GetProcessHeap(),0,deformated
);
2865 if (!MSI_RecordIsNull(row
,7))
2867 buffer
= MSI_RecordGetString(row
,7);
2868 IShellLinkW_SetDescription(sl
,buffer
);
2871 if (!MSI_RecordIsNull(row
,8))
2872 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
2874 if (!MSI_RecordIsNull(row
,9))
2879 buffer
= MSI_RecordGetString(row
,9);
2881 build_icon_path(package
,buffer
,&Path
);
2882 index
= MSI_RecordGetInteger(row
,10);
2884 IShellLinkW_SetIconLocation(sl
,Path
,index
);
2885 HeapFree(GetProcessHeap(),0,Path
);
2888 if (!MSI_RecordIsNull(row
,11))
2889 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
2891 if (!MSI_RecordIsNull(row
,12))
2894 buffer
= MSI_RecordGetString(row
,12);
2895 Path
= resolve_folder(package
, buffer
, FALSE
, FALSE
, NULL
);
2896 IShellLinkW_SetWorkingDirectory(sl
,Path
);
2897 HeapFree(GetProcessHeap(), 0, Path
);
2900 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
2901 IPersistFile_Save(pf
,target_file
,FALSE
);
2903 HeapFree(GetProcessHeap(),0,target_file
);
2905 IPersistFile_Release( pf
);
2906 IShellLinkW_Release( sl
);
2908 return ERROR_SUCCESS
;
2911 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
2916 static const WCHAR Query
[] =
2917 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2918 '`','S','h','o','r','t','c','u','t','`',0};
2921 return ERROR_INVALID_HANDLE
;
2923 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2924 if (rc
!= ERROR_SUCCESS
)
2925 return ERROR_SUCCESS
;
2927 res
= CoInitialize( NULL
);
2930 ERR("CoInitialize failed\n");
2931 return ERROR_FUNCTION_FAILED
;
2934 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
2935 msiobj_release(&view
->hdr
);
2942 static UINT
ITERATE_PublishProduct(MSIRECORD
*row
, LPVOID param
)
2944 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2946 LPWSTR FilePath
=NULL
;
2947 LPCWSTR FileName
=NULL
;
2952 FileName
= MSI_RecordGetString(row
,1);
2955 ERR("Unable to get FileName\n");
2956 return ERROR_SUCCESS
;
2959 build_icon_path(package
,FileName
,&FilePath
);
2961 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
2963 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2964 FILE_ATTRIBUTE_NORMAL
, NULL
);
2966 if (the_file
== INVALID_HANDLE_VALUE
)
2968 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
2969 HeapFree(GetProcessHeap(),0,FilePath
);
2970 return ERROR_SUCCESS
;
2977 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
2978 if (rc
!= ERROR_SUCCESS
)
2980 ERR("Failed to get stream\n");
2981 CloseHandle(the_file
);
2982 DeleteFileW(FilePath
);
2985 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
2986 } while (sz
== 1024);
2988 HeapFree(GetProcessHeap(),0,FilePath
);
2990 CloseHandle(the_file
);
2991 return ERROR_SUCCESS
;
2995 * 99% of the work done here is only done for
2996 * advertised installs. However this is where the
2997 * Icon table is processed and written out
2998 * so that is what I am going to do here.
3000 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
3004 static const WCHAR Query
[]=
3005 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3006 '`','I','c','o','n','`',0};
3007 /* for registry stuff */
3010 static const WCHAR szProductLanguage
[] =
3011 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3012 static const WCHAR szARPProductIcon
[] =
3013 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
3014 static const WCHAR szProductVersion
[] =
3015 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3019 MSIHANDLE hDb
, hSumInfo
;
3022 return ERROR_INVALID_HANDLE
;
3024 /* write out icon files */
3026 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3027 if (rc
== ERROR_SUCCESS
)
3029 MSI_IterateRecords(view
, NULL
, ITERATE_PublishProduct
, package
);
3030 msiobj_release(&view
->hdr
);
3033 /* ok there is a lot more done here but i need to figure out what */
3035 rc
= MSIREG_OpenProductsKey(package
->ProductCode
,&hkey
,TRUE
);
3036 if (rc
!= ERROR_SUCCESS
)
3039 rc
= MSIREG_OpenUserProductsKey(package
->ProductCode
,&hukey
,TRUE
);
3040 if (rc
!= ERROR_SUCCESS
)
3044 buffer
= load_dynamic_property(package
,INSTALLPROPERTY_PRODUCTNAMEstringW
,NULL
);
3045 size
= strlenW(buffer
)*sizeof(WCHAR
);
3046 RegSetValueExW(hukey
,INSTALLPROPERTY_PRODUCTNAMEstringW
,0,REG_SZ
,
3047 (LPBYTE
)buffer
,size
);
3048 HeapFree(GetProcessHeap(),0,buffer
);
3050 buffer
= load_dynamic_property(package
,szProductLanguage
,NULL
);
3051 size
= sizeof(DWORD
);
3052 langid
= atoiW(buffer
);
3053 RegSetValueExW(hukey
,INSTALLPROPERTY_LANGUAGEstringW
,0,REG_DWORD
,
3054 (LPBYTE
)&langid
,size
);
3055 HeapFree(GetProcessHeap(),0,buffer
);
3057 buffer
= load_dynamic_property(package
,szARPProductIcon
,NULL
);
3061 build_icon_path(package
,buffer
,&path
);
3062 size
= strlenW(path
) * sizeof(WCHAR
);
3063 RegSetValueExW(hukey
,INSTALLPROPERTY_PRODUCTICONstringW
,0,REG_SZ
,
3066 HeapFree(GetProcessHeap(),0,buffer
);
3068 buffer
= load_dynamic_property(package
,szProductVersion
,NULL
);
3071 DWORD verdword
= build_version_dword(buffer
);
3072 size
= sizeof(DWORD
);
3073 RegSetValueExW(hukey
,INSTALLPROPERTY_VERSIONstringW
,0,REG_DWORD
, (LPBYTE
3076 HeapFree(GetProcessHeap(),0,buffer
);
3078 FIXME("Need to write more keys to the user registry\n");
3080 hDb
= alloc_msihandle( &package
->db
->hdr
);
3081 rc
= MsiGetSummaryInformationW(hDb
, NULL
, 0, &hSumInfo
);
3082 MsiCloseHandle(hDb
);
3083 if (rc
== ERROR_SUCCESS
)
3085 WCHAR guidbuffer
[0x200];
3087 rc
= MsiSummaryInfoGetPropertyW(hSumInfo
, 9, NULL
, NULL
, NULL
,
3089 if (rc
== ERROR_SUCCESS
)
3091 WCHAR squashed
[GUID_SIZE
];
3092 /* for now we only care about the first guid */
3093 LPWSTR ptr
= strchrW(guidbuffer
,';');
3095 squash_guid(guidbuffer
,squashed
);
3096 size
= strlenW(squashed
)*sizeof(WCHAR
);
3097 RegSetValueExW(hukey
,INSTALLPROPERTY_PACKAGECODEstringW
,0,REG_SZ
,
3098 (LPBYTE
)squashed
, size
);
3102 ERR("Unable to query Revision_Number... \n");
3105 MsiCloseHandle(hSumInfo
);
3109 ERR("Unable to open Summary Information\n");
3121 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
3123 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3124 LPCWSTR component
,section
,key
,value
,identifier
,filename
,dirproperty
;
3125 LPWSTR deformated_section
, deformated_key
, deformated_value
;
3126 LPWSTR folder
, fullname
= NULL
;
3128 INT component_index
,action
;
3129 static const WCHAR szWindowsFolder
[] =
3130 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3132 component
= MSI_RecordGetString(row
, 8);
3133 component_index
= get_loaded_component(package
,component
);
3135 if (!ACTION_VerifyComponentForAction(package
, component_index
,
3136 INSTALLSTATE_LOCAL
))
3138 TRACE("Skipping ini file due to disabled component %s\n",
3139 debugstr_w(component
));
3141 package
->components
[component_index
].Action
=
3142 package
->components
[component_index
].Installed
;
3144 return ERROR_SUCCESS
;
3147 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
3149 identifier
= MSI_RecordGetString(row
,1);
3150 filename
= MSI_RecordGetString(row
,2);
3151 dirproperty
= MSI_RecordGetString(row
,3);
3152 section
= MSI_RecordGetString(row
,4);
3153 key
= MSI_RecordGetString(row
,5);
3154 value
= MSI_RecordGetString(row
,6);
3155 action
= MSI_RecordGetInteger(row
,7);
3157 deformat_string(package
,section
,&deformated_section
);
3158 deformat_string(package
,key
,&deformated_key
);
3159 deformat_string(package
,value
,&deformated_value
);
3163 folder
= resolve_folder(package
, dirproperty
, FALSE
, FALSE
, NULL
);
3165 folder
= load_dynamic_property(package
,dirproperty
,NULL
);
3168 folder
= load_dynamic_property(package
, szWindowsFolder
, NULL
);
3172 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty
));
3176 fullname
= build_directory_name(3, folder
, filename
, NULL
);
3180 TRACE("Adding value %s to section %s in %s\n",
3181 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3182 debugstr_w(fullname
));
3183 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3184 deformated_value
, fullname
);
3186 else if (action
== 1)
3189 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
3190 returned
, 10, fullname
);
3191 if (returned
[0] == 0)
3193 TRACE("Adding value %s to section %s in %s\n",
3194 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3195 debugstr_w(fullname
));
3197 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3198 deformated_value
, fullname
);
3201 else if (action
== 3)
3202 FIXME("Append to existing section not yet implemented\n");
3204 uirow
= MSI_CreateRecord(4);
3205 MSI_RecordSetStringW(uirow
,1,identifier
);
3206 MSI_RecordSetStringW(uirow
,2,deformated_section
);
3207 MSI_RecordSetStringW(uirow
,3,deformated_key
);
3208 MSI_RecordSetStringW(uirow
,4,deformated_value
);
3209 ui_actiondata(package
,szWriteIniValues
,uirow
);
3210 msiobj_release( &uirow
->hdr
);
3212 HeapFree(GetProcessHeap(),0,fullname
);
3213 HeapFree(GetProcessHeap(),0,folder
);
3214 HeapFree(GetProcessHeap(),0,deformated_key
);
3215 HeapFree(GetProcessHeap(),0,deformated_value
);
3216 HeapFree(GetProcessHeap(),0,deformated_section
);
3217 return ERROR_SUCCESS
;
3220 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
3224 static const WCHAR ExecSeqQuery
[] =
3225 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3226 '`','I','n','i','F','i','l','e','`',0};
3228 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3229 if (rc
!= ERROR_SUCCESS
)
3231 TRACE("no IniFile table\n");
3232 return ERROR_SUCCESS
;
3235 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
3236 msiobj_release(&view
->hdr
);
3240 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
3242 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3247 static const WCHAR ExeStr
[] =
3248 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3249 static const WCHAR close
[] = {'\"',0};
3251 PROCESS_INFORMATION info
;
3254 memset(&si
,0,sizeof(STARTUPINFOW
));
3256 filename
= MSI_RecordGetString(row
,1);
3257 index
= get_loaded_file(package
,filename
);
3261 ERR("Unable to find file id %s\n",debugstr_w(filename
));
3262 return ERROR_SUCCESS
;
3265 len
= strlenW(ExeStr
);
3266 len
+= strlenW(package
->files
[index
].TargetPath
);
3269 FullName
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
3270 strcpyW(FullName
,ExeStr
);
3271 strcatW(FullName
,package
->files
[index
].TargetPath
);
3272 strcatW(FullName
,close
);
3274 TRACE("Registering %s\n",debugstr_w(FullName
));
3275 brc
= CreateProcessW(NULL
, FullName
, NULL
, NULL
, FALSE
, 0, NULL
, c_colon
,
3279 msi_dialog_check_messages(info
.hProcess
);
3281 HeapFree(GetProcessHeap(),0,FullName
);
3282 return ERROR_SUCCESS
;
3285 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
3289 static const WCHAR ExecSeqQuery
[] =
3290 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3291 '`','S','e','l','f','R','e','g','`',0};
3293 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3294 if (rc
!= ERROR_SUCCESS
)
3296 TRACE("no SelfReg table\n");
3297 return ERROR_SUCCESS
;
3300 MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
3301 msiobj_release(&view
->hdr
);
3303 return ERROR_SUCCESS
;
3306 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
3314 return ERROR_INVALID_HANDLE
;
3316 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
,&hkey
,TRUE
);
3317 if (rc
!= ERROR_SUCCESS
)
3320 rc
= MSIREG_OpenUserFeaturesKey(package
->ProductCode
,&hukey
,TRUE
);
3321 if (rc
!= ERROR_SUCCESS
)
3324 /* here the guids are base 85 encoded */
3325 for (i
= 0; i
< package
->loaded_features
; i
++)
3331 BOOL absent
= FALSE
;
3333 if (!ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_LOCAL
) &&
3334 !ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_SOURCE
) &&
3335 !ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_ADVERTISED
))
3338 size
= package
->features
[i
].ComponentCount
*21;
3340 if (package
->features
[i
].Feature_Parent
[0])
3341 size
+= strlenW(package
->features
[i
].Feature_Parent
)+2;
3343 data
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
3346 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
3349 memset(buf
,0,sizeof(buf
));
3350 if (package
->components
3351 [package
->features
[i
].Components
[j
]].ComponentId
[0]!=0)
3353 TRACE("From %s\n",debugstr_w(package
->components
3354 [package
->features
[i
].Components
[j
]].ComponentId
));
3355 CLSIDFromString(package
->components
3356 [package
->features
[i
].Components
[j
]].ComponentId
,
3358 encode_base85_guid(&clsid
,buf
);
3359 TRACE("to %s\n",debugstr_w(buf
));
3363 if (package
->features
[i
].Feature_Parent
[0])
3365 static const WCHAR sep
[] = {'\2',0};
3367 strcatW(data
,package
->features
[i
].Feature_Parent
);
3370 size
= (strlenW(data
)+1)*sizeof(WCHAR
);
3371 RegSetValueExW(hkey
,package
->features
[i
].Feature
,0,REG_SZ
,
3373 HeapFree(GetProcessHeap(),0,data
);
3377 size
= strlenW(package
->features
[i
].Feature_Parent
)*sizeof(WCHAR
);
3378 RegSetValueExW(hukey
,package
->features
[i
].Feature
,0,REG_SZ
,
3379 (LPBYTE
)package
->features
[i
].Feature_Parent
,size
);
3383 size
= (strlenW(package
->features
[i
].Feature_Parent
)+2)*
3385 data
= HeapAlloc(GetProcessHeap(),0,size
);
3387 strcpyW(&data
[1],package
->features
[i
].Feature_Parent
);
3388 RegSetValueExW(hukey
,package
->features
[i
].Feature
,0,REG_SZ
,
3390 HeapFree(GetProcessHeap(),0,data
);
3400 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
3403 LPWSTR buffer
= NULL
;
3406 static WCHAR szNONE
[] = {0};
3407 static const WCHAR szWindowsInstaler
[] =
3408 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3409 static const WCHAR szPropKeys
[][80] =
3411 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3412 {'A','R','P','C','O','N','T','A','C','T',0},
3413 {'A','R','P','C','O','M','M','E','N','T','S',0},
3414 {'P','r','o','d','u','c','t','N','a','m','e',0},
3415 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3416 {'A','R','P','H','E','L','P','L','I','N','K',0},
3417 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3418 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3419 {'S','o','u','r','c','e','D','i','r',0},
3420 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3421 {'A','R','P','R','E','A','D','M','E',0},
3422 {'A','R','P','S','I','Z','E',0},
3423 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3424 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3428 static const WCHAR szRegKeys
[][80] =
3430 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3431 {'C','o','n','t','a','c','t',0},
3432 {'C','o','m','m','e','n','t','s',0},
3433 {'D','i','s','p','l','a','y','N','a','m','e',0},
3434 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3435 {'H','e','l','p','L','i','n','k',0},
3436 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3437 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3438 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3439 {'P','u','b','l','i','s','h','e','r',0},
3440 {'R','e','a','d','m','e',0},
3441 {'S','i','z','e',0},
3442 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3443 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3447 static const WCHAR installerPathFmt
[] = {
3449 'I','n','s','t','a','l','l','e','r','\\',0};
3450 static const WCHAR fmt
[] = {
3452 'I','n','s','t','a','l','l','e','r','\\',
3453 '%','x','.','m','s','i',0};
3454 static const WCHAR szUpgradeCode
[] =
3455 {'U','p','g','r','a','d','e','C','o','d','e',0};
3456 static const WCHAR modpath_fmt
[] =
3457 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3458 static const WCHAR szModifyPath
[] =
3459 {'M','o','d','i','f','y','P','a','t','h',0};
3460 static const WCHAR szUninstallString
[] =
3461 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3462 static const WCHAR szEstimatedSize
[] =
3463 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3464 static const WCHAR szProductLanguage
[] =
3465 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3466 static const WCHAR szProductVersion
[] =
3467 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3470 static const WCHAR date_fmt
[] = {'%','i','%','i','%','i',0};
3471 LPWSTR upgrade_code
;
3472 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], packagefile
[MAX_PATH
];
3476 return ERROR_INVALID_HANDLE
;
3478 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
,&hkey
,TRUE
);
3479 if (rc
!= ERROR_SUCCESS
)
3482 /* dump all the info i can grab */
3483 FIXME("Flesh out more information \n");
3486 while (szPropKeys
[i
][0]!=0)
3488 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
3489 if (rc
!= ERROR_SUCCESS
)
3491 size
= strlenW(buffer
)*sizeof(WCHAR
);
3492 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPBYTE
)buffer
,size
);
3493 HeapFree(GetProcessHeap(),0,buffer
);
3499 RegSetValueExW(hkey
,szWindowsInstaler
,0,REG_DWORD
,(LPBYTE
)&rc
,size
);
3501 /* copy the package locally */
3502 num
= GetTickCount() & 0xffff;
3506 GetWindowsDirectoryW(windir
, sizeof(windir
) / sizeof(windir
[0]));
3507 snprintfW(packagefile
,sizeof(packagefile
)/sizeof(packagefile
[0]),fmt
,
3511 HANDLE handle
= CreateFileW(packagefile
,GENERIC_WRITE
, 0, NULL
,
3512 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
3513 if (handle
!= INVALID_HANDLE_VALUE
)
3515 CloseHandle(handle
);
3518 if (GetLastError() != ERROR_FILE_EXISTS
&&
3519 GetLastError() != ERROR_SHARING_VIOLATION
)
3521 if (!(++num
& 0xffff)) num
= 1;
3522 sprintfW(packagefile
,fmt
,num
);
3523 } while (num
!= start
);
3525 snprintfW(path
,sizeof(path
)/sizeof(path
[0]),installerPathFmt
,windir
);
3526 create_full_pathW(path
);
3527 TRACE("Copying to local package %s\n",debugstr_w(packagefile
));
3528 if (!CopyFileW(package
->msiFilePath
,packagefile
,FALSE
))
3529 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3530 debugstr_w(package
->msiFilePath
), debugstr_w(packagefile
),
3532 size
= strlenW(packagefile
)*sizeof(WCHAR
);
3533 RegSetValueExW(hkey
,INSTALLPROPERTY_LOCALPACKAGEstringW
,0,REG_SZ
,
3534 (LPBYTE
)packagefile
,size
);
3536 /* do ModifyPath and UninstallString */
3537 size
= deformat_string(package
,modpath_fmt
,&buffer
);
3538 RegSetValueExW(hkey
,szModifyPath
,0,REG_EXPAND_SZ
,(LPBYTE
)buffer
,size
);
3539 RegSetValueExW(hkey
,szUninstallString
,0,REG_EXPAND_SZ
,(LPBYTE
)buffer
,size
);
3540 HeapFree(GetProcessHeap(),0,buffer
);
3542 FIXME("Write real Estimated Size when we have it\n");
3544 RegSetValueExW(hkey
,szEstimatedSize
,0,REG_DWORD
,(LPBYTE
)&size
,sizeof(DWORD
));
3546 GetLocalTime(&systime
);
3547 size
= 9*sizeof(WCHAR
);
3548 buffer
= HeapAlloc(GetProcessHeap(),0,size
);
3549 sprintfW(buffer
,date_fmt
,systime
.wYear
,systime
.wMonth
,systime
.wDay
);
3550 size
= strlenW(buffer
)*sizeof(WCHAR
);
3551 RegSetValueExW(hkey
,INSTALLPROPERTY_INSTALLDATEstringW
,0,REG_SZ
,
3552 (LPBYTE
)buffer
,size
);
3553 HeapFree(GetProcessHeap(),0,buffer
);
3555 buffer
= load_dynamic_property(package
,szProductLanguage
,NULL
);
3556 size
= atoiW(buffer
);
3557 RegSetValueExW(hkey
,INSTALLPROPERTY_LANGUAGEstringW
,0,REG_DWORD
,
3558 (LPBYTE
)&size
,sizeof(DWORD
));
3559 HeapFree(GetProcessHeap(),1,buffer
);
3561 buffer
= load_dynamic_property(package
,szProductVersion
,NULL
);
3564 DWORD verdword
= build_version_dword(buffer
);
3565 DWORD vermajor
= verdword
>>24;
3566 DWORD verminor
= (verdword
>>16)&0x00FF;
3567 size
= sizeof(DWORD
);
3568 RegSetValueExW(hkey
,INSTALLPROPERTY_VERSIONstringW
,0,REG_DWORD
,
3569 (LPBYTE
)&verdword
,size
);
3570 RegSetValueExW(hkey
,INSTALLPROPERTY_VERSIONMAJORstringW
,0,REG_DWORD
,
3571 (LPBYTE
)&vermajor
,size
);
3572 RegSetValueExW(hkey
,INSTALLPROPERTY_VERSIONMINORstringW
,0,REG_DWORD
,
3573 (LPBYTE
)&verminor
,size
);
3575 HeapFree(GetProcessHeap(),0,buffer
);
3577 /* Handle Upgrade Codes */
3578 upgrade_code
= load_dynamic_property(package
,szUpgradeCode
, NULL
);
3583 MSIREG_OpenUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3584 squash_guid(package
->ProductCode
,squashed
);
3585 RegSetValueExW(hkey2
, squashed
, 0,REG_SZ
,NULL
,0);
3587 MSIREG_OpenUserUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3588 squash_guid(package
->ProductCode
,squashed
);
3589 RegSetValueExW(hkey2
, squashed
, 0,REG_SZ
,NULL
,0);
3592 HeapFree(GetProcessHeap(),0,upgrade_code
);
3598 return ERROR_SUCCESS
;
3601 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
3606 return ERROR_INVALID_HANDLE
;
3608 rc
= execute_script(package
,INSTALL_SCRIPT
);
3613 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
3618 return ERROR_INVALID_HANDLE
;
3620 /* turn off scheduleing */
3621 package
->script
->CurrentlyScripting
= FALSE
;
3623 /* first do the same as an InstallExecute */
3624 rc
= ACTION_InstallExecute(package
);
3625 if (rc
!= ERROR_SUCCESS
)
3628 /* then handle Commit Actions */
3629 rc
= execute_script(package
,COMMIT_SCRIPT
);
3634 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
3636 static const WCHAR RunOnce
[] = {
3637 'S','o','f','t','w','a','r','e','\\',
3638 'M','i','c','r','o','s','o','f','t','\\',
3639 'W','i','n','d','o','w','s','\\',
3640 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3641 'R','u','n','O','n','c','e',0};
3642 static const WCHAR InstallRunOnce
[] = {
3643 'S','o','f','t','w','a','r','e','\\',
3644 'M','i','c','r','o','s','o','f','t','\\',
3645 'W','i','n','d','o','w','s','\\',
3646 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3647 'I','n','s','t','a','l','l','e','r','\\',
3648 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3650 static const WCHAR msiexec_fmt
[] = {
3652 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3653 '\"','%','s','\"',0};
3654 static const WCHAR install_fmt
[] = {
3655 '/','I',' ','\"','%','s','\"',' ',
3656 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3657 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3658 WCHAR buffer
[256], sysdir
[MAX_PATH
];
3660 WCHAR squished_pc
[100];
3664 return ERROR_INVALID_HANDLE
;
3666 squash_guid(package
->ProductCode
,squished_pc
);
3668 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
3669 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
3670 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
3673 size
= strlenW(buffer
)*sizeof(WCHAR
);
3674 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPBYTE
)buffer
,size
);
3677 TRACE("Reboot command %s\n",debugstr_w(buffer
));
3679 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
3680 sprintfW(buffer
,install_fmt
,package
->ProductCode
,squished_pc
);
3682 size
= strlenW(buffer
)*sizeof(WCHAR
);
3683 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPBYTE
)buffer
,size
);
3686 return ERROR_INSTALL_SUSPEND
;
3689 UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
3692 * we are currently doing what should be done here in the top level Install
3693 * however for Adminastrative and uninstalls this step will be needed
3695 return ERROR_SUCCESS
;
3698 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
3706 static const WCHAR szPropKeys
[][80] =
3708 {'P','r','o','d','u','c','t','I','D',0},
3709 {'U','S','E','R','N','A','M','E',0},
3710 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3714 static const WCHAR szRegKeys
[][80] =
3716 {'P','r','o','d','u','c','t','I','D',0},
3717 {'R','e','g','O','w','n','e','r',0},
3718 {'R','e','g','C','o','m','p','a','n','y',0},
3723 return ERROR_INVALID_HANDLE
;
3725 productid
= load_dynamic_property(package
,INSTALLPROPERTY_PRODUCTIDstringW
,
3728 return ERROR_SUCCESS
;
3730 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
,&hkey
,TRUE
);
3731 if (rc
!= ERROR_SUCCESS
)
3735 while (szPropKeys
[i
][0]!=0)
3737 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
3738 if (rc
== ERROR_SUCCESS
)
3740 size
= strlenW(buffer
)*sizeof(WCHAR
);
3741 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPBYTE
)buffer
,size
);
3744 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,NULL
,0);
3749 HeapFree(GetProcessHeap(),0,productid
);
3752 return ERROR_SUCCESS
;
3756 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
3758 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
3759 static const WCHAR szTwo
[] = {'2',0};
3762 level
= load_dynamic_property(package
,szUILevel
,NULL
);
3764 MSI_SetPropertyW(package
,szUILevel
,szTwo
);
3765 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
3766 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
3767 MSI_SetPropertyW(package
,szUILevel
,level
);
3768 HeapFree(GetProcessHeap(),0,level
);
3774 * Code based off of code located here
3775 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3777 * Using string index 4 (full font name) instead of 1 (family name)
3779 static LPWSTR
load_ttfname_from(LPCWSTR filename
)
3785 typedef struct _tagTT_OFFSET_TABLE
{
3786 USHORT uMajorVersion
;
3787 USHORT uMinorVersion
;
3788 USHORT uNumOfTables
;
3789 USHORT uSearchRange
;
3790 USHORT uEntrySelector
;
3794 typedef struct _tagTT_TABLE_DIRECTORY
{
3795 char szTag
[4]; /* table name */
3796 ULONG uCheckSum
; /* Check sum */
3797 ULONG uOffset
; /* Offset from beginning of file */
3798 ULONG uLength
; /* length of the table in bytes */
3799 }TT_TABLE_DIRECTORY
;
3801 typedef struct _tagTT_NAME_TABLE_HEADER
{
3802 USHORT uFSelector
; /* format selector. Always 0 */
3803 USHORT uNRCount
; /* Name Records count */
3804 USHORT uStorageOffset
; /* Offset for strings storage,
3805 * from start of the table */
3806 }TT_NAME_TABLE_HEADER
;
3808 typedef struct _tagTT_NAME_RECORD
{
3813 USHORT uStringLength
;
3814 USHORT uStringOffset
; /* from start of storage area */
3817 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3818 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3820 handle
= CreateFileW(filename
,GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
3821 FILE_ATTRIBUTE_NORMAL
, 0 );
3822 if (handle
!= INVALID_HANDLE_VALUE
)
3824 TT_TABLE_DIRECTORY tblDir
;
3825 BOOL bFound
= FALSE
;
3826 TT_OFFSET_TABLE ttOffsetTable
;
3828 ReadFile(handle
,&ttOffsetTable
, sizeof(TT_OFFSET_TABLE
),NULL
,NULL
);
3829 ttOffsetTable
.uNumOfTables
= SWAPWORD(ttOffsetTable
.uNumOfTables
);
3830 ttOffsetTable
.uMajorVersion
= SWAPWORD(ttOffsetTable
.uMajorVersion
);
3831 ttOffsetTable
.uMinorVersion
= SWAPWORD(ttOffsetTable
.uMinorVersion
);
3833 if (ttOffsetTable
.uMajorVersion
!= 1 ||
3834 ttOffsetTable
.uMinorVersion
!= 0)
3837 for (i
=0; i
< ttOffsetTable
.uNumOfTables
; i
++)
3839 ReadFile(handle
,&tblDir
, sizeof(TT_TABLE_DIRECTORY
),NULL
,NULL
);
3840 if (strncmp(tblDir
.szTag
,"name",4)==0)
3843 tblDir
.uLength
= SWAPLONG(tblDir
.uLength
);
3844 tblDir
.uOffset
= SWAPLONG(tblDir
.uOffset
);
3851 TT_NAME_TABLE_HEADER ttNTHeader
;
3852 TT_NAME_RECORD ttRecord
;
3854 SetFilePointer(handle
, tblDir
.uOffset
, NULL
, FILE_BEGIN
);
3855 ReadFile(handle
,&ttNTHeader
, sizeof(TT_NAME_TABLE_HEADER
),
3858 ttNTHeader
.uNRCount
= SWAPWORD(ttNTHeader
.uNRCount
);
3859 ttNTHeader
.uStorageOffset
= SWAPWORD(ttNTHeader
.uStorageOffset
);
3861 for(i
=0; i
<ttNTHeader
.uNRCount
; i
++)
3863 ReadFile(handle
,&ttRecord
, sizeof(TT_NAME_RECORD
),NULL
,NULL
);
3864 ttRecord
.uNameID
= SWAPWORD(ttRecord
.uNameID
);
3865 /* 4 is the Full Font Name */
3866 if(ttRecord
.uNameID
== 4)
3870 static LPCSTR tt
= " (TrueType)";
3872 ttRecord
.uStringLength
= SWAPWORD(ttRecord
.uStringLength
);
3873 ttRecord
.uStringOffset
= SWAPWORD(ttRecord
.uStringOffset
);
3874 nPos
= SetFilePointer(handle
, 0, NULL
, FILE_CURRENT
);
3875 SetFilePointer(handle
, tblDir
.uOffset
+
3876 ttRecord
.uStringOffset
+
3877 ttNTHeader
.uStorageOffset
,
3879 buf
= HeapAlloc(GetProcessHeap(), 0,
3880 ttRecord
.uStringLength
+ 1 + strlen(tt
));
3881 memset(buf
, 0, ttRecord
.uStringLength
+ 1 + strlen(tt
));
3882 ReadFile(handle
, buf
, ttRecord
.uStringLength
, NULL
, NULL
);
3883 if (strlen(buf
) > 0)
3886 ret
= strdupAtoW(buf
);
3887 HeapFree(GetProcessHeap(),0,buf
);
3891 HeapFree(GetProcessHeap(),0,buf
);
3892 SetFilePointer(handle
,nPos
, NULL
, FILE_BEGIN
);
3896 CloseHandle(handle
);
3899 ERR("Unable to open font file %s\n", debugstr_w(filename
));
3901 TRACE("Returning fontname %s\n",debugstr_w(ret
));
3905 static UINT
ITERATE_RegisterFonts(MSIRECORD
*row
, LPVOID param
)
3907 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3912 static const WCHAR regfont1
[] =
3913 {'S','o','f','t','w','a','r','e','\\',
3914 'M','i','c','r','o','s','o','f','t','\\',
3915 'W','i','n','d','o','w','s',' ','N','T','\\',
3916 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3917 'F','o','n','t','s',0};
3918 static const WCHAR regfont2
[] =
3919 {'S','o','f','t','w','a','r','e','\\',
3920 'M','i','c','r','o','s','o','f','t','\\',
3921 'W','i','n','d','o','w','s','\\',
3922 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3923 'F','o','n','t','s',0};
3927 file
= MSI_RecordGetString(row
,1);
3928 index
= get_loaded_file(package
,file
);
3931 ERR("Unable to load file\n");
3932 return ERROR_SUCCESS
;
3935 /* check to make sure that component is installed */
3936 if (!ACTION_VerifyComponentForAction(package
,
3937 package
->files
[index
].ComponentIndex
, INSTALLSTATE_LOCAL
))
3939 TRACE("Skipping: Component not scheduled for install\n");
3940 return ERROR_SUCCESS
;
3943 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont1
,&hkey1
);
3944 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont2
,&hkey2
);
3946 if (MSI_RecordIsNull(row
,2))
3947 name
= load_ttfname_from(package
->files
[index
].TargetPath
);
3949 name
= load_dynamic_stringW(row
,2);
3953 size
= strlenW(package
->files
[index
].FileName
) * sizeof(WCHAR
);
3954 RegSetValueExW(hkey1
,name
,0,REG_SZ
,
3955 (LPBYTE
)package
->files
[index
].FileName
,size
);
3956 RegSetValueExW(hkey2
,name
,0,REG_SZ
,
3957 (LPBYTE
)package
->files
[index
].FileName
,size
);
3960 HeapFree(GetProcessHeap(),0,name
);
3963 return ERROR_SUCCESS
;
3966 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
)
3970 static const WCHAR ExecSeqQuery
[] =
3971 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3972 '`','F','o','n','t','`',0};
3974 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3975 if (rc
!= ERROR_SUCCESS
)
3977 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc
);
3978 return ERROR_SUCCESS
;
3981 MSI_IterateRecords(view
, NULL
, ITERATE_RegisterFonts
, package
);
3982 msiobj_release(&view
->hdr
);
3984 return ERROR_SUCCESS
;
3987 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
3989 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3990 LPCWSTR compgroupid
=NULL
;
3991 LPCWSTR feature
=NULL
;
3992 LPCWSTR text
= NULL
;
3993 LPCWSTR qualifier
= NULL
;
3994 LPCWSTR component
= NULL
;
3995 LPWSTR advertise
= NULL
;
3996 LPWSTR output
= NULL
;
3998 UINT rc
= ERROR_SUCCESS
;
4002 component
= MSI_RecordGetString(rec
,3);
4003 index
= get_loaded_component(package
,component
);
4005 if (!ACTION_VerifyComponentForAction(package
, index
,
4006 INSTALLSTATE_LOCAL
) &&
4007 !ACTION_VerifyComponentForAction(package
, index
,
4008 INSTALLSTATE_SOURCE
) &&
4009 !ACTION_VerifyComponentForAction(package
, index
,
4010 INSTALLSTATE_ADVERTISED
))
4012 TRACE("Skipping: Component %s not scheduled for install\n",
4013 debugstr_w(component
));
4015 return ERROR_SUCCESS
;
4018 compgroupid
= MSI_RecordGetString(rec
,1);
4020 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
4021 if (rc
!= ERROR_SUCCESS
)
4024 text
= MSI_RecordGetString(rec
,4);
4025 qualifier
= MSI_RecordGetString(rec
,2);
4026 feature
= MSI_RecordGetString(rec
,5);
4028 advertise
= create_component_advertise_string(package
,
4029 &package
->components
[index
], feature
);
4031 sz
= strlenW(advertise
);
4034 sz
+= lstrlenW(text
);
4037 sz
*= sizeof(WCHAR
);
4039 output
= HeapAlloc(GetProcessHeap(),0,sz
);
4040 memset(output
,0,sz
);
4041 strcpyW(output
,advertise
);
4044 strcatW(output
,text
);
4046 sz
= (lstrlenW(output
)+2) * sizeof(WCHAR
);
4047 RegSetValueExW(hkey
, qualifier
,0,REG_MULTI_SZ
, (LPBYTE
)output
, sz
);
4051 HeapFree(GetProcessHeap(),0,output
);
4057 * At present I am ignorning the advertised components part of this and only
4058 * focusing on the qualified component sets
4060 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
4064 static const WCHAR ExecSeqQuery
[] =
4065 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4066 '`','P','u','b','l','i','s','h',
4067 'C','o','m','p','o','n','e','n','t','`',0};
4069 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4070 if (rc
!= ERROR_SUCCESS
)
4071 return ERROR_SUCCESS
;
4073 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
4074 msiobj_release(&view
->hdr
);