2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004,2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
37 #include "wine/debug.h"
42 #include "wine/unicode.h"
46 #define REG_PROGRESS_VALUE 13200
47 #define COMPONENT_PROGRESS_VALUE 24000
49 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
54 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
);
55 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
);
56 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
);
61 typedef UINT (*STANDARDACTIONHANDLER
)(MSIPACKAGE
*);
63 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
);
64 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
);
65 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
);
66 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
);
67 static UINT
ACTION_FileCost(MSIPACKAGE
*package
);
68 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
);
69 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
);
70 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
);
71 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
);
72 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
);
73 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
);
74 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
);
75 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
);
76 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
);
77 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
);
78 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
);
79 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
);
80 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
);
81 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
);
82 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
);
83 static UINT
ACTION_ResolveSource(MSIPACKAGE
*package
);
84 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
);
85 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
);
86 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
);
89 * consts and values used
91 static const WCHAR c_colon
[] = {'C',':','\\',0};
93 const static WCHAR szCreateFolders
[] =
94 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
95 const static WCHAR szCostFinalize
[] =
96 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
97 const WCHAR szInstallFiles
[] =
98 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
99 const WCHAR szDuplicateFiles
[] =
100 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
101 const static WCHAR szWriteRegistryValues
[] =
102 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
103 'V','a','l','u','e','s',0};
104 const static WCHAR szCostInitialize
[] =
105 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
106 const static WCHAR szFileCost
[] =
107 {'F','i','l','e','C','o','s','t',0};
108 const static WCHAR szInstallInitialize
[] =
109 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
110 const static WCHAR szInstallValidate
[] =
111 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
112 const static WCHAR szLaunchConditions
[] =
113 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
114 const static WCHAR szProcessComponents
[] =
115 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
116 const static WCHAR szRegisterTypeLibraries
[] =
117 {'R','e','g','i','s','t','e','r','T','y','p','e',
118 'L','i','b','r','a','r','i','e','s',0};
119 const WCHAR szRegisterClassInfo
[] =
120 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
121 const WCHAR szRegisterProgIdInfo
[] =
122 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
123 const static WCHAR szCreateShortcuts
[] =
124 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
125 const static WCHAR szPublishProduct
[] =
126 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
127 const static WCHAR szWriteIniValues
[] =
128 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
129 const static WCHAR szSelfRegModules
[] =
130 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
131 const static WCHAR szPublishFeatures
[] =
132 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
133 const static WCHAR szRegisterProduct
[] =
134 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
135 const static WCHAR szInstallExecute
[] =
136 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
137 const static WCHAR szInstallExecuteAgain
[] =
138 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
139 'A','g','a','i','n',0};
140 const static WCHAR szInstallFinalize
[] =
141 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
142 const static WCHAR szForceReboot
[] =
143 {'F','o','r','c','e','R','e','b','o','o','t',0};
144 const static WCHAR szResolveSource
[] =
145 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
146 const WCHAR szAppSearch
[] =
147 {'A','p','p','S','e','a','r','c','h',0};
148 const static WCHAR szAllocateRegistrySpace
[] =
149 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
150 'S','p','a','c','e',0};
151 const static WCHAR szBindImage
[] =
152 {'B','i','n','d','I','m','a','g','e',0};
153 const static WCHAR szCCPSearch
[] =
154 {'C','C','P','S','e','a','r','c','h',0};
155 const static WCHAR szDeleteServices
[] =
156 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
157 const static WCHAR szDisableRollback
[] =
158 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
159 const static WCHAR szExecuteAction
[] =
160 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
161 const WCHAR szFindRelatedProducts
[] =
162 {'F','i','n','d','R','e','l','a','t','e','d',
163 'P','r','o','d','u','c','t','s',0};
164 const static WCHAR szInstallAdminPackage
[] =
165 {'I','n','s','t','a','l','l','A','d','m','i','n',
166 'P','a','c','k','a','g','e',0};
167 const static WCHAR szInstallSFPCatalogFile
[] =
168 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
170 const static WCHAR szIsolateComponents
[] =
171 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
172 const WCHAR szMigrateFeatureStates
[] =
173 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
174 'S','t','a','t','e','s',0};
175 const WCHAR szMoveFiles
[] =
176 {'M','o','v','e','F','i','l','e','s',0};
177 const static WCHAR szMsiPublishAssemblies
[] =
178 {'M','s','i','P','u','b','l','i','s','h',
179 'A','s','s','e','m','b','l','i','e','s',0};
180 const static WCHAR szMsiUnpublishAssemblies
[] =
181 {'M','s','i','U','n','p','u','b','l','i','s','h',
182 'A','s','s','e','m','b','l','i','e','s',0};
183 const static WCHAR szInstallODBC
[] =
184 {'I','n','s','t','a','l','l','O','D','B','C',0};
185 const static WCHAR szInstallServices
[] =
186 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
187 const WCHAR szPatchFiles
[] =
188 {'P','a','t','c','h','F','i','l','e','s',0};
189 const static WCHAR szPublishComponents
[] =
190 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
191 const static WCHAR szRegisterComPlus
[] =
192 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
193 const WCHAR szRegisterExtensionInfo
[] =
194 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
196 const static WCHAR szRegisterFonts
[] =
197 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
198 const WCHAR szRegisterMIMEInfo
[] =
199 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
200 const static WCHAR szRegisterUser
[] =
201 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
202 const WCHAR szRemoveDuplicateFiles
[] =
203 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
204 'F','i','l','e','s',0};
205 const static WCHAR szRemoveEnvironmentStrings
[] =
206 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
207 'S','t','r','i','n','g','s',0};
208 const WCHAR szRemoveExistingProducts
[] =
209 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
210 'P','r','o','d','u','c','t','s',0};
211 const WCHAR szRemoveFiles
[] =
212 {'R','e','m','o','v','e','F','i','l','e','s',0};
213 const static WCHAR szRemoveFolders
[] =
214 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
215 const static WCHAR szRemoveIniValues
[] =
216 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
217 const static WCHAR szRemoveODBC
[] =
218 {'R','e','m','o','v','e','O','D','B','C',0};
219 const static WCHAR szRemoveRegistryValues
[] =
220 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
221 'V','a','l','u','e','s',0};
222 const static WCHAR szRemoveShortcuts
[] =
223 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
224 const static WCHAR szRMCCPSearch
[] =
225 {'R','M','C','C','P','S','e','a','r','c','h',0};
226 const static WCHAR szScheduleReboot
[] =
227 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
228 const static WCHAR szSelfUnregModules
[] =
229 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
230 const static WCHAR szSetODBCFolders
[] =
231 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
232 const static WCHAR szStartServices
[] =
233 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
234 const static WCHAR szStopServices
[] =
235 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
236 const static WCHAR szUnpublishComponents
[] =
237 {'U','n','p','u','b','l','i','s','h',
238 'C','o','m','p','o','n','e','n','t','s',0};
239 const static WCHAR szUnpublishFeatures
[] =
240 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
241 const WCHAR szUnregisterClassInfo
[] =
242 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
244 const static WCHAR szUnregisterComPlus
[] =
245 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
246 const WCHAR szUnregisterExtensionInfo
[] =
247 {'U','n','r','e','g','i','s','t','e','r',
248 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
249 const static WCHAR szUnregisterFonts
[] =
250 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
251 const WCHAR szUnregisterMIMEInfo
[] =
252 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
253 const WCHAR szUnregisterProgIdInfo
[] =
254 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
256 const static WCHAR szUnregisterTypeLibraries
[] =
257 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
258 'L','i','b','r','a','r','i','e','s',0};
259 const static WCHAR szValidateProductID
[] =
260 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
261 const static WCHAR szWriteEnvironmentStrings
[] =
262 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
263 'S','t','r','i','n','g','s',0};
267 STANDARDACTIONHANDLER handler
;
270 static struct _actions StandardActions
[] = {
271 { szAllocateRegistrySpace
, NULL
},
272 { szAppSearch
, ACTION_AppSearch
},
273 { szBindImage
, NULL
},
274 { szCCPSearch
, NULL
},
275 { szCostFinalize
, ACTION_CostFinalize
},
276 { szCostInitialize
, ACTION_CostInitialize
},
277 { szCreateFolders
, ACTION_CreateFolders
},
278 { szCreateShortcuts
, ACTION_CreateShortcuts
},
279 { szDeleteServices
, NULL
},
280 { szDisableRollback
, NULL
},
281 { szDuplicateFiles
, ACTION_DuplicateFiles
},
282 { szExecuteAction
, ACTION_ExecuteAction
},
283 { szFileCost
, ACTION_FileCost
},
284 { szFindRelatedProducts
, ACTION_FindRelatedProducts
},
285 { szForceReboot
, ACTION_ForceReboot
},
286 { szInstallAdminPackage
, NULL
},
287 { szInstallExecute
, ACTION_InstallExecute
},
288 { szInstallExecuteAgain
, ACTION_InstallExecute
},
289 { szInstallFiles
, ACTION_InstallFiles
},
290 { szInstallFinalize
, ACTION_InstallFinalize
},
291 { szInstallInitialize
, ACTION_InstallInitialize
},
292 { szInstallSFPCatalogFile
, NULL
},
293 { szInstallValidate
, ACTION_InstallValidate
},
294 { szIsolateComponents
, NULL
},
295 { szLaunchConditions
, ACTION_LaunchConditions
},
296 { szMigrateFeatureStates
, NULL
},
297 { szMoveFiles
, NULL
},
298 { szMsiPublishAssemblies
, NULL
},
299 { szMsiUnpublishAssemblies
, NULL
},
300 { szInstallODBC
, NULL
},
301 { szInstallServices
, NULL
},
302 { szPatchFiles
, NULL
},
303 { szProcessComponents
, ACTION_ProcessComponents
},
304 { szPublishComponents
, ACTION_PublishComponents
},
305 { szPublishFeatures
, ACTION_PublishFeatures
},
306 { szPublishProduct
, ACTION_PublishProduct
},
307 { szRegisterClassInfo
, ACTION_RegisterClassInfo
},
308 { szRegisterComPlus
, NULL
},
309 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
},
310 { szRegisterFonts
, ACTION_RegisterFonts
},
311 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
},
312 { szRegisterProduct
, ACTION_RegisterProduct
},
313 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
},
314 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
},
315 { szRegisterUser
, ACTION_RegisterUser
},
316 { szRemoveDuplicateFiles
, NULL
},
317 { szRemoveEnvironmentStrings
, NULL
},
318 { szRemoveExistingProducts
, NULL
},
319 { szRemoveFiles
, NULL
},
320 { szRemoveFolders
, NULL
},
321 { szRemoveIniValues
, NULL
},
322 { szRemoveODBC
, NULL
},
323 { szRemoveRegistryValues
, NULL
},
324 { szRemoveShortcuts
, NULL
},
325 { szResolveSource
, ACTION_ResolveSource
},
326 { szRMCCPSearch
, NULL
},
327 { szScheduleReboot
, NULL
},
328 { szSelfRegModules
, ACTION_SelfRegModules
},
329 { szSelfUnregModules
, NULL
},
330 { szSetODBCFolders
, NULL
},
331 { szStartServices
, NULL
},
332 { szStopServices
, NULL
},
333 { szUnpublishComponents
, NULL
},
334 { szUnpublishFeatures
, NULL
},
335 { szUnregisterClassInfo
, NULL
},
336 { szUnregisterComPlus
, NULL
},
337 { szUnregisterExtensionInfo
, NULL
},
338 { szUnregisterFonts
, NULL
},
339 { szUnregisterMIMEInfo
, NULL
},
340 { szUnregisterProgIdInfo
, NULL
},
341 { szUnregisterTypeLibraries
, NULL
},
342 { szValidateProductID
, NULL
},
343 { szWriteEnvironmentStrings
, NULL
},
344 { szWriteIniValues
, ACTION_WriteIniValues
},
345 { szWriteRegistryValues
, ACTION_WriteRegistryValues
},
350 /********************************************************
352 ********************************************************/
354 static void ce_actiontext(MSIPACKAGE
* package
, LPCWSTR action
)
356 static const WCHAR szActionText
[] =
357 {'A','c','t','i','o','n','T','e','x','t',0};
360 row
= MSI_CreateRecord(1);
361 MSI_RecordSetStringW(row
,1,action
);
362 ControlEvent_FireSubscribedEvent(package
,szActionText
, row
);
363 msiobj_release(&row
->hdr
);
366 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
368 static const WCHAR template_s
[]=
369 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
371 static const WCHAR format
[] =
372 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
373 static const WCHAR Query_t
[] =
374 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
375 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
376 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
377 ' ','\'','%','s','\'',0};
384 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
386 row
= MSI_QueryGetRecord( package
->db
, Query_t
, action
);
390 ActionText
= MSI_RecordGetString(row
,2);
391 deformat_string(package
, ActionText
, &deformated
);
393 sprintfW(message
,template_s
,timet
,action
,deformated
);
394 ce_actiontext(package
, deformated
);
395 msiobj_release(&row
->hdr
);
397 row
= MSI_CreateRecord(1);
398 MSI_RecordSetStringW(row
,1,message
);
400 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
401 msiobj_release(&row
->hdr
);
402 msi_free(deformated
);
405 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
409 static const WCHAR template_s
[]=
410 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
412 static const WCHAR template_e
[]=
413 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
414 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
416 static const WCHAR format
[] =
417 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
421 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
423 sprintfW(message
,template_s
,timet
,action
);
425 sprintfW(message
,template_e
,timet
,action
,rc
);
427 row
= MSI_CreateRecord(1);
428 MSI_RecordSetStringW(row
,1,message
);
430 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
431 msiobj_release(&row
->hdr
);
434 /****************************************************
435 * TOP level entry points
436 *****************************************************/
438 UINT
ACTION_DoTopLevelINSTALL(MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
439 LPCWSTR szCommandLine
, LPCWSTR msiFilePath
)
445 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
446 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
447 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
449 MSI_SetPropertyW(package
, szAction
, szInstall
);
451 package
->script
= msi_alloc(sizeof(MSISCRIPT
));
452 memset(package
->script
,0,sizeof(MSISCRIPT
));
454 package
->script
->InWhatSequence
= SEQUENCE_INSTALL
;
456 package
->msiFilePath
= strdupW(msiFilePath
);
460 LPWSTR p
, check
, path
;
462 package
->PackagePath
= strdupW(szPackagePath
);
463 path
= strdupW(szPackagePath
);
464 p
= strrchrW(path
,'\\');
473 path
= msi_alloc(MAX_PATH
*sizeof(WCHAR
));
474 GetCurrentDirectoryW(MAX_PATH
,path
);
478 check
= msi_dup_property( package
, cszSourceDir
);
480 MSI_SetPropertyW(package
, cszSourceDir
, path
);
488 ptr
= (LPWSTR
)szCommandLine
;
495 TRACE("Looking at %s\n",debugstr_w(ptr
));
497 ptr2
= strchrW(ptr
,'=');
503 while (*ptr
== ' ') ptr
++;
505 prop
= msi_alloc((len
+1)*sizeof(WCHAR
));
506 memcpy(prop
,ptr
,len
*sizeof(WCHAR
));
512 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
525 val
= msi_alloc((len
+1)*sizeof(WCHAR
));
526 memcpy(val
,ptr2
,len
*sizeof(WCHAR
));
529 if (strlenW(prop
) > 0)
531 TRACE("Found commandline property (%s) = (%s)\n",
532 debugstr_w(prop
), debugstr_w(val
));
533 MSI_SetPropertyW(package
,prop
,val
);
543 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
545 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
547 package
->script
->InWhatSequence
|= SEQUENCE_UI
;
548 rc
= ACTION_ProcessUISequence(package
);
550 if (rc
== ERROR_SUCCESS
)
552 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
553 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
557 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
560 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
564 /* install was halted but should be considered a success */
568 package
->script
->CurrentlyScripting
= FALSE
;
570 /* process the ending type action */
571 if (rc
== ERROR_SUCCESS
)
572 ACTION_PerformActionSequence(package
,-1,ui
);
573 else if (rc
== ERROR_INSTALL_USEREXIT
)
574 ACTION_PerformActionSequence(package
,-2,ui
);
575 else if (rc
== ERROR_INSTALL_SUSPEND
)
576 ACTION_PerformActionSequence(package
,-4,ui
);
578 ACTION_PerformActionSequence(package
,-3,ui
);
580 /* finish up running custom actions */
581 ACTION_FinishCustomActions(package
);
586 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
)
588 UINT rc
= ERROR_SUCCESS
;
590 static const WCHAR ExecSeqQuery
[] =
591 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
592 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
593 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
594 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
596 static const WCHAR UISeqQuery
[] =
597 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
598 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
599 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
600 ' ', '=',' ','%','i',0};
603 row
= MSI_QueryGetRecord(package
->db
, UISeqQuery
, seq
);
605 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, seq
);
609 LPCWSTR action
, cond
;
611 TRACE("Running the actions\n");
613 /* check conditions */
614 cond
= MSI_RecordGetString(row
,2);
617 /* this is a hack to skip errors in the condition code */
618 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
622 action
= MSI_RecordGetString(row
,1);
625 ERR("failed to fetch action\n");
626 rc
= ERROR_FUNCTION_FAILED
;
631 rc
= ACTION_PerformUIAction(package
,action
);
633 rc
= ACTION_PerformAction(package
,action
,FALSE
);
635 msiobj_release(&row
->hdr
);
646 } iterate_action_param
;
648 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
650 iterate_action_param
*iap
= (iterate_action_param
*)param
;
652 LPCWSTR cond
, action
;
654 action
= MSI_RecordGetString(row
,1);
657 ERR("Error is retrieving action name\n");
658 return ERROR_FUNCTION_FAILED
;
661 /* check conditions */
662 cond
= MSI_RecordGetString(row
,2);
665 /* this is a hack to skip errors in the condition code */
666 if (MSI_EvaluateConditionW(iap
->package
, cond
) == MSICONDITION_FALSE
)
668 TRACE("Skipping action: %s (condition is false)\n",
670 return ERROR_SUCCESS
;
675 rc
= ACTION_PerformUIAction(iap
->package
,action
);
677 rc
= ACTION_PerformAction(iap
->package
,action
,FALSE
);
679 msi_dialog_check_messages( NULL
);
681 if (iap
->package
->CurrentInstallState
!= ERROR_SUCCESS
)
682 rc
= iap
->package
->CurrentInstallState
;
684 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
687 if (rc
!= ERROR_SUCCESS
)
688 ERR("Execution halted due to error (%i)\n",rc
);
693 UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR szTable
, INT iSequenceMode
)
697 static const WCHAR query
[] =
698 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
700 ' ','W','H','E','R','E',' ',
701 '`','S','e','q','u','e','n','c','e','`',' ',
702 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
703 '`','S','e','q','u','e','n','c','e','`',0};
704 iterate_action_param iap
;
707 * FIXME: probably should be checking UILevel in the
708 * ACTION_PerformUIAction/ACTION_PerformAction
709 * rather than saving the UI level here. Those
710 * two functions can be merged too.
712 iap
.package
= package
;
715 TRACE("%p %s %i\n", package
, debugstr_w(szTable
), iSequenceMode
);
717 r
= MSI_OpenQuery( package
->db
, &view
, query
, szTable
);
718 if (r
== ERROR_SUCCESS
)
720 r
= MSI_IterateRecords( view
, NULL
, ITERATE_Actions
, &iap
);
721 msiobj_release(&view
->hdr
);
727 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
731 static const WCHAR ExecSeqQuery
[] =
732 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
733 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
734 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
735 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
736 'O','R','D','E','R',' ', 'B','Y',' ',
737 '`','S','e','q','u','e','n','c','e','`',0 };
739 static const WCHAR IVQuery
[] =
740 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
741 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
742 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
743 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
744 ' ','\'', 'I','n','s','t','a','l','l',
745 'V','a','l','i','d','a','t','e','\'', 0};
747 iterate_action_param iap
;
749 iap
.package
= package
;
752 if (package
->script
->ExecuteSequenceRun
)
754 TRACE("Execute Sequence already Run\n");
755 return ERROR_SUCCESS
;
758 package
->script
->ExecuteSequenceRun
= TRUE
;
760 /* get the sequence number */
763 row
= MSI_QueryGetRecord(package
->db
, IVQuery
);
765 return ERROR_FUNCTION_FAILED
;
766 seq
= MSI_RecordGetInteger(row
,1);
767 msiobj_release(&row
->hdr
);
770 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
771 if (rc
== ERROR_SUCCESS
)
773 TRACE("Running the actions\n");
775 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
776 msiobj_release(&view
->hdr
);
782 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
786 static const WCHAR ExecSeqQuery
[] =
787 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
788 '`','I','n','s','t','a','l','l',
789 'U','I','S','e','q','u','e','n','c','e','`',
790 ' ','W','H','E','R','E',' ',
791 '`','S','e','q','u','e','n','c','e','`',' ',
792 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
793 '`','S','e','q','u','e','n','c','e','`',0};
794 iterate_action_param iap
;
796 iap
.package
= package
;
799 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
801 if (rc
== ERROR_SUCCESS
)
803 TRACE("Running the actions \n");
805 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, &iap
);
806 msiobj_release(&view
->hdr
);
812 /********************************************************
813 * ACTION helper functions and functions that perform the actions
814 *******************************************************/
815 static BOOL
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
,
816 UINT
* rc
, BOOL force
)
822 if (!run
&& !package
->script
->CurrentlyScripting
)
827 if (strcmpW(action
,szInstallFinalize
) == 0 ||
828 strcmpW(action
,szInstallExecute
) == 0 ||
829 strcmpW(action
,szInstallExecuteAgain
) == 0)
834 while (StandardActions
[i
].action
!= NULL
)
836 if (strcmpW(StandardActions
[i
].action
, action
)==0)
840 ui_actioninfo(package
, action
, TRUE
, 0);
841 *rc
= schedule_action(package
,INSTALL_SCRIPT
,action
);
842 ui_actioninfo(package
, action
, FALSE
, *rc
);
846 ui_actionstart(package
, action
);
847 if (StandardActions
[i
].handler
)
849 *rc
= StandardActions
[i
].handler(package
);
853 FIXME("unhandled standard action %s\n",debugstr_w(action
));
865 static BOOL
ACTION_HandleCustomAction( MSIPACKAGE
* package
, LPCWSTR action
,
866 UINT
* rc
, BOOL force
)
871 arc
= ACTION_CustomAction(package
,action
, force
);
873 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
882 * A lot of actions are really important even if they don't do anything
883 * explicit... Lots of properties are set at the beginning of the installation
884 * CostFinalize does a bunch of work to translate the directories and such
886 * But until I get write access to the database that is hard, so I am going to
887 * hack it to see if I can get something to run.
889 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, BOOL force
)
891 UINT rc
= ERROR_SUCCESS
;
894 TRACE("Performing action (%s)\n",debugstr_w(action
));
896 handled
= ACTION_HandleStandardAction(package
, action
, &rc
, force
);
899 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, force
);
903 FIXME("unhandled msi action %s\n",debugstr_w(action
));
904 rc
= ERROR_FUNCTION_NOT_CALLED
;
910 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
)
912 UINT rc
= ERROR_SUCCESS
;
913 BOOL handled
= FALSE
;
915 TRACE("Performing action (%s)\n",debugstr_w(action
));
917 handled
= ACTION_HandleStandardAction(package
, action
, &rc
,TRUE
);
920 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, FALSE
);
922 if( !handled
&& ACTION_DialogBox(package
,action
) == ERROR_SUCCESS
)
927 FIXME("unhandled msi action %s\n",debugstr_w(action
));
928 rc
= ERROR_FUNCTION_NOT_CALLED
;
936 * Actual Action Handlers
939 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
941 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
947 dir
= MSI_RecordGetString(row
,1);
950 ERR("Unable to get folder id \n");
951 return ERROR_SUCCESS
;
954 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,&folder
);
957 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
958 return ERROR_SUCCESS
;
961 TRACE("Folder is %s\n",debugstr_w(full_path
));
964 uirow
= MSI_CreateRecord(1);
965 MSI_RecordSetStringW(uirow
,1,full_path
);
966 ui_actiondata(package
,szCreateFolders
,uirow
);
967 msiobj_release( &uirow
->hdr
);
969 if (folder
->State
== 0)
970 create_full_pathW(full_path
);
975 return ERROR_SUCCESS
;
980 * Also we cannot enable/disable components either, so for now I am just going
981 * to do all the directories for all the components.
983 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
985 static const WCHAR ExecSeqQuery
[] =
986 {'S','E','L','E','C','T',' ',
987 '`','D','i','r','e','c','t','o','r','y','_','`',
988 ' ','F','R','O','M',' ',
989 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
993 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
994 if (rc
!= ERROR_SUCCESS
)
995 return ERROR_SUCCESS
;
997 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
998 msiobj_release(&view
->hdr
);
1003 static MSICOMPONENT
* load_component( MSIRECORD
* row
)
1007 comp
= msi_alloc_zero( sizeof(MSICOMPONENT
) );
1011 /* fill in the data */
1012 comp
->Component
= load_dynamic_stringW( row
, 1 );
1014 TRACE("Loading Component %s\n", debugstr_w(comp
->Component
));
1016 comp
->ComponentId
= load_dynamic_stringW( row
, 2 );
1017 comp
->Directory
= load_dynamic_stringW( row
, 3 );
1018 comp
->Attributes
= MSI_RecordGetInteger(row
,4);
1019 comp
->Condition
= load_dynamic_stringW( row
, 5 );
1020 comp
->KeyPath
= load_dynamic_stringW( row
, 6 );
1022 comp
->Installed
= INSTALLSTATE_ABSENT
;
1023 comp
->Action
= INSTALLSTATE_UNKNOWN
;
1024 comp
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1026 comp
->Enabled
= TRUE
;
1032 MSIPACKAGE
*package
;
1033 MSIFEATURE
*feature
;
1036 static UINT
add_feature_component( MSIFEATURE
*feature
, MSICOMPONENT
*comp
)
1040 cl
= msi_alloc( sizeof (*cl
) );
1042 return ERROR_NOT_ENOUGH_MEMORY
;
1043 cl
->component
= comp
;
1044 list_add_tail( &feature
->Components
, &cl
->entry
);
1046 return ERROR_SUCCESS
;
1049 static UINT
iterate_component_check( MSIRECORD
*row
, LPVOID param
)
1051 _ilfs
* ilfs
= (_ilfs
*)param
;
1052 MSIPACKAGE
*package
= ilfs
->package
;
1053 MSIFEATURE
*feature
= ilfs
->feature
;
1056 comp
= load_component( row
);
1058 return ERROR_FUNCTION_FAILED
;
1060 list_add_tail( &package
->components
, &comp
->entry
);
1061 add_feature_component( feature
, comp
);
1063 TRACE("Loaded new component %p\n", comp
);
1065 return ERROR_SUCCESS
;
1068 static UINT
iterate_load_featurecomponents(MSIRECORD
*row
, LPVOID param
)
1070 _ilfs
* ilfs
= (_ilfs
*)param
;
1075 static const WCHAR Query
[] =
1076 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1077 '`','C','o','m','p','o','n','e','n','t','`',' ',
1078 'W','H','E','R','E',' ',
1079 '`','C','o','m','p','o','n','e','n','t','`',' ',
1080 '=','\'','%','s','\'',0};
1082 component
= MSI_RecordGetString(row
,1);
1084 /* check to see if the component is already loaded */
1085 comp
= get_loaded_component( ilfs
->package
, component
);
1088 TRACE("Component %s already loaded\n", debugstr_w(component
) );
1089 add_feature_component( ilfs
->feature
, comp
);
1090 return ERROR_SUCCESS
;
1093 rc
= MSI_OpenQuery(ilfs
->package
->db
, &view
, Query
, component
);
1094 if (rc
!= ERROR_SUCCESS
)
1095 return ERROR_SUCCESS
;
1097 rc
= MSI_IterateRecords(view
, NULL
, iterate_component_check
, ilfs
);
1098 msiobj_release( &view
->hdr
);
1100 return ERROR_SUCCESS
;
1103 static UINT
load_feature(MSIRECORD
* row
, LPVOID param
)
1105 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
1106 MSIFEATURE
* feature
;
1107 static const WCHAR Query1
[] =
1108 {'S','E','L','E','C','T',' ',
1109 '`','C','o','m','p','o','n','e','n','t','_','`',
1110 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1111 'C','o','m','p','o','n','e','n','t','s','`',' ',
1112 'W','H','E','R','E',' ',
1113 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1118 /* fill in the data */
1120 feature
= msi_alloc_zero( sizeof (MSIFEATURE
) );
1122 return ERROR_NOT_ENOUGH_MEMORY
;
1124 list_init( &feature
->Components
);
1126 feature
->Feature
= load_dynamic_stringW( row
, 1 );
1128 TRACE("Loading feature %s\n",debugstr_w(feature
->Feature
));
1130 feature
->Feature_Parent
= load_dynamic_stringW( row
, 2 );
1131 feature
->Title
= load_dynamic_stringW( row
, 3 );
1132 feature
->Description
= load_dynamic_stringW( row
, 4 );
1134 if (!MSI_RecordIsNull(row
,5))
1135 feature
->Display
= MSI_RecordGetInteger(row
,5);
1137 feature
->Level
= MSI_RecordGetInteger(row
,6);
1138 feature
->Directory
= load_dynamic_stringW( row
, 7 );
1139 feature
->Attributes
= MSI_RecordGetInteger(row
,8);
1141 feature
->Installed
= INSTALLSTATE_ABSENT
;
1142 feature
->Action
= INSTALLSTATE_UNKNOWN
;
1143 feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1145 list_add_tail( &package
->features
, &feature
->entry
);
1147 /* load feature components */
1149 rc
= MSI_OpenQuery( package
->db
, &view
, Query1
, feature
->Feature
);
1150 if (rc
!= ERROR_SUCCESS
)
1151 return ERROR_SUCCESS
;
1153 ilfs
.package
= package
;
1154 ilfs
.feature
= feature
;
1156 MSI_IterateRecords(view
, NULL
, iterate_load_featurecomponents
, &ilfs
);
1157 msiobj_release(&view
->hdr
);
1159 return ERROR_SUCCESS
;
1162 static UINT
load_file(MSIRECORD
*row
, LPVOID param
)
1164 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
1168 /* fill in the data */
1170 file
= msi_alloc_zero( sizeof (MSIFILE
) );
1172 return ERROR_NOT_ENOUGH_MEMORY
;
1174 file
->File
= load_dynamic_stringW( row
, 1 );
1176 component
= MSI_RecordGetString( row
, 2 );
1177 file
->Component
= get_loaded_component( package
, component
);
1179 if (!file
->Component
)
1180 ERR("Unfound Component %s\n",debugstr_w(component
));
1182 file
->FileName
= load_dynamic_stringW( row
, 3 );
1183 reduce_to_longfilename( file
->FileName
);
1185 file
->ShortName
= load_dynamic_stringW( row
, 3 );
1186 reduce_to_shortfilename( file
->ShortName
);
1188 file
->FileSize
= MSI_RecordGetInteger( row
, 4 );
1189 file
->Version
= load_dynamic_stringW( row
, 5 );
1190 file
->Language
= load_dynamic_stringW( row
, 6 );
1191 file
->Attributes
= MSI_RecordGetInteger( row
, 7 );
1192 file
->Sequence
= MSI_RecordGetInteger( row
, 8 );
1196 TRACE("File Loaded (%s)\n",debugstr_w(file
->File
));
1198 list_add_tail( &package
->files
, &file
->entry
);
1200 return ERROR_SUCCESS
;
1203 static UINT
load_all_files(MSIPACKAGE
*package
)
1207 static const WCHAR Query
[] =
1208 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1209 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1210 '`','S','e','q','u','e','n','c','e','`', 0};
1213 return ERROR_INVALID_HANDLE
;
1215 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1216 if (rc
!= ERROR_SUCCESS
)
1217 return ERROR_SUCCESS
;
1219 rc
= MSI_IterateRecords(view
, NULL
, load_file
, package
);
1220 msiobj_release(&view
->hdr
);
1222 return ERROR_SUCCESS
;
1227 * I am not doing any of the costing functionality yet.
1228 * Mostly looking at doing the Component and Feature loading
1230 * The native MSI does A LOT of modification to tables here. Mostly adding
1231 * a lot of temporary columns to the Feature and Component tables.
1233 * note: Native msi also tracks the short filename. But I am only going to
1234 * track the long ones. Also looking at this directory table
1235 * it appears that the directory table does not get the parents
1236 * resolved base on property only based on their entries in the
1239 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1243 static const WCHAR Query_all
[] =
1244 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1245 '`','F','e','a','t','u','r','e','`',0};
1246 static const WCHAR szCosting
[] =
1247 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1248 static const WCHAR szZero
[] = { '0', 0 };
1252 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1254 return ERROR_SUCCESS
;
1256 MSI_SetPropertyW(package
, szCosting
, szZero
);
1257 MSI_SetPropertyW(package
, cszRootDrive
, c_colon
);
1259 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1260 if (rc
!= ERROR_SUCCESS
)
1263 rc
= MSI_IterateRecords(view
, NULL
, load_feature
, package
);
1264 msiobj_release(&view
->hdr
);
1266 load_all_files(package
);
1268 return ERROR_SUCCESS
;
1271 static UINT
execute_script(MSIPACKAGE
*package
, UINT script
)
1274 UINT rc
= ERROR_SUCCESS
;
1276 TRACE("Executing Script %i\n",script
);
1278 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
1281 action
= package
->script
->Actions
[script
][i
];
1282 ui_actionstart(package
, action
);
1283 TRACE("Executing Action (%s)\n",debugstr_w(action
));
1284 rc
= ACTION_PerformAction(package
, action
, TRUE
);
1285 msi_free(package
->script
->Actions
[script
][i
]);
1286 if (rc
!= ERROR_SUCCESS
)
1289 msi_free(package
->script
->Actions
[script
]);
1291 package
->script
->ActionCount
[script
] = 0;
1292 package
->script
->Actions
[script
] = NULL
;
1296 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1298 return ERROR_SUCCESS
;
1302 static MSIFOLDER
*load_folder( MSIPACKAGE
*package
, LPCWSTR dir
)
1304 static const WCHAR Query
[] =
1305 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1306 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1307 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1308 ' ','=',' ','\'','%','s','\'',
1310 LPWSTR ptargetdir
, targetdir
, srcdir
;
1312 LPWSTR shortname
= NULL
;
1313 MSIRECORD
* row
= 0;
1316 TRACE("Looking for dir %s\n",debugstr_w(dir
));
1318 folder
= get_loaded_folder( package
, dir
);
1322 TRACE("Working to load %s\n",debugstr_w(dir
));
1324 folder
= msi_alloc_zero( sizeof (MSIFOLDER
) );
1328 folder
->Directory
= strdupW(dir
);
1330 row
= MSI_QueryGetRecord(package
->db
, Query
, dir
);
1334 ptargetdir
= targetdir
= load_dynamic_stringW(row
,3);
1336 /* split src and target dir */
1337 if (strchrW(targetdir
,':'))
1339 srcdir
=strchrW(targetdir
,':');
1346 /* for now only pick long filename versions */
1347 if (strchrW(targetdir
,'|'))
1349 shortname
= targetdir
;
1350 targetdir
= strchrW(targetdir
,'|');
1354 /* for the sourcedir pick the short filename */
1355 if (srcdir
&& strchrW(srcdir
,'|'))
1357 LPWSTR p
= strchrW(srcdir
,'|');
1361 /* now check for root dirs */
1362 if (targetdir
[0] == '.' && targetdir
[1] == 0)
1367 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir
));
1368 msi_free( folder
->TargetDefault
);
1369 folder
->TargetDefault
= strdupW(targetdir
);
1373 folder
->SourceDefault
= strdupW(srcdir
);
1375 folder
->SourceDefault
= strdupW(shortname
);
1377 folder
->SourceDefault
= strdupW(targetdir
);
1378 msi_free(ptargetdir
);
1379 TRACE(" SourceDefault = %s\n", debugstr_w( folder
->SourceDefault
));
1381 parent
= MSI_RecordGetString(row
,2);
1384 folder
->Parent
= load_folder( package
, parent
);
1385 if ( folder
->Parent
)
1386 TRACE("loaded parent %p %s\n", folder
->Parent
,
1387 debugstr_w(folder
->Parent
->Directory
));
1389 ERR("failed to load parent folder %s\n", debugstr_w(parent
));
1392 folder
->Property
= msi_dup_property( package
, dir
);
1394 msiobj_release(&row
->hdr
);
1396 list_add_tail( &package
->folders
, &folder
->entry
);
1398 TRACE("%s returning %p\n",debugstr_w(dir
),folder
);
1403 /* scan for and update current install states */
1404 static void ACTION_UpdateInstallStates(MSIPACKAGE
*package
)
1407 MSIFEATURE
*feature
;
1409 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1412 res
= MsiGetComponentPathW( package
->ProductCode
,
1413 comp
->ComponentId
, NULL
, NULL
);
1415 res
= INSTALLSTATE_ABSENT
;
1416 comp
->Installed
= res
;
1419 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1422 INSTALLSTATE res
= -10;
1424 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1426 comp
= cl
->component
;
1429 res
= comp
->Installed
;
1432 if (res
== comp
->Installed
)
1435 if (res
!= comp
->Installed
)
1436 res
= INSTALLSTATE_INCOMPLETE
;
1439 feature
->Installed
= res
;
1443 static BOOL
process_state_property (MSIPACKAGE
* package
, LPCWSTR property
,
1446 static const WCHAR all
[]={'A','L','L',0};
1448 MSIFEATURE
*feature
;
1450 override
= msi_dup_property( package
, property
);
1454 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1456 if (strcmpiW(override
,all
)==0)
1458 feature
->ActionRequest
= state
;
1459 feature
->Action
= state
;
1463 LPWSTR ptr
= override
;
1464 LPWSTR ptr2
= strchrW(override
,',');
1468 if ((ptr2
&& strncmpW(ptr
,feature
->Feature
, ptr2
-ptr
)==0)
1469 || (!ptr2
&& strcmpW(ptr
,feature
->Feature
)==0))
1471 feature
->ActionRequest
= state
;
1472 feature
->Action
= state
;
1478 ptr2
= strchrW(ptr
,',');
1490 static UINT
SetFeatureStates(MSIPACKAGE
*package
)
1494 static const WCHAR szlevel
[] =
1495 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1496 static const WCHAR szAddLocal
[] =
1497 {'A','D','D','L','O','C','A','L',0};
1498 static const WCHAR szRemove
[] =
1499 {'R','E','M','O','V','E',0};
1500 BOOL override
= FALSE
;
1501 MSICOMPONENT
* component
;
1502 MSIFEATURE
*feature
;
1505 /* I do not know if this is where it should happen.. but */
1507 TRACE("Checking Install Level\n");
1509 level
= msi_dup_property( package
, szlevel
);
1512 install_level
= atoiW(level
);
1518 /* ok hereis the _real_ rub
1519 * all these activation/deactivation things happen in order and things
1520 * later on the list override things earlier on the list.
1521 * 1) INSTALLLEVEL processing
1531 * 11) FILEADDDEFAULT
1532 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
1533 * ignored for all the features. seems strange, especially since it is not
1534 * documented anywhere, but it is how it works.
1536 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1537 * REMOVE are the big ones, since we don't handle administrative installs
1540 override
|= process_state_property(package
,szAddLocal
,INSTALLSTATE_LOCAL
);
1541 override
|= process_state_property(package
,szRemove
,INSTALLSTATE_ABSENT
);
1545 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1547 BOOL feature_state
= ((feature
->Level
> 0) &&
1548 (feature
->Level
<= install_level
));
1550 if ((feature_state
) && (feature
->Action
== INSTALLSTATE_UNKNOWN
))
1552 if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1554 feature
->ActionRequest
= INSTALLSTATE_SOURCE
;
1555 feature
->Action
= INSTALLSTATE_SOURCE
;
1557 else if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1559 feature
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1560 feature
->Action
= INSTALLSTATE_ADVERTISED
;
1564 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1565 feature
->Action
= INSTALLSTATE_LOCAL
;
1572 /* set the Preselected Property */
1573 static const WCHAR szPreselected
[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1574 static const WCHAR szOne
[] = { '1', 0 };
1576 MSI_SetPropertyW(package
,szPreselected
,szOne
);
1580 * now we want to enable or disable components base on feature
1583 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1587 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
1588 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
1589 feature
->ActionRequest
);
1591 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1593 component
= cl
->component
;
1595 if (!component
->Enabled
)
1597 component
->Action
= INSTALLSTATE_UNKNOWN
;
1598 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1602 if (feature
->Action
== INSTALLSTATE_LOCAL
)
1604 component
->Action
= INSTALLSTATE_LOCAL
;
1605 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1607 else if (feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1609 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1610 (component
->Action
== INSTALLSTATE_ABSENT
) ||
1611 (component
->Action
== INSTALLSTATE_ADVERTISED
))
1614 component
->Action
= INSTALLSTATE_SOURCE
;
1615 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1618 else if (feature
->ActionRequest
== INSTALLSTATE_ADVERTISED
)
1620 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
1621 (component
->Action
== INSTALLSTATE_ABSENT
))
1624 component
->Action
= INSTALLSTATE_ADVERTISED
;
1625 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1628 else if (feature
->ActionRequest
== INSTALLSTATE_ABSENT
)
1630 if (component
->Action
== INSTALLSTATE_UNKNOWN
)
1632 component
->Action
= INSTALLSTATE_ABSENT
;
1633 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
1640 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1642 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
1643 debugstr_w(component
->Component
), component
->Installed
,
1644 component
->Action
, component
->ActionRequest
);
1648 return ERROR_SUCCESS
;
1651 static UINT
ITERATE_CostFinalizeDirectories(MSIRECORD
*row
, LPVOID param
)
1653 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1657 name
= MSI_RecordGetString(row
,1);
1659 /* This helper function now does ALL the work */
1660 TRACE("Dir %s ...\n",debugstr_w(name
));
1661 load_folder(package
,name
);
1662 path
= resolve_folder(package
,name
,FALSE
,TRUE
,NULL
);
1663 TRACE("resolves to %s\n",debugstr_w(path
));
1666 return ERROR_SUCCESS
;
1669 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1671 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1673 MSIFEATURE
*feature
;
1675 name
= MSI_RecordGetString( row
, 1 );
1677 feature
= get_loaded_feature( package
, name
);
1679 ERR("FAILED to find loaded feature %s\n",debugstr_w(name
));
1683 Condition
= MSI_RecordGetString(row
,3);
1685 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
1687 int level
= MSI_RecordGetInteger(row
,2);
1688 TRACE("Reseting feature %s to level %i\n", debugstr_w(name
), level
);
1689 feature
->Level
= level
;
1692 return ERROR_SUCCESS
;
1697 * A lot is done in this function aside from just the costing.
1698 * The costing needs to be implemented at some point but for now I am going
1699 * to focus on the directory building
1702 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
1704 static const WCHAR ExecSeqQuery
[] =
1705 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1706 '`','D','i','r','e','c','t','o','r','y','`',0};
1707 static const WCHAR ConditionQuery
[] =
1708 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1709 '`','C','o','n','d','i','t','i','o','n','`',0};
1710 static const WCHAR szCosting
[] =
1711 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1712 static const WCHAR szlevel
[] =
1713 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1714 static const WCHAR szOne
[] = { '1', 0 };
1723 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1725 return ERROR_SUCCESS
;
1727 TRACE("Building Directory properties\n");
1729 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1730 if (rc
== ERROR_SUCCESS
)
1732 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeDirectories
,
1734 msiobj_release(&view
->hdr
);
1737 TRACE("File calculations\n");
1739 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
1741 MSICOMPONENT
* comp
= file
->Component
;
1747 /* calculate target */
1748 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
1750 msi_free(file
->TargetPath
);
1752 TRACE("file %s is named %s\n",
1753 debugstr_w(file
->File
),debugstr_w(file
->FileName
));
1755 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
1759 TRACE("file %s resolves to %s\n",
1760 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
1762 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
1765 comp
->Cost
+= file
->FileSize
;
1775 static const WCHAR name
[] =
1777 static const WCHAR name_fmt
[] =
1778 {'%','u','.','%','u','.','%','u','.','%','u',0};
1779 WCHAR filever
[0x100];
1780 VS_FIXEDFILEINFO
*lpVer
;
1782 TRACE("Version comparison.. \n");
1783 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
1784 version
= msi_alloc(versize
);
1785 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
1787 VerQueryValueW(version
, name
, (LPVOID
*)&lpVer
, &sz
);
1789 sprintfW(filever
,name_fmt
,
1790 HIWORD(lpVer
->dwFileVersionMS
),
1791 LOWORD(lpVer
->dwFileVersionMS
),
1792 HIWORD(lpVer
->dwFileVersionLS
),
1793 LOWORD(lpVer
->dwFileVersionLS
));
1795 TRACE("new %s old %s\n", debugstr_w(file
->Version
),
1796 debugstr_w(filever
));
1797 if (strcmpiW(filever
,file
->Version
)<0)
1800 FIXME("cost should be diff in size\n");
1801 comp
->Cost
+= file
->FileSize
;
1811 TRACE("Evaluating Condition Table\n");
1813 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
1814 if (rc
== ERROR_SUCCESS
)
1816 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeConditions
,
1818 msiobj_release(&view
->hdr
);
1821 TRACE("Enabling or Disabling Components\n");
1822 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1824 if (comp
->Condition
)
1826 if (MSI_EvaluateConditionW(package
,
1827 comp
->Condition
) == MSICONDITION_FALSE
)
1829 TRACE("Disabling component %s\n", debugstr_w(comp
->Component
));
1830 comp
->Enabled
= FALSE
;
1835 MSI_SetPropertyW(package
,szCosting
,szOne
);
1836 /* set default run level if not set */
1837 level
= msi_dup_property( package
, szlevel
);
1839 MSI_SetPropertyW(package
,szlevel
, szOne
);
1842 ACTION_UpdateInstallStates(package
);
1844 return SetFeatureStates(package
);
1847 /* OK this value is "interpreted" and then formatted based on the
1848 first few characters */
1849 static LPSTR
parse_value(MSIPACKAGE
*package
, LPCWSTR value
, DWORD
*type
,
1853 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
1859 LPWSTR deformated
= NULL
;
1862 deformat_string(package
, &value
[2], &deformated
);
1864 /* binary value type */
1868 *size
= (strlenW(ptr
)/2)+1;
1870 *size
= strlenW(ptr
)/2;
1872 data
= msi_alloc(*size
);
1878 /* if uneven pad with a zero in front */
1884 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1886 TRACE("Uneven byte count\n");
1894 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
1897 msi_free(deformated
);
1899 TRACE("Data %li bytes(%i)\n",*size
,count
);
1906 deformat_string(package
, &value
[1], &deformated
);
1909 *size
= sizeof(DWORD
);
1910 data
= msi_alloc(*size
);
1916 if ( (*p
< '0') || (*p
> '9') )
1922 if (deformated
[0] == '-')
1925 TRACE("DWORD %li\n",*(LPDWORD
)data
);
1927 msi_free(deformated
);
1932 static const WCHAR szMulti
[] = {'[','~',']',0};
1941 *type
=REG_EXPAND_SZ
;
1949 if (strstrW(value
,szMulti
))
1950 *type
= REG_MULTI_SZ
;
1952 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
1957 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
1959 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
1960 static const WCHAR szHCR
[] =
1961 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
1962 'R','O','O','T','\\',0};
1963 static const WCHAR szHCU
[] =
1964 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
1965 'U','S','E','R','\\',0};
1966 static const WCHAR szHLM
[] =
1967 {'H','K','E','Y','_','L','O','C','A','L','_',
1968 'M','A','C','H','I','N','E','\\',0};
1969 static const WCHAR szHU
[] =
1970 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
1972 LPSTR value_data
= NULL
;
1973 HKEY root_key
, hkey
;
1976 LPCWSTR szRoot
, component
, name
, key
, value
;
1981 BOOL check_first
= FALSE
;
1984 ui_progress(package
,2,0,0,0);
1991 component
= MSI_RecordGetString(row
, 6);
1992 comp
= get_loaded_component(package
,component
);
1994 return ERROR_SUCCESS
;
1996 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
1998 TRACE("Skipping write due to disabled component %s\n",
1999 debugstr_w(component
));
2001 comp
->Action
= comp
->Installed
;
2003 return ERROR_SUCCESS
;
2006 comp
->Action
= INSTALLSTATE_LOCAL
;
2008 name
= MSI_RecordGetString(row
, 4);
2009 if( MSI_RecordIsNull(row
,5) && name
)
2011 /* null values can have special meanings */
2012 if (name
[0]=='-' && name
[1] == 0)
2013 return ERROR_SUCCESS
;
2014 else if ((name
[0]=='+' && name
[1] == 0) ||
2015 (name
[0] == '*' && name
[1] == 0))
2020 root
= MSI_RecordGetInteger(row
,2);
2021 key
= MSI_RecordGetString(row
, 3);
2023 /* get the root key */
2028 static const WCHAR szALLUSER
[] = {'A','L','L','U','S','E','R','S',0};
2029 LPWSTR all_users
= msi_dup_property( package
, szALLUSER
);
2030 if (all_users
&& all_users
[0] == '1')
2032 root_key
= HKEY_LOCAL_MACHINE
;
2037 root_key
= HKEY_CURRENT_USER
;
2040 msi_free(all_users
);
2043 case 0: root_key
= HKEY_CLASSES_ROOT
;
2046 case 1: root_key
= HKEY_CURRENT_USER
;
2049 case 2: root_key
= HKEY_LOCAL_MACHINE
;
2052 case 3: root_key
= HKEY_USERS
;
2056 ERR("Unknown root %i\n",root
);
2062 return ERROR_SUCCESS
;
2064 deformat_string(package
, key
, &deformated
);
2065 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
2066 uikey
= msi_alloc(size
*sizeof(WCHAR
));
2067 strcpyW(uikey
,szRoot
);
2068 strcatW(uikey
,deformated
);
2070 if (RegCreateKeyW( root_key
, deformated
, &hkey
))
2072 ERR("Could not create key %s\n",debugstr_w(deformated
));
2073 msi_free(deformated
);
2075 return ERROR_SUCCESS
;
2077 msi_free(deformated
);
2079 value
= MSI_RecordGetString(row
,5);
2081 value_data
= parse_value(package
, value
, &type
, &size
);
2084 static const WCHAR szEmpty
[] = {0};
2085 value_data
= (LPSTR
)strdupW(szEmpty
);
2090 deformat_string(package
, name
, &deformated
);
2092 /* get the double nulls to terminate SZ_MULTI */
2093 if (type
== REG_MULTI_SZ
)
2094 size
+=sizeof(WCHAR
);
2098 TRACE("Setting value %s of %s\n",debugstr_w(deformated
),
2100 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
)value_data
, size
);
2105 rc
= RegQueryValueExW(hkey
, deformated
, NULL
, NULL
, NULL
, &sz
);
2106 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
2108 TRACE("value %s of %s checked already exists\n",
2109 debugstr_w(deformated
), debugstr_w(uikey
));
2113 TRACE("Checked and setting value %s of %s\n",
2114 debugstr_w(deformated
), debugstr_w(uikey
));
2115 if (deformated
|| size
)
2116 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
) value_data
, size
);
2121 uirow
= MSI_CreateRecord(3);
2122 MSI_RecordSetStringW(uirow
,2,deformated
);
2123 MSI_RecordSetStringW(uirow
,1,uikey
);
2126 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2128 MSI_RecordSetStringW(uirow
,3,value
);
2130 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2131 msiobj_release( &uirow
->hdr
);
2133 msi_free(value_data
);
2134 msi_free(deformated
);
2137 return ERROR_SUCCESS
;
2140 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2144 static const WCHAR ExecSeqQuery
[] =
2145 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2146 '`','R','e','g','i','s','t','r','y','`',0 };
2149 return ERROR_INVALID_HANDLE
;
2151 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2152 if (rc
!= ERROR_SUCCESS
)
2153 return ERROR_SUCCESS
;
2155 /* increment progress bar each time action data is sent */
2156 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
2158 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2160 msiobj_release(&view
->hdr
);
2164 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
2166 package
->script
->CurrentlyScripting
= TRUE
;
2168 return ERROR_SUCCESS
;
2172 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
2177 static const WCHAR q1
[]=
2178 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2179 '`','R','e','g','i','s','t','r','y','`',0};
2182 MSIFEATURE
*feature
;
2185 TRACE("InstallValidate\n");
2187 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
2188 if (rc
== ERROR_SUCCESS
)
2190 MSI_IterateRecords( view
, &progress
, NULL
, package
);
2191 msiobj_release( &view
->hdr
);
2192 total
+= progress
* REG_PROGRESS_VALUE
;
2195 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2196 total
+= COMPONENT_PROGRESS_VALUE
;
2198 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2199 total
+= file
->FileSize
;
2201 ui_progress(package
,0,total
,0,0);
2203 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2205 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2206 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
2207 feature
->ActionRequest
);
2210 return ERROR_SUCCESS
;
2213 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
2215 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2216 LPCWSTR cond
= NULL
;
2217 LPCWSTR message
= NULL
;
2218 static const WCHAR title
[]=
2219 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2221 cond
= MSI_RecordGetString(row
,1);
2223 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
2226 message
= MSI_RecordGetString(row
,2);
2227 deformat_string(package
,message
,&deformated
);
2228 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
2229 msi_free(deformated
);
2230 return ERROR_FUNCTION_FAILED
;
2233 return ERROR_SUCCESS
;
2236 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
2239 MSIQUERY
* view
= NULL
;
2240 static const WCHAR ExecSeqQuery
[] =
2241 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2242 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2244 TRACE("Checking launch conditions\n");
2246 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2247 if (rc
!= ERROR_SUCCESS
)
2248 return ERROR_SUCCESS
;
2250 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
2251 msiobj_release(&view
->hdr
);
2256 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, MSICOMPONENT
*cmp
)
2260 return resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,NULL
);
2262 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
2264 MSIRECORD
* row
= 0;
2266 LPWSTR deformated
,buffer
,deformated_name
;
2268 static const WCHAR ExecSeqQuery
[] =
2269 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2270 '`','R','e','g','i','s','t','r','y','`',' ',
2271 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2272 ' ','=',' ' ,'\'','%','s','\'',0 };
2273 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
2274 static const WCHAR fmt2
[]=
2275 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2277 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
,cmp
->KeyPath
);
2281 root
= MSI_RecordGetInteger(row
,2);
2282 key
= MSI_RecordGetString(row
, 3);
2283 name
= MSI_RecordGetString(row
, 4);
2284 deformat_string(package
, key
, &deformated
);
2285 deformat_string(package
, name
, &deformated_name
);
2287 len
= strlenW(deformated
) + 6;
2288 if (deformated_name
)
2289 len
+=strlenW(deformated_name
);
2291 buffer
= msi_alloc( len
*sizeof(WCHAR
));
2293 if (deformated_name
)
2294 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
2296 sprintfW(buffer
,fmt
,root
,deformated
);
2298 msi_free(deformated
);
2299 msi_free(deformated_name
);
2300 msiobj_release(&row
->hdr
);
2304 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2306 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2311 MSIFILE
*file
= get_loaded_file( package
, cmp
->KeyPath
);
2314 return strdupW( file
->TargetPath
);
2319 static HKEY
openSharedDLLsKey(void)
2322 static const WCHAR path
[] =
2323 {'S','o','f','t','w','a','r','e','\\',
2324 'M','i','c','r','o','s','o','f','t','\\',
2325 'W','i','n','d','o','w','s','\\',
2326 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2327 'S','h','a','r','e','d','D','L','L','s',0};
2329 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
2333 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
2338 DWORD sz
= sizeof(count
);
2341 hkey
= openSharedDLLsKey();
2342 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
2343 if (rc
!= ERROR_SUCCESS
)
2349 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
2353 hkey
= openSharedDLLsKey();
2355 msi_reg_set_val_dword( hkey
, path
, count
);
2357 RegDeleteValueW(hkey
,path
);
2363 * Return TRUE if the count should be written out and FALSE if not
2365 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, MSICOMPONENT
*comp
)
2367 MSIFEATURE
*feature
;
2371 /* only refcount DLLs */
2372 if (comp
->KeyPath
== NULL
||
2373 comp
->Attributes
& msidbComponentAttributesRegistryKeyPath
||
2374 comp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2378 count
= ACTION_GetSharedDLLsCount( comp
->FullKeypath
);
2379 write
= (count
> 0);
2381 if (comp
->Attributes
& msidbComponentAttributesSharedDllRefCount
)
2385 /* increment counts */
2386 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2390 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_LOCAL
))
2393 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
2395 if ( cl
->component
== comp
)
2400 /* decrement counts */
2401 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2405 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_ABSENT
))
2408 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
2410 if ( cl
->component
== comp
)
2415 /* ref count all the files in the component */
2420 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2422 if (file
->Component
== comp
)
2423 ACTION_WriteSharedDLLsCount( file
->TargetPath
, count
);
2427 /* add a count for permenent */
2428 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
2431 comp
->RefCount
= count
;
2434 ACTION_WriteSharedDLLsCount( comp
->FullKeypath
, comp
->RefCount
);
2438 * Ok further analysis makes me think that this work is
2439 * actually done in the PublishComponents and PublishFeatures
2440 * step, and not here. It appears like the keypath and all that is
2441 * resolved in this step, however actually written in the Publish steps.
2442 * But we will leave it here for now because it is unclear
2444 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
2446 WCHAR squished_pc
[GUID_SIZE
];
2447 WCHAR squished_cc
[GUID_SIZE
];
2450 HKEY hkey
=0,hkey2
=0;
2453 return ERROR_INVALID_HANDLE
;
2455 /* writes the Component and Features values to the registry */
2457 rc
= MSIREG_OpenComponents(&hkey
);
2458 if (rc
!= ERROR_SUCCESS
)
2461 squash_guid(package
->ProductCode
,squished_pc
);
2462 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
2464 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2466 ui_progress(package
,2,0,0,0);
2467 if (comp
->ComponentId
)
2471 squash_guid(comp
->ComponentId
,squished_cc
);
2473 msi_free(comp
->FullKeypath
);
2474 comp
->FullKeypath
= resolve_keypath( package
, comp
);
2476 /* do the refcounting */
2477 ACTION_RefCountComponent( package
, comp
);
2479 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2480 debugstr_w(comp
->Component
),
2481 debugstr_w(squished_cc
),
2482 debugstr_w(comp
->FullKeypath
),
2485 * Write the keypath out if the component is to be registered
2486 * and delete the key if the component is to be deregistered
2488 if (ACTION_VerifyComponentForAction(package
, comp
,
2489 INSTALLSTATE_LOCAL
))
2491 rc
= RegCreateKeyW(hkey
,squished_cc
,&hkey2
);
2492 if (rc
!= ERROR_SUCCESS
)
2495 if (comp
->FullKeypath
)
2497 msi_reg_set_val_str( hkey2
, squished_pc
, comp
->FullKeypath
);
2499 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
2501 static const WCHAR szPermKey
[] =
2502 { '0','0','0','0','0','0','0','0','0','0','0','0',
2503 '0','0','0','0','0','0','0','0','0','0','0','0',
2504 '0','0','0','0','0','0','0','0',0};
2506 msi_reg_set_val_str( hkey2
, szPermKey
, comp
->FullKeypath
);
2512 uirow
= MSI_CreateRecord(3);
2513 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
2514 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
2515 MSI_RecordSetStringW(uirow
,3,comp
->FullKeypath
);
2516 ui_actiondata(package
,szProcessComponents
,uirow
);
2517 msiobj_release( &uirow
->hdr
);
2520 else if (ACTION_VerifyComponentForAction(package
, comp
,
2521 INSTALLSTATE_ABSENT
))
2525 rc
= RegOpenKeyW(hkey
,squished_cc
,&hkey2
);
2526 if (rc
!= ERROR_SUCCESS
)
2529 RegDeleteValueW(hkey2
,squished_pc
);
2531 /* if the key is empty delete it */
2532 res
= RegEnumKeyExW(hkey2
,0,NULL
,0,0,NULL
,0,NULL
);
2534 if (res
== ERROR_NO_MORE_ITEMS
)
2535 RegDeleteKeyW(hkey
,squished_cc
);
2538 uirow
= MSI_CreateRecord(2);
2539 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
2540 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
2541 ui_actiondata(package
,szProcessComponents
,uirow
);
2542 msiobj_release( &uirow
->hdr
);
2559 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
2560 LPWSTR lpszName
, LONG_PTR lParam
)
2563 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
2564 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
2568 if (!IS_INTRESOURCE(lpszName
))
2570 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
2574 sz
= strlenW(tl_struct
->source
)+4;
2575 sz
*= sizeof(WCHAR
);
2577 if ((INT
)lpszName
== 1)
2578 tl_struct
->path
= strdupW(tl_struct
->source
);
2581 tl_struct
->path
= msi_alloc(sz
);
2582 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
2585 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
2586 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
2587 if (!SUCCEEDED(res
))
2589 msi_free(tl_struct
->path
);
2590 tl_struct
->path
= NULL
;
2595 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
2596 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
2598 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2602 msi_free(tl_struct
->path
);
2603 tl_struct
->path
= NULL
;
2605 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
2606 ITypeLib_Release(tl_struct
->ptLib
);
2611 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
2613 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2617 typelib_struct tl_struct
;
2619 static const WCHAR szTYPELIB
[] = {'T','Y','P','E','L','I','B',0};
2621 component
= MSI_RecordGetString(row
,3);
2622 comp
= get_loaded_component(package
,component
);
2624 return ERROR_SUCCESS
;
2626 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
2628 TRACE("Skipping typelib reg due to disabled component\n");
2630 comp
->Action
= comp
->Installed
;
2632 return ERROR_SUCCESS
;
2635 comp
->Action
= INSTALLSTATE_LOCAL
;
2637 file
= get_loaded_file( package
, comp
->KeyPath
);
2639 return ERROR_SUCCESS
;
2641 module
= LoadLibraryExW( file
->TargetPath
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
2645 guid
= load_dynamic_stringW(row
,1);
2646 CLSIDFromString(guid
, &tl_struct
.clsid
);
2648 tl_struct
.source
= strdupW( file
->TargetPath
);
2649 tl_struct
.path
= NULL
;
2651 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
2652 (LONG_PTR
)&tl_struct
);
2654 if (tl_struct
.path
!= NULL
)
2660 helpid
= MSI_RecordGetString(row
,6);
2663 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,NULL
);
2664 res
= RegisterTypeLib(tl_struct
.ptLib
,tl_struct
.path
,help
);
2667 if (!SUCCEEDED(res
))
2668 ERR("Failed to register type library %s\n",
2669 debugstr_w(tl_struct
.path
));
2672 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
2674 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
2677 ITypeLib_Release(tl_struct
.ptLib
);
2678 msi_free(tl_struct
.path
);
2681 ERR("Failed to load type library %s\n",
2682 debugstr_w(tl_struct
.source
));
2684 FreeLibrary(module
);
2685 msi_free(tl_struct
.source
);
2688 ERR("Could not load file! %s\n", debugstr_w(file
->TargetPath
));
2690 return ERROR_SUCCESS
;
2693 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
2696 * OK this is a bit confusing.. I am given a _Component key and I believe
2697 * that the file that is being registered as a type library is the "key file
2698 * of that component" which I interpret to mean "The file in the KeyPath of
2703 static const WCHAR Query
[] =
2704 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2705 '`','T','y','p','e','L','i','b','`',0};
2708 return ERROR_INVALID_HANDLE
;
2710 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2711 if (rc
!= ERROR_SUCCESS
)
2712 return ERROR_SUCCESS
;
2714 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
2715 msiobj_release(&view
->hdr
);
2719 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
2721 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
2722 LPWSTR target_file
, target_folder
;
2724 WCHAR filename
[0x100];
2727 static const WCHAR szlnk
[]={'.','l','n','k',0};
2732 buffer
= MSI_RecordGetString(row
,4);
2733 comp
= get_loaded_component(package
,buffer
);
2735 return ERROR_SUCCESS
;
2737 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
2739 TRACE("Skipping shortcut creation due to disabled component\n");
2741 comp
->Action
= comp
->Installed
;
2743 return ERROR_SUCCESS
;
2746 comp
->Action
= INSTALLSTATE_LOCAL
;
2748 ui_actiondata(package
,szCreateShortcuts
,row
);
2750 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
2751 &IID_IShellLinkW
, (LPVOID
*) &sl
);
2755 ERR("Is IID_IShellLink\n");
2756 return ERROR_SUCCESS
;
2759 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
2762 ERR("Is IID_IPersistFile\n");
2763 return ERROR_SUCCESS
;
2766 buffer
= MSI_RecordGetString(row
,2);
2767 target_folder
= resolve_folder(package
, buffer
,FALSE
,FALSE
,NULL
);
2769 /* may be needed because of a bug somehwere else */
2770 create_full_pathW(target_folder
);
2773 MSI_RecordGetStringW(row
,3,filename
,&sz
);
2774 reduce_to_longfilename(filename
);
2775 if (!strchrW(filename
,'.') || strcmpiW(strchrW(filename
,'.'),szlnk
))
2776 strcatW(filename
,szlnk
);
2777 target_file
= build_directory_name(2, target_folder
, filename
);
2778 msi_free(target_folder
);
2780 buffer
= MSI_RecordGetString(row
,5);
2781 if (strchrW(buffer
,'['))
2784 deformat_string(package
,buffer
,&deformated
);
2785 IShellLinkW_SetPath(sl
,deformated
);
2786 msi_free(deformated
);
2790 FIXME("poorly handled shortcut format, advertised shortcut\n");
2791 IShellLinkW_SetPath(sl
,comp
->FullKeypath
);
2794 if (!MSI_RecordIsNull(row
,6))
2797 buffer
= MSI_RecordGetString(row
,6);
2798 deformat_string(package
,buffer
,&deformated
);
2799 IShellLinkW_SetArguments(sl
,deformated
);
2800 msi_free(deformated
);
2803 if (!MSI_RecordIsNull(row
,7))
2805 buffer
= MSI_RecordGetString(row
,7);
2806 IShellLinkW_SetDescription(sl
,buffer
);
2809 if (!MSI_RecordIsNull(row
,8))
2810 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
2812 if (!MSI_RecordIsNull(row
,9))
2817 buffer
= MSI_RecordGetString(row
,9);
2819 Path
= build_icon_path(package
,buffer
);
2820 index
= MSI_RecordGetInteger(row
,10);
2822 IShellLinkW_SetIconLocation(sl
,Path
,index
);
2826 if (!MSI_RecordIsNull(row
,11))
2827 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
2829 if (!MSI_RecordIsNull(row
,12))
2832 buffer
= MSI_RecordGetString(row
,12);
2833 Path
= resolve_folder(package
, buffer
, FALSE
, FALSE
, NULL
);
2834 IShellLinkW_SetWorkingDirectory(sl
,Path
);
2838 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
2839 IPersistFile_Save(pf
,target_file
,FALSE
);
2841 msi_free(target_file
);
2843 IPersistFile_Release( pf
);
2844 IShellLinkW_Release( sl
);
2846 return ERROR_SUCCESS
;
2849 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
2854 static const WCHAR Query
[] =
2855 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2856 '`','S','h','o','r','t','c','u','t','`',0};
2859 return ERROR_INVALID_HANDLE
;
2861 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2862 if (rc
!= ERROR_SUCCESS
)
2863 return ERROR_SUCCESS
;
2865 res
= CoInitialize( NULL
);
2868 ERR("CoInitialize failed\n");
2869 return ERROR_FUNCTION_FAILED
;
2872 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
2873 msiobj_release(&view
->hdr
);
2880 static UINT
ITERATE_PublishProduct(MSIRECORD
*row
, LPVOID param
)
2882 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
2890 FileName
= MSI_RecordGetString(row
,1);
2893 ERR("Unable to get FileName\n");
2894 return ERROR_SUCCESS
;
2897 FilePath
= build_icon_path(package
,FileName
);
2899 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
2901 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2902 FILE_ATTRIBUTE_NORMAL
, NULL
);
2904 if (the_file
== INVALID_HANDLE_VALUE
)
2906 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
2908 return ERROR_SUCCESS
;
2915 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
2916 if (rc
!= ERROR_SUCCESS
)
2918 ERR("Failed to get stream\n");
2919 CloseHandle(the_file
);
2920 DeleteFileW(FilePath
);
2923 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
2924 } while (sz
== 1024);
2928 CloseHandle(the_file
);
2929 return ERROR_SUCCESS
;
2933 * 99% of the work done here is only done for
2934 * advertised installs. However this is where the
2935 * Icon table is processed and written out
2936 * so that is what I am going to do here.
2938 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
2942 static const WCHAR Query
[]=
2943 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2944 '`','I','c','o','n','`',0};
2945 /* for registry stuff */
2948 static const WCHAR szProductLanguage
[] =
2949 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
2950 static const WCHAR szARPProductIcon
[] =
2951 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
2952 static const WCHAR szProductVersion
[] =
2953 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
2957 MSIHANDLE hDb
, hSumInfo
;
2960 return ERROR_INVALID_HANDLE
;
2962 /* write out icon files */
2964 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2965 if (rc
== ERROR_SUCCESS
)
2967 MSI_IterateRecords(view
, NULL
, ITERATE_PublishProduct
, package
);
2968 msiobj_release(&view
->hdr
);
2971 /* ok there is a lot more done here but i need to figure out what */
2973 rc
= MSIREG_OpenProductsKey(package
->ProductCode
,&hkey
,TRUE
);
2974 if (rc
!= ERROR_SUCCESS
)
2977 rc
= MSIREG_OpenUserProductsKey(package
->ProductCode
,&hukey
,TRUE
);
2978 if (rc
!= ERROR_SUCCESS
)
2982 buffer
= msi_dup_property( package
, INSTALLPROPERTY_PRODUCTNAMEW
);
2983 msi_reg_set_val_str( hukey
, INSTALLPROPERTY_PRODUCTNAMEW
, buffer
);
2986 buffer
= msi_dup_property( package
, szProductLanguage
);
2987 langid
= atoiW(buffer
);
2988 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
2991 buffer
= msi_dup_property( package
, szARPProductIcon
);
2994 LPWSTR path
= build_icon_path(package
,buffer
);
2995 msi_reg_set_val_str( hukey
, INSTALLPROPERTY_PRODUCTICONW
, path
);
3000 buffer
= msi_dup_property( package
, szProductVersion
);
3003 DWORD verdword
= build_version_dword(buffer
);
3004 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
3008 FIXME("Need to write more keys to the user registry\n");
3010 hDb
= alloc_msihandle( &package
->db
->hdr
);
3011 rc
= MsiGetSummaryInformationW(hDb
, NULL
, 0, &hSumInfo
);
3012 MsiCloseHandle(hDb
);
3013 if (rc
== ERROR_SUCCESS
)
3015 WCHAR guidbuffer
[0x200];
3017 rc
= MsiSummaryInfoGetPropertyW(hSumInfo
, 9, NULL
, NULL
, NULL
,
3019 if (rc
== ERROR_SUCCESS
)
3021 WCHAR squashed
[GUID_SIZE
];
3022 /* for now we only care about the first guid */
3023 LPWSTR ptr
= strchrW(guidbuffer
,';');
3025 squash_guid(guidbuffer
,squashed
);
3026 msi_reg_set_val_str( hukey
, INSTALLPROPERTY_PACKAGECODEW
, squashed
);
3030 ERR("Unable to query Revision_Number... \n");
3033 MsiCloseHandle(hSumInfo
);
3037 ERR("Unable to open Summary Information\n");
3049 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
3051 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3052 LPCWSTR component
,section
,key
,value
,identifier
,filename
,dirproperty
;
3053 LPWSTR deformated_section
, deformated_key
, deformated_value
;
3054 LPWSTR folder
, fullname
= NULL
;
3058 static const WCHAR szWindowsFolder
[] =
3059 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3061 component
= MSI_RecordGetString(row
, 8);
3062 comp
= get_loaded_component(package
,component
);
3064 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
))
3066 TRACE("Skipping ini file due to disabled component %s\n",
3067 debugstr_w(component
));
3069 comp
->Action
= comp
->Installed
;
3071 return ERROR_SUCCESS
;
3074 comp
->Action
= INSTALLSTATE_LOCAL
;
3076 identifier
= MSI_RecordGetString(row
,1);
3077 filename
= MSI_RecordGetString(row
,2);
3078 dirproperty
= MSI_RecordGetString(row
,3);
3079 section
= MSI_RecordGetString(row
,4);
3080 key
= MSI_RecordGetString(row
,5);
3081 value
= MSI_RecordGetString(row
,6);
3082 action
= MSI_RecordGetInteger(row
,7);
3084 deformat_string(package
,section
,&deformated_section
);
3085 deformat_string(package
,key
,&deformated_key
);
3086 deformat_string(package
,value
,&deformated_value
);
3090 folder
= resolve_folder(package
, dirproperty
, FALSE
, FALSE
, NULL
);
3092 folder
= msi_dup_property( package
, dirproperty
);
3095 folder
= msi_dup_property( package
, szWindowsFolder
);
3099 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty
));
3103 fullname
= build_directory_name(2, folder
, filename
);
3107 TRACE("Adding value %s to section %s in %s\n",
3108 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3109 debugstr_w(fullname
));
3110 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3111 deformated_value
, fullname
);
3113 else if (action
== 1)
3116 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
3117 returned
, 10, fullname
);
3118 if (returned
[0] == 0)
3120 TRACE("Adding value %s to section %s in %s\n",
3121 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3122 debugstr_w(fullname
));
3124 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3125 deformated_value
, fullname
);
3128 else if (action
== 3)
3129 FIXME("Append to existing section not yet implemented\n");
3131 uirow
= MSI_CreateRecord(4);
3132 MSI_RecordSetStringW(uirow
,1,identifier
);
3133 MSI_RecordSetStringW(uirow
,2,deformated_section
);
3134 MSI_RecordSetStringW(uirow
,3,deformated_key
);
3135 MSI_RecordSetStringW(uirow
,4,deformated_value
);
3136 ui_actiondata(package
,szWriteIniValues
,uirow
);
3137 msiobj_release( &uirow
->hdr
);
3141 msi_free(deformated_key
);
3142 msi_free(deformated_value
);
3143 msi_free(deformated_section
);
3144 return ERROR_SUCCESS
;
3147 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
3151 static const WCHAR ExecSeqQuery
[] =
3152 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3153 '`','I','n','i','F','i','l','e','`',0};
3155 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3156 if (rc
!= ERROR_SUCCESS
)
3158 TRACE("no IniFile table\n");
3159 return ERROR_SUCCESS
;
3162 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
3163 msiobj_release(&view
->hdr
);
3167 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
3169 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3174 static const WCHAR ExeStr
[] =
3175 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3176 static const WCHAR close
[] = {'\"',0};
3178 PROCESS_INFORMATION info
;
3181 memset(&si
,0,sizeof(STARTUPINFOW
));
3183 filename
= MSI_RecordGetString(row
,1);
3184 file
= get_loaded_file( package
, filename
);
3188 ERR("Unable to find file id %s\n",debugstr_w(filename
));
3189 return ERROR_SUCCESS
;
3192 len
= strlenW(ExeStr
) + strlenW( file
->TargetPath
) + 2;
3194 FullName
= msi_alloc(len
*sizeof(WCHAR
));
3195 strcpyW(FullName
,ExeStr
);
3196 strcatW( FullName
, file
->TargetPath
);
3197 strcatW(FullName
,close
);
3199 TRACE("Registering %s\n",debugstr_w(FullName
));
3200 brc
= CreateProcessW(NULL
, FullName
, NULL
, NULL
, FALSE
, 0, NULL
, c_colon
,
3204 msi_dialog_check_messages(info
.hProcess
);
3207 return ERROR_SUCCESS
;
3210 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
3214 static const WCHAR ExecSeqQuery
[] =
3215 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3216 '`','S','e','l','f','R','e','g','`',0};
3218 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3219 if (rc
!= ERROR_SUCCESS
)
3221 TRACE("no SelfReg table\n");
3222 return ERROR_SUCCESS
;
3225 MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
3226 msiobj_release(&view
->hdr
);
3228 return ERROR_SUCCESS
;
3231 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
3233 MSIFEATURE
*feature
;
3239 return ERROR_INVALID_HANDLE
;
3241 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
,&hkey
,TRUE
);
3242 if (rc
!= ERROR_SUCCESS
)
3245 rc
= MSIREG_OpenUserFeaturesKey(package
->ProductCode
,&hukey
,TRUE
);
3246 if (rc
!= ERROR_SUCCESS
)
3249 /* here the guids are base 85 encoded */
3250 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3256 BOOL absent
= FALSE
;
3258 if (!ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_LOCAL
) &&
3259 !ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_SOURCE
) &&
3260 !ACTION_VerifyFeatureForAction( feature
, INSTALLSTATE_ADVERTISED
))
3264 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3268 if (feature
->Feature_Parent
)
3269 size
+= strlenW( feature
->Feature_Parent
)+2;
3271 data
= msi_alloc(size
* sizeof(WCHAR
));
3274 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3276 MSICOMPONENT
* component
= cl
->component
;
3279 memset(buf
,0,sizeof(buf
));
3280 if (component
->ComponentId
)
3282 TRACE("From %s\n",debugstr_w(component
->ComponentId
));
3283 CLSIDFromString(component
->ComponentId
, &clsid
);
3284 encode_base85_guid(&clsid
,buf
);
3285 TRACE("to %s\n",debugstr_w(buf
));
3289 if (feature
->Feature_Parent
)
3291 static const WCHAR sep
[] = {'\2',0};
3293 strcatW(data
,feature
->Feature_Parent
);
3296 msi_reg_set_val_str( hkey
, feature
->Feature
, data
);
3300 if (feature
->Feature_Parent
)
3301 size
= strlenW(feature
->Feature_Parent
)*sizeof(WCHAR
);
3304 RegSetValueExW(hukey
,feature
->Feature
,0,REG_SZ
,
3305 (LPBYTE
)feature
->Feature_Parent
,size
);
3309 size
+= 2*sizeof(WCHAR
);
3310 data
= msi_alloc(size
);
3313 if (feature
->Feature_Parent
)
3314 strcpyW( &data
[1], feature
->Feature_Parent
);
3315 RegSetValueExW(hukey
,feature
->Feature
,0,REG_SZ
,
3327 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
3330 LPWSTR buffer
= NULL
;
3333 static const WCHAR szWindowsInstaller
[] =
3334 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
3335 static const WCHAR szPropKeys
[][80] =
3337 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
3338 {'A','R','P','C','O','N','T','A','C','T',0},
3339 {'A','R','P','C','O','M','M','E','N','T','S',0},
3340 {'P','r','o','d','u','c','t','N','a','m','e',0},
3341 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
3342 {'A','R','P','H','E','L','P','L','I','N','K',0},
3343 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
3344 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
3345 {'S','o','u','r','c','e','D','i','r',0},
3346 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
3347 {'A','R','P','R','E','A','D','M','E',0},
3348 {'A','R','P','S','I','Z','E',0},
3349 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
3350 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
3354 static const WCHAR szRegKeys
[][80] =
3356 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
3357 {'C','o','n','t','a','c','t',0},
3358 {'C','o','m','m','e','n','t','s',0},
3359 {'D','i','s','p','l','a','y','N','a','m','e',0},
3360 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
3361 {'H','e','l','p','L','i','n','k',0},
3362 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
3363 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
3364 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
3365 {'P','u','b','l','i','s','h','e','r',0},
3366 {'R','e','a','d','m','e',0},
3367 {'S','i','z','e',0},
3368 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
3369 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
3373 static const WCHAR installerPathFmt
[] = {
3375 'I','n','s','t','a','l','l','e','r','\\',0};
3376 static const WCHAR fmt
[] = {
3378 'I','n','s','t','a','l','l','e','r','\\',
3379 '%','x','.','m','s','i',0};
3380 static const WCHAR szUpgradeCode
[] =
3381 {'U','p','g','r','a','d','e','C','o','d','e',0};
3382 static const WCHAR modpath_fmt
[] =
3383 {'M','s','i','E','x','e','c','.','e','x','e',' ','/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
3384 static const WCHAR szModifyPath
[] =
3385 {'M','o','d','i','f','y','P','a','t','h',0};
3386 static const WCHAR szUninstallString
[] =
3387 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
3388 static const WCHAR szEstimatedSize
[] =
3389 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
3390 static const WCHAR szProductLanguage
[] =
3391 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3392 static const WCHAR szProductVersion
[] =
3393 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3396 static const WCHAR date_fmt
[] = {'%','i','%','i','%','i',0};
3397 LPWSTR upgrade_code
;
3398 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], packagefile
[MAX_PATH
];
3402 return ERROR_INVALID_HANDLE
;
3404 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
,&hkey
,TRUE
);
3405 if (rc
!= ERROR_SUCCESS
)
3408 /* dump all the info i can grab */
3409 FIXME("Flesh out more information \n");
3411 for( i
=0; szPropKeys
[i
][0]; i
++ )
3413 buffer
= msi_dup_property( package
, szPropKeys
[i
] );
3414 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
3418 msi_reg_set_val_dword( hkey
, szWindowsInstaller
, 1 );
3420 /* copy the package locally */
3421 num
= GetTickCount() & 0xffff;
3425 GetWindowsDirectoryW(windir
, sizeof(windir
) / sizeof(windir
[0]));
3426 snprintfW(packagefile
,sizeof(packagefile
)/sizeof(packagefile
[0]),fmt
,
3430 HANDLE handle
= CreateFileW(packagefile
,GENERIC_WRITE
, 0, NULL
,
3431 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
3432 if (handle
!= INVALID_HANDLE_VALUE
)
3434 CloseHandle(handle
);
3437 if (GetLastError() != ERROR_FILE_EXISTS
&&
3438 GetLastError() != ERROR_SHARING_VIOLATION
)
3440 if (!(++num
& 0xffff)) num
= 1;
3441 sprintfW(packagefile
,fmt
,num
);
3442 } while (num
!= start
);
3444 snprintfW(path
,sizeof(path
)/sizeof(path
[0]),installerPathFmt
,windir
);
3445 create_full_pathW(path
);
3446 TRACE("Copying to local package %s\n",debugstr_w(packagefile
));
3447 if (!CopyFileW(package
->msiFilePath
,packagefile
,FALSE
))
3448 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
3449 debugstr_w(package
->msiFilePath
), debugstr_w(packagefile
),
3451 msi_reg_set_val_str( hkey
, INSTALLPROPERTY_LOCALPACKAGEW
, packagefile
);
3453 /* do ModifyPath and UninstallString */
3454 size
= deformat_string(package
,modpath_fmt
,&buffer
);
3455 RegSetValueExW(hkey
,szModifyPath
,0,REG_EXPAND_SZ
,(LPBYTE
)buffer
,size
);
3456 RegSetValueExW(hkey
,szUninstallString
,0,REG_EXPAND_SZ
,(LPBYTE
)buffer
,size
);
3459 FIXME("Write real Estimated Size when we have it\n");
3460 msi_reg_set_val_dword( hkey
, szEstimatedSize
, 0 );
3462 GetLocalTime(&systime
);
3463 size
= 9*sizeof(WCHAR
);
3464 buffer
= msi_alloc(size
);
3465 sprintfW(buffer
,date_fmt
,systime
.wYear
,systime
.wMonth
,systime
.wDay
);
3466 msi_reg_set_val_str( hkey
, INSTALLPROPERTY_INSTALLDATEW
, buffer
);
3469 buffer
= msi_dup_property( package
, szProductLanguage
);
3470 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_LANGUAGEW
, atoiW(buffer
) );
3473 buffer
= msi_dup_property( package
, szProductVersion
);
3476 DWORD verdword
= build_version_dword(buffer
);
3478 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
3479 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_VERSIONMAJORW
, verdword
>>24 );
3480 msi_reg_set_val_dword( hkey
, INSTALLPROPERTY_VERSIONMINORW
, (verdword
>>16)&0x00FF );
3484 /* Handle Upgrade Codes */
3485 upgrade_code
= msi_dup_property( package
, szUpgradeCode
);
3490 MSIREG_OpenUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3491 squash_guid(package
->ProductCode
,squashed
);
3492 msi_reg_set_val_str( hkey2
, squashed
, NULL
);
3494 MSIREG_OpenUserUpgradeCodesKey(upgrade_code
, &hkey2
, TRUE
);
3495 squash_guid(package
->ProductCode
,squashed
);
3496 msi_reg_set_val_str( hkey2
, squashed
, NULL
);
3499 msi_free(upgrade_code
);
3505 return ERROR_SUCCESS
;
3508 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
3513 return ERROR_INVALID_HANDLE
;
3515 rc
= execute_script(package
,INSTALL_SCRIPT
);
3520 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
3525 return ERROR_INVALID_HANDLE
;
3527 /* turn off scheduleing */
3528 package
->script
->CurrentlyScripting
= FALSE
;
3530 /* first do the same as an InstallExecute */
3531 rc
= ACTION_InstallExecute(package
);
3532 if (rc
!= ERROR_SUCCESS
)
3535 /* then handle Commit Actions */
3536 rc
= execute_script(package
,COMMIT_SCRIPT
);
3541 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
3543 static const WCHAR RunOnce
[] = {
3544 'S','o','f','t','w','a','r','e','\\',
3545 'M','i','c','r','o','s','o','f','t','\\',
3546 'W','i','n','d','o','w','s','\\',
3547 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3548 'R','u','n','O','n','c','e',0};
3549 static const WCHAR InstallRunOnce
[] = {
3550 'S','o','f','t','w','a','r','e','\\',
3551 'M','i','c','r','o','s','o','f','t','\\',
3552 'W','i','n','d','o','w','s','\\',
3553 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3554 'I','n','s','t','a','l','l','e','r','\\',
3555 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
3557 static const WCHAR msiexec_fmt
[] = {
3559 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
3560 '\"','%','s','\"',0};
3561 static const WCHAR install_fmt
[] = {
3562 '/','I',' ','\"','%','s','\"',' ',
3563 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
3564 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
3565 WCHAR buffer
[256], sysdir
[MAX_PATH
];
3567 WCHAR squished_pc
[100];
3570 return ERROR_INVALID_HANDLE
;
3572 squash_guid(package
->ProductCode
,squished_pc
);
3574 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
3575 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
3576 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
3579 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
3582 TRACE("Reboot command %s\n",debugstr_w(buffer
));
3584 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
3585 sprintfW(buffer
,install_fmt
,package
->ProductCode
,squished_pc
);
3587 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
3590 return ERROR_INSTALL_SUSPEND
;
3593 UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
3598 * we are currently doing what should be done here in the top level Install
3599 * however for Adminastrative and uninstalls this step will be needed
3601 if (!package
->PackagePath
)
3602 return ERROR_SUCCESS
;
3604 attrib
= GetFileAttributesW(package
->PackagePath
);
3605 if (attrib
== INVALID_FILE_ATTRIBUTES
)
3611 rc
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
3612 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
,
3613 INSTALLPROPERTY_DISKPROMPTW
,NULL
,&size
);
3614 if (rc
== ERROR_MORE_DATA
)
3616 prompt
= msi_alloc(size
* sizeof(WCHAR
));
3617 MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
3618 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
,
3619 INSTALLPROPERTY_DISKPROMPTW
,prompt
,&size
);
3622 prompt
= strdupW(package
->PackagePath
);
3624 msg
= generate_error_string(package
,1302,1,prompt
);
3625 while(attrib
== INVALID_FILE_ATTRIBUTES
)
3627 rc
= MessageBoxW(NULL
,msg
,NULL
,MB_OKCANCEL
);
3630 rc
= ERROR_INSTALL_USEREXIT
;
3633 attrib
= GetFileAttributesW(package
->PackagePath
);
3639 return ERROR_SUCCESS
;
3644 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
3651 static const WCHAR szPropKeys
[][80] =
3653 {'P','r','o','d','u','c','t','I','D',0},
3654 {'U','S','E','R','N','A','M','E',0},
3655 {'C','O','M','P','A','N','Y','N','A','M','E',0},
3659 static const WCHAR szRegKeys
[][80] =
3661 {'P','r','o','d','u','c','t','I','D',0},
3662 {'R','e','g','O','w','n','e','r',0},
3663 {'R','e','g','C','o','m','p','a','n','y',0},
3668 return ERROR_INVALID_HANDLE
;
3670 productid
= msi_dup_property( package
, INSTALLPROPERTY_PRODUCTIDW
);
3672 return ERROR_SUCCESS
;
3674 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
,&hkey
,TRUE
);
3675 if (rc
!= ERROR_SUCCESS
)
3678 for( i
= 0; szPropKeys
[i
][0]; i
++ )
3680 buffer
= msi_dup_property( package
, szPropKeys
[i
] );
3681 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
3686 msi_free(productid
);
3689 return ERROR_SUCCESS
;
3693 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
3695 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
3696 static const WCHAR szTwo
[] = {'2',0};
3699 level
= msi_dup_property( package
, szUILevel
);
3701 MSI_SetPropertyW(package
,szUILevel
,szTwo
);
3702 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
3703 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
3704 MSI_SetPropertyW(package
,szUILevel
,level
);
3711 * Code based off of code located here
3712 * http://www.codeproject.com/gdi/fontnamefromfile.asp
3714 * Using string index 4 (full font name) instead of 1 (family name)
3716 static LPWSTR
load_ttfname_from(LPCWSTR filename
)
3722 typedef struct _tagTT_OFFSET_TABLE
{
3723 USHORT uMajorVersion
;
3724 USHORT uMinorVersion
;
3725 USHORT uNumOfTables
;
3726 USHORT uSearchRange
;
3727 USHORT uEntrySelector
;
3731 typedef struct _tagTT_TABLE_DIRECTORY
{
3732 char szTag
[4]; /* table name */
3733 ULONG uCheckSum
; /* Check sum */
3734 ULONG uOffset
; /* Offset from beginning of file */
3735 ULONG uLength
; /* length of the table in bytes */
3736 }TT_TABLE_DIRECTORY
;
3738 typedef struct _tagTT_NAME_TABLE_HEADER
{
3739 USHORT uFSelector
; /* format selector. Always 0 */
3740 USHORT uNRCount
; /* Name Records count */
3741 USHORT uStorageOffset
; /* Offset for strings storage,
3742 * from start of the table */
3743 }TT_NAME_TABLE_HEADER
;
3745 typedef struct _tagTT_NAME_RECORD
{
3750 USHORT uStringLength
;
3751 USHORT uStringOffset
; /* from start of storage area */
3754 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
3755 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
3757 handle
= CreateFileW(filename
,GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
3758 FILE_ATTRIBUTE_NORMAL
, 0 );
3759 if (handle
!= INVALID_HANDLE_VALUE
)
3761 TT_TABLE_DIRECTORY tblDir
;
3762 BOOL bFound
= FALSE
;
3763 TT_OFFSET_TABLE ttOffsetTable
;
3765 ReadFile(handle
,&ttOffsetTable
, sizeof(TT_OFFSET_TABLE
),NULL
,NULL
);
3766 ttOffsetTable
.uNumOfTables
= SWAPWORD(ttOffsetTable
.uNumOfTables
);
3767 ttOffsetTable
.uMajorVersion
= SWAPWORD(ttOffsetTable
.uMajorVersion
);
3768 ttOffsetTable
.uMinorVersion
= SWAPWORD(ttOffsetTable
.uMinorVersion
);
3770 if (ttOffsetTable
.uMajorVersion
!= 1 ||
3771 ttOffsetTable
.uMinorVersion
!= 0)
3774 for (i
=0; i
< ttOffsetTable
.uNumOfTables
; i
++)
3776 ReadFile(handle
,&tblDir
, sizeof(TT_TABLE_DIRECTORY
),NULL
,NULL
);
3777 if (strncmp(tblDir
.szTag
,"name",4)==0)
3780 tblDir
.uLength
= SWAPLONG(tblDir
.uLength
);
3781 tblDir
.uOffset
= SWAPLONG(tblDir
.uOffset
);
3788 TT_NAME_TABLE_HEADER ttNTHeader
;
3789 TT_NAME_RECORD ttRecord
;
3791 SetFilePointer(handle
, tblDir
.uOffset
, NULL
, FILE_BEGIN
);
3792 ReadFile(handle
,&ttNTHeader
, sizeof(TT_NAME_TABLE_HEADER
),
3795 ttNTHeader
.uNRCount
= SWAPWORD(ttNTHeader
.uNRCount
);
3796 ttNTHeader
.uStorageOffset
= SWAPWORD(ttNTHeader
.uStorageOffset
);
3798 for(i
=0; i
<ttNTHeader
.uNRCount
; i
++)
3800 ReadFile(handle
,&ttRecord
, sizeof(TT_NAME_RECORD
),NULL
,NULL
);
3801 ttRecord
.uNameID
= SWAPWORD(ttRecord
.uNameID
);
3802 /* 4 is the Full Font Name */
3803 if(ttRecord
.uNameID
== 4)
3807 static LPCSTR tt
= " (TrueType)";
3809 ttRecord
.uStringLength
= SWAPWORD(ttRecord
.uStringLength
);
3810 ttRecord
.uStringOffset
= SWAPWORD(ttRecord
.uStringOffset
);
3811 nPos
= SetFilePointer(handle
, 0, NULL
, FILE_CURRENT
);
3812 SetFilePointer(handle
, tblDir
.uOffset
+
3813 ttRecord
.uStringOffset
+
3814 ttNTHeader
.uStorageOffset
,
3816 buf
= msi_alloc( ttRecord
.uStringLength
+ 1 + strlen(tt
) );
3817 memset(buf
, 0, ttRecord
.uStringLength
+ 1 + strlen(tt
));
3818 ReadFile(handle
, buf
, ttRecord
.uStringLength
, NULL
, NULL
);
3819 if (strlen(buf
) > 0)
3822 ret
= strdupAtoW(buf
);
3828 SetFilePointer(handle
,nPos
, NULL
, FILE_BEGIN
);
3832 CloseHandle(handle
);
3835 ERR("Unable to open font file %s\n", debugstr_w(filename
));
3837 TRACE("Returning fontname %s\n",debugstr_w(ret
));
3841 static UINT
ITERATE_RegisterFonts(MSIRECORD
*row
, LPVOID param
)
3843 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3847 static const WCHAR regfont1
[] =
3848 {'S','o','f','t','w','a','r','e','\\',
3849 'M','i','c','r','o','s','o','f','t','\\',
3850 'W','i','n','d','o','w','s',' ','N','T','\\',
3851 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3852 'F','o','n','t','s',0};
3853 static const WCHAR regfont2
[] =
3854 {'S','o','f','t','w','a','r','e','\\',
3855 'M','i','c','r','o','s','o','f','t','\\',
3856 'W','i','n','d','o','w','s','\\',
3857 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3858 'F','o','n','t','s',0};
3862 filename
= MSI_RecordGetString( row
, 1 );
3863 file
= get_loaded_file( package
, filename
);
3866 ERR("Unable to load file\n");
3867 return ERROR_SUCCESS
;
3870 /* check to make sure that component is installed */
3871 if (!ACTION_VerifyComponentForAction(package
,
3872 file
->Component
, INSTALLSTATE_LOCAL
))
3874 TRACE("Skipping: Component not scheduled for install\n");
3875 return ERROR_SUCCESS
;
3878 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont1
,&hkey1
);
3879 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont2
,&hkey2
);
3881 if (MSI_RecordIsNull(row
,2))
3882 name
= load_ttfname_from( file
->TargetPath
);
3884 name
= load_dynamic_stringW(row
,2);
3888 msi_reg_set_val_str( hkey1
, name
, file
->FileName
);
3889 msi_reg_set_val_str( hkey2
, name
, file
->FileName
);
3895 return ERROR_SUCCESS
;
3898 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
)
3902 static const WCHAR ExecSeqQuery
[] =
3903 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3904 '`','F','o','n','t','`',0};
3906 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3907 if (rc
!= ERROR_SUCCESS
)
3909 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc
);
3910 return ERROR_SUCCESS
;
3913 MSI_IterateRecords(view
, NULL
, ITERATE_RegisterFonts
, package
);
3914 msiobj_release(&view
->hdr
);
3916 return ERROR_SUCCESS
;
3919 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
3921 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
3922 LPCWSTR compgroupid
=NULL
;
3923 LPCWSTR feature
=NULL
;
3924 LPCWSTR text
= NULL
;
3925 LPCWSTR qualifier
= NULL
;
3926 LPCWSTR component
= NULL
;
3927 LPWSTR advertise
= NULL
;
3928 LPWSTR output
= NULL
;
3930 UINT rc
= ERROR_SUCCESS
;
3934 component
= MSI_RecordGetString(rec
,3);
3935 comp
= get_loaded_component(package
,component
);
3937 if (!ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_LOCAL
) &&
3938 !ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_SOURCE
) &&
3939 !ACTION_VerifyComponentForAction(package
, comp
, INSTALLSTATE_ADVERTISED
))
3941 TRACE("Skipping: Component %s not scheduled for install\n",
3942 debugstr_w(component
));
3944 return ERROR_SUCCESS
;
3947 compgroupid
= MSI_RecordGetString(rec
,1);
3949 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
3950 if (rc
!= ERROR_SUCCESS
)
3953 text
= MSI_RecordGetString(rec
,4);
3954 qualifier
= MSI_RecordGetString(rec
,2);
3955 feature
= MSI_RecordGetString(rec
,5);
3957 advertise
= create_component_advertise_string(package
, comp
, feature
);
3959 sz
= strlenW(advertise
);
3962 sz
+= lstrlenW(text
);
3965 sz
*= sizeof(WCHAR
);
3967 output
= msi_alloc(sz
);
3968 memset(output
,0,sz
);
3969 strcpyW(output
,advertise
);
3970 msi_free(advertise
);
3973 strcatW(output
,text
);
3975 msi_reg_set_val_multi_str( hkey
, qualifier
, output
);
3985 * At present I am ignorning the advertised components part of this and only
3986 * focusing on the qualified component sets
3988 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
3992 static const WCHAR ExecSeqQuery
[] =
3993 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3994 '`','P','u','b','l','i','s','h',
3995 'C','o','m','p','o','n','e','n','t','`',0};
3997 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3998 if (rc
!= ERROR_SUCCESS
)
3999 return ERROR_SUCCESS
;
4001 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
4002 msiobj_release(&view
->hdr
);