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"
42 #include "msvcrt/fcntl.h"
49 #include "wine/unicode.h"
53 #define REG_PROGRESS_VALUE 13200
54 #define COMPONENT_PROGRESS_VALUE 24000
56 WINE_DEFAULT_DEBUG_CHANNEL(msi);
61 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
62 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
63 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq);
64 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
70 typedef UINT (*STANDARDACTIONHANDLER)(MSIPACKAGE*);
72 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
73 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
74 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
75 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
76 static UINT ACTION_FileCost(MSIPACKAGE *package);
77 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
78 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
79 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
80 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
81 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
82 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
83 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
84 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
85 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
86 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
87 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
88 static UINT ACTION_WriteIniValues(MSIPACKAGE *package);
89 static UINT ACTION_SelfRegModules(MSIPACKAGE *package);
90 static UINT ACTION_PublishFeatures(MSIPACKAGE *package);
91 static UINT ACTION_RegisterProduct(MSIPACKAGE *package);
92 static UINT ACTION_InstallExecute(MSIPACKAGE *package);
93 static UINT ACTION_InstallFinalize(MSIPACKAGE *package);
94 static UINT ACTION_ForceReboot(MSIPACKAGE *package);
95 static UINT ACTION_ResolveSource(MSIPACKAGE *package);
99 * consts and values used
101 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
102 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
103 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
104 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
105 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
106 static const WCHAR c_collen[] = {'C',':','\\',0};
108 static const WCHAR cszbs[]={'\\',0};
110 const static WCHAR szCreateFolders[] =
111 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
112 const static WCHAR szCostFinalize[] =
113 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
114 const static WCHAR szInstallFiles[] =
115 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
116 const static WCHAR szDuplicateFiles[] =
117 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
118 const static WCHAR szWriteRegistryValues[] =
119 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
120 const static WCHAR szCostInitialize[] =
121 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
122 const static WCHAR szFileCost[] =
123 {'F','i','l','e','C','o','s','t',0};
124 const static WCHAR szInstallInitialize[] =
125 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
126 const static WCHAR szInstallValidate[] =
127 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
128 const static WCHAR szLaunchConditions[] =
129 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
130 const static WCHAR szProcessComponents[] =
131 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
132 const static WCHAR szRegisterTypeLibraries[] =
133 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
135 const static WCHAR szRegisterClassInfo[] =
136 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
137 const static WCHAR szRegisterProgIdInfo[] =
138 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
139 const static WCHAR szCreateShortcuts[] =
140 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
141 const static WCHAR szPublishProduct[] =
142 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
143 const static WCHAR szWriteIniValues[] =
144 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
145 const static WCHAR szSelfRegModules[] =
146 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
147 const static WCHAR szPublishFeatures[] =
148 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
149 const static WCHAR szRegisterProduct[] =
150 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
151 const static WCHAR szInstallExecute[] =
152 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
153 const static WCHAR szInstallExecuteAgain[] =
154 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e','A','g','a','i','n',0};
155 const static WCHAR szInstallFinalize[] =
156 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
157 const static WCHAR szForceReboot[] =
158 {'F','o','r','c','e','R','e','b','o','o','t',0};
159 const static WCHAR szResolveSource[] =
160 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
161 const static WCHAR szAppSearch[] =
162 {'A','p','p','S','e','a','r','c','h',0};
163 const static WCHAR szAllocateRegistrySpace[] =
164 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y','S','p','a','c','e',0};
165 const static WCHAR szBindImage[] =
166 {'B','i','n','d','I','m','a','g','e',0};
167 const static WCHAR szCCPSearch[] =
168 {'C','C','P','S','e','a','r','c','h',0};
169 const static WCHAR szDeleteServices[] =
170 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
171 const static WCHAR szDisableRollback[] =
172 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
173 const static WCHAR szExecuteAction[] =
174 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
175 const static WCHAR szFindRelatedProducts[] =
176 {'F','i','n','d','R','e','l','a','t','e','d','P','r','o','d','u','c','t','s',0};
177 const static WCHAR szInstallAdminPackage[] =
178 {'I','n','s','t','a','l','l','A','d','m','i','n','P','a','c','k','a','g','e',0};
179 const static WCHAR szInstallSFPCatalogFile[] =
180 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g','F','i','l','e',0};
181 const static WCHAR szIsolateComponents[] =
182 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
183 const static WCHAR szMigrateFeatureStates[] =
184 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e','S','t','a','t','e','s',0};
185 const static WCHAR szMoveFiles[] =
186 {'M','o','v','e','F','i','l','e','s',0};
187 const static WCHAR szMsiPublishAssemblies[] =
188 {'M','s','i','P','u','b','l','i','s','h','A','s','s','e','m','b','l','i','e','s',0};
189 const static WCHAR szMsiUnpublishAssemblies[] =
190 {'M','s','i','U','n','p','u','b','l','i','s','h','A','s','s','e','m','b','l','i','e','s',0};
191 const static WCHAR szInstallODBC[] =
192 {'I','n','s','t','a','l','l','O','D','B','C',0};
193 const static WCHAR szInstallServices[] =
194 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
195 const static WCHAR szPatchFiles[] =
196 {'P','a','t','c','h','F','i','l','e','s',0};
197 const static WCHAR szPublishComponents[] =
198 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
199 const static WCHAR szRegisterComPlus[] =
200 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
201 const static WCHAR szRegisterExtensionInfo[] =
202 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n','I','n','f','o',0};
203 const static WCHAR szRegisterFonts[] =
204 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
205 const static WCHAR szRegisterMIMEInfo[] =
206 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
207 const static WCHAR szRegisterUser[] =
208 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
209 const static WCHAR szRemoveDuplicateFiles[] =
210 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
211 const static WCHAR szRemoveEnvironmentStrings[] =
212 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t','S','t','r','i','n','g','s',0};
213 const static WCHAR szRemoveExistingProducts[] =
214 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g','P','r','o','d','u','c','t','s',0};
215 const static WCHAR szRemoveFiles[] =
216 {'R','e','m','o','v','e','F','i','l','e','s',0};
217 const static WCHAR szRemoveFolders[] =
218 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
219 const static WCHAR szRemoveIniValues[] =
220 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
221 const static WCHAR szRemoveODBC[] =
222 {'R','e','m','o','v','e','O','D','B','C',0};
223 const static WCHAR szRemoveRegistryValues[] =
224 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
225 const static WCHAR szRemoveShortcuts[] =
226 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
227 const static WCHAR szRMCCPSearch[] =
228 {'R','M','C','C','P','S','e','a','r','c','h',0};
229 const static WCHAR szScheduleReboot[] =
230 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
231 const static WCHAR szSelfUnregModules[] =
232 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
233 const static WCHAR szSetODBCFolders[] =
234 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
235 const static WCHAR szStartServices[] =
236 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
237 const static WCHAR szStopServices[] =
238 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
239 const static WCHAR szUnpublishComponents[] =
240 {'U','n','p','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
241 const static WCHAR szUnpublishFeatures[] =
242 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
243 const static WCHAR szUnregisterClassInfo[] =
244 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
245 const static WCHAR szUnregisterComPlus[] =
246 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
247 const static WCHAR szUnregisterExtensionInfo[] =
248 {'U','n','r','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n','I','n','f','o',0};
249 const static WCHAR szUnregisterFonts[] =
250 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
251 const static WCHAR szUnregisterMIMEInfo[] =
252 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
253 const static WCHAR szUnregisterProgIdInfo[] =
254 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
255 const static WCHAR szUnregisterTypeLibraries[] =
256 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r','i','e','s',0};
257 const static WCHAR szValidateProductID[] =
258 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
259 const static WCHAR szWriteEnvironmentStrings[] =
260 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t','S','t','r','i','n','g','s',0};
264 STANDARDACTIONHANDLER handler;
267 struct _actions StandardActions[] = {
268 { szAllocateRegistrySpace, NULL},
269 { szAppSearch, ACTION_AppSearch },
270 { szBindImage, NULL},
271 { szCCPSearch, NULL},
272 { szCostFinalize, ACTION_CostFinalize },
273 { szCostInitialize, ACTION_CostInitialize },
274 { szCreateFolders, ACTION_CreateFolders },
275 { szCreateShortcuts, ACTION_CreateShortcuts },
276 { szDeleteServices, NULL},
277 { szDisableRollback, NULL},
278 { szDuplicateFiles, ACTION_DuplicateFiles},
279 { szExecuteAction, NULL},
280 { szFileCost, ACTION_FileCost },
281 { szFindRelatedProducts, NULL},
282 { szForceReboot, ACTION_ForceReboot },
283 { szInstallAdminPackage, NULL},
284 { szInstallExecute, ACTION_InstallExecute },
285 { szInstallExecuteAgain, ACTION_InstallExecute },
286 { szInstallFiles, ACTION_InstallFiles},
287 { szInstallFinalize, ACTION_InstallFinalize },
288 { szInstallInitialize, ACTION_InstallInitialize },
289 { szInstallSFPCatalogFile, NULL},
290 { szInstallValidate, ACTION_InstallValidate },
291 { szIsolateComponents, NULL},
292 { szLaunchConditions, ACTION_LaunchConditions },
293 { szMigrateFeatureStates, NULL},
294 { szMoveFiles, NULL},
295 { szMsiPublishAssemblies, NULL},
296 { szMsiUnpublishAssemblies, NULL},
297 { szInstallODBC, NULL},
298 { szInstallServices, NULL},
299 { szPatchFiles, NULL},
300 { szProcessComponents, ACTION_ProcessComponents },
301 { szPublishComponents, NULL},
302 { szPublishFeatures, ACTION_PublishFeatures },
303 { szPublishProduct, ACTION_PublishProduct },
304 { szRegisterClassInfo, ACTION_RegisterClassInfo },
305 { szRegisterComPlus, NULL},
306 { szRegisterExtensionInfo, NULL},
307 { szRegisterFonts, NULL},
308 { szRegisterMIMEInfo, NULL},
309 { szRegisterProduct, ACTION_RegisterProduct },
310 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
311 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
312 { szRegisterUser, NULL},
313 { szRemoveDuplicateFiles, NULL},
314 { szRemoveEnvironmentStrings, NULL},
315 { szRemoveExistingProducts, NULL},
316 { szRemoveFiles, NULL},
317 { szRemoveFolders, NULL},
318 { szRemoveIniValues, NULL},
319 { szRemoveODBC, NULL},
320 { szRemoveRegistryValues, NULL},
321 { szRemoveShortcuts, NULL},
322 { szResolveSource, ACTION_ResolveSource},
323 { szRMCCPSearch, NULL},
324 { szScheduleReboot, NULL},
325 { szSelfRegModules, ACTION_SelfRegModules },
326 { szSelfUnregModules, NULL},
327 { szSetODBCFolders, NULL},
328 { szStartServices, NULL},
329 { szStopServices, NULL},
330 { szUnpublishComponents, NULL},
331 { szUnpublishFeatures, NULL},
332 { szUnregisterClassInfo, NULL},
333 { szUnregisterComPlus, NULL},
334 { szUnregisterExtensionInfo, NULL},
335 { szUnregisterFonts, NULL},
336 { szUnregisterMIMEInfo, NULL},
337 { szUnregisterProgIdInfo, NULL},
338 { szUnregisterTypeLibraries, NULL},
339 { szValidateProductID, NULL},
340 { szWriteEnvironmentStrings, NULL},
341 { szWriteIniValues, ACTION_WriteIniValues },
342 { szWriteRegistryValues, ACTION_WriteRegistryValues},
347 /********************************************************
348 * helper functions to get around current HACKS and such
349 ********************************************************/
350 inline static void reduce_to_longfilename(WCHAR* filename)
352 LPWSTR p = strchrW(filename,'|');
354 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
357 WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
364 if (MSI_RecordIsNull(row,index))
367 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
369 /* having an empty string is different than NULL */
372 ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
378 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
379 rc = MSI_RecordGetStringW(row,index,ret,&sz);
380 if (rc!=ERROR_SUCCESS)
382 ERR("Unable to load dynamic string\n");
383 HeapFree(GetProcessHeap(), 0, ret);
389 LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop, UINT* rc)
395 r = MSI_GetPropertyW(package, prop, NULL, &sz);
396 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
403 str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
404 r = MSI_GetPropertyW(package, prop, str, &sz);
405 if (r != ERROR_SUCCESS)
407 HeapFree(GetProcessHeap(),0,str);
415 int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
420 for (i = 0; i < package->loaded_components; i++)
422 if (strcmpW(Component,package->components[i].Component)==0)
431 int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
436 for (i = 0; i < package->loaded_features; i++)
438 if (strcmpW(Feature,package->features[i].Feature)==0)
447 int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
452 for (i = 0; i < package->loaded_files; i++)
454 if (strcmpW(file,package->files[i].File)==0)
463 int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
471 for (i=0; i < package->loaded_files; i++)
472 if (strcmpW(package->files[i].File,name)==0)
475 index = package->loaded_files;
476 package->loaded_files++;
477 if (package->loaded_files== 1)
478 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
480 package->files = HeapReAlloc(GetProcessHeap(),0,
481 package->files , package->loaded_files * sizeof(MSIFILE));
483 memset(&package->files[index],0,sizeof(MSIFILE));
485 package->files[index].File = dupstrW(name);
486 package->files[index].TargetPath = dupstrW(path);
487 package->files[index].Temporary = TRUE;
489 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
494 static void remove_tracked_tempfiles(MSIPACKAGE* package)
501 for (i = 0; i < package->loaded_files; i++)
503 if (package->files[i].Temporary)
505 TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
506 DeleteFileW(package->files[i].TargetPath);
512 /* wrapper to resist a need for a full rewrite right now */
513 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
517 MSIRECORD *rec = MSI_CreateRecord(1);
519 WCHAR size_buf[2] = {' ',0};
521 MSI_RecordSetStringW(rec,0,ptr);
522 MSI_FormatRecordW(package,rec,size_buf,&size);
526 *data = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
528 MSI_FormatRecordW(package,rec,*data,&size);
531 msiobj_release( &rec->hdr );
532 return sizeof(WCHAR)*size;
534 msiobj_release( &rec->hdr );
541 /* Called when the package is being closed */
542 void ACTION_free_package_structures( MSIPACKAGE* package)
546 TRACE("Freeing package action data\n");
548 remove_tracked_tempfiles(package);
550 /* No dynamic buffers in features */
551 if (package->features && package->loaded_features > 0)
552 HeapFree(GetProcessHeap(),0,package->features);
554 for (i = 0; i < package->loaded_folders; i++)
556 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
557 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
558 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
559 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
560 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
561 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
563 if (package->folders && package->loaded_folders > 0)
564 HeapFree(GetProcessHeap(),0,package->folders);
566 /* no dynamic buffers in components */
567 if (package->components && package->loaded_components > 0)
568 HeapFree(GetProcessHeap(),0,package->components);
570 for (i = 0; i < package->loaded_files; i++)
572 HeapFree(GetProcessHeap(),0,package->files[i].File);
573 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
574 HeapFree(GetProcessHeap(),0,package->files[i].Version);
575 HeapFree(GetProcessHeap(),0,package->files[i].Language);
576 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
577 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
580 if (package->files && package->loaded_files > 0)
581 HeapFree(GetProcessHeap(),0,package->files);
583 for (i = 0; i < package->DeferredActionCount; i++)
584 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
585 HeapFree(GetProcessHeap(),0,package->DeferredAction);
587 for (i = 0; i < package->CommitActionCount; i++)
588 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
589 HeapFree(GetProcessHeap(),0,package->CommitAction);
591 HeapFree(GetProcessHeap(),0,package->PackagePath);
594 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
598 row = MSI_CreateRecord(4);
599 MSI_RecordSetInteger(row,1,a);
600 MSI_RecordSetInteger(row,2,b);
601 MSI_RecordSetInteger(row,3,c);
602 MSI_RecordSetInteger(row,4,d);
603 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
604 msiobj_release(&row->hdr);
607 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
609 static const WCHAR Query_t[] =
610 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
611 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
612 ' ','\'','%','s','\'',0};
619 if (!package->LastAction || strcmpW(package->LastAction,action))
621 rc = MSI_OpenQuery(package->db, &view, Query_t, action);
622 if (rc != ERROR_SUCCESS)
625 rc = MSI_ViewExecute(view, 0);
626 if (rc != ERROR_SUCCESS)
631 rc = MSI_ViewFetch(view,&row);
632 if (rc != ERROR_SUCCESS)
638 if (MSI_RecordIsNull(row,3))
640 msiobj_release(&row->hdr);
642 msiobj_release(&view->hdr);
646 /* update the cached actionformat */
647 HeapFree(GetProcessHeap(),0,package->ActionFormat);
648 package->ActionFormat = load_dynamic_stringW(row,3);
650 HeapFree(GetProcessHeap(),0,package->LastAction);
651 package->LastAction = dupstrW(action);
653 msiobj_release(&row->hdr);
655 msiobj_release(&view->hdr);
658 MSI_RecordSetStringW(record,0,package->ActionFormat);
660 MSI_FormatRecordW(package,record,message,&size);
662 row = MSI_CreateRecord(1);
663 MSI_RecordSetStringW(row,1,message);
665 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
666 msiobj_release(&row->hdr);
670 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
672 static const WCHAR template_s[]=
673 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
674 static const WCHAR format[] =
675 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
676 static const WCHAR Query_t[] =
677 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
678 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
679 ' ','\'','%','s','\'',0};
685 WCHAR *ActionText=NULL;
687 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
689 rc = MSI_OpenQuery(package->db, &view, Query_t, action);
690 if (rc != ERROR_SUCCESS)
692 rc = MSI_ViewExecute(view, 0);
693 if (rc != ERROR_SUCCESS)
696 msiobj_release(&view->hdr);
699 rc = MSI_ViewFetch(view,&row);
700 if (rc != ERROR_SUCCESS)
703 msiobj_release(&view->hdr);
707 ActionText = load_dynamic_stringW(row,2);
708 msiobj_release(&row->hdr);
710 msiobj_release(&view->hdr);
712 sprintfW(message,template_s,timet,action,ActionText);
714 row = MSI_CreateRecord(1);
715 MSI_RecordSetStringW(row,1,message);
717 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
718 msiobj_release(&row->hdr);
719 HeapFree(GetProcessHeap(),0,ActionText);
722 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
726 static const WCHAR template_s[]=
727 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
729 static const WCHAR template_e[]=
730 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
731 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
732 static const WCHAR format[] =
733 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
737 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
739 sprintfW(message,template_s,timet,action);
741 sprintfW(message,template_e,timet,action,rc);
743 row = MSI_CreateRecord(1);
744 MSI_RecordSetStringW(row,1,message);
746 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
747 msiobj_release(&row->hdr);
751 * build_directory_name()
753 * This function is to save messing round with directory names
754 * It handles adding backslashes between path segments,
755 * and can add \ at the end of the directory name if told to.
757 * It takes a variable number of arguments.
758 * It always allocates a new string for the result, so make sure
759 * to free the return value when finished with it.
761 * The first arg is the number of path segments that follow.
762 * The arguments following count are a list of path segments.
763 * A path segment may be NULL.
765 * Path segments will be added with a \ separating them.
766 * A \ will not be added after the last segment, however if the
767 * last segment is NULL, then the last character will be a \
770 static LPWSTR build_directory_name(DWORD count, ...)
777 for(i=0; i<count; i++)
779 LPCWSTR str = va_arg(va,LPCWSTR);
781 sz += strlenW(str) + 1;
785 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
789 for(i=0; i<count; i++)
791 LPCWSTR str = va_arg(va,LPCWSTR);
795 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
802 /****************************************************
803 * TOP level entry points
804 *****************************************************/
806 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
807 LPCWSTR szCommandLine)
812 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
813 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
814 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
816 MSI_SetPropertyW(package, szAction, szInstall);
820 LPWSTR p, check, path;
822 package->PackagePath = dupstrW(szPackagePath);
823 path = dupstrW(szPackagePath);
824 p = strrchrW(path,'\\');
832 HeapFree(GetProcessHeap(),0,path);
833 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
834 GetCurrentDirectoryW(MAX_PATH,path);
838 check = load_dynamic_property(package, cszSourceDir,NULL);
840 MSI_SetPropertyW(package, cszSourceDir, path);
842 HeapFree(GetProcessHeap(), 0, check);
844 HeapFree(GetProcessHeap(), 0, path);
850 ptr = (LPWSTR)szCommandLine;
857 TRACE("Looking at %s\n",debugstr_w(ptr));
859 ptr2 = strchrW(ptr,'=');
865 while (*ptr == ' ') ptr++;
867 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
868 strncpyW(prop,ptr,len);
874 while (*ptr && (quote || (!quote && *ptr!=' ')))
887 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
888 strncpyW(val,ptr2,len);
891 if (strlenW(prop) > 0)
893 TRACE("Found commandline property (%s) = (%s)\n",
894 debugstr_w(prop), debugstr_w(val));
895 MSI_SetPropertyW(package,prop,val);
897 HeapFree(GetProcessHeap(),0,val);
898 HeapFree(GetProcessHeap(),0,prop);
905 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
907 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
909 rc = ACTION_ProcessUISequence(package);
910 if (rc == ERROR_SUCCESS)
911 rc = ACTION_ProcessExecSequence(package,TRUE);
914 rc = ACTION_ProcessExecSequence(package,FALSE);
917 rc = ACTION_ProcessExecSequence(package,FALSE);
921 /* install was halted but should be considered a success */
925 /* process the ending type action */
926 if (rc == ERROR_SUCCESS)
927 ACTION_PerformActionSequence(package,-1);
928 else if (rc == ERROR_INSTALL_USEREXIT)
929 ACTION_PerformActionSequence(package,-2);
930 else if (rc == ERROR_FUNCTION_FAILED)
931 ACTION_PerformActionSequence(package,-3);
932 else if (rc == ERROR_INSTALL_SUSPEND)
933 ACTION_PerformActionSequence(package,-4);
935 /* finish up running custom actions */
936 ACTION_FinishCustomActions(package);
941 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq)
948 static const WCHAR ExecSeqQuery[] = {
949 's','e','l','e','c','t',' ','*',' ',
951 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
952 'S','e','q','u','e','n','c','e',' ',
953 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
956 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
958 if (rc == ERROR_SUCCESS)
960 rc = MSI_ViewExecute(view, 0);
962 if (rc != ERROR_SUCCESS)
965 msiobj_release(&view->hdr);
969 TRACE("Running the actions\n");
971 rc = MSI_ViewFetch(view,&row);
972 if (rc != ERROR_SUCCESS)
978 /* check conditions */
979 if (!MSI_RecordIsNull(row,2))
982 cond = load_dynamic_stringW(row,2);
986 /* this is a hack to skip errors in the condition code */
987 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
989 HeapFree(GetProcessHeap(),0,cond);
990 msiobj_release(&row->hdr);
994 HeapFree(GetProcessHeap(),0,cond);
999 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1000 if (rc != ERROR_SUCCESS)
1002 ERR("Error is %x\n",rc);
1003 msiobj_release(&row->hdr);
1007 rc = ACTION_PerformAction(package,buffer);
1008 msiobj_release(&row->hdr);
1010 MSI_ViewClose(view);
1011 msiobj_release(&view->hdr);
1019 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1023 static const WCHAR ExecSeqQuery[] = {
1024 's','e','l','e','c','t',' ','*',' ',
1025 'f','r','o','m',' ',
1026 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1027 'S','e','q','u','e','n','c','e',' ',
1028 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
1029 '>',' ','%','i',' ','o','r','d','e','r',' ',
1030 'b','y',' ','S','e','q','u','e','n','c','e',0 };
1031 MSIRECORD * row = 0;
1032 static const WCHAR IVQuery[] = {
1033 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
1034 'f','r','o','m',' ','I','n','s','t','a','l','l',
1035 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
1036 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
1037 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
1041 /* get the sequence number */
1044 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
1045 if (rc != ERROR_SUCCESS)
1047 rc = MSI_ViewExecute(view, 0);
1048 if (rc != ERROR_SUCCESS)
1050 MSI_ViewClose(view);
1051 msiobj_release(&view->hdr);
1054 rc = MSI_ViewFetch(view,&row);
1055 if (rc != ERROR_SUCCESS)
1057 MSI_ViewClose(view);
1058 msiobj_release(&view->hdr);
1061 seq = MSI_RecordGetInteger(row,1);
1062 msiobj_release(&row->hdr);
1063 MSI_ViewClose(view);
1064 msiobj_release(&view->hdr);
1067 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1068 if (rc == ERROR_SUCCESS)
1070 rc = MSI_ViewExecute(view, 0);
1072 if (rc != ERROR_SUCCESS)
1074 MSI_ViewClose(view);
1075 msiobj_release(&view->hdr);
1079 TRACE("Running the actions\n");
1083 WCHAR buffer[0x100];
1086 rc = MSI_ViewFetch(view,&row);
1087 if (rc != ERROR_SUCCESS)
1093 /* check conditions */
1094 if (!MSI_RecordIsNull(row,2))
1097 cond = load_dynamic_stringW(row,2);
1101 /* this is a hack to skip errors in the condition code */
1102 if (MSI_EvaluateConditionW(package, cond) ==
1105 HeapFree(GetProcessHeap(),0,cond);
1106 msiobj_release(&row->hdr);
1110 HeapFree(GetProcessHeap(),0,cond);
1115 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1116 if (rc != ERROR_SUCCESS)
1118 ERR("Error is %x\n",rc);
1119 msiobj_release(&row->hdr);
1123 rc = ACTION_PerformAction(package,buffer);
1125 if (rc == ERROR_FUNCTION_NOT_CALLED)
1128 if (rc != ERROR_SUCCESS)
1130 ERR("Execution halted due to error (%i)\n",rc);
1131 msiobj_release(&row->hdr);
1135 msiobj_release(&row->hdr);
1138 MSI_ViewClose(view);
1139 msiobj_release(&view->hdr);
1147 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1151 static const WCHAR ExecSeqQuery [] = {
1152 's','e','l','e','c','t',' ','*',' ',
1153 'f','r','o','m',' ','I','n','s','t','a','l','l',
1154 'U','I','S','e','q','u','e','n','c','e',' ',
1155 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
1156 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
1158 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1160 if (rc == ERROR_SUCCESS)
1162 rc = MSI_ViewExecute(view, 0);
1164 if (rc != ERROR_SUCCESS)
1166 MSI_ViewClose(view);
1167 msiobj_release(&view->hdr);
1171 TRACE("Running the actions \n");
1175 WCHAR buffer[0x100];
1177 MSIRECORD * row = 0;
1179 rc = MSI_ViewFetch(view,&row);
1180 if (rc != ERROR_SUCCESS)
1186 /* check conditions */
1187 if (!MSI_RecordIsNull(row,2))
1190 cond = load_dynamic_stringW(row,2);
1194 /* this is a hack to skip errors in the condition code */
1195 if (MSI_EvaluateConditionW(package, cond) ==
1198 HeapFree(GetProcessHeap(),0,cond);
1199 msiobj_release(&row->hdr);
1203 HeapFree(GetProcessHeap(),0,cond);
1208 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1209 if (rc != ERROR_SUCCESS)
1211 ERR("Error is %x\n",rc);
1212 msiobj_release(&row->hdr);
1216 rc = ACTION_PerformUIAction(package,buffer);
1218 if (rc == ERROR_FUNCTION_NOT_CALLED)
1221 if (rc != ERROR_SUCCESS)
1223 ERR("Execution halted due to error (%i)\n",rc);
1224 msiobj_release(&row->hdr);
1228 msiobj_release(&row->hdr);
1231 MSI_ViewClose(view);
1232 msiobj_release(&view->hdr);
1239 /********************************************************
1240 * ACTION helper functions and functions that perform the actions
1241 *******************************************************/
1242 BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action, UINT* rc)
1248 while (StandardActions[i].action != NULL)
1250 if (strcmpW(StandardActions[i].action, action)==0)
1252 ui_actioninfo(package, action, TRUE, 0);
1253 ui_actionstart(package, action);
1254 if (StandardActions[i].handler)
1256 *rc = StandardActions[i].handler(package);
1260 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1261 *rc = ERROR_SUCCESS;
1263 ui_actioninfo(package, action, FALSE, *rc);
1272 BOOL ACTION_HandleDialogBox(MSIPACKAGE *package, LPCWSTR dialog, UINT* rc)
1277 * for the UI when we get that working
1279 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1281 *rc = package->CurrentInstallState;
1288 BOOL ACTION_HandleCustomAction(MSIPACKAGE* package, LPCWSTR action, UINT* rc)
1293 arc = ACTION_CustomAction(package,action,FALSE);
1295 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1304 * A lot of actions are really important even if they don't do anything
1305 * explicit... Lots of properties are set at the beginning of the installation
1306 * CostFinalize does a bunch of work to translate the directories and such
1308 * But until I get write access to the database that is hard, so I am going to
1309 * hack it to see if I can get something to run.
1311 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
1313 UINT rc = ERROR_SUCCESS;
1316 TRACE("Performing action (%s)\n",debugstr_w(action));
1318 handled = ACTION_HandleStandardAction(package, action, &rc);
1321 handled = ACTION_HandleCustomAction(package, action, &rc);
1325 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1326 rc = ERROR_FUNCTION_NOT_CALLED;
1329 package->CurrentInstallState = rc;
1333 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1335 UINT rc = ERROR_SUCCESS;
1336 BOOL handled = FALSE;
1338 TRACE("Performing action (%s)\n",debugstr_w(action));
1340 handled = ACTION_HandleStandardAction(package, action, &rc);
1343 handled = ACTION_HandleCustomAction(package, action, &rc);
1346 handled = ACTION_HandleDialogBox(package, action, &rc);
1350 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1351 rc = ERROR_FUNCTION_NOT_CALLED;
1354 package->CurrentInstallState = rc;
1358 /***********************************************************************
1361 * Recursively create all directories in the path.
1363 * shamelessly stolen from setupapi/queue.c
1365 static BOOL create_full_pathW(const WCHAR *path)
1371 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1374 strcpyW(new_path, path);
1376 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1377 new_path[len - 1] = 0;
1379 while(!CreateDirectoryW(new_path, NULL))
1382 DWORD last_error = GetLastError();
1383 if(last_error == ERROR_ALREADY_EXISTS)
1386 if(last_error != ERROR_PATH_NOT_FOUND)
1392 if(!(slash = strrchrW(new_path, '\\')))
1398 len = slash - new_path;
1400 if(!create_full_pathW(new_path))
1405 new_path[len] = '\\';
1408 HeapFree(GetProcessHeap(), 0, new_path);
1413 * Also we cannot enable/disable components either, so for now I am just going
1414 * to do all the directories for all the components.
1416 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1418 static const WCHAR ExecSeqQuery[] = {
1419 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1420 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1425 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1426 if (rc != ERROR_SUCCESS)
1427 return ERROR_SUCCESS;
1429 rc = MSI_ViewExecute(view, 0);
1430 if (rc != ERROR_SUCCESS)
1432 MSI_ViewClose(view);
1433 msiobj_release(&view->hdr);
1442 MSIRECORD *row = NULL, *uirow;
1444 rc = MSI_ViewFetch(view,&row);
1445 if (rc != ERROR_SUCCESS)
1452 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1454 if (rc!= ERROR_SUCCESS)
1456 ERR("Unable to get folder id \n");
1457 msiobj_release(&row->hdr);
1462 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1465 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1466 msiobj_release(&row->hdr);
1470 TRACE("Folder is %s\n",debugstr_w(full_path));
1473 uirow = MSI_CreateRecord(1);
1474 MSI_RecordSetStringW(uirow,1,full_path);
1475 ui_actiondata(package,szCreateFolders,uirow);
1476 msiobj_release( &uirow->hdr );
1478 if (folder->State == 0)
1479 create_full_pathW(full_path);
1483 msiobj_release(&row->hdr);
1484 HeapFree(GetProcessHeap(),0,full_path);
1486 MSI_ViewClose(view);
1487 msiobj_release(&view->hdr);
1492 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1494 int index = package->loaded_components;
1497 /* fill in the data */
1499 package->loaded_components++;
1500 if (package->loaded_components == 1)
1501 package->components = HeapAlloc(GetProcessHeap(),0,
1502 sizeof(MSICOMPONENT));
1504 package->components = HeapReAlloc(GetProcessHeap(),0,
1505 package->components, package->loaded_components *
1506 sizeof(MSICOMPONENT));
1508 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1511 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1513 TRACE("Loading Component %s\n",
1514 debugstr_w(package->components[index].Component));
1517 if (!MSI_RecordIsNull(row,2))
1518 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1521 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1523 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1526 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1529 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1531 package->components[index].Installed = INSTALLSTATE_ABSENT;
1532 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1533 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1535 package->components[index].Enabled = TRUE;
1540 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1542 int index = package->loaded_features;
1544 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1545 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1546 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1547 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1548 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1549 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1550 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1557 /* fill in the data */
1559 package->loaded_features ++;
1560 if (package->loaded_features == 1)
1561 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1563 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1564 package->loaded_features * sizeof(MSIFEATURE));
1566 memset(&package->features[index],0,sizeof(MSIFEATURE));
1569 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1571 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1574 if (!MSI_RecordIsNull(row,2))
1575 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1578 if (!MSI_RecordIsNull(row,3))
1579 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1582 if (!MSI_RecordIsNull(row,4))
1583 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1585 if (!MSI_RecordIsNull(row,5))
1586 package->features[index].Display = MSI_RecordGetInteger(row,5);
1588 package->features[index].Level= MSI_RecordGetInteger(row,6);
1591 if (!MSI_RecordIsNull(row,7))
1592 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1594 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1596 package->features[index].Installed = INSTALLSTATE_ABSENT;
1597 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1598 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1600 /* load feature components */
1602 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1603 if (rc != ERROR_SUCCESS)
1605 rc = MSI_ViewExecute(view,0);
1606 if (rc != ERROR_SUCCESS)
1608 MSI_ViewClose(view);
1609 msiobj_release(&view->hdr);
1615 WCHAR buffer[0x100];
1618 INT cnt = package->features[index].ComponentCount;
1620 rc = MSI_ViewFetch(view,&row2);
1621 if (rc != ERROR_SUCCESS)
1625 MSI_RecordGetStringW(row2,1,buffer,&sz);
1627 /* check to see if the component is already loaded */
1628 c_indx = get_loaded_component(package,buffer);
1631 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1633 package->features[index].Components[cnt] = c_indx;
1634 package->features[index].ComponentCount ++;
1638 rc = MSI_OpenQuery(package->db, &view2, Query2, buffer);
1639 if (rc != ERROR_SUCCESS)
1641 msiobj_release( &row2->hdr );
1644 rc = MSI_ViewExecute(view2,0);
1645 if (rc != ERROR_SUCCESS)
1647 msiobj_release( &row2->hdr );
1648 MSI_ViewClose(view2);
1649 msiobj_release( &view2->hdr );
1656 rc = MSI_ViewFetch(view2,&row3);
1657 if (rc != ERROR_SUCCESS)
1659 c_indx = load_component(package,row3);
1660 msiobj_release( &row3->hdr );
1662 package->features[index].Components[cnt] = c_indx;
1663 package->features[index].ComponentCount ++;
1664 TRACE("Loaded new component to index %i\n",c_indx);
1666 MSI_ViewClose(view2);
1667 msiobj_release( &view2->hdr );
1668 msiobj_release( &row2->hdr );
1670 MSI_ViewClose(view);
1671 msiobj_release(&view->hdr);
1675 * I am not doing any of the costing functionality yet.
1676 * Mostly looking at doing the Component and Feature loading
1678 * The native MSI does A LOT of modification to tables here. Mostly adding
1679 * a lot of temporary columns to the Feature and Component tables.
1681 * note: Native msi also tracks the short filename. But I am only going to
1682 * track the long ones. Also looking at this directory table
1683 * it appears that the directory table does not get the parents
1684 * resolved base on property only based on their entries in the
1687 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1692 static const WCHAR Query_all[] = {
1693 'S','E','L','E','C','T',' ','*',' ',
1694 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1695 static const WCHAR szCosting[] = {
1696 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1697 static const WCHAR szZero[] = { '0', 0 };
1699 MSI_SetPropertyW(package, szCosting, szZero);
1700 MSI_SetPropertyW(package, cszRootDrive , c_collen);
1702 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1703 if (rc != ERROR_SUCCESS)
1705 rc = MSI_ViewExecute(view,0);
1706 if (rc != ERROR_SUCCESS)
1708 MSI_ViewClose(view);
1709 msiobj_release(&view->hdr);
1716 rc = MSI_ViewFetch(view,&row);
1717 if (rc != ERROR_SUCCESS)
1720 load_feature(package,row);
1721 msiobj_release(&row->hdr);
1723 MSI_ViewClose(view);
1724 msiobj_release(&view->hdr);
1726 return ERROR_SUCCESS;
1729 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1731 DWORD index = package->loaded_files;
1735 /* fill in the data */
1737 package->loaded_files++;
1738 if (package->loaded_files== 1)
1739 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1741 package->files = HeapReAlloc(GetProcessHeap(),0,
1742 package->files , package->loaded_files * sizeof(MSIFILE));
1744 memset(&package->files[index],0,sizeof(MSIFILE));
1746 package->files[index].File = load_dynamic_stringW(row, 1);
1747 buffer = load_dynamic_stringW(row, 2);
1749 package->files[index].ComponentIndex = -1;
1750 for (i = 0; i < package->loaded_components; i++)
1751 if (strcmpW(package->components[i].Component,buffer)==0)
1753 package->files[index].ComponentIndex = i;
1756 if (package->files[index].ComponentIndex == -1)
1757 ERR("Unfound Component %s\n",debugstr_w(buffer));
1758 HeapFree(GetProcessHeap(), 0, buffer);
1760 package->files[index].FileName = load_dynamic_stringW(row,3);
1762 reduce_to_longfilename(package->files[index].FileName);
1764 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1765 package->files[index].Version = load_dynamic_stringW(row, 5);
1766 package->files[index].Language = load_dynamic_stringW(row, 6);
1767 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1768 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1770 package->files[index].Temporary = FALSE;
1771 package->files[index].State = 0;
1773 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1775 return ERROR_SUCCESS;
1778 static UINT ACTION_FileCost(MSIPACKAGE *package)
1783 static const WCHAR Query[] = {
1784 'S','E','L','E','C','T',' ','*',' ',
1785 'F','R','O','M',' ','F','i','l','e',' ',
1786 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1789 return ERROR_INVALID_HANDLE;
1791 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1792 if (rc != ERROR_SUCCESS)
1793 return ERROR_SUCCESS;
1795 rc = MSI_ViewExecute(view, 0);
1796 if (rc != ERROR_SUCCESS)
1798 MSI_ViewClose(view);
1799 msiobj_release(&view->hdr);
1800 return ERROR_SUCCESS;
1805 rc = MSI_ViewFetch(view,&row);
1806 if (rc != ERROR_SUCCESS)
1811 load_file(package,row);
1812 msiobj_release(&row->hdr);
1814 MSI_ViewClose(view);
1815 msiobj_release(&view->hdr);
1817 return ERROR_SUCCESS;
1820 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1823 static const WCHAR Query[] =
1824 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1825 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1826 'o','r','y','`',' ','=',' ','`','%','s','`',0};
1829 LPWSTR targetdir, parent, srcdir;
1830 MSIRECORD * row = 0;
1834 TRACE("Looking for dir %s\n",debugstr_w(dir));
1836 for (i = 0; i < package->loaded_folders; i++)
1838 if (strcmpW(package->folders[i].Directory,dir)==0)
1840 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1845 TRACE("Working to load %s\n",debugstr_w(dir));
1847 index = package->loaded_folders++;
1848 if (package->loaded_folders==1)
1849 package->folders = HeapAlloc(GetProcessHeap(),0,
1852 package->folders= HeapReAlloc(GetProcessHeap(),0,
1853 package->folders, package->loaded_folders*
1856 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1858 package->folders[index].Directory = dupstrW(dir);
1860 rc = MSI_OpenQuery(package->db, &view, Query, dir);
1861 if (rc != ERROR_SUCCESS)
1864 rc = MSI_ViewExecute(view, 0);
1865 if (rc != ERROR_SUCCESS)
1867 MSI_ViewClose(view);
1868 msiobj_release(&view->hdr);
1872 rc = MSI_ViewFetch(view,&row);
1873 if (rc != ERROR_SUCCESS)
1875 MSI_ViewClose(view);
1876 msiobj_release(&view->hdr);
1880 targetdir = load_dynamic_stringW(row,3);
1882 /* split src and target dir */
1883 if (strchrW(targetdir,':'))
1885 srcdir=strchrW(targetdir,':');
1892 /* for now only pick long filename versions */
1893 if (strchrW(targetdir,'|'))
1895 targetdir = strchrW(targetdir,'|');
1899 if (srcdir && strchrW(srcdir,'|'))
1901 srcdir= strchrW(srcdir,'|');
1906 /* now check for root dirs */
1907 if (targetdir[0] == '.' && targetdir[1] == 0)
1910 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1915 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1916 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
1917 package->folders[index].TargetDefault = dupstrW(targetdir);
1921 package->folders[index].SourceDefault = dupstrW(srcdir);
1923 package->folders[index].SourceDefault = dupstrW(targetdir);
1924 HeapFree(GetProcessHeap(), 0, targetdir);
1926 parent = load_dynamic_stringW(row,2);
1929 i = load_folder(package,parent);
1930 package->folders[index].ParentIndex = i;
1931 TRACE("Parent is index %i... %s %s\n",
1932 package->folders[index].ParentIndex,
1933 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1934 debugstr_w(parent));
1937 package->folders[index].ParentIndex = -2;
1938 HeapFree(GetProcessHeap(), 0, parent);
1940 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
1942 msiobj_release(&row->hdr);
1943 MSI_ViewClose(view);
1944 msiobj_release(&view->hdr);
1945 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1950 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
1951 BOOL set_prop, MSIFOLDER **folder)
1954 LPWSTR p, path = NULL;
1956 TRACE("Working to resolve %s\n",debugstr_w(name));
1958 /* special resolving for Target and Source root dir */
1959 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
1963 path = load_dynamic_property(package,cszTargetDir,NULL);
1966 path = load_dynamic_property(package,cszRootDrive,NULL);
1968 MSI_SetPropertyW(package,cszTargetDir,path);
1972 for (i = 0; i < package->loaded_folders; i++)
1974 if (strcmpW(package->folders[i].Directory,name)==0)
1977 *folder = &(package->folders[i]);
1983 path = load_dynamic_property(package,cszSourceDir,NULL);
1986 path = load_dynamic_property(package,cszDatabase,NULL);
1989 p = strrchrW(path,'\\');
1996 for (i = 0; i < package->loaded_folders; i++)
1998 if (strcmpW(package->folders[i].Directory,name)==0)
2001 *folder = &(package->folders[i]);
2007 for (i = 0; i < package->loaded_folders; i++)
2009 if (strcmpW(package->folders[i].Directory,name)==0)
2013 if (i >= package->loaded_folders)
2017 *folder = &(package->folders[i]);
2019 if (!source && package->folders[i].ResolvedTarget)
2021 path = dupstrW(package->folders[i].ResolvedTarget);
2022 TRACE(" already resolved to %s\n",debugstr_w(path));
2025 else if (source && package->folders[i].ResolvedSource)
2027 path = dupstrW(package->folders[i].ResolvedSource);
2030 else if (!source && package->folders[i].Property)
2032 path = build_directory_name(2, package->folders[i].Property, NULL);
2034 TRACE(" internally set to %s\n",debugstr_w(path));
2036 MSI_SetPropertyW(package,name,path);
2040 if (package->folders[i].ParentIndex >= 0)
2042 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2044 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2046 p = resolve_folder(package, parent, source, set_prop, NULL);
2049 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2050 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2051 package->folders[i].ResolvedTarget = dupstrW(path);
2052 TRACE(" resolved into %s\n",debugstr_w(path));
2054 MSI_SetPropertyW(package,name,path);
2058 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2059 package->folders[i].ResolvedSource = dupstrW(path);
2061 HeapFree(GetProcessHeap(),0,p);
2066 /* update compoennt state based on a feature change */
2067 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2070 INSTALLSTATE newstate;
2071 MSIFEATURE *feature;
2073 i = get_loaded_feature(package,szFeature);
2077 feature = &package->features[i];
2078 newstate = feature->ActionRequest;
2080 for( i = 0; i < feature->ComponentCount; i++)
2082 MSICOMPONENT* component = &package->components[feature->Components[i]];
2084 if (!component->Enabled)
2088 if (newstate == INSTALLSTATE_LOCAL)
2089 component->ActionRequest = INSTALLSTATE_LOCAL;
2094 component->ActionRequest = newstate;
2096 /*if any other feature wants is local we need to set it local*/
2098 j < package->loaded_features &&
2099 component->ActionRequest != INSTALLSTATE_LOCAL;
2102 for (k = 0; k < package->features[j].ComponentCount; k++)
2103 if ( package->features[j].Components[k] ==
2104 feature->Components[i] )
2106 if (package->features[j].ActionRequest ==
2108 component->ActionRequest = INSTALLSTATE_LOCAL;
2117 static UINT SetFeatureStates(MSIPACKAGE *package)
2123 LPWSTR override = NULL;
2124 static const WCHAR all[]={'A','L','L',0};
2125 static const WCHAR szlevel[] = {
2126 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2127 static const WCHAR szAddLocal[] = {
2128 'A','D','D','L','O','C','A','L',0};
2130 /* I do not know if this is where it should happen.. but */
2132 TRACE("Checking Install Level\n");
2134 level = load_dynamic_property(package,szlevel,NULL);
2137 install_level = atoiW(level);
2138 HeapFree(GetProcessHeap(), 0, level);
2143 /* ok hereis the rub
2144 * ADDLOCAL and its friend OVERRIDE INSTALLLEVLE
2145 * I have confirmed this if ADDLOCALis stated then the INSTALLLEVEL is
2146 * itnored for all the features. seems strange, epsecially since it is not
2147 * documented anywhere, but it is how it works.
2150 override = load_dynamic_property(package,szAddLocal,NULL);
2154 for(i = 0; i < package->loaded_features; i++)
2156 if (strcmpiW(override,all)==0)
2158 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2159 package->features[i].Action = INSTALLSTATE_LOCAL;
2163 LPWSTR ptr = override;
2164 LPWSTR ptr2 = strchrW(override,',');
2169 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2171 strcmpW(ptr,package->features[i].Feature)==0))
2173 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2174 package->features[i].Action = INSTALLSTATE_LOCAL;
2180 ptr2 = strchrW(ptr,',');
2187 HeapFree(GetProcessHeap(),0,override);
2191 for(i = 0; i < package->loaded_features; i++)
2193 BOOL feature_state= ((package->features[i].Level > 0) &&
2194 (package->features[i].Level <= install_level));
2198 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2199 package->features[i].Action = INSTALLSTATE_LOCAL;
2205 * now we want to enable or disable components base on feature
2208 for(i = 0; i < package->loaded_features; i++)
2210 MSIFEATURE* feature = &package->features[i];
2211 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2212 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2213 feature->ActionRequest);
2215 for( j = 0; j < feature->ComponentCount; j++)
2217 MSICOMPONENT* component = &package->components[
2218 feature->Components[j]];
2220 if (!component->Enabled)
2222 component->Action = INSTALLSTATE_ABSENT;
2223 component->ActionRequest = INSTALLSTATE_ABSENT;
2227 if (feature->Action == INSTALLSTATE_LOCAL)
2228 component->Action = INSTALLSTATE_LOCAL;
2229 if (feature->ActionRequest == INSTALLSTATE_LOCAL)
2230 component->ActionRequest = INSTALLSTATE_LOCAL;
2235 for(i = 0; i < package->loaded_components; i++)
2237 MSICOMPONENT* component= &package->components[i];
2239 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2240 debugstr_w(component->Component), component->Installed,
2241 component->Action, component->ActionRequest);
2245 return ERROR_SUCCESS;
2249 * A lot is done in this function aside from just the costing.
2250 * The costing needs to be implemented at some point but for now I am going
2251 * to focus on the directory building
2254 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2256 static const WCHAR ExecSeqQuery[] = {
2257 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2258 'D','i','r','e','c','t','o','r','y',0};
2259 static const WCHAR ConditionQuery[] = {
2260 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2261 'C','o','n','d','i','t','i','o','n',0};
2262 static const WCHAR szCosting[] = {
2263 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2264 static const WCHAR szlevel[] = {
2265 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2266 static const WCHAR szOne[] = { '1', 0 };
2272 TRACE("Building Directory properties\n");
2274 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2275 if (rc == ERROR_SUCCESS)
2277 rc = MSI_ViewExecute(view, 0);
2278 if (rc != ERROR_SUCCESS)
2280 MSI_ViewClose(view);
2281 msiobj_release(&view->hdr);
2289 MSIRECORD * row = 0;
2292 rc = MSI_ViewFetch(view,&row);
2293 if (rc != ERROR_SUCCESS)
2300 MSI_RecordGetStringW(row,1,name,&sz);
2302 /* This helper function now does ALL the work */
2303 TRACE("Dir %s ...\n",debugstr_w(name));
2304 load_folder(package,name);
2305 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2306 TRACE("resolves to %s\n",debugstr_w(path));
2307 HeapFree( GetProcessHeap(), 0, path);
2309 msiobj_release(&row->hdr);
2311 MSI_ViewClose(view);
2312 msiobj_release(&view->hdr);
2315 TRACE("File calculations %i files\n",package->loaded_files);
2317 for (i = 0; i < package->loaded_files; i++)
2319 MSICOMPONENT* comp = NULL;
2320 MSIFILE* file= NULL;
2322 file = &package->files[i];
2323 if (file->ComponentIndex >= 0)
2324 comp = &package->components[file->ComponentIndex];
2326 if (file->Temporary == TRUE)
2333 /* calculate target */
2334 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2336 HeapFree(GetProcessHeap(),0,file->TargetPath);
2338 TRACE("file %s is named %s\n",
2339 debugstr_w(file->File),debugstr_w(file->FileName));
2341 file->TargetPath = build_directory_name(2, p, file->FileName);
2343 HeapFree(GetProcessHeap(),0,p);
2345 TRACE("file %s resolves to %s\n",
2346 debugstr_w(file->File),debugstr_w(file->TargetPath));
2348 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2351 comp->Cost += file->FileSize;
2361 static const WCHAR name[] =
2363 static const WCHAR name_fmt[] =
2364 {'%','u','.','%','u','.','%','u','.','%','u',0};
2365 WCHAR filever[0x100];
2366 VS_FIXEDFILEINFO *lpVer;
2368 TRACE("Version comparison.. \n");
2369 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2370 version = HeapAlloc(GetProcessHeap(),0,versize);
2371 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2373 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2375 sprintfW(filever,name_fmt,
2376 HIWORD(lpVer->dwFileVersionMS),
2377 LOWORD(lpVer->dwFileVersionMS),
2378 HIWORD(lpVer->dwFileVersionLS),
2379 LOWORD(lpVer->dwFileVersionLS));
2381 TRACE("new %s old %s\n", debugstr_w(file->Version),
2382 debugstr_w(filever));
2383 if (strcmpiW(filever,file->Version)<0)
2386 FIXME("cost should be diff in size\n");
2387 comp->Cost += file->FileSize;
2391 HeapFree(GetProcessHeap(),0,version);
2399 TRACE("Evaluating Condition Table\n");
2401 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2402 if (rc == ERROR_SUCCESS)
2404 rc = MSI_ViewExecute(view, 0);
2405 if (rc != ERROR_SUCCESS)
2407 MSI_ViewClose(view);
2408 msiobj_release(&view->hdr);
2414 WCHAR Feature[0x100];
2415 MSIRECORD * row = 0;
2419 rc = MSI_ViewFetch(view,&row);
2421 if (rc != ERROR_SUCCESS)
2428 MSI_RecordGetStringW(row,1,Feature,&sz);
2430 feature_index = get_loaded_feature(package,Feature);
2431 if (feature_index < 0)
2432 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2436 Condition = load_dynamic_stringW(row,3);
2438 if (MSI_EvaluateConditionW(package,Condition) ==
2441 int level = MSI_RecordGetInteger(row,2);
2442 TRACE("Reseting feature %s to level %i\n",
2443 debugstr_w(Feature), level);
2444 package->features[feature_index].Level = level;
2446 HeapFree(GetProcessHeap(),0,Condition);
2449 msiobj_release(&row->hdr);
2451 MSI_ViewClose(view);
2452 msiobj_release(&view->hdr);
2455 TRACE("Enabling or Disabling Components\n");
2456 for (i = 0; i < package->loaded_components; i++)
2458 if (package->components[i].Condition[0])
2460 if (MSI_EvaluateConditionW(package,
2461 package->components[i].Condition) == MSICONDITION_FALSE)
2463 TRACE("Disabling component %s\n",
2464 debugstr_w(package->components[i].Component));
2465 package->components[i].Enabled = FALSE;
2470 MSI_SetPropertyW(package,szCosting,szOne);
2471 /* set default run level if not set */
2472 level = load_dynamic_property(package,szlevel,NULL);
2474 MSI_SetPropertyW(package,szlevel, szOne);
2476 HeapFree(GetProcessHeap(),0,level);
2478 return SetFeatureStates(package);
2483 * This is a helper function for handling embedded cabinet media
2485 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2493 WCHAR tmp[MAX_PATH];
2495 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2496 if (rc != ERROR_SUCCESS)
2500 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2501 GetTempPathW(MAX_PATH,tmp);
2503 GetTempFileNameW(tmp,stream_name,0,source);
2505 track_tempfile(package,strrchrW(source,'\\'), source);
2506 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2507 FILE_ATTRIBUTE_NORMAL, NULL);
2509 if (the_file == INVALID_HANDLE_VALUE)
2511 rc = ERROR_FUNCTION_FAILED;
2515 WriteFile(the_file,data,size,&write,NULL);
2516 CloseHandle(the_file);
2517 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2519 HeapFree(GetProcessHeap(),0,data);
2524 /* Support functions for FDI functions */
2527 MSIPACKAGE* package;
2532 static void * cabinet_alloc(ULONG cb)
2534 return HeapAlloc(GetProcessHeap(), 0, cb);
2537 static void cabinet_free(void *pv)
2539 HeapFree(GetProcessHeap(), 0, pv);
2542 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2545 DWORD dwShareMode = 0;
2546 DWORD dwCreateDisposition = OPEN_EXISTING;
2547 switch (oflag & _O_ACCMODE)
2550 dwAccess = GENERIC_READ;
2551 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2554 dwAccess = GENERIC_WRITE;
2555 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2558 dwAccess = GENERIC_READ | GENERIC_WRITE;
2559 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2562 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2563 dwCreateDisposition = CREATE_NEW;
2564 else if (oflag & _O_CREAT)
2565 dwCreateDisposition = CREATE_ALWAYS;
2566 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2569 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2572 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2577 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2580 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2585 static int cabinet_close(INT_PTR hf)
2587 return CloseHandle((HANDLE)hf) ? 0 : -1;
2590 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2592 /* flags are compatible and so are passed straight through */
2593 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2596 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2598 /* FIXME: try to do more processing in this function */
2601 case fdintCOPY_FILE:
2603 CabData *data = (CabData*) pfdin->pv;
2604 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2609 LPWSTR tracknametmp;
2610 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2612 if (data->file_name && strcmp(data->file_name,pfdin->psz1))
2615 file = cabinet_alloc((len+1)*sizeof(char));
2616 strcpy(file, data->cab_path);
2617 strcat(file, pfdin->psz1);
2619 TRACE("file: %s\n", debugstr_a(file));
2621 /* track this file so it can be deleted if not installed */
2622 trackpath=strdupAtoW(file);
2623 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2624 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2625 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2627 strcpyW(trackname,tmpprefix);
2628 strcatW(trackname,tracknametmp);
2630 track_tempfile(data->package, trackname, trackpath);
2632 HeapFree(GetProcessHeap(),0,trackpath);
2633 HeapFree(GetProcessHeap(),0,trackname);
2634 HeapFree(GetProcessHeap(),0,tracknametmp);
2636 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2638 case fdintCLOSE_FILE_INFO:
2642 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2644 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2646 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2649 cabinet_close(pfdin->hf);
2657 /***********************************************************************
2658 * extract_cabinet_file
2660 * Extract files from a cab file.
2662 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2663 const WCHAR* path, const WCHAR* file)
2673 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2674 debugstr_w(file), debugstr_w(path));
2676 hfdi = FDICreate(cabinet_alloc,
2687 ERR("FDICreate failed\n");
2691 if (!(cabinet = strdupWtoA( source )))
2696 if (!(cab_path = strdupWtoA( path )))
2699 HeapFree(GetProcessHeap(), 0, cabinet);
2703 data.package = package;
2704 data.cab_path = cab_path;
2706 file_name = strdupWtoA(file);
2709 data.file_name = file_name;
2711 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
2714 ERR("FDICopy failed\n");
2718 HeapFree(GetProcessHeap(), 0, cabinet);
2719 HeapFree(GetProcessHeap(), 0, cab_path);
2720 HeapFree(GetProcessHeap(), 0, file_name);
2725 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2726 WCHAR* path, WCHAR* file)
2730 MSIRECORD * row = 0;
2731 static WCHAR source[MAX_PATH];
2732 static const WCHAR ExecSeqQuery[] = {
2733 's','e','l','e','c','t',' ','*',' ',
2734 'f','r','o','m',' ','M','e','d','i','a',' ',
2735 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2736 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2741 static UINT last_sequence = 0;
2743 if (sequence <= last_sequence)
2745 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2746 /*extract_a_cabinet_file(package, source,path,file); */
2747 return ERROR_SUCCESS;
2750 sprintfW(Query,ExecSeqQuery,sequence);
2752 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2753 if (rc != ERROR_SUCCESS)
2756 rc = MSI_ViewExecute(view, 0);
2757 if (rc != ERROR_SUCCESS)
2759 MSI_ViewClose(view);
2760 msiobj_release(&view->hdr);
2764 rc = MSI_ViewFetch(view,&row);
2765 if (rc != ERROR_SUCCESS)
2767 MSI_ViewClose(view);
2768 msiobj_release(&view->hdr);
2771 seq = MSI_RecordGetInteger(row,2);
2772 last_sequence = seq;
2774 if (!MSI_RecordIsNull(row,4))
2777 MSI_RecordGetStringW(row,4,cab,&sz);
2778 TRACE("Source is CAB %s\n",debugstr_w(cab));
2779 /* the stream does not contain the # character */
2782 writeout_cabinet_stream(package,&cab[1],source);
2783 strcpyW(path,source);
2784 *(strrchrW(path,'\\')+1)=0;
2789 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2791 ERR("No Source dir defined \n");
2792 rc = ERROR_FUNCTION_FAILED;
2796 strcpyW(path,source);
2797 strcatW(source,cab);
2798 /* extract the cab file into a folder in the temp folder */
2800 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2802 GetTempPathW(MAX_PATH,path);
2805 rc = !extract_a_cabinet_file(package, source,path,NULL);
2810 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
2811 strcpyW(path,source);
2813 msiobj_release(&row->hdr);
2814 MSI_ViewClose(view);
2815 msiobj_release(&view->hdr);
2819 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2821 UINT rc = ERROR_SUCCESS;
2823 LPWSTR install_path;
2825 install_path = resolve_folder(package, package->components[component].Directory,
2826 FALSE, FALSE, &folder);
2828 return ERROR_FUNCTION_FAILED;
2830 /* create the path */
2831 if (folder->State == 0)
2833 create_full_pathW(install_path);
2836 HeapFree(GetProcessHeap(), 0, install_path);
2841 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
2843 UINT rc = ERROR_SUCCESS;
2846 WCHAR uipath[MAX_PATH];
2849 return ERROR_INVALID_HANDLE;
2851 /* increment progress bar each time action data is sent */
2852 ui_progress(package,1,1,0,0);
2854 for (index = 0; index < package->loaded_files; index++)
2856 WCHAR path_to_source[MAX_PATH];
2859 file = &package->files[index];
2861 if (file->Temporary)
2864 if (package->components[file->ComponentIndex].ActionRequest !=
2867 ui_progress(package,2,file->FileSize,0,0);
2868 TRACE("File %s is not scheduled for install\n",
2869 debugstr_w(file->File));
2874 if ((file->State == 1) || (file->State == 2))
2878 MSICOMPONENT* comp = NULL;
2880 TRACE("Installing %s\n",debugstr_w(file->File));
2881 rc = ready_media_for_file(package,file->Sequence,path_to_source,
2885 * our file table could change here because a new temp file
2886 * may have been created
2888 file = &package->files[index];
2889 if (rc != ERROR_SUCCESS)
2891 ERR("Unable to ready media\n");
2892 rc = ERROR_FUNCTION_FAILED;
2896 create_component_directory( package, file->ComponentIndex);
2898 /* recalculate file paths because things may have changed */
2900 if (file->ComponentIndex >= 0)
2901 comp = &package->components[file->ComponentIndex];
2903 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2904 HeapFree(GetProcessHeap(),0,file->TargetPath);
2906 file->TargetPath = build_directory_name(2, p, file->FileName);
2908 len = strlenW(path_to_source) + strlenW(file->File) + 2;
2909 file->SourcePath = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
2910 strcpyW(file->SourcePath, path_to_source);
2911 strcatW(file->SourcePath, file->File);
2913 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
2914 debugstr_w(file->TargetPath));
2917 uirow=MSI_CreateRecord(9);
2918 MSI_RecordSetStringW(uirow,1,file->File);
2919 strcpyW(uipath,file->TargetPath);
2920 *(strrchrW(uipath,'\\')+1)=0;
2921 MSI_RecordSetStringW(uirow,9,uipath);
2922 MSI_RecordSetInteger(uirow,6,file->FileSize);
2923 ui_actiondata(package,szInstallFiles,uirow);
2924 msiobj_release( &uirow->hdr );
2925 ui_progress(package,2,file->FileSize,0,0);
2927 if (!MoveFileW(file->SourcePath,file->TargetPath))
2929 rc = GetLastError();
2930 ERR("Unable to move file (%s -> %s) (error %d)\n",
2931 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
2933 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
2935 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
2936 DeleteFileW(file->SourcePath);
2939 else if (rc == ERROR_FILE_NOT_FOUND)
2941 ERR("Source File Not Found! Continueing\n");
2946 ERR("Ignoring Error and continuing...\n");
2958 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
2959 LPWSTR* file_source)
2964 return ERROR_INVALID_HANDLE;
2966 for (index = 0; index < package->loaded_files; index ++)
2968 if (strcmpW(file_key,package->files[index].File)==0)
2970 if (package->files[index].State >= 2)
2972 *file_source = dupstrW(package->files[index].TargetPath);
2973 return ERROR_SUCCESS;
2976 return ERROR_FILE_NOT_FOUND;
2980 return ERROR_FUNCTION_FAILED;
2983 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
2987 MSIRECORD * row = 0;
2988 static const WCHAR ExecSeqQuery[] = {
2989 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2990 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2993 return ERROR_INVALID_HANDLE;
2995 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2996 if (rc != ERROR_SUCCESS)
2997 return ERROR_SUCCESS;
2999 rc = MSI_ViewExecute(view, 0);
3000 if (rc != ERROR_SUCCESS)
3002 MSI_ViewClose(view);
3003 msiobj_release(&view->hdr);
3009 WCHAR file_key[0x100];
3010 WCHAR *file_source = NULL;
3011 WCHAR dest_name[0x100];
3012 LPWSTR dest_path, dest;
3013 WCHAR component[0x100];
3014 INT component_index;
3018 rc = MSI_ViewFetch(view,&row);
3019 if (rc != ERROR_SUCCESS)
3026 rc = MSI_RecordGetStringW(row,2,component,&sz);
3027 if (rc != ERROR_SUCCESS)
3029 ERR("Unable to get component\n");
3030 msiobj_release(&row->hdr);
3034 component_index = get_loaded_component(package,component);
3035 if (package->components[component_index].ActionRequest !=
3038 TRACE("Skipping copy due to disabled component\n");
3040 /* the action taken was the same as the current install state */
3041 package->components[component_index].Action =
3042 package->components[component_index].Installed;
3044 msiobj_release(&row->hdr);
3048 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3049 package->components[component_index].Installed = INSTALLSTATE_LOCAL;
3052 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3053 if (rc != ERROR_SUCCESS)
3055 ERR("Unable to get file key\n");
3056 msiobj_release(&row->hdr);
3060 rc = get_file_target(package,file_key,&file_source);
3062 if (rc != ERROR_SUCCESS)
3064 ERR("Original file unknown %s\n",debugstr_w(file_key));
3065 msiobj_release(&row->hdr);
3066 HeapFree(GetProcessHeap(),0,file_source);
3070 if (MSI_RecordIsNull(row,4))
3072 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3077 MSI_RecordGetStringW(row,4,dest_name,&sz);
3078 reduce_to_longfilename(dest_name);
3081 if (MSI_RecordIsNull(row,5))
3084 dest_path = dupstrW(file_source);
3085 p = strrchrW(dest_path,'\\');
3091 WCHAR destkey[0x100];
3093 MSI_RecordGetStringW(row,5,destkey,&sz);
3095 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3098 ERR("Unable to get destination folder\n");
3099 msiobj_release(&row->hdr);
3100 HeapFree(GetProcessHeap(),0,file_source);
3105 dest = build_directory_name(2, dest_path, dest_name);
3106 HeapFree(GetProcessHeap(), 0, dest_path);
3108 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3111 if (strcmpW(file_source,dest))
3112 rc = !CopyFileW(file_source,dest,TRUE);
3116 if (rc != ERROR_SUCCESS)
3117 ERR("Failed to copy file\n");
3119 FIXME("We should track these duplicate files as well\n");
3121 msiobj_release(&row->hdr);
3122 HeapFree(GetProcessHeap(),0,dest);
3123 HeapFree(GetProcessHeap(),0,file_source);
3125 MSI_ViewClose(view);
3126 msiobj_release(&view->hdr);
3131 /* OK this value is "interpreted" and then formatted based on the
3132 first few characters */
3133 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3137 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3146 deformat_string(package, &value[2], &deformated);
3148 /* binary value type */
3151 *size = strlenW(ptr)/2;
3152 data = HeapAlloc(GetProcessHeap(),0,*size);
3164 data[count] = (BYTE)strtol(byte,NULL,0);
3167 HeapFree(GetProcessHeap(),0,deformated);
3169 TRACE("Data %li bytes(%i)\n",*size,count);
3174 deformat_string(package, &value[1], &deformated);
3177 *size = sizeof(DWORD);
3178 data = HeapAlloc(GetProcessHeap(),0,*size);
3179 *(LPDWORD)data = atoiW(deformated);
3180 TRACE("DWORD %i\n",*data);
3182 HeapFree(GetProcessHeap(),0,deformated);
3187 static const WCHAR szMulti[] = {'[','~',']',0};
3196 *type=REG_EXPAND_SZ;
3204 if (strstrW(value,szMulti))
3205 *type = REG_MULTI_SZ;
3207 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3212 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3216 MSIRECORD * row = 0;
3217 static const WCHAR ExecSeqQuery[] = {
3218 's','e','l','e','c','t',' ','*',' ',
3219 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
3222 return ERROR_INVALID_HANDLE;
3224 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3225 if (rc != ERROR_SUCCESS)
3226 return ERROR_SUCCESS;
3228 rc = MSI_ViewExecute(view, 0);
3229 if (rc != ERROR_SUCCESS)
3231 MSI_ViewClose(view);
3232 msiobj_release(&view->hdr);
3236 /* increment progress bar each time action data is sent */
3237 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3241 static const WCHAR szHCR[] =
3242 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
3243 static const WCHAR szHCU[] =
3244 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
3245 static const WCHAR szHLM[] =
3246 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
3248 static const WCHAR szHU[] =
3249 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3251 LPSTR value_data = NULL;
3252 HKEY root_key, hkey;
3254 LPWSTR value, key, name, component, deformated;
3256 INT component_index;
3261 rc = MSI_ViewFetch(view,&row);
3262 if (rc != ERROR_SUCCESS)
3267 ui_progress(package,2,0,0,0);
3274 component = load_dynamic_stringW(row, 6);
3275 component_index = get_loaded_component(package,component);
3277 if (package->components[component_index].ActionRequest !=
3280 TRACE("Skipping write due to disabled component\n");
3281 msiobj_release(&row->hdr);
3283 package->components[component_index].Action =
3284 package->components[component_index].Installed;
3289 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3290 package->components[component_index].Installed = INSTALLSTATE_LOCAL;
3292 /* null values have special meanings during uninstalls and such */
3294 if(MSI_RecordIsNull(row,5))
3296 msiobj_release(&row->hdr);
3300 root = MSI_RecordGetInteger(row,2);
3301 key = load_dynamic_stringW(row, 3);
3303 name = load_dynamic_stringW(row, 4);
3305 /* get the root key */
3308 case 0: root_key = HKEY_CLASSES_ROOT;
3311 case 1: root_key = HKEY_CURRENT_USER;
3314 case 2: root_key = HKEY_LOCAL_MACHINE;
3317 case 3: root_key = HKEY_USERS;
3321 ERR("Unknown root %i\n",root);
3328 msiobj_release(&row->hdr);
3332 deformat_string(package, key , &deformated);
3333 size = strlenW(deformated) + strlenW(szRoot) + 1;
3334 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3335 strcpyW(uikey,szRoot);
3336 strcatW(uikey,deformated);
3338 if (RegCreateKeyW( root_key, deformated, &hkey))
3340 ERR("Could not create key %s\n",debugstr_w(deformated));
3341 msiobj_release(&row->hdr);
3342 HeapFree(GetProcessHeap(),0,deformated);
3345 HeapFree(GetProcessHeap(),0,deformated);
3347 value = load_dynamic_stringW(row,5);
3348 value_data = parse_value(package, value, &type, &size);
3350 deformat_string(package, name, &deformated);
3354 TRACE("Setting value %s\n",debugstr_w(deformated));
3355 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3357 uirow = MSI_CreateRecord(3);
3358 MSI_RecordSetStringW(uirow,2,deformated);
3359 MSI_RecordSetStringW(uirow,1,uikey);
3362 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3364 MSI_RecordSetStringW(uirow,3,value);
3366 ui_actiondata(package,szWriteRegistryValues,uirow);
3367 msiobj_release( &uirow->hdr );
3369 HeapFree(GetProcessHeap(),0,value_data);
3371 HeapFree(GetProcessHeap(),0,value);
3372 HeapFree(GetProcessHeap(),0,deformated);
3374 msiobj_release(&row->hdr);
3377 HeapFree(GetProcessHeap(),0,uikey);
3378 HeapFree(GetProcessHeap(),0,key);
3379 HeapFree(GetProcessHeap(),0,name);
3380 HeapFree(GetProcessHeap(),0,component);
3382 MSI_ViewClose(view);
3383 msiobj_release(&view->hdr);
3387 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3389 return ERROR_SUCCESS;
3393 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3397 static const WCHAR q1[]={
3398 'S','E','L','E','C','T',' ','*',' ',
3399 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3402 MSIRECORD * row = 0;
3405 TRACE(" InstallValidate \n");
3407 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3408 if (rc != ERROR_SUCCESS)
3409 return ERROR_SUCCESS;
3411 rc = MSI_ViewExecute(view, 0);
3412 if (rc != ERROR_SUCCESS)
3414 MSI_ViewClose(view);
3415 msiobj_release(&view->hdr);
3420 rc = MSI_ViewFetch(view,&row);
3421 if (rc != ERROR_SUCCESS)
3428 msiobj_release(&row->hdr);
3430 MSI_ViewClose(view);
3431 msiobj_release(&view->hdr);
3433 total = total + progress * REG_PROGRESS_VALUE;
3434 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3435 for (i=0; i < package->loaded_files; i++)
3436 total += package->files[i].FileSize;
3437 ui_progress(package,0,total,0,0);
3439 return ERROR_SUCCESS;
3442 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3445 MSIQUERY * view = NULL;
3446 MSIRECORD * row = 0;
3447 static const WCHAR ExecSeqQuery[] = {
3448 'S','E','L','E','C','T',' ','*',' ',
3449 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3450 static const WCHAR title[]=
3451 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3453 TRACE("Checking launch conditions\n");
3455 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3456 if (rc != ERROR_SUCCESS)
3457 return ERROR_SUCCESS;
3459 rc = MSI_ViewExecute(view, 0);
3460 if (rc != ERROR_SUCCESS)
3462 MSI_ViewClose(view);
3463 msiobj_release(&view->hdr);
3468 while (rc == ERROR_SUCCESS)
3471 LPWSTR message = NULL;
3473 rc = MSI_ViewFetch(view,&row);
3474 if (rc != ERROR_SUCCESS)
3480 cond = load_dynamic_stringW(row,1);
3482 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3485 message = load_dynamic_stringW(row,2);
3486 deformat_string(package,message,&deformated);
3487 MessageBoxW(NULL,deformated,title,MB_OK);
3488 HeapFree(GetProcessHeap(),0,message);
3489 HeapFree(GetProcessHeap(),0,deformated);
3490 rc = ERROR_FUNCTION_FAILED;
3492 HeapFree(GetProcessHeap(),0,cond);
3493 msiobj_release(&row->hdr);
3495 MSI_ViewClose(view);
3496 msiobj_release(&view->hdr);
3500 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3503 MSICOMPONENT* cmp = &package->components[component_index];
3505 if (cmp->KeyPath[0]==0)
3507 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3510 if (cmp->Attributes & 0x4)
3513 MSIRECORD * row = 0;
3515 LPWSTR key,deformated,buffer,name,deformated_name;
3516 static const WCHAR ExecSeqQuery[] = {
3517 's','e','l','e','c','t',' ','*',' ',
3518 'f','r','o','m',' ','R','e','g','i','s','t','r','y',' ',
3519 'w','h','e','r','e',' ','R','e','g','i','s','t','r','y',' ','=',' '
3520 ,'`','%','s','`',0 };
3521 static const WCHAR fmt[]={'%','0','2','i',':','%','s',0};
3522 static const WCHAR fmt2[]={'%','0','2','i',':','%','s','\\','%','s',0};
3524 rc = MSI_OpenQuery(package->db,&view,ExecSeqQuery,cmp->KeyPath);
3526 if (rc!=ERROR_SUCCESS)
3529 rc = MSI_ViewExecute(view, 0);
3530 if (rc != ERROR_SUCCESS)
3532 MSI_ViewClose(view);
3533 msiobj_release(&view->hdr);
3537 rc = MSI_ViewFetch(view,&row);
3538 if (rc != ERROR_SUCCESS)
3540 MSI_ViewClose(view);
3541 msiobj_release(&view->hdr);
3545 root = MSI_RecordGetInteger(row,2);
3546 key = load_dynamic_stringW(row, 3);
3547 name = load_dynamic_stringW(row, 4);
3548 deformat_string(package, key , &deformated);
3549 deformat_string(package, name, &deformated_name);
3551 len = strlenW(deformated) + 5;
3552 if (deformated_name)
3553 len+=strlenW(deformated_name);
3555 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3557 if (deformated_name)
3558 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3560 sprintfW(buffer,fmt,root,deformated);
3562 HeapFree(GetProcessHeap(),0,key);
3563 HeapFree(GetProcessHeap(),0,deformated);
3564 HeapFree(GetProcessHeap(),0,name);
3565 HeapFree(GetProcessHeap(),0,deformated_name);
3566 msiobj_release(&row->hdr);
3567 MSI_ViewClose(view);
3568 msiobj_release(&view->hdr);
3572 else if (cmp->Attributes & 0x20)
3574 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3580 j = get_loaded_file(package,cmp->KeyPath);
3584 LPWSTR p = dupstrW(package->files[j].TargetPath);
3592 * Ok further analysis makes me think that this work is
3593 * actually done in the PublishComponents and PublishFeatures
3594 * step, and not here. It appears like the keypath and all that is
3595 * resolved in this step, however actually written in the Publish steps.
3596 * But we will leave it here for now because it is unclear
3598 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3601 WCHAR squished_pc[GUID_SIZE];
3602 WCHAR squished_cc[GUID_SIZE];
3605 HKEY hkey=0,hkey2=0;
3606 static const WCHAR szProductCode[]=
3607 {'P','r','o','d','u','c','t','C','o','d','e',0};
3610 return ERROR_INVALID_HANDLE;
3612 /* writes the Component and Features values to the registry */
3613 productcode = load_dynamic_property(package,szProductCode,&rc);
3617 rc = MSIREG_OpenComponents(&hkey);
3618 if (rc != ERROR_SUCCESS)
3621 squash_guid(productcode,squished_pc);
3622 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
3623 for (i = 0; i < package->loaded_components; i++)
3625 ui_progress(package,2,0,0,0);
3626 if (package->components[i].ComponentId[0]!=0)
3628 WCHAR *keypath = NULL;
3631 squash_guid(package->components[i].ComponentId,squished_cc);
3632 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
3633 if (rc != ERROR_SUCCESS)
3636 keypath = resolve_keypath(package,i);
3639 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
3640 (strlenW(keypath)+1)*sizeof(WCHAR));
3644 uirow = MSI_CreateRecord(3);
3645 MSI_RecordSetStringW(uirow,1,productcode);
3646 MSI_RecordSetStringW(uirow,2,package->components[i].
3648 MSI_RecordSetStringW(uirow,3,keypath);
3649 ui_actiondata(package,szProcessComponents,uirow);
3650 msiobj_release( &uirow->hdr );
3651 HeapFree(GetProcessHeap(),0,keypath);
3656 HeapFree(GetProcessHeap(), 0, productcode);
3661 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
3664 * OK this is a bit confusing.. I am given a _Component key and I believe
3665 * that the file that is being registered as a type library is the "key file
3666 * of that component" which I interpret to mean "The file in the KeyPath of
3671 MSIRECORD * row = 0;
3672 static const WCHAR Query[] = {
3673 'S','E','L','E','C','T',' ','*',' ',
3674 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3679 return ERROR_INVALID_HANDLE;
3681 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3682 if (rc != ERROR_SUCCESS)
3683 return ERROR_SUCCESS;
3685 rc = MSI_ViewExecute(view, 0);
3686 if (rc != ERROR_SUCCESS)
3688 MSI_ViewClose(view);
3689 msiobj_release(&view->hdr);
3695 WCHAR component[0x100];
3699 rc = MSI_ViewFetch(view,&row);
3700 if (rc != ERROR_SUCCESS)
3707 MSI_RecordGetStringW(row,3,component,&sz);
3709 index = get_loaded_component(package,component);
3712 msiobj_release(&row->hdr);
3716 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
3718 TRACE("Skipping typelib reg due to disabled component\n");
3719 msiobj_release(&row->hdr);
3721 package->components[index].Action =
3722 package->components[index].Installed;
3727 package->components[index].Action = INSTALLSTATE_LOCAL;
3728 package->components[index].Installed = INSTALLSTATE_LOCAL;
3730 index = get_loaded_file(package,package->components[index].KeyPath);
3734 msiobj_release(&row->hdr);
3738 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
3742 WCHAR helpid[0x100];
3745 MSI_RecordGetStringW(row,6,helpid,&sz);
3747 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
3748 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
3749 HeapFree(GetProcessHeap(),0,help);
3751 if (!SUCCEEDED(res))
3752 ERR("Failed to register type library %s\n",
3753 debugstr_w(package->files[index].TargetPath));
3756 /* Yes the row has more fields than I need, but #1 is
3757 correct and the only one I need. Why make a new row? */
3759 ui_actiondata(package,szRegisterTypeLibraries,row);
3761 TRACE("Registered %s\n",
3762 debugstr_w(package->files[index].TargetPath));
3766 ITypeLib_Release(ptLib);
3769 ERR("Failed to load type library %s\n",
3770 debugstr_w(package->files[index].TargetPath));
3772 msiobj_release(&row->hdr);
3774 MSI_ViewClose(view);
3775 msiobj_release(&view->hdr);
3780 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
3782 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3785 MSIRECORD * row = 0;
3786 static const WCHAR ExecSeqQuery[] =
3787 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3788 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3793 return ERROR_INVALID_HANDLE;
3795 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
3796 if (rc != ERROR_SUCCESS)
3799 rc = MSI_ViewExecute(view, 0);
3800 if (rc != ERROR_SUCCESS)
3802 MSI_ViewClose(view);
3803 msiobj_release(&view->hdr);
3807 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
3808 RegCreateKeyW(hkey2,clsid,&hkey3);
3809 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
3810 (strlenW(app)+1)*sizeof(WCHAR));
3812 rc = MSI_ViewFetch(view,&row);
3813 if (rc != ERROR_SUCCESS)
3815 MSI_ViewClose(view);
3816 msiobj_release(&view->hdr);
3820 if (!MSI_RecordIsNull(row,2))
3822 LPWSTR deformated=0;
3824 static const WCHAR szRemoteServerName[] =
3825 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3826 buffer = load_dynamic_stringW(row,2);
3827 size = deformat_string(package,buffer,&deformated);
3828 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
3830 HeapFree(GetProcessHeap(),0,deformated);
3831 HeapFree(GetProcessHeap(),0,buffer);
3834 if (!MSI_RecordIsNull(row,3))
3836 static const WCHAR szLocalService[] =
3837 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3839 buffer = load_dynamic_stringW(row,3);
3840 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3841 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
3842 HeapFree(GetProcessHeap(),0,buffer);
3845 if (!MSI_RecordIsNull(row,4))
3847 static const WCHAR szService[] =
3848 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3850 buffer = load_dynamic_stringW(row,4);
3851 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3852 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
3853 HeapFree(GetProcessHeap(),0,buffer);
3856 if (!MSI_RecordIsNull(row,5))
3858 static const WCHAR szDLL[] =
3859 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3861 buffer = load_dynamic_stringW(row,5);
3862 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3863 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
3864 HeapFree(GetProcessHeap(),0,buffer);
3867 if (!MSI_RecordIsNull(row,6))
3869 static const WCHAR szActivate[] =
3870 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3871 static const WCHAR szY[] = {'Y',0};
3873 if (MSI_RecordGetInteger(row,6))
3874 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
3877 if (!MSI_RecordIsNull(row,7))
3879 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
3880 static const WCHAR szUser[] =
3881 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3883 if (MSI_RecordGetInteger(row,7))
3884 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
3887 msiobj_release(&row->hdr);
3888 MSI_ViewClose(view);
3889 msiobj_release(&view->hdr);
3895 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
3898 * Again I am assuming the words, "Whose key file represents" when referring
3899 * to a Component as to meaning that Components KeyPath file
3901 * Also there is a very strong connection between ClassInfo and ProgID
3902 * that I am mostly glossing over.
3903 * What would be more propper is to load the ClassInfo and the ProgID info
3904 * into memory data structures and then be able to enable and disable them
3905 * based on component.
3910 MSIRECORD * row = 0;
3911 static const WCHAR ExecSeqQuery[] = {
3912 'S','E','L','E','C','T',' ','*',' ',
3913 'f','r','o','m',' ','C','l','a','s','s',0};
3914 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3915 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
3916 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3917 static const WCHAR szSpace[] = {' ',0};
3918 HKEY hkey,hkey2,hkey3;
3919 LPWSTR argument,deformated;
3922 return ERROR_INVALID_HANDLE;
3924 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
3925 if (rc != ERROR_SUCCESS)
3926 return ERROR_FUNCTION_FAILED;
3928 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3929 if (rc != ERROR_SUCCESS)
3935 rc = MSI_ViewExecute(view, 0);
3936 if (rc != ERROR_SUCCESS)
3938 MSI_ViewClose(view);
3939 msiobj_release(&view->hdr);
3946 WCHAR buffer[0x100];
3952 rc = MSI_ViewFetch(view,&row);
3953 if (rc != ERROR_SUCCESS)
3960 MSI_RecordGetStringW(row,3,buffer,&sz);
3962 index = get_loaded_component(package,buffer);
3966 msiobj_release(&row->hdr);
3970 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
3972 TRACE("Skipping class reg due to disabled component\n");
3973 msiobj_release(&row->hdr);
3975 package->components[index].Action =
3976 package->components[index].Installed;
3981 package->components[index].Action = INSTALLSTATE_LOCAL;
3982 package->components[index].Installed = INSTALLSTATE_LOCAL;
3985 MSI_RecordGetStringW(row,1,clsid,&sz);
3986 RegCreateKeyW(hkey,clsid,&hkey2);
3988 if (!MSI_RecordIsNull(row,5))
3991 MSI_RecordGetStringW(row,5,desc,&sz);
3993 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
3994 (strlenW(desc)+1)*sizeof(WCHAR));
4000 MSI_RecordGetStringW(row,2,buffer,&sz);
4002 RegCreateKeyW(hkey2,buffer,&hkey3);
4004 index = get_loaded_file(package,package->components[index].KeyPath);
4006 argument = load_dynamic_stringW(row,11);
4007 size = deformat_string(package,argument,&deformated);
4009 size+=sizeof(WCHAR);
4010 HeapFree(GetProcessHeap(),0,argument);
4011 size += (strlenW(package->files[index].TargetPath))*sizeof(WCHAR);
4013 argument = (LPWSTR)HeapAlloc(GetProcessHeap(),0,size+sizeof(WCHAR));
4014 strcpyW(argument,package->files[index].TargetPath);
4017 strcatW(argument,szSpace);
4018 strcatW(argument,deformated);
4021 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4022 HeapFree(GetProcessHeap(),0,deformated);
4023 HeapFree(GetProcessHeap(),0,argument);
4027 if (!MSI_RecordIsNull(row,4))
4030 MSI_RecordGetStringW(row,4,buffer,&sz);
4032 RegCreateKeyW(hkey2,szProgID,&hkey3);
4034 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4035 (strlenW(buffer)+1)*sizeof(WCHAR));
4040 if (!MSI_RecordIsNull(row,6))
4043 MSI_RecordGetStringW(row,6,buffer,&sz);
4045 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4046 (strlenW(buffer)+1)*sizeof(WCHAR));
4048 register_appid(package,buffer,desc);
4052 if (!MSI_RecordIsNull(row,7))
4054 FIXME("Process field 7\n");
4057 if (!MSI_RecordIsNull(row,8))
4059 static const WCHAR szDefaultIcon[] =
4060 {'D','e','f','a','u','l','t','I','c','o','n',0};
4062 LPWSTR FileName = load_dynamic_stringW(row,8);
4066 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
4067 build_icon_path(package,FileName,&FilePath);
4068 if (!MSI_RecordIsNull(row,9))
4070 static const WCHAR index_fmt[] = {',','%','i',0};
4071 WCHAR index_buf[20];
4072 index = MSI_RecordGetInteger(row,9);
4073 sprintfW(index_buf,index_fmt,index);
4074 size = strlenW(FilePath)+strlenW(index_buf)+1;
4075 size *= sizeof(WCHAR);
4076 HeapReAlloc(GetProcessHeap(),0,FilePath,size);
4078 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)FilePath,
4079 (strlenW(FilePath)+1) * sizeof(WCHAR));
4080 HeapFree(GetProcessHeap(),0,FilePath);
4081 HeapFree(GetProcessHeap(),0,FileName);
4085 if (!MSI_RecordIsNull(row,10))
4087 static const WCHAR szInproc32[] = {
4088 'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',0};
4089 static const WCHAR szInproc[] = {
4090 'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
4091 INT i = MSI_RecordGetInteger(row,10);
4092 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4094 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4095 static const WCHAR ole32[] = {
4096 'o','l','e','3','2','.','d','l','l',0};
4100 size = strlenW(ole2) * sizeof(WCHAR);
4101 RegCreateKeyW(hkey2,szInproc,&hkey3);
4102 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4106 size = strlenW(ole32) * sizeof(WCHAR);
4107 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4108 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4112 size = strlenW(ole2) * sizeof(WCHAR);
4113 RegCreateKeyW(hkey2,szInproc,&hkey3);
4114 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4116 size = strlenW(ole32) * sizeof(WCHAR);
4117 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4118 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4126 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4127 argument = load_dynamic_stringW(row,10);
4128 reduce_to_longfilename(argument);
4129 size = strlenW(argument)*sizeof(WCHAR);
4131 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4132 HeapFree(GetProcessHeap(),0,argument);
4140 ui_actiondata(package,szRegisterClassInfo,row);
4142 msiobj_release(&row->hdr);
4144 MSI_ViewClose(view);
4145 msiobj_release(&view->hdr);
4152 static UINT register_progid_base(MSIPACKAGE* package, MSIRECORD * row,
4155 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4156 static const WCHAR szDefaultIcon[] = {
4157 'D','e','f','a','u','l','t','I','c','o','n',0};
4159 WCHAR buffer[0x100];
4164 MSI_RecordGetStringW(row,1,buffer,&sz);
4165 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4167 if (!MSI_RecordIsNull(row,4))
4170 MSI_RecordGetStringW(row,4,buffer,&sz);
4171 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4175 if (!MSI_RecordIsNull(row,3))
4179 MSI_RecordGetStringW(row,3,buffer,&sz);
4180 RegCreateKeyW(hkey,szCLSID,&hkey2);
4181 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4185 strcpyW(clsid,buffer);
4191 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4192 return ERROR_FUNCTION_FAILED;
4194 if (!MSI_RecordIsNull(row,5))
4196 INT index = MSI_RecordGetInteger(row,6);
4197 LPWSTR FileName = load_dynamic_stringW(row,5);
4198 LPWSTR FilePath,IconPath;
4199 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4201 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4202 build_icon_path(package,FileName,&FilePath);
4204 IconPath = HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4207 sprintfW(IconPath,fmt,FilePath,index);
4208 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)IconPath,
4209 (strlenW(IconPath)+1) * sizeof(WCHAR));
4210 HeapFree(GetProcessHeap(),0,FilePath);
4211 HeapFree(GetProcessHeap(),0,FileName);
4214 return ERROR_SUCCESS;
4217 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4219 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4224 MSIRECORD * row = 0;
4225 static const WCHAR Query_t[] =
4226 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
4227 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
4231 return ERROR_INVALID_HANDLE;
4233 rc = MSI_OpenQuery(package->db, &view, Query_t, parent);
4234 if (rc != ERROR_SUCCESS)
4237 rc = MSI_ViewExecute(view, 0);
4238 if (rc != ERROR_SUCCESS)
4240 MSI_ViewClose(view);
4241 msiobj_release(&view->hdr);
4245 rc = MSI_ViewFetch(view,&row);
4246 if (rc != ERROR_SUCCESS)
4248 MSI_ViewClose(view);
4249 msiobj_release(&view->hdr);
4253 register_progid(package,row,clsid);
4255 msiobj_release(&row->hdr);
4256 MSI_ViewClose(view);
4257 msiobj_release(&view->hdr);
4261 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4263 UINT rc = ERROR_SUCCESS;
4265 if (MSI_RecordIsNull(row,2))
4266 rc = register_progid_base(package,row,clsid);
4269 WCHAR buffer[0x1000];
4272 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4273 static const WCHAR szDefaultIcon[] = {
4274 'D','e','f','a','u','l','t','I','c','o','n',0};
4276 /* check if already registered */
4278 MSI_RecordGetStringW(row,1,buffer,&sz);
4279 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4280 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4281 if (disp == REG_OPENED_EXISTING_KEY)
4283 TRACE("Key already registered\n");
4289 MSI_RecordGetStringW(row,2,buffer,&sz);
4290 rc = register_parent_progid(package,buffer,clsid);
4292 /* clsid is same as parent */
4293 RegCreateKeyW(hkey,szCLSID,&hkey2);
4294 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4300 if (!MSI_RecordIsNull(row,4))
4303 MSI_RecordGetStringW(row,4,buffer,&sz);
4304 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4305 (strlenW(buffer)+1) * sizeof(WCHAR));
4308 if (!MSI_RecordIsNull(row,5))
4310 LPWSTR FileName = load_dynamic_stringW(row,5);
4312 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4313 build_icon_path(package,FileName,&FilePath);
4314 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)FilePath,
4315 (strlenW(FilePath)+1) * sizeof(WCHAR));
4316 HeapFree(GetProcessHeap(),0,FilePath);
4317 HeapFree(GetProcessHeap(),0,FileName);
4326 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4329 * Sigh, here I am just brute force registering all progids
4330 * this needs to be linked to the Classes that have been registered
4331 * but the easiest way to do that is to load all these stuff into
4332 * memory for easy checking.
4334 * Gives me something to continue to work toward.
4338 MSIRECORD * row = 0;
4339 static const WCHAR Query[] = {
4340 'S','E','L','E','C','T',' ','*',' ',
4341 'F','R','O','M',' ','P','r','o','g','I','d',0};
4344 return ERROR_INVALID_HANDLE;
4346 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4347 if (rc != ERROR_SUCCESS)
4348 return ERROR_SUCCESS;
4350 rc = MSI_ViewExecute(view, 0);
4351 if (rc != ERROR_SUCCESS)
4353 MSI_ViewClose(view);
4354 msiobj_release(&view->hdr);
4360 WCHAR clsid[0x1000];
4362 rc = MSI_ViewFetch(view,&row);
4363 if (rc != ERROR_SUCCESS)
4369 register_progid(package,row,clsid);
4370 ui_actiondata(package,szRegisterProgIdInfo,row);
4372 msiobj_release(&row->hdr);
4374 MSI_ViewClose(view);
4375 msiobj_release(&view->hdr);
4379 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4383 LPWSTR SystemFolder;
4387 static const WCHAR szInstaller[] =
4388 {'I','n','s','t','a','l','l','e','r','\\',0};
4389 static const WCHAR szProductCode[] =
4390 {'P','r','o','d','u','c','t','C','o','d','e',0};
4391 static const WCHAR szFolder[] =
4392 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4394 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4398 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4400 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4402 create_full_pathW(dest);
4404 *FilePath = build_directory_name(2, dest, icon_name);
4406 HeapFree(GetProcessHeap(),0,SystemFolder);
4407 HeapFree(GetProcessHeap(),0,ProductCode);
4408 HeapFree(GetProcessHeap(),0,dest);
4409 return ERROR_SUCCESS;
4412 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4416 MSIRECORD * row = 0;
4417 static const WCHAR Query[] = {
4418 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4419 'S','h','o','r','t','c','u','t',0};
4425 return ERROR_INVALID_HANDLE;
4427 res = CoInitialize( NULL );
4430 ERR("CoInitialize failed\n");
4431 return ERROR_FUNCTION_FAILED;
4434 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4435 if (rc != ERROR_SUCCESS)
4436 return ERROR_SUCCESS;
4438 rc = MSI_ViewExecute(view, 0);
4439 if (rc != ERROR_SUCCESS)
4441 MSI_ViewClose(view);
4442 msiobj_release(&view->hdr);
4448 LPWSTR target_file, target_folder;
4449 WCHAR buffer[0x100];
4452 static const WCHAR szlnk[]={'.','l','n','k',0};
4454 rc = MSI_ViewFetch(view,&row);
4455 if (rc != ERROR_SUCCESS)
4462 MSI_RecordGetStringW(row,4,buffer,&sz);
4464 index = get_loaded_component(package,buffer);
4468 msiobj_release(&row->hdr);
4472 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4474 TRACE("Skipping shortcut creation due to disabled component\n");
4475 msiobj_release(&row->hdr);
4477 package->components[index].Action =
4478 package->components[index].Installed;
4483 package->components[index].Action = INSTALLSTATE_LOCAL;
4484 package->components[index].Installed = INSTALLSTATE_LOCAL;
4486 ui_actiondata(package,szCreateShortcuts,row);
4488 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4489 &IID_IShellLinkW, (LPVOID *) &sl );
4493 ERR("Is IID_IShellLink\n");
4494 msiobj_release(&row->hdr);
4498 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4501 ERR("Is IID_IPersistFile\n");
4502 msiobj_release(&row->hdr);
4507 MSI_RecordGetStringW(row,2,buffer,&sz);
4508 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4510 /* may be needed because of a bug somehwere else */
4511 create_full_pathW(target_folder);
4514 MSI_RecordGetStringW(row,3,buffer,&sz);
4515 reduce_to_longfilename(buffer);
4516 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4517 strcatW(buffer,szlnk);
4518 target_file = build_directory_name(2, target_folder, buffer);
4519 HeapFree(GetProcessHeap(),0,target_folder);
4522 MSI_RecordGetStringW(row,5,buffer,&sz);
4523 if (strchrW(buffer,'['))
4526 deformat_string(package,buffer,&deformated);
4527 IShellLinkW_SetPath(sl,deformated);
4528 HeapFree(GetProcessHeap(),0,deformated);
4532 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4533 IPersistFile_Release( pf );
4534 IShellLinkW_Release( sl );
4535 msiobj_release(&row->hdr);
4539 if (!MSI_RecordIsNull(row,6))
4543 MSI_RecordGetStringW(row,6,buffer,&sz);
4544 deformat_string(package,buffer,&deformated);
4545 IShellLinkW_SetArguments(sl,deformated);
4546 HeapFree(GetProcessHeap(),0,deformated);
4549 if (!MSI_RecordIsNull(row,7))
4552 deformated = load_dynamic_stringW(row,7);
4553 IShellLinkW_SetDescription(sl,deformated);
4554 HeapFree(GetProcessHeap(),0,deformated);
4557 if (!MSI_RecordIsNull(row,8))
4558 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4560 if (!MSI_RecordIsNull(row,9))
4566 MSI_RecordGetStringW(row,9,buffer,&sz);
4568 build_icon_path(package,buffer,&Path);
4569 index = MSI_RecordGetInteger(row,10);
4571 IShellLinkW_SetIconLocation(sl,Path,index);
4572 HeapFree(GetProcessHeap(),0,Path);
4575 if (!MSI_RecordIsNull(row,11))
4576 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4578 if (!MSI_RecordIsNull(row,12))
4582 MSI_RecordGetStringW(row,12,buffer,&sz);
4583 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
4584 IShellLinkW_SetWorkingDirectory(sl,Path);
4585 HeapFree(GetProcessHeap(), 0, Path);
4588 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4589 IPersistFile_Save(pf,target_file,FALSE);
4591 HeapFree(GetProcessHeap(),0,target_file);
4593 IPersistFile_Release( pf );
4594 IShellLinkW_Release( sl );
4596 msiobj_release(&row->hdr);
4598 MSI_ViewClose(view);
4599 msiobj_release(&view->hdr);
4609 * 99% of the work done here is only done for
4610 * advertised installs. However this is where the
4611 * Icon table is processed and written out
4612 * so that is what I am going to do here.
4614 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4618 MSIRECORD * row = 0;
4619 static const WCHAR Query[]={
4620 'S','E','L','E','C','T',' ','*',' ',
4621 'f','r','o','m',' ','I','c','o','n',0};
4623 /* for registry stuff */
4627 static const WCHAR szProductCode[]=
4628 {'P','r','o','d','u','c','t','C','o','d','e',0};
4629 static const WCHAR szProductName[] = {
4630 'P','r','o','d','u','c','t','N','a','m','e',0};
4631 static const WCHAR szPackageCode[] = {
4632 'P','a','c','k','a','g','e','C','o','d','e',0};
4635 MSIHANDLE hDb, hSumInfo;
4638 return ERROR_INVALID_HANDLE;
4640 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4641 if (rc != ERROR_SUCCESS)
4644 rc = MSI_ViewExecute(view, 0);
4645 if (rc != ERROR_SUCCESS)
4647 MSI_ViewClose(view);
4648 msiobj_release(&view->hdr);
4655 WCHAR *FilePath=NULL;
4656 WCHAR *FileName=NULL;
4659 rc = MSI_ViewFetch(view,&row);
4660 if (rc != ERROR_SUCCESS)
4666 FileName = load_dynamic_stringW(row,1);
4669 ERR("Unable to get FileName\n");
4670 msiobj_release(&row->hdr);
4674 build_icon_path(package,FileName,&FilePath);
4676 HeapFree(GetProcessHeap(),0,FileName);
4678 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4680 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4681 FILE_ATTRIBUTE_NORMAL, NULL);
4683 if (the_file == INVALID_HANDLE_VALUE)
4685 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4686 msiobj_release(&row->hdr);
4687 HeapFree(GetProcessHeap(),0,FilePath);
4695 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4696 if (rc != ERROR_SUCCESS)
4698 ERR("Failed to get stream\n");
4699 CloseHandle(the_file);
4700 DeleteFileW(FilePath);
4703 WriteFile(the_file,buffer,sz,&write,NULL);
4704 } while (sz == 1024);
4706 HeapFree(GetProcessHeap(),0,FilePath);
4708 CloseHandle(the_file);
4709 msiobj_release(&row->hdr);
4711 MSI_ViewClose(view);
4712 msiobj_release(&view->hdr);
4715 /* ok there is a lot more done here but i need to figure out what */
4716 productcode = load_dynamic_property(package,szProductCode,&rc);
4720 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
4721 if (rc != ERROR_SUCCESS)
4724 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
4725 if (rc != ERROR_SUCCESS)
4729 buffer = load_dynamic_property(package,szProductName,NULL);
4730 size = strlenW(buffer)*sizeof(WCHAR);
4731 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
4732 HeapFree(GetProcessHeap(),0,buffer);
4733 FIXME("Need to write more keys to the user registry\n");
4735 hDb= msiobj_findhandle( &package->db->hdr );
4736 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
4737 if (rc == ERROR_SUCCESS)
4739 WCHAR guidbuffer[0x200];
4741 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 8, NULL, NULL, NULL,
4743 if (rc == ERROR_SUCCESS)
4745 WCHAR squashed[GUID_SIZE];
4746 /* for now we only care about the first guid */
4747 LPWSTR ptr = strchrW(guidbuffer,';');
4749 squash_guid(guidbuffer,squashed);
4750 size = strlenW(guidbuffer)*sizeof(WCHAR);
4751 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)guidbuffer,
4757 ERR("Unable to query Revision_Number... \n");
4760 MsiCloseHandle(hSumInfo);
4764 ERR("Unable to open Summary Information\n");
4770 HeapFree(GetProcessHeap(),0,productcode);
4777 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
4781 MSIRECORD * row = 0;
4782 static const WCHAR ExecSeqQuery[] = {'S','e','l','e','c','t',' ','*',
4783 ' ','f','r','o','m',' ','I','n','i','F','i','l','e',0};
4784 static const WCHAR szWindowsFolder[] =
4785 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4787 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4788 if (rc != ERROR_SUCCESS)
4790 TRACE("no IniFile table\n");
4791 return ERROR_SUCCESS;
4794 rc = MSI_ViewExecute(view, 0);
4795 if (rc != ERROR_SUCCESS)
4797 MSI_ViewClose(view);
4798 msiobj_release(&view->hdr);
4804 LPWSTR component,filename,dirproperty,section,key,value,identifier;
4805 LPWSTR deformated_section, deformated_key, deformated_value;
4806 LPWSTR folder, fullname = NULL;
4808 INT component_index,action;
4810 rc = MSI_ViewFetch(view,&row);
4811 if (rc != ERROR_SUCCESS)
4817 component = load_dynamic_stringW(row, 8);
4818 component_index = get_loaded_component(package,component);
4819 HeapFree(GetProcessHeap(),0,component);
4821 if (package->components[component_index].ActionRequest !=
4824 TRACE("Skipping ini file due to disabled component\n");
4825 msiobj_release(&row->hdr);
4827 package->components[component_index].Action =
4828 package->components[component_index].Installed;
4833 package->components[component_index].Action = INSTALLSTATE_LOCAL;
4834 package->components[component_index].Installed = INSTALLSTATE_LOCAL;
4836 identifier = load_dynamic_stringW(row,1);
4837 filename = load_dynamic_stringW(row,2);
4838 dirproperty = load_dynamic_stringW(row,3);
4839 section = load_dynamic_stringW(row,4);
4840 key = load_dynamic_stringW(row,5);
4841 value = load_dynamic_stringW(row,6);
4842 action = MSI_RecordGetInteger(row,7);
4844 deformat_string(package,section,&deformated_section);
4845 deformat_string(package,key,&deformated_key);
4846 deformat_string(package,value,&deformated_value);
4850 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
4852 folder = load_dynamic_property(package,dirproperty,NULL);
4855 folder = load_dynamic_property(package, szWindowsFolder, NULL);
4859 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
4863 fullname = build_directory_name(3, folder, filename, NULL);
4867 TRACE("Adding value %s to section %s in %s\n",
4868 debugstr_w(deformated_key), debugstr_w(deformated_section),
4869 debugstr_w(fullname));
4870 WritePrivateProfileStringW(deformated_section, deformated_key,
4871 deformated_value, fullname);
4873 else if (action == 1)
4876 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
4877 returned, 10, fullname);
4878 if (returned[0] == 0)
4880 TRACE("Adding value %s to section %s in %s\n",
4881 debugstr_w(deformated_key), debugstr_w(deformated_section),
4882 debugstr_w(fullname));
4884 WritePrivateProfileStringW(deformated_section, deformated_key,
4885 deformated_value, fullname);
4888 else if (action == 3)
4890 FIXME("Append to existing section not yet implemented\n");
4893 uirow = MSI_CreateRecord(4);
4894 MSI_RecordSetStringW(uirow,1,identifier);
4895 MSI_RecordSetStringW(uirow,2,deformated_section);
4896 MSI_RecordSetStringW(uirow,3,deformated_key);
4897 MSI_RecordSetStringW(uirow,4,deformated_value);
4898 ui_actiondata(package,szWriteIniValues,uirow);
4899 msiobj_release( &uirow->hdr );
4901 HeapFree(GetProcessHeap(),0,identifier);
4902 HeapFree(GetProcessHeap(),0,fullname);
4903 HeapFree(GetProcessHeap(),0,filename);
4904 HeapFree(GetProcessHeap(),0,key);
4905 HeapFree(GetProcessHeap(),0,value);
4906 HeapFree(GetProcessHeap(),0,section);
4907 HeapFree(GetProcessHeap(),0,dirproperty);
4908 HeapFree(GetProcessHeap(),0,folder);
4909 HeapFree(GetProcessHeap(),0,deformated_key);
4910 HeapFree(GetProcessHeap(),0,deformated_value);
4911 HeapFree(GetProcessHeap(),0,deformated_section);
4912 msiobj_release(&row->hdr);
4914 MSI_ViewClose(view);
4915 msiobj_release(&view->hdr);
4919 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
4923 MSIRECORD * row = 0;
4924 static const WCHAR ExecSeqQuery[] = {'S','e','l','e','c','t',' ','*',' ',
4925 'f','r','o','m',' ','S','e','l','f','R','e','g',0};
4927 static const WCHAR ExeStr[] = {
4928 'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ',0};
4930 PROCESS_INFORMATION info;
4933 memset(&si,0,sizeof(STARTUPINFOW));
4935 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4936 if (rc != ERROR_SUCCESS)
4938 TRACE("no SelfReg table\n");
4939 return ERROR_SUCCESS;
4942 rc = MSI_ViewExecute(view, 0);
4943 if (rc != ERROR_SUCCESS)
4945 MSI_ViewClose(view);
4946 msiobj_release(&view->hdr);
4956 rc = MSI_ViewFetch(view,&row);
4957 if (rc != ERROR_SUCCESS)
4963 filename = load_dynamic_stringW(row,1);
4964 index = get_loaded_file(package,filename);
4968 ERR("Unable to find file id %s\n",debugstr_w(filename));
4969 HeapFree(GetProcessHeap(),0,filename);
4970 msiobj_release(&row->hdr);
4973 HeapFree(GetProcessHeap(),0,filename);
4975 len = strlenW(ExeStr);
4976 len += strlenW(package->files[index].TargetPath);
4979 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
4980 strcpyW(filename,ExeStr);
4981 strcatW(filename,package->files[index].TargetPath);
4983 TRACE("Registering %s\n",debugstr_w(filename));
4984 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
4985 c_collen, &si, &info);
4988 WaitForSingleObject(info.hProcess,INFINITE);
4990 HeapFree(GetProcessHeap(),0,filename);
4991 msiobj_release(&row->hdr);
4993 MSI_ViewClose(view);
4994 msiobj_release(&view->hdr);
4998 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
5005 static const WCHAR szProductCode[]=
5006 {'P','r','o','d','u','c','t','C','o','d','e',0};
5009 return ERROR_INVALID_HANDLE;
5011 productcode = load_dynamic_property(package,szProductCode,&rc);
5015 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
5016 if (rc != ERROR_SUCCESS)
5019 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
5020 if (rc != ERROR_SUCCESS)
5023 /* here the guids are base 85 encoded */
5024 for (i = 0; i < package->loaded_features; i++)
5031 size = package->features[i].ComponentCount*21;
5033 if (package->features[i].Feature_Parent[0])
5034 size += strlenW(package->features[i].Feature_Parent)+2;
5036 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
5039 for (j = 0; j < package->features[i].ComponentCount; j++)
5042 memset(buf,0,sizeof(buf));
5043 TRACE("From %s\n",debugstr_w(package->components
5044 [package->features[i].Components[j]].ComponentId));
5045 CLSIDFromString(package->components
5046 [package->features[i].Components[j]].ComponentId,
5048 encode_base85_guid(&clsid,buf);
5049 TRACE("to %s\n",debugstr_w(buf));
5052 if (package->features[i].Feature_Parent[0])
5054 static const WCHAR sep[] = {'\2',0};
5056 strcatW(data,package->features[i].Feature_Parent);
5059 size = (strlenW(data)+1)*sizeof(WCHAR);
5060 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
5062 HeapFree(GetProcessHeap(),0,data);
5064 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
5065 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
5066 (LPSTR)package->features[i].Feature_Parent,size);
5072 HeapFree(GetProcessHeap(), 0, productcode);
5076 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
5078 static const WCHAR szProductCode[]=
5079 {'P','r','o','d','u','c','t','C','o','d','e',0};
5085 static WCHAR szNONE[] = {0};
5086 static const WCHAR szWindowsInstaler[] =
5087 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
5088 static const WCHAR szPropKeys[][80] =
5090 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
5091 {'A','R','P','C','O','N','T','A','C','T'},
5092 {'A','R','P','C','O','M','M','E','N','T','S',0},
5093 {'P','r','o','d','u','c','t','N','a','m','e',0},
5094 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
5095 {'A','R','P','H','E','L','P','L','I','N','K',0},
5096 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
5097 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
5098 {'S','O','U','R','C','E','D','I','R',0},
5099 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
5100 {'A','R','P','R','E','A','D','M','E',0},
5101 {'A','R','P','S','I','Z','E',0},
5102 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
5103 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
5104 {'P','r','o','d','u','c','t','I','D',0},
5108 static const WCHAR szRegKeys[][80] =
5110 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
5111 {'C','o','n','t','a','c','t',0},
5112 {'C','o','m','m','e','n','t','s',0},
5113 {'D','i','s','p','l','a','y','N','a','m','e',0},
5114 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
5115 {'H','e','l','p','L','i','n','k',0},
5116 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
5117 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
5118 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
5119 {'P','u','b','l','i','s','h','e','r',0},
5120 {'R','e','a','d','m','e',0},
5121 {'S','i','z','e',0},
5122 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
5123 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
5124 {'P','r','o','d','u','c','t','I','D',0},
5128 static const WCHAR path[] = {
5129 'C',':','\\','W','i','n','d','o','w','s','\\',
5130 'I','n','s','t','a','l','l','e','r','\\'};
5131 static const WCHAR fmt[] = {
5132 'C',':','\\','W','i','n','d','o','w','s','\\',
5133 'I','n','s','t','a','l','l','e','r','\\',
5134 '%','x','.','m','s','i',0};
5135 static const WCHAR szLocalPackage[]=
5136 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
5137 WCHAR packagefile[MAX_PATH];
5141 return ERROR_INVALID_HANDLE;
5143 productcode = load_dynamic_property(package,szProductCode,&rc);
5147 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
5148 if (rc != ERROR_SUCCESS)
5151 /* dump all the info i can grab */
5152 FIXME("Flesh out more information \n");
5155 while (szPropKeys[i][0]!=0)
5157 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
5158 if (rc != ERROR_SUCCESS)
5160 size = strlenW(buffer)*sizeof(WCHAR);
5161 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
5167 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
5169 /* copy the package locally */
5170 num = GetTickCount() & 0xffff;
5174 sprintfW(packagefile,fmt,num);
5177 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
5178 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
5179 if (handle != INVALID_HANDLE_VALUE)
5181 CloseHandle(handle);
5184 if (GetLastError() != ERROR_FILE_EXISTS &&
5185 GetLastError() != ERROR_SHARING_VIOLATION)
5187 if (!(++num & 0xffff)) num = 1;
5188 sprintfW(packagefile,fmt,num);
5189 } while (num != start);
5191 create_full_pathW(path);
5192 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
5193 CopyFileW(package->PackagePath,packagefile,FALSE);
5194 size = strlenW(packagefile)*sizeof(WCHAR);
5195 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
5198 HeapFree(GetProcessHeap(),0,productcode);
5201 return ERROR_SUCCESS;
5204 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
5208 return ERROR_INVALID_HANDLE;
5210 for (i = 0; i < package->DeferredActionCount; i++)
5213 action = package->DeferredAction[i];
5214 ui_actionstart(package, action);
5215 TRACE("Executing Action (%s)\n",debugstr_w(action));
5216 ACTION_CustomAction(package,action,TRUE);
5217 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
5219 HeapFree(GetProcessHeap(),0,package->DeferredAction);
5221 package->DeferredActionCount = 0;
5222 package->DeferredAction = NULL;
5224 return ERROR_SUCCESS;
5227 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
5231 return ERROR_INVALID_HANDLE;
5233 /* first do the same as an InstallExecute */
5234 ACTION_InstallExecute(package);
5236 /* then handle Commit Actions */
5237 for (i = 0; i < package->CommitActionCount; i++)
5240 action = package->CommitAction[i];
5241 ui_actionstart(package, action);
5242 TRACE("Executing Commit Action (%s)\n",debugstr_w(action));
5243 ACTION_CustomAction(package,action,TRUE);
5244 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
5246 HeapFree(GetProcessHeap(),0,package->CommitAction);
5248 package->CommitActionCount = 0;
5249 package->CommitAction = NULL;
5251 return ERROR_SUCCESS;
5254 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
5256 static const WCHAR RunOnce[] = {
5257 'S','o','f','t','w','a','r','e','\\',
5258 'M','i','c','r','o','s','o','f','t','\\',
5259 'W','i','n','d','o','w','s','\\',
5260 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5261 'R','u','n','O','n','c','e'};
5262 static const WCHAR InstallRunOnce[] = {
5263 'S','o','f','t','w','a','r','e','\\',
5264 'M','i','c','r','o','s','o','f','t','\\',
5265 'W','i','n','d','o','w','s','\\',
5266 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5267 'I','n','s','t','a','l','l','e','r','\\',
5268 'R','u','n','O','n','c','e','E','n','t','r','i','e','s'};
5270 static const WCHAR msiexec_fmt[] = {
5271 'C',':','\\','W','i','n','d','o','w','s','\\','S','y','s','t','e','m',
5272 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5273 '\"','%','s','\"',0};
5274 static const WCHAR install_fmt[] = {
5275 '/','I',' ','\"','%','s','\"',' ',
5276 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5277 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5281 WCHAR squished_pc[100];
5284 static const WCHAR szProductCode[]=
5285 {'P','r','o','d','u','c','t','C','o','d','e',0};
5286 static const WCHAR szLUS[] = {
5287 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
5288 static const WCHAR szSourceList[] = {
5289 'S','o','u','r','c','e','L','i','s','t',0};
5290 static const WCHAR szPackageName[] = {
5291 'P','a','c','k','a','g','e','N','a','m','e',0};
5294 return ERROR_INVALID_HANDLE;
5296 productcode = load_dynamic_property(package,szProductCode,&rc);
5300 squash_guid(productcode,squished_pc);
5302 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
5303 sprintfW(buffer,msiexec_fmt,squished_pc);
5305 size = strlenW(buffer)*sizeof(WCHAR);
5306 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5309 TRACE("Reboot command %s\n",debugstr_w(buffer));
5311 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
5312 sprintfW(buffer,install_fmt,productcode,squished_pc);
5313 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5316 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5317 if (rc == ERROR_SUCCESS)
5321 RegCreateKeyW(hukey, szSourceList, &hukey2);
5322 buf = load_dynamic_property(package,cszSourceDir,NULL);
5323 size = strlenW(buf)*sizeof(WCHAR);
5324 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
5325 HeapFree(GetProcessHeap(),0,buf);
5327 buf = strrchrW(package->PackagePath,'\\');
5331 size = strlenW(buf)*sizeof(WCHAR);
5332 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
5335 RegCloseKey(hukey2);
5337 HeapFree(GetProcessHeap(),0,productcode);
5339 return ERROR_INSTALL_SUSPEND;
5342 UINT ACTION_ResolveSource(MSIPACKAGE* package)
5345 * we are currently doing what should be done here in the top level Install
5346 * however for Adminastrative and uninstalls this step will be needed
5348 return ERROR_SUCCESS;
5351 /* Msi functions that seem appropriate here */
5352 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
5357 TRACE(" exteral attempt at action %s\n",szAction);
5360 return ERROR_FUNCTION_FAILED;
5362 return ERROR_FUNCTION_FAILED;
5364 szwAction = strdupAtoW(szAction);
5367 return ERROR_FUNCTION_FAILED;
5370 rc = MsiDoActionW(hInstall, szwAction);
5371 HeapFree(GetProcessHeap(),0,szwAction);
5375 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
5377 MSIPACKAGE *package;
5378 UINT ret = ERROR_INVALID_HANDLE;
5380 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
5382 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5385 ret = ACTION_PerformAction(package,szAction);
5386 msiobj_release( &package->hdr );
5391 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
5392 LPSTR szPathBuf, DWORD* pcchPathBuf)
5398 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
5401 return ERROR_FUNCTION_FAILED;
5403 return ERROR_FUNCTION_FAILED;
5405 szwFolder = strdupAtoW(szFolder);
5408 return ERROR_FUNCTION_FAILED;
5410 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
5412 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
5414 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
5415 *pcchPathBuf, NULL, NULL );
5417 HeapFree(GetProcessHeap(),0,szwFolder);
5418 HeapFree(GetProcessHeap(),0,szwPathBuf);
5423 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
5424 szPathBuf, DWORD* pcchPathBuf)
5427 UINT rc = ERROR_FUNCTION_FAILED;
5428 MSIPACKAGE *package;
5430 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5432 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5434 return ERROR_INVALID_HANDLE;
5435 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
5436 msiobj_release( &package->hdr );
5438 if (path && (strlenW(path) > *pcchPathBuf))
5440 *pcchPathBuf = strlenW(path)+1;
5441 rc = ERROR_MORE_DATA;
5445 *pcchPathBuf = strlenW(path)+1;
5446 strcpyW(szPathBuf,path);
5447 TRACE("Returning Path %s\n",debugstr_w(path));
5450 HeapFree(GetProcessHeap(),0,path);
5456 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
5457 LPSTR szPathBuf, DWORD* pcchPathBuf)
5463 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
5466 return ERROR_FUNCTION_FAILED;
5468 return ERROR_FUNCTION_FAILED;
5470 szwFolder = strdupAtoW(szFolder);
5472 return ERROR_FUNCTION_FAILED;
5474 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
5476 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
5478 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
5479 *pcchPathBuf, NULL, NULL );
5481 HeapFree(GetProcessHeap(),0,szwFolder);
5482 HeapFree(GetProcessHeap(),0,szwPathBuf);
5487 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
5488 szPathBuf, DWORD* pcchPathBuf)
5491 UINT rc = ERROR_FUNCTION_FAILED;
5492 MSIPACKAGE *package;
5494 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5496 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5498 return ERROR_INVALID_HANDLE;
5499 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
5500 msiobj_release( &package->hdr );
5502 if (path && strlenW(path) > *pcchPathBuf)
5504 *pcchPathBuf = strlenW(path)+1;
5505 rc = ERROR_MORE_DATA;
5509 *pcchPathBuf = strlenW(path)+1;
5510 strcpyW(szPathBuf,path);
5511 TRACE("Returning Path %s\n",debugstr_w(path));
5514 HeapFree(GetProcessHeap(),0,path);
5520 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
5521 LPCSTR szFolderPath)
5524 LPWSTR szwFolderPath;
5528 return ERROR_FUNCTION_FAILED;
5530 return ERROR_FUNCTION_FAILED;
5532 szwFolder = strdupAtoW(szFolder);
5534 return ERROR_FUNCTION_FAILED;
5536 szwFolderPath = strdupAtoW(szFolderPath);
5539 HeapFree(GetProcessHeap(),0,szwFolder);
5540 return ERROR_FUNCTION_FAILED;
5543 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
5545 HeapFree(GetProcessHeap(),0,szwFolder);
5546 HeapFree(GetProcessHeap(),0,szwFolderPath);
5551 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
5552 LPCWSTR szFolderPath)
5556 LPWSTR path2 = NULL;
5559 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
5562 return ERROR_INVALID_HANDLE;
5564 if (szFolderPath[0]==0)
5565 return ERROR_FUNCTION_FAILED;
5567 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
5568 return ERROR_FUNCTION_FAILED;
5570 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
5573 return ERROR_INVALID_PARAMETER;
5575 HeapFree(GetProcessHeap(),0,folder->Property);
5576 folder->Property = build_directory_name(2, szFolderPath, NULL);
5578 if (strcmpiW(path, folder->Property) == 0)
5581 * Resolved Target has not really changed, so just
5582 * set this folder and do not recalculate everything.
5584 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
5585 folder->ResolvedTarget = NULL;
5586 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
5587 HeapFree(GetProcessHeap(),0,path2);
5591 for (i = 0; i < package->loaded_folders; i++)
5593 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
5594 package->folders[i].ResolvedTarget=NULL;
5597 for (i = 0; i < package->loaded_folders; i++)
5599 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
5601 HeapFree(GetProcessHeap(),0,path2);
5604 HeapFree(GetProcessHeap(),0,path);
5606 return ERROR_SUCCESS;
5609 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
5610 LPCWSTR szFolderPath)
5612 MSIPACKAGE *package;
5615 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
5617 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5618 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
5619 msiobj_release( &package->hdr );
5623 /***********************************************************************
5624 * MsiGetMode (MSI.@)
5626 * Returns an internal installer state (if it is running in a mode iRunMode)
5629 * hInstall [I] Handle to the installation
5630 * hRunMode [I] Checking run mode
5631 * MSIRUNMODE_ADMIN Administrative mode
5632 * MSIRUNMODE_ADVERTISE Advertisement mode
5633 * MSIRUNMODE_MAINTENANCE Maintenance mode
5634 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
5635 * MSIRUNMODE_LOGENABLED Log file is writing
5636 * MSIRUNMODE_OPERATIONS Operations in progress??
5637 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
5638 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
5639 * MSIRUNMODE_CABINET Files from cabinet are installed
5640 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
5641 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
5642 * MSIRUNMODE_RESERVED11 Reserved
5643 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
5644 * MSIRUNMODE_ZAWENABLED Demand installation is supported
5645 * MSIRUNMODE_RESERVED14 Reserved
5646 * MSIRUNMODE_RESERVED15 Reserved
5647 * MSIRUNMODE_SCHEDULED called from install script
5648 * MSIRUNMODE_ROLLBACK called from rollback script
5649 * MSIRUNMODE_COMMIT called from commit script
5652 * In the state: TRUE
5653 * Not in the state: FALSE
5657 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
5659 FIXME("STUB (iRunMode=%i)\n",iRunMode);
5664 * According to the docs, when this is called it immediately recalculates
5665 * all the component states as well
5667 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
5668 INSTALLSTATE iState)
5670 LPWSTR szwFeature = NULL;
5673 szwFeature = strdupAtoW(szFeature);
5676 return ERROR_FUNCTION_FAILED;
5678 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
5680 HeapFree(GetProcessHeap(),0,szwFeature);
5685 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
5686 INSTALLSTATE iState)
5688 MSIPACKAGE* package;
5691 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
5693 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5695 return ERROR_INVALID_HANDLE;
5697 index = get_loaded_feature(package,szFeature);
5699 return ERROR_UNKNOWN_FEATURE;
5701 package->features[index].ActionRequest= iState;
5702 ACTION_UpdateComponentStates(package,szFeature);
5704 return ERROR_SUCCESS;
5707 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
5708 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5710 LPWSTR szwFeature = NULL;
5713 szwFeature = strdupAtoW(szFeature);
5715 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
5717 HeapFree( GetProcessHeap(), 0 , szwFeature);
5722 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
5723 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5727 index = get_loaded_feature(package,szFeature);
5729 return ERROR_UNKNOWN_FEATURE;
5732 *piInstalled = package->features[index].Installed;
5735 *piAction = package->features[index].Action;
5737 TRACE("returning %i %i\n",*piInstalled,*piAction);
5739 return ERROR_SUCCESS;
5742 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
5743 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5745 MSIPACKAGE* package;
5748 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
5751 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5753 return ERROR_INVALID_HANDLE;
5754 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
5755 msiobj_release( &package->hdr );
5759 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
5760 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5762 LPWSTR szwComponent= NULL;
5765 szwComponent= strdupAtoW(szComponent);
5767 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
5769 HeapFree( GetProcessHeap(), 0 , szwComponent);
5774 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
5775 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5779 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
5782 index = get_loaded_component(package,szComponent);
5784 return ERROR_UNKNOWN_COMPONENT;
5787 *piInstalled = package->components[index].Installed;
5790 *piAction = package->components[index].Action;
5792 TRACE("states (%i, %i)\n",
5793 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
5795 return ERROR_SUCCESS;
5798 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
5799 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5801 MSIPACKAGE* package;
5804 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
5805 piInstalled, piAction);
5807 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5809 return ERROR_INVALID_HANDLE;
5810 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
5811 msiobj_release( &package->hdr );
5816 static UINT ACTION_Template(MSIPACKAGE *package)
5820 MSIRECORD * row = 0;
5821 static const WCHAR ExecSeqQuery[] = {0};
5823 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5824 if (rc != ERROR_SUCCESS)
5827 rc = MSI_ViewExecute(view, 0);
5828 if (rc != ERROR_SUCCESS)
5830 MSI_ViewClose(view);
5831 msiobj_release(&view->hdr);
5837 rc = MSI_ViewFetch(view,&row);
5838 if (rc != ERROR_SUCCESS)
5844 msiobj_release(&row->hdr);
5846 MSI_ViewClose(view);
5847 msiobj_release(&view->hdr);