2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 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
38 #include "wine/debug.h"
43 #include "msvcrt/fcntl.h"
50 #include "wine/unicode.h"
54 #define REG_PROGRESS_VALUE 13200
55 #define COMPONENT_PROGRESS_VALUE 24000
57 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
62 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
);
63 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
);
64 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
);
65 static UINT
build_icon_path(MSIPACKAGE
*package
, LPCWSTR icon_name
,
71 typedef UINT (*STANDARDACTIONHANDLER
)(MSIPACKAGE
*);
73 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
);
74 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
);
75 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
);
76 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
);
77 static UINT
ACTION_FileCost(MSIPACKAGE
*package
);
78 static UINT
ACTION_InstallFiles(MSIPACKAGE
*package
);
79 static UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
);
80 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
);
81 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
);
82 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
);
83 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
);
84 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
);
85 static UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
);
86 static UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
);
87 static UINT
ACTION_RegisterExtensionInfo(MSIPACKAGE
*package
);
88 static UINT
ACTION_RegisterMIMEInfo(MSIPACKAGE
*package
);
89 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
);
90 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
);
91 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
);
92 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
);
93 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
);
94 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
);
95 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
);
96 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
);
97 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
);
98 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
);
99 static UINT
ACTION_ResolveSource(MSIPACKAGE
*package
);
100 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
);
101 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
);
102 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
);
106 * consts and values used
108 static const WCHAR cszSourceDir
[] = {'S','o','u','r','c','e','D','i','r',0};
109 static const WCHAR cszRootDrive
[] = {'R','O','O','T','D','R','I','V','E',0};
110 static const WCHAR cszTargetDir
[] = {'T','A','R','G','E','T','D','I','R',0};
111 static const WCHAR cszTempFolder
[]= {'T','e','m','p','F','o','l','d','e','r',0};
112 static const WCHAR cszDatabase
[]={'D','A','T','A','B','A','S','E',0};
113 static const WCHAR c_colon
[] = {'C',':','\\',0};
114 static const WCHAR szProductCode
[]=
115 {'P','r','o','d','u','c','t','C','o','d','e',0};
116 static const WCHAR cszbs
[]={'\\',0};
117 const static WCHAR szCreateFolders
[] =
118 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
119 const static WCHAR szCostFinalize
[] =
120 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
121 const static WCHAR szInstallFiles
[] =
122 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
123 const static WCHAR szDuplicateFiles
[] =
124 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
125 const static WCHAR szWriteRegistryValues
[] =
126 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
127 'V','a','l','u','e','s',0};
128 const static WCHAR szCostInitialize
[] =
129 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
130 const static WCHAR szFileCost
[] =
131 {'F','i','l','e','C','o','s','t',0};
132 const static WCHAR szInstallInitialize
[] =
133 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
134 const static WCHAR szInstallValidate
[] =
135 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
136 const static WCHAR szLaunchConditions
[] =
137 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
138 const static WCHAR szProcessComponents
[] =
139 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
140 const static WCHAR szRegisterTypeLibraries
[] =
141 {'R','e','g','i','s','t','e','r','T','y','p','e',
142 'L','i','b','r','a','r','i','e','s',0};
143 const static WCHAR szRegisterClassInfo
[] =
144 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
145 const static WCHAR szRegisterProgIdInfo
[] =
146 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
147 const static WCHAR szCreateShortcuts
[] =
148 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
149 const static WCHAR szPublishProduct
[] =
150 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
151 const static WCHAR szWriteIniValues
[] =
152 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
153 const static WCHAR szSelfRegModules
[] =
154 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
155 const static WCHAR szPublishFeatures
[] =
156 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
157 const static WCHAR szRegisterProduct
[] =
158 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
159 const static WCHAR szInstallExecute
[] =
160 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
161 const static WCHAR szInstallExecuteAgain
[] =
162 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
163 'A','g','a','i','n',0};
164 const static WCHAR szInstallFinalize
[] =
165 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
166 const static WCHAR szForceReboot
[] =
167 {'F','o','r','c','e','R','e','b','o','o','t',0};
168 const static WCHAR szResolveSource
[] =
169 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
170 const static WCHAR szAppSearch
[] =
171 {'A','p','p','S','e','a','r','c','h',0};
172 const static WCHAR szAllocateRegistrySpace
[] =
173 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
174 'S','p','a','c','e',0};
175 const static WCHAR szBindImage
[] =
176 {'B','i','n','d','I','m','a','g','e',0};
177 const static WCHAR szCCPSearch
[] =
178 {'C','C','P','S','e','a','r','c','h',0};
179 const static WCHAR szDeleteServices
[] =
180 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
181 const static WCHAR szDisableRollback
[] =
182 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
183 const static WCHAR szExecuteAction
[] =
184 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
185 const static WCHAR szFindRelatedProducts
[] =
186 {'F','i','n','d','R','e','l','a','t','e','d',
187 'P','r','o','d','u','c','t','s',0};
188 const static WCHAR szInstallAdminPackage
[] =
189 {'I','n','s','t','a','l','l','A','d','m','i','n',
190 'P','a','c','k','a','g','e',0};
191 const static WCHAR szInstallSFPCatalogFile
[] =
192 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
194 const static WCHAR szIsolateComponents
[] =
195 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
196 const static WCHAR szMigrateFeatureStates
[] =
197 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
198 'S','t','a','t','e','s',0};
199 const static WCHAR szMoveFiles
[] =
200 {'M','o','v','e','F','i','l','e','s',0};
201 const static WCHAR szMsiPublishAssemblies
[] =
202 {'M','s','i','P','u','b','l','i','s','h',
203 'A','s','s','e','m','b','l','i','e','s',0};
204 const static WCHAR szMsiUnpublishAssemblies
[] =
205 {'M','s','i','U','n','p','u','b','l','i','s','h',
206 'A','s','s','e','m','b','l','i','e','s',0};
207 const static WCHAR szInstallODBC
[] =
208 {'I','n','s','t','a','l','l','O','D','B','C',0};
209 const static WCHAR szInstallServices
[] =
210 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
211 const static WCHAR szPatchFiles
[] =
212 {'P','a','t','c','h','F','i','l','e','s',0};
213 const static WCHAR szPublishComponents
[] =
214 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
215 const static WCHAR szRegisterComPlus
[] =
216 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
217 const static WCHAR szRegisterExtensionInfo
[] =
218 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
220 const static WCHAR szRegisterFonts
[] =
221 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
222 const static WCHAR szRegisterMIMEInfo
[] =
223 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
224 const static WCHAR szRegisterUser
[] =
225 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
226 const static WCHAR szRemoveDuplicateFiles
[] =
227 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
228 'F','i','l','e','s',0};
229 const static WCHAR szRemoveEnvironmentStrings
[] =
230 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
231 'S','t','r','i','n','g','s',0};
232 const static WCHAR szRemoveExistingProducts
[] =
233 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
234 'P','r','o','d','u','c','t','s',0};
235 const static WCHAR szRemoveFiles
[] =
236 {'R','e','m','o','v','e','F','i','l','e','s',0};
237 const static WCHAR szRemoveFolders
[] =
238 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
239 const static WCHAR szRemoveIniValues
[] =
240 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
241 const static WCHAR szRemoveODBC
[] =
242 {'R','e','m','o','v','e','O','D','B','C',0};
243 const static WCHAR szRemoveRegistryValues
[] =
244 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
245 'V','a','l','u','e','s',0};
246 const static WCHAR szRemoveShortcuts
[] =
247 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
248 const static WCHAR szRMCCPSearch
[] =
249 {'R','M','C','C','P','S','e','a','r','c','h',0};
250 const static WCHAR szScheduleReboot
[] =
251 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
252 const static WCHAR szSelfUnregModules
[] =
253 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
254 const static WCHAR szSetODBCFolders
[] =
255 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
256 const static WCHAR szStartServices
[] =
257 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
258 const static WCHAR szStopServices
[] =
259 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
260 const static WCHAR szUnpublishComponents
[] =
261 {'U','n','p','u','b','l','i','s','h',
262 'C','o','m','p','o','n','e','n','t','s',0};
263 const static WCHAR szUnpublishFeatures
[] =
264 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
265 const static WCHAR szUnregisterClassInfo
[] =
266 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
268 const static WCHAR szUnregisterComPlus
[] =
269 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
270 const static WCHAR szUnregisterExtensionInfo
[] =
271 {'U','n','r','e','g','i','s','t','e','r',
272 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
273 const static WCHAR szUnregisterFonts
[] =
274 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
275 const static WCHAR szUnregisterMIMEInfo
[] =
276 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
277 const static WCHAR szUnregisterProgIdInfo
[] =
278 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
280 const static WCHAR szUnregisterTypeLibraries
[] =
281 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
282 'L','i','b','r','a','r','i','e','s',0};
283 const static WCHAR szValidateProductID
[] =
284 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
285 const static WCHAR szWriteEnvironmentStrings
[] =
286 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
287 'S','t','r','i','n','g','s',0};
291 STANDARDACTIONHANDLER handler
;
294 static struct _actions StandardActions
[] = {
295 { szAllocateRegistrySpace
, NULL
},
296 { szAppSearch
, ACTION_AppSearch
},
297 { szBindImage
, NULL
},
298 { szCCPSearch
, NULL
},
299 { szCostFinalize
, ACTION_CostFinalize
},
300 { szCostInitialize
, ACTION_CostInitialize
},
301 { szCreateFolders
, ACTION_CreateFolders
},
302 { szCreateShortcuts
, ACTION_CreateShortcuts
},
303 { szDeleteServices
, NULL
},
304 { szDisableRollback
, NULL
},
305 { szDuplicateFiles
, ACTION_DuplicateFiles
},
306 { szExecuteAction
, ACTION_ExecuteAction
},
307 { szFileCost
, ACTION_FileCost
},
308 { szFindRelatedProducts
, NULL
},
309 { szForceReboot
, ACTION_ForceReboot
},
310 { szInstallAdminPackage
, NULL
},
311 { szInstallExecute
, ACTION_InstallExecute
},
312 { szInstallExecuteAgain
, ACTION_InstallExecute
},
313 { szInstallFiles
, ACTION_InstallFiles
},
314 { szInstallFinalize
, ACTION_InstallFinalize
},
315 { szInstallInitialize
, ACTION_InstallInitialize
},
316 { szInstallSFPCatalogFile
, NULL
},
317 { szInstallValidate
, ACTION_InstallValidate
},
318 { szIsolateComponents
, NULL
},
319 { szLaunchConditions
, ACTION_LaunchConditions
},
320 { szMigrateFeatureStates
, NULL
},
321 { szMoveFiles
, NULL
},
322 { szMsiPublishAssemblies
, NULL
},
323 { szMsiUnpublishAssemblies
, NULL
},
324 { szInstallODBC
, NULL
},
325 { szInstallServices
, NULL
},
326 { szPatchFiles
, NULL
},
327 { szProcessComponents
, ACTION_ProcessComponents
},
328 { szPublishComponents
, ACTION_PublishComponents
},
329 { szPublishFeatures
, ACTION_PublishFeatures
},
330 { szPublishProduct
, ACTION_PublishProduct
},
331 { szRegisterClassInfo
, ACTION_RegisterClassInfo
},
332 { szRegisterComPlus
, NULL
},
333 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
},
334 { szRegisterFonts
, ACTION_RegisterFonts
},
335 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
},
336 { szRegisterProduct
, ACTION_RegisterProduct
},
337 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
},
338 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
},
339 { szRegisterUser
, ACTION_RegisterUser
},
340 { szRemoveDuplicateFiles
, NULL
},
341 { szRemoveEnvironmentStrings
, NULL
},
342 { szRemoveExistingProducts
, NULL
},
343 { szRemoveFiles
, NULL
},
344 { szRemoveFolders
, NULL
},
345 { szRemoveIniValues
, NULL
},
346 { szRemoveODBC
, NULL
},
347 { szRemoveRegistryValues
, NULL
},
348 { szRemoveShortcuts
, NULL
},
349 { szResolveSource
, ACTION_ResolveSource
},
350 { szRMCCPSearch
, NULL
},
351 { szScheduleReboot
, NULL
},
352 { szSelfRegModules
, ACTION_SelfRegModules
},
353 { szSelfUnregModules
, NULL
},
354 { szSetODBCFolders
, NULL
},
355 { szStartServices
, NULL
},
356 { szStopServices
, NULL
},
357 { szUnpublishComponents
, NULL
},
358 { szUnpublishFeatures
, NULL
},
359 { szUnregisterClassInfo
, NULL
},
360 { szUnregisterComPlus
, NULL
},
361 { szUnregisterExtensionInfo
, NULL
},
362 { szUnregisterFonts
, NULL
},
363 { szUnregisterMIMEInfo
, NULL
},
364 { szUnregisterProgIdInfo
, NULL
},
365 { szUnregisterTypeLibraries
, NULL
},
366 { szValidateProductID
, NULL
},
367 { szWriteEnvironmentStrings
, NULL
},
368 { szWriteIniValues
, ACTION_WriteIniValues
},
369 { szWriteRegistryValues
, ACTION_WriteRegistryValues
},
374 /********************************************************
375 * helper functions to get around current HACKS and such
376 ********************************************************/
377 inline static void reduce_to_longfilename(WCHAR
* filename
)
379 LPWSTR p
= strchrW(filename
,'|');
381 memmove(filename
, p
+1, (strlenW(p
+1)+1)*sizeof(WCHAR
));
384 inline static void reduce_to_shortfilename(WCHAR
* filename
)
386 LPWSTR p
= strchrW(filename
,'|');
391 WCHAR
*load_dynamic_stringW(MSIRECORD
*row
, INT index
)
398 if (MSI_RecordIsNull(row
,index
))
401 rc
= MSI_RecordGetStringW(row
,index
,NULL
,&sz
);
403 /* having an empty string is different than NULL */
406 ret
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
));
412 ret
= HeapAlloc(GetProcessHeap(),0,sz
* sizeof (WCHAR
));
413 rc
= MSI_RecordGetStringW(row
,index
,ret
,&sz
);
414 if (rc
!=ERROR_SUCCESS
)
416 ERR("Unable to load dynamic string\n");
417 HeapFree(GetProcessHeap(), 0, ret
);
423 LPWSTR
load_dynamic_property(MSIPACKAGE
*package
, LPCWSTR prop
, UINT
* rc
)
429 r
= MSI_GetPropertyW(package
, prop
, NULL
, &sz
);
430 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
437 str
= HeapAlloc(GetProcessHeap(),0,sz
*sizeof(WCHAR
));
438 r
= MSI_GetPropertyW(package
, prop
, str
, &sz
);
439 if (r
!= ERROR_SUCCESS
)
441 HeapFree(GetProcessHeap(),0,str
);
449 int get_loaded_component(MSIPACKAGE
* package
, LPCWSTR Component
)
454 for (i
= 0; i
< package
->loaded_components
; i
++)
456 if (strcmpW(Component
,package
->components
[i
].Component
)==0)
465 int get_loaded_feature(MSIPACKAGE
* package
, LPCWSTR Feature
)
470 for (i
= 0; i
< package
->loaded_features
; i
++)
472 if (strcmpW(Feature
,package
->features
[i
].Feature
)==0)
481 int get_loaded_file(MSIPACKAGE
* package
, LPCWSTR file
)
486 for (i
= 0; i
< package
->loaded_files
; i
++)
488 if (strcmpW(file
,package
->files
[i
].File
)==0)
497 int track_tempfile(MSIPACKAGE
*package
, LPCWSTR name
, LPCWSTR path
)
505 for (i
=0; i
< package
->loaded_files
; i
++)
506 if (strcmpW(package
->files
[i
].File
,name
)==0)
509 index
= package
->loaded_files
;
510 package
->loaded_files
++;
511 if (package
->loaded_files
== 1)
512 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
514 package
->files
= HeapReAlloc(GetProcessHeap(),0,
515 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
517 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
519 package
->files
[index
].File
= strdupW(name
);
520 package
->files
[index
].TargetPath
= strdupW(path
);
521 package
->files
[index
].Temporary
= TRUE
;
523 TRACE("Tracking tempfile (%s)\n",debugstr_w(package
->files
[index
].File
));
528 static void remove_tracked_tempfiles(MSIPACKAGE
* package
)
535 for (i
= 0; i
< package
->loaded_files
; i
++)
537 if (package
->files
[i
].Temporary
)
539 TRACE("Cleaning up %s\n",debugstr_w(package
->files
[i
].TargetPath
));
540 DeleteFileW(package
->files
[i
].TargetPath
);
546 /* wrapper to resist a need for a full rewrite right now */
547 DWORD
deformat_string(MSIPACKAGE
*package
, LPCWSTR ptr
, WCHAR
** data
)
551 MSIRECORD
*rec
= MSI_CreateRecord(1);
554 MSI_RecordSetStringW(rec
,0,ptr
);
555 MSI_FormatRecordW(package
,rec
,NULL
,&size
);
559 *data
= HeapAlloc(GetProcessHeap(),0,size
*sizeof(WCHAR
));
561 MSI_FormatRecordW(package
,rec
,*data
,&size
);
564 msiobj_release( &rec
->hdr
);
565 return sizeof(WCHAR
)*size
;
567 msiobj_release( &rec
->hdr
);
574 /* Called when the package is being closed */
575 void ACTION_free_package_structures( MSIPACKAGE
* package
)
579 TRACE("Freeing package action data\n");
581 remove_tracked_tempfiles(package
);
583 /* No dynamic buffers in features */
584 if (package
->features
&& package
->loaded_features
> 0)
585 HeapFree(GetProcessHeap(),0,package
->features
);
587 for (i
= 0; i
< package
->loaded_folders
; i
++)
589 HeapFree(GetProcessHeap(),0,package
->folders
[i
].Directory
);
590 HeapFree(GetProcessHeap(),0,package
->folders
[i
].TargetDefault
);
591 HeapFree(GetProcessHeap(),0,package
->folders
[i
].SourceDefault
);
592 HeapFree(GetProcessHeap(),0,package
->folders
[i
].ResolvedTarget
);
593 HeapFree(GetProcessHeap(),0,package
->folders
[i
].ResolvedSource
);
594 HeapFree(GetProcessHeap(),0,package
->folders
[i
].Property
);
596 if (package
->folders
&& package
->loaded_folders
> 0)
597 HeapFree(GetProcessHeap(),0,package
->folders
);
599 for (i
= 0; i
< package
->loaded_components
; i
++)
600 HeapFree(GetProcessHeap(),0,package
->components
[i
].FullKeypath
);
602 if (package
->components
&& package
->loaded_components
> 0)
603 HeapFree(GetProcessHeap(),0,package
->components
);
605 for (i
= 0; i
< package
->loaded_files
; i
++)
607 HeapFree(GetProcessHeap(),0,package
->files
[i
].File
);
608 HeapFree(GetProcessHeap(),0,package
->files
[i
].FileName
);
609 HeapFree(GetProcessHeap(),0,package
->files
[i
].ShortName
);
610 HeapFree(GetProcessHeap(),0,package
->files
[i
].Version
);
611 HeapFree(GetProcessHeap(),0,package
->files
[i
].Language
);
612 HeapFree(GetProcessHeap(),0,package
->files
[i
].SourcePath
);
613 HeapFree(GetProcessHeap(),0,package
->files
[i
].TargetPath
);
616 if (package
->files
&& package
->loaded_files
> 0)
617 HeapFree(GetProcessHeap(),0,package
->files
);
619 /* clean up extension, progid, class and verb structures */
620 for (i
= 0; i
< package
->loaded_classes
; i
++)
622 HeapFree(GetProcessHeap(),0,package
->classes
[i
].Description
);
623 HeapFree(GetProcessHeap(),0,package
->classes
[i
].FileTypeMask
);
624 HeapFree(GetProcessHeap(),0,package
->classes
[i
].IconPath
);
625 HeapFree(GetProcessHeap(),0,package
->classes
[i
].DefInprocHandler
);
626 HeapFree(GetProcessHeap(),0,package
->classes
[i
].DefInprocHandler32
);
627 HeapFree(GetProcessHeap(),0,package
->classes
[i
].Argument
);
628 HeapFree(GetProcessHeap(),0,package
->classes
[i
].ProgIDText
);
631 if (package
->classes
&& package
->loaded_classes
> 0)
632 HeapFree(GetProcessHeap(),0,package
->classes
);
634 for (i
= 0; i
< package
->loaded_extensions
; i
++)
636 HeapFree(GetProcessHeap(),0,package
->extensions
[i
].ProgIDText
);
639 if (package
->extensions
&& package
->loaded_extensions
> 0)
640 HeapFree(GetProcessHeap(),0,package
->extensions
);
642 for (i
= 0; i
< package
->loaded_progids
; i
++)
644 HeapFree(GetProcessHeap(),0,package
->progids
[i
].ProgID
);
645 HeapFree(GetProcessHeap(),0,package
->progids
[i
].Description
);
646 HeapFree(GetProcessHeap(),0,package
->progids
[i
].IconPath
);
649 if (package
->progids
&& package
->loaded_progids
> 0)
650 HeapFree(GetProcessHeap(),0,package
->progids
);
652 for (i
= 0; i
< package
->loaded_verbs
; i
++)
654 HeapFree(GetProcessHeap(),0,package
->verbs
[i
].Verb
);
655 HeapFree(GetProcessHeap(),0,package
->verbs
[i
].Command
);
656 HeapFree(GetProcessHeap(),0,package
->verbs
[i
].Argument
);
659 if (package
->verbs
&& package
->loaded_verbs
> 0)
660 HeapFree(GetProcessHeap(),0,package
->verbs
);
662 for (i
= 0; i
< package
->loaded_mimes
; i
++)
663 HeapFree(GetProcessHeap(),0,package
->mimes
[i
].ContentType
);
665 if (package
->mimes
&& package
->loaded_mimes
> 0)
666 HeapFree(GetProcessHeap(),0,package
->mimes
);
668 for (i
= 0; i
< package
->loaded_appids
; i
++)
670 HeapFree(GetProcessHeap(),0,package
->appids
[i
].RemoteServerName
);
671 HeapFree(GetProcessHeap(),0,package
->appids
[i
].LocalServer
);
672 HeapFree(GetProcessHeap(),0,package
->appids
[i
].ServiceParameters
);
673 HeapFree(GetProcessHeap(),0,package
->appids
[i
].DllSurrogate
);
676 if (package
->appids
&& package
->loaded_appids
> 0)
677 HeapFree(GetProcessHeap(),0,package
->appids
);
681 for (i
= 0; i
< TOTAL_SCRIPTS
; i
++)
684 for (j
= 0; j
< package
->script
->ActionCount
[i
]; j
++)
685 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[i
][j
]);
687 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[i
]);
689 HeapFree(GetProcessHeap(),0,package
->script
);
692 HeapFree(GetProcessHeap(),0,package
->PackagePath
);
694 /* cleanup control event subscriptions */
695 ControlEvent_CleanupSubscriptions(package
);
698 static void ce_actiontext(MSIPACKAGE
* package
, LPCWSTR action
)
700 static const WCHAR szActionText
[] =
701 {'A','c','t','i','o','n','T','e','x','t',0};
704 row
= MSI_CreateRecord(1);
705 MSI_RecordSetStringW(row
,1,action
);
706 ControlEvent_FireSubscribedEvent(package
,szActionText
, row
);
707 msiobj_release(&row
->hdr
);
710 static void ui_progress(MSIPACKAGE
*package
, int a
, int b
, int c
, int d
)
714 row
= MSI_CreateRecord(4);
715 MSI_RecordSetInteger(row
,1,a
);
716 MSI_RecordSetInteger(row
,2,b
);
717 MSI_RecordSetInteger(row
,3,c
);
718 MSI_RecordSetInteger(row
,4,d
);
719 MSI_ProcessMessage(package
, INSTALLMESSAGE_PROGRESS
, row
);
720 msiobj_release(&row
->hdr
);
722 msi_dialog_check_messages(NULL
);
725 static void ui_actiondata(MSIPACKAGE
*package
, LPCWSTR action
, MSIRECORD
* record
)
727 static const WCHAR Query_t
[] =
728 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
729 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
730 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
731 ' ','\'','%','s','\'',0};
735 static const WCHAR szActionData
[] =
736 {'A','c','t','i','o','n','D','a','t','a',0};
738 if (!package
->LastAction
|| strcmpW(package
->LastAction
,action
))
740 row
= MSI_QueryGetRecord(package
->db
, Query_t
, action
);
744 if (MSI_RecordIsNull(row
,3))
746 msiobj_release(&row
->hdr
);
750 /* update the cached actionformat */
751 HeapFree(GetProcessHeap(),0,package
->ActionFormat
);
752 package
->ActionFormat
= load_dynamic_stringW(row
,3);
754 HeapFree(GetProcessHeap(),0,package
->LastAction
);
755 package
->LastAction
= strdupW(action
);
757 msiobj_release(&row
->hdr
);
760 MSI_RecordSetStringW(record
,0,package
->ActionFormat
);
762 MSI_FormatRecordW(package
,record
,message
,&size
);
764 row
= MSI_CreateRecord(1);
765 MSI_RecordSetStringW(row
,1,message
);
767 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
769 ControlEvent_FireSubscribedEvent(package
,szActionData
, row
);
771 msiobj_release(&row
->hdr
);
775 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
777 static const WCHAR template_s
[]=
778 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
780 static const WCHAR format
[] =
781 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
782 static const WCHAR Query_t
[] =
783 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
784 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
785 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
786 ' ','\'','%','s','\'',0};
790 WCHAR
*ActionText
=NULL
;
792 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
794 row
= MSI_QueryGetRecord( package
->db
, Query_t
, action
);
798 ActionText
= load_dynamic_stringW(row
,2);
799 msiobj_release(&row
->hdr
);
801 sprintfW(message
,template_s
,timet
,action
,ActionText
);
803 row
= MSI_CreateRecord(1);
804 MSI_RecordSetStringW(row
,1,message
);
806 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
807 msiobj_release(&row
->hdr
);
808 HeapFree(GetProcessHeap(),0,ActionText
);
811 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
815 static const WCHAR template_s
[]=
816 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
818 static const WCHAR template_e
[]=
819 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
820 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
822 static const WCHAR format
[] =
823 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
827 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
829 sprintfW(message
,template_s
,timet
,action
);
831 sprintfW(message
,template_e
,timet
,action
,rc
);
833 row
= MSI_CreateRecord(1);
834 MSI_RecordSetStringW(row
,1,message
);
836 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
837 msiobj_release(&row
->hdr
);
841 * build_directory_name()
843 * This function is to save messing round with directory names
844 * It handles adding backslashes between path segments,
845 * and can add \ at the end of the directory name if told to.
847 * It takes a variable number of arguments.
848 * It always allocates a new string for the result, so make sure
849 * to free the return value when finished with it.
851 * The first arg is the number of path segments that follow.
852 * The arguments following count are a list of path segments.
853 * A path segment may be NULL.
855 * Path segments will be added with a \ separating them.
856 * A \ will not be added after the last segment, however if the
857 * last segment is NULL, then the last character will be a \
860 static LPWSTR
build_directory_name(DWORD count
, ...)
867 for(i
=0; i
<count
; i
++)
869 LPCWSTR str
= va_arg(va
,LPCWSTR
);
871 sz
+= strlenW(str
) + 1;
875 dir
= HeapAlloc(GetProcessHeap(), 0, sz
*sizeof(WCHAR
));
879 for(i
=0; i
<count
; i
++)
881 LPCWSTR str
= va_arg(va
,LPCWSTR
);
885 if( ((i
+1)!=count
) && dir
[strlenW(dir
)-1]!='\\')
891 static BOOL
ACTION_VerifyComponentForAction(MSIPACKAGE
* package
, INT index
,
894 if (package
->components
[index
].Installed
== check
)
897 if (package
->components
[index
].ActionRequest
== check
)
903 static BOOL
ACTION_VerifyFeatureForAction(MSIPACKAGE
* package
, INT index
,
906 if (package
->features
[index
].Installed
== check
)
909 if (package
->features
[index
].ActionRequest
== check
)
916 /****************************************************
917 * TOP level entry points
918 *****************************************************/
920 UINT
ACTION_DoTopLevelINSTALL(MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
921 LPCWSTR szCommandLine
)
927 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
928 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
929 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
931 MSI_SetPropertyW(package
, szAction
, szInstall
);
933 package
->script
= HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT
));
934 memset(package
->script
,0,sizeof(MSISCRIPT
));
938 LPWSTR p
, check
, path
;
940 package
->PackagePath
= strdupW(szPackagePath
);
941 path
= strdupW(szPackagePath
);
942 p
= strrchrW(path
,'\\');
950 HeapFree(GetProcessHeap(),0,path
);
951 path
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
*sizeof(WCHAR
));
952 GetCurrentDirectoryW(MAX_PATH
,path
);
956 check
= load_dynamic_property(package
, cszSourceDir
,NULL
);
958 MSI_SetPropertyW(package
, cszSourceDir
, path
);
960 HeapFree(GetProcessHeap(), 0, check
);
962 HeapFree(GetProcessHeap(), 0, path
);
968 ptr
= (LPWSTR
)szCommandLine
;
975 TRACE("Looking at %s\n",debugstr_w(ptr
));
977 ptr2
= strchrW(ptr
,'=');
983 while (*ptr
== ' ') ptr
++;
985 prop
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
986 memcpy(prop
,ptr
,len
*sizeof(WCHAR
));
992 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
1005 val
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
1006 memcpy(val
,ptr2
,len
*sizeof(WCHAR
));
1009 if (strlenW(prop
) > 0)
1011 TRACE("Found commandline property (%s) = (%s)\n",
1012 debugstr_w(prop
), debugstr_w(val
));
1013 MSI_SetPropertyW(package
,prop
,val
);
1015 HeapFree(GetProcessHeap(),0,val
);
1016 HeapFree(GetProcessHeap(),0,prop
);
1023 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
1025 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
1027 rc
= ACTION_ProcessUISequence(package
);
1029 if (rc
== ERROR_SUCCESS
)
1030 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
1033 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
1036 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
1040 /* install was halted but should be considered a success */
1044 package
->script
->CurrentlyScripting
= FALSE
;
1046 /* process the ending type action */
1047 if (rc
== ERROR_SUCCESS
)
1048 ACTION_PerformActionSequence(package
,-1,ui
);
1049 else if (rc
== ERROR_INSTALL_USEREXIT
)
1050 ACTION_PerformActionSequence(package
,-2,ui
);
1051 else if (rc
== ERROR_INSTALL_SUSPEND
)
1052 ACTION_PerformActionSequence(package
,-4,ui
);
1054 ACTION_PerformActionSequence(package
,-3,ui
);
1056 /* finish up running custom actions */
1057 ACTION_FinishCustomActions(package
);
1062 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
, BOOL UI
)
1064 UINT rc
= ERROR_SUCCESS
;
1065 WCHAR buffer
[0x100];
1067 MSIRECORD
* row
= 0;
1068 static const WCHAR ExecSeqQuery
[] =
1069 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1070 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1071 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1072 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
1074 static const WCHAR UISeqQuery
[] =
1075 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1076 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1077 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
1078 ' ', '=',' ','%','i',0};
1081 row
= MSI_QueryGetRecord(package
->db
, UISeqQuery
, seq
);
1083 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, seq
);
1087 TRACE("Running the actions\n");
1089 /* check conditions */
1090 if (!MSI_RecordIsNull(row
,2))
1093 cond
= load_dynamic_stringW(row
,2);
1097 /* this is a hack to skip errors in the condition code */
1098 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
1100 HeapFree(GetProcessHeap(),0,cond
);
1104 HeapFree(GetProcessHeap(),0,cond
);
1109 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
1110 if (rc
!= ERROR_SUCCESS
)
1112 ERR("Error is %x\n",rc
);
1113 msiobj_release(&row
->hdr
);
1118 rc
= ACTION_PerformUIAction(package
,buffer
);
1120 rc
= ACTION_PerformAction(package
,buffer
, FALSE
);
1122 msiobj_release(&row
->hdr
);
1130 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
1134 static const WCHAR ExecSeqQuery
[] =
1135 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1136 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1137 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1138 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
1139 'O','R','D','E','R',' ', 'B','Y',' ',
1140 '`','S','e','q','u','e','n','c','e','`',0 };
1141 MSIRECORD
* row
= 0;
1142 static const WCHAR IVQuery
[] =
1143 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
1144 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
1145 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
1146 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
1147 ' ','\'', 'I','n','s','t','a','l','l',
1148 'V','a','l','i','d','a','t','e','\'', 0};
1152 if (package
->script
->ExecuteSequenceRun
)
1154 TRACE("Execute Sequence already Run\n");
1155 return ERROR_SUCCESS
;
1158 package
->script
->ExecuteSequenceRun
= TRUE
;
1160 /* get the sequence number */
1163 row
= MSI_QueryGetRecord(package
->db
, IVQuery
);
1165 return ERROR_FUNCTION_FAILED
;
1166 seq
= MSI_RecordGetInteger(row
,1);
1167 msiobj_release(&row
->hdr
);
1170 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
1171 if (rc
== ERROR_SUCCESS
)
1173 rc
= MSI_ViewExecute(view
, 0);
1175 if (rc
!= ERROR_SUCCESS
)
1177 MSI_ViewClose(view
);
1178 msiobj_release(&view
->hdr
);
1182 TRACE("Running the actions\n");
1186 WCHAR buffer
[0x100];
1189 rc
= MSI_ViewFetch(view
,&row
);
1190 if (rc
!= ERROR_SUCCESS
)
1197 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
1198 if (rc
!= ERROR_SUCCESS
)
1200 ERR("Error is %x\n",rc
);
1201 msiobj_release(&row
->hdr
);
1205 /* check conditions */
1206 if (!MSI_RecordIsNull(row
,2))
1209 cond
= load_dynamic_stringW(row
,2);
1213 /* this is a hack to skip errors in the condition code */
1214 if (MSI_EvaluateConditionW(package
, cond
) ==
1217 HeapFree(GetProcessHeap(),0,cond
);
1218 msiobj_release(&row
->hdr
);
1219 TRACE("Skipping action: %s (condition is false)\n",
1220 debugstr_w(buffer
));
1224 HeapFree(GetProcessHeap(),0,cond
);
1228 rc
= ACTION_PerformAction(package
,buffer
, FALSE
);
1230 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
1233 if (rc
!= ERROR_SUCCESS
)
1235 ERR("Execution halted due to error (%i)\n",rc
);
1236 msiobj_release(&row
->hdr
);
1240 msiobj_release(&row
->hdr
);
1243 MSI_ViewClose(view
);
1244 msiobj_release(&view
->hdr
);
1252 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
1256 static const WCHAR ExecSeqQuery
[] =
1257 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1258 '`','I','n','s','t','a','l','l',
1259 'U','I','S','e','q','u','e','n','c','e','`',
1260 ' ','W','H','E','R','E',' ',
1261 '`','S','e','q','u','e','n','c','e','`',' ',
1262 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1263 '`','S','e','q','u','e','n','c','e','`',0};
1265 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1267 if (rc
== ERROR_SUCCESS
)
1269 rc
= MSI_ViewExecute(view
, 0);
1271 if (rc
!= ERROR_SUCCESS
)
1273 MSI_ViewClose(view
);
1274 msiobj_release(&view
->hdr
);
1278 TRACE("Running the actions \n");
1282 WCHAR buffer
[0x100];
1284 MSIRECORD
* row
= 0;
1286 rc
= MSI_ViewFetch(view
,&row
);
1287 if (rc
!= ERROR_SUCCESS
)
1294 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
1295 if (rc
!= ERROR_SUCCESS
)
1297 ERR("Error is %x\n",rc
);
1298 msiobj_release(&row
->hdr
);
1303 /* check conditions */
1304 if (!MSI_RecordIsNull(row
,2))
1307 cond
= load_dynamic_stringW(row
,2);
1311 /* this is a hack to skip errors in the condition code */
1312 if (MSI_EvaluateConditionW(package
, cond
) ==
1315 HeapFree(GetProcessHeap(),0,cond
);
1316 msiobj_release(&row
->hdr
);
1317 TRACE("Skipping action: %s (condition is false)\n",
1318 debugstr_w(buffer
));
1322 HeapFree(GetProcessHeap(),0,cond
);
1326 rc
= ACTION_PerformUIAction(package
,buffer
);
1328 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
1331 if (rc
!= ERROR_SUCCESS
)
1333 ERR("Execution halted due to error (%i)\n",rc
);
1334 msiobj_release(&row
->hdr
);
1338 msiobj_release(&row
->hdr
);
1341 MSI_ViewClose(view
);
1342 msiobj_release(&view
->hdr
);
1349 /********************************************************
1350 * ACTION helper functions and functions that perform the actions
1351 *******************************************************/
1352 static BOOL
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
,
1353 UINT
* rc
, BOOL force
)
1359 if (!run
&& !package
->script
->CurrentlyScripting
)
1364 if (strcmpW(action
,szInstallFinalize
) == 0 ||
1365 strcmpW(action
,szInstallExecute
) == 0 ||
1366 strcmpW(action
,szInstallExecuteAgain
) == 0)
1371 while (StandardActions
[i
].action
!= NULL
)
1373 if (strcmpW(StandardActions
[i
].action
, action
)==0)
1375 ce_actiontext(package
, action
);
1378 ui_actioninfo(package
, action
, TRUE
, 0);
1379 *rc
= schedule_action(package
,INSTALL_SCRIPT
,action
);
1380 ui_actioninfo(package
, action
, FALSE
, *rc
);
1384 ui_actionstart(package
, action
);
1385 if (StandardActions
[i
].handler
)
1387 *rc
= StandardActions
[i
].handler(package
);
1391 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action
));
1392 *rc
= ERROR_SUCCESS
;
1403 BOOL
ACTION_HandleDialogBox(MSIPACKAGE
*package
, LPCWSTR dialog
, UINT
* rc
)
1407 if (ACTION_DialogBox(package
,dialog
) == ERROR_SUCCESS
)
1409 *rc
= package
->CurrentInstallState
;
1415 BOOL
ACTION_HandleCustomAction(MSIPACKAGE
* package
, LPCWSTR action
, UINT
* rc
,
1421 arc
= ACTION_CustomAction(package
,action
, force
);
1423 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
1432 * A lot of actions are really important even if they don't do anything
1433 * explicit... Lots of properties are set at the beginning of the installation
1434 * CostFinalize does a bunch of work to translate the directories and such
1436 * But until I get write access to the database that is hard, so I am going to
1437 * hack it to see if I can get something to run.
1439 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, BOOL force
)
1441 UINT rc
= ERROR_SUCCESS
;
1444 TRACE("Performing action (%s)\n",debugstr_w(action
));
1446 handled
= ACTION_HandleStandardAction(package
, action
, &rc
, force
);
1449 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, force
);
1453 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
1454 rc
= ERROR_FUNCTION_NOT_CALLED
;
1457 package
->CurrentInstallState
= rc
;
1461 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
)
1463 UINT rc
= ERROR_SUCCESS
;
1464 BOOL handled
= FALSE
;
1466 TRACE("Performing action (%s)\n",debugstr_w(action
));
1468 handled
= ACTION_HandleStandardAction(package
, action
, &rc
,TRUE
);
1471 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, FALSE
);
1474 handled
= ACTION_HandleDialogBox(package
, action
, &rc
);
1476 msi_dialog_check_messages( NULL
);
1480 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
1481 rc
= ERROR_FUNCTION_NOT_CALLED
;
1484 package
->CurrentInstallState
= rc
;
1488 /***********************************************************************
1491 * Recursively create all directories in the path.
1493 * shamelessly stolen from setupapi/queue.c
1495 static BOOL
create_full_pathW(const WCHAR
*path
)
1501 new_path
= HeapAlloc(GetProcessHeap(), 0, (strlenW(path
) + 1) *
1504 strcpyW(new_path
, path
);
1506 while((len
= strlenW(new_path
)) && new_path
[len
- 1] == '\\')
1507 new_path
[len
- 1] = 0;
1509 while(!CreateDirectoryW(new_path
, NULL
))
1512 DWORD last_error
= GetLastError();
1513 if(last_error
== ERROR_ALREADY_EXISTS
)
1516 if(last_error
!= ERROR_PATH_NOT_FOUND
)
1522 if(!(slash
= strrchrW(new_path
, '\\')))
1528 len
= slash
- new_path
;
1530 if(!create_full_pathW(new_path
))
1535 new_path
[len
] = '\\';
1538 HeapFree(GetProcessHeap(), 0, new_path
);
1543 * Also we cannot enable/disable components either, so for now I am just going
1544 * to do all the directories for all the components.
1546 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
1548 static const WCHAR ExecSeqQuery
[] =
1549 {'S','E','L','E','C','T',' ',
1550 '`','D','i','r','e','c','t','o','r','y','_','`',
1551 ' ','F','R','O','M',' ',
1552 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
1557 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1558 if (rc
!= ERROR_SUCCESS
)
1559 return ERROR_SUCCESS
;
1561 rc
= MSI_ViewExecute(view
, 0);
1562 if (rc
!= ERROR_SUCCESS
)
1564 MSI_ViewClose(view
);
1565 msiobj_release(&view
->hdr
);
1574 MSIRECORD
*row
= NULL
, *uirow
;
1576 rc
= MSI_ViewFetch(view
,&row
);
1577 if (rc
!= ERROR_SUCCESS
)
1584 rc
= MSI_RecordGetStringW(row
,1,dir
,&sz
);
1586 if (rc
!= ERROR_SUCCESS
)
1588 ERR("Unable to get folder id \n");
1589 msiobj_release(&row
->hdr
);
1594 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,&folder
);
1597 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
1598 msiobj_release(&row
->hdr
);
1602 TRACE("Folder is %s\n",debugstr_w(full_path
));
1605 uirow
= MSI_CreateRecord(1);
1606 MSI_RecordSetStringW(uirow
,1,full_path
);
1607 ui_actiondata(package
,szCreateFolders
,uirow
);
1608 msiobj_release( &uirow
->hdr
);
1610 if (folder
->State
== 0)
1611 create_full_pathW(full_path
);
1615 msiobj_release(&row
->hdr
);
1616 HeapFree(GetProcessHeap(),0,full_path
);
1618 MSI_ViewClose(view
);
1619 msiobj_release(&view
->hdr
);
1624 static int load_component(MSIPACKAGE
* package
, MSIRECORD
* row
)
1626 int index
= package
->loaded_components
;
1629 /* fill in the data */
1631 package
->loaded_components
++;
1632 if (package
->loaded_components
== 1)
1633 package
->components
= HeapAlloc(GetProcessHeap(),0,
1634 sizeof(MSICOMPONENT
));
1636 package
->components
= HeapReAlloc(GetProcessHeap(),0,
1637 package
->components
, package
->loaded_components
*
1638 sizeof(MSICOMPONENT
));
1640 memset(&package
->components
[index
],0,sizeof(MSICOMPONENT
));
1642 sz
= IDENTIFIER_SIZE
;
1643 MSI_RecordGetStringW(row
,1,package
->components
[index
].Component
,&sz
);
1645 TRACE("Loading Component %s\n",
1646 debugstr_w(package
->components
[index
].Component
));
1649 if (!MSI_RecordIsNull(row
,2))
1650 MSI_RecordGetStringW(row
,2,package
->components
[index
].ComponentId
,&sz
);
1652 sz
= IDENTIFIER_SIZE
;
1653 MSI_RecordGetStringW(row
,3,package
->components
[index
].Directory
,&sz
);
1655 package
->components
[index
].Attributes
= MSI_RecordGetInteger(row
,4);
1658 MSI_RecordGetStringW(row
,5,package
->components
[index
].Condition
,&sz
);
1660 sz
= IDENTIFIER_SIZE
;
1661 MSI_RecordGetStringW(row
,6,package
->components
[index
].KeyPath
,&sz
);
1663 package
->components
[index
].Installed
= INSTALLSTATE_ABSENT
;
1664 package
->components
[index
].Action
= INSTALLSTATE_UNKNOWN
;
1665 package
->components
[index
].ActionRequest
= INSTALLSTATE_UNKNOWN
;
1667 package
->components
[index
].Enabled
= TRUE
;
1672 static void load_feature(MSIPACKAGE
* package
, MSIRECORD
* row
)
1674 int index
= package
->loaded_features
;
1676 static const WCHAR Query1
[] =
1677 {'S','E','L','E','C','T',' ',
1678 '`','C','o','m','p','o','n','e','n','t','_','`',
1679 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1680 'C','o','m','p','o','n','e','n','t','s','`',' ',
1681 'W','H','E','R','E',' ',
1682 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1683 static const WCHAR Query2
[] =
1684 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1685 '`','C','o','m','p','o','n','e','n','t','`',' ',
1686 'W','H','E','R','E',' ',
1687 '`','C','o','m','p','o','n','e','n','t','`',' ',
1688 '=','\'','%','s','\'',0};
1695 /* fill in the data */
1697 package
->loaded_features
++;
1698 if (package
->loaded_features
== 1)
1699 package
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE
));
1701 package
->features
= HeapReAlloc(GetProcessHeap(),0,package
->features
,
1702 package
->loaded_features
* sizeof(MSIFEATURE
));
1704 memset(&package
->features
[index
],0,sizeof(MSIFEATURE
));
1706 sz
= IDENTIFIER_SIZE
;
1707 MSI_RecordGetStringW(row
,1,package
->features
[index
].Feature
,&sz
);
1709 TRACE("Loading feature %s\n",debugstr_w(package
->features
[index
].Feature
));
1711 sz
= IDENTIFIER_SIZE
;
1712 if (!MSI_RecordIsNull(row
,2))
1713 MSI_RecordGetStringW(row
,2,package
->features
[index
].Feature_Parent
,&sz
);
1716 if (!MSI_RecordIsNull(row
,3))
1717 MSI_RecordGetStringW(row
,3,package
->features
[index
].Title
,&sz
);
1720 if (!MSI_RecordIsNull(row
,4))
1721 MSI_RecordGetStringW(row
,4,package
->features
[index
].Description
,&sz
);
1723 if (!MSI_RecordIsNull(row
,5))
1724 package
->features
[index
].Display
= MSI_RecordGetInteger(row
,5);
1726 package
->features
[index
].Level
= MSI_RecordGetInteger(row
,6);
1728 sz
= IDENTIFIER_SIZE
;
1729 if (!MSI_RecordIsNull(row
,7))
1730 MSI_RecordGetStringW(row
,7,package
->features
[index
].Directory
,&sz
);
1732 package
->features
[index
].Attributes
= MSI_RecordGetInteger(row
,8);
1734 package
->features
[index
].Installed
= INSTALLSTATE_ABSENT
;
1735 package
->features
[index
].Action
= INSTALLSTATE_UNKNOWN
;
1736 package
->features
[index
].ActionRequest
= INSTALLSTATE_UNKNOWN
;
1738 /* load feature components */
1740 rc
= MSI_OpenQuery(package
->db
, &view
, Query1
, package
->features
[index
].Feature
);
1741 if (rc
!= ERROR_SUCCESS
)
1743 rc
= MSI_ViewExecute(view
,0);
1744 if (rc
!= ERROR_SUCCESS
)
1746 MSI_ViewClose(view
);
1747 msiobj_release(&view
->hdr
);
1753 WCHAR buffer
[0x100];
1756 INT cnt
= package
->features
[index
].ComponentCount
;
1758 rc
= MSI_ViewFetch(view
,&row2
);
1759 if (rc
!= ERROR_SUCCESS
)
1763 MSI_RecordGetStringW(row2
,1,buffer
,&sz
);
1765 /* check to see if the component is already loaded */
1766 c_indx
= get_loaded_component(package
,buffer
);
1769 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer
),
1771 package
->features
[index
].Components
[cnt
] = c_indx
;
1772 package
->features
[index
].ComponentCount
++;
1773 msiobj_release( &row2
->hdr
);
1777 rc
= MSI_OpenQuery(package
->db
, &view2
, Query2
, buffer
);
1778 if (rc
!= ERROR_SUCCESS
)
1780 msiobj_release( &row2
->hdr
);
1783 rc
= MSI_ViewExecute(view2
,0);
1784 if (rc
!= ERROR_SUCCESS
)
1786 msiobj_release( &row2
->hdr
);
1787 MSI_ViewClose(view2
);
1788 msiobj_release( &view2
->hdr
);
1795 rc
= MSI_ViewFetch(view2
,&row3
);
1796 if (rc
!= ERROR_SUCCESS
)
1798 c_indx
= load_component(package
,row3
);
1799 msiobj_release( &row3
->hdr
);
1801 package
->features
[index
].Components
[cnt
] = c_indx
;
1802 package
->features
[index
].ComponentCount
++;
1803 TRACE("Loaded new component to index %i\n",c_indx
);
1805 MSI_ViewClose(view2
);
1806 msiobj_release( &view2
->hdr
);
1807 msiobj_release( &row2
->hdr
);
1809 MSI_ViewClose(view
);
1810 msiobj_release(&view
->hdr
);
1813 static UINT
load_file(MSIPACKAGE
* package
, MSIRECORD
* row
)
1815 DWORD index
= package
->loaded_files
;
1819 /* fill in the data */
1821 package
->loaded_files
++;
1822 if (package
->loaded_files
== 1)
1823 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
1825 package
->files
= HeapReAlloc(GetProcessHeap(),0,
1826 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
1828 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
1830 package
->files
[index
].File
= load_dynamic_stringW(row
, 1);
1831 buffer
= load_dynamic_stringW(row
, 2);
1833 package
->files
[index
].ComponentIndex
= -1;
1834 for (i
= 0; i
< package
->loaded_components
; i
++)
1835 if (strcmpW(package
->components
[i
].Component
,buffer
)==0)
1837 package
->files
[index
].ComponentIndex
= i
;
1840 if (package
->files
[index
].ComponentIndex
== -1)
1841 ERR("Unfound Component %s\n",debugstr_w(buffer
));
1842 HeapFree(GetProcessHeap(), 0, buffer
);
1844 package
->files
[index
].FileName
= load_dynamic_stringW(row
,3);
1845 reduce_to_longfilename(package
->files
[index
].FileName
);
1847 package
->files
[index
].ShortName
= load_dynamic_stringW(row
,3);
1848 reduce_to_shortfilename(package
->files
[index
].ShortName
);
1850 package
->files
[index
].FileSize
= MSI_RecordGetInteger(row
,4);
1851 package
->files
[index
].Version
= load_dynamic_stringW(row
, 5);
1852 package
->files
[index
].Language
= load_dynamic_stringW(row
, 6);
1853 package
->files
[index
].Attributes
= MSI_RecordGetInteger(row
,7);
1854 package
->files
[index
].Sequence
= MSI_RecordGetInteger(row
,8);
1856 package
->files
[index
].Temporary
= FALSE
;
1857 package
->files
[index
].State
= 0;
1859 TRACE("File Loaded (%s)\n",debugstr_w(package
->files
[index
].File
));
1861 return ERROR_SUCCESS
;
1864 static UINT
load_all_files(MSIPACKAGE
*package
)
1869 static const WCHAR Query
[] =
1870 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1871 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1872 '`','S','e','q','u','e','n','c','e','`', 0};
1875 return ERROR_INVALID_HANDLE
;
1877 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1878 if (rc
!= ERROR_SUCCESS
)
1879 return ERROR_SUCCESS
;
1881 rc
= MSI_ViewExecute(view
, 0);
1882 if (rc
!= ERROR_SUCCESS
)
1884 MSI_ViewClose(view
);
1885 msiobj_release(&view
->hdr
);
1886 return ERROR_SUCCESS
;
1891 rc
= MSI_ViewFetch(view
,&row
);
1892 if (rc
!= ERROR_SUCCESS
)
1897 load_file(package
,row
);
1898 msiobj_release(&row
->hdr
);
1900 MSI_ViewClose(view
);
1901 msiobj_release(&view
->hdr
);
1903 return ERROR_SUCCESS
;
1908 * I am not doing any of the costing functionality yet.
1909 * Mostly looking at doing the Component and Feature loading
1911 * The native MSI does A LOT of modification to tables here. Mostly adding
1912 * a lot of temporary columns to the Feature and Component tables.
1914 * note: Native msi also tracks the short filename. But I am only going to
1915 * track the long ones. Also looking at this directory table
1916 * it appears that the directory table does not get the parents
1917 * resolved base on property only based on their entries in the
1920 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1925 static const WCHAR Query_all
[] =
1926 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1927 '`','F','e','a','t','u','r','e','`',0};
1928 static const WCHAR szCosting
[] =
1929 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1930 static const WCHAR szZero
[] = { '0', 0 };
1934 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
1936 return ERROR_SUCCESS
;
1938 MSI_SetPropertyW(package
, szCosting
, szZero
);
1939 MSI_SetPropertyW(package
, cszRootDrive
, c_colon
);
1941 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1942 if (rc
!= ERROR_SUCCESS
)
1944 rc
= MSI_ViewExecute(view
,0);
1945 if (rc
!= ERROR_SUCCESS
)
1947 MSI_ViewClose(view
);
1948 msiobj_release(&view
->hdr
);
1955 rc
= MSI_ViewFetch(view
,&row
);
1956 if (rc
!= ERROR_SUCCESS
)
1959 load_feature(package
,row
);
1960 msiobj_release(&row
->hdr
);
1962 MSI_ViewClose(view
);
1963 msiobj_release(&view
->hdr
);
1965 load_all_files(package
);
1967 return ERROR_SUCCESS
;
1970 UINT
schedule_action(MSIPACKAGE
*package
, UINT script
, LPCWSTR action
)
1973 LPWSTR
*newbuf
= NULL
;
1974 if (script
>= TOTAL_SCRIPTS
)
1976 FIXME("Unknown script requested %i\n",script
);
1977 return ERROR_FUNCTION_FAILED
;
1979 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action
), script
);
1981 count
= package
->script
->ActionCount
[script
];
1982 package
->script
->ActionCount
[script
]++;
1984 newbuf
= HeapReAlloc(GetProcessHeap(),0,
1985 package
->script
->Actions
[script
],
1986 package
->script
->ActionCount
[script
]* sizeof(LPWSTR
));
1988 newbuf
= HeapAlloc(GetProcessHeap(),0, sizeof(LPWSTR
));
1990 newbuf
[count
] = strdupW(action
);
1991 package
->script
->Actions
[script
] = newbuf
;
1993 return ERROR_SUCCESS
;
1996 UINT
execute_script(MSIPACKAGE
*package
, UINT script
)
1999 UINT rc
= ERROR_SUCCESS
;
2001 TRACE("Executing Script %i\n",script
);
2003 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
2006 action
= package
->script
->Actions
[script
][i
];
2007 ui_actionstart(package
, action
);
2008 TRACE("Executing Action (%s)\n",debugstr_w(action
));
2009 rc
= ACTION_PerformAction(package
, action
, TRUE
);
2010 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
][i
]);
2011 if (rc
!= ERROR_SUCCESS
)
2014 HeapFree(GetProcessHeap(),0,package
->script
->Actions
[script
]);
2016 package
->script
->ActionCount
[script
] = 0;
2017 package
->script
->Actions
[script
] = NULL
;
2021 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
2023 return ERROR_SUCCESS
;
2027 static INT
load_folder(MSIPACKAGE
*package
, const WCHAR
* dir
)
2029 static const WCHAR Query
[] =
2030 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2031 '`','D','i','r','e','c', 't','o','r','y','`',' ',
2032 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
2033 ' ','=',' ','\'','%','s','\'',
2035 LPWSTR ptargetdir
, targetdir
, parent
, srcdir
;
2036 LPWSTR shortname
= NULL
;
2037 MSIRECORD
* row
= 0;
2041 TRACE("Looking for dir %s\n",debugstr_w(dir
));
2043 for (i
= 0; i
< package
->loaded_folders
; i
++)
2045 if (strcmpW(package
->folders
[i
].Directory
,dir
)==0)
2047 TRACE(" %s retuning on index %lu\n",debugstr_w(dir
),i
);
2052 TRACE("Working to load %s\n",debugstr_w(dir
));
2054 index
= package
->loaded_folders
++;
2055 if (package
->loaded_folders
==1)
2056 package
->folders
= HeapAlloc(GetProcessHeap(),0,
2059 package
->folders
= HeapReAlloc(GetProcessHeap(),0,
2060 package
->folders
, package
->loaded_folders
*
2063 memset(&package
->folders
[index
],0,sizeof(MSIFOLDER
));
2065 package
->folders
[index
].Directory
= strdupW(dir
);
2067 row
= MSI_QueryGetRecord(package
->db
, Query
, dir
);
2071 ptargetdir
= targetdir
= load_dynamic_stringW(row
,3);
2073 /* split src and target dir */
2074 if (strchrW(targetdir
,':'))
2076 srcdir
=strchrW(targetdir
,':');
2083 /* for now only pick long filename versions */
2084 if (strchrW(targetdir
,'|'))
2086 shortname
= targetdir
;
2087 targetdir
= strchrW(targetdir
,'|');
2091 /* for the sourcedir pick the short filename */
2092 if (srcdir
&& strchrW(srcdir
,'|'))
2094 LPWSTR p
= strchrW(srcdir
,'|');
2098 /* now check for root dirs */
2099 if (targetdir
[0] == '.' && targetdir
[1] == 0)
2102 if (srcdir
&& srcdir
[0] == '.' && srcdir
[1] == 0)
2107 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir
));
2108 HeapFree(GetProcessHeap(),0, package
->folders
[index
].TargetDefault
);
2109 package
->folders
[index
].TargetDefault
= strdupW(targetdir
);
2113 package
->folders
[index
].SourceDefault
= strdupW(srcdir
);
2115 package
->folders
[index
].SourceDefault
= strdupW(shortname
);
2117 package
->folders
[index
].SourceDefault
= strdupW(targetdir
);
2118 HeapFree(GetProcessHeap(), 0, ptargetdir
);
2119 TRACE(" SourceDefault = %s\n",debugstr_w(package
->folders
[index
].SourceDefault
));
2121 parent
= load_dynamic_stringW(row
,2);
2124 i
= load_folder(package
,parent
);
2125 package
->folders
[index
].ParentIndex
= i
;
2126 TRACE("Parent is index %i... %s %s\n",
2127 package
->folders
[index
].ParentIndex
,
2128 debugstr_w(package
->folders
[package
->folders
[index
].ParentIndex
].Directory
),
2129 debugstr_w(parent
));
2132 package
->folders
[index
].ParentIndex
= -2;
2133 HeapFree(GetProcessHeap(), 0, parent
);
2135 package
->folders
[index
].Property
= load_dynamic_property(package
, dir
,NULL
);
2137 msiobj_release(&row
->hdr
);
2138 TRACE(" %s retuning on index %i\n",debugstr_w(dir
),index
);
2143 LPWSTR
resolve_folder(MSIPACKAGE
*package
, LPCWSTR name
, BOOL source
,
2144 BOOL set_prop
, MSIFOLDER
**folder
)
2147 LPWSTR p
, path
= NULL
;
2149 TRACE("Working to resolve %s\n",debugstr_w(name
));
2151 /* special resolving for Target and Source root dir */
2152 if (strcmpW(name
,cszTargetDir
)==0 || strcmpW(name
,cszSourceDir
)==0)
2156 path
= load_dynamic_property(package
,cszTargetDir
,NULL
);
2159 path
= load_dynamic_property(package
,cszRootDrive
,NULL
);
2161 MSI_SetPropertyW(package
,cszTargetDir
,path
);
2165 for (i
= 0; i
< package
->loaded_folders
; i
++)
2167 if (strcmpW(package
->folders
[i
].Directory
,name
)==0)
2170 *folder
= &(package
->folders
[i
]);
2176 path
= load_dynamic_property(package
,cszSourceDir
,NULL
);
2179 path
= load_dynamic_property(package
,cszDatabase
,NULL
);
2182 p
= strrchrW(path
,'\\');
2189 for (i
= 0; i
< package
->loaded_folders
; i
++)
2191 if (strcmpW(package
->folders
[i
].Directory
,name
)==0)
2194 *folder
= &(package
->folders
[i
]);
2200 for (i
= 0; i
< package
->loaded_folders
; i
++)
2202 if (strcmpW(package
->folders
[i
].Directory
,name
)==0)
2206 if (i
>= package
->loaded_folders
)
2210 *folder
= &(package
->folders
[i
]);
2212 if (!source
&& package
->folders
[i
].ResolvedTarget
)
2214 path
= strdupW(package
->folders
[i
].ResolvedTarget
);
2215 TRACE(" already resolved to %s\n",debugstr_w(path
));
2218 else if (source
&& package
->folders
[i
].ResolvedSource
)
2220 path
= strdupW(package
->folders
[i
].ResolvedSource
);
2221 TRACE(" (source)already resolved to %s\n",debugstr_w(path
));
2224 else if (!source
&& package
->folders
[i
].Property
)
2226 path
= build_directory_name(2, package
->folders
[i
].Property
, NULL
);
2228 TRACE(" internally set to %s\n",debugstr_w(path
));
2230 MSI_SetPropertyW(package
,name
,path
);
2234 if (package
->folders
[i
].ParentIndex
>= 0)
2236 LPWSTR parent
= package
->folders
[package
->folders
[i
].ParentIndex
].Directory
;
2238 TRACE(" ! Parent is %s\n", debugstr_w(parent
));
2240 p
= resolve_folder(package
, parent
, source
, set_prop
, NULL
);
2243 TRACE(" TargetDefault = %s\n",debugstr_w(package
->folders
[i
].TargetDefault
));
2244 path
= build_directory_name(3, p
, package
->folders
[i
].TargetDefault
, NULL
);
2245 package
->folders
[i
].ResolvedTarget
= strdupW(path
);
2246 TRACE(" resolved into %s\n",debugstr_w(path
));
2248 MSI_SetPropertyW(package
,name
,path
);
2252 path
= build_directory_name(3, p
, package
->folders
[i
].SourceDefault
, NULL
);
2253 TRACE(" (source)resolved into %s\n",debugstr_w(path
));
2254 package
->folders
[i
].ResolvedSource
= strdupW(path
);
2256 HeapFree(GetProcessHeap(),0,p
);
2261 /* scan for and update current install states */
2262 void ACTION_UpdateInstallStates(MSIPACKAGE
*package
)
2267 productcode
= load_dynamic_property(package
,szProductCode
,NULL
);
2269 for (i
= 0; i
< package
->loaded_components
; i
++)
2272 res
= MsiGetComponentPathW(productcode
,
2273 package
->components
[i
].ComponentId
, NULL
, NULL
);
2275 res
= INSTALLSTATE_ABSENT
;
2276 package
->components
[i
].Installed
= res
;
2279 for (i
= 0; i
< package
->loaded_features
; i
++)
2281 INSTALLSTATE res
= -10;
2283 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
2285 MSICOMPONENT
* component
= &package
->components
[package
->features
[i
].
2288 res
= component
->Installed
;
2291 if (res
== component
->Installed
)
2294 if (res
!= component
->Installed
)
2295 res
= INSTALLSTATE_INCOMPLETE
;
2301 /* update compoennt state based on a feature change */
2302 void ACTION_UpdateComponentStates(MSIPACKAGE
*package
, LPCWSTR szFeature
)
2305 INSTALLSTATE newstate
;
2306 MSIFEATURE
*feature
;
2308 i
= get_loaded_feature(package
,szFeature
);
2312 feature
= &package
->features
[i
];
2313 newstate
= feature
->ActionRequest
;
2315 for( i
= 0; i
< feature
->ComponentCount
; i
++)
2317 MSICOMPONENT
* component
= &package
->components
[feature
->Components
[i
]];
2319 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
2320 newstate
, debugstr_w(component
->Component
), component
->Installed
,
2321 component
->Action
, component
->ActionRequest
);
2323 if (!component
->Enabled
)
2327 if (newstate
== INSTALLSTATE_LOCAL
)
2329 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
2330 component
->Action
= INSTALLSTATE_LOCAL
;
2336 component
->ActionRequest
= newstate
;
2337 component
->Action
= newstate
;
2339 /*if any other feature wants is local we need to set it local*/
2341 j
< package
->loaded_features
&&
2342 component
->ActionRequest
!= INSTALLSTATE_LOCAL
;
2345 for (k
= 0; k
< package
->features
[j
].ComponentCount
; k
++)
2346 if ( package
->features
[j
].Components
[k
] ==
2347 feature
->Components
[i
] )
2349 if (package
->features
[j
].ActionRequest
==
2352 TRACE("Saved by %s\n", debugstr_w(package
->features
[j
].Feature
));
2353 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
2354 component
->Action
= INSTALLSTATE_LOCAL
;
2361 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
2362 newstate
, debugstr_w(component
->Component
), component
->Installed
,
2363 component
->Action
, component
->ActionRequest
);
2367 static BOOL
process_state_property (MSIPACKAGE
* package
, LPCWSTR property
,
2370 static const WCHAR all
[]={'A','L','L',0};
2371 LPWSTR override
= NULL
;
2375 override
= load_dynamic_property(package
, property
, NULL
);
2379 for(i
= 0; i
< package
->loaded_features
; i
++)
2381 if (strcmpiW(override
,all
)==0)
2383 package
->features
[i
].ActionRequest
= state
;
2384 package
->features
[i
].Action
= state
;
2388 LPWSTR ptr
= override
;
2389 LPWSTR ptr2
= strchrW(override
,',');
2394 strncmpW(ptr
,package
->features
[i
].Feature
, ptr2
-ptr
)==0)
2396 strcmpW(ptr
,package
->features
[i
].Feature
)==0))
2398 package
->features
[i
].ActionRequest
= state
;
2399 package
->features
[i
].Action
= state
;
2405 ptr2
= strchrW(ptr
,',');
2412 HeapFree(GetProcessHeap(),0,override
);
2418 static UINT
SetFeatureStates(MSIPACKAGE
*package
)
2424 static const WCHAR szlevel
[] =
2425 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2426 static const WCHAR szAddLocal
[] =
2427 {'A','D','D','L','O','C','A','L',0};
2428 static const WCHAR szRemove
[] =
2429 {'R','E','M','O','V','E',0};
2430 BOOL override
= FALSE
;
2432 /* I do not know if this is where it should happen.. but */
2434 TRACE("Checking Install Level\n");
2436 level
= load_dynamic_property(package
,szlevel
,NULL
);
2439 install_level
= atoiW(level
);
2440 HeapFree(GetProcessHeap(), 0, level
);
2445 /* ok hereis the _real_ rub
2446 * all these activation/deactivation things happen in order and things
2447 * later on the list override things earlier on the list.
2448 * 1) INSTALLLEVEL processing
2458 * 11) FILEADDDEFAULT
2459 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2460 * ignored for all the features. seems strange, especially since it is not
2461 * documented anywhere, but it is how it works.
2463 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2464 * REMOVE are the big ones, since we don't handle administrative installs
2467 override
|= process_state_property(package
,szAddLocal
,INSTALLSTATE_LOCAL
);
2468 override
|= process_state_property(package
,szRemove
,INSTALLSTATE_ABSENT
);
2472 for(i
= 0; i
< package
->loaded_features
; i
++)
2474 BOOL feature_state
= ((package
->features
[i
].Level
> 0) &&
2475 (package
->features
[i
].Level
<= install_level
));
2477 if ((feature_state
) &&
2478 (package
->features
[i
].Action
== INSTALLSTATE_UNKNOWN
))
2480 if (package
->features
[i
].Attributes
&
2481 msidbFeatureAttributesFavorSource
)
2483 package
->features
[i
].ActionRequest
= INSTALLSTATE_SOURCE
;
2484 package
->features
[i
].Action
= INSTALLSTATE_SOURCE
;
2486 else if (package
->features
[i
].Attributes
&
2487 msidbFeatureAttributesFavorAdvertise
)
2489 package
->features
[i
].ActionRequest
=INSTALLSTATE_ADVERTISED
;
2490 package
->features
[i
].Action
=INSTALLSTATE_ADVERTISED
;
2494 package
->features
[i
].ActionRequest
= INSTALLSTATE_LOCAL
;
2495 package
->features
[i
].Action
= INSTALLSTATE_LOCAL
;
2502 * now we want to enable or disable components base on feature
2505 for(i
= 0; i
< package
->loaded_features
; i
++)
2507 MSIFEATURE
* feature
= &package
->features
[i
];
2508 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2509 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
2510 feature
->ActionRequest
);
2512 for( j
= 0; j
< feature
->ComponentCount
; j
++)
2514 MSICOMPONENT
* component
= &package
->components
[
2515 feature
->Components
[j
]];
2517 if (!component
->Enabled
)
2519 component
->Action
= INSTALLSTATE_UNKNOWN
;
2520 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
2524 if (feature
->Action
== INSTALLSTATE_LOCAL
)
2526 component
->Action
= INSTALLSTATE_LOCAL
;
2527 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
2529 else if (feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
2531 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
2532 (component
->Action
== INSTALLSTATE_ABSENT
) ||
2533 (component
->Action
== INSTALLSTATE_ADVERTISED
))
2536 component
->Action
= INSTALLSTATE_SOURCE
;
2537 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
2540 else if (feature
->ActionRequest
== INSTALLSTATE_ADVERTISED
)
2542 if ((component
->Action
== INSTALLSTATE_UNKNOWN
) ||
2543 (component
->Action
== INSTALLSTATE_ABSENT
))
2546 component
->Action
= INSTALLSTATE_ADVERTISED
;
2547 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
2550 else if (feature
->ActionRequest
== INSTALLSTATE_ABSENT
)
2552 if (component
->Action
== INSTALLSTATE_UNKNOWN
)
2554 component
->Action
= INSTALLSTATE_ABSENT
;
2555 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
2562 for(i
= 0; i
< package
->loaded_components
; i
++)
2564 MSICOMPONENT
* component
= &package
->components
[i
];
2566 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2567 debugstr_w(component
->Component
), component
->Installed
,
2568 component
->Action
, component
->ActionRequest
);
2572 return ERROR_SUCCESS
;
2576 * A lot is done in this function aside from just the costing.
2577 * The costing needs to be implemented at some point but for now I am going
2578 * to focus on the directory building
2581 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2583 static const WCHAR ExecSeqQuery
[] =
2584 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2585 '`','D','i','r','e','c','t','o','r','y','`',0};
2586 static const WCHAR ConditionQuery
[] =
2587 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2588 '`','C','o','n','d','i','t','i','o','n','`',0};
2589 static const WCHAR szCosting
[] =
2590 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2591 static const WCHAR szlevel
[] =
2592 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2593 static const WCHAR szOne
[] = { '1', 0 };
2601 MSI_GetPropertyW(package
, szCosting
, buffer
, &sz
);
2603 return ERROR_SUCCESS
;
2605 TRACE("Building Directory properties\n");
2607 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2608 if (rc
== ERROR_SUCCESS
)
2610 rc
= MSI_ViewExecute(view
, 0);
2611 if (rc
!= ERROR_SUCCESS
)
2613 MSI_ViewClose(view
);
2614 msiobj_release(&view
->hdr
);
2622 MSIRECORD
* row
= 0;
2625 rc
= MSI_ViewFetch(view
,&row
);
2626 if (rc
!= ERROR_SUCCESS
)
2633 MSI_RecordGetStringW(row
,1,name
,&sz
);
2635 /* This helper function now does ALL the work */
2636 TRACE("Dir %s ...\n",debugstr_w(name
));
2637 load_folder(package
,name
);
2638 path
= resolve_folder(package
,name
,FALSE
,TRUE
,NULL
);
2639 TRACE("resolves to %s\n",debugstr_w(path
));
2640 HeapFree( GetProcessHeap(), 0, path
);
2642 msiobj_release(&row
->hdr
);
2644 MSI_ViewClose(view
);
2645 msiobj_release(&view
->hdr
);
2648 TRACE("File calculations %i files\n",package
->loaded_files
);
2650 for (i
= 0; i
< package
->loaded_files
; i
++)
2652 MSICOMPONENT
* comp
= NULL
;
2653 MSIFILE
* file
= NULL
;
2655 file
= &package
->files
[i
];
2656 if (file
->ComponentIndex
>= 0)
2657 comp
= &package
->components
[file
->ComponentIndex
];
2659 if (file
->Temporary
== TRUE
)
2666 /* calculate target */
2667 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
2669 HeapFree(GetProcessHeap(),0,file
->TargetPath
);
2671 TRACE("file %s is named %s\n",
2672 debugstr_w(file
->File
),debugstr_w(file
->FileName
));
2674 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
2676 HeapFree(GetProcessHeap(),0,p
);
2678 TRACE("file %s resolves to %s\n",
2679 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
2681 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
2684 comp
->Cost
+= file
->FileSize
;
2694 static const WCHAR name
[] =
2696 static const WCHAR name_fmt
[] =
2697 {'%','u','.','%','u','.','%','u','.','%','u',0};
2698 WCHAR filever
[0x100];
2699 VS_FIXEDFILEINFO
*lpVer
;
2701 TRACE("Version comparison.. \n");
2702 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
2703 version
= HeapAlloc(GetProcessHeap(),0,versize
);
2704 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
2706 VerQueryValueW(version
, name
, (LPVOID
*)&lpVer
, &sz
);
2708 sprintfW(filever
,name_fmt
,
2709 HIWORD(lpVer
->dwFileVersionMS
),
2710 LOWORD(lpVer
->dwFileVersionMS
),
2711 HIWORD(lpVer
->dwFileVersionLS
),
2712 LOWORD(lpVer
->dwFileVersionLS
));
2714 TRACE("new %s old %s\n", debugstr_w(file
->Version
),
2715 debugstr_w(filever
));
2716 if (strcmpiW(filever
,file
->Version
)<0)
2719 FIXME("cost should be diff in size\n");
2720 comp
->Cost
+= file
->FileSize
;
2724 HeapFree(GetProcessHeap(),0,version
);
2732 TRACE("Evaluating Condition Table\n");
2734 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
2735 if (rc
== ERROR_SUCCESS
)
2737 rc
= MSI_ViewExecute(view
, 0);
2738 if (rc
!= ERROR_SUCCESS
)
2740 MSI_ViewClose(view
);
2741 msiobj_release(&view
->hdr
);
2747 WCHAR Feature
[0x100];
2748 MSIRECORD
* row
= 0;
2752 rc
= MSI_ViewFetch(view
,&row
);
2754 if (rc
!= ERROR_SUCCESS
)
2761 MSI_RecordGetStringW(row
,1,Feature
,&sz
);
2763 feature_index
= get_loaded_feature(package
,Feature
);
2764 if (feature_index
< 0)
2765 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature
));
2769 Condition
= load_dynamic_stringW(row
,3);
2771 if (MSI_EvaluateConditionW(package
,Condition
) ==
2774 int level
= MSI_RecordGetInteger(row
,2);
2775 TRACE("Reseting feature %s to level %i\n",
2776 debugstr_w(Feature
), level
);
2777 package
->features
[feature_index
].Level
= level
;
2779 HeapFree(GetProcessHeap(),0,Condition
);
2782 msiobj_release(&row
->hdr
);
2784 MSI_ViewClose(view
);
2785 msiobj_release(&view
->hdr
);
2788 TRACE("Enabling or Disabling Components\n");
2789 for (i
= 0; i
< package
->loaded_components
; i
++)
2791 if (package
->components
[i
].Condition
[0])
2793 if (MSI_EvaluateConditionW(package
,
2794 package
->components
[i
].Condition
) == MSICONDITION_FALSE
)
2796 TRACE("Disabling component %s\n",
2797 debugstr_w(package
->components
[i
].Component
));
2798 package
->components
[i
].Enabled
= FALSE
;
2803 MSI_SetPropertyW(package
,szCosting
,szOne
);
2804 /* set default run level if not set */
2805 level
= load_dynamic_property(package
,szlevel
,NULL
);
2807 MSI_SetPropertyW(package
,szlevel
, szOne
);
2809 HeapFree(GetProcessHeap(),0,level
);
2811 ACTION_UpdateInstallStates(package
);
2813 return SetFeatureStates(package
);
2817 * This is a helper function for handling embedded cabinet media
2819 static UINT
writeout_cabinet_stream(MSIPACKAGE
*package
, WCHAR
* stream_name
,
2827 WCHAR tmp
[MAX_PATH
];
2829 rc
= read_raw_stream_data(package
->db
,stream_name
,&data
,&size
);
2830 if (rc
!= ERROR_SUCCESS
)
2834 if (MSI_GetPropertyW(package
, cszTempFolder
, tmp
, &write
))
2835 GetTempPathW(MAX_PATH
,tmp
);
2837 GetTempFileNameW(tmp
,stream_name
,0,source
);
2839 track_tempfile(package
,strrchrW(source
,'\\'), source
);
2840 the_file
= CreateFileW(source
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2841 FILE_ATTRIBUTE_NORMAL
, NULL
);
2843 if (the_file
== INVALID_HANDLE_VALUE
)
2845 ERR("Unable to create file %s\n",debugstr_w(source
));
2846 rc
= ERROR_FUNCTION_FAILED
;
2850 WriteFile(the_file
,data
,size
,&write
,NULL
);
2851 CloseHandle(the_file
);
2852 TRACE("wrote %li bytes to %s\n",write
,debugstr_w(source
));
2854 HeapFree(GetProcessHeap(),0,data
);
2859 /* Support functions for FDI functions */
2862 MSIPACKAGE
* package
;
2867 static void * cabinet_alloc(ULONG cb
)
2869 return HeapAlloc(GetProcessHeap(), 0, cb
);
2872 static void cabinet_free(void *pv
)
2874 HeapFree(GetProcessHeap(), 0, pv
);
2877 static INT_PTR
cabinet_open(char *pszFile
, int oflag
, int pmode
)
2880 DWORD dwShareMode
= 0;
2881 DWORD dwCreateDisposition
= OPEN_EXISTING
;
2882 switch (oflag
& _O_ACCMODE
)
2885 dwAccess
= GENERIC_READ
;
2886 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
2889 dwAccess
= GENERIC_WRITE
;
2890 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
2893 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
2894 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
2897 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
2898 dwCreateDisposition
= CREATE_NEW
;
2899 else if (oflag
& _O_CREAT
)
2900 dwCreateDisposition
= CREATE_ALWAYS
;
2901 return (INT_PTR
)CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
2902 dwCreateDisposition
, 0, NULL
);
2905 static UINT
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
2908 if (ReadFile((HANDLE
)hf
, pv
, cb
, &dwRead
, NULL
))
2913 static UINT
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
2916 if (WriteFile((HANDLE
)hf
, pv
, cb
, &dwWritten
, NULL
))
2921 static int cabinet_close(INT_PTR hf
)
2923 return CloseHandle((HANDLE
)hf
) ? 0 : -1;
2926 static long cabinet_seek(INT_PTR hf
, long dist
, int seektype
)
2928 /* flags are compatible and so are passed straight through */
2929 return SetFilePointer((HANDLE
)hf
, dist
, NULL
, seektype
);
2932 static INT_PTR
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
2934 /* FIXME: try to do more processing in this function */
2937 case fdintCOPY_FILE
:
2939 CabData
*data
= (CabData
*) pfdin
->pv
;
2940 ULONG len
= strlen(data
->cab_path
) + strlen(pfdin
->psz1
);
2945 LPWSTR tracknametmp
;
2946 static const WCHAR tmpprefix
[] = {'C','A','B','T','M','P','_',0};
2948 if (data
->file_name
&& lstrcmpiA(data
->file_name
,pfdin
->psz1
))
2951 file
= cabinet_alloc((len
+1)*sizeof(char));
2952 strcpy(file
, data
->cab_path
);
2953 strcat(file
, pfdin
->psz1
);
2955 TRACE("file: %s\n", debugstr_a(file
));
2957 /* track this file so it can be deleted if not installed */
2958 trackpath
=strdupAtoW(file
);
2959 tracknametmp
=strdupAtoW(strrchr(file
,'\\')+1);
2960 trackname
= HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp
) +
2961 strlenW(tmpprefix
)+1) * sizeof(WCHAR
));
2963 strcpyW(trackname
,tmpprefix
);
2964 strcatW(trackname
,tracknametmp
);
2966 track_tempfile(data
->package
, trackname
, trackpath
);
2968 HeapFree(GetProcessHeap(),0,trackpath
);
2969 HeapFree(GetProcessHeap(),0,trackname
);
2970 HeapFree(GetProcessHeap(),0,tracknametmp
);
2972 return cabinet_open(file
, _O_WRONLY
| _O_CREAT
, 0);
2974 case fdintCLOSE_FILE_INFO
:
2978 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
2980 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
2982 if (!SetFileTime((HANDLE
)pfdin
->hf
, &ftLocal
, 0, &ftLocal
))
2985 cabinet_close(pfdin
->hf
);
2993 /***********************************************************************
2994 * extract_cabinet_file
2996 * Extract files from a cab file.
2998 static BOOL
extract_a_cabinet_file(MSIPACKAGE
* package
, const WCHAR
* source
,
2999 const WCHAR
* path
, const WCHAR
* file
)
3009 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source
),
3010 debugstr_w(file
), debugstr_w(path
));
3012 hfdi
= FDICreate(cabinet_alloc
,
3023 ERR("FDICreate failed\n");
3027 if (!(cabinet
= strdupWtoA( source
)))
3032 if (!(cab_path
= strdupWtoA( path
)))
3035 HeapFree(GetProcessHeap(), 0, cabinet
);
3039 data
.package
= package
;
3040 data
.cab_path
= cab_path
;
3042 file_name
= strdupWtoA(file
);
3045 data
.file_name
= file_name
;
3047 ret
= FDICopy(hfdi
, cabinet
, "", 0, cabinet_notify
, NULL
, &data
);
3050 ERR("FDICopy failed\n");
3054 HeapFree(GetProcessHeap(), 0, cabinet
);
3055 HeapFree(GetProcessHeap(), 0, cab_path
);
3056 HeapFree(GetProcessHeap(), 0, file_name
);
3061 static UINT
ready_media_for_file(MSIPACKAGE
*package
, WCHAR
* path
,
3064 UINT rc
= ERROR_SUCCESS
;
3065 MSIRECORD
* row
= 0;
3066 static WCHAR source
[MAX_PATH
];
3067 static const WCHAR ExecSeqQuery
[] =
3068 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3069 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3070 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
3071 ' ','%', 'i',' ','O','R','D','E','R',' ','B','Y',' ',
3072 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',0};
3076 static UINT last_sequence
= 0;
3078 if (file
->Attributes
& msidbFileAttributesNoncompressed
)
3080 TRACE("Uncompressed File, no media to ready.\n");
3081 return ERROR_SUCCESS
;
3084 if (file
->Sequence
<= last_sequence
)
3086 TRACE("Media already ready (%u, %u)\n",file
->Sequence
,last_sequence
);
3087 /*extract_a_cabinet_file(package, source,path,file->File); */
3088 return ERROR_SUCCESS
;
3091 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, file
->Sequence
);
3093 return ERROR_FUNCTION_FAILED
;
3095 seq
= MSI_RecordGetInteger(row
,2);
3096 last_sequence
= seq
;
3098 if (!MSI_RecordIsNull(row
,4))
3101 MSI_RecordGetStringW(row
,4,cab
,&sz
);
3102 TRACE("Source is CAB %s\n",debugstr_w(cab
));
3103 /* the stream does not contain the # character */
3106 writeout_cabinet_stream(package
,&cab
[1],source
);
3107 strcpyW(path
,source
);
3108 *(strrchrW(path
,'\\')+1)=0;
3113 if (MSI_GetPropertyW(package
, cszSourceDir
, source
, &sz
))
3115 ERR("No Source dir defined \n");
3116 rc
= ERROR_FUNCTION_FAILED
;
3120 strcpyW(path
,source
);
3121 strcatW(source
,cab
);
3122 /* extract the cab file into a folder in the temp folder */
3124 if (MSI_GetPropertyW(package
, cszTempFolder
,path
, &sz
)
3126 GetTempPathW(MAX_PATH
,path
);
3129 rc
= !extract_a_cabinet_file(package
, source
,path
,NULL
);
3134 MSI_GetPropertyW(package
,cszSourceDir
,source
,&sz
);
3135 strcpyW(path
,source
);
3137 msiobj_release(&row
->hdr
);
3141 inline static UINT
create_component_directory ( MSIPACKAGE
* package
, INT component
)
3143 UINT rc
= ERROR_SUCCESS
;
3145 LPWSTR install_path
;
3147 install_path
= resolve_folder(package
, package
->components
[component
].Directory
,
3148 FALSE
, FALSE
, &folder
);
3150 return ERROR_FUNCTION_FAILED
;
3152 /* create the path */
3153 if (folder
->State
== 0)
3155 create_full_pathW(install_path
);
3158 HeapFree(GetProcessHeap(), 0, install_path
);
3163 static UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
3165 UINT rc
= ERROR_SUCCESS
;
3168 WCHAR uipath
[MAX_PATH
];
3171 return ERROR_INVALID_HANDLE
;
3173 /* increment progress bar each time action data is sent */
3174 ui_progress(package
,1,1,0,0);
3176 for (index
= 0; index
< package
->loaded_files
; index
++)
3178 WCHAR path_to_source
[MAX_PATH
];
3181 file
= &package
->files
[index
];
3183 if (file
->Temporary
)
3187 if (!ACTION_VerifyComponentForAction(package
, file
->ComponentIndex
,
3188 INSTALLSTATE_LOCAL
))
3190 ui_progress(package
,2,file
->FileSize
,0,0);
3191 TRACE("File %s is not scheduled for install\n",
3192 debugstr_w(file
->File
));
3197 if ((file
->State
== 1) || (file
->State
== 2))
3200 MSICOMPONENT
* comp
= NULL
;
3202 TRACE("Installing %s\n",debugstr_w(file
->File
));
3203 rc
= ready_media_for_file(package
, path_to_source
, file
);
3206 * our file table could change here because a new temp file
3207 * may have been created
3209 file
= &package
->files
[index
];
3210 if (rc
!= ERROR_SUCCESS
)
3212 ERR("Unable to ready media\n");
3213 rc
= ERROR_FUNCTION_FAILED
;
3217 create_component_directory( package
, file
->ComponentIndex
);
3219 /* recalculate file paths because things may have changed */
3221 if (file
->ComponentIndex
>= 0)
3222 comp
= &package
->components
[file
->ComponentIndex
];
3224 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
3225 HeapFree(GetProcessHeap(),0,file
->TargetPath
);
3227 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
3228 HeapFree(GetProcessHeap(),0,p
);
3230 if (file
->Attributes
& msidbFileAttributesNoncompressed
)
3232 p
= resolve_folder(package
, comp
->Directory
, TRUE
, FALSE
, NULL
);
3233 file
->SourcePath
= build_directory_name(2, p
, file
->ShortName
);
3234 HeapFree(GetProcessHeap(),0,p
);
3237 file
->SourcePath
= build_directory_name(2, path_to_source
,
3241 TRACE("file paths %s to %s\n",debugstr_w(file
->SourcePath
),
3242 debugstr_w(file
->TargetPath
));
3245 uirow
=MSI_CreateRecord(9);
3246 MSI_RecordSetStringW(uirow
,1,file
->File
);
3247 strcpyW(uipath
,file
->TargetPath
);
3248 *(strrchrW(uipath
,'\\')+1)=0;
3249 MSI_RecordSetStringW(uirow
,9,uipath
);
3250 MSI_RecordSetInteger(uirow
,6,file
->FileSize
);
3251 ui_actiondata(package
,szInstallFiles
,uirow
);
3252 msiobj_release( &uirow
->hdr
);
3253 ui_progress(package
,2,file
->FileSize
,0,0);
3256 if (file
->Attributes
& msidbFileAttributesNoncompressed
)
3257 rc
= CopyFileW(file
->SourcePath
,file
->TargetPath
,FALSE
);
3259 rc
= MoveFileW(file
->SourcePath
, file
->TargetPath
);
3263 rc
= GetLastError();
3264 ERR("Unable to move/copy file (%s -> %s) (error %d)\n",
3265 debugstr_w(file
->SourcePath
), debugstr_w(file
->TargetPath
),
3267 if (rc
== ERROR_ALREADY_EXISTS
&& file
->State
== 2)
3269 if (!CopyFileW(file
->SourcePath
,file
->TargetPath
,FALSE
))
3270 ERR("Unable to copy file (%s -> %s) (error %ld)\n",
3271 debugstr_w(file
->SourcePath
),
3272 debugstr_w(file
->TargetPath
), GetLastError());
3273 if (!(file
->Attributes
& msidbFileAttributesNoncompressed
))
3274 DeleteFileW(file
->SourcePath
);
3277 else if (rc
== ERROR_FILE_NOT_FOUND
)
3279 ERR("Source File Not Found! Continuing\n");
3282 else if (file
->Attributes
& msidbFileAttributesVital
)
3284 ERR("Ignoring Error and continuing (nonvital file)...\n");
3299 inline static UINT
get_file_target(MSIPACKAGE
*package
, LPCWSTR file_key
,
3300 LPWSTR
* file_source
)
3305 return ERROR_INVALID_HANDLE
;
3307 for (index
= 0; index
< package
->loaded_files
; index
++)
3309 if (strcmpW(file_key
,package
->files
[index
].File
)==0)
3311 if (package
->files
[index
].State
>= 2)
3313 *file_source
= strdupW(package
->files
[index
].TargetPath
);
3314 return ERROR_SUCCESS
;
3317 return ERROR_FILE_NOT_FOUND
;
3321 return ERROR_FUNCTION_FAILED
;
3324 static UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
3328 MSIRECORD
* row
= 0;
3329 static const WCHAR ExecSeqQuery
[] =
3330 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3331 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
3334 return ERROR_INVALID_HANDLE
;
3336 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3337 if (rc
!= ERROR_SUCCESS
)
3338 return ERROR_SUCCESS
;
3340 rc
= MSI_ViewExecute(view
, 0);
3341 if (rc
!= ERROR_SUCCESS
)
3343 MSI_ViewClose(view
);
3344 msiobj_release(&view
->hdr
);
3350 WCHAR file_key
[0x100];
3351 WCHAR
*file_source
= NULL
;
3352 WCHAR dest_name
[0x100];
3353 LPWSTR dest_path
, dest
;
3354 WCHAR component
[0x100];
3355 INT component_index
;
3359 rc
= MSI_ViewFetch(view
,&row
);
3360 if (rc
!= ERROR_SUCCESS
)
3367 rc
= MSI_RecordGetStringW(row
,2,component
,&sz
);
3368 if (rc
!= ERROR_SUCCESS
)
3370 ERR("Unable to get component\n");
3371 msiobj_release(&row
->hdr
);
3375 component_index
= get_loaded_component(package
,component
);
3377 if (!ACTION_VerifyComponentForAction(package
, component_index
,
3378 INSTALLSTATE_LOCAL
))
3380 TRACE("Skipping copy due to disabled component\n");
3382 /* the action taken was the same as the current install state */
3383 package
->components
[component_index
].Action
=
3384 package
->components
[component_index
].Installed
;
3386 msiobj_release(&row
->hdr
);
3390 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
3393 rc
= MSI_RecordGetStringW(row
,3,file_key
,&sz
);
3394 if (rc
!= ERROR_SUCCESS
)
3396 ERR("Unable to get file key\n");
3397 msiobj_release(&row
->hdr
);
3401 rc
= get_file_target(package
,file_key
,&file_source
);
3403 if (rc
!= ERROR_SUCCESS
)
3405 ERR("Original file unknown %s\n",debugstr_w(file_key
));
3406 msiobj_release(&row
->hdr
);
3407 HeapFree(GetProcessHeap(),0,file_source
);
3411 if (MSI_RecordIsNull(row
,4))
3413 strcpyW(dest_name
,strrchrW(file_source
,'\\')+1);
3418 MSI_RecordGetStringW(row
,4,dest_name
,&sz
);
3419 reduce_to_longfilename(dest_name
);
3422 if (MSI_RecordIsNull(row
,5))
3425 dest_path
= strdupW(file_source
);
3426 p
= strrchrW(dest_path
,'\\');
3432 WCHAR destkey
[0x100];
3434 MSI_RecordGetStringW(row
,5,destkey
,&sz
);
3436 dest_path
= resolve_folder(package
, destkey
, FALSE
,FALSE
,NULL
);
3439 ERR("Unable to get destination folder\n");
3440 msiobj_release(&row
->hdr
);
3441 HeapFree(GetProcessHeap(),0,file_source
);
3446 dest
= build_directory_name(2, dest_path
, dest_name
);
3448 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source
),
3451 if (strcmpW(file_source
,dest
))
3452 rc
= !CopyFileW(file_source
,dest
,TRUE
);
3456 if (rc
!= ERROR_SUCCESS
)
3457 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source
), debugstr_w(dest_path
), GetLastError());
3459 FIXME("We should track these duplicate files as well\n");
3461 msiobj_release(&row
->hdr
);
3462 HeapFree(GetProcessHeap(),0,dest_path
);
3463 HeapFree(GetProcessHeap(),0,dest
);
3464 HeapFree(GetProcessHeap(),0,file_source
);
3466 MSI_ViewClose(view
);
3467 msiobj_release(&view
->hdr
);
3472 /* OK this value is "interpreted" and then formatted based on the
3473 first few characters */
3474 static LPSTR
parse_value(MSIPACKAGE
*package
, WCHAR
*value
, DWORD
*type
,
3478 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
3484 LPWSTR deformated
= NULL
;
3487 deformat_string(package
, &value
[2], &deformated
);
3489 /* binary value type */
3493 *size
= (strlenW(ptr
)/2)+1;
3495 *size
= strlenW(ptr
)/2;
3497 data
= HeapAlloc(GetProcessHeap(),0,*size
);
3503 /* if uneven pad with a zero in front */
3509 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
3511 TRACE("Uneven byte count\n");
3519 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
3522 HeapFree(GetProcessHeap(),0,deformated
);
3524 TRACE("Data %li bytes(%i)\n",*size
,count
);
3531 deformat_string(package
, &value
[1], &deformated
);
3534 *size
= sizeof(DWORD
);
3535 data
= HeapAlloc(GetProcessHeap(),0,*size
);
3541 if ( (*p
< '0') || (*p
> '9') )
3547 if (deformated
[0] == '-')
3550 TRACE("DWORD %li\n",*(LPDWORD
)data
);
3552 HeapFree(GetProcessHeap(),0,deformated
);
3557 static const WCHAR szMulti
[] = {'[','~',']',0};
3566 *type
=REG_EXPAND_SZ
;
3574 if (strstrW(value
,szMulti
))
3575 *type
= REG_MULTI_SZ
;
3577 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
3582 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
3586 MSIRECORD
* row
= 0;
3587 static const WCHAR ExecSeqQuery
[] =
3588 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3589 '`','R','e','g','i','s','t','r','y','`',0 };
3592 return ERROR_INVALID_HANDLE
;
3594 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3595 if (rc
!= ERROR_SUCCESS
)
3596 return ERROR_SUCCESS
;
3598 rc
= MSI_ViewExecute(view
, 0);
3599 if (rc
!= ERROR_SUCCESS
)
3601 MSI_ViewClose(view
);
3602 msiobj_release(&view
->hdr
);
3606 /* increment progress bar each time action data is sent */
3607 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
3611 static const WCHAR szHCR
[] =
3612 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3613 'R','O','O','T','\\',0};
3614 static const WCHAR szHCU
[] =
3615 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3616 'U','S','E','R','\\',0};
3617 static const WCHAR szHLM
[] =
3618 {'H','K','E','Y','_','L','O','C','A','L','_',
3619 'M','A','C','H','I','N','E','\\',0};
3620 static const WCHAR szHU
[] =
3621 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3623 LPSTR value_data
= NULL
;
3624 HKEY root_key
, hkey
;
3626 LPWSTR value
, key
, name
, component
, deformated
;
3628 INT component_index
;
3632 BOOL check_first
= FALSE
;
3634 rc
= MSI_ViewFetch(view
,&row
);
3635 if (rc
!= ERROR_SUCCESS
)
3640 ui_progress(package
,2,0,0,0);
3647 component
= load_dynamic_stringW(row
, 6);
3648 component_index
= get_loaded_component(package
,component
);
3650 if (!ACTION_VerifyComponentForAction(package
, component_index
,
3651 INSTALLSTATE_LOCAL
))
3653 TRACE("Skipping write due to disabled component\n");
3654 msiobj_release(&row
->hdr
);
3656 package
->components
[component_index
].Action
=
3657 package
->components
[component_index
].Installed
;
3662 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
3664 name
= load_dynamic_stringW(row
, 4);
3665 if( MSI_RecordIsNull(row
,5) && name
)
3667 /* null values can have special meanings */
3668 if (name
[0]=='-' && name
[1] == 0)
3670 msiobj_release(&row
->hdr
);
3673 else if ((name
[0]=='+' && name
[1] == 0) ||
3674 (name
[0] == '*' && name
[1] == 0))
3676 HeapFree(GetProcessHeap(),0,name
);
3682 root
= MSI_RecordGetInteger(row
,2);
3683 key
= load_dynamic_stringW(row
, 3);
3686 /* get the root key */
3689 case 0: root_key
= HKEY_CLASSES_ROOT
;
3692 case 1: root_key
= HKEY_CURRENT_USER
;
3695 case 2: root_key
= HKEY_LOCAL_MACHINE
;
3698 case 3: root_key
= HKEY_USERS
;
3702 ERR("Unknown root %i\n",root
);
3709 msiobj_release(&row
->hdr
);
3713 deformat_string(package
, key
, &deformated
);
3714 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
3715 uikey
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(WCHAR
));
3716 strcpyW(uikey
,szRoot
);
3717 strcatW(uikey
,deformated
);
3719 if (RegCreateKeyW( root_key
, deformated
, &hkey
))
3721 ERR("Could not create key %s\n",debugstr_w(deformated
));
3722 msiobj_release(&row
->hdr
);
3723 HeapFree(GetProcessHeap(),0,deformated
);
3726 HeapFree(GetProcessHeap(),0,deformated
);
3728 value
= load_dynamic_stringW(row
,5);
3730 value_data
= parse_value(package
, value
, &type
, &size
);
3733 static const WCHAR szEmpty
[] = {0};
3734 value_data
= (LPSTR
)strdupW(szEmpty
);
3739 deformat_string(package
, name
, &deformated
);
3741 /* get the double nulls to terminate SZ_MULTI */
3742 if (type
== REG_MULTI_SZ
)
3743 size
+=sizeof(WCHAR
);
3747 TRACE("Setting value %s of %s\n",debugstr_w(deformated
),
3749 RegSetValueExW(hkey
, deformated
, 0, type
, value_data
, size
);
3754 rc
= RegQueryValueExW(hkey
, deformated
, NULL
, NULL
, NULL
, &sz
);
3755 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
3757 TRACE("value %s of %s checked already exists\n",
3758 debugstr_w(deformated
), debugstr_w(uikey
));
3762 TRACE("Checked and setting value %s of %s\n",
3763 debugstr_w(deformated
), debugstr_w(uikey
));
3764 RegSetValueExW(hkey
, deformated
, 0, type
, value_data
, size
);
3768 uirow
= MSI_CreateRecord(3);
3769 MSI_RecordSetStringW(uirow
,2,deformated
);
3770 MSI_RecordSetStringW(uirow
,1,uikey
);
3773 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
3775 MSI_RecordSetStringW(uirow
,3,value
);
3777 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
3778 msiobj_release( &uirow
->hdr
);
3780 HeapFree(GetProcessHeap(),0,value_data
);
3781 HeapFree(GetProcessHeap(),0,value
);
3782 HeapFree(GetProcessHeap(),0,deformated
);
3784 msiobj_release(&row
->hdr
);
3787 HeapFree(GetProcessHeap(),0,uikey
);
3788 HeapFree(GetProcessHeap(),0,key
);
3789 HeapFree(GetProcessHeap(),0,name
);
3790 HeapFree(GetProcessHeap(),0,component
);
3792 MSI_ViewClose(view
);
3793 msiobj_release(&view
->hdr
);
3797 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
3799 package
->script
->CurrentlyScripting
= TRUE
;
3801 return ERROR_SUCCESS
;
3805 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
3809 static const WCHAR q1
[]=
3810 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3811 '`','R','e','g','i','s','t','r','y','`',0};
3814 MSIRECORD
* row
= 0;
3817 TRACE(" InstallValidate \n");
3819 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
3820 if (rc
!= ERROR_SUCCESS
)
3821 return ERROR_SUCCESS
;
3823 rc
= MSI_ViewExecute(view
, 0);
3824 if (rc
!= ERROR_SUCCESS
)
3826 MSI_ViewClose(view
);
3827 msiobj_release(&view
->hdr
);
3832 rc
= MSI_ViewFetch(view
,&row
);
3833 if (rc
!= ERROR_SUCCESS
)
3840 msiobj_release(&row
->hdr
);
3842 MSI_ViewClose(view
);
3843 msiobj_release(&view
->hdr
);
3845 total
= total
+ progress
* REG_PROGRESS_VALUE
;
3846 total
= total
+ package
->loaded_components
* COMPONENT_PROGRESS_VALUE
;
3847 for (i
=0; i
< package
->loaded_files
; i
++)
3848 total
+= package
->files
[i
].FileSize
;
3849 ui_progress(package
,0,total
,0,0);
3851 for(i
= 0; i
< package
->loaded_features
; i
++)
3853 MSIFEATURE
* feature
= &package
->features
[i
];
3854 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
3855 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
3856 feature
->ActionRequest
);
3859 return ERROR_SUCCESS
;
3862 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
3865 MSIQUERY
* view
= NULL
;
3866 MSIRECORD
* row
= 0;
3867 static const WCHAR ExecSeqQuery
[] =
3868 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3869 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
3870 static const WCHAR title
[]=
3871 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3873 TRACE("Checking launch conditions\n");
3875 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3876 if (rc
!= ERROR_SUCCESS
)
3877 return ERROR_SUCCESS
;
3879 rc
= MSI_ViewExecute(view
, 0);
3880 if (rc
!= ERROR_SUCCESS
)
3882 MSI_ViewClose(view
);
3883 msiobj_release(&view
->hdr
);
3888 while (rc
== ERROR_SUCCESS
)
3891 LPWSTR message
= NULL
;
3893 rc
= MSI_ViewFetch(view
,&row
);
3894 if (rc
!= ERROR_SUCCESS
)
3900 cond
= load_dynamic_stringW(row
,1);
3902 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
3905 message
= load_dynamic_stringW(row
,2);
3906 deformat_string(package
,message
,&deformated
);
3907 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
3908 HeapFree(GetProcessHeap(),0,message
);
3909 HeapFree(GetProcessHeap(),0,deformated
);
3910 rc
= ERROR_FUNCTION_FAILED
;
3912 HeapFree(GetProcessHeap(),0,cond
);
3913 msiobj_release(&row
->hdr
);
3915 MSI_ViewClose(view
);
3916 msiobj_release(&view
->hdr
);
3920 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, INT
3923 MSICOMPONENT
* cmp
= &package
->components
[component_index
];
3925 if (cmp
->KeyPath
[0]==0)
3927 LPWSTR p
= resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,NULL
);
3930 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
3932 MSIRECORD
* row
= 0;
3934 LPWSTR key
,deformated
,buffer
,name
,deformated_name
;
3935 static const WCHAR ExecSeqQuery
[] =
3936 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3937 '`','R','e','g','i','s','t','r','y','`',' ',
3938 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
3939 ' ','=',' ' ,'\'','%','s','\'',0 };
3940 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
3941 static const WCHAR fmt2
[]=
3942 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3944 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
,cmp
->KeyPath
);
3948 root
= MSI_RecordGetInteger(row
,2);
3949 key
= load_dynamic_stringW(row
, 3);
3950 name
= load_dynamic_stringW(row
, 4);
3951 deformat_string(package
, key
, &deformated
);
3952 deformat_string(package
, name
, &deformated_name
);
3954 len
= strlenW(deformated
) + 6;
3955 if (deformated_name
)
3956 len
+=strlenW(deformated_name
);
3958 buffer
= HeapAlloc(GetProcessHeap(),0, len
*sizeof(WCHAR
));
3960 if (deformated_name
)
3961 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
3963 sprintfW(buffer
,fmt
,root
,deformated
);
3965 HeapFree(GetProcessHeap(),0,key
);
3966 HeapFree(GetProcessHeap(),0,deformated
);
3967 HeapFree(GetProcessHeap(),0,name
);
3968 HeapFree(GetProcessHeap(),0,deformated_name
);
3969 msiobj_release(&row
->hdr
);
3973 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
3975 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3981 j
= get_loaded_file(package
,cmp
->KeyPath
);
3985 LPWSTR p
= strdupW(package
->files
[j
].TargetPath
);
3992 static HKEY
openSharedDLLsKey()
3995 static const WCHAR path
[] =
3996 {'S','o','f','t','w','a','r','e','\\',
3997 'M','i','c','r','o','s','o','f','t','\\',
3998 'W','i','n','d','o','w','s','\\',
3999 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4000 'S','h','a','r','e','d','D','L','L','s',0};
4002 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
4006 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
4011 DWORD sz
= sizeof(count
);
4014 hkey
= openSharedDLLsKey();
4015 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
4016 if (rc
!= ERROR_SUCCESS
)
4022 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
4026 hkey
= openSharedDLLsKey();
4028 RegSetValueExW(hkey
,path
,0,REG_DWORD
,
4029 (LPBYTE
)&count
,sizeof(count
));
4031 RegDeleteValueW(hkey
,path
);
4037 * Return TRUE if the count should be written out and FALSE if not
4039 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, UINT index
)
4045 /* only refcount DLLs */
4046 if (package
->components
[index
].KeyPath
[0]==0 ||
4047 package
->components
[index
].Attributes
&
4048 msidbComponentAttributesRegistryKeyPath
||
4049 package
->components
[index
].Attributes
&
4050 msidbComponentAttributesODBCDataSource
)
4054 count
= ACTION_GetSharedDLLsCount(package
->components
[index
].
4056 write
= (count
> 0);
4058 if (package
->components
[index
].Attributes
&
4059 msidbComponentAttributesSharedDllRefCount
)
4063 /* increment counts */
4064 for (j
= 0; j
< package
->loaded_features
; j
++)
4068 if (!ACTION_VerifyFeatureForAction(package
,j
,INSTALLSTATE_LOCAL
))
4071 for (i
= 0; i
< package
->features
[j
].ComponentCount
; i
++)
4073 if (package
->features
[j
].Components
[i
] == index
)
4077 /* decrement counts */
4078 for (j
= 0; j
< package
->loaded_features
; j
++)
4081 if (!ACTION_VerifyFeatureForAction(package
,j
,INSTALLSTATE_ABSENT
))
4084 for (i
= 0; i
< package
->features
[j
].ComponentCount
; i
++)
4086 if (package
->features
[j
].Components
[i
] == index
)
4091 /* ref count all the files in the component */
4093 for (j
= 0; j
< package
->loaded_files
; j
++)
4095 if (package
->files
[j
].Temporary
)
4097 if (package
->files
[j
].ComponentIndex
== index
)
4098 ACTION_WriteSharedDLLsCount(package
->files
[j
].TargetPath
,count
);
4101 /* add a count for permenent */
4102 if (package
->components
[index
].Attributes
&
4103 msidbComponentAttributesPermanent
)
4106 package
->components
[index
].RefCount
= count
;
4109 ACTION_WriteSharedDLLsCount(package
->components
[index
].FullKeypath
,
4110 package
->components
[index
].RefCount
);
4114 * Ok further analysis makes me think that this work is
4115 * actually done in the PublishComponents and PublishFeatures
4116 * step, and not here. It appears like the keypath and all that is
4117 * resolved in this step, however actually written in the Publish steps.
4118 * But we will leave it here for now because it is unclear
4120 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
4123 WCHAR squished_pc
[GUID_SIZE
];
4124 WCHAR squished_cc
[GUID_SIZE
];
4127 HKEY hkey
=0,hkey2
=0;
4130 return ERROR_INVALID_HANDLE
;
4132 /* writes the Component and Features values to the registry */
4133 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
4137 rc
= MSIREG_OpenComponents(&hkey
);
4138 if (rc
!= ERROR_SUCCESS
)
4141 squash_guid(productcode
,squished_pc
);
4142 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
4143 for (i
= 0; i
< package
->loaded_components
; i
++)
4145 ui_progress(package
,2,0,0,0);
4146 if (package
->components
[i
].ComponentId
[0]!=0)
4148 WCHAR
*keypath
= NULL
;
4151 squash_guid(package
->components
[i
].ComponentId
,squished_cc
);
4153 keypath
= resolve_keypath(package
,i
);
4154 package
->components
[i
].FullKeypath
= keypath
;
4156 /* do the refcounting */
4157 ACTION_RefCountComponent( package
, i
);
4159 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
4160 debugstr_w(package
->components
[i
].Component
),
4161 debugstr_w(squished_cc
),
4162 debugstr_w(package
->components
[i
].FullKeypath
),
4163 package
->components
[i
].RefCount
);
4165 * Write the keypath out if the component is to be registered
4166 * and delete the key if the component is to be deregistered
4168 if (ACTION_VerifyComponentForAction(package
, i
,
4169 INSTALLSTATE_LOCAL
))
4171 rc
= RegCreateKeyW(hkey
,squished_cc
,&hkey2
);
4172 if (rc
!= ERROR_SUCCESS
)
4177 RegSetValueExW(hkey2
,squished_pc
,0,REG_SZ
,(LPVOID
)keypath
,
4178 (strlenW(keypath
)+1)*sizeof(WCHAR
));
4180 if (package
->components
[i
].Attributes
&
4181 msidbComponentAttributesPermanent
)
4183 static const WCHAR szPermKey
[] =
4184 { '0','0','0','0','0','0','0','0','0','0','0','0',
4185 '0','0','0','0','0','0','0', '0','0','0','0','0',
4186 '0','0','0','0','0','0','0','0',0};
4188 RegSetValueExW(hkey2
,szPermKey
,0,REG_SZ
,
4190 (strlenW(keypath
)+1)*sizeof(WCHAR
));
4196 uirow
= MSI_CreateRecord(3);
4197 MSI_RecordSetStringW(uirow
,1,productcode
);
4198 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].
4200 MSI_RecordSetStringW(uirow
,3,keypath
);
4201 ui_actiondata(package
,szProcessComponents
,uirow
);
4202 msiobj_release( &uirow
->hdr
);
4205 else if (ACTION_VerifyComponentForAction(package
, i
,
4206 INSTALLSTATE_ABSENT
))
4210 rc
= RegOpenKeyW(hkey
,squished_cc
,&hkey2
);
4211 if (rc
!= ERROR_SUCCESS
)
4214 RegDeleteValueW(hkey2
,squished_pc
);
4216 /* if the key is empty delete it */
4217 res
= RegEnumKeyExW(hkey2
,0,NULL
,0,0,NULL
,0,NULL
);
4219 if (res
== ERROR_NO_MORE_ITEMS
)
4220 RegDeleteKeyW(hkey
,squished_cc
);
4223 uirow
= MSI_CreateRecord(2);
4224 MSI_RecordSetStringW(uirow
,1,productcode
);
4225 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].
4227 ui_actiondata(package
,szProcessComponents
,uirow
);
4228 msiobj_release( &uirow
->hdr
);
4233 HeapFree(GetProcessHeap(), 0, productcode
);
4246 BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
4247 LPWSTR lpszName
, LONG_PTR lParam
)
4250 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
4251 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
4255 if (!IS_INTRESOURCE(lpszName
))
4257 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
4261 sz
= strlenW(tl_struct
->source
)+4;
4262 sz
*= sizeof(WCHAR
);
4264 if ((INT
)lpszName
== 1)
4265 tl_struct
->path
= strdupW(tl_struct
->source
);
4268 tl_struct
->path
= HeapAlloc(GetProcessHeap(),0,sz
);
4269 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
4272 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
4273 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
4274 if (!SUCCEEDED(res
))
4276 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
4277 tl_struct
->path
= NULL
;
4282 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
4283 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
4285 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
4289 HeapFree(GetProcessHeap(),0,tl_struct
->path
);
4290 tl_struct
->path
= NULL
;
4292 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
4293 ITypeLib_Release(tl_struct
->ptLib
);
4298 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
4301 * OK this is a bit confusing.. I am given a _Component key and I believe
4302 * that the file that is being registered as a type library is the "key file
4303 * of that component" which I interpret to mean "The file in the KeyPath of
4308 MSIRECORD
* row
= 0;
4309 static const WCHAR Query
[] =
4310 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4311 '`','T','y','p','e','L','i','b','`',0};
4314 return ERROR_INVALID_HANDLE
;
4316 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
4317 if (rc
!= ERROR_SUCCESS
)
4318 return ERROR_SUCCESS
;
4320 rc
= MSI_ViewExecute(view
, 0);
4321 if (rc
!= ERROR_SUCCESS
)
4323 MSI_ViewClose(view
);
4324 msiobj_release(&view
->hdr
);
4330 WCHAR component
[0x100];
4334 typelib_struct tl_struct
;
4336 static const WCHAR szTYPELIB
[] = {'T','Y','P','E','L','I','B',0};
4338 rc
= MSI_ViewFetch(view
,&row
);
4339 if (rc
!= ERROR_SUCCESS
)
4346 MSI_RecordGetStringW(row
,3,component
,&sz
);
4348 index
= get_loaded_component(package
,component
);
4351 msiobj_release(&row
->hdr
);
4355 if (!ACTION_VerifyComponentForAction(package
, index
,
4356 INSTALLSTATE_LOCAL
))
4358 TRACE("Skipping typelib reg due to disabled component\n");
4359 msiobj_release(&row
->hdr
);
4361 package
->components
[index
].Action
=
4362 package
->components
[index
].Installed
;
4367 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
4369 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
4373 msiobj_release(&row
->hdr
);
4377 guid
= load_dynamic_stringW(row
,1);
4378 module
= LoadLibraryExW(package
->files
[index
].TargetPath
, NULL
,
4379 LOAD_LIBRARY_AS_DATAFILE
);
4382 CLSIDFromString(guid
, &tl_struct
.clsid
);
4383 tl_struct
.source
= strdupW(package
->files
[index
].TargetPath
);
4384 tl_struct
.path
= NULL
;
4386 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
4387 (LONG_PTR
)&tl_struct
);
4389 if (tl_struct
.path
!= NULL
)
4392 WCHAR helpid
[0x100];
4396 MSI_RecordGetStringW(row
,6,helpid
,&sz
);
4398 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,NULL
);
4399 res
= RegisterTypeLib(tl_struct
.ptLib
,tl_struct
.path
,help
);
4400 HeapFree(GetProcessHeap(),0,help
);
4402 if (!SUCCEEDED(res
))
4403 ERR("Failed to register type library %s\n",
4404 debugstr_w(tl_struct
.path
));
4407 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
4409 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
4412 ITypeLib_Release(tl_struct
.ptLib
);
4413 HeapFree(GetProcessHeap(),0,tl_struct
.path
);
4416 ERR("Failed to load type library %s\n",
4417 debugstr_w(tl_struct
.source
));
4419 FreeLibrary(module
);
4420 HeapFree(GetProcessHeap(),0,tl_struct
.source
);
4423 ERR("Could not load file! %s\n",
4424 debugstr_w(package
->files
[index
].TargetPath
));
4425 msiobj_release(&row
->hdr
);
4427 MSI_ViewClose(view
);
4428 msiobj_release(&view
->hdr
);
4432 static INT
load_appid(MSIPACKAGE
* package
, MSIRECORD
*row
)
4434 DWORD index
= package
->loaded_appids
;
4438 /* fill in the data */
4440 package
->loaded_appids
++;
4441 if (package
->loaded_appids
== 1)
4442 package
->appids
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIAPPID
));
4444 package
->appids
= HeapReAlloc(GetProcessHeap(),0,
4445 package
->appids
, package
->loaded_appids
* sizeof(MSIAPPID
));
4447 memset(&package
->appids
[index
],0,sizeof(MSIAPPID
));
4449 sz
= IDENTIFIER_SIZE
;
4450 MSI_RecordGetStringW(row
, 1, package
->appids
[index
].AppID
, &sz
);
4451 TRACE("loading appid %s\n",debugstr_w(package
->appids
[index
].AppID
));
4453 buffer
= load_dynamic_stringW(row
,2);
4454 deformat_string(package
,buffer
,&package
->appids
[index
].RemoteServerName
);
4455 HeapFree(GetProcessHeap(),0,buffer
);
4457 package
->appids
[index
].LocalServer
= load_dynamic_stringW(row
,3);
4458 package
->appids
[index
].ServiceParameters
= load_dynamic_stringW(row
,4);
4459 package
->appids
[index
].DllSurrogate
= load_dynamic_stringW(row
,5);
4461 package
->appids
[index
].ActivateAtStorage
= !MSI_RecordIsNull(row
,6);
4462 package
->appids
[index
].RunAsInteractiveUser
= !MSI_RecordIsNull(row
,7);
4467 static INT
load_given_appid(MSIPACKAGE
*package
, LPCWSTR appid
)
4472 static const WCHAR ExecSeqQuery
[] =
4473 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4474 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
4475 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
4480 /* check for appids already loaded */
4481 for (i
= 0; i
< package
->loaded_appids
; i
++)
4482 if (strcmpiW(package
->appids
[i
].AppID
,appid
)==0)
4484 TRACE("found appid %s at index %i\n",debugstr_w(appid
),i
);
4488 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, appid
);
4492 rc
= load_appid(package
, row
);
4493 msiobj_release(&row
->hdr
);
4498 static INT
load_given_progid(MSIPACKAGE
*package
, LPCWSTR progid
);
4499 static INT
load_given_class(MSIPACKAGE
*package
, LPCWSTR classid
);
4501 static INT
load_progid(MSIPACKAGE
* package
, MSIRECORD
*row
)
4503 DWORD index
= package
->loaded_progids
;
4506 /* fill in the data */
4508 package
->loaded_progids
++;
4509 if (package
->loaded_progids
== 1)
4510 package
->progids
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIPROGID
));
4512 package
->progids
= HeapReAlloc(GetProcessHeap(),0,
4513 package
->progids
, package
->loaded_progids
* sizeof(MSIPROGID
));
4515 memset(&package
->progids
[index
],0,sizeof(MSIPROGID
));
4517 package
->progids
[index
].ProgID
= load_dynamic_stringW(row
,1);
4518 TRACE("loading progid %s\n",debugstr_w(package
->progids
[index
].ProgID
));
4520 buffer
= load_dynamic_stringW(row
,2);
4521 package
->progids
[index
].ParentIndex
= load_given_progid(package
,buffer
);
4522 if (package
->progids
[index
].ParentIndex
< 0 && buffer
)
4523 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer
));
4524 HeapFree(GetProcessHeap(),0,buffer
);
4526 buffer
= load_dynamic_stringW(row
,3);
4527 package
->progids
[index
].ClassIndex
= load_given_class(package
,buffer
);
4528 if (package
->progids
[index
].ClassIndex
< 0 && buffer
)
4529 FIXME("Unknown class %s\n",debugstr_w(buffer
));
4530 HeapFree(GetProcessHeap(),0,buffer
);
4532 package
->progids
[index
].Description
= load_dynamic_stringW(row
,4);
4534 if (!MSI_RecordIsNull(row
,6))
4536 INT icon_index
= MSI_RecordGetInteger(row
,6);
4537 LPWSTR FileName
= load_dynamic_stringW(row
,5);
4539 static const WCHAR fmt
[] = {'%','s',',','%','i',0};
4541 build_icon_path(package
,FileName
,&FilePath
);
4543 package
->progids
[index
].IconPath
=
4544 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath
)+10)*
4547 sprintfW(package
->progids
[index
].IconPath
,fmt
,FilePath
,icon_index
);
4549 HeapFree(GetProcessHeap(),0,FilePath
);
4550 HeapFree(GetProcessHeap(),0,FileName
);
4554 buffer
= load_dynamic_stringW(row
,5);
4556 build_icon_path(package
,buffer
,&(package
->progids
[index
].IconPath
));
4557 HeapFree(GetProcessHeap(),0,buffer
);
4560 package
->progids
[index
].CurVerIndex
= -1;
4561 package
->progids
[index
].VersionIndIndex
= -1;
4563 /* if we have a parent then we may be that parents CurVer */
4564 if (package
->progids
[index
].ParentIndex
>= 0 &&
4565 package
->progids
[index
].ParentIndex
!= index
)
4567 int pindex
= package
->progids
[index
].ParentIndex
;
4568 while (package
->progids
[pindex
].ParentIndex
>= 0)
4569 pindex
= package
->progids
[pindex
].ParentIndex
;
4571 FIXME("BAD BAD need to determing if we are really the CurVer\n");
4573 package
->progids
[index
].CurVerIndex
= pindex
;
4574 package
->progids
[pindex
].VersionIndIndex
= index
;
4580 static INT
load_given_progid(MSIPACKAGE
*package
, LPCWSTR progid
)
4585 static const WCHAR ExecSeqQuery
[] =
4586 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4587 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
4588 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
4593 /* check for progids already loaded */
4594 for (i
= 0; i
< package
->loaded_progids
; i
++)
4595 if (strcmpiW(package
->progids
[i
].ProgID
,progid
)==0)
4597 TRACE("found progid %s at index %i\n",debugstr_w(progid
), i
);
4601 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, progid
);
4605 rc
= load_progid(package
, row
);
4606 msiobj_release(&row
->hdr
);
4611 static INT
load_class(MSIPACKAGE
* package
, MSIRECORD
*row
)
4613 DWORD index
= package
->loaded_classes
;
4617 /* fill in the data */
4619 package
->loaded_classes
++;
4620 if (package
->loaded_classes
== 1)
4621 package
->classes
= HeapAlloc(GetProcessHeap(),0,sizeof(MSICLASS
));
4623 package
->classes
= HeapReAlloc(GetProcessHeap(),0,
4624 package
->classes
, package
->loaded_classes
* sizeof(MSICLASS
));
4626 memset(&package
->classes
[index
],0,sizeof(MSICLASS
));
4628 sz
= IDENTIFIER_SIZE
;
4629 MSI_RecordGetStringW(row
, 1, package
->classes
[index
].CLSID
, &sz
);
4630 TRACE("loading class %s\n",debugstr_w(package
->classes
[index
].CLSID
));
4631 sz
= IDENTIFIER_SIZE
;
4632 MSI_RecordGetStringW(row
, 2, package
->classes
[index
].Context
, &sz
);
4633 buffer
= load_dynamic_stringW(row
,3);
4634 package
->classes
[index
].ComponentIndex
= get_loaded_component(package
,
4636 HeapFree(GetProcessHeap(),0,buffer
);
4638 package
->classes
[index
].ProgIDText
= load_dynamic_stringW(row
,4);
4639 package
->classes
[index
].ProgIDIndex
=
4640 load_given_progid(package
, package
->classes
[index
].ProgIDText
);
4642 package
->classes
[index
].Description
= load_dynamic_stringW(row
,5);
4644 buffer
= load_dynamic_stringW(row
,6);
4646 package
->classes
[index
].AppIDIndex
=
4647 load_given_appid(package
, buffer
);
4649 package
->classes
[index
].AppIDIndex
= -1;
4650 HeapFree(GetProcessHeap(),0,buffer
);
4652 package
->classes
[index
].FileTypeMask
= load_dynamic_stringW(row
,7);
4654 if (!MSI_RecordIsNull(row
,9))
4657 INT icon_index
= MSI_RecordGetInteger(row
,9);
4658 LPWSTR FileName
= load_dynamic_stringW(row
,8);
4660 static const WCHAR fmt
[] = {'%','s',',','%','i',0};
4662 build_icon_path(package
,FileName
,&FilePath
);
4664 package
->classes
[index
].IconPath
=
4665 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath
)+5)*
4668 sprintfW(package
->classes
[index
].IconPath
,fmt
,FilePath
,icon_index
);
4670 HeapFree(GetProcessHeap(),0,FilePath
);
4671 HeapFree(GetProcessHeap(),0,FileName
);
4675 buffer
= load_dynamic_stringW(row
,8);
4677 build_icon_path(package
,buffer
,&(package
->classes
[index
].IconPath
));
4678 HeapFree(GetProcessHeap(),0,buffer
);
4681 if (!MSI_RecordIsNull(row
,10))
4683 i
= MSI_RecordGetInteger(row
,10);
4684 if (i
!= MSI_NULL_INTEGER
&& i
> 0 && i
< 4)
4686 static const WCHAR ole2
[] = {'o','l','e','2','.','d','l','l',0};
4687 static const WCHAR ole32
[] = {'o','l','e','3','2','.','d','l','l',0};
4692 package
->classes
[index
].DefInprocHandler
= strdupW(ole2
);
4695 package
->classes
[index
].DefInprocHandler32
= strdupW(ole32
);
4698 package
->classes
[index
].DefInprocHandler
= strdupW(ole2
);
4699 package
->classes
[index
].DefInprocHandler32
= strdupW(ole32
);
4705 package
->classes
[index
].DefInprocHandler32
= load_dynamic_stringW(
4707 reduce_to_longfilename(package
->classes
[index
].DefInprocHandler32
);
4710 buffer
= load_dynamic_stringW(row
,11);
4711 deformat_string(package
,buffer
,&package
->classes
[index
].Argument
);
4712 HeapFree(GetProcessHeap(),0,buffer
);
4714 buffer
= load_dynamic_stringW(row
,12);
4715 package
->classes
[index
].FeatureIndex
= get_loaded_feature(package
,buffer
);
4716 HeapFree(GetProcessHeap(),0,buffer
);
4718 package
->classes
[index
].Attributes
= MSI_RecordGetInteger(row
,13);
4724 * the Class table has 3 primary keys. Generally it is only
4725 * referenced through the first CLSID key. However when loading
4726 * all of the classes we need to make sure we do not ignore rows
4727 * with other Context and ComponentIndexs
4729 static INT
load_given_class(MSIPACKAGE
*package
, LPCWSTR classid
)
4734 static const WCHAR ExecSeqQuery
[] =
4735 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4736 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
4737 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
4743 /* check for classes already loaded */
4744 for (i
= 0; i
< package
->loaded_classes
; i
++)
4745 if (strcmpiW(package
->classes
[i
].CLSID
,classid
)==0)
4747 TRACE("found class %s at index %i\n",debugstr_w(classid
), i
);
4751 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, classid
);
4755 rc
= load_class(package
, row
);
4756 msiobj_release(&row
->hdr
);
4761 static INT
load_given_extension(MSIPACKAGE
*package
, LPCWSTR extension
);
4763 static INT
load_mime(MSIPACKAGE
* package
, MSIRECORD
*row
)
4765 DWORD index
= package
->loaded_mimes
;
4769 /* fill in the data */
4771 package
->loaded_mimes
++;
4772 if (package
->loaded_mimes
== 1)
4773 package
->mimes
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIMIME
));
4775 package
->mimes
= HeapReAlloc(GetProcessHeap(),0,
4776 package
->mimes
, package
->loaded_mimes
*
4779 memset(&package
->mimes
[index
],0,sizeof(MSIMIME
));
4781 package
->mimes
[index
].ContentType
= load_dynamic_stringW(row
,1);
4782 TRACE("loading mime %s\n",debugstr_w(package
->mimes
[index
].ContentType
));
4784 buffer
= load_dynamic_stringW(row
,2);
4785 package
->mimes
[index
].ExtensionIndex
= load_given_extension(package
,
4787 HeapFree(GetProcessHeap(),0,buffer
);
4789 sz
= IDENTIFIER_SIZE
;
4790 MSI_RecordGetStringW(row
,3,package
->mimes
[index
].CLSID
,&sz
);
4791 package
->mimes
[index
].ClassIndex
= load_given_class(package
,
4792 package
->mimes
[index
].CLSID
);
4797 static INT
load_given_mime(MSIPACKAGE
*package
, LPCWSTR mime
)
4802 static const WCHAR ExecSeqQuery
[] =
4803 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4804 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
4805 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
4806 '\'','%','s','\'',0};
4811 /* check for mime already loaded */
4812 for (i
= 0; i
< package
->loaded_mimes
; i
++)
4813 if (strcmpiW(package
->mimes
[i
].ContentType
,mime
)==0)
4815 TRACE("found mime %s at index %i\n",debugstr_w(mime
), i
);
4819 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, mime
);
4823 rc
= load_mime(package
, row
);
4824 msiobj_release(&row
->hdr
);
4829 static INT
load_extension(MSIPACKAGE
* package
, MSIRECORD
*row
)
4831 DWORD index
= package
->loaded_extensions
;
4835 /* fill in the data */
4837 package
->loaded_extensions
++;
4838 if (package
->loaded_extensions
== 1)
4839 package
->extensions
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIEXTENSION
));
4841 package
->extensions
= HeapReAlloc(GetProcessHeap(),0,
4842 package
->extensions
, package
->loaded_extensions
*
4843 sizeof(MSIEXTENSION
));
4845 memset(&package
->extensions
[index
],0,sizeof(MSIEXTENSION
));
4848 MSI_RecordGetStringW(row
,1,package
->extensions
[index
].Extension
,&sz
);
4849 TRACE("loading extension %s\n",
4850 debugstr_w(package
->extensions
[index
].Extension
));
4852 buffer
= load_dynamic_stringW(row
,2);
4853 package
->extensions
[index
].ComponentIndex
=
4854 get_loaded_component(package
,buffer
);
4855 HeapFree(GetProcessHeap(),0,buffer
);
4857 package
->extensions
[index
].ProgIDText
= load_dynamic_stringW(row
,3);
4858 package
->extensions
[index
].ProgIDIndex
= load_given_progid(package
,
4859 package
->extensions
[index
].ProgIDText
);
4861 buffer
= load_dynamic_stringW(row
,4);
4862 package
->extensions
[index
].MIMEIndex
= load_given_mime(package
,buffer
);
4863 HeapFree(GetProcessHeap(),0,buffer
);
4865 buffer
= load_dynamic_stringW(row
,5);
4866 package
->extensions
[index
].FeatureIndex
=
4867 get_loaded_feature(package
,buffer
);
4868 HeapFree(GetProcessHeap(),0,buffer
);
4874 * While the extension table has 2 primary keys, this function is only looking
4875 * at the Extension key which is what is referenced as a forign key
4877 static INT
load_given_extension(MSIPACKAGE
*package
, LPCWSTR extension
)
4882 static const WCHAR ExecSeqQuery
[] =
4883 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4884 '`','E','x','t','e','n','s','i','o','n','`',' ',
4885 'W','H','E','R','E',' ',
4886 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
4887 '\'','%','s','\'',0};
4892 /* check for extensions already loaded */
4893 for (i
= 0; i
< package
->loaded_extensions
; i
++)
4894 if (strcmpiW(package
->extensions
[i
].Extension
,extension
)==0)
4896 TRACE("extension %s already loaded at %i\n",debugstr_w(extension
),
4901 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, extension
);
4905 rc
= load_extension(package
, row
);
4906 msiobj_release(&row
->hdr
);
4911 static UINT
iterate_load_verb(MSIRECORD
*row
, LPVOID param
)
4913 MSIPACKAGE
* package
= (MSIPACKAGE
*)param
;
4914 DWORD index
= package
->loaded_verbs
;
4917 /* fill in the data */
4919 package
->loaded_verbs
++;
4920 if (package
->loaded_verbs
== 1)
4921 package
->verbs
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIVERB
));
4923 package
->verbs
= HeapReAlloc(GetProcessHeap(),0,
4924 package
->verbs
, package
->loaded_verbs
* sizeof(MSIVERB
));
4926 memset(&package
->verbs
[index
],0,sizeof(MSIVERB
));
4928 buffer
= load_dynamic_stringW(row
,1);
4929 package
->verbs
[index
].ExtensionIndex
= load_given_extension(package
,buffer
);
4930 if (package
->verbs
[index
].ExtensionIndex
< 0 && buffer
)
4931 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer
));
4932 HeapFree(GetProcessHeap(),0,buffer
);
4934 package
->verbs
[index
].Verb
= load_dynamic_stringW(row
,2);
4935 TRACE("loading verb %s\n",debugstr_w(package
->verbs
[index
].Verb
));
4936 package
->verbs
[index
].Sequence
= MSI_RecordGetInteger(row
,3);
4938 buffer
= load_dynamic_stringW(row
,4);
4939 deformat_string(package
,buffer
,&package
->verbs
[index
].Command
);
4940 HeapFree(GetProcessHeap(),0,buffer
);
4942 buffer
= load_dynamic_stringW(row
,5);
4943 deformat_string(package
,buffer
,&package
->verbs
[index
].Argument
);
4944 HeapFree(GetProcessHeap(),0,buffer
);
4946 /* assosiate the verb with the correct extension */
4947 if (package
->verbs
[index
].ExtensionIndex
>= 0)
4949 MSIEXTENSION
* extension
= &package
->extensions
[package
->verbs
[index
].
4951 int count
= extension
->VerbCount
;
4954 FIXME("Exceeding max verb count! Increase that limit!!!\n");
4957 extension
->VerbCount
++;
4958 extension
->Verbs
[count
] = index
;
4962 return ERROR_SUCCESS
;
4965 static UINT
iterate_all_classes(MSIRECORD
*rec
, LPVOID param
)
4970 INT component_index
;
4971 MSIPACKAGE
* package
=(MSIPACKAGE
*)param
;
4975 clsid
= load_dynamic_stringW(rec
,1);
4976 context
= load_dynamic_stringW(rec
,2);
4977 buffer
= load_dynamic_stringW(rec
,3);
4978 component_index
= get_loaded_component(package
,buffer
);
4980 for (i
= 0; i
< package
->loaded_classes
; i
++)
4982 if (strcmpiW(clsid
,package
->classes
[i
].CLSID
))
4984 if (strcmpW(context
,package
->classes
[i
].Context
))
4986 if (component_index
== package
->classes
[i
].ComponentIndex
)
4993 HeapFree(GetProcessHeap(),0,buffer
);
4994 HeapFree(GetProcessHeap(),0,clsid
);
4995 HeapFree(GetProcessHeap(),0,context
);
4998 load_class(package
, rec
);
5000 return ERROR_SUCCESS
;
5003 static VOID
load_all_classes(MSIPACKAGE
*package
)
5005 UINT rc
= ERROR_SUCCESS
;
5008 static const WCHAR ExecSeqQuery
[] =
5009 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
5010 '`','C','l','a','s','s','`',0};
5012 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5013 if (rc
!= ERROR_SUCCESS
)
5016 rc
= MSI_IterateRecords(view
, NULL
, iterate_all_classes
, package
);
5017 msiobj_release(&view
->hdr
);
5020 static UINT
iterate_all_extensions(MSIRECORD
*rec
, LPVOID param
)
5024 INT component_index
;
5025 MSIPACKAGE
* package
=(MSIPACKAGE
*)param
;
5029 extension
= load_dynamic_stringW(rec
,1);
5030 buffer
= load_dynamic_stringW(rec
,2);
5031 component_index
= get_loaded_component(package
,buffer
);
5033 for (i
= 0; i
< package
->loaded_extensions
; i
++)
5035 if (strcmpiW(extension
,package
->extensions
[i
].Extension
))
5037 if (component_index
== package
->extensions
[i
].ComponentIndex
)
5044 HeapFree(GetProcessHeap(),0,buffer
);
5045 HeapFree(GetProcessHeap(),0,extension
);
5048 load_extension(package
, rec
);
5050 return ERROR_SUCCESS
;
5053 static VOID
load_all_extensions(MSIPACKAGE
*package
)
5055 UINT rc
= ERROR_SUCCESS
;
5058 static const WCHAR ExecSeqQuery
[] =
5059 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5060 '`','E','x','t','e','n','s','i','o','n','`',0};
5062 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5063 if (rc
!= ERROR_SUCCESS
)
5066 rc
= MSI_IterateRecords(view
, NULL
, iterate_all_extensions
, package
);
5067 msiobj_release(&view
->hdr
);
5070 static UINT
iterate_all_progids(MSIRECORD
*rec
, LPVOID param
)
5073 MSIPACKAGE
* package
=(MSIPACKAGE
*)param
;
5075 buffer
= load_dynamic_stringW(rec
,1);
5076 load_given_progid(package
,buffer
);
5077 HeapFree(GetProcessHeap(),0,buffer
);
5078 return ERROR_SUCCESS
;
5081 static VOID
load_all_progids(MSIPACKAGE
*package
)
5083 UINT rc
= ERROR_SUCCESS
;
5086 static const WCHAR ExecSeqQuery
[] =
5087 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
5088 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
5090 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5091 if (rc
!= ERROR_SUCCESS
)
5094 rc
= MSI_IterateRecords(view
, NULL
, iterate_all_progids
, package
);
5095 msiobj_release(&view
->hdr
);
5098 static VOID
load_all_verbs(MSIPACKAGE
*package
)
5100 UINT rc
= ERROR_SUCCESS
;
5103 static const WCHAR ExecSeqQuery
[] =
5104 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5105 '`','V','e','r','b','`',0};
5107 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5108 if (rc
!= ERROR_SUCCESS
)
5111 rc
= MSI_IterateRecords(view
, NULL
, iterate_load_verb
, package
);
5112 msiobj_release(&view
->hdr
);
5115 static UINT
iterate_all_mimes(MSIRECORD
*rec
, LPVOID param
)
5118 MSIPACKAGE
* package
=(MSIPACKAGE
*)param
;
5120 buffer
= load_dynamic_stringW(rec
,1);
5121 load_given_mime(package
,buffer
);
5122 HeapFree(GetProcessHeap(),0,buffer
);
5123 return ERROR_SUCCESS
;
5126 static VOID
load_all_mimes(MSIPACKAGE
*package
)
5128 UINT rc
= ERROR_SUCCESS
;
5131 static const WCHAR ExecSeqQuery
[] =
5132 {'S','E','L','E','C','T',' ',
5133 '`','C','o','n','t','e','n','t','T','y','p','e','`',
5134 ' ','F','R','O','M',' ',
5135 '`','M','I','M','E','`',0};
5137 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5138 if (rc
!= ERROR_SUCCESS
)
5141 rc
= MSI_IterateRecords(view
, NULL
, iterate_all_mimes
, package
);
5142 msiobj_release(&view
->hdr
);
5145 static void load_classes_and_such(MSIPACKAGE
*package
)
5147 TRACE("Loading all the class info and related tables\n");
5149 /* check if already loaded */
5150 if (package
->classes
|| package
->extensions
|| package
->progids
||
5151 package
->verbs
|| package
->mimes
)
5154 load_all_classes(package
);
5155 load_all_extensions(package
);
5156 load_all_progids(package
);
5157 /* these loads must come after the other loads */
5158 load_all_verbs(package
);
5159 load_all_mimes(package
);
5162 static void mark_progid_for_install(MSIPACKAGE
* package
, INT index
)
5167 if (index
< 0 || index
>= package
->loaded_progids
)
5170 progid
= &package
->progids
[index
];
5172 if (progid
->InstallMe
== TRUE
)
5175 progid
->InstallMe
= TRUE
;
5177 /* all children if this is a parent also install */
5178 for (i
= 0; i
< package
->loaded_progids
; i
++)
5179 if (package
->progids
[i
].ParentIndex
== index
)
5180 mark_progid_for_install(package
,i
);
5183 static void mark_mime_for_install(MSIPACKAGE
* package
, INT index
)
5187 if (index
< 0 || index
>= package
->loaded_mimes
)
5190 mime
= &package
->mimes
[index
];
5192 if (mime
->InstallMe
== TRUE
)
5195 mime
->InstallMe
= TRUE
;
5198 static UINT
register_appid(MSIPACKAGE
*package
, int appidIndex
, LPCWSTR app
)
5200 static const WCHAR szAppID
[] = { 'A','p','p','I','D',0 };
5204 return ERROR_INVALID_HANDLE
;
5206 RegCreateKeyW(HKEY_CLASSES_ROOT
,szAppID
,&hkey2
);
5207 RegCreateKeyW(hkey2
,package
->appids
[appidIndex
].AppID
,&hkey3
);
5208 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)app
,
5209 (strlenW(app
)+1)*sizeof(WCHAR
));
5211 if (package
->appids
[appidIndex
].RemoteServerName
)
5214 static const WCHAR szRemoteServerName
[] =
5215 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
5218 size
= (strlenW(package
->appids
[appidIndex
].RemoteServerName
)+1) *
5221 RegSetValueExW(hkey3
,szRemoteServerName
,0,REG_SZ
,
5222 (LPVOID
)package
->appids
[appidIndex
].RemoteServerName
,
5226 if (package
->appids
[appidIndex
].LocalServer
)
5228 static const WCHAR szLocalService
[] =
5229 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
5231 size
= (strlenW(package
->appids
[appidIndex
].LocalServer
)+1) *
5234 RegSetValueExW(hkey3
,szLocalService
,0,REG_SZ
,
5235 (LPVOID
)package
->appids
[appidIndex
].LocalServer
,size
);
5238 if (package
->appids
[appidIndex
].ServiceParameters
)
5240 static const WCHAR szService
[] =
5241 {'S','e','r','v','i','c','e',
5242 'P','a','r','a','m','e','t','e','r','s',0};
5244 size
= (strlenW(package
->appids
[appidIndex
].ServiceParameters
)+1) *
5246 RegSetValueExW(hkey3
,szService
,0,REG_SZ
,
5247 (LPVOID
)package
->appids
[appidIndex
].ServiceParameters
,
5251 if (package
->appids
[appidIndex
].DllSurrogate
)
5253 static const WCHAR szDLL
[] =
5254 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
5256 size
= (strlenW(package
->appids
[appidIndex
].DllSurrogate
)+1) *
5258 RegSetValueExW(hkey3
,szDLL
,0,REG_SZ
,
5259 (LPVOID
)package
->appids
[appidIndex
].DllSurrogate
,size
);
5262 if (package
->appids
[appidIndex
].ActivateAtStorage
)
5264 static const WCHAR szActivate
[] =
5265 {'A','c','t','i','v','a','t','e','A','s',
5266 'S','t','o','r','a','g','e',0};
5267 static const WCHAR szY
[] = {'Y',0};
5269 RegSetValueExW(hkey3
,szActivate
,0,REG_SZ
,(LPVOID
)szY
,4);
5272 if (package
->appids
[appidIndex
].RunAsInteractiveUser
)
5274 static const WCHAR szRunAs
[] = {'R','u','n','A','s',0};
5275 static const WCHAR szUser
[] =
5276 {'I','n','t','e','r','a','c','t','i','v','e',' ',
5279 RegSetValueExW(hkey3
,szRunAs
,0,REG_SZ
,(LPVOID
)szUser
,sizeof(szUser
));
5284 return ERROR_SUCCESS
;
5287 static UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
)
5290 * Again I am assuming the words, "Whose key file represents" when referring
5291 * to a Component as to meaning that Components KeyPath file
5296 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
5297 static const WCHAR szProgID
[] = { 'P','r','o','g','I','D',0 };
5298 static const WCHAR szVIProgID
[] = { 'V','e','r','s','i','o','n','I','n','d','e','p','e','n','d','e','n','t','P','r','o','g','I','D',0 };
5299 static const WCHAR szAppID
[] = { 'A','p','p','I','D',0 };
5300 static const WCHAR szSpace
[] = {' ',0};
5301 static const WCHAR szInprocServer32
[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
5302 static const WCHAR szFileType_fmt
[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
5303 HKEY hkey
,hkey2
,hkey3
;
5304 BOOL install_on_demand
= FALSE
;
5308 return ERROR_INVALID_HANDLE
;
5310 load_classes_and_such(package
);
5311 rc
= RegCreateKeyW(HKEY_CLASSES_ROOT
,szCLSID
,&hkey
);
5312 if (rc
!= ERROR_SUCCESS
)
5313 return ERROR_FUNCTION_FAILED
;
5315 /* install_on_demand should be set if OLE supports install on demand OLE
5316 * servers. For now i am defaulting to FALSE because i do not know how to
5317 * check, and i am told our builtin OLE does not support it
5320 for (i
= 0; i
< package
->loaded_classes
; i
++)
5326 if (package
->classes
[i
].ComponentIndex
< 0)
5331 index
= package
->classes
[i
].ComponentIndex
;
5332 f_index
= package
->classes
[i
].FeatureIndex
;
5335 * yes. MSDN says that these are based on _Feature_ not on
5336 * Component. So verify the feature is to be installed
5338 if ((!ACTION_VerifyFeatureForAction(package
, f_index
,
5339 INSTALLSTATE_LOCAL
)) &&
5340 !(install_on_demand
&& ACTION_VerifyFeatureForAction(package
,
5341 f_index
, INSTALLSTATE_ADVERTISED
)))
5343 TRACE("Skipping class %s reg due to disabled feature %s\n",
5344 debugstr_w(package
->classes
[i
].CLSID
),
5345 debugstr_w(package
->features
[f_index
].Feature
));
5350 TRACE("Registering index %i class %s\n",i
,
5351 debugstr_w(package
->classes
[i
].CLSID
));
5353 package
->classes
[i
].Installed
= TRUE
;
5354 if (package
->classes
[i
].ProgIDIndex
>= 0)
5355 mark_progid_for_install(package
, package
->classes
[i
].ProgIDIndex
);
5357 RegCreateKeyW(hkey
,package
->classes
[i
].CLSID
,&hkey2
);
5359 if (package
->classes
[i
].Description
)
5360 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)package
->classes
[i
].
5361 Description
, (strlenW(package
->classes
[i
].
5362 Description
)+1)*sizeof(WCHAR
));
5364 RegCreateKeyW(hkey2
,package
->classes
[i
].Context
,&hkey3
);
5365 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
5368 /* the context server is a short path name
5369 * except for if it is InprocServer32...
5371 if (strcmpiW(package
->classes
[i
].Context
,szInprocServer32
)!=0)
5374 sz
= GetShortPathNameW(package
->files
[index
].TargetPath
, NULL
, 0);
5377 ERR("Unable to find short path for CLSID COM Server\n");
5382 size
= sz
* sizeof(WCHAR
);
5384 if (package
->classes
[i
].Argument
)
5386 size
+= strlenW(package
->classes
[i
].Argument
) *
5388 size
+= sizeof(WCHAR
);
5391 argument
= HeapAlloc(GetProcessHeap(), 0, size
+ sizeof(WCHAR
));
5392 GetShortPathNameW(package
->files
[index
].TargetPath
, argument
,
5395 if (package
->classes
[i
].Argument
)
5397 strcatW(argument
,szSpace
);
5398 strcatW(argument
,package
->classes
[i
].Argument
);
5404 size
= lstrlenW(package
->files
[index
].TargetPath
) * sizeof(WCHAR
);
5406 if (package
->classes
[i
].Argument
)
5408 size
+= strlenW(package
->classes
[i
].Argument
) * sizeof(WCHAR
);
5409 size
+= sizeof(WCHAR
);
5412 argument
= HeapAlloc(GetProcessHeap(), 0, size
+ sizeof(WCHAR
));
5413 strcpyW(argument
, package
->files
[index
].TargetPath
);
5415 if (package
->classes
[i
].Argument
)
5417 strcatW(argument
,szSpace
);
5418 strcatW(argument
,package
->classes
[i
].Argument
);
5424 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
, (LPVOID
)argument
, size
);
5425 HeapFree(GetProcessHeap(),0,argument
);
5430 if (package
->classes
[i
].ProgIDIndex
>= 0 ||
5431 package
->classes
[i
].ProgIDText
)
5435 if (package
->classes
[i
].ProgIDIndex
>= 0)
5436 progid
= package
->progids
[
5437 package
->classes
[i
].ProgIDIndex
].ProgID
;
5439 progid
= package
->classes
[i
].ProgIDText
;
5441 RegCreateKeyW(hkey2
,szProgID
,&hkey3
);
5442 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)progid
,
5443 (strlenW(progid
)+1) *sizeof(WCHAR
));
5446 if (package
->classes
[i
].ProgIDIndex
>= 0 &&
5447 package
->progids
[package
->classes
[i
].ProgIDIndex
].
5448 VersionIndIndex
>= 0)
5450 LPWSTR viprogid
= strdupW(package
->progids
[package
->progids
[
5451 package
->classes
[i
].ProgIDIndex
].VersionIndIndex
].
5453 RegCreateKeyW(hkey2
,szVIProgID
,&hkey3
);
5454 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)viprogid
,
5455 (strlenW(viprogid
)+1) *sizeof(WCHAR
));
5457 HeapFree(GetProcessHeap(), 0, viprogid
);
5461 if (package
->classes
[i
].AppIDIndex
>= 0)
5463 RegSetValueExW(hkey2
,szAppID
,0,REG_SZ
,
5464 (LPVOID
)package
->appids
[package
->classes
[i
].AppIDIndex
].AppID
,
5465 (strlenW(package
->appids
[package
->classes
[i
].AppIDIndex
].AppID
)+1)
5468 register_appid(package
,package
->classes
[i
].AppIDIndex
,
5469 package
->classes
[i
].Description
);
5472 if (package
->classes
[i
].IconPath
)
5474 static const WCHAR szDefaultIcon
[] =
5475 {'D','e','f','a','u','l','t','I','c','o','n',0};
5477 RegCreateKeyW(hkey2
,szDefaultIcon
,&hkey3
);
5479 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,
5480 (LPVOID
)package
->classes
[i
].IconPath
,
5481 (strlenW(package
->classes
[i
].IconPath
)+1) *
5487 if (package
->classes
[i
].DefInprocHandler
)
5489 static const WCHAR szInproc
[] =
5490 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
5492 size
= (strlenW(package
->classes
[i
].DefInprocHandler
) + 1) *
5494 RegCreateKeyW(hkey2
,szInproc
,&hkey3
);
5495 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,
5496 (LPVOID
)package
->classes
[i
].DefInprocHandler
, size
);
5500 if (package
->classes
[i
].DefInprocHandler32
)
5502 static const WCHAR szInproc32
[] =
5503 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
5505 size
= (strlenW(package
->classes
[i
].DefInprocHandler32
) + 1) *
5508 RegCreateKeyW(hkey2
,szInproc32
,&hkey3
);
5509 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,
5510 (LPVOID
)package
->classes
[i
].DefInprocHandler32
,size
);
5516 /* if there is a FileTypeMask, register the FileType */
5517 if (package
->classes
[i
].FileTypeMask
)
5522 ptr
= package
->classes
[i
].FileTypeMask
;
5525 ptr2
= strchrW(ptr
,';');
5528 keyname
= HeapAlloc(GetProcessHeap(),0,(strlenW(szFileType_fmt
)+
5529 strlenW(package
->classes
[i
].CLSID
) + 4)
5531 sprintfW(keyname
,szFileType_fmt
, package
->classes
[i
].CLSID
,
5534 RegCreateKeyW(HKEY_CLASSES_ROOT
,keyname
,&hkey2
);
5535 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
, (LPVOID
)ptr
,
5536 strlenW(ptr
)*sizeof(WCHAR
));
5538 HeapFree(GetProcessHeap(), 0, keyname
);
5549 uirow
= MSI_CreateRecord(1);
5551 MSI_RecordSetStringW(uirow
,1,package
->classes
[i
].CLSID
);
5552 ui_actiondata(package
,szRegisterClassInfo
,uirow
);
5553 msiobj_release(&uirow
->hdr
);
5560 static UINT
register_progid_base(MSIPACKAGE
* package
, MSIPROGID
* progid
,
5563 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
5564 static const WCHAR szDefaultIcon
[] =
5565 {'D','e','f','a','u','l','t','I','c','o','n',0};
5568 RegCreateKeyW(HKEY_CLASSES_ROOT
,progid
->ProgID
,&hkey
);
5570 if (progid
->Description
)
5572 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,
5573 (LPVOID
)progid
->Description
,
5574 (strlenW(progid
->Description
)+1) *
5578 if (progid
->ClassIndex
>= 0)
5580 RegCreateKeyW(hkey
,szCLSID
,&hkey2
);
5581 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,
5582 (LPVOID
)package
->classes
[progid
->ClassIndex
].CLSID
,
5583 (strlenW(package
->classes
[progid
->ClassIndex
].CLSID
)+1)
5587 strcpyW(clsid
,package
->classes
[progid
->ClassIndex
].CLSID
);
5593 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
5596 if (progid
->IconPath
)
5598 RegCreateKeyW(hkey
,szDefaultIcon
,&hkey2
);
5600 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)progid
->IconPath
,
5601 (strlenW(progid
->IconPath
)+1) * sizeof(WCHAR
));
5604 return ERROR_SUCCESS
;
5607 static UINT
register_progid(MSIPACKAGE
*package
, MSIPROGID
* progid
,
5610 UINT rc
= ERROR_SUCCESS
;
5612 if (progid
->ParentIndex
< 0)
5613 rc
= register_progid_base(package
, progid
, clsid
);
5618 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
5619 static const WCHAR szDefaultIcon
[] =
5620 {'D','e','f','a','u','l','t','I','c','o','n',0};
5621 static const WCHAR szCurVer
[] =
5622 {'C','u','r','V','e','r',0};
5624 /* check if already registered */
5625 RegCreateKeyExW(HKEY_CLASSES_ROOT
, progid
->ProgID
, 0, NULL
, 0,
5626 KEY_ALL_ACCESS
, NULL
, &hkey
, &disp
);
5627 if (disp
== REG_OPENED_EXISTING_KEY
)
5629 TRACE("Key already registered\n");
5634 TRACE("Registering Parent %s index %i\n",
5635 debugstr_w(package
->progids
[progid
->ParentIndex
].ProgID
),
5636 progid
->ParentIndex
);
5637 rc
= register_progid(package
,&package
->progids
[progid
->ParentIndex
],
5640 /* clsid is same as parent */
5641 RegCreateKeyW(hkey
,szCLSID
,&hkey2
);
5642 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)clsid
, (strlenW(clsid
)+1) *
5648 if (progid
->Description
)
5650 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)progid
->Description
,
5651 (strlenW(progid
->Description
)+1) * sizeof(WCHAR
));
5654 if (progid
->IconPath
)
5656 RegCreateKeyW(hkey
,szDefaultIcon
,&hkey2
);
5657 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)progid
->IconPath
,
5658 (strlenW(progid
->IconPath
)+1) * sizeof(WCHAR
));
5662 /* write out the current version */
5663 if (progid
->CurVerIndex
>= 0)
5665 RegCreateKeyW(hkey
,szCurVer
,&hkey2
);
5666 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,
5667 (LPVOID
)package
->progids
[progid
->CurVerIndex
].ProgID
,
5668 (strlenW(package
->progids
[progid
->CurVerIndex
].ProgID
)+1) *
5678 static UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
)
5684 return ERROR_INVALID_HANDLE
;
5686 load_classes_and_such(package
);
5688 for (i
= 0; i
< package
->loaded_progids
; i
++)
5690 WCHAR clsid
[0x1000];
5692 /* check if this progid is to be installed */
5693 package
->progids
[i
].InstallMe
= ((package
->progids
[i
].InstallMe
) ||
5694 (package
->progids
[i
].ClassIndex
>= 0 &&
5695 package
->classes
[package
->progids
[i
].ClassIndex
].Installed
));
5697 if (!package
->progids
[i
].InstallMe
)
5699 TRACE("progid %s not scheduled to be installed\n",
5700 debugstr_w(package
->progids
[i
].ProgID
));
5704 TRACE("Registering progid %s index %i\n",
5705 debugstr_w(package
->progids
[i
].ProgID
), i
);
5707 register_progid(package
,&package
->progids
[i
],clsid
);
5709 uirow
= MSI_CreateRecord(1);
5710 MSI_RecordSetStringW(uirow
,1,package
->progids
[i
].ProgID
);
5711 ui_actiondata(package
,szRegisterProgIdInfo
,uirow
);
5712 msiobj_release(&uirow
->hdr
);
5715 return ERROR_SUCCESS
;
5718 static UINT
build_icon_path(MSIPACKAGE
*package
, LPCWSTR icon_name
,
5722 LPWSTR SystemFolder
;
5726 static const WCHAR szInstaller
[] =
5727 {'M','i','c','r','o','s','o','f','t','\\',
5728 'I','n','s','t','a','l','l','e','r','\\',0};
5729 static const WCHAR szFolder
[] =
5730 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
5732 ProductCode
= load_dynamic_property(package
,szProductCode
,&rc
);
5736 SystemFolder
= load_dynamic_property(package
,szFolder
,NULL
);
5738 dest
= build_directory_name(3, SystemFolder
, szInstaller
, ProductCode
);
5740 create_full_pathW(dest
);
5742 *FilePath
= build_directory_name(2, dest
, icon_name
);
5744 HeapFree(GetProcessHeap(),0,SystemFolder
);
5745 HeapFree(GetProcessHeap(),0,ProductCode
);
5746 HeapFree(GetProcessHeap(),0,dest
);
5747 return ERROR_SUCCESS
;
5750 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
5754 MSIRECORD
* row
= 0;
5755 static const WCHAR Query
[] =
5756 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5757 '`','S','h','o','r','t','c','u','t','`',0};
5763 return ERROR_INVALID_HANDLE
;
5765 res
= CoInitialize( NULL
);
5768 ERR("CoInitialize failed\n");
5769 return ERROR_FUNCTION_FAILED
;
5772 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
5773 if (rc
!= ERROR_SUCCESS
)
5774 return ERROR_SUCCESS
;
5776 rc
= MSI_ViewExecute(view
, 0);
5777 if (rc
!= ERROR_SUCCESS
)
5779 MSI_ViewClose(view
);
5780 msiobj_release(&view
->hdr
);
5786 LPWSTR target_file
, target_folder
;
5787 WCHAR buffer
[0x100];
5790 static const WCHAR szlnk
[]={'.','l','n','k',0};
5792 rc
= MSI_ViewFetch(view
,&row
);
5793 if (rc
!= ERROR_SUCCESS
)
5800 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
5802 index
= get_loaded_component(package
,buffer
);
5806 msiobj_release(&row
->hdr
);
5810 if (!ACTION_VerifyComponentForAction(package
, index
,
5811 INSTALLSTATE_LOCAL
))
5813 TRACE("Skipping shortcut creation due to disabled component\n");
5814 msiobj_release(&row
->hdr
);
5816 package
->components
[index
].Action
=
5817 package
->components
[index
].Installed
;
5822 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
5824 ui_actiondata(package
,szCreateShortcuts
,row
);
5826 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
5827 &IID_IShellLinkW
, (LPVOID
*) &sl
);
5831 ERR("Is IID_IShellLink\n");
5832 msiobj_release(&row
->hdr
);
5836 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
5839 ERR("Is IID_IPersistFile\n");
5840 msiobj_release(&row
->hdr
);
5845 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
5846 target_folder
= resolve_folder(package
, buffer
,FALSE
,FALSE
,NULL
);
5848 /* may be needed because of a bug somehwere else */
5849 create_full_pathW(target_folder
);
5852 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
5853 reduce_to_longfilename(buffer
);
5854 if (!strchrW(buffer
,'.') || strcmpiW(strchrW(buffer
,'.'),szlnk
))
5855 strcatW(buffer
,szlnk
);
5856 target_file
= build_directory_name(2, target_folder
, buffer
);
5857 HeapFree(GetProcessHeap(),0,target_folder
);
5860 MSI_RecordGetStringW(row
,5,buffer
,&sz
);
5861 if (strchrW(buffer
,'['))
5864 deformat_string(package
,buffer
,&deformated
);
5865 IShellLinkW_SetPath(sl
,deformated
);
5866 HeapFree(GetProcessHeap(),0,deformated
);
5871 FIXME("poorly handled shortcut format, advertised shortcut\n");
5872 keypath
= strdupW(package
->components
[index
].FullKeypath
);
5873 IShellLinkW_SetPath(sl
,keypath
);
5874 HeapFree(GetProcessHeap(),0,keypath
);
5877 if (!MSI_RecordIsNull(row
,6))
5881 MSI_RecordGetStringW(row
,6,buffer
,&sz
);
5882 deformat_string(package
,buffer
,&deformated
);
5883 IShellLinkW_SetArguments(sl
,deformated
);
5884 HeapFree(GetProcessHeap(),0,deformated
);
5887 if (!MSI_RecordIsNull(row
,7))
5890 deformated
= load_dynamic_stringW(row
,7);
5891 IShellLinkW_SetDescription(sl
,deformated
);
5892 HeapFree(GetProcessHeap(),0,deformated
);
5895 if (!MSI_RecordIsNull(row
,8))
5896 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
5898 if (!MSI_RecordIsNull(row
,9))
5904 MSI_RecordGetStringW(row
,9,buffer
,&sz
);
5906 build_icon_path(package
,buffer
,&Path
);
5907 index
= MSI_RecordGetInteger(row
,10);
5909 IShellLinkW_SetIconLocation(sl
,Path
,index
);
5910 HeapFree(GetProcessHeap(),0,Path
);
5913 if (!MSI_RecordIsNull(row
,11))
5914 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
5916 if (!MSI_RecordIsNull(row
,12))
5920 MSI_RecordGetStringW(row
,12,buffer
,&sz
);
5921 Path
= resolve_folder(package
, buffer
, FALSE
, FALSE
, NULL
);
5922 IShellLinkW_SetWorkingDirectory(sl
,Path
);
5923 HeapFree(GetProcessHeap(), 0, Path
);
5926 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
5927 IPersistFile_Save(pf
,target_file
,FALSE
);
5929 HeapFree(GetProcessHeap(),0,target_file
);
5931 IPersistFile_Release( pf
);
5932 IShellLinkW_Release( sl
);
5934 msiobj_release(&row
->hdr
);
5936 MSI_ViewClose(view
);
5937 msiobj_release(&view
->hdr
);
5947 * 99% of the work done here is only done for
5948 * advertised installs. However this is where the
5949 * Icon table is processed and written out
5950 * so that is what I am going to do here.
5952 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
5956 MSIRECORD
* row
= 0;
5957 static const WCHAR Query
[]=
5958 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5959 '`','I','c','o','n','`',0};
5961 /* for registry stuff */
5965 static const WCHAR szProductName
[] =
5966 {'P','r','o','d','u','c','t','N','a','m','e',0};
5967 static const WCHAR szPackageCode
[] =
5968 {'P','a','c','k','a','g','e','C','o','d','e',0};
5971 MSIHANDLE hDb
, hSumInfo
;
5974 return ERROR_INVALID_HANDLE
;
5976 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
5977 if (rc
!= ERROR_SUCCESS
)
5980 rc
= MSI_ViewExecute(view
, 0);
5981 if (rc
!= ERROR_SUCCESS
)
5983 MSI_ViewClose(view
);
5984 msiobj_release(&view
->hdr
);
5991 WCHAR
*FilePath
=NULL
;
5992 WCHAR
*FileName
=NULL
;
5995 rc
= MSI_ViewFetch(view
,&row
);
5996 if (rc
!= ERROR_SUCCESS
)
6002 FileName
= load_dynamic_stringW(row
,1);
6005 ERR("Unable to get FileName\n");
6006 msiobj_release(&row
->hdr
);
6010 build_icon_path(package
,FileName
,&FilePath
);
6012 HeapFree(GetProcessHeap(),0,FileName
);
6014 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
6016 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
6017 FILE_ATTRIBUTE_NORMAL
, NULL
);
6019 if (the_file
== INVALID_HANDLE_VALUE
)
6021 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
6022 msiobj_release(&row
->hdr
);
6023 HeapFree(GetProcessHeap(),0,FilePath
);
6031 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
6032 if (rc
!= ERROR_SUCCESS
)
6034 ERR("Failed to get stream\n");
6035 CloseHandle(the_file
);
6036 DeleteFileW(FilePath
);
6039 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
6040 } while (sz
== 1024);
6042 HeapFree(GetProcessHeap(),0,FilePath
);
6044 CloseHandle(the_file
);
6045 msiobj_release(&row
->hdr
);
6047 MSI_ViewClose(view
);
6048 msiobj_release(&view
->hdr
);
6051 /* ok there is a lot more done here but i need to figure out what */
6052 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
6056 rc
= MSIREG_OpenProductsKey(productcode
,&hkey
,TRUE
);
6057 if (rc
!= ERROR_SUCCESS
)
6060 rc
= MSIREG_OpenUserProductsKey(productcode
,&hukey
,TRUE
);
6061 if (rc
!= ERROR_SUCCESS
)
6065 buffer
= load_dynamic_property(package
,szProductName
,NULL
);
6066 size
= strlenW(buffer
)*sizeof(WCHAR
);
6067 RegSetValueExW(hukey
,szProductName
,0,REG_SZ
, (LPSTR
)buffer
,size
);
6068 HeapFree(GetProcessHeap(),0,buffer
);
6069 FIXME("Need to write more keys to the user registry\n");
6071 hDb
= alloc_msihandle( &package
->db
->hdr
);
6072 rc
= MsiGetSummaryInformationW(hDb
, NULL
, 0, &hSumInfo
);
6073 MsiCloseHandle(hDb
);
6074 if (rc
== ERROR_SUCCESS
)
6076 WCHAR guidbuffer
[0x200];
6078 rc
= MsiSummaryInfoGetPropertyW(hSumInfo
, 9, NULL
, NULL
, NULL
,
6080 if (rc
== ERROR_SUCCESS
)
6082 WCHAR squashed
[GUID_SIZE
];
6083 /* for now we only care about the first guid */
6084 LPWSTR ptr
= strchrW(guidbuffer
,';');
6086 squash_guid(guidbuffer
,squashed
);
6087 size
= strlenW(squashed
)*sizeof(WCHAR
);
6088 RegSetValueExW(hukey
,szPackageCode
,0,REG_SZ
, (LPSTR
)squashed
,
6093 ERR("Unable to query Revision_Number... \n");
6096 MsiCloseHandle(hSumInfo
);
6100 ERR("Unable to open Summary Information\n");
6106 HeapFree(GetProcessHeap(),0,productcode
);
6113 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
6117 MSIRECORD
* row
= 0;
6118 static const WCHAR ExecSeqQuery
[] =
6119 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6120 '`','I','n','i','F','i','l','e','`',0};
6121 static const WCHAR szWindowsFolder
[] =
6122 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
6124 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
6125 if (rc
!= ERROR_SUCCESS
)
6127 TRACE("no IniFile table\n");
6128 return ERROR_SUCCESS
;
6131 rc
= MSI_ViewExecute(view
, 0);
6132 if (rc
!= ERROR_SUCCESS
)
6134 MSI_ViewClose(view
);
6135 msiobj_release(&view
->hdr
);
6141 LPWSTR component
,filename
,dirproperty
,section
,key
,value
,identifier
;
6142 LPWSTR deformated_section
, deformated_key
, deformated_value
;
6143 LPWSTR folder
, fullname
= NULL
;
6145 INT component_index
,action
;
6147 rc
= MSI_ViewFetch(view
,&row
);
6148 if (rc
!= ERROR_SUCCESS
)
6154 component
= load_dynamic_stringW(row
, 8);
6155 component_index
= get_loaded_component(package
,component
);
6156 HeapFree(GetProcessHeap(),0,component
);
6158 if (!ACTION_VerifyComponentForAction(package
, component_index
,
6159 INSTALLSTATE_LOCAL
))
6161 TRACE("Skipping ini file due to disabled component\n");
6162 msiobj_release(&row
->hdr
);
6164 package
->components
[component_index
].Action
=
6165 package
->components
[component_index
].Installed
;
6170 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
6172 identifier
= load_dynamic_stringW(row
,1);
6173 filename
= load_dynamic_stringW(row
,2);
6174 dirproperty
= load_dynamic_stringW(row
,3);
6175 section
= load_dynamic_stringW(row
,4);
6176 key
= load_dynamic_stringW(row
,5);
6177 value
= load_dynamic_stringW(row
,6);
6178 action
= MSI_RecordGetInteger(row
,7);
6180 deformat_string(package
,section
,&deformated_section
);
6181 deformat_string(package
,key
,&deformated_key
);
6182 deformat_string(package
,value
,&deformated_value
);
6186 folder
= resolve_folder(package
, dirproperty
, FALSE
, FALSE
, NULL
);
6188 folder
= load_dynamic_property(package
,dirproperty
,NULL
);
6191 folder
= load_dynamic_property(package
, szWindowsFolder
, NULL
);
6195 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty
));
6199 fullname
= build_directory_name(3, folder
, filename
, NULL
);
6203 TRACE("Adding value %s to section %s in %s\n",
6204 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
6205 debugstr_w(fullname
));
6206 WritePrivateProfileStringW(deformated_section
, deformated_key
,
6207 deformated_value
, fullname
);
6209 else if (action
== 1)
6212 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
6213 returned
, 10, fullname
);
6214 if (returned
[0] == 0)
6216 TRACE("Adding value %s to section %s in %s\n",
6217 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
6218 debugstr_w(fullname
));
6220 WritePrivateProfileStringW(deformated_section
, deformated_key
,
6221 deformated_value
, fullname
);
6224 else if (action
== 3)
6226 FIXME("Append to existing section not yet implemented\n");
6229 uirow
= MSI_CreateRecord(4);
6230 MSI_RecordSetStringW(uirow
,1,identifier
);
6231 MSI_RecordSetStringW(uirow
,2,deformated_section
);
6232 MSI_RecordSetStringW(uirow
,3,deformated_key
);
6233 MSI_RecordSetStringW(uirow
,4,deformated_value
);
6234 ui_actiondata(package
,szWriteIniValues
,uirow
);
6235 msiobj_release( &uirow
->hdr
);
6237 HeapFree(GetProcessHeap(),0,identifier
);
6238 HeapFree(GetProcessHeap(),0,fullname
);
6239 HeapFree(GetProcessHeap(),0,filename
);
6240 HeapFree(GetProcessHeap(),0,key
);
6241 HeapFree(GetProcessHeap(),0,value
);
6242 HeapFree(GetProcessHeap(),0,section
);
6243 HeapFree(GetProcessHeap(),0,dirproperty
);
6244 HeapFree(GetProcessHeap(),0,folder
);
6245 HeapFree(GetProcessHeap(),0,deformated_key
);
6246 HeapFree(GetProcessHeap(),0,deformated_value
);
6247 HeapFree(GetProcessHeap(),0,deformated_section
);
6248 msiobj_release(&row
->hdr
);
6250 MSI_ViewClose(view
);
6251 msiobj_release(&view
->hdr
);
6255 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
6259 MSIRECORD
* row
= 0;
6260 static const WCHAR ExecSeqQuery
[] =
6261 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6262 '`','S','e','l','f','R','e','g','`',0};
6264 static const WCHAR ExeStr
[] =
6265 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
6266 static const WCHAR close
[] = {'\"',0};
6268 PROCESS_INFORMATION info
;
6271 memset(&si
,0,sizeof(STARTUPINFOW
));
6273 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
6274 if (rc
!= ERROR_SUCCESS
)
6276 TRACE("no SelfReg table\n");
6277 return ERROR_SUCCESS
;
6280 rc
= MSI_ViewExecute(view
, 0);
6281 if (rc
!= ERROR_SUCCESS
)
6283 MSI_ViewClose(view
);
6284 msiobj_release(&view
->hdr
);
6294 rc
= MSI_ViewFetch(view
,&row
);
6295 if (rc
!= ERROR_SUCCESS
)
6301 filename
= load_dynamic_stringW(row
,1);
6302 index
= get_loaded_file(package
,filename
);
6306 ERR("Unable to find file id %s\n",debugstr_w(filename
));
6307 HeapFree(GetProcessHeap(),0,filename
);
6308 msiobj_release(&row
->hdr
);
6311 HeapFree(GetProcessHeap(),0,filename
);
6313 len
= strlenW(ExeStr
);
6314 len
+= strlenW(package
->files
[index
].TargetPath
);
6317 filename
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
6318 strcpyW(filename
,ExeStr
);
6319 strcatW(filename
,package
->files
[index
].TargetPath
);
6320 strcatW(filename
,close
);
6322 TRACE("Registering %s\n",debugstr_w(filename
));
6323 brc
= CreateProcessW(NULL
, filename
, NULL
, NULL
, FALSE
, 0, NULL
,
6324 c_colon
, &si
, &info
);
6327 msi_dialog_check_messages(info
.hProcess
);
6329 HeapFree(GetProcessHeap(),0,filename
);
6330 msiobj_release(&row
->hdr
);
6332 MSI_ViewClose(view
);
6333 msiobj_release(&view
->hdr
);
6337 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
6346 return ERROR_INVALID_HANDLE
;
6348 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
6352 rc
= MSIREG_OpenFeaturesKey(productcode
,&hkey
,TRUE
);
6353 if (rc
!= ERROR_SUCCESS
)
6356 rc
= MSIREG_OpenUserFeaturesKey(productcode
,&hukey
,TRUE
);
6357 if (rc
!= ERROR_SUCCESS
)
6360 /* here the guids are base 85 encoded */
6361 for (i
= 0; i
< package
->loaded_features
; i
++)
6367 BOOL absent
= FALSE
;
6369 if (!ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_LOCAL
) &&
6370 !ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_SOURCE
) &&
6371 !ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_ADVERTISED
))
6374 size
= package
->features
[i
].ComponentCount
*21;
6376 if (package
->features
[i
].Feature_Parent
[0])
6377 size
+= strlenW(package
->features
[i
].Feature_Parent
)+2;
6379 data
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
6382 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
6385 memset(buf
,0,sizeof(buf
));
6386 if (package
->components
6387 [package
->features
[i
].Components
[j
]].ComponentId
[0]!=0)
6389 TRACE("From %s\n",debugstr_w(package
->components
6390 [package
->features
[i
].Components
[j
]].ComponentId
));
6391 CLSIDFromString(package
->components
6392 [package
->features
[i
].Components
[j
]].ComponentId
,
6394 encode_base85_guid(&clsid
,buf
);
6395 TRACE("to %s\n",debugstr_w(buf
));
6399 if (package
->features
[i
].Feature_Parent
[0])
6401 static const WCHAR sep
[] = {'\2',0};
6403 strcatW(data
,package
->features
[i
].Feature_Parent
);
6406 size
= (strlenW(data
)+1)*sizeof(WCHAR
);
6407 RegSetValueExW(hkey
,package
->features
[i
].Feature
,0,REG_SZ
,
6409 HeapFree(GetProcessHeap(),0,data
);
6413 size
= strlenW(package
->features
[i
].Feature_Parent
)*sizeof(WCHAR
);
6414 RegSetValueExW(hukey
,package
->features
[i
].Feature
,0,REG_SZ
,
6415 (LPSTR
)package
->features
[i
].Feature_Parent
,size
);
6419 size
= (strlenW(package
->features
[i
].Feature_Parent
)+2)*
6421 data
= HeapAlloc(GetProcessHeap(),0,size
);
6423 strcpyW(&data
[1],package
->features
[i
].Feature_Parent
);
6424 RegSetValueExW(hukey
,package
->features
[i
].Feature
,0,REG_SZ
,
6426 HeapFree(GetProcessHeap(),0,data
);
6433 HeapFree(GetProcessHeap(), 0, productcode
);
6437 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
6444 static WCHAR szNONE
[] = {0};
6445 static const WCHAR szWindowsInstaler
[] =
6446 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
6447 static const WCHAR szPropKeys
[][80] =
6449 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
6450 {'A','R','P','C','O','N','T','A','C','T',0},
6451 {'A','R','P','C','O','M','M','E','N','T','S',0},
6452 {'P','r','o','d','u','c','t','N','a','m','e',0},
6453 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
6454 {'A','R','P','H','E','L','P','L','I','N','K',0},
6455 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
6456 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
6457 {'S','o','u','r','c','e','D','i','r',0},
6458 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
6459 {'A','R','P','R','E','A','D','M','E',0},
6460 {'A','R','P','S','I','Z','E',0},
6461 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
6462 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
6466 static const WCHAR szRegKeys
[][80] =
6468 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
6469 {'C','o','n','t','a','c','t',0},
6470 {'C','o','m','m','e','n','t','s',0},
6471 {'D','i','s','p','l','a','y','N','a','m','e',0},
6472 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
6473 {'H','e','l','p','L','i','n','k',0},
6474 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
6475 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
6476 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
6477 {'P','u','b','l','i','s','h','e','r',0},
6478 {'R','e','a','d','m','e',0},
6479 {'S','i','z','e',0},
6480 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
6481 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
6485 static const WCHAR installerPathFmt
[] = {
6487 'I','n','s','t','a','l','l','e','r','\\',0};
6488 static const WCHAR fmt
[] = {
6490 'I','n','s','t','a','l','l','e','r','\\',
6491 '%','x','.','m','s','i',0};
6492 static const WCHAR szLocalPackage
[]=
6493 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
6494 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], packagefile
[MAX_PATH
];
6498 return ERROR_INVALID_HANDLE
;
6500 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
6504 rc
= MSIREG_OpenUninstallKey(productcode
,&hkey
,TRUE
);
6505 if (rc
!= ERROR_SUCCESS
)
6508 /* dump all the info i can grab */
6509 FIXME("Flesh out more information \n");
6512 while (szPropKeys
[i
][0]!=0)
6514 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
6515 if (rc
!= ERROR_SUCCESS
)
6517 size
= strlenW(buffer
)*sizeof(WCHAR
);
6518 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPSTR
)buffer
,size
);
6524 RegSetValueExW(hkey
,szWindowsInstaler
,0,REG_DWORD
,(LPSTR
)&rc
,size
);
6526 /* copy the package locally */
6527 num
= GetTickCount() & 0xffff;
6531 GetWindowsDirectoryW(windir
, sizeof(windir
) / sizeof(windir
[0]));
6532 snprintfW(packagefile
,sizeof(packagefile
)/sizeof(packagefile
[0]),fmt
,
6536 HANDLE handle
= CreateFileW(packagefile
,GENERIC_WRITE
, 0, NULL
,
6537 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
6538 if (handle
!= INVALID_HANDLE_VALUE
)
6540 CloseHandle(handle
);
6543 if (GetLastError() != ERROR_FILE_EXISTS
&&
6544 GetLastError() != ERROR_SHARING_VIOLATION
)
6546 if (!(++num
& 0xffff)) num
= 1;
6547 sprintfW(packagefile
,fmt
,num
);
6548 } while (num
!= start
);
6550 snprintfW(path
,sizeof(path
)/sizeof(path
[0]),installerPathFmt
,windir
);
6551 create_full_pathW(path
);
6552 TRACE("Copying to local package %s\n",debugstr_w(packagefile
));
6553 if (!CopyFileW(package
->PackagePath
,packagefile
,FALSE
))
6554 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
6555 debugstr_w(package
->PackagePath
), debugstr_w(packagefile
),
6557 size
= strlenW(packagefile
)*sizeof(WCHAR
);
6558 RegSetValueExW(hkey
,szLocalPackage
,0,REG_SZ
,(LPSTR
)packagefile
,size
);
6561 HeapFree(GetProcessHeap(),0,productcode
);
6564 return ERROR_SUCCESS
;
6567 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
6572 return ERROR_INVALID_HANDLE
;
6574 rc
= execute_script(package
,INSTALL_SCRIPT
);
6579 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
6584 return ERROR_INVALID_HANDLE
;
6586 /* turn off scheduleing */
6587 package
->script
->CurrentlyScripting
= FALSE
;
6589 /* first do the same as an InstallExecute */
6590 rc
= ACTION_InstallExecute(package
);
6591 if (rc
!= ERROR_SUCCESS
)
6594 /* then handle Commit Actions */
6595 rc
= execute_script(package
,COMMIT_SCRIPT
);
6600 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
6602 static const WCHAR RunOnce
[] = {
6603 'S','o','f','t','w','a','r','e','\\',
6604 'M','i','c','r','o','s','o','f','t','\\',
6605 'W','i','n','d','o','w','s','\\',
6606 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6607 'R','u','n','O','n','c','e',0};
6608 static const WCHAR InstallRunOnce
[] = {
6609 'S','o','f','t','w','a','r','e','\\',
6610 'M','i','c','r','o','s','o','f','t','\\',
6611 'W','i','n','d','o','w','s','\\',
6612 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6613 'I','n','s','t','a','l','l','e','r','\\',
6614 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
6616 static const WCHAR msiexec_fmt
[] = {
6618 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
6619 '\"','%','s','\"',0};
6620 static const WCHAR install_fmt
[] = {
6621 '/','I',' ','\"','%','s','\"',' ',
6622 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
6623 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
6624 WCHAR buffer
[256], sysdir
[MAX_PATH
];
6627 WCHAR squished_pc
[100];
6630 static const WCHAR szLUS
[] = {
6631 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
6632 static const WCHAR szSourceList
[] = {
6633 'S','o','u','r','c','e','L','i','s','t',0};
6634 static const WCHAR szPackageName
[] = {
6635 'P','a','c','k','a','g','e','N','a','m','e',0};
6638 return ERROR_INVALID_HANDLE
;
6640 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
6644 squash_guid(productcode
,squished_pc
);
6646 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
6647 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
6648 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
6651 size
= strlenW(buffer
)*sizeof(WCHAR
);
6652 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPSTR
)buffer
,size
);
6655 TRACE("Reboot command %s\n",debugstr_w(buffer
));
6657 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
6658 sprintfW(buffer
,install_fmt
,productcode
,squished_pc
);
6660 size
= strlenW(buffer
)*sizeof(WCHAR
);
6661 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPSTR
)buffer
,size
);
6664 rc
= MSIREG_OpenUserProductsKey(productcode
,&hukey
,TRUE
);
6665 if (rc
== ERROR_SUCCESS
)
6669 RegCreateKeyW(hukey
, szSourceList
, &hukey2
);
6670 buf
= load_dynamic_property(package
,cszSourceDir
,NULL
);
6671 size
= strlenW(buf
)*sizeof(WCHAR
);
6672 RegSetValueExW(hukey2
,szLUS
,0,REG_SZ
,(LPSTR
)buf
,size
);
6673 HeapFree(GetProcessHeap(),0,buf
);
6675 buf
= strrchrW(package
->PackagePath
,'\\');
6679 size
= strlenW(buf
)*sizeof(WCHAR
);
6680 RegSetValueExW(hukey2
,szPackageName
,0,REG_SZ
,(LPSTR
)buf
,size
);
6683 RegCloseKey(hukey2
);
6685 HeapFree(GetProcessHeap(),0,productcode
);
6687 return ERROR_INSTALL_SUSPEND
;
6690 UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
6693 * we are currently doing what should be done here in the top level Install
6694 * however for Adminastrative and uninstalls this step will be needed
6696 return ERROR_SUCCESS
;
6699 static LPWSTR
create_component_advertise_string(MSIPACKAGE
* package
,
6700 MSICOMPONENT
* component
, LPCWSTR feature
)
6702 LPWSTR productid
=NULL
;
6704 WCHAR productid_85
[21];
6705 WCHAR component_85
[21];
6707 * I have a fair bit of confusion as to when a < is used and when a > is
6708 * used. I do not think i have it right...
6710 * Ok it appears that the > is used if there is a guid for the compoenent
6711 * and the < is used if not.
6713 static WCHAR fmt1
[] = {'%','s','%','s','<',0,0};
6714 static WCHAR fmt2
[] = {'%','s','%','s','>','%','s',0,0};
6715 LPWSTR output
= NULL
;
6718 memset(productid_85
,0,sizeof(productid_85
));
6719 memset(component_85
,0,sizeof(component_85
));
6721 productid
= load_dynamic_property(package
,szProductCode
,NULL
);
6722 CLSIDFromString(productid
, &clsid
);
6724 encode_base85_guid(&clsid
,productid_85
);
6726 CLSIDFromString(component
->ComponentId
, &clsid
);
6727 encode_base85_guid(&clsid
,component_85
);
6729 TRACE("Doing something with this... %s %s %s\n",
6730 debugstr_w(productid_85
), debugstr_w(feature
),
6731 debugstr_w(component_85
));
6733 sz
= lstrlenW(productid_85
) + lstrlenW(feature
);
6735 sz
+= lstrlenW(component_85
);
6738 sz
*= sizeof(WCHAR
);
6740 output
= HeapAlloc(GetProcessHeap(),0,sz
);
6741 memset(output
,0,sz
);
6744 sprintfW(output
,fmt2
,productid_85
,feature
,component_85
);
6746 sprintfW(output
,fmt1
,productid_85
,feature
);
6748 HeapFree(GetProcessHeap(),0,productid
);
6753 static UINT
register_verb(MSIPACKAGE
*package
, LPCWSTR progid
,
6754 MSICOMPONENT
* component
, MSIEXTENSION
* extension
,
6755 MSIVERB
* verb
, INT
* Sequence
)
6759 static const WCHAR szShell
[] = {'s','h','e','l','l',0};
6760 static const WCHAR szCommand
[] = {'c','o','m','m','a','n','d',0};
6761 static const WCHAR fmt
[] = {'\"','%','s','\"',' ','%','s',0};
6762 static const WCHAR fmt2
[] = {'\"','%','s','\"',0};
6767 keyname
= build_directory_name(4, progid
, szShell
, verb
->Verb
, szCommand
);
6769 TRACE("Making Key %s\n",debugstr_w(keyname
));
6770 RegCreateKeyW(HKEY_CLASSES_ROOT
, keyname
, &key
);
6771 size
= strlenW(component
->FullKeypath
);
6773 size
+= strlenW(verb
->Argument
);
6776 command
= HeapAlloc(GetProcessHeap(),0, size
* sizeof (WCHAR
));
6778 sprintfW(command
, fmt
, component
->FullKeypath
, verb
->Argument
);
6780 sprintfW(command
, fmt2
, component
->FullKeypath
);
6782 RegSetValueExW(key
,NULL
,0,REG_SZ
, (LPVOID
)command
, (strlenW(command
)+1)*
6784 HeapFree(GetProcessHeap(),0,command
);
6786 advertise
= create_component_advertise_string(package
, component
,
6787 package
->features
[extension
->FeatureIndex
].Feature
);
6789 size
= strlenW(advertise
);
6792 size
+= strlenW(verb
->Argument
);
6795 command
= HeapAlloc(GetProcessHeap(),0, size
* sizeof (WCHAR
));
6796 memset(command
,0,size
*sizeof(WCHAR
));
6798 strcpyW(command
,advertise
);
6801 static const WCHAR szSpace
[] = {' ',0};
6802 strcatW(command
,szSpace
);
6803 strcatW(command
,verb
->Argument
);
6806 RegSetValueExW(key
, szCommand
, 0, REG_MULTI_SZ
, (LPBYTE
)command
,
6807 (strlenW(command
)+2)*sizeof(WCHAR
));
6810 HeapFree(GetProcessHeap(),0,keyname
);
6811 HeapFree(GetProcessHeap(),0,advertise
);
6812 HeapFree(GetProcessHeap(),0,command
);
6816 keyname
= build_directory_name(3, progid
, szShell
, verb
->Verb
);
6817 RegCreateKeyW(HKEY_CLASSES_ROOT
, keyname
, &key
);
6818 RegSetValueExW(key
,NULL
,0,REG_SZ
, (LPVOID
)verb
->Command
,
6819 (strlenW(verb
->Command
)+1) *sizeof(WCHAR
));
6821 HeapFree(GetProcessHeap(),0,keyname
);
6824 if (verb
->Sequence
!= MSI_NULL_INTEGER
)
6826 if (*Sequence
== MSI_NULL_INTEGER
|| verb
->Sequence
< *Sequence
)
6828 *Sequence
= verb
->Sequence
;
6829 keyname
= build_directory_name(2, progid
, szShell
);
6830 RegCreateKeyW(HKEY_CLASSES_ROOT
, keyname
, &key
);
6831 RegSetValueExW(key
,NULL
,0,REG_SZ
, (LPVOID
)verb
->Verb
,
6832 (strlenW(verb
->Verb
)+1) *sizeof(WCHAR
));
6834 HeapFree(GetProcessHeap(),0,keyname
);
6837 return ERROR_SUCCESS
;
6840 static UINT
ACTION_RegisterExtensionInfo(MSIPACKAGE
*package
)
6842 static const WCHAR szContentType
[] =
6843 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
6847 BOOL install_on_demand
= TRUE
;
6850 return ERROR_INVALID_HANDLE
;
6852 load_classes_and_such(package
);
6854 /* We need to set install_on_demand based on if the shell handles advertised
6855 * shortcuts and the like. Because Mike McCormack is working on this i am
6856 * going to default to TRUE
6859 for (i
= 0; i
< package
->loaded_extensions
; i
++)
6861 WCHAR extension
[257];
6864 index
= package
->extensions
[i
].ComponentIndex
;
6865 f_index
= package
->extensions
[i
].FeatureIndex
;
6871 * yes. MSDN says that these are based on _Feature_ not on
6872 * Component. So verify the feature is to be installed
6874 if ((!ACTION_VerifyFeatureForAction(package
, f_index
,
6875 INSTALLSTATE_LOCAL
)) &&
6876 !(install_on_demand
&& ACTION_VerifyFeatureForAction(package
,
6877 f_index
, INSTALLSTATE_ADVERTISED
)))
6879 TRACE("Skipping extension %s reg due to disabled feature %s\n",
6880 debugstr_w(package
->extensions
[i
].Extension
),
6881 debugstr_w(package
->features
[f_index
].Feature
));
6886 TRACE("Registering extension %s index %i\n",
6887 debugstr_w(package
->extensions
[i
].Extension
), i
);
6889 package
->extensions
[i
].Installed
= TRUE
;
6891 /* this is only registered if the extension has at least 1 verb
6894 if (package
->extensions
[i
].ProgIDIndex
>= 0 &&
6895 package
->extensions
[i
].VerbCount
> 0)
6896 mark_progid_for_install(package
, package
->extensions
[i
].ProgIDIndex
);
6898 if (package
->extensions
[i
].MIMEIndex
>= 0)
6899 mark_mime_for_install(package
, package
->extensions
[i
].MIMEIndex
);
6903 strcatW(extension
,package
->extensions
[i
].Extension
);
6905 RegCreateKeyW(HKEY_CLASSES_ROOT
,extension
,&hkey
);
6907 if (package
->extensions
[i
].MIMEIndex
>= 0)
6909 RegSetValueExW(hkey
,szContentType
,0,REG_SZ
,
6910 (LPVOID
)package
->mimes
[package
->extensions
[i
].
6911 MIMEIndex
].ContentType
,
6912 (strlenW(package
->mimes
[package
->extensions
[i
].
6913 MIMEIndex
].ContentType
)+1)*sizeof(WCHAR
));
6916 if (package
->extensions
[i
].ProgIDIndex
>= 0 ||
6917 package
->extensions
[i
].ProgIDText
)
6919 static const WCHAR szSN
[] =
6920 {'\\','S','h','e','l','l','N','e','w',0};
6925 INT Sequence
= MSI_NULL_INTEGER
;
6927 if (package
->extensions
[i
].ProgIDIndex
>= 0)
6928 progid
= package
->progids
[package
->extensions
[i
].
6929 ProgIDIndex
].ProgID
;
6931 progid
= package
->extensions
[i
].ProgIDText
;
6933 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)progid
,
6934 (strlenW(progid
)+1)*sizeof(WCHAR
));
6936 newkey
= HeapAlloc(GetProcessHeap(),0,
6937 (strlenW(progid
)+strlenW(szSN
)+1) * sizeof(WCHAR
));
6939 strcpyW(newkey
,progid
);
6940 strcatW(newkey
,szSN
);
6941 RegCreateKeyW(hkey
,newkey
,&hkey2
);
6944 HeapFree(GetProcessHeap(),0,newkey
);
6946 /* do all the verbs */
6947 for (v
= 0; v
< package
->extensions
[i
].VerbCount
; v
++)
6948 register_verb(package
, progid
,
6949 &package
->components
[index
],
6950 &package
->extensions
[i
],
6951 &package
->verbs
[package
->extensions
[i
].Verbs
[v
]],
6957 uirow
= MSI_CreateRecord(1);
6958 MSI_RecordSetStringW(uirow
,1,package
->extensions
[i
].Extension
);
6959 ui_actiondata(package
,szRegisterExtensionInfo
,uirow
);
6960 msiobj_release(&uirow
->hdr
);
6963 return ERROR_SUCCESS
;
6966 static UINT
ACTION_RegisterMIMEInfo(MSIPACKAGE
*package
)
6968 static const WCHAR szExten
[] =
6969 {'E','x','t','e','n','s','i','o','n',0 };
6975 return ERROR_INVALID_HANDLE
;
6977 load_classes_and_such(package
);
6979 for (i
= 0; i
< package
->loaded_mimes
; i
++)
6981 WCHAR extension
[257];
6984 static const WCHAR fmt
[] =
6985 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
6986 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
6990 * check if the MIME is to be installed. Either as requesed by an
6991 * extension or Class
6993 package
->mimes
[i
].InstallMe
= ((package
->mimes
[i
].InstallMe
) ||
6994 (package
->mimes
[i
].ClassIndex
>= 0 &&
6995 package
->classes
[package
->mimes
[i
].ClassIndex
].Installed
) ||
6996 (package
->mimes
[i
].ExtensionIndex
>=0 &&
6997 package
->extensions
[package
->mimes
[i
].ExtensionIndex
].Installed
));
6999 if (!package
->mimes
[i
].InstallMe
)
7001 TRACE("MIME %s not scheduled to be installed\n",
7002 debugstr_w(package
->mimes
[i
].ContentType
));
7006 mime
= package
->mimes
[i
].ContentType
;
7007 exten
= package
->extensions
[package
->mimes
[i
].ExtensionIndex
].Extension
;
7010 strcatW(extension
,exten
);
7012 key
= HeapAlloc(GetProcessHeap(),0,(strlenW(mime
)+strlenW(fmt
)+1) *
7014 sprintfW(key
,fmt
,mime
);
7015 RegCreateKeyW(HKEY_CLASSES_ROOT
,key
,&hkey
);
7016 RegSetValueExW(hkey
,szExten
,0,REG_SZ
,(LPVOID
)extension
,
7017 (strlenW(extension
)+1)*sizeof(WCHAR
));
7019 HeapFree(GetProcessHeap(),0,key
);
7021 if (package
->mimes
[i
].CLSID
[0])
7023 FIXME("Handle non null for field 3\n");
7028 uirow
= MSI_CreateRecord(2);
7029 MSI_RecordSetStringW(uirow
,1,package
->mimes
[i
].ContentType
);
7030 MSI_RecordSetStringW(uirow
,2,exten
);
7031 ui_actiondata(package
,szRegisterMIMEInfo
,uirow
);
7032 msiobj_release(&uirow
->hdr
);
7035 return ERROR_SUCCESS
;
7038 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
7040 static const WCHAR szProductID
[]=
7041 {'P','r','o','d','u','c','t','I','D',0};
7049 static const WCHAR szPropKeys
[][80] =
7051 {'P','r','o','d','u','c','t','I','D',0},
7052 {'U','S','E','R','N','A','M','E',0},
7053 {'C','O','M','P','A','N','Y','N','A','M','E',0},
7057 static const WCHAR szRegKeys
[][80] =
7059 {'P','r','o','d','u','c','t','I','D',0},
7060 {'R','e','g','O','w','n','e','r',0},
7061 {'R','e','g','C','o','m','p','a','n','y',0},
7066 return ERROR_INVALID_HANDLE
;
7068 productid
= load_dynamic_property(package
,szProductID
,&rc
);
7070 return ERROR_SUCCESS
;
7072 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
7076 rc
= MSIREG_OpenUninstallKey(productcode
,&hkey
,TRUE
);
7077 if (rc
!= ERROR_SUCCESS
)
7081 while (szPropKeys
[i
][0]!=0)
7083 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
7084 if (rc
== ERROR_SUCCESS
)
7086 size
= strlenW(buffer
)*sizeof(WCHAR
);
7087 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPSTR
)buffer
,size
);
7090 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,NULL
,0);
7095 HeapFree(GetProcessHeap(),0,productcode
);
7096 HeapFree(GetProcessHeap(),0,productid
);
7099 return ERROR_SUCCESS
;
7103 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
7106 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
7112 * Code based off of code located here
7113 * http://www.codeproject.com/gdi/fontnamefromfile.asp
7115 * Using string index 4 (full font name) instead of 1 (family name)
7117 static LPWSTR
load_ttfname_from(LPCWSTR filename
)
7123 typedef struct _tagTT_OFFSET_TABLE
{
7124 USHORT uMajorVersion
;
7125 USHORT uMinorVersion
;
7126 USHORT uNumOfTables
;
7127 USHORT uSearchRange
;
7128 USHORT uEntrySelector
;
7132 typedef struct _tagTT_TABLE_DIRECTORY
{
7133 char szTag
[4]; /* table name */
7134 ULONG uCheckSum
; /* Check sum */
7135 ULONG uOffset
; /* Offset from beginning of file */
7136 ULONG uLength
; /* length of the table in bytes */
7137 }TT_TABLE_DIRECTORY
;
7139 typedef struct _tagTT_NAME_TABLE_HEADER
{
7140 USHORT uFSelector
; /* format selector. Always 0 */
7141 USHORT uNRCount
; /* Name Records count */
7142 USHORT uStorageOffset
; /* Offset for strings storage,
7143 * from start of the table */
7144 }TT_NAME_TABLE_HEADER
;
7146 typedef struct _tagTT_NAME_RECORD
{
7151 USHORT uStringLength
;
7152 USHORT uStringOffset
; /* from start of storage area */
7155 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
7156 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
7158 handle
= CreateFileW(filename
,GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
7159 FILE_ATTRIBUTE_NORMAL
, 0 );
7160 if (handle
!= INVALID_HANDLE_VALUE
)
7162 TT_TABLE_DIRECTORY tblDir
;
7163 BOOL bFound
= FALSE
;
7164 TT_OFFSET_TABLE ttOffsetTable
;
7166 ReadFile(handle
,&ttOffsetTable
, sizeof(TT_OFFSET_TABLE
),NULL
,NULL
);
7167 ttOffsetTable
.uNumOfTables
= SWAPWORD(ttOffsetTable
.uNumOfTables
);
7168 ttOffsetTable
.uMajorVersion
= SWAPWORD(ttOffsetTable
.uMajorVersion
);
7169 ttOffsetTable
.uMinorVersion
= SWAPWORD(ttOffsetTable
.uMinorVersion
);
7171 if (ttOffsetTable
.uMajorVersion
!= 1 ||
7172 ttOffsetTable
.uMinorVersion
!= 0)
7175 for (i
=0; i
< ttOffsetTable
.uNumOfTables
; i
++)
7177 ReadFile(handle
,&tblDir
, sizeof(TT_TABLE_DIRECTORY
),NULL
,NULL
);
7178 if (strncmp(tblDir
.szTag
,"name",4)==0)
7181 tblDir
.uLength
= SWAPLONG(tblDir
.uLength
);
7182 tblDir
.uOffset
= SWAPLONG(tblDir
.uOffset
);
7189 TT_NAME_TABLE_HEADER ttNTHeader
;
7190 TT_NAME_RECORD ttRecord
;
7192 SetFilePointer(handle
, tblDir
.uOffset
, NULL
, FILE_BEGIN
);
7193 ReadFile(handle
,&ttNTHeader
, sizeof(TT_NAME_TABLE_HEADER
),
7196 ttNTHeader
.uNRCount
= SWAPWORD(ttNTHeader
.uNRCount
);
7197 ttNTHeader
.uStorageOffset
= SWAPWORD(ttNTHeader
.uStorageOffset
);
7199 for(i
=0; i
<ttNTHeader
.uNRCount
; i
++)
7201 ReadFile(handle
,&ttRecord
, sizeof(TT_NAME_RECORD
),NULL
,NULL
);
7202 ttRecord
.uNameID
= SWAPWORD(ttRecord
.uNameID
);
7203 /* 4 is the Full Font Name */
7204 if(ttRecord
.uNameID
== 4)
7208 static const LPSTR tt
= " (TrueType)";
7210 ttRecord
.uStringLength
= SWAPWORD(ttRecord
.uStringLength
);
7211 ttRecord
.uStringOffset
= SWAPWORD(ttRecord
.uStringOffset
);
7212 nPos
= SetFilePointer(handle
, 0, NULL
, FILE_CURRENT
);
7213 SetFilePointer(handle
, tblDir
.uOffset
+
7214 ttRecord
.uStringOffset
+
7215 ttNTHeader
.uStorageOffset
,
7217 buf
= HeapAlloc(GetProcessHeap(), 0,
7218 ttRecord
.uStringLength
+ 1 + strlen(tt
));
7219 memset(buf
, 0, ttRecord
.uStringLength
+ 1 + strlen(tt
));
7220 ReadFile(handle
, buf
, ttRecord
.uStringLength
, NULL
, NULL
);
7221 if (strlen(buf
) > 0)
7224 ret
= strdupAtoW(buf
);
7225 HeapFree(GetProcessHeap(),0,buf
);
7229 HeapFree(GetProcessHeap(),0,buf
);
7230 SetFilePointer(handle
,nPos
, NULL
, FILE_BEGIN
);
7234 CloseHandle(handle
);
7237 ERR("Unable to open font file %s\n", debugstr_w(filename
));
7239 TRACE("Returning fontname %s\n",debugstr_w(ret
));
7243 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
)
7247 MSIRECORD
* row
= 0;
7248 static const WCHAR ExecSeqQuery
[] =
7249 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7250 '`','F','o','n','t','`',0};
7251 static const WCHAR regfont1
[] =
7252 {'S','o','f','t','w','a','r','e','\\',
7253 'M','i','c','r','o','s','o','f','t','\\',
7254 'W','i','n','d','o','w','s',' ','N','T','\\',
7255 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7256 'F','o','n','t','s',0};
7257 static const WCHAR regfont2
[] =
7258 {'S','o','f','t','w','a','r','e','\\',
7259 'M','i','c','r','o','s','o','f','t','\\',
7260 'W','i','n','d','o','w','s','\\',
7261 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7262 'F','o','n','t','s',0};
7266 TRACE("%p\n", package
);
7268 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
7269 if (rc
!= ERROR_SUCCESS
)
7271 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc
);
7272 return ERROR_SUCCESS
;
7275 rc
= MSI_ViewExecute(view
, 0);
7276 if (rc
!= ERROR_SUCCESS
)
7278 MSI_ViewClose(view
);
7279 msiobj_release(&view
->hdr
);
7280 TRACE("MSI_ViewExecute returned %d\n", rc
);
7281 return ERROR_SUCCESS
;
7284 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont1
,&hkey1
);
7285 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont2
,&hkey2
);
7294 rc
= MSI_ViewFetch(view
,&row
);
7295 if (rc
!= ERROR_SUCCESS
)
7301 file
= load_dynamic_stringW(row
,1);
7302 index
= get_loaded_file(package
,file
);
7305 ERR("Unable to load file\n");
7306 HeapFree(GetProcessHeap(),0,file
);
7310 /* check to make sure that component is installed */
7311 if (!ACTION_VerifyComponentForAction(package
,
7312 package
->files
[index
].ComponentIndex
, INSTALLSTATE_LOCAL
))
7314 TRACE("Skipping: Component not scheduled for install\n");
7315 HeapFree(GetProcessHeap(),0,file
);
7317 msiobj_release(&row
->hdr
);
7322 if (MSI_RecordIsNull(row
,2))
7323 name
= load_ttfname_from(package
->files
[index
].TargetPath
);
7325 name
= load_dynamic_stringW(row
,2);
7329 size
= strlenW(package
->files
[index
].FileName
) * sizeof(WCHAR
);
7330 RegSetValueExW(hkey1
,name
,0,REG_SZ
,
7331 (LPBYTE
)package
->files
[index
].FileName
,size
);
7332 RegSetValueExW(hkey2
,name
,0,REG_SZ
,
7333 (LPBYTE
)package
->files
[index
].FileName
,size
);
7336 HeapFree(GetProcessHeap(),0,file
);
7337 HeapFree(GetProcessHeap(),0,name
);
7338 msiobj_release(&row
->hdr
);
7340 MSI_ViewClose(view
);
7341 msiobj_release(&view
->hdr
);
7346 TRACE("returning %d\n", rc
);
7350 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
7352 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
7353 LPWSTR compgroupid
=NULL
;
7354 LPWSTR feature
=NULL
;
7356 LPWSTR qualifier
= NULL
;
7357 LPWSTR component
= NULL
;
7358 LPWSTR advertise
= NULL
;
7359 LPWSTR output
= NULL
;
7361 UINT rc
= ERROR_SUCCESS
;
7365 component
= load_dynamic_stringW(rec
,3);
7366 index
= get_loaded_component(package
,component
);
7368 if (!ACTION_VerifyComponentForAction(package
, index
,
7369 INSTALLSTATE_LOCAL
) &&
7370 !ACTION_VerifyComponentForAction(package
, index
,
7371 INSTALLSTATE_SOURCE
) &&
7372 !ACTION_VerifyComponentForAction(package
, index
,
7373 INSTALLSTATE_ADVERTISED
))
7375 TRACE("Skipping: Component %s not scheduled for install\n",
7376 debugstr_w(component
));
7378 HeapFree(GetProcessHeap(),0,component
);
7379 return ERROR_SUCCESS
;
7382 compgroupid
= load_dynamic_stringW(rec
,1);
7384 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
7385 if (rc
!= ERROR_SUCCESS
)
7388 text
= load_dynamic_stringW(rec
,4);
7389 qualifier
= load_dynamic_stringW(rec
,2);
7390 feature
= load_dynamic_stringW(rec
,5);
7392 advertise
= create_component_advertise_string(package
,
7393 &package
->components
[index
], feature
);
7395 sz
= strlenW(advertise
);
7398 sz
+= lstrlenW(text
);
7401 sz
*= sizeof(WCHAR
);
7403 output
= HeapAlloc(GetProcessHeap(),0,sz
);
7404 memset(output
,0,sz
);
7405 strcpyW(output
,advertise
);
7408 strcatW(output
,text
);
7410 sz
= (lstrlenW(output
)+2) * sizeof(WCHAR
);
7411 RegSetValueExW(hkey
, qualifier
,0,REG_MULTI_SZ
, (LPBYTE
)output
, sz
);
7415 HeapFree(GetProcessHeap(),0,output
);
7416 HeapFree(GetProcessHeap(),0,compgroupid
);
7417 HeapFree(GetProcessHeap(),0,component
);
7418 HeapFree(GetProcessHeap(),0,feature
);
7419 HeapFree(GetProcessHeap(),0,text
);
7420 HeapFree(GetProcessHeap(),0,qualifier
);
7426 * At present I am ignorning the advertised components part of this and only
7427 * focusing on the qualified component sets
7429 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
7433 static const WCHAR ExecSeqQuery
[] =
7434 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7435 '`','P','u','b','l','i','s','h',
7436 'C','o','m','p','o','n','e','n','t','`',0};
7438 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
7439 if (rc
!= ERROR_SUCCESS
)
7440 return ERROR_SUCCESS
;
7442 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
7443 msiobj_release(&view
->hdr
);
7448 /* Msi functions that seem appropriate here */
7450 /***********************************************************************
7451 * MsiDoActionA (MSI.@)
7453 UINT WINAPI
MsiDoActionA( MSIHANDLE hInstall
, LPCSTR szAction
)
7458 TRACE(" exteral attempt at action %s\n",szAction
);
7461 return ERROR_FUNCTION_FAILED
;
7463 return ERROR_FUNCTION_FAILED
;
7465 szwAction
= strdupAtoW(szAction
);
7468 return ERROR_FUNCTION_FAILED
;
7471 rc
= MsiDoActionW(hInstall
, szwAction
);
7472 HeapFree(GetProcessHeap(),0,szwAction
);
7476 /***********************************************************************
7477 * MsiDoActionW (MSI.@)
7479 UINT WINAPI
MsiDoActionW( MSIHANDLE hInstall
, LPCWSTR szAction
)
7481 MSIPACKAGE
*package
;
7482 UINT ret
= ERROR_INVALID_HANDLE
;
7484 TRACE(" external attempt at action %s \n",debugstr_w(szAction
));
7486 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
7489 ret
= ACTION_PerformUIAction(package
,szAction
);
7490 msiobj_release( &package
->hdr
);
7495 UINT WINAPI
MsiGetTargetPathA( MSIHANDLE hInstall
, LPCSTR szFolder
,
7496 LPSTR szPathBuf
, DWORD
* pcchPathBuf
)
7502 TRACE("getting folder %s %p %li\n",szFolder
,szPathBuf
, *pcchPathBuf
);
7505 return ERROR_FUNCTION_FAILED
;
7507 return ERROR_FUNCTION_FAILED
;
7509 szwFolder
= strdupAtoW(szFolder
);
7512 return ERROR_FUNCTION_FAILED
;
7514 szwPathBuf
= HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf
* sizeof(WCHAR
));
7516 rc
= MsiGetTargetPathW(hInstall
, szwFolder
, szwPathBuf
,pcchPathBuf
);
7518 WideCharToMultiByte( CP_ACP
, 0, szwPathBuf
, *pcchPathBuf
, szPathBuf
,
7519 *pcchPathBuf
, NULL
, NULL
);
7521 HeapFree(GetProcessHeap(),0,szwFolder
);
7522 HeapFree(GetProcessHeap(),0,szwPathBuf
);
7527 UINT WINAPI
MsiGetTargetPathW( MSIHANDLE hInstall
, LPCWSTR szFolder
, LPWSTR
7528 szPathBuf
, DWORD
* pcchPathBuf
)
7531 UINT rc
= ERROR_FUNCTION_FAILED
;
7532 MSIPACKAGE
*package
;
7534 TRACE("(%s %p %li)\n",debugstr_w(szFolder
),szPathBuf
,*pcchPathBuf
);
7536 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
7538 return ERROR_INVALID_HANDLE
;
7539 path
= resolve_folder(package
, szFolder
, FALSE
, FALSE
, NULL
);
7540 msiobj_release( &package
->hdr
);
7542 if (path
&& (strlenW(path
) > *pcchPathBuf
))
7544 *pcchPathBuf
= strlenW(path
)+1;
7545 rc
= ERROR_MORE_DATA
;
7549 *pcchPathBuf
= strlenW(path
)+1;
7550 strcpyW(szPathBuf
,path
);
7551 TRACE("Returning Path %s\n",debugstr_w(path
));
7554 HeapFree(GetProcessHeap(),0,path
);
7560 UINT WINAPI
MsiGetSourcePathA( MSIHANDLE hInstall
, LPCSTR szFolder
,
7561 LPSTR szPathBuf
, DWORD
* pcchPathBuf
)
7567 TRACE("getting source %s %p %li\n",szFolder
,szPathBuf
, *pcchPathBuf
);
7570 return ERROR_FUNCTION_FAILED
;
7572 return ERROR_FUNCTION_FAILED
;
7574 szwFolder
= strdupAtoW(szFolder
);
7576 return ERROR_FUNCTION_FAILED
;
7578 szwPathBuf
= HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf
* sizeof(WCHAR
));
7580 rc
= MsiGetSourcePathW(hInstall
, szwFolder
, szwPathBuf
,pcchPathBuf
);
7582 WideCharToMultiByte( CP_ACP
, 0, szwPathBuf
, *pcchPathBuf
, szPathBuf
,
7583 *pcchPathBuf
, NULL
, NULL
);
7585 HeapFree(GetProcessHeap(),0,szwFolder
);
7586 HeapFree(GetProcessHeap(),0,szwPathBuf
);
7591 UINT WINAPI
MsiGetSourcePathW( MSIHANDLE hInstall
, LPCWSTR szFolder
, LPWSTR
7592 szPathBuf
, DWORD
* pcchPathBuf
)
7595 UINT rc
= ERROR_FUNCTION_FAILED
;
7596 MSIPACKAGE
*package
;
7598 TRACE("(%s %p %li)\n",debugstr_w(szFolder
),szPathBuf
,*pcchPathBuf
);
7600 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
7602 return ERROR_INVALID_HANDLE
;
7603 path
= resolve_folder(package
, szFolder
, TRUE
, FALSE
, NULL
);
7604 msiobj_release( &package
->hdr
);
7606 if (path
&& strlenW(path
) > *pcchPathBuf
)
7608 *pcchPathBuf
= strlenW(path
)+1;
7609 rc
= ERROR_MORE_DATA
;
7613 *pcchPathBuf
= strlenW(path
)+1;
7614 strcpyW(szPathBuf
,path
);
7615 TRACE("Returning Path %s\n",debugstr_w(path
));
7618 HeapFree(GetProcessHeap(),0,path
);
7624 /***********************************************************************
7625 * MsiSetTargetPathA (MSI.@)
7627 UINT WINAPI
MsiSetTargetPathA(MSIHANDLE hInstall
, LPCSTR szFolder
,
7628 LPCSTR szFolderPath
)
7631 LPWSTR szwFolderPath
;
7635 return ERROR_FUNCTION_FAILED
;
7637 return ERROR_FUNCTION_FAILED
;
7639 szwFolder
= strdupAtoW(szFolder
);
7641 return ERROR_FUNCTION_FAILED
;
7643 szwFolderPath
= strdupAtoW(szFolderPath
);
7646 HeapFree(GetProcessHeap(),0,szwFolder
);
7647 return ERROR_FUNCTION_FAILED
;
7650 rc
= MsiSetTargetPathW(hInstall
, szwFolder
, szwFolderPath
);
7652 HeapFree(GetProcessHeap(),0,szwFolder
);
7653 HeapFree(GetProcessHeap(),0,szwFolderPath
);
7658 UINT
MSI_SetTargetPathW(MSIPACKAGE
*package
, LPCWSTR szFolder
,
7659 LPCWSTR szFolderPath
)
7663 LPWSTR path2
= NULL
;
7666 TRACE("(%p %s %s)\n",package
, debugstr_w(szFolder
),debugstr_w(szFolderPath
));
7669 return ERROR_INVALID_HANDLE
;
7671 if (szFolderPath
[0]==0)
7672 return ERROR_FUNCTION_FAILED
;
7674 if (GetFileAttributesW(szFolderPath
) == INVALID_FILE_ATTRIBUTES
)
7675 return ERROR_FUNCTION_FAILED
;
7677 path
= resolve_folder(package
,szFolder
,FALSE
,FALSE
,&folder
);
7680 return ERROR_INVALID_PARAMETER
;
7682 HeapFree(GetProcessHeap(),0,folder
->Property
);
7683 folder
->Property
= build_directory_name(2, szFolderPath
, NULL
);
7685 if (lstrcmpiW(path
, folder
->Property
) == 0)
7688 * Resolved Target has not really changed, so just
7689 * set this folder and do not recalculate everything.
7691 HeapFree(GetProcessHeap(),0,folder
->ResolvedTarget
);
7692 folder
->ResolvedTarget
= NULL
;
7693 path2
= resolve_folder(package
,szFolder
,FALSE
,TRUE
,NULL
);
7694 HeapFree(GetProcessHeap(),0,path2
);
7698 for (i
= 0; i
< package
->loaded_folders
; i
++)
7700 HeapFree(GetProcessHeap(),0,package
->folders
[i
].ResolvedTarget
);
7701 package
->folders
[i
].ResolvedTarget
=NULL
;
7704 for (i
= 0; i
< package
->loaded_folders
; i
++)
7706 path2
=resolve_folder(package
, package
->folders
[i
].Directory
, FALSE
,
7708 HeapFree(GetProcessHeap(),0,path2
);
7711 HeapFree(GetProcessHeap(),0,path
);
7713 return ERROR_SUCCESS
;
7716 /***********************************************************************
7717 * MsiSetTargetPathW (MSI.@)
7719 UINT WINAPI
MsiSetTargetPathW(MSIHANDLE hInstall
, LPCWSTR szFolder
,
7720 LPCWSTR szFolderPath
)
7722 MSIPACKAGE
*package
;
7725 TRACE("(%s %s)\n",debugstr_w(szFolder
),debugstr_w(szFolderPath
));
7727 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
7728 ret
= MSI_SetTargetPathW( package
, szFolder
, szFolderPath
);
7729 msiobj_release( &package
->hdr
);
7733 /***********************************************************************
7734 * MsiGetMode (MSI.@)
7736 * Returns an internal installer state (if it is running in a mode iRunMode)
7739 * hInstall [I] Handle to the installation
7740 * hRunMode [I] Checking run mode
7741 * MSIRUNMODE_ADMIN Administrative mode
7742 * MSIRUNMODE_ADVERTISE Advertisement mode
7743 * MSIRUNMODE_MAINTENANCE Maintenance mode
7744 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
7745 * MSIRUNMODE_LOGENABLED Log file is writing
7746 * MSIRUNMODE_OPERATIONS Operations in progress??
7747 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
7748 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
7749 * MSIRUNMODE_CABINET Files from cabinet are installed
7750 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
7751 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
7752 * MSIRUNMODE_RESERVED11 Reserved
7753 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
7754 * MSIRUNMODE_ZAWENABLED Demand installation is supported
7755 * MSIRUNMODE_RESERVED14 Reserved
7756 * MSIRUNMODE_RESERVED15 Reserved
7757 * MSIRUNMODE_SCHEDULED called from install script
7758 * MSIRUNMODE_ROLLBACK called from rollback script
7759 * MSIRUNMODE_COMMIT called from commit script
7762 * In the state: TRUE
7763 * Not in the state: FALSE
7767 BOOL WINAPI
MsiGetMode(MSIHANDLE hInstall
, MSIRUNMODE iRunMode
)
7769 FIXME("STUB (iRunMode=%i)\n",iRunMode
);
7773 /***********************************************************************
7774 * MsiSetFeatureStateA (MSI.@)
7776 * According to the docs, when this is called it immediately recalculates
7777 * all the component states as well
7779 UINT WINAPI
MsiSetFeatureStateA(MSIHANDLE hInstall
, LPCSTR szFeature
,
7780 INSTALLSTATE iState
)
7782 LPWSTR szwFeature
= NULL
;
7785 szwFeature
= strdupAtoW(szFeature
);
7788 return ERROR_FUNCTION_FAILED
;
7790 rc
= MsiSetFeatureStateW(hInstall
,szwFeature
, iState
);
7792 HeapFree(GetProcessHeap(),0,szwFeature
);
7799 UINT WINAPI
MSI_SetFeatureStateW(MSIPACKAGE
* package
, LPCWSTR szFeature
,
7800 INSTALLSTATE iState
)
7803 UINT rc
= ERROR_SUCCESS
;
7805 TRACE(" %s to %i\n",debugstr_w(szFeature
), iState
);
7807 index
= get_loaded_feature(package
,szFeature
);
7809 return ERROR_UNKNOWN_FEATURE
;
7811 if (iState
== INSTALLSTATE_ADVERTISED
&&
7812 package
->features
[index
].Attributes
&
7813 msidbFeatureAttributesDisallowAdvertise
)
7814 return ERROR_FUNCTION_FAILED
;
7816 package
->features
[index
].ActionRequest
= iState
;
7817 package
->features
[index
].Action
= iState
;
7819 ACTION_UpdateComponentStates(package
,szFeature
);
7821 /* update all the features that are children of this feature */
7822 for (i
= 0; i
< package
->loaded_features
; i
++)
7824 if (strcmpW(szFeature
, package
->features
[i
].Feature_Parent
) == 0)
7825 MSI_SetFeatureStateW(package
, package
->features
[i
].Feature
, iState
);
7831 /***********************************************************************
7832 * MsiSetFeatureStateW (MSI.@)
7834 UINT WINAPI
MsiSetFeatureStateW(MSIHANDLE hInstall
, LPCWSTR szFeature
,
7835 INSTALLSTATE iState
)
7837 MSIPACKAGE
* package
;
7838 UINT rc
= ERROR_SUCCESS
;
7840 TRACE(" %s to %i\n",debugstr_w(szFeature
), iState
);
7842 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
7844 return ERROR_INVALID_HANDLE
;
7846 rc
= MSI_SetFeatureStateW(package
,szFeature
,iState
);
7848 msiobj_release( &package
->hdr
);
7852 UINT WINAPI
MsiGetFeatureStateA(MSIHANDLE hInstall
, LPSTR szFeature
,
7853 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
7855 LPWSTR szwFeature
= NULL
;
7858 szwFeature
= strdupAtoW(szFeature
);
7860 rc
= MsiGetFeatureStateW(hInstall
,szwFeature
,piInstalled
, piAction
);
7862 HeapFree( GetProcessHeap(), 0 , szwFeature
);
7867 UINT
MSI_GetFeatureStateW(MSIPACKAGE
*package
, LPWSTR szFeature
,
7868 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
7872 index
= get_loaded_feature(package
,szFeature
);
7874 return ERROR_UNKNOWN_FEATURE
;
7877 *piInstalled
= package
->features
[index
].Installed
;
7880 *piAction
= package
->features
[index
].Action
;
7882 TRACE("returning %i %i\n",*piInstalled
,*piAction
);
7884 return ERROR_SUCCESS
;
7887 UINT WINAPI
MsiGetFeatureStateW(MSIHANDLE hInstall
, LPWSTR szFeature
,
7888 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
7890 MSIPACKAGE
* package
;
7893 TRACE("%ld %s %p %p\n", hInstall
, debugstr_w(szFeature
), piInstalled
,
7896 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
7898 return ERROR_INVALID_HANDLE
;
7899 ret
= MSI_GetFeatureStateW(package
, szFeature
, piInstalled
, piAction
);
7900 msiobj_release( &package
->hdr
);
7904 /***********************************************************************
7905 * MsiGetComponentStateA (MSI.@)
7907 UINT WINAPI
MsiGetComponentStateA(MSIHANDLE hInstall
, LPSTR szComponent
,
7908 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
7910 LPWSTR szwComponent
= NULL
;
7913 szwComponent
= strdupAtoW(szComponent
);
7915 rc
= MsiGetComponentStateW(hInstall
,szwComponent
,piInstalled
, piAction
);
7917 HeapFree( GetProcessHeap(), 0 , szwComponent
);
7922 UINT
MSI_GetComponentStateW(MSIPACKAGE
*package
, LPWSTR szComponent
,
7923 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
7927 TRACE("%p %s %p %p\n", package
, debugstr_w(szComponent
), piInstalled
,
7930 index
= get_loaded_component(package
,szComponent
);
7932 return ERROR_UNKNOWN_COMPONENT
;
7935 *piInstalled
= package
->components
[index
].Installed
;
7938 *piAction
= package
->components
[index
].Action
;
7940 TRACE("states (%i, %i)\n",
7941 (piInstalled
)?*piInstalled
:-1,(piAction
)?*piAction
:-1);
7943 return ERROR_SUCCESS
;
7946 /***********************************************************************
7947 * MsiGetComponentStateW (MSI.@)
7949 UINT WINAPI
MsiGetComponentStateW(MSIHANDLE hInstall
, LPWSTR szComponent
,
7950 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
7952 MSIPACKAGE
* package
;
7955 TRACE("%ld %s %p %p\n", hInstall
, debugstr_w(szComponent
),
7956 piInstalled
, piAction
);
7958 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
7960 return ERROR_INVALID_HANDLE
;
7961 ret
= MSI_GetComponentStateW( package
, szComponent
, piInstalled
, piAction
);
7962 msiobj_release( &package
->hdr
);