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
)
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
));
452 LPWSTR p
, check
, path
;
454 package
->PackagePath
= strdupW(szPackagePath
);
455 path
= strdupW(szPackagePath
);
456 p
= strrchrW(path
,'\\');
464 HeapFree(GetProcessHeap(),0,path
);
465 path
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
*sizeof(WCHAR
));
466 GetCurrentDirectoryW(MAX_PATH
,path
);
470 check
= load_dynamic_property(package
, cszSourceDir
,NULL
);
472 MSI_SetPropertyW(package
, cszSourceDir
, path
);
474 HeapFree(GetProcessHeap(), 0, check
);
476 HeapFree(GetProcessHeap(), 0, path
);
482 ptr
= (LPWSTR
)szCommandLine
;
489 TRACE("Looking at %s\n",debugstr_w(ptr
));
491 ptr2
= strchrW(ptr
,'=');
497 while (*ptr
== ' ') ptr
++;
499 prop
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
500 memcpy(prop
,ptr
,len
*sizeof(WCHAR
));
506 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
519 val
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
520 memcpy(val
,ptr2
,len
*sizeof(WCHAR
));
523 if (strlenW(prop
) > 0)
525 TRACE("Found commandline property (%s) = (%s)\n",
526 debugstr_w(prop
), debugstr_w(val
));
527 MSI_SetPropertyW(package
,prop
,val
);
529 HeapFree(GetProcessHeap(),0,val
);
530 HeapFree(GetProcessHeap(),0,prop
);
537 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
539 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
541 rc
= ACTION_ProcessUISequence(package
);
543 if (rc
== ERROR_SUCCESS
)
544 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
547 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
550 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
554 /* install was halted but should be considered a success */
558 package
->script
->CurrentlyScripting
= FALSE
;
560 /* process the ending type action */
561 if (rc
== ERROR_SUCCESS
)
562 ACTION_PerformActionSequence(package
,-1,ui
);
563 else if (rc
== ERROR_INSTALL_USEREXIT
)
564 ACTION_PerformActionSequence(package
,-2,ui
);
565 else if (rc
== ERROR_INSTALL_SUSPEND
)
566 ACTION_PerformActionSequence(package
,-4,ui
);
568 ACTION_PerformActionSequence(package
,-3,ui
);
570 /* finish up running custom actions */
571 ACTION_FinishCustomActions(package
);
576 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
)
578 UINT rc
= ERROR_SUCCESS
;
580 static const WCHAR ExecSeqQuery
[] =
581 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
582 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
583 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
584 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
586 static const WCHAR UISeqQuery
[] =
587 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
588 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
589 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
590 ' ', '=',' ','%','i',0};
593 row
= MSI_QueryGetRecord(package
->db
, UISeqQuery
, seq
);
595 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, seq
);
599 LPCWSTR action
, cond
;
601 TRACE("Running the actions\n");
603 /* check conditions */
604 cond
= MSI_RecordGetString(row
,2);
607 /* this is a hack to skip errors in the condition code */
608 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
612 action
= MSI_RecordGetString(row
,1);
615 ERR("failed to fetch action\n");
616 rc
= ERROR_FUNCTION_FAILED
;
621 rc
= ACTION_PerformUIAction(package
,action
);
623 rc
= ACTION_PerformAction(package
,action
,FALSE
);
625 msiobj_release(&row
->hdr
);
636 } iterate_action_param
;
638 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
640 iterate_action_param
*iap
= (iterate_action_param
*)param
;
642 LPCWSTR cond
, action
;
644 action
= MSI_RecordGetString(row
,1);
647 ERR("Error is retrieving action name\n");
648 return ERROR_FUNCTION_FAILED
;
651 /* check conditions */
652 cond
= MSI_RecordGetString(row
,2);
655 /* this is a hack to skip errors in the condition code */
656 if (MSI_EvaluateConditionW(iap
->package
, cond
) == MSICONDITION_FALSE
)
658 TRACE("Skipping action: %s (condition is false)\n",
660 return ERROR_SUCCESS
;
665 rc
= ACTION_PerformUIAction(iap
->package
,action
);
667 rc
= ACTION_PerformAction(iap
->package
,action
,FALSE
);
669 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
672 if (rc
!= ERROR_SUCCESS
)
673 ERR("Execution halted due to error (%i)\n",rc
);
678 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
682 static const WCHAR ExecSeqQuery
[] =
683 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
684 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
685 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
686 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
687 'O','R','D','E','R',' ', 'B','Y',' ',
688 '`','S','e','q','u','e','n','c','e','`',0 };
690 static const WCHAR IVQuery
[] =
691 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
692 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
693 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
694 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
695 ' ','\'', 'I','n','s','t','a','l','l',
696 'V','a','l','i','d','a','t','e','\'', 0};
698 iterate_action_param iap
;
700 iap
.package
= package
;
703 if (package
->script
->ExecuteSequenceRun
)
705 TRACE("Execute Sequence already Run\n");
706 return ERROR_SUCCESS
;
709 package
->script
->ExecuteSequenceRun
= TRUE
;
711 /* get the sequence number */
714 row
= MSI_QueryGetRecord(package
->db
, IVQuery
);
716 return ERROR_FUNCTION_FAILED
;
717 seq
= MSI_RecordGetInteger(row
,1);
718 msiobj_release(&row
->hdr
);
721 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
722 if (rc
== ERROR_SUCCESS
)
724 TRACE("Running the actions\n");
726 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
727 msiobj_release(&view
->hdr
);
733 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
737 static const WCHAR ExecSeqQuery
[] =
738 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
739 '`','I','n','s','t','a','l','l',
740 'U','I','S','e','q','u','e','n','c','e','`',
741 ' ','W','H','E','R','E',' ',
742 '`','S','e','q','u','e','n','c','e','`',' ',
743 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
744 '`','S','e','q','u','e','n','c','e','`',0};
745 iterate_action_param iap
;
747 iap
.package
= package
;
750 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
752 if (rc
== ERROR_SUCCESS
)
754 TRACE("Running the actions \n");
756 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
757 msiobj_release(&view
->hdr
);
763 /********************************************************
764 * ACTION helper functions and functions that perform the actions
765 *******************************************************/
766 static BOOL
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
,
767 UINT
* rc
, BOOL force
)
773 if (!run
&& !package
->script
->CurrentlyScripting
)
778 if (strcmpW(action
,szInstallFinalize
) == 0 ||
779 strcmpW(action
,szInstallExecute
) == 0 ||
780 strcmpW(action
,szInstallExecuteAgain
) == 0)
785 while (StandardActions
[i
].action
!= NULL
)
787 if (strcmpW(StandardActions
[i
].action
, action
)==0)
789 ce_actiontext(package
, action
);
792 ui_actioninfo(package
, action
, TRUE
, 0);
793 *rc
= schedule_action(package
,INSTALL_SCRIPT
,action
);
794 ui_actioninfo(package
, action
, FALSE
, *rc
);
798 ui_actionstart(package
, action
);
799 if (StandardActions
[i
].handler
)
801 *rc
= StandardActions
[i
].handler(package
);
805 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action
));
817 static BOOL
ACTION_HandleDialogBox( MSIPACKAGE
*package
, LPCWSTR dialog
, UINT
* rc
)
821 if (ACTION_DialogBox(package
,dialog
) == ERROR_SUCCESS
)
823 *rc
= package
->CurrentInstallState
;
829 static BOOL
ACTION_HandleCustomAction( MSIPACKAGE
* package
, LPCWSTR action
,
830 UINT
* rc
, BOOL force
)
835 arc
= ACTION_CustomAction(package
,action
, force
);
837 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
846 * A lot of actions are really important even if they don't do anything
847 * explicit... Lots of properties are set at the beginning of the installation
848 * CostFinalize does a bunch of work to translate the directories and such
850 * But until I get write access to the database that is hard, so I am going to
851 * hack it to see if I can get something to run.
853 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, BOOL force
)
855 UINT rc
= ERROR_SUCCESS
;
858 TRACE("Performing action (%s)\n",debugstr_w(action
));
860 handled
= ACTION_HandleStandardAction(package
, action
, &rc
, force
);
863 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, force
);
867 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
868 rc
= ERROR_FUNCTION_NOT_CALLED
;
871 package
->CurrentInstallState
= rc
;
875 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
)
877 UINT rc
= ERROR_SUCCESS
;
878 BOOL handled
= FALSE
;
880 TRACE("Performing action (%s)\n",debugstr_w(action
));
882 handled
= ACTION_HandleStandardAction(package
, action
, &rc
,TRUE
);
885 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, FALSE
);
888 handled
= ACTION_HandleDialogBox(package
, action
, &rc
);
890 msi_dialog_check_messages( NULL
);
894 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
895 rc
= ERROR_FUNCTION_NOT_CALLED
;
898 package
->CurrentInstallState
= rc
;
904 * Actual Action Handlers
907 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
909 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
915 dir
= MSI_RecordGetString(row
,1);
918 ERR("Unable to get folder id \n");
919 return ERROR_SUCCESS
;
922 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,&folder
);
925 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
926 return ERROR_SUCCESS
;
929 TRACE("Folder is %s\n",debugstr_w(full_path
));
932 uirow
= MSI_CreateRecord(1);
933 MSI_RecordSetStringW(uirow
,1,full_path
);
934 ui_actiondata(package
,szCreateFolders
,uirow
);
935 msiobj_release( &uirow
->hdr
);
937 if (folder
->State
== 0)
938 create_full_pathW(full_path
);
942 HeapFree(GetProcessHeap(),0,full_path
);
943 return ERROR_SUCCESS
;
948 * Also we cannot enable/disable components either, so for now I am just going
949 * to do all the directories for all the components.
951 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
953 static const WCHAR ExecSeqQuery
[] =
954 {'S','E','L','E','C','T',' ',
955 '`','D','i','r','e','c','t','o','r','y','_','`',
956 ' ','F','R','O','M',' ',
957 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
961 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
962 if (rc
!= ERROR_SUCCESS
)
963 return ERROR_SUCCESS
;
965 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
966 msiobj_release(&view
->hdr
);
971 static int load_component(MSIPACKAGE
* package
, MSIRECORD
* row
)
973 int index
= package
->loaded_components
;
976 /* fill in the data */
978 package
->loaded_components
++;
979 if (package
->loaded_components
== 1)
980 package
->components
= HeapAlloc(GetProcessHeap(),0,
981 sizeof(MSICOMPONENT
));
983 package
->components
= HeapReAlloc(GetProcessHeap(),0,
984 package
->components
, package
->loaded_components
*
985 sizeof(MSICOMPONENT
));
987 memset(&package
->components
[index
],0,sizeof(MSICOMPONENT
));
989 sz
= IDENTIFIER_SIZE
;
990 MSI_RecordGetStringW(row
,1,package
->components
[index
].Component
,&sz
);
992 TRACE("Loading Component %s\n",
993 debugstr_w(package
->components
[index
].Component
));
996 if (!MSI_RecordIsNull(row
,2))
997 MSI_RecordGetStringW(row
,2,package
->components
[index
].ComponentId
,&sz
);
999 sz
= IDENTIFIER_SIZE
;
1000 MSI_RecordGetStringW(row
,3,package
->components
[index
].Directory
,&sz
);
1002 package
->components
[index
].Attributes
= MSI_RecordGetInteger(row
,4);
1005 MSI_RecordGetStringW(row
,5,package
->components
[index
].Condition
,&sz
);
1007 sz
= IDENTIFIER_SIZE
;
1008 MSI_RecordGetStringW(row
,6,package
->components
[index
].KeyPath
,&sz
);
1010 package
->components
[index
].Installed
= INSTALLSTATE_ABSENT
;
1011 package
->components
[index
].Action
= INSTALLSTATE_UNKNOWN
;
1012 package
->components
[index
].ActionRequest
= INSTALLSTATE_UNKNOWN
;
1014 package
->components
[index
].Enabled
= TRUE
;
1019 static void load_feature(MSIPACKAGE
* package
, MSIRECORD
* row
)
1021 int index
= package
->loaded_features
;
1023 static const WCHAR Query1
[] =
1024 {'S','E','L','E','C','T',' ',
1025 '`','C','o','m','p','o','n','e','n','t','_','`',
1026 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1027 'C','o','m','p','o','n','e','n','t','s','`',' ',
1028 'W','H','E','R','E',' ',
1029 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1030 static const WCHAR Query2
[] =
1031 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1032 '`','C','o','m','p','o','n','e','n','t','`',' ',
1033 'W','H','E','R','E',' ',
1034 '`','C','o','m','p','o','n','e','n','t','`',' ',
1035 '=','\'','%','s','\'',0};
1042 /* fill in the data */
1044 package
->loaded_features
++;
1045 if (package
->loaded_features
== 1)
1046 package
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE
));
1048 package
->features
= HeapReAlloc(GetProcessHeap(),0,package
->features
,
1049 package
->loaded_features
* sizeof(MSIFEATURE
));
1051 memset(&package
->features
[index
],0,sizeof(MSIFEATURE
));
1053 sz
= IDENTIFIER_SIZE
;
1054 MSI_RecordGetStringW(row
,1,package
->features
[index
].Feature
,&sz
);
1056 TRACE("Loading feature %s\n",debugstr_w(package
->features
[index
].Feature
));
1058 sz
= IDENTIFIER_SIZE
;
1059 if (!MSI_RecordIsNull(row
,2))
1060 MSI_RecordGetStringW(row
,2,package
->features
[index
].Feature_Parent
,&sz
);
1063 if (!MSI_RecordIsNull(row
,3))
1064 MSI_RecordGetStringW(row
,3,package
->features
[index
].Title
,&sz
);
1067 if (!MSI_RecordIsNull(row
,4))
1068 MSI_RecordGetStringW(row
,4,package
->features
[index
].Description
,&sz
);
1070 if (!MSI_RecordIsNull(row
,5))
1071 package
->features
[index
].Display
= MSI_RecordGetInteger(row
,5);
1073 package
->features
[index
].Level
= MSI_RecordGetInteger(row
,6);
1075 sz
= IDENTIFIER_SIZE
;
1076 if (!MSI_RecordIsNull(row
,7))
1077 MSI_RecordGetStringW(row
,7,package
->features
[index
].Directory
,&sz
);
1079 package
->features
[index
].Attributes
= MSI_RecordGetInteger(row
,8);
1081 package
->features
[index
].Installed
= INSTALLSTATE_ABSENT
;
1082 package
->features
[index
].Action
= INSTALLSTATE_UNKNOWN
;
1083 package
->features
[index
].ActionRequest
= INSTALLSTATE_UNKNOWN
;
1085 /* load feature components */
1087 rc
= MSI_OpenQuery(package
->db
, &view
, Query1
, package
->features
[index
].Feature
);
1088 if (rc
!= ERROR_SUCCESS
)
1090 rc
= MSI_ViewExecute(view
,0);
1091 if (rc
!= ERROR_SUCCESS
)
1093 MSI_ViewClose(view
);
1094 msiobj_release(&view
->hdr
);
1102 INT cnt
= package
->features
[index
].ComponentCount
;
1104 rc
= MSI_ViewFetch(view
,&row2
);
1105 if (rc
!= ERROR_SUCCESS
)
1108 component
= MSI_RecordGetString(row2
,1);
1110 /* check to see if the component is already loaded */
1111 c_indx
= get_loaded_component(package
,component
);
1114 TRACE("Component %s already loaded at %i\n", debugstr_w(component
),
1116 package
->features
[index
].Components
[cnt
] = c_indx
;
1117 package
->features
[index
].ComponentCount
++;
1118 msiobj_release( &row2
->hdr
);
1122 rc
= MSI_OpenQuery(package
->db
, &view2
, Query2
, component
);
1123 if (rc
!= ERROR_SUCCESS
)
1125 msiobj_release( &row2
->hdr
);
1128 rc
= MSI_ViewExecute(view2
,0);
1129 if (rc
!= ERROR_SUCCESS
)
1131 msiobj_release( &row2
->hdr
);
1132 MSI_ViewClose(view2
);
1133 msiobj_release( &view2
->hdr
);
1140 rc
= MSI_ViewFetch(view2
,&row3
);
1141 if (rc
!= ERROR_SUCCESS
)
1143 c_indx
= load_component(package
,row3
);
1144 msiobj_release( &row3
->hdr
);
1146 package
->features
[index
].Components
[cnt
] = c_indx
;
1147 package
->features
[index
].ComponentCount
++;
1148 TRACE("Loaded new component to index %i\n",c_indx
);
1150 MSI_ViewClose(view2
);
1151 msiobj_release( &view2
->hdr
);
1152 msiobj_release( &row2
->hdr
);
1154 MSI_ViewClose(view
);
1155 msiobj_release(&view
->hdr
);
1158 static UINT
load_file(MSIPACKAGE
* package
, MSIRECORD
* row
)
1160 DWORD index
= package
->loaded_files
;
1163 /* fill in the data */
1165 package
->loaded_files
++;
1166 if (package
->loaded_files
== 1)
1167 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
1169 package
->files
= HeapReAlloc(GetProcessHeap(),0,
1170 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
1172 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
1174 package
->files
[index
].File
= load_dynamic_stringW(row
, 1);
1176 component
= MSI_RecordGetString(row
, 2);
1177 package
->files
[index
].ComponentIndex
= get_loaded_component(package
,
1180 if (package
->files
[index
].ComponentIndex
== -1)
1181 ERR("Unfound Component %s\n",debugstr_w(component
));
1183 package
->files
[index
].FileName
= load_dynamic_stringW(row
,3);
1184 reduce_to_longfilename(package
->files
[index
].FileName
);
1186 package
->files
[index
].ShortName
= load_dynamic_stringW(row
,3);
1187 reduce_to_shortfilename(package
->files
[index
].ShortName
);
1189 package
->files
[index
].FileSize
= MSI_RecordGetInteger(row
,4);
1190 package
->files
[index
].Version
= load_dynamic_stringW(row
, 5);
1191 package
->files
[index
].Language
= load_dynamic_stringW(row
, 6);
1192 package
->files
[index
].Attributes
= MSI_RecordGetInteger(row
,7);
1193 package
->files
[index
].Sequence
= MSI_RecordGetInteger(row
,8);
1195 package
->files
[index
].Temporary
= FALSE
;
1196 package
->files
[index
].State
= 0;
1198 TRACE("File Loaded (%s)\n",debugstr_w(package
->files
[index
].File
));
1200 return ERROR_SUCCESS
;
1203 static UINT
load_all_files(MSIPACKAGE
*package
)
1208 static const WCHAR Query
[] =
1209 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1210 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1211 '`','S','e','q','u','e','n','c','e','`', 0};
1214 return ERROR_INVALID_HANDLE
;
1216 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1217 if (rc
!= ERROR_SUCCESS
)
1218 return ERROR_SUCCESS
;
1220 rc
= MSI_ViewExecute(view
, 0);
1221 if (rc
!= ERROR_SUCCESS
)
1223 MSI_ViewClose(view
);
1224 msiobj_release(&view
->hdr
);
1225 return ERROR_SUCCESS
;
1230 rc
= MSI_ViewFetch(view
,&row
);
1231 if (rc
!= ERROR_SUCCESS
)
1236 load_file(package
,row
);
1237 msiobj_release(&row
->hdr
);
1239 MSI_ViewClose(view
);
1240 msiobj_release(&view
->hdr
);
1242 return ERROR_SUCCESS
;
1247 * I am not doing any of the costing functionality yet.
1248 * Mostly looking at doing the Component and Feature loading
1250 * The native MSI does A LOT of modification to tables here. Mostly adding
1251 * a lot of temporary columns to the Feature and Component tables.
1253 * note: Native msi also tracks the short filename. But I am only going to
1254 * track the long ones. Also looking at this directory table
1255 * it appears that the directory table does not get the parents
1256 * resolved base on property only based on their entries in the
1259 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1264 static const WCHAR Query_all
[] =
1265 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1266 '`','F','e','a','t','u','r','e','`',0};
1267 static const WCHAR szCosting
[] =
1268 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1269 static const WCHAR szZero
[] = { '0', 0 };
1273 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1275 return ERROR_SUCCESS
;
1277 MSI_SetPropertyW(package
, szCosting
, szZero
);
1278 MSI_SetPropertyW(package
, cszRootDrive
, c_colon
);
1280 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1281 if (rc
!= ERROR_SUCCESS
)
1283 rc
= MSI_ViewExecute(view
,0);
1284 if (rc
!= ERROR_SUCCESS
)
1286 MSI_ViewClose(view
);
1287 msiobj_release(&view
->hdr
);
1294 rc
= MSI_ViewFetch(view
,&row
);
1295 if (rc
!= ERROR_SUCCESS
)
1298 load_feature(package
,row
);
1299 msiobj_release(&row
->hdr
);
1301 MSI_ViewClose(view
);
1302 msiobj_release(&view
->hdr
);
1304 load_all_files(package
);
1306 return ERROR_SUCCESS
;
1309 static UINT
execute_script(MSIPACKAGE
*package
, UINT script
)
1312 UINT rc
= ERROR_SUCCESS
;
1314 TRACE("Executing Script %i\n",script
);
1316 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
1319 action
= package
->script
->Actions
[script
][i
];
1320 ui_actionstart(package
, action
);
1321 TRACE("Executing Action (%s)\n",debugstr_w(action
));
1322 rc
= ACTION_PerformAction(package
, action
, TRUE
);
1323 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
][i
]);
1324 if (rc
!= ERROR_SUCCESS
)
1327 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
]);
1329 package
->script
->ActionCount
[script
] = 0;
1330 package
->script
->Actions
[script
] = NULL
;
1334 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1336 return ERROR_SUCCESS
;
1340 static INT
load_folder(MSIPACKAGE
*package
, const WCHAR
* dir
)
1342 static const WCHAR Query
[] =
1343 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1344 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1345 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1346 ' ','=',' ','\'','%','s','\'',
1348 LPWSTR ptargetdir
, targetdir
, srcdir
;
1350 LPWSTR shortname
= NULL
;
1351 MSIRECORD
* row
= 0;
1355 TRACE("Looking for dir %s\n",debugstr_w(dir
));
1357 for (i
= 0; i
< package
->loaded_folders
; i
++)
1359 if (strcmpW(package
->folders
[i
].Directory
,dir
)==0)
1361 TRACE(" %s retuning on index %lu\n",debugstr_w(dir
),i
);
1366 TRACE("Working to load %s\n",debugstr_w(dir
));
1368 index
= package
->loaded_folders
++;
1369 if (package
->loaded_folders
==1)
1370 package
->folders
= HeapAlloc(GetProcessHeap(),0,
1373 package
->folders
= HeapReAlloc(GetProcessHeap(),0,
1374 package
->folders
, package
->loaded_folders
*
1377 memset(&package
->folders
[index
],0,sizeof(MSIFOLDER
));
1379 package
->folders
[index
].Directory
= strdupW(dir
);
1381 row
= MSI_QueryGetRecord(package
->db
, Query
, dir
);
1385 ptargetdir
= targetdir
= load_dynamic_stringW(row
,3);
1387 /* split src and target dir */
1388 if (strchrW(targetdir
,':'))
1390 srcdir
=strchrW(targetdir
,':');
1397 /* for now only pick long filename versions */
1398 if (strchrW(targetdir
,'|'))
1400 shortname
= targetdir
;
1401 targetdir
= strchrW(targetdir
,'|');
1405 /* for the sourcedir pick the short filename */
1406 if (srcdir
&& strchrW(srcdir
,'|'))
1408 LPWSTR p
= strchrW(srcdir
,'|');
1412 /* now check for root dirs */
1413 if (targetdir
[0] == '.' && targetdir
[1] == 0)
1416 if (srcdir
&& srcdir
[0] == '.' && srcdir
[1] == 0)
1421 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir
));
1422 HeapFree(GetProcessHeap(),0, package
->folders
[index
].TargetDefault
);
1423 package
->folders
[index
].TargetDefault
= strdupW(targetdir
);
1427 package
->folders
[index
].SourceDefault
= strdupW(srcdir
);
1429 package
->folders
[index
].SourceDefault
= strdupW(shortname
);
1431 package
->folders
[index
].SourceDefault
= strdupW(targetdir
);
1432 HeapFree(GetProcessHeap(), 0, ptargetdir
);
1433 TRACE(" SourceDefault = %s\n",debugstr_w(package
->folders
[index
].SourceDefault
));
1435 parent
= MSI_RecordGetString(row
,2);
1438 i
= load_folder(package
,parent
);
1439 package
->folders
[index
].ParentIndex
= i
;
1440 TRACE("Parent is index %i... %s %s\n",
1441 package
->folders
[index
].ParentIndex
,
1442 debugstr_w(package
->folders
[package
->folders
[index
].ParentIndex
].Directory
),
1443 debugstr_w(parent
));
1446 package
->folders
[index
].ParentIndex
= -2;
1448 package
->folders
[index
].Property
= load_dynamic_property(package
, dir
,NULL
);
1450 msiobj_release(&row
->hdr
);
1451 TRACE(" %s retuning on index %i\n",debugstr_w(dir
),index
);
1455 /* scan for and update current install states */
1456 static void ACTION_UpdateInstallStates(MSIPACKAGE
*package
)
1461 productcode
= load_dynamic_property(package
,szProductCode
,NULL
);
1463 for (i
= 0; i
< package
->loaded_components
; i
++)
1466 res
= MsiGetComponentPathW(productcode
,
1467 package
->components
[i
].ComponentId
, NULL
, NULL
);
1469 res
= INSTALLSTATE_ABSENT
;
1470 package
->components
[i
].Installed
= res
;
1473 for (i
= 0; i
< package
->loaded_features
; i
++)
1475 INSTALLSTATE res
= -10;
1477 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
1479 MSICOMPONENT
* component
= &package
->components
[package
->features
[i
].
1482 res
= component
->Installed
;
1485 if (res
== component
->Installed
)
1488 if (res
!= component
->Installed
)
1489 res
= INSTALLSTATE_INCOMPLETE
;
1495 static BOOL
process_state_property (MSIPACKAGE
* package
, LPCWSTR property
,
1498 static const WCHAR all
[]={'A','L','L',0};
1499 LPWSTR override
= NULL
;
1503 override
= load_dynamic_property(package
, property
, NULL
);
1507 for(i
= 0; i
< package
->loaded_features
; i
++)
1509 if (strcmpiW(override
,all
)==0)
1511 package
->features
[i
].ActionRequest
= state
;
1512 package
->features
[i
].Action
= state
;
1516 LPWSTR ptr
= override
;
1517 LPWSTR ptr2
= strchrW(override
,',');
1522 strncmpW(ptr
,package
->features
[i
].Feature
, ptr2
-ptr
)==0)
1524 strcmpW(ptr
,package
->features
[i
].Feature
)==0))
1526 package
->features
[i
].ActionRequest
= state
;
1527 package
->features
[i
].Action
= state
;
1533 ptr2
= strchrW(ptr
,',');
1540 HeapFree(GetProcessHeap(),0,override
);
1546 static UINT
SetFeatureStates(MSIPACKAGE
*package
)
1552 static const WCHAR szlevel
[] =
1553 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1554 static const WCHAR szAddLocal
[] =
1555 {'A','D','D','L','O','C','A','L',0};
1556 static const WCHAR szRemove
[] =
1557 {'R','E','M','O','V','E',0};
1558 BOOL override
= FALSE
;
1560 /* I do not know if this is where it should happen.. but */
1562 TRACE("Checking Install Level\n");
1564 level
= load_dynamic_property(package
,szlevel
,NULL
);
1567 install_level
= atoiW(level
);
1568 HeapFree(GetProcessHeap(), 0, level
);
1573 /* ok hereis the _real_ rub
1574 * all these activation/deactivation things happen in order and things
1575 * later on the list override things earlier on the list.
1576 * 1) INSTALLLEVEL processing
1586 * 11) FILEADDDEFAULT
1587 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1588 * ignored for all the features. seems strange, especially since it is not
1589 * documented anywhere, but it is how it works.
1591 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1592 * REMOVE are the big ones, since we don't handle administrative installs
1595 override
|= process_state_property(package
,szAddLocal
,INSTALLSTATE_LOCAL
);
1596 override
|= process_state_property(package
,szRemove
,INSTALLSTATE_ABSENT
);
1600 for(i
= 0; i
< package
->loaded_features
; i
++)
1602 BOOL feature_state
= ((package
->features
[i
].Level
> 0) &&
1603 (package
->features
[i
].Level
<= install_level
));
1605 if ((feature_state
) &&
1606 (package
->features
[i
].Action
== INSTALLSTATE_UNKNOWN
))
1608 if (package
->features
[i
].Attributes
&
1609 msidbFeatureAttributesFavorSource
)
1611 package
->features
[i
].ActionRequest
= INSTALLSTATE_SOURCE
;
1612 package
->features
[i
].Action
= INSTALLSTATE_SOURCE
;
1614 else if (package
->features
[i
].Attributes
&
1615 msidbFeatureAttributesFavorAdvertise
)
1617 package
->features
[i
].ActionRequest
=INSTALLSTATE_ADVERTISED
;
1618 package
->features
[i
].Action
=INSTALLSTATE_ADVERTISED
;
1622 package
->features
[i
].ActionRequest
= INSTALLSTATE_LOCAL
;
1623 package
->features
[i
].Action
= INSTALLSTATE_LOCAL
;
1630 /* set the Preselected Property */
1631 static const WCHAR szPreselected
[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1632 static const WCHAR szOne
[] = { '1', 0 };
1634 MSI_SetPropertyW(package
,szPreselected
,szOne
);
1638 * now we want to enable or disable components base on feature
1641 for(i
= 0; i
< package
->loaded_features
; i
++)
1643 MSIFEATURE
* feature
= &package
->features
[i
];
1644 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1645 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
1646 feature
->ActionRequest
);
1648 for( j
= 0; j
< feature
->ComponentCount
; j
++)
1650 MSICOMPONENT
* component
= &package
->components
[
1651 feature
->Components
[j
]];
1653 if (!component
->Enabled
)
1655 component
->Action
= INSTALLSTATE_UNKNOWN
;
1656 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1660 if (feature
->Action
== INSTALLSTATE_LOCAL
)
1662 component
->Action
= INSTALLSTATE_LOCAL
;
1663 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1665 else if (feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1667 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1668 (component
->Action
== INSTALLSTATE_ABSENT
) ||
1669 (component
->Action
== INSTALLSTATE_ADVERTISED
))
1672 component
->Action
= INSTALLSTATE_SOURCE
;
1673 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1676 else if (feature
->ActionRequest
== INSTALLSTATE_ADVERTISED
)
1678 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1679 (component
->Action
== INSTALLSTATE_ABSENT
))
1682 component
->Action
= INSTALLSTATE_ADVERTISED
;
1683 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1686 else if (feature
->ActionRequest
== INSTALLSTATE_ABSENT
)
1688 if (component
->Action
== INSTALLSTATE_UNKNOWN
)
1690 component
->Action
= INSTALLSTATE_ABSENT
;
1691 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
1698 for(i
= 0; i
< package
->loaded_components
; i
++)
1700 MSICOMPONENT
* component
= &package
->components
[i
];
1702 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1703 debugstr_w(component
->Component
), component
->Installed
,
1704 component
->Action
, component
->ActionRequest
);
1708 return ERROR_SUCCESS
;
1711 static UINT
ITERATE_CostFinalizeDirectories(MSIRECORD
*row
, LPVOID param
)
1713 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1717 name
= MSI_RecordGetString(row
,1);
1719 /* This helper function now does ALL the work */
1720 TRACE("Dir %s ...\n",debugstr_w(name
));
1721 load_folder(package
,name
);
1722 path
= resolve_folder(package
,name
,FALSE
,TRUE
,NULL
);
1723 TRACE("resolves to %s\n",debugstr_w(path
));
1724 HeapFree( GetProcessHeap(), 0, path
);
1726 return ERROR_SUCCESS
;
1729 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1731 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1735 Feature
= MSI_RecordGetString(row
,1);
1737 feature_index
= get_loaded_feature(package
,Feature
);
1738 if (feature_index
< 0)
1739 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature
));
1743 Condition
= MSI_RecordGetString(row
,3);
1745 if (MSI_EvaluateConditionW(package
,Condition
) ==
1748 int level
= MSI_RecordGetInteger(row
,2);
1749 TRACE("Reseting feature %s to level %i\n",
1750 debugstr_w(Feature
), level
);
1751 package
->features
[feature_index
].Level
= level
;
1754 return ERROR_SUCCESS
;
1759 * A lot is done in this function aside from just the costing.
1760 * The costing needs to be implemented at some point but for now I am going
1761 * to focus on the directory building
1764 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
1766 static const WCHAR ExecSeqQuery
[] =
1767 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1768 '`','D','i','r','e','c','t','o','r','y','`',0};
1769 static const WCHAR ConditionQuery
[] =
1770 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1771 '`','C','o','n','d','i','t','i','o','n','`',0};
1772 static const WCHAR szCosting
[] =
1773 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1774 static const WCHAR szlevel
[] =
1775 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1776 static const WCHAR szOne
[] = { '1', 0 };
1784 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1786 return ERROR_SUCCESS
;
1788 TRACE("Building Directory properties\n");
1790 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1791 if (rc
== ERROR_SUCCESS
)
1793 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeDirectories
,
1795 msiobj_release(&view
->hdr
);
1798 TRACE("File calculations %i files\n",package
->loaded_files
);
1800 for (i
= 0; i
< package
->loaded_files
; i
++)
1802 MSICOMPONENT
* comp
= NULL
;
1803 MSIFILE
* file
= NULL
;
1805 file
= &package
->files
[i
];
1806 if (file
->ComponentIndex
>= 0)
1807 comp
= &package
->components
[file
->ComponentIndex
];
1809 if (file
->Temporary
== TRUE
)
1816 /* calculate target */
1817 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
1819 HeapFree(GetProcessHeap(),0,file
->TargetPath
);
1821 TRACE("file %s is named %s\n",
1822 debugstr_w(file
->File
),debugstr_w(file
->FileName
));
1824 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
1826 HeapFree(GetProcessHeap(),0,p
);
1828 TRACE("file %s resolves to %s\n",
1829 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
1831 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
1834 comp
->Cost
+= file
->FileSize
;
1844 static const WCHAR name
[] =
1846 static const WCHAR name_fmt
[] =
1847 {'%','u','.','%','u','.','%','u','.','%','u',0};
1848 WCHAR filever
[0x100];
1849 VS_FIXEDFILEINFO
*lpVer
;
1851 TRACE("Version comparison.. \n");
1852 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
1853 version
= HeapAlloc(GetProcessHeap(),0,versize
);
1854 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
1856 VerQueryValueW(version
, name
, (LPVOID
*)&lpVer
, &sz
);
1858 sprintfW(filever
,name_fmt
,
1859 HIWORD(lpVer
->dwFileVersionMS
),
1860 LOWORD(lpVer
->dwFileVersionMS
),
1861 HIWORD(lpVer
->dwFileVersionLS
),
1862 LOWORD(lpVer
->dwFileVersionLS
));
1864 TRACE("new %s old %s\n", debugstr_w(file
->Version
),
1865 debugstr_w(filever
));
1866 if (strcmpiW(filever
,file
->Version
)<0)
1869 FIXME("cost should be diff in size\n");
1870 comp
->Cost
+= file
->FileSize
;
1874 HeapFree(GetProcessHeap(),0,version
);
1882 TRACE("Evaluating Condition Table\n");
1884 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
1885 if (rc
== ERROR_SUCCESS
)
1887 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeConditions
,
1889 msiobj_release(&view
->hdr
);
1892 TRACE("Enabling or Disabling Components\n");
1893 for (i
= 0; i
< package
->loaded_components
; i
++)
1895 if (package
->components
[i
].Condition
[0])
1897 if (MSI_EvaluateConditionW(package
,
1898 package
->components
[i
].Condition
) == MSICONDITION_FALSE
)
1900 TRACE("Disabling component %s\n",
1901 debugstr_w(package
->components
[i
].Component
));
1902 package
->components
[i
].Enabled
= FALSE
;
1907 MSI_SetPropertyW(package
,szCosting
,szOne
);
1908 /* set default run level if not set */
1909 level
= load_dynamic_property(package
,szlevel
,NULL
);
1911 MSI_SetPropertyW(package
,szlevel
, szOne
);
1913 HeapFree(GetProcessHeap(),0,level
);
1915 ACTION_UpdateInstallStates(package
);
1917 return SetFeatureStates(package
);
1922 /* OK this value is "interpreted" and then formatted based on the
1923 first few characters */
1924 static LPSTR
parse_value(MSIPACKAGE
*package
, LPCWSTR value
, DWORD
*type
,
1928 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
1934 LPWSTR deformated
= NULL
;
1937 deformat_string(package
, &value
[2], &deformated
);
1939 /* binary value type */
1943 *size
= (strlenW(ptr
)/2)+1;
1945 *size
= strlenW(ptr
)/2;
1947 data
= HeapAlloc(GetProcessHeap(),0,*size
);
1953 /* if uneven pad with a zero in front */
1959 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1961 TRACE("Uneven byte count\n");
1969 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1972 HeapFree(GetProcessHeap(),0,deformated
);
1974 TRACE("Data %li bytes(%i)\n",*size
,count
);
1981 deformat_string(package
, &value
[1], &deformated
);
1984 *size
= sizeof(DWORD
);
1985 data
= HeapAlloc(GetProcessHeap(),0,*size
);
1991 if ( (*p
< '0') || (*p
> '9') )
1997 if (deformated
[0] == '-')
2000 TRACE("DWORD %li\n",*(LPDWORD
)data
);
2002 HeapFree(GetProcessHeap(),0,deformated
);
2007 static const WCHAR szMulti
[] = {'[','~',']',0};
2016 *type
=REG_EXPAND_SZ
;
2024 if (strstrW(value
,szMulti
))
2025 *type
= REG_MULTI_SZ
;
2027 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
2032 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
2034 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
2035 static const WCHAR szHCR
[] =
2036 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
2037 'R','O','O','T','\\',0};
2038 static const WCHAR szHCU
[] =
2039 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
2040 'U','S','E','R','\\',0};
2041 static const WCHAR szHLM
[] =
2042 {'H','K','E','Y','_','L','O','C','A','L','_',
2043 'M','A','C','H','I','N','E','\\',0};
2044 static const WCHAR szHU
[] =
2045 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2047 LPSTR value_data
= NULL
;
2048 HKEY root_key
, hkey
;
2051 LPCWSTR szRoot
, component
, name
, key
, value
;
2052 INT component_index
;
2056 BOOL check_first
= FALSE
;
2059 ui_progress(package
,2,0,0,0);
2066 component
= MSI_RecordGetString(row
, 6);
2067 component_index
= get_loaded_component(package
,component
);
2069 if (!ACTION_VerifyComponentForAction(package
, component_index
,
2070 INSTALLSTATE_LOCAL
))
2072 TRACE("Skipping write due to disabled component %s\n",
2073 debugstr_w(component
));
2075 package
->components
[component_index
].Action
=
2076 package
->components
[component_index
].Installed
;
2078 return ERROR_SUCCESS
;
2081 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
2083 name
= MSI_RecordGetString(row
, 4);
2084 if( MSI_RecordIsNull(row
,5) && name
)
2086 /* null values can have special meanings */
2087 if (name
[0]=='-' && name
[1] == 0)
2088 return ERROR_SUCCESS
;
2089 else if ((name
[0]=='+' && name
[1] == 0) ||
2090 (name
[0] == '*' && name
[1] == 0))
2095 root
= MSI_RecordGetInteger(row
,2);
2096 key
= MSI_RecordGetString(row
, 3);
2098 /* get the root key */
2101 case 0: root_key
= HKEY_CLASSES_ROOT
;
2104 case 1: root_key
= HKEY_CURRENT_USER
;
2107 case 2: root_key
= HKEY_LOCAL_MACHINE
;
2110 case 3: root_key
= HKEY_USERS
;
2114 ERR("Unknown root %i\n",root
);
2120 return ERROR_SUCCESS
;
2122 deformat_string(package
, key
, &deformated
);
2123 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
2124 uikey
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(WCHAR
));
2125 strcpyW(uikey
,szRoot
);
2126 strcatW(uikey
,deformated
);
2128 if (RegCreateKeyW( root_key
, deformated
, &hkey
))
2130 ERR("Could not create key %s\n",debugstr_w(deformated
));
2131 HeapFree(GetProcessHeap(),0,deformated
);
2132 HeapFree(GetProcessHeap(),0,uikey
);
2133 return ERROR_SUCCESS
;
2135 HeapFree(GetProcessHeap(),0,deformated
);
2137 value
= MSI_RecordGetString(row
,5);
2139 value_data
= parse_value(package
, value
, &type
, &size
);
2142 static const WCHAR szEmpty
[] = {0};
2143 value_data
= (LPSTR
)strdupW(szEmpty
);
2148 deformat_string(package
, name
, &deformated
);
2150 /* get the double nulls to terminate SZ_MULTI */
2151 if (type
== REG_MULTI_SZ
)
2152 size
+=sizeof(WCHAR
);
2156 TRACE("Setting value %s of %s\n",debugstr_w(deformated
),
2158 RegSetValueExW(hkey
, deformated
, 0, type
, value_data
, size
);
2163 rc
= RegQueryValueExW(hkey
, deformated
, NULL
, NULL
, NULL
, &sz
);
2164 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
2166 TRACE("value %s of %s checked already exists\n",
2167 debugstr_w(deformated
), debugstr_w(uikey
));
2171 TRACE("Checked and setting value %s of %s\n",
2172 debugstr_w(deformated
), debugstr_w(uikey
));
2173 if (deformated
|| size
)
2174 RegSetValueExW(hkey
, deformated
, 0, type
, value_data
, size
);
2179 uirow
= MSI_CreateRecord(3);
2180 MSI_RecordSetStringW(uirow
,2,deformated
);
2181 MSI_RecordSetStringW(uirow
,1,uikey
);
2184 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2186 MSI_RecordSetStringW(uirow
,3,value
);
2188 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2189 msiobj_release( &uirow
->hdr
);
2191 HeapFree(GetProcessHeap(),0,value_data
);
2192 HeapFree(GetProcessHeap(),0,deformated
);
2193 HeapFree(GetProcessHeap(),0,uikey
);
2195 return ERROR_SUCCESS
;
2198 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2202 static const WCHAR ExecSeqQuery
[] =
2203 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2204 '`','R','e','g','i','s','t','r','y','`',0 };
2207 return ERROR_INVALID_HANDLE
;
2209 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2210 if (rc
!= ERROR_SUCCESS
)
2211 return ERROR_SUCCESS
;
2213 /* increment progress bar each time action data is sent */
2214 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
2216 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2218 msiobj_release(&view
->hdr
);
2222 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
2224 package
->script
->CurrentlyScripting
= TRUE
;
2226 return ERROR_SUCCESS
;
2230 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
2234 static const WCHAR q1
[]=
2235 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2236 '`','R','e','g','i','s','t','r','y','`',0};
2239 MSIRECORD
* row
= 0;
2242 TRACE(" InstallValidate \n");
2244 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
2245 if (rc
!= ERROR_SUCCESS
)
2246 return ERROR_SUCCESS
;
2248 rc
= MSI_ViewExecute(view
, 0);
2249 if (rc
!= ERROR_SUCCESS
)
2251 MSI_ViewClose(view
);
2252 msiobj_release(&view
->hdr
);
2257 rc
= MSI_ViewFetch(view
,&row
);
2258 if (rc
!= ERROR_SUCCESS
)
2265 msiobj_release(&row
->hdr
);
2267 MSI_ViewClose(view
);
2268 msiobj_release(&view
->hdr
);
2270 total
= total
+ progress
* REG_PROGRESS_VALUE
;
2271 total
= total
+ package
->loaded_components
* COMPONENT_PROGRESS_VALUE
;
2272 for (i
=0; i
< package
->loaded_files
; i
++)
2273 total
+= package
->files
[i
].FileSize
;
2274 ui_progress(package
,0,total
,0,0);
2276 for(i
= 0; i
< package
->loaded_features
; i
++)
2278 MSIFEATURE
* feature
= &package
->features
[i
];
2279 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2280 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
2281 feature
->ActionRequest
);
2284 return ERROR_SUCCESS
;
2287 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
2290 MSIQUERY
* view
= NULL
;
2291 MSIRECORD
* row
= 0;
2292 static const WCHAR ExecSeqQuery
[] =
2293 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2294 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2295 static const WCHAR title
[]=
2296 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2298 TRACE("Checking launch conditions\n");
2300 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2301 if (rc
!= ERROR_SUCCESS
)
2302 return ERROR_SUCCESS
;
2304 rc
= MSI_ViewExecute(view
, 0);
2305 if (rc
!= ERROR_SUCCESS
)
2307 MSI_ViewClose(view
);
2308 msiobj_release(&view
->hdr
);
2313 while (rc
== ERROR_SUCCESS
)
2315 LPCWSTR cond
= NULL
;
2316 LPCWSTR message
= NULL
;
2318 rc
= MSI_ViewFetch(view
,&row
);
2319 if (rc
!= ERROR_SUCCESS
)
2325 cond
= MSI_RecordGetString(row
,1);
2327 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
2330 message
= MSI_RecordGetString(row
,2);
2331 deformat_string(package
,message
,&deformated
);
2332 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
2333 HeapFree(GetProcessHeap(),0,deformated
);
2334 rc
= ERROR_FUNCTION_FAILED
;
2336 msiobj_release(&row
->hdr
);
2338 MSI_ViewClose(view
);
2339 msiobj_release(&view
->hdr
);
2343 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, INT
2346 MSICOMPONENT
* cmp
= &package
->components
[component_index
];
2348 if (cmp
->KeyPath
[0]==0)
2350 LPWSTR p
= resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,NULL
);
2353 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
2355 MSIRECORD
* row
= 0;
2357 LPWSTR deformated
,buffer
,deformated_name
;
2359 static const WCHAR ExecSeqQuery
[] =
2360 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2361 '`','R','e','g','i','s','t','r','y','`',' ',
2362 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2363 ' ','=',' ' ,'\'','%','s','\'',0 };
2364 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
2365 static const WCHAR fmt2
[]=
2366 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2368 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
,cmp
->KeyPath
);
2372 root
= MSI_RecordGetInteger(row
,2);
2373 key
= MSI_RecordGetString(row
, 3);
2374 name
= MSI_RecordGetString(row
, 4);
2375 deformat_string(package
, key
, &deformated
);
2376 deformat_string(package
, name
, &deformated_name
);
2378 len
= strlenW(deformated
) + 6;
2379 if (deformated_name
)
2380 len
+=strlenW(deformated_name
);
2382 buffer
= HeapAlloc(GetProcessHeap(),0, len
*sizeof(WCHAR
));
2384 if (deformated_name
)
2385 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
2387 sprintfW(buffer
,fmt
,root
,deformated
);
2389 HeapFree(GetProcessHeap(),0,deformated
);
2390 HeapFree(GetProcessHeap(),0,deformated_name
);
2391 msiobj_release(&row
->hdr
);
2395 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2397 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2403 j
= get_loaded_file(package
,cmp
->KeyPath
);
2407 LPWSTR p
= strdupW(package
->files
[j
].TargetPath
);
2414 static HKEY
openSharedDLLsKey(void)
2417 static const WCHAR path
[] =
2418 {'S','o','f','t','w','a','r','e','\\',
2419 'M','i','c','r','o','s','o','f','t','\\',
2420 'W','i','n','d','o','w','s','\\',
2421 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2422 'S','h','a','r','e','d','D','L','L','s',0};
2424 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
2428 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
2433 DWORD sz
= sizeof(count
);
2436 hkey
= openSharedDLLsKey();
2437 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
2438 if (rc
!= ERROR_SUCCESS
)
2444 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
2448 hkey
= openSharedDLLsKey();
2450 RegSetValueExW(hkey
,path
,0,REG_DWORD
,
2451 (LPBYTE
)&count
,sizeof(count
));
2453 RegDeleteValueW(hkey
,path
);
2459 * Return TRUE if the count should be written out and FALSE if not
2461 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, UINT index
)
2467 /* only refcount DLLs */
2468 if (package
->components
[index
].KeyPath
[0]==0 ||
2469 package
->components
[index
].Attributes
&
2470 msidbComponentAttributesRegistryKeyPath
||
2471 package
->components
[index
].Attributes
&
2472 msidbComponentAttributesODBCDataSource
)
2476 count
= ACTION_GetSharedDLLsCount(package
->components
[index
].
2478 write
= (count
> 0);
2480 if (package
->components
[index
].Attributes
&
2481 msidbComponentAttributesSharedDllRefCount
)
2485 /* increment counts */
2486 for (j
= 0; j
< package
->loaded_features
; j
++)
2490 if (!ACTION_VerifyFeatureForAction(package
,j
,INSTALLSTATE_LOCAL
))
2493 for (i
= 0; i
< package
->features
[j
].ComponentCount
; i
++)
2495 if (package
->features
[j
].Components
[i
] == index
)
2499 /* decrement counts */
2500 for (j
= 0; j
< package
->loaded_features
; j
++)
2503 if (!ACTION_VerifyFeatureForAction(package
,j
,INSTALLSTATE_ABSENT
))
2506 for (i
= 0; i
< package
->features
[j
].ComponentCount
; i
++)
2508 if (package
->features
[j
].Components
[i
] == index
)
2513 /* ref count all the files in the component */
2515 for (j
= 0; j
< package
->loaded_files
; j
++)
2517 if (package
->files
[j
].Temporary
)
2519 if (package
->files
[j
].ComponentIndex
== index
)
2520 ACTION_WriteSharedDLLsCount(package
->files
[j
].TargetPath
,count
);
2523 /* add a count for permenent */
2524 if (package
->components
[index
].Attributes
&
2525 msidbComponentAttributesPermanent
)
2528 package
->components
[index
].RefCount
= count
;
2531 ACTION_WriteSharedDLLsCount(package
->components
[index
].FullKeypath
,
2532 package
->components
[index
].RefCount
);
2536 * Ok further analysis makes me think that this work is
2537 * actually done in the PublishComponents and PublishFeatures
2538 * step, and not here. It appears like the keypath and all that is
2539 * resolved in this step, however actually written in the Publish steps.
2540 * But we will leave it here for now because it is unclear
2542 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
2545 WCHAR squished_pc
[GUID_SIZE
];
2546 WCHAR squished_cc
[GUID_SIZE
];
2549 HKEY hkey
=0,hkey2
=0;
2552 return ERROR_INVALID_HANDLE
;
2554 /* writes the Component and Features values to the registry */
2555 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
2559 rc
= MSIREG_OpenComponents(&hkey
);
2560 if (rc
!= ERROR_SUCCESS
)
2563 squash_guid(productcode
,squished_pc
);
2564 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
2565 for (i
= 0; i
< package
->loaded_components
; i
++)
2567 ui_progress(package
,2,0,0,0);
2568 if (package
->components
[i
].ComponentId
[0]!=0)
2570 WCHAR
*keypath
= NULL
;
2573 squash_guid(package
->components
[i
].ComponentId
,squished_cc
);
2575 keypath
= resolve_keypath(package
,i
);
2576 package
->components
[i
].FullKeypath
= keypath
;
2578 /* do the refcounting */
2579 ACTION_RefCountComponent( package
, i
);
2581 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2582 debugstr_w(package
->components
[i
].Component
),
2583 debugstr_w(squished_cc
),
2584 debugstr_w(package
->components
[i
].FullKeypath
),
2585 package
->components
[i
].RefCount
);
2587 * Write the keypath out if the component is to be registered
2588 * and delete the key if the component is to be deregistered
2590 if (ACTION_VerifyComponentForAction(package
, i
,
2591 INSTALLSTATE_LOCAL
))
2593 rc
= RegCreateKeyW(hkey
,squished_cc
,&hkey2
);
2594 if (rc
!= ERROR_SUCCESS
)
2599 RegSetValueExW(hkey2
,squished_pc
,0,REG_SZ
,(LPVOID
)keypath
,
2600 (strlenW(keypath
)+1)*sizeof(WCHAR
));
2602 if (package
->components
[i
].Attributes
&
2603 msidbComponentAttributesPermanent
)
2605 static const WCHAR szPermKey
[] =
2606 { '0','0','0','0','0','0','0','0','0','0','0','0',
2607 '0','0','0','0','0','0','0', '0','0','0','0','0',
2608 '0','0','0','0','0','0','0','0',0};
2610 RegSetValueExW(hkey2
,szPermKey
,0,REG_SZ
,
2612 (strlenW(keypath
)+1)*sizeof(WCHAR
));
2618 uirow
= MSI_CreateRecord(3);
2619 MSI_RecordSetStringW(uirow
,1,productcode
);
2620 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].
2622 MSI_RecordSetStringW(uirow
,3,keypath
);
2623 ui_actiondata(package
,szProcessComponents
,uirow
);
2624 msiobj_release( &uirow
->hdr
);
2627 else if (ACTION_VerifyComponentForAction(package
, i
,
2628 INSTALLSTATE_ABSENT
))
2632 rc
= RegOpenKeyW(hkey
,squished_cc
,&hkey2
);
2633 if (rc
!= ERROR_SUCCESS
)
2636 RegDeleteValueW(hkey2
,squished_pc
);
2638 /* if the key is empty delete it */
2639 res
= RegEnumKeyExW(hkey2
,0,NULL
,0,0,NULL
,0,NULL
);
2641 if (res
== ERROR_NO_MORE_ITEMS
)
2642 RegDeleteKeyW(hkey
,squished_cc
);
2645 uirow
= MSI_CreateRecord(2);
2646 MSI_RecordSetStringW(uirow
,1,productcode
);
2647 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].
2649 ui_actiondata(package
,szProcessComponents
,uirow
);
2650 msiobj_release( &uirow
->hdr
);
2655 HeapFree(GetProcessHeap(), 0, productcode
);
2668 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
2669 LPWSTR lpszName
, LONG_PTR lParam
)
2672 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
2673 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
2677 if (!IS_INTRESOURCE(lpszName
))
2679 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
2683 sz
= strlenW(tl_struct
->source
)+4;
2684 sz
*= sizeof(WCHAR
);
2686 if ((INT
)lpszName
== 1)
2687 tl_struct
->path
= strdupW(tl_struct
->source
);
2690 tl_struct
->path
= HeapAlloc(GetProcessHeap(),0,sz
);
2691 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
2694 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
2695 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
2696 if (!SUCCEEDED(res
))
2698 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
2699 tl_struct
->path
= NULL
;
2704 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
2705 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
2707 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2711 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
2712 tl_struct
->path
= NULL
;
2714 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2715 ITypeLib_Release(tl_struct
->ptLib
);
2720 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
2723 * OK this is a bit confusing.. I am given a _Component key and I believe
2724 * that the file that is being registered as a type library is the "key file
2725 * of that component" which I interpret to mean "The file in the KeyPath of
2730 MSIRECORD
* row
= 0;
2731 static const WCHAR Query
[] =
2732 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2733 '`','T','y','p','e','L','i','b','`',0};
2736 return ERROR_INVALID_HANDLE
;
2738 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2739 if (rc
!= ERROR_SUCCESS
)
2740 return ERROR_SUCCESS
;
2742 rc
= MSI_ViewExecute(view
, 0);
2743 if (rc
!= ERROR_SUCCESS
)
2745 MSI_ViewClose(view
);
2746 msiobj_release(&view
->hdr
);
2754 typelib_struct tl_struct
;
2756 static const WCHAR szTYPELIB
[] = {'T','Y','P','E','L','I','B',0};
2758 rc
= MSI_ViewFetch(view
,&row
);
2759 if (rc
!= ERROR_SUCCESS
)
2765 component
= MSI_RecordGetString(row
,3);
2766 index
= get_loaded_component(package
,component
);
2769 msiobj_release(&row
->hdr
);
2773 if (!ACTION_VerifyComponentForAction(package
, index
,
2774 INSTALLSTATE_LOCAL
))
2776 TRACE("Skipping typelib reg due to disabled component\n");
2777 msiobj_release(&row
->hdr
);
2779 package
->components
[index
].Action
=
2780 package
->components
[index
].Installed
;
2785 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
2787 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
2791 msiobj_release(&row
->hdr
);
2795 module
= LoadLibraryExW(package
->files
[index
].TargetPath
, NULL
,
2796 LOAD_LIBRARY_AS_DATAFILE
);
2800 guid
= load_dynamic_stringW(row
,1);
2801 CLSIDFromString(guid
, &tl_struct
.clsid
);
2802 HeapFree(GetProcessHeap(),0,guid
);
2803 tl_struct
.source
= strdupW(package
->files
[index
].TargetPath
);
2804 tl_struct
.path
= NULL
;
2806 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
2807 (LONG_PTR
)&tl_struct
);
2809 if (tl_struct
.path
!= NULL
)
2815 helpid
= MSI_RecordGetString(row
,6);
2818 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,NULL
);
2819 res
= RegisterTypeLib(tl_struct
.ptLib
,tl_struct
.path
,help
);
2820 HeapFree(GetProcessHeap(),0,help
);
2822 if (!SUCCEEDED(res
))
2823 ERR("Failed to register type library %s\n",
2824 debugstr_w(tl_struct
.path
));
2827 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
2829 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
2832 ITypeLib_Release(tl_struct
.ptLib
);
2833 HeapFree(GetProcessHeap(),0,tl_struct
.path
);
2836 ERR("Failed to load type library %s\n",
2837 debugstr_w(tl_struct
.source
));
2839 FreeLibrary(module
);
2840 HeapFree(GetProcessHeap(),0,tl_struct
.source
);
2843 ERR("Could not load file! %s\n",
2844 debugstr_w(package
->files
[index
].TargetPath
));
2845 msiobj_release(&row
->hdr
);
2847 MSI_ViewClose(view
);
2848 msiobj_release(&view
->hdr
);
2852 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
2856 MSIRECORD
* row
= 0;
2857 static const WCHAR Query
[] =
2858 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2859 '`','S','h','o','r','t','c','u','t','`',0};
2865 return ERROR_INVALID_HANDLE
;
2867 res
= CoInitialize( NULL
);
2870 ERR("CoInitialize failed\n");
2871 return ERROR_FUNCTION_FAILED
;
2874 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2875 if (rc
!= ERROR_SUCCESS
)
2876 return ERROR_SUCCESS
;
2878 rc
= MSI_ViewExecute(view
, 0);
2879 if (rc
!= ERROR_SUCCESS
)
2881 MSI_ViewClose(view
);
2882 msiobj_release(&view
->hdr
);
2888 LPWSTR target_file
, target_folder
;
2890 WCHAR filename
[0x100];
2893 static const WCHAR szlnk
[]={'.','l','n','k',0};
2895 rc
= MSI_ViewFetch(view
,&row
);
2896 if (rc
!= ERROR_SUCCESS
)
2902 buffer
= MSI_RecordGetString(row
,4);
2903 index
= get_loaded_component(package
,buffer
);
2907 msiobj_release(&row
->hdr
);
2911 if (!ACTION_VerifyComponentForAction(package
, index
,
2912 INSTALLSTATE_LOCAL
))
2914 TRACE("Skipping shortcut creation due to disabled component\n");
2915 msiobj_release(&row
->hdr
);
2917 package
->components
[index
].Action
=
2918 package
->components
[index
].Installed
;
2923 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
2925 ui_actiondata(package
,szCreateShortcuts
,row
);
2927 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
2928 &IID_IShellLinkW
, (LPVOID
*) &sl
);
2932 ERR("Is IID_IShellLink\n");
2933 msiobj_release(&row
->hdr
);
2937 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
2940 ERR("Is IID_IPersistFile\n");
2941 msiobj_release(&row
->hdr
);
2945 buffer
= MSI_RecordGetString(row
,2);
2946 target_folder
= resolve_folder(package
, buffer
,FALSE
,FALSE
,NULL
);
2948 /* may be needed because of a bug somehwere else */
2949 create_full_pathW(target_folder
);
2952 MSI_RecordGetStringW(row
,3,filename
,&sz
);
2953 reduce_to_longfilename(filename
);
2954 if (!strchrW(filename
,'.') || strcmpiW(strchrW(filename
,'.'),szlnk
))
2955 strcatW(filename
,szlnk
);
2956 target_file
= build_directory_name(2, target_folder
, filename
);
2957 HeapFree(GetProcessHeap(),0,target_folder
);
2959 buffer
= MSI_RecordGetString(row
,5);
2960 if (strchrW(buffer
,'['))
2963 deformat_string(package
,buffer
,&deformated
);
2964 IShellLinkW_SetPath(sl
,deformated
);
2965 HeapFree(GetProcessHeap(),0,deformated
);
2970 FIXME("poorly handled shortcut format, advertised shortcut\n");
2971 keypath
= strdupW(package
->components
[index
].FullKeypath
);
2972 IShellLinkW_SetPath(sl
,keypath
);
2973 HeapFree(GetProcessHeap(),0,keypath
);
2976 if (!MSI_RecordIsNull(row
,6))
2979 buffer
= MSI_RecordGetString(row
,6);
2980 deformat_string(package
,buffer
,&deformated
);
2981 IShellLinkW_SetArguments(sl
,deformated
);
2982 HeapFree(GetProcessHeap(),0,deformated
);
2985 if (!MSI_RecordIsNull(row
,7))
2987 buffer
= MSI_RecordGetString(row
,7);
2988 IShellLinkW_SetDescription(sl
,buffer
);
2991 if (!MSI_RecordIsNull(row
,8))
2992 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
2994 if (!MSI_RecordIsNull(row
,9))
2999 buffer
= MSI_RecordGetString(row
,9);
3001 build_icon_path(package
,buffer
,&Path
);
3002 index
= MSI_RecordGetInteger(row
,10);
3004 IShellLinkW_SetIconLocation(sl
,Path
,index
);
3005 HeapFree(GetProcessHeap(),0,Path
);
3008 if (!MSI_RecordIsNull(row
,11))
3009 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
3011 if (!MSI_RecordIsNull(row
,12))
3014 buffer
= MSI_RecordGetString(row
,12);
3015 Path
= resolve_folder(package
, buffer
, FALSE
, FALSE
, NULL
);
3016 IShellLinkW_SetWorkingDirectory(sl
,Path
);
3017 HeapFree(GetProcessHeap(), 0, Path
);
3020 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
3021 IPersistFile_Save(pf
,target_file
,FALSE
);
3023 HeapFree(GetProcessHeap(),0,target_file
);
3025 IPersistFile_Release( pf
);
3026 IShellLinkW_Release( sl
);
3028 msiobj_release(&row
->hdr
);
3030 MSI_ViewClose(view
);
3031 msiobj_release(&view
->hdr
);
3041 * 99% of the work done here is only done for
3042 * advertised installs. However this is where the
3043 * Icon table is processed and written out
3044 * so that is what I am going to do here.
3046 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
3050 MSIRECORD
* row
= 0;
3051 static const WCHAR Query
[]=
3052 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3053 '`','I','c','o','n','`',0};
3055 /* for registry stuff */
3059 static const WCHAR szProductName
[] =
3060 {'P','r','o','d','u','c','t','N','a','m','e',0};
3061 static const WCHAR szPackageCode
[] =
3062 {'P','a','c','k','a','g','e','C','o','d','e',0};
3063 static const WCHAR szLanguage
[] =
3064 {'L','a','n','g','u','a','g','e',0};
3065 static const WCHAR szProductLanguage
[] =
3066 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3067 static const WCHAR szProductIcon
[] =
3068 {'P','r','o','d','u','c','t','I','c','o','n',0};
3069 static const WCHAR szARPProductIcon
[] =
3070 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
3071 static const WCHAR szProductVersion
[] =
3072 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3073 static const WCHAR szVersion
[] =
3074 {'V','e','r','s','i','o','n',0};
3078 MSIHANDLE hDb
, hSumInfo
;
3081 return ERROR_INVALID_HANDLE
;
3083 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3084 if (rc
!= ERROR_SUCCESS
)
3087 rc
= MSI_ViewExecute(view
, 0);
3088 if (rc
!= ERROR_SUCCESS
)
3090 MSI_ViewClose(view
);
3091 msiobj_release(&view
->hdr
);
3098 LPWSTR FilePath
=NULL
;
3099 LPCWSTR FileName
=NULL
;
3102 rc
= MSI_ViewFetch(view
,&row
);
3103 if (rc
!= ERROR_SUCCESS
)
3109 FileName
= MSI_RecordGetString(row
,1);
3112 ERR("Unable to get FileName\n");
3113 msiobj_release(&row
->hdr
);
3117 build_icon_path(package
,FileName
,&FilePath
);
3119 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
3121 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
3122 FILE_ATTRIBUTE_NORMAL
, NULL
);
3124 if (the_file
== INVALID_HANDLE_VALUE
)
3126 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
3127 msiobj_release(&row
->hdr
);
3128 HeapFree(GetProcessHeap(),0,FilePath
);
3136 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
3137 if (rc
!= ERROR_SUCCESS
)
3139 ERR("Failed to get stream\n");
3140 CloseHandle(the_file
);
3141 DeleteFileW(FilePath
);
3144 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
3145 } while (sz
== 1024);
3147 HeapFree(GetProcessHeap(),0,FilePath
);
3149 CloseHandle(the_file
);
3150 msiobj_release(&row
->hdr
);
3152 MSI_ViewClose(view
);
3153 msiobj_release(&view
->hdr
);
3156 /* ok there is a lot more done here but i need to figure out what */
3157 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
3161 rc
= MSIREG_OpenProductsKey(productcode
,&hkey
,TRUE
);
3162 if (rc
!= ERROR_SUCCESS
)
3165 rc
= MSIREG_OpenUserProductsKey(productcode
,&hukey
,TRUE
);
3166 if (rc
!= ERROR_SUCCESS
)
3170 buffer
= load_dynamic_property(package
,szProductName
,NULL
);
3171 size
= strlenW(buffer
)*sizeof(WCHAR
);
3172 RegSetValueExW(hukey
,szProductName
,0,REG_SZ
, (BYTE
*)buffer
,size
);
3173 HeapFree(GetProcessHeap(),0,buffer
);
3175 buffer
= load_dynamic_property(package
,szProductLanguage
,NULL
);
3176 size
= sizeof(DWORD
);
3177 langid
= atoiW(buffer
);
3178 RegSetValueExW(hukey
,szLanguage
,0,REG_DWORD
, (BYTE
*)&langid
,size
);
3179 HeapFree(GetProcessHeap(),0,buffer
);
3181 buffer
= load_dynamic_property(package
,szARPProductIcon
,NULL
);
3185 build_icon_path(package
,buffer
,&path
);
3186 size
= strlenW(path
) * sizeof(WCHAR
);
3187 RegSetValueExW(hukey
,szProductIcon
,0,REG_SZ
, (BYTE
*)path
,size
);
3189 HeapFree(GetProcessHeap(),0,buffer
);
3191 buffer
= load_dynamic_property(package
,szProductVersion
,NULL
);
3194 DWORD verdword
= build_version_dword(buffer
);
3195 size
= sizeof(DWORD
);
3196 RegSetValueExW(hukey
,szVersion
,0,REG_DWORD
, (BYTE
*)&verdword
,size
);
3198 HeapFree(GetProcessHeap(),0,buffer
);
3200 FIXME("Need to write more keys to the user registry\n");
3202 hDb
= alloc_msihandle( &package
->db
->hdr
);
3203 rc
= MsiGetSummaryInformationW(hDb
, NULL
, 0, &hSumInfo
);
3204 MsiCloseHandle(hDb
);
3205 if (rc
== ERROR_SUCCESS
)
3207 WCHAR guidbuffer
[0x200];
3209 rc
= MsiSummaryInfoGetPropertyW(hSumInfo
, 9, NULL
, NULL
, NULL
,
3211 if (rc
== ERROR_SUCCESS
)
3213 WCHAR squashed
[GUID_SIZE
];
3214 /* for now we only care about the first guid */
3215 LPWSTR ptr
= strchrW(guidbuffer
,';');
3217 squash_guid(guidbuffer
,squashed
);
3218 size
= strlenW(squashed
)*sizeof(WCHAR
);
3219 RegSetValueExW(hukey
,szPackageCode
,0,REG_SZ
, (LPSTR
)squashed
,
3224 ERR("Unable to query Revision_Number... \n");
3227 MsiCloseHandle(hSumInfo
);
3231 ERR("Unable to open Summary Information\n");
3237 HeapFree(GetProcessHeap(),0,productcode
);
3244 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
3248 MSIRECORD
* row
= 0;
3249 static const WCHAR ExecSeqQuery
[] =
3250 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3251 '`','I','n','i','F','i','l','e','`',0};
3252 static const WCHAR szWindowsFolder
[] =
3253 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3255 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3256 if (rc
!= ERROR_SUCCESS
)
3258 TRACE("no IniFile table\n");
3259 return ERROR_SUCCESS
;
3262 rc
= MSI_ViewExecute(view
, 0);
3263 if (rc
!= ERROR_SUCCESS
)
3265 MSI_ViewClose(view
);
3266 msiobj_release(&view
->hdr
);
3272 LPCWSTR component
,section
,key
,value
,identifier
,filename
,dirproperty
;
3273 LPWSTR deformated_section
, deformated_key
, deformated_value
;
3274 LPWSTR folder
, fullname
= NULL
;
3276 INT component_index
,action
;
3278 rc
= MSI_ViewFetch(view
,&row
);
3279 if (rc
!= ERROR_SUCCESS
)
3285 component
= MSI_RecordGetString(row
, 8);
3286 component_index
= get_loaded_component(package
,component
);
3288 if (!ACTION_VerifyComponentForAction(package
, component_index
,
3289 INSTALLSTATE_LOCAL
))
3291 TRACE("Skipping ini file due to disabled component %s\n",
3292 debugstr_w(component
));
3293 msiobj_release(&row
->hdr
);
3295 package
->components
[component_index
].Action
=
3296 package
->components
[component_index
].Installed
;
3301 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
3303 identifier
= MSI_RecordGetString(row
,1);
3304 filename
= MSI_RecordGetString(row
,2);
3305 dirproperty
= MSI_RecordGetString(row
,3);
3306 section
= MSI_RecordGetString(row
,4);
3307 key
= MSI_RecordGetString(row
,5);
3308 value
= MSI_RecordGetString(row
,6);
3309 action
= MSI_RecordGetInteger(row
,7);
3311 deformat_string(package
,section
,&deformated_section
);
3312 deformat_string(package
,key
,&deformated_key
);
3313 deformat_string(package
,value
,&deformated_value
);
3317 folder
= resolve_folder(package
, dirproperty
, FALSE
, FALSE
, NULL
);
3319 folder
= load_dynamic_property(package
,dirproperty
,NULL
);
3322 folder
= load_dynamic_property(package
, szWindowsFolder
, NULL
);
3326 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty
));
3330 fullname
= build_directory_name(3, folder
, filename
, NULL
);
3334 TRACE("Adding value %s to section %s in %s\n",
3335 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3336 debugstr_w(fullname
));
3337 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3338 deformated_value
, fullname
);
3340 else if (action
== 1)
3343 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
3344 returned
, 10, fullname
);
3345 if (returned
[0] == 0)
3347 TRACE("Adding value %s to section %s in %s\n",
3348 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3349 debugstr_w(fullname
));
3351 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3352 deformated_value
, fullname
);
3355 else if (action
== 3)
3357 FIXME("Append to existing section not yet implemented\n");
3360 uirow
= MSI_CreateRecord(4);
3361 MSI_RecordSetStringW(uirow
,1,identifier
);
3362 MSI_RecordSetStringW(uirow
,2,deformated_section
);
3363 MSI_RecordSetStringW(uirow
,3,deformated_key
);
3364 MSI_RecordSetStringW(uirow
,4,deformated_value
);
3365 ui_actiondata(package
,szWriteIniValues
,uirow
);
3366 msiobj_release( &uirow
->hdr
);
3368 HeapFree(GetProcessHeap(),0,fullname
);
3369 HeapFree(GetProcessHeap(),0,folder
);
3370 HeapFree(GetProcessHeap(),0,deformated_key
);
3371 HeapFree(GetProcessHeap(),0,deformated_value
);
3372 HeapFree(GetProcessHeap(),0,deformated_section
);
3373 msiobj_release(&row
->hdr
);
3375 MSI_ViewClose(view
);
3376 msiobj_release(&view
->hdr
);
3380 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
3384 MSIRECORD
* row
= 0;
3385 static const WCHAR ExecSeqQuery
[] =
3386 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3387 '`','S','e','l','f','R','e','g','`',0};
3389 static const WCHAR ExeStr
[] =
3390 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3391 static const WCHAR close
[] = {'\"',0};
3393 PROCESS_INFORMATION info
;
3396 memset(&si
,0,sizeof(STARTUPINFOW
));
3398 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3399 if (rc
!= ERROR_SUCCESS
)
3401 TRACE("no SelfReg table\n");
3402 return ERROR_SUCCESS
;
3405 rc
= MSI_ViewExecute(view
, 0);
3406 if (rc
!= ERROR_SUCCESS
)
3408 MSI_ViewClose(view
);
3409 msiobj_release(&view
->hdr
);
3420 rc
= MSI_ViewFetch(view
,&row
);
3421 if (rc
!= ERROR_SUCCESS
)
3427 filename
= MSI_RecordGetString(row
,1);
3428 index
= get_loaded_file(package
,filename
);
3432 ERR("Unable to find file id %s\n",debugstr_w(filename
));
3433 msiobj_release(&row
->hdr
);
3437 len
= strlenW(ExeStr
);
3438 len
+= strlenW(package
->files
[index
].TargetPath
);
3441 FullName
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
3442 strcpyW(FullName
,ExeStr
);
3443 strcatW(FullName
,package
->files
[index
].TargetPath
);
3444 strcatW(FullName
,close
);
3446 TRACE("Registering %s\n",debugstr_w(FullName
));
3447 brc
= CreateProcessW(NULL
, FullName
, NULL
, NULL
, FALSE
, 0, NULL
,
3448 c_colon
, &si
, &info
);
3451 msi_dialog_check_messages(info
.hProcess
);
3453 HeapFree(GetProcessHeap(),0,FullName
);
3454 msiobj_release(&row
->hdr
);
3456 MSI_ViewClose(view
);
3457 msiobj_release(&view
->hdr
);
3461 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
3470 return ERROR_INVALID_HANDLE
;
3472 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
3476 rc
= MSIREG_OpenFeaturesKey(productcode
,&hkey
,TRUE
);
3477 if (rc
!= ERROR_SUCCESS
)
3480 rc
= MSIREG_OpenUserFeaturesKey(productcode
,&hukey
,TRUE
);
3481 if (rc
!= ERROR_SUCCESS
)
3484 /* here the guids are base 85 encoded */
3485 for (i
= 0; i
< package
->loaded_features
; i
++)
3491 BOOL absent
= FALSE
;
3493 if (!ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_LOCAL
) &&
3494 !ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_SOURCE
) &&
3495 !ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_ADVERTISED
))
3498 size
= package
->features
[i
].ComponentCount
*21;
3500 if (package
->features
[i
].Feature_Parent
[0])
3501 size
+= strlenW(package
->features
[i
].Feature_Parent
)+2;
3503 data
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
3506 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
3509 memset(buf
,0,sizeof(buf
));
3510 if (package
->components
3511 [package
->features
[i
].Components
[j
]].ComponentId
[0]!=0)
3513 TRACE("From %s\n",debugstr_w(package
->components
3514 [package
->features
[i
].Components
[j
]].ComponentId
));
3515 CLSIDFromString(package
->components
3516 [package
->features
[i
].Components
[j
]].ComponentId
,
3518 encode_base85_guid(&clsid
,buf
);
3519 TRACE("to %s\n",debugstr_w(buf
));
3523 if (package
->features
[i
].Feature_Parent
[0])
3525 static const WCHAR sep
[] = {'\2',0};
3527 strcatW(data
,package
->features
[i
].Feature_Parent
);
3530 size
= (strlenW(data
)+1)*sizeof(WCHAR
);
3531 RegSetValueExW(hkey
,package
->features
[i
].Feature
,0,REG_SZ
,
3533 HeapFree(GetProcessHeap(),0,data
);
3537 size
= strlenW(package
->features
[i
].Feature_Parent
)*sizeof(WCHAR
);
3538 RegSetValueExW(hukey
,package
->features
[i
].Feature
,0,REG_SZ
,
3539 (LPSTR
)package
->features
[i
].Feature_Parent
,size
);
3543 size
= (strlenW(package
->features
[i
].Feature_Parent
)+2)*
3545 data
= HeapAlloc(GetProcessHeap(),0,size
);
3547 strcpyW(&data
[1],package
->features
[i
].Feature_Parent
);
3548 RegSetValueExW(hukey
,package
->features
[i
].Feature
,0,REG_SZ
,
3550 HeapFree(GetProcessHeap(),0,data
);
3557 HeapFree(GetProcessHeap(), 0, productcode
);
3561 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
3564 LPWSTR buffer
= NULL
;
3568 static WCHAR szNONE
[] = {0};
3569 static const WCHAR szWindowsInstaler
[] =
3570 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3571 static const WCHAR szPropKeys
[][80] =
3573 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3574 {'A','R','P','C','O','N','T','A','C','T',0},
3575 {'A','R','P','C','O','M','M','E','N','T','S',0},
3576 {'P','r','o','d','u','c','t','N','a','m','e',0},
3577 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3578 {'A','R','P','H','E','L','P','L','I','N','K',0},
3579 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3580 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3581 {'S','o','u','r','c','e','D','i','r',0},
3582 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3583 {'A','R','P','R','E','A','D','M','E',0},
3584 {'A','R','P','S','I','Z','E',0},
3585 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3586 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3590 static const WCHAR szRegKeys
[][80] =
3592 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3593 {'C','o','n','t','a','c','t',0},
3594 {'C','o','m','m','e','n','t','s',0},
3595 {'D','i','s','p','l','a','y','N','a','m','e',0},
3596 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3597 {'H','e','l','p','L','i','n','k',0},
3598 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3599 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3600 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3601 {'P','u','b','l','i','s','h','e','r',0},
3602 {'R','e','a','d','m','e',0},
3603 {'S','i','z','e',0},
3604 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3605 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3609 static const WCHAR installerPathFmt
[] = {
3611 'I','n','s','t','a','l','l','e','r','\\',0};
3612 static const WCHAR fmt
[] = {
3614 'I','n','s','t','a','l','l','e','r','\\',
3615 '%','x','.','m','s','i',0};
3616 static const WCHAR szLocalPackage
[]=
3617 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
3618 static const WCHAR szUpgradeCode
[] =
3619 {'U','p','g','r','a','d','e','C','o','d','e',0};
3620 static const WCHAR modpath_fmt
[] =
3621 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3622 static const WCHAR szModifyPath
[] =
3623 {'M','o','d','i','f','y','P','a','t','h',0};
3624 static const WCHAR szUninstallString
[] =
3625 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3626 static const WCHAR szEstimatedSize
[] =
3627 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3628 static const WCHAR szInstallDate
[] =
3629 {'I','n','s','t','a','l','l','D','a','t','e',0};
3630 static const WCHAR szLanguage
[] =
3631 {'L','a','n','g','u','a','g','e',0};
3632 static const WCHAR szProductLanguage
[] =
3633 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3634 static const WCHAR szProductVersion
[] =
3635 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3636 static const WCHAR szVersion
[] =
3637 {'V','e','r','s','i','o','n',0};
3638 static const WCHAR szVersionMajor
[] =
3639 {'V','e','r','s','i','o','n','M','a','j','o','r',0};
3640 static const WCHAR szVersionMinor
[] =
3641 {'V','e','r','s','i','o','n','M','i','n','o','r',0};
3644 static const WCHAR date_fmt
[] = {'%','i','%','i','%','i',0};
3645 LPWSTR upgrade_code
;
3646 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], packagefile
[MAX_PATH
];
3650 return ERROR_INVALID_HANDLE
;
3652 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
3656 rc
= MSIREG_OpenUninstallKey(productcode
,&hkey
,TRUE
);
3657 if (rc
!= ERROR_SUCCESS
)
3660 /* dump all the info i can grab */
3661 FIXME("Flesh out more information \n");
3664 while (szPropKeys
[i
][0]!=0)
3666 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
3667 if (rc
!= ERROR_SUCCESS
)
3669 size
= strlenW(buffer
)*sizeof(WCHAR
);
3670 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPSTR
)buffer
,size
);
3671 HeapFree(GetProcessHeap(),0,buffer
);
3677 RegSetValueExW(hkey
,szWindowsInstaler
,0,REG_DWORD
,(LPSTR
)&rc
,size
);
3679 /* copy the package locally */
3680 num
= GetTickCount() & 0xffff;
3684 GetWindowsDirectoryW(windir
, sizeof(windir
) / sizeof(windir
[0]));
3685 snprintfW(packagefile
,sizeof(packagefile
)/sizeof(packagefile
[0]),fmt
,
3689 HANDLE handle
= CreateFileW(packagefile
,GENERIC_WRITE
, 0, NULL
,
3690 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
3691 if (handle
!= INVALID_HANDLE_VALUE
)
3693 CloseHandle(handle
);
3696 if (GetLastError() != ERROR_FILE_EXISTS
&&
3697 GetLastError() != ERROR_SHARING_VIOLATION
)
3699 if (!(++num
& 0xffff)) num
= 1;
3700 sprintfW(packagefile
,fmt
,num
);
3701 } while (num
!= start
);
3703 snprintfW(path
,sizeof(path
)/sizeof(path
[0]),installerPathFmt
,windir
);
3704 create_full_pathW(path
);
3705 TRACE("Copying to local package %s\n",debugstr_w(packagefile
));
3706 if (!CopyFileW(package
->PackagePath
,packagefile
,FALSE
))
3707 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3708 debugstr_w(package
->PackagePath
), debugstr_w(packagefile
),
3710 size
= strlenW(packagefile
)*sizeof(WCHAR
);
3711 RegSetValueExW(hkey
,szLocalPackage
,0,REG_SZ
,(LPSTR
)packagefile
,size
);
3713 /* do ModifyPath and UninstallString */
3714 size
= deformat_string(package
,modpath_fmt
,&buffer
);
3715 RegSetValueExW(hkey
,szModifyPath
,0,REG_EXPAND_SZ
,(LPSTR
)buffer
,size
);
3716 RegSetValueExW(hkey
,szUninstallString
,0,REG_EXPAND_SZ
,(LPSTR
)buffer
,size
);
3717 HeapFree(GetProcessHeap(),0,buffer
);
3719 FIXME("Write real Estimated Size when we have it\n");
3721 RegSetValueExW(hkey
,szEstimatedSize
,0,REG_DWORD
,(LPSTR
)&size
,sizeof(DWORD
));
3723 GetLocalTime(&systime
);
3724 size
= 9*sizeof(WCHAR
);
3725 buffer
= HeapAlloc(GetProcessHeap(),0,size
);
3726 sprintfW(buffer
,date_fmt
,systime
.wYear
,systime
.wMonth
,systime
.wDay
);
3727 size
= strlenW(buffer
)*sizeof(WCHAR
);
3728 RegSetValueExW(hkey
,szInstallDate
,0,REG_SZ
,(LPSTR
)buffer
,size
);
3729 HeapFree(GetProcessHeap(),0,buffer
);
3731 buffer
= load_dynamic_property(package
,szProductLanguage
,NULL
);
3732 size
= atoiW(buffer
);
3733 RegSetValueExW(hkey
,szLanguage
,0,REG_DWORD
, (LPSTR
)&size
,sizeof(DWORD
));
3734 HeapFree(GetProcessHeap(),1,buffer
);
3736 buffer
= load_dynamic_property(package
,szProductVersion
,NULL
);
3739 DWORD verdword
= build_version_dword(buffer
);
3740 DWORD vermajor
= verdword
>>24;
3741 DWORD verminor
= (verdword
>>16)&0x00FF;
3742 size
= sizeof(DWORD
);
3743 RegSetValueExW(hkey
,szVersion
,0,REG_DWORD
,(LPSTR
)&verdword
,size
);
3744 RegSetValueExW(hkey
,szVersionMajor
,0,REG_DWORD
,(LPSTR
)&vermajor
,size
);
3745 RegSetValueExW(hkey
,szVersionMinor
,0,REG_DWORD
,(LPSTR
)&verminor
,size
);
3747 HeapFree(GetProcessHeap(),0,buffer
);
3749 /* Handle Upgrade Codes */
3750 upgrade_code
= load_dynamic_property(package
,szUpgradeCode
, NULL
);
3755 MSIREG_OpenUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3756 squash_guid(productcode
,squashed
);
3757 RegSetValueExW(hkey2
, squashed
, 0,REG_SZ
,NULL
,0);
3759 MSIREG_OpenUserUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3760 squash_guid(productcode
,squashed
);
3761 RegSetValueExW(hkey2
, squashed
, 0,REG_SZ
,NULL
,0);
3764 HeapFree(GetProcessHeap(),0,upgrade_code
);
3768 HeapFree(GetProcessHeap(),0,productcode
);
3771 return ERROR_SUCCESS
;
3774 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
3779 return ERROR_INVALID_HANDLE
;
3781 rc
= execute_script(package
,INSTALL_SCRIPT
);
3786 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
3791 return ERROR_INVALID_HANDLE
;
3793 /* turn off scheduleing */
3794 package
->script
->CurrentlyScripting
= FALSE
;
3796 /* first do the same as an InstallExecute */
3797 rc
= ACTION_InstallExecute(package
);
3798 if (rc
!= ERROR_SUCCESS
)
3801 /* then handle Commit Actions */
3802 rc
= execute_script(package
,COMMIT_SCRIPT
);
3807 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
3809 static const WCHAR RunOnce
[] = {
3810 'S','o','f','t','w','a','r','e','\\',
3811 'M','i','c','r','o','s','o','f','t','\\',
3812 'W','i','n','d','o','w','s','\\',
3813 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3814 'R','u','n','O','n','c','e',0};
3815 static const WCHAR InstallRunOnce
[] = {
3816 'S','o','f','t','w','a','r','e','\\',
3817 'M','i','c','r','o','s','o','f','t','\\',
3818 'W','i','n','d','o','w','s','\\',
3819 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3820 'I','n','s','t','a','l','l','e','r','\\',
3821 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3823 static const WCHAR msiexec_fmt
[] = {
3825 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3826 '\"','%','s','\"',0};
3827 static const WCHAR install_fmt
[] = {
3828 '/','I',' ','\"','%','s','\"',' ',
3829 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3830 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3831 WCHAR buffer
[256], sysdir
[MAX_PATH
];
3834 WCHAR squished_pc
[100];
3837 static const WCHAR szLUS
[] = {
3838 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
3839 static const WCHAR szSourceList
[] = {
3840 'S','o','u','r','c','e','L','i','s','t',0};
3841 static const WCHAR szPackageName
[] = {
3842 'P','a','c','k','a','g','e','N','a','m','e',0};
3845 return ERROR_INVALID_HANDLE
;
3847 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
3851 squash_guid(productcode
,squished_pc
);
3853 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
3854 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
3855 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
3858 size
= strlenW(buffer
)*sizeof(WCHAR
);
3859 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPSTR
)buffer
,size
);
3862 TRACE("Reboot command %s\n",debugstr_w(buffer
));
3864 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
3865 sprintfW(buffer
,install_fmt
,productcode
,squished_pc
);
3867 size
= strlenW(buffer
)*sizeof(WCHAR
);
3868 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPSTR
)buffer
,size
);
3871 rc
= MSIREG_OpenUserProductsKey(productcode
,&hukey
,TRUE
);
3872 if (rc
== ERROR_SUCCESS
)
3876 RegCreateKeyW(hukey
, szSourceList
, &hukey2
);
3877 buf
= load_dynamic_property(package
,cszSourceDir
,NULL
);
3878 size
= strlenW(buf
)*sizeof(WCHAR
);
3879 RegSetValueExW(hukey2
,szLUS
,0,REG_SZ
,(LPSTR
)buf
,size
);
3880 HeapFree(GetProcessHeap(),0,buf
);
3882 buf
= strrchrW(package
->PackagePath
,'\\');
3886 size
= strlenW(buf
)*sizeof(WCHAR
);
3887 RegSetValueExW(hukey2
,szPackageName
,0,REG_SZ
,(LPSTR
)buf
,size
);
3890 RegCloseKey(hukey2
);
3892 HeapFree(GetProcessHeap(),0,productcode
);
3894 return ERROR_INSTALL_SUSPEND
;
3897 UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
3900 * we are currently doing what should be done here in the top level Install
3901 * however for Adminastrative and uninstalls this step will be needed
3903 return ERROR_SUCCESS
;
3906 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
3908 static const WCHAR szProductID
[]=
3909 {'P','r','o','d','u','c','t','I','D',0};
3917 static const WCHAR szPropKeys
[][80] =
3919 {'P','r','o','d','u','c','t','I','D',0},
3920 {'U','S','E','R','N','A','M','E',0},
3921 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3925 static const WCHAR szRegKeys
[][80] =
3927 {'P','r','o','d','u','c','t','I','D',0},
3928 {'R','e','g','O','w','n','e','r',0},
3929 {'R','e','g','C','o','m','p','a','n','y',0},
3934 return ERROR_INVALID_HANDLE
;
3936 productid
= load_dynamic_property(package
,szProductID
,&rc
);
3938 return ERROR_SUCCESS
;
3940 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
3944 rc
= MSIREG_OpenUninstallKey(productcode
,&hkey
,TRUE
);
3945 if (rc
!= ERROR_SUCCESS
)
3949 while (szPropKeys
[i
][0]!=0)
3951 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
3952 if (rc
== ERROR_SUCCESS
)
3954 size
= strlenW(buffer
)*sizeof(WCHAR
);
3955 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPSTR
)buffer
,size
);
3958 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,NULL
,0);
3963 HeapFree(GetProcessHeap(),0,productcode
);
3964 HeapFree(GetProcessHeap(),0,productid
);
3967 return ERROR_SUCCESS
;
3971 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
3974 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
3980 * Code based off of code located here
3981 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3983 * Using string index 4 (full font name) instead of 1 (family name)
3985 static LPWSTR
load_ttfname_from(LPCWSTR filename
)
3991 typedef struct _tagTT_OFFSET_TABLE
{
3992 USHORT uMajorVersion
;
3993 USHORT uMinorVersion
;
3994 USHORT uNumOfTables
;
3995 USHORT uSearchRange
;
3996 USHORT uEntrySelector
;
4000 typedef struct _tagTT_TABLE_DIRECTORY
{
4001 char szTag
[4]; /* table name */
4002 ULONG uCheckSum
; /* Check sum */
4003 ULONG uOffset
; /* Offset from beginning of file */
4004 ULONG uLength
; /* length of the table in bytes */
4005 }TT_TABLE_DIRECTORY
;
4007 typedef struct _tagTT_NAME_TABLE_HEADER
{
4008 USHORT uFSelector
; /* format selector. Always 0 */
4009 USHORT uNRCount
; /* Name Records count */
4010 USHORT uStorageOffset
; /* Offset for strings storage,
4011 * from start of the table */
4012 }TT_NAME_TABLE_HEADER
;
4014 typedef struct _tagTT_NAME_RECORD
{
4019 USHORT uStringLength
;
4020 USHORT uStringOffset
; /* from start of storage area */
4023 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
4024 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
4026 handle
= CreateFileW(filename
,GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
4027 FILE_ATTRIBUTE_NORMAL
, 0 );
4028 if (handle
!= INVALID_HANDLE_VALUE
)
4030 TT_TABLE_DIRECTORY tblDir
;
4031 BOOL bFound
= FALSE
;
4032 TT_OFFSET_TABLE ttOffsetTable
;
4034 ReadFile(handle
,&ttOffsetTable
, sizeof(TT_OFFSET_TABLE
),NULL
,NULL
);
4035 ttOffsetTable
.uNumOfTables
= SWAPWORD(ttOffsetTable
.uNumOfTables
);
4036 ttOffsetTable
.uMajorVersion
= SWAPWORD(ttOffsetTable
.uMajorVersion
);
4037 ttOffsetTable
.uMinorVersion
= SWAPWORD(ttOffsetTable
.uMinorVersion
);
4039 if (ttOffsetTable
.uMajorVersion
!= 1 ||
4040 ttOffsetTable
.uMinorVersion
!= 0)
4043 for (i
=0; i
< ttOffsetTable
.uNumOfTables
; i
++)
4045 ReadFile(handle
,&tblDir
, sizeof(TT_TABLE_DIRECTORY
),NULL
,NULL
);
4046 if (strncmp(tblDir
.szTag
,"name",4)==0)
4049 tblDir
.uLength
= SWAPLONG(tblDir
.uLength
);
4050 tblDir
.uOffset
= SWAPLONG(tblDir
.uOffset
);
4057 TT_NAME_TABLE_HEADER ttNTHeader
;
4058 TT_NAME_RECORD ttRecord
;
4060 SetFilePointer(handle
, tblDir
.uOffset
, NULL
, FILE_BEGIN
);
4061 ReadFile(handle
,&ttNTHeader
, sizeof(TT_NAME_TABLE_HEADER
),
4064 ttNTHeader
.uNRCount
= SWAPWORD(ttNTHeader
.uNRCount
);
4065 ttNTHeader
.uStorageOffset
= SWAPWORD(ttNTHeader
.uStorageOffset
);
4067 for(i
=0; i
<ttNTHeader
.uNRCount
; i
++)
4069 ReadFile(handle
,&ttRecord
, sizeof(TT_NAME_RECORD
),NULL
,NULL
);
4070 ttRecord
.uNameID
= SWAPWORD(ttRecord
.uNameID
);
4071 /* 4 is the Full Font Name */
4072 if(ttRecord
.uNameID
== 4)
4076 static LPCSTR tt
= " (TrueType)";
4078 ttRecord
.uStringLength
= SWAPWORD(ttRecord
.uStringLength
);
4079 ttRecord
.uStringOffset
= SWAPWORD(ttRecord
.uStringOffset
);
4080 nPos
= SetFilePointer(handle
, 0, NULL
, FILE_CURRENT
);
4081 SetFilePointer(handle
, tblDir
.uOffset
+
4082 ttRecord
.uStringOffset
+
4083 ttNTHeader
.uStorageOffset
,
4085 buf
= HeapAlloc(GetProcessHeap(), 0,
4086 ttRecord
.uStringLength
+ 1 + strlen(tt
));
4087 memset(buf
, 0, ttRecord
.uStringLength
+ 1 + strlen(tt
));
4088 ReadFile(handle
, buf
, ttRecord
.uStringLength
, NULL
, NULL
);
4089 if (strlen(buf
) > 0)
4092 ret
= strdupAtoW(buf
);
4093 HeapFree(GetProcessHeap(),0,buf
);
4097 HeapFree(GetProcessHeap(),0,buf
);
4098 SetFilePointer(handle
,nPos
, NULL
, FILE_BEGIN
);
4102 CloseHandle(handle
);
4105 ERR("Unable to open font file %s\n", debugstr_w(filename
));
4107 TRACE("Returning fontname %s\n",debugstr_w(ret
));
4111 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
)
4115 MSIRECORD
* row
= 0;
4116 static const WCHAR ExecSeqQuery
[] =
4117 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4118 '`','F','o','n','t','`',0};
4119 static const WCHAR regfont1
[] =
4120 {'S','o','f','t','w','a','r','e','\\',
4121 'M','i','c','r','o','s','o','f','t','\\',
4122 'W','i','n','d','o','w','s',' ','N','T','\\',
4123 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4124 'F','o','n','t','s',0};
4125 static const WCHAR regfont2
[] =
4126 {'S','o','f','t','w','a','r','e','\\',
4127 'M','i','c','r','o','s','o','f','t','\\',
4128 'W','i','n','d','o','w','s','\\',
4129 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4130 'F','o','n','t','s',0};
4134 TRACE("%p\n", package
);
4136 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4137 if (rc
!= ERROR_SUCCESS
)
4139 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc
);
4140 return ERROR_SUCCESS
;
4143 rc
= MSI_ViewExecute(view
, 0);
4144 if (rc
!= ERROR_SUCCESS
)
4146 MSI_ViewClose(view
);
4147 msiobj_release(&view
->hdr
);
4148 TRACE("MSI_ViewExecute returned %d\n", rc
);
4149 return ERROR_SUCCESS
;
4152 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont1
,&hkey1
);
4153 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont2
,&hkey2
);
4162 rc
= MSI_ViewFetch(view
,&row
);
4163 if (rc
!= ERROR_SUCCESS
)
4169 file
= MSI_RecordGetString(row
,1);
4170 index
= get_loaded_file(package
,file
);
4173 ERR("Unable to load file\n");
4177 /* check to make sure that component is installed */
4178 if (!ACTION_VerifyComponentForAction(package
,
4179 package
->files
[index
].ComponentIndex
, INSTALLSTATE_LOCAL
))
4181 TRACE("Skipping: Component not scheduled for install\n");
4183 msiobj_release(&row
->hdr
);
4188 if (MSI_RecordIsNull(row
,2))
4189 name
= load_ttfname_from(package
->files
[index
].TargetPath
);
4191 name
= load_dynamic_stringW(row
,2);
4195 size
= strlenW(package
->files
[index
].FileName
) * sizeof(WCHAR
);
4196 RegSetValueExW(hkey1
,name
,0,REG_SZ
,
4197 (LPBYTE
)package
->files
[index
].FileName
,size
);
4198 RegSetValueExW(hkey2
,name
,0,REG_SZ
,
4199 (LPBYTE
)package
->files
[index
].FileName
,size
);
4202 HeapFree(GetProcessHeap(),0,name
);
4203 msiobj_release(&row
->hdr
);
4205 MSI_ViewClose(view
);
4206 msiobj_release(&view
->hdr
);
4211 TRACE("returning %d\n", rc
);
4215 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
4217 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
4218 LPCWSTR compgroupid
=NULL
;
4219 LPCWSTR feature
=NULL
;
4220 LPCWSTR text
= NULL
;
4221 LPCWSTR qualifier
= NULL
;
4222 LPCWSTR component
= NULL
;
4223 LPWSTR advertise
= NULL
;
4224 LPWSTR output
= NULL
;
4226 UINT rc
= ERROR_SUCCESS
;
4230 component
= MSI_RecordGetString(rec
,3);
4231 index
= get_loaded_component(package
,component
);
4233 if (!ACTION_VerifyComponentForAction(package
, index
,
4234 INSTALLSTATE_LOCAL
) &&
4235 !ACTION_VerifyComponentForAction(package
, index
,
4236 INSTALLSTATE_SOURCE
) &&
4237 !ACTION_VerifyComponentForAction(package
, index
,
4238 INSTALLSTATE_ADVERTISED
))
4240 TRACE("Skipping: Component %s not scheduled for install\n",
4241 debugstr_w(component
));
4243 return ERROR_SUCCESS
;
4246 compgroupid
= MSI_RecordGetString(rec
,1);
4248 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
4249 if (rc
!= ERROR_SUCCESS
)
4252 text
= MSI_RecordGetString(rec
,4);
4253 qualifier
= MSI_RecordGetString(rec
,2);
4254 feature
= MSI_RecordGetString(rec
,5);
4256 advertise
= create_component_advertise_string(package
,
4257 &package
->components
[index
], feature
);
4259 sz
= strlenW(advertise
);
4262 sz
+= lstrlenW(text
);
4265 sz
*= sizeof(WCHAR
);
4267 output
= HeapAlloc(GetProcessHeap(),0,sz
);
4268 memset(output
,0,sz
);
4269 strcpyW(output
,advertise
);
4272 strcatW(output
,text
);
4274 sz
= (lstrlenW(output
)+2) * sizeof(WCHAR
);
4275 RegSetValueExW(hkey
, qualifier
,0,REG_MULTI_SZ
, (LPBYTE
)output
, sz
);
4279 HeapFree(GetProcessHeap(),0,output
);
4285 * At present I am ignorning the advertised components part of this and only
4286 * focusing on the qualified component sets
4288 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
4292 static const WCHAR ExecSeqQuery
[] =
4293 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4294 '`','P','u','b','l','i','s','h',
4295 'C','o','m','p','o','n','e','n','t','`',0};
4297 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4298 if (rc
!= ERROR_SUCCESS
)
4299 return ERROR_SUCCESS
;
4301 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
4302 msiobj_release(&view
->hdr
);