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,'\\');
831 check = load_dynamic_property(package, cszSourceDir,NULL);
833 MSI_SetPropertyW(package, cszSourceDir, path);
835 HeapFree(GetProcessHeap(), 0, check);
837 HeapFree(GetProcessHeap(), 0, path);
843 ptr = (LPWSTR)szCommandLine;
850 TRACE("Looking at %s\n",debugstr_w(ptr));
852 ptr2 = strchrW(ptr,'=');
858 while (*ptr == ' ') ptr++;
860 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
861 strncpyW(prop,ptr,len);
867 while (*ptr && (quote || (!quote && *ptr!=' ')))
880 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
881 strncpyW(val,ptr2,len);
884 if (strlenW(prop) > 0)
886 TRACE("Found commandline property (%s) = (%s)\n",
887 debugstr_w(prop), debugstr_w(val));
888 MSI_SetPropertyW(package,prop,val);
890 HeapFree(GetProcessHeap(),0,val);
891 HeapFree(GetProcessHeap(),0,prop);
898 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
900 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
902 rc = ACTION_ProcessUISequence(package);
903 if (rc == ERROR_SUCCESS)
904 rc = ACTION_ProcessExecSequence(package,TRUE);
907 rc = ACTION_ProcessExecSequence(package,FALSE);
910 rc = ACTION_ProcessExecSequence(package,FALSE);
914 /* install was halted but should be considered a success */
918 /* process the ending type action */
919 if (rc == ERROR_SUCCESS)
920 ACTION_PerformActionSequence(package,-1);
921 else if (rc == ERROR_INSTALL_USEREXIT)
922 ACTION_PerformActionSequence(package,-2);
923 else if (rc == ERROR_FUNCTION_FAILED)
924 ACTION_PerformActionSequence(package,-3);
925 else if (rc == ERROR_INSTALL_SUSPEND)
926 ACTION_PerformActionSequence(package,-4);
928 /* finish up running custom actions */
929 ACTION_FinishCustomActions(package);
934 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq)
941 static const WCHAR ExecSeqQuery[] = {
942 's','e','l','e','c','t',' ','*',' ',
944 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
945 'S','e','q','u','e','n','c','e',' ',
946 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
949 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
951 if (rc == ERROR_SUCCESS)
953 rc = MSI_ViewExecute(view, 0);
955 if (rc != ERROR_SUCCESS)
958 msiobj_release(&view->hdr);
962 TRACE("Running the actions\n");
964 rc = MSI_ViewFetch(view,&row);
965 if (rc != ERROR_SUCCESS)
971 /* check conditions */
972 if (!MSI_RecordIsNull(row,2))
975 cond = load_dynamic_stringW(row,2);
979 /* this is a hack to skip errors in the condition code */
980 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
982 HeapFree(GetProcessHeap(),0,cond);
983 msiobj_release(&row->hdr);
987 HeapFree(GetProcessHeap(),0,cond);
992 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
993 if (rc != ERROR_SUCCESS)
995 ERR("Error is %x\n",rc);
996 msiobj_release(&row->hdr);
1000 rc = ACTION_PerformAction(package,buffer);
1001 msiobj_release(&row->hdr);
1003 MSI_ViewClose(view);
1004 msiobj_release(&view->hdr);
1012 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1016 static const WCHAR ExecSeqQuery[] = {
1017 's','e','l','e','c','t',' ','*',' ',
1018 'f','r','o','m',' ',
1019 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1020 'S','e','q','u','e','n','c','e',' ',
1021 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
1022 '>',' ','%','i',' ','o','r','d','e','r',' ',
1023 'b','y',' ','S','e','q','u','e','n','c','e',0 };
1024 MSIRECORD * row = 0;
1025 static const WCHAR IVQuery[] = {
1026 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
1027 'f','r','o','m',' ','I','n','s','t','a','l','l',
1028 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
1029 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
1030 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
1034 /* get the sequence number */
1037 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
1038 if (rc != ERROR_SUCCESS)
1040 rc = MSI_ViewExecute(view, 0);
1041 if (rc != ERROR_SUCCESS)
1043 MSI_ViewClose(view);
1044 msiobj_release(&view->hdr);
1047 rc = MSI_ViewFetch(view,&row);
1048 if (rc != ERROR_SUCCESS)
1050 MSI_ViewClose(view);
1051 msiobj_release(&view->hdr);
1054 seq = MSI_RecordGetInteger(row,1);
1055 msiobj_release(&row->hdr);
1056 MSI_ViewClose(view);
1057 msiobj_release(&view->hdr);
1060 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1061 if (rc == ERROR_SUCCESS)
1063 rc = MSI_ViewExecute(view, 0);
1065 if (rc != ERROR_SUCCESS)
1067 MSI_ViewClose(view);
1068 msiobj_release(&view->hdr);
1072 TRACE("Running the actions\n");
1076 WCHAR buffer[0x100];
1079 rc = MSI_ViewFetch(view,&row);
1080 if (rc != ERROR_SUCCESS)
1086 /* check conditions */
1087 if (!MSI_RecordIsNull(row,2))
1090 cond = load_dynamic_stringW(row,2);
1094 /* this is a hack to skip errors in the condition code */
1095 if (MSI_EvaluateConditionW(package, cond) ==
1098 HeapFree(GetProcessHeap(),0,cond);
1099 msiobj_release(&row->hdr);
1103 HeapFree(GetProcessHeap(),0,cond);
1108 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1109 if (rc != ERROR_SUCCESS)
1111 ERR("Error is %x\n",rc);
1112 msiobj_release(&row->hdr);
1116 rc = ACTION_PerformAction(package,buffer);
1118 if (rc == ERROR_FUNCTION_NOT_CALLED)
1121 if (rc != ERROR_SUCCESS)
1123 ERR("Execution halted due to error (%i)\n",rc);
1124 msiobj_release(&row->hdr);
1128 msiobj_release(&row->hdr);
1131 MSI_ViewClose(view);
1132 msiobj_release(&view->hdr);
1140 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1144 static const WCHAR ExecSeqQuery [] = {
1145 's','e','l','e','c','t',' ','*',' ',
1146 'f','r','o','m',' ','I','n','s','t','a','l','l',
1147 'U','I','S','e','q','u','e','n','c','e',' ',
1148 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
1149 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
1151 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1153 if (rc == ERROR_SUCCESS)
1155 rc = MSI_ViewExecute(view, 0);
1157 if (rc != ERROR_SUCCESS)
1159 MSI_ViewClose(view);
1160 msiobj_release(&view->hdr);
1164 TRACE("Running the actions \n");
1168 WCHAR buffer[0x100];
1170 MSIRECORD * row = 0;
1172 rc = MSI_ViewFetch(view,&row);
1173 if (rc != ERROR_SUCCESS)
1179 /* check conditions */
1180 if (!MSI_RecordIsNull(row,2))
1183 cond = load_dynamic_stringW(row,2);
1187 /* this is a hack to skip errors in the condition code */
1188 if (MSI_EvaluateConditionW(package, cond) ==
1191 HeapFree(GetProcessHeap(),0,cond);
1192 msiobj_release(&row->hdr);
1196 HeapFree(GetProcessHeap(),0,cond);
1201 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1202 if (rc != ERROR_SUCCESS)
1204 ERR("Error is %x\n",rc);
1205 msiobj_release(&row->hdr);
1209 rc = ACTION_PerformUIAction(package,buffer);
1211 if (rc == ERROR_FUNCTION_NOT_CALLED)
1214 if (rc != ERROR_SUCCESS)
1216 ERR("Execution halted due to error (%i)\n",rc);
1217 msiobj_release(&row->hdr);
1221 msiobj_release(&row->hdr);
1224 MSI_ViewClose(view);
1225 msiobj_release(&view->hdr);
1232 /********************************************************
1233 * ACTION helper functions and functions that perform the actions
1234 *******************************************************/
1235 BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action, UINT* rc)
1241 while (StandardActions[i].action != NULL)
1243 if (strcmpW(StandardActions[i].action, action)==0)
1245 ui_actioninfo(package, action, TRUE, 0);
1246 ui_actionstart(package, action);
1247 if (StandardActions[i].handler)
1249 *rc = StandardActions[i].handler(package);
1253 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1254 *rc = ERROR_SUCCESS;
1256 ui_actioninfo(package, action, FALSE, *rc);
1265 BOOL ACTION_HandleDialogBox(MSIPACKAGE *package, LPCWSTR dialog, UINT* rc)
1270 * for the UI when we get that working
1272 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1274 *rc = package->CurrentInstallState;
1281 BOOL ACTION_HandleCustomAction(MSIPACKAGE* package, LPCWSTR action, UINT* rc)
1286 arc = ACTION_CustomAction(package,action,FALSE);
1288 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1297 * A lot of actions are really important even if they don't do anything
1298 * explicit... Lots of properties are set at the beginning of the installation
1299 * CostFinalize does a bunch of work to translate the directories and such
1301 * But until I get write access to the database that is hard, so I am going to
1302 * hack it to see if I can get something to run.
1304 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
1306 UINT rc = ERROR_SUCCESS;
1309 TRACE("Performing action (%s)\n",debugstr_w(action));
1311 handled = ACTION_HandleStandardAction(package, action, &rc);
1314 handled = ACTION_HandleCustomAction(package, action, &rc);
1318 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1319 rc = ERROR_FUNCTION_NOT_CALLED;
1322 package->CurrentInstallState = rc;
1326 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1328 UINT rc = ERROR_SUCCESS;
1329 BOOL handled = FALSE;
1331 TRACE("Performing action (%s)\n",debugstr_w(action));
1333 handled = ACTION_HandleStandardAction(package, action, &rc);
1336 handled = ACTION_HandleCustomAction(package, action, &rc);
1339 handled = ACTION_HandleDialogBox(package, action, &rc);
1343 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1344 rc = ERROR_FUNCTION_NOT_CALLED;
1347 package->CurrentInstallState = rc;
1351 /***********************************************************************
1354 * Recursively create all directories in the path.
1356 * shamelessly stolen from setupapi/queue.c
1358 static BOOL create_full_pathW(const WCHAR *path)
1364 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1367 strcpyW(new_path, path);
1369 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1370 new_path[len - 1] = 0;
1372 while(!CreateDirectoryW(new_path, NULL))
1375 DWORD last_error = GetLastError();
1376 if(last_error == ERROR_ALREADY_EXISTS)
1379 if(last_error != ERROR_PATH_NOT_FOUND)
1385 if(!(slash = strrchrW(new_path, '\\')))
1391 len = slash - new_path;
1393 if(!create_full_pathW(new_path))
1398 new_path[len] = '\\';
1401 HeapFree(GetProcessHeap(), 0, new_path);
1406 * Also we cannot enable/disable components either, so for now I am just going
1407 * to do all the directories for all the components.
1409 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1411 static const WCHAR ExecSeqQuery[] = {
1412 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1413 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1418 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1419 if (rc != ERROR_SUCCESS)
1420 return ERROR_SUCCESS;
1422 rc = MSI_ViewExecute(view, 0);
1423 if (rc != ERROR_SUCCESS)
1425 MSI_ViewClose(view);
1426 msiobj_release(&view->hdr);
1435 MSIRECORD *row = NULL, *uirow;
1437 rc = MSI_ViewFetch(view,&row);
1438 if (rc != ERROR_SUCCESS)
1445 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1447 if (rc!= ERROR_SUCCESS)
1449 ERR("Unable to get folder id \n");
1450 msiobj_release(&row->hdr);
1455 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1458 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1459 msiobj_release(&row->hdr);
1463 TRACE("Folder is %s\n",debugstr_w(full_path));
1466 uirow = MSI_CreateRecord(1);
1467 MSI_RecordSetStringW(uirow,1,full_path);
1468 ui_actiondata(package,szCreateFolders,uirow);
1469 msiobj_release( &uirow->hdr );
1471 if (folder->State == 0)
1472 create_full_pathW(full_path);
1476 msiobj_release(&row->hdr);
1477 HeapFree(GetProcessHeap(),0,full_path);
1479 MSI_ViewClose(view);
1480 msiobj_release(&view->hdr);
1485 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1487 int index = package->loaded_components;
1490 /* fill in the data */
1492 package->loaded_components++;
1493 if (package->loaded_components == 1)
1494 package->components = HeapAlloc(GetProcessHeap(),0,
1495 sizeof(MSICOMPONENT));
1497 package->components = HeapReAlloc(GetProcessHeap(),0,
1498 package->components, package->loaded_components *
1499 sizeof(MSICOMPONENT));
1501 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1504 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1506 TRACE("Loading Component %s\n",
1507 debugstr_w(package->components[index].Component));
1510 if (!MSI_RecordIsNull(row,2))
1511 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1514 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1516 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1519 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1522 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1524 package->components[index].Installed = INSTALLSTATE_ABSENT;
1525 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1526 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1528 package->components[index].Enabled = TRUE;
1533 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1535 int index = package->loaded_features;
1537 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1538 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1539 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1540 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1541 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1542 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1543 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1550 /* fill in the data */
1552 package->loaded_features ++;
1553 if (package->loaded_features == 1)
1554 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1556 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1557 package->loaded_features * sizeof(MSIFEATURE));
1559 memset(&package->features[index],0,sizeof(MSIFEATURE));
1562 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1564 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1567 if (!MSI_RecordIsNull(row,2))
1568 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1571 if (!MSI_RecordIsNull(row,3))
1572 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1575 if (!MSI_RecordIsNull(row,4))
1576 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1578 if (!MSI_RecordIsNull(row,5))
1579 package->features[index].Display = MSI_RecordGetInteger(row,5);
1581 package->features[index].Level= MSI_RecordGetInteger(row,6);
1584 if (!MSI_RecordIsNull(row,7))
1585 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1587 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1589 package->features[index].Installed = INSTALLSTATE_ABSENT;
1590 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1591 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1593 /* load feature components */
1595 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1596 if (rc != ERROR_SUCCESS)
1598 rc = MSI_ViewExecute(view,0);
1599 if (rc != ERROR_SUCCESS)
1601 MSI_ViewClose(view);
1602 msiobj_release(&view->hdr);
1608 WCHAR buffer[0x100];
1611 INT cnt = package->features[index].ComponentCount;
1613 rc = MSI_ViewFetch(view,&row2);
1614 if (rc != ERROR_SUCCESS)
1618 MSI_RecordGetStringW(row2,1,buffer,&sz);
1620 /* check to see if the component is already loaded */
1621 c_indx = get_loaded_component(package,buffer);
1624 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1626 package->features[index].Components[cnt] = c_indx;
1627 package->features[index].ComponentCount ++;
1631 rc = MSI_OpenQuery(package->db, &view2, Query2, buffer);
1632 if (rc != ERROR_SUCCESS)
1634 msiobj_release( &row2->hdr );
1637 rc = MSI_ViewExecute(view2,0);
1638 if (rc != ERROR_SUCCESS)
1640 msiobj_release( &row2->hdr );
1641 MSI_ViewClose(view2);
1642 msiobj_release( &view2->hdr );
1649 rc = MSI_ViewFetch(view2,&row3);
1650 if (rc != ERROR_SUCCESS)
1652 c_indx = load_component(package,row3);
1653 msiobj_release( &row3->hdr );
1655 package->features[index].Components[cnt] = c_indx;
1656 package->features[index].ComponentCount ++;
1657 TRACE("Loaded new component to index %i\n",c_indx);
1659 MSI_ViewClose(view2);
1660 msiobj_release( &view2->hdr );
1661 msiobj_release( &row2->hdr );
1663 MSI_ViewClose(view);
1664 msiobj_release(&view->hdr);
1668 * I am not doing any of the costing functionality yet.
1669 * Mostly looking at doing the Component and Feature loading
1671 * The native MSI does A LOT of modification to tables here. Mostly adding
1672 * a lot of temporary columns to the Feature and Component tables.
1674 * note: Native msi also tracks the short filename. But I am only going to
1675 * track the long ones. Also looking at this directory table
1676 * it appears that the directory table does not get the parents
1677 * resolved base on property only based on their entries in the
1680 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1685 static const WCHAR Query_all[] = {
1686 'S','E','L','E','C','T',' ','*',' ',
1687 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1688 static const WCHAR szCosting[] = {
1689 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1690 static const WCHAR szZero[] = { '0', 0 };
1692 MSI_SetPropertyW(package, szCosting, szZero);
1693 MSI_SetPropertyW(package, cszRootDrive , c_collen);
1695 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1696 if (rc != ERROR_SUCCESS)
1698 rc = MSI_ViewExecute(view,0);
1699 if (rc != ERROR_SUCCESS)
1701 MSI_ViewClose(view);
1702 msiobj_release(&view->hdr);
1709 rc = MSI_ViewFetch(view,&row);
1710 if (rc != ERROR_SUCCESS)
1713 load_feature(package,row);
1714 msiobj_release(&row->hdr);
1716 MSI_ViewClose(view);
1717 msiobj_release(&view->hdr);
1719 return ERROR_SUCCESS;
1722 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1724 DWORD index = package->loaded_files;
1728 /* fill in the data */
1730 package->loaded_files++;
1731 if (package->loaded_files== 1)
1732 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1734 package->files = HeapReAlloc(GetProcessHeap(),0,
1735 package->files , package->loaded_files * sizeof(MSIFILE));
1737 memset(&package->files[index],0,sizeof(MSIFILE));
1739 package->files[index].File = load_dynamic_stringW(row, 1);
1740 buffer = load_dynamic_stringW(row, 2);
1742 package->files[index].ComponentIndex = -1;
1743 for (i = 0; i < package->loaded_components; i++)
1744 if (strcmpW(package->components[i].Component,buffer)==0)
1746 package->files[index].ComponentIndex = i;
1749 if (package->files[index].ComponentIndex == -1)
1750 ERR("Unfound Component %s\n",debugstr_w(buffer));
1751 HeapFree(GetProcessHeap(), 0, buffer);
1753 package->files[index].FileName = load_dynamic_stringW(row,3);
1755 reduce_to_longfilename(package->files[index].FileName);
1757 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1758 package->files[index].Version = load_dynamic_stringW(row, 5);
1759 package->files[index].Language = load_dynamic_stringW(row, 6);
1760 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1761 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1763 package->files[index].Temporary = FALSE;
1764 package->files[index].State = 0;
1766 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1768 return ERROR_SUCCESS;
1771 static UINT ACTION_FileCost(MSIPACKAGE *package)
1776 static const WCHAR Query[] = {
1777 'S','E','L','E','C','T',' ','*',' ',
1778 'F','R','O','M',' ','F','i','l','e',' ',
1779 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1782 return ERROR_INVALID_HANDLE;
1784 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1785 if (rc != ERROR_SUCCESS)
1786 return ERROR_SUCCESS;
1788 rc = MSI_ViewExecute(view, 0);
1789 if (rc != ERROR_SUCCESS)
1791 MSI_ViewClose(view);
1792 msiobj_release(&view->hdr);
1793 return ERROR_SUCCESS;
1798 rc = MSI_ViewFetch(view,&row);
1799 if (rc != ERROR_SUCCESS)
1804 load_file(package,row);
1805 msiobj_release(&row->hdr);
1807 MSI_ViewClose(view);
1808 msiobj_release(&view->hdr);
1810 return ERROR_SUCCESS;
1813 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1816 static const WCHAR Query[] =
1817 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1818 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1819 'o','r','y','`',' ','=',' ','`','%','s','`',0};
1822 LPWSTR targetdir, parent, srcdir;
1823 MSIRECORD * row = 0;
1827 TRACE("Looking for dir %s\n",debugstr_w(dir));
1829 for (i = 0; i < package->loaded_folders; i++)
1831 if (strcmpW(package->folders[i].Directory,dir)==0)
1833 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1838 TRACE("Working to load %s\n",debugstr_w(dir));
1840 index = package->loaded_folders++;
1841 if (package->loaded_folders==1)
1842 package->folders = HeapAlloc(GetProcessHeap(),0,
1845 package->folders= HeapReAlloc(GetProcessHeap(),0,
1846 package->folders, package->loaded_folders*
1849 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1851 package->folders[index].Directory = dupstrW(dir);
1853 rc = MSI_OpenQuery(package->db, &view, Query, dir);
1854 if (rc != ERROR_SUCCESS)
1857 rc = MSI_ViewExecute(view, 0);
1858 if (rc != ERROR_SUCCESS)
1860 MSI_ViewClose(view);
1861 msiobj_release(&view->hdr);
1865 rc = MSI_ViewFetch(view,&row);
1866 if (rc != ERROR_SUCCESS)
1868 MSI_ViewClose(view);
1869 msiobj_release(&view->hdr);
1873 targetdir = load_dynamic_stringW(row,3);
1875 /* split src and target dir */
1876 if (strchrW(targetdir,':'))
1878 srcdir=strchrW(targetdir,':');
1885 /* for now only pick long filename versions */
1886 if (strchrW(targetdir,'|'))
1888 targetdir = strchrW(targetdir,'|');
1892 if (srcdir && strchrW(srcdir,'|'))
1894 srcdir= strchrW(srcdir,'|');
1899 /* now check for root dirs */
1900 if (targetdir[0] == '.' && targetdir[1] == 0)
1903 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1908 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1909 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
1910 package->folders[index].TargetDefault = dupstrW(targetdir);
1914 package->folders[index].SourceDefault = dupstrW(srcdir);
1916 package->folders[index].SourceDefault = dupstrW(targetdir);
1917 HeapFree(GetProcessHeap(), 0, targetdir);
1919 parent = load_dynamic_stringW(row,2);
1922 i = load_folder(package,parent);
1923 package->folders[index].ParentIndex = i;
1924 TRACE("Parent is index %i... %s %s\n",
1925 package->folders[index].ParentIndex,
1926 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1927 debugstr_w(parent));
1930 package->folders[index].ParentIndex = -2;
1931 HeapFree(GetProcessHeap(), 0, parent);
1933 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
1935 msiobj_release(&row->hdr);
1936 MSI_ViewClose(view);
1937 msiobj_release(&view->hdr);
1938 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1943 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
1944 BOOL set_prop, MSIFOLDER **folder)
1947 LPWSTR p, path = NULL;
1949 TRACE("Working to resolve %s\n",debugstr_w(name));
1951 /* special resolving for Target and Source root dir */
1952 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
1956 path = load_dynamic_property(package,cszTargetDir,NULL);
1959 path = load_dynamic_property(package,cszRootDrive,NULL);
1961 MSI_SetPropertyW(package,cszTargetDir,path);
1965 for (i = 0; i < package->loaded_folders; i++)
1967 if (strcmpW(package->folders[i].Directory,name)==0)
1970 *folder = &(package->folders[i]);
1976 path = load_dynamic_property(package,cszSourceDir,NULL);
1979 path = load_dynamic_property(package,cszDatabase,NULL);
1982 p = strrchrW(path,'\\');
1989 for (i = 0; i < package->loaded_folders; i++)
1991 if (strcmpW(package->folders[i].Directory,name)==0)
1994 *folder = &(package->folders[i]);
2000 for (i = 0; i < package->loaded_folders; i++)
2002 if (strcmpW(package->folders[i].Directory,name)==0)
2006 if (i >= package->loaded_folders)
2010 *folder = &(package->folders[i]);
2012 if (!source && package->folders[i].ResolvedTarget)
2014 path = dupstrW(package->folders[i].ResolvedTarget);
2015 TRACE(" already resolved to %s\n",debugstr_w(path));
2018 else if (source && package->folders[i].ResolvedSource)
2020 path = dupstrW(package->folders[i].ResolvedSource);
2023 else if (!source && package->folders[i].Property)
2025 path = build_directory_name(2, package->folders[i].Property, NULL);
2027 TRACE(" internally set to %s\n",debugstr_w(path));
2029 MSI_SetPropertyW(package,name,path);
2033 if (package->folders[i].ParentIndex >= 0)
2035 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2037 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2039 p = resolve_folder(package, parent, source, set_prop, NULL);
2042 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2043 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2044 package->folders[i].ResolvedTarget = dupstrW(path);
2045 TRACE(" resolved into %s\n",debugstr_w(path));
2047 MSI_SetPropertyW(package,name,path);
2051 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2052 package->folders[i].ResolvedSource = dupstrW(path);
2054 HeapFree(GetProcessHeap(),0,p);
2059 /* update compoennt state based on a feature change */
2060 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2063 INSTALLSTATE newstate;
2064 MSIFEATURE *feature;
2066 i = get_loaded_feature(package,szFeature);
2070 feature = &package->features[i];
2071 newstate = feature->ActionRequest;
2073 for( i = 0; i < feature->ComponentCount; i++)
2075 MSICOMPONENT* component = &package->components[feature->Components[i]];
2077 if (!component->Enabled)
2081 if (newstate == INSTALLSTATE_LOCAL)
2082 component->ActionRequest = INSTALLSTATE_LOCAL;
2087 component->ActionRequest = newstate;
2089 /*if any other feature wants is local we need to set it local*/
2091 j < package->loaded_features &&
2092 component->ActionRequest != INSTALLSTATE_LOCAL;
2095 for (k = 0; k < package->features[j].ComponentCount; k++)
2096 if ( package->features[j].Components[k] ==
2097 feature->Components[i] )
2099 if (package->features[j].ActionRequest ==
2101 component->ActionRequest = INSTALLSTATE_LOCAL;
2110 static UINT SetFeatureStates(MSIPACKAGE *package)
2116 LPWSTR override = NULL;
2117 static const WCHAR all[]={'A','L','L',0};
2118 static const WCHAR szlevel[] = {
2119 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2120 static const WCHAR szAddLocal[] = {
2121 'A','D','D','L','O','C','A','L',0};
2123 /* I do not know if this is where it should happen.. but */
2125 TRACE("Checking Install Level\n");
2127 level = load_dynamic_property(package,szlevel,NULL);
2130 install_level = atoiW(level);
2131 HeapFree(GetProcessHeap(), 0, level);
2136 /* ok hereis the rub
2137 * ADDLOCAL and its friend OVERRIDE INSTALLLEVLE
2138 * I have confirmed this if ADDLOCALis stated then the INSTALLLEVEL is
2139 * itnored for all the features. seems strange, epsecially since it is not
2140 * documented anywhere, but it is how it works.
2143 override = load_dynamic_property(package,szAddLocal,NULL);
2147 for(i = 0; i < package->loaded_features; i++)
2149 if (strcmpiW(override,all)==0)
2151 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2152 package->features[i].Action = INSTALLSTATE_LOCAL;
2156 LPWSTR ptr = override;
2157 LPWSTR ptr2 = strchrW(override,',');
2162 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2164 strcmpW(ptr,package->features[i].Feature)==0))
2166 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2167 package->features[i].Action = INSTALLSTATE_LOCAL;
2173 ptr2 = strchrW(ptr,',');
2180 HeapFree(GetProcessHeap(),0,override);
2184 for(i = 0; i < package->loaded_features; i++)
2186 BOOL feature_state= ((package->features[i].Level > 0) &&
2187 (package->features[i].Level <= install_level));
2191 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2192 package->features[i].Action = INSTALLSTATE_LOCAL;
2198 * now we want to enable or disable components base on feature
2201 for(i = 0; i < package->loaded_features; i++)
2203 MSIFEATURE* feature = &package->features[i];
2204 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2205 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2206 feature->ActionRequest);
2208 for( j = 0; j < feature->ComponentCount; j++)
2210 MSICOMPONENT* component = &package->components[
2211 feature->Components[j]];
2213 if (!component->Enabled)
2215 component->Action = INSTALLSTATE_ABSENT;
2216 component->ActionRequest = INSTALLSTATE_ABSENT;
2220 if (feature->Action == INSTALLSTATE_LOCAL)
2221 component->Action = INSTALLSTATE_LOCAL;
2222 if (feature->ActionRequest == INSTALLSTATE_LOCAL)
2223 component->ActionRequest = INSTALLSTATE_LOCAL;
2228 for(i = 0; i < package->loaded_components; i++)
2230 MSICOMPONENT* component= &package->components[i];
2232 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2233 debugstr_w(component->Component), component->Installed,
2234 component->Action, component->ActionRequest);
2238 return ERROR_SUCCESS;
2242 * A lot is done in this function aside from just the costing.
2243 * The costing needs to be implemented at some point but for now I am going
2244 * to focus on the directory building
2247 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2249 static const WCHAR ExecSeqQuery[] = {
2250 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2251 'D','i','r','e','c','t','o','r','y',0};
2252 static const WCHAR ConditionQuery[] = {
2253 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2254 'C','o','n','d','i','t','i','o','n',0};
2255 static const WCHAR szCosting[] = {
2256 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2257 static const WCHAR szlevel[] = {
2258 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2259 static const WCHAR szOne[] = { '1', 0 };
2265 TRACE("Building Directory properties\n");
2267 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2268 if (rc == ERROR_SUCCESS)
2270 rc = MSI_ViewExecute(view, 0);
2271 if (rc != ERROR_SUCCESS)
2273 MSI_ViewClose(view);
2274 msiobj_release(&view->hdr);
2282 MSIRECORD * row = 0;
2285 rc = MSI_ViewFetch(view,&row);
2286 if (rc != ERROR_SUCCESS)
2293 MSI_RecordGetStringW(row,1,name,&sz);
2295 /* This helper function now does ALL the work */
2296 TRACE("Dir %s ...\n",debugstr_w(name));
2297 load_folder(package,name);
2298 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2299 TRACE("resolves to %s\n",debugstr_w(path));
2300 HeapFree( GetProcessHeap(), 0, path);
2302 msiobj_release(&row->hdr);
2304 MSI_ViewClose(view);
2305 msiobj_release(&view->hdr);
2308 TRACE("File calculations %i files\n",package->loaded_files);
2310 for (i = 0; i < package->loaded_files; i++)
2312 MSICOMPONENT* comp = NULL;
2313 MSIFILE* file= NULL;
2315 file = &package->files[i];
2316 if (file->ComponentIndex >= 0)
2317 comp = &package->components[file->ComponentIndex];
2319 if (file->Temporary == TRUE)
2326 /* calculate target */
2327 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2329 HeapFree(GetProcessHeap(),0,file->TargetPath);
2331 TRACE("file %s is named %s\n",
2332 debugstr_w(file->File),debugstr_w(file->FileName));
2334 file->TargetPath = build_directory_name(2, p, file->FileName);
2336 HeapFree(GetProcessHeap(),0,p);
2338 TRACE("file %s resolves to %s\n",
2339 debugstr_w(file->File),debugstr_w(file->TargetPath));
2341 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2344 comp->Cost += file->FileSize;
2354 static const WCHAR name[] =
2356 static const WCHAR name_fmt[] =
2357 {'%','u','.','%','u','.','%','u','.','%','u',0};
2358 WCHAR filever[0x100];
2359 VS_FIXEDFILEINFO *lpVer;
2361 TRACE("Version comparison.. \n");
2362 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2363 version = HeapAlloc(GetProcessHeap(),0,versize);
2364 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2366 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2368 sprintfW(filever,name_fmt,
2369 HIWORD(lpVer->dwFileVersionMS),
2370 LOWORD(lpVer->dwFileVersionMS),
2371 HIWORD(lpVer->dwFileVersionLS),
2372 LOWORD(lpVer->dwFileVersionLS));
2374 TRACE("new %s old %s\n", debugstr_w(file->Version),
2375 debugstr_w(filever));
2376 if (strcmpiW(filever,file->Version)<0)
2379 FIXME("cost should be diff in size\n");
2380 comp->Cost += file->FileSize;
2384 HeapFree(GetProcessHeap(),0,version);
2392 TRACE("Evaluating Condition Table\n");
2394 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2395 if (rc == ERROR_SUCCESS)
2397 rc = MSI_ViewExecute(view, 0);
2398 if (rc != ERROR_SUCCESS)
2400 MSI_ViewClose(view);
2401 msiobj_release(&view->hdr);
2407 WCHAR Feature[0x100];
2408 MSIRECORD * row = 0;
2412 rc = MSI_ViewFetch(view,&row);
2414 if (rc != ERROR_SUCCESS)
2421 MSI_RecordGetStringW(row,1,Feature,&sz);
2423 feature_index = get_loaded_feature(package,Feature);
2424 if (feature_index < 0)
2425 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2429 Condition = load_dynamic_stringW(row,3);
2431 if (MSI_EvaluateConditionW(package,Condition) ==
2434 int level = MSI_RecordGetInteger(row,2);
2435 TRACE("Reseting feature %s to level %i\n",
2436 debugstr_w(Feature), level);
2437 package->features[feature_index].Level = level;
2439 HeapFree(GetProcessHeap(),0,Condition);
2442 msiobj_release(&row->hdr);
2444 MSI_ViewClose(view);
2445 msiobj_release(&view->hdr);
2448 TRACE("Enabling or Disabling Components\n");
2449 for (i = 0; i < package->loaded_components; i++)
2451 if (package->components[i].Condition[0])
2453 if (MSI_EvaluateConditionW(package,
2454 package->components[i].Condition) == MSICONDITION_FALSE)
2456 TRACE("Disabling component %s\n",
2457 debugstr_w(package->components[i].Component));
2458 package->components[i].Enabled = FALSE;
2463 MSI_SetPropertyW(package,szCosting,szOne);
2464 /* set default run level if not set */
2465 level = load_dynamic_property(package,szlevel,NULL);
2467 MSI_SetPropertyW(package,szlevel, szOne);
2469 HeapFree(GetProcessHeap(),0,level);
2471 return SetFeatureStates(package);
2476 * This is a helper function for handling embedded cabinet media
2478 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2486 WCHAR tmp[MAX_PATH];
2488 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2489 if (rc != ERROR_SUCCESS)
2493 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2494 GetTempPathW(MAX_PATH,tmp);
2496 GetTempFileNameW(tmp,stream_name,0,source);
2498 track_tempfile(package,strrchrW(source,'\\'), source);
2499 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2500 FILE_ATTRIBUTE_NORMAL, NULL);
2502 if (the_file == INVALID_HANDLE_VALUE)
2504 rc = ERROR_FUNCTION_FAILED;
2508 WriteFile(the_file,data,size,&write,NULL);
2509 CloseHandle(the_file);
2510 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2512 HeapFree(GetProcessHeap(),0,data);
2517 /* Support functions for FDI functions */
2520 MSIPACKAGE* package;
2525 static void * cabinet_alloc(ULONG cb)
2527 return HeapAlloc(GetProcessHeap(), 0, cb);
2530 static void cabinet_free(void *pv)
2532 HeapFree(GetProcessHeap(), 0, pv);
2535 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2538 DWORD dwShareMode = 0;
2539 DWORD dwCreateDisposition = OPEN_EXISTING;
2540 switch (oflag & _O_ACCMODE)
2543 dwAccess = GENERIC_READ;
2544 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2547 dwAccess = GENERIC_WRITE;
2548 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2551 dwAccess = GENERIC_READ | GENERIC_WRITE;
2552 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2555 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2556 dwCreateDisposition = CREATE_NEW;
2557 else if (oflag & _O_CREAT)
2558 dwCreateDisposition = CREATE_ALWAYS;
2559 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2562 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2565 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2570 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2573 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2578 static int cabinet_close(INT_PTR hf)
2580 return CloseHandle((HANDLE)hf) ? 0 : -1;
2583 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2585 /* flags are compatible and so are passed straight through */
2586 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2589 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2591 /* FIXME: try to do more processing in this function */
2594 case fdintCOPY_FILE:
2596 CabData *data = (CabData*) pfdin->pv;
2597 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2602 LPWSTR tracknametmp;
2603 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2605 if (data->file_name && strcmp(data->file_name,pfdin->psz1))
2608 file = cabinet_alloc((len+1)*sizeof(char));
2609 strcpy(file, data->cab_path);
2610 strcat(file, pfdin->psz1);
2612 TRACE("file: %s\n", debugstr_a(file));
2614 /* track this file so it can be deleted if not installed */
2615 trackpath=strdupAtoW(file);
2616 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2617 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2618 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2620 strcpyW(trackname,tmpprefix);
2621 strcatW(trackname,tracknametmp);
2623 track_tempfile(data->package, trackname, trackpath);
2625 HeapFree(GetProcessHeap(),0,trackpath);
2626 HeapFree(GetProcessHeap(),0,trackname);
2627 HeapFree(GetProcessHeap(),0,tracknametmp);
2629 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2631 case fdintCLOSE_FILE_INFO:
2635 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2637 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2639 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2642 cabinet_close(pfdin->hf);
2650 /***********************************************************************
2651 * extract_cabinet_file
2653 * Extract files from a cab file.
2655 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2656 const WCHAR* path, const WCHAR* file)
2666 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2667 debugstr_w(file), debugstr_w(path));
2669 hfdi = FDICreate(cabinet_alloc,
2680 ERR("FDICreate failed\n");
2684 if (!(cabinet = strdupWtoA( source )))
2689 if (!(cab_path = strdupWtoA( path )))
2692 HeapFree(GetProcessHeap(), 0, cabinet);
2696 data.package = package;
2697 data.cab_path = cab_path;
2699 file_name = strdupWtoA(file);
2702 data.file_name = file_name;
2704 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
2707 ERR("FDICopy failed\n");
2711 HeapFree(GetProcessHeap(), 0, cabinet);
2712 HeapFree(GetProcessHeap(), 0, cab_path);
2713 HeapFree(GetProcessHeap(), 0, file_name);
2718 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2719 WCHAR* path, WCHAR* file)
2723 MSIRECORD * row = 0;
2724 static WCHAR source[MAX_PATH];
2725 static const WCHAR ExecSeqQuery[] = {
2726 's','e','l','e','c','t',' ','*',' ',
2727 'f','r','o','m',' ','M','e','d','i','a',' ',
2728 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2729 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2734 static UINT last_sequence = 0;
2736 if (sequence <= last_sequence)
2738 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2739 /*extract_a_cabinet_file(package, source,path,file); */
2740 return ERROR_SUCCESS;
2743 sprintfW(Query,ExecSeqQuery,sequence);
2745 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2746 if (rc != ERROR_SUCCESS)
2749 rc = MSI_ViewExecute(view, 0);
2750 if (rc != ERROR_SUCCESS)
2752 MSI_ViewClose(view);
2753 msiobj_release(&view->hdr);
2757 rc = MSI_ViewFetch(view,&row);
2758 if (rc != ERROR_SUCCESS)
2760 MSI_ViewClose(view);
2761 msiobj_release(&view->hdr);
2764 seq = MSI_RecordGetInteger(row,2);
2765 last_sequence = seq;
2767 if (!MSI_RecordIsNull(row,4))
2770 MSI_RecordGetStringW(row,4,cab,&sz);
2771 TRACE("Source is CAB %s\n",debugstr_w(cab));
2772 /* the stream does not contain the # character */
2775 writeout_cabinet_stream(package,&cab[1],source);
2776 strcpyW(path,source);
2777 *(strrchrW(path,'\\')+1)=0;
2782 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2784 ERR("No Source dir defined \n");
2785 rc = ERROR_FUNCTION_FAILED;
2789 strcpyW(path,source);
2790 strcatW(source,cab);
2791 /* extract the cab file into a folder in the temp folder */
2793 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2795 GetTempPathW(MAX_PATH,path);
2798 rc = !extract_a_cabinet_file(package, source,path,NULL);
2800 msiobj_release(&row->hdr);
2801 MSI_ViewClose(view);
2802 msiobj_release(&view->hdr);
2806 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2808 UINT rc = ERROR_SUCCESS;
2810 LPWSTR install_path;
2812 install_path = resolve_folder(package, package->components[component].Directory,
2813 FALSE, FALSE, &folder);
2815 return ERROR_FUNCTION_FAILED;
2817 /* create the path */
2818 if (folder->State == 0)
2820 create_full_pathW(install_path);
2823 HeapFree(GetProcessHeap(), 0, install_path);
2828 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
2830 UINT rc = ERROR_SUCCESS;
2833 WCHAR uipath[MAX_PATH];
2836 return ERROR_INVALID_HANDLE;
2838 /* increment progress bar each time action data is sent */
2839 ui_progress(package,1,1,0,0);
2841 for (index = 0; index < package->loaded_files; index++)
2843 WCHAR path_to_source[MAX_PATH];
2846 file = &package->files[index];
2848 if (file->Temporary)
2851 if (package->components[file->ComponentIndex].ActionRequest !=
2854 ui_progress(package,2,file->FileSize,0,0);
2855 TRACE("File %s is not scheduled for install\n",
2856 debugstr_w(file->File));
2861 if ((file->State == 1) || (file->State == 2))
2865 MSICOMPONENT* comp = NULL;
2867 TRACE("Installing %s\n",debugstr_w(file->File));
2868 rc = ready_media_for_file(package,file->Sequence,path_to_source,
2872 * our file table could change here because a new temp file
2873 * may have been created
2875 file = &package->files[index];
2876 if (rc != ERROR_SUCCESS)
2878 ERR("Unable to ready media\n");
2879 rc = ERROR_FUNCTION_FAILED;
2883 create_component_directory( package, file->ComponentIndex);
2885 /* recalculate file paths because things may have changed */
2887 if (file->ComponentIndex >= 0)
2888 comp = &package->components[file->ComponentIndex];
2890 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2891 HeapFree(GetProcessHeap(),0,file->TargetPath);
2893 file->TargetPath = build_directory_name(2, p, file->FileName);
2895 len = strlenW(path_to_source) + strlenW(file->File) + 2;
2896 file->SourcePath = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
2897 strcpyW(file->SourcePath, path_to_source);
2898 strcatW(file->SourcePath, file->File);
2900 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
2901 debugstr_w(file->TargetPath));
2904 uirow=MSI_CreateRecord(9);
2905 MSI_RecordSetStringW(uirow,1,file->File);
2906 strcpyW(uipath,file->TargetPath);
2907 *(strrchrW(uipath,'\\')+1)=0;
2908 MSI_RecordSetStringW(uirow,9,uipath);
2909 MSI_RecordSetInteger(uirow,6,file->FileSize);
2910 ui_actiondata(package,szInstallFiles,uirow);
2911 msiobj_release( &uirow->hdr );
2912 ui_progress(package,2,file->FileSize,0,0);
2914 if (!MoveFileW(file->SourcePath,file->TargetPath))
2916 rc = GetLastError();
2917 ERR("Unable to move file (%s -> %s) (error %d)\n",
2918 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
2920 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
2922 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
2923 DeleteFileW(file->SourcePath);
2926 else if (rc == ERROR_FILE_NOT_FOUND)
2928 ERR("Source File Not Found! Continueing\n");
2933 ERR("Ignoring Error and continuing...\n");
2945 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
2946 LPWSTR* file_source)
2951 return ERROR_INVALID_HANDLE;
2953 for (index = 0; index < package->loaded_files; index ++)
2955 if (strcmpW(file_key,package->files[index].File)==0)
2957 if (package->files[index].State >= 2)
2959 *file_source = dupstrW(package->files[index].TargetPath);
2960 return ERROR_SUCCESS;
2963 return ERROR_FILE_NOT_FOUND;
2967 return ERROR_FUNCTION_FAILED;
2970 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
2974 MSIRECORD * row = 0;
2975 static const WCHAR ExecSeqQuery[] = {
2976 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2977 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2980 return ERROR_INVALID_HANDLE;
2982 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2983 if (rc != ERROR_SUCCESS)
2984 return ERROR_SUCCESS;
2986 rc = MSI_ViewExecute(view, 0);
2987 if (rc != ERROR_SUCCESS)
2989 MSI_ViewClose(view);
2990 msiobj_release(&view->hdr);
2996 WCHAR file_key[0x100];
2997 WCHAR *file_source = NULL;
2998 WCHAR dest_name[0x100];
2999 LPWSTR dest_path, dest;
3000 WCHAR component[0x100];
3001 INT component_index;
3005 rc = MSI_ViewFetch(view,&row);
3006 if (rc != ERROR_SUCCESS)
3013 rc = MSI_RecordGetStringW(row,2,component,&sz);
3014 if (rc != ERROR_SUCCESS)
3016 ERR("Unable to get component\n");
3017 msiobj_release(&row->hdr);
3021 component_index = get_loaded_component(package,component);
3022 if (package->components[component_index].ActionRequest !=
3025 TRACE("Skipping copy due to disabled component\n");
3027 /* the action taken was the same as the current install state */
3028 package->components[component_index].Action =
3029 package->components[component_index].Installed;
3031 msiobj_release(&row->hdr);
3035 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3036 package->components[component_index].Installed = INSTALLSTATE_LOCAL;
3039 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3040 if (rc != ERROR_SUCCESS)
3042 ERR("Unable to get file key\n");
3043 msiobj_release(&row->hdr);
3047 rc = get_file_target(package,file_key,&file_source);
3049 if (rc != ERROR_SUCCESS)
3051 ERR("Original file unknown %s\n",debugstr_w(file_key));
3052 msiobj_release(&row->hdr);
3053 HeapFree(GetProcessHeap(),0,file_source);
3057 if (MSI_RecordIsNull(row,4))
3059 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3064 MSI_RecordGetStringW(row,4,dest_name,&sz);
3065 reduce_to_longfilename(dest_name);
3068 if (MSI_RecordIsNull(row,5))
3071 dest_path = dupstrW(file_source);
3072 p = strrchrW(dest_path,'\\');
3078 WCHAR destkey[0x100];
3080 MSI_RecordGetStringW(row,5,destkey,&sz);
3082 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3085 ERR("Unable to get destination folder\n");
3086 msiobj_release(&row->hdr);
3087 HeapFree(GetProcessHeap(),0,file_source);
3092 dest = build_directory_name(2, dest_path, dest_name);
3093 HeapFree(GetProcessHeap(), 0, dest_path);
3095 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3098 if (strcmpW(file_source,dest))
3099 rc = !CopyFileW(file_source,dest,TRUE);
3103 if (rc != ERROR_SUCCESS)
3104 ERR("Failed to copy file\n");
3106 FIXME("We should track these duplicate files as well\n");
3108 msiobj_release(&row->hdr);
3109 HeapFree(GetProcessHeap(),0,dest);
3110 HeapFree(GetProcessHeap(),0,file_source);
3112 MSI_ViewClose(view);
3113 msiobj_release(&view->hdr);
3118 /* OK this value is "interpreted" and then formatted based on the
3119 first few characters */
3120 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3124 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3133 deformat_string(package, &value[2], &deformated);
3135 /* binary value type */
3138 *size = strlenW(ptr)/2;
3139 data = HeapAlloc(GetProcessHeap(),0,*size);
3151 data[count] = (BYTE)strtol(byte,NULL,0);
3154 HeapFree(GetProcessHeap(),0,deformated);
3156 TRACE("Data %li bytes(%i)\n",*size,count);
3161 deformat_string(package, &value[1], &deformated);
3164 *size = sizeof(DWORD);
3165 data = HeapAlloc(GetProcessHeap(),0,*size);
3166 *(LPDWORD)data = atoiW(deformated);
3167 TRACE("DWORD %i\n",*data);
3169 HeapFree(GetProcessHeap(),0,deformated);
3174 static const WCHAR szMulti[] = {'[','~',']',0};
3183 *type=REG_EXPAND_SZ;
3191 if (strstrW(value,szMulti))
3192 *type = REG_MULTI_SZ;
3194 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3199 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3203 MSIRECORD * row = 0;
3204 static const WCHAR ExecSeqQuery[] = {
3205 's','e','l','e','c','t',' ','*',' ',
3206 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
3209 return ERROR_INVALID_HANDLE;
3211 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3212 if (rc != ERROR_SUCCESS)
3213 return ERROR_SUCCESS;
3215 rc = MSI_ViewExecute(view, 0);
3216 if (rc != ERROR_SUCCESS)
3218 MSI_ViewClose(view);
3219 msiobj_release(&view->hdr);
3223 /* increment progress bar each time action data is sent */
3224 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3228 static const WCHAR szHCR[] =
3229 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
3230 static const WCHAR szHCU[] =
3231 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
3232 static const WCHAR szHLM[] =
3233 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
3235 static const WCHAR szHU[] =
3236 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3238 LPSTR value_data = NULL;
3239 HKEY root_key, hkey;
3241 LPWSTR value, key, name, component, deformated;
3243 INT component_index;
3248 rc = MSI_ViewFetch(view,&row);
3249 if (rc != ERROR_SUCCESS)
3254 ui_progress(package,2,0,0,0);
3261 component = load_dynamic_stringW(row, 6);
3262 component_index = get_loaded_component(package,component);
3264 if (package->components[component_index].ActionRequest !=
3267 TRACE("Skipping write due to disabled component\n");
3268 msiobj_release(&row->hdr);
3270 package->components[component_index].Action =
3271 package->components[component_index].Installed;
3276 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3277 package->components[component_index].Installed = INSTALLSTATE_LOCAL;
3279 /* null values have special meanings during uninstalls and such */
3281 if(MSI_RecordIsNull(row,5))
3283 msiobj_release(&row->hdr);
3287 root = MSI_RecordGetInteger(row,2);
3288 key = load_dynamic_stringW(row, 3);
3290 name = load_dynamic_stringW(row, 4);
3292 /* get the root key */
3295 case 0: root_key = HKEY_CLASSES_ROOT;
3298 case 1: root_key = HKEY_CURRENT_USER;
3301 case 2: root_key = HKEY_LOCAL_MACHINE;
3304 case 3: root_key = HKEY_USERS;
3308 ERR("Unknown root %i\n",root);
3315 msiobj_release(&row->hdr);
3319 deformat_string(package, key , &deformated);
3320 size = strlenW(deformated) + strlenW(szRoot) + 1;
3321 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3322 strcpyW(uikey,szRoot);
3323 strcatW(uikey,deformated);
3325 if (RegCreateKeyW( root_key, deformated, &hkey))
3327 ERR("Could not create key %s\n",debugstr_w(deformated));
3328 msiobj_release(&row->hdr);
3329 HeapFree(GetProcessHeap(),0,deformated);
3332 HeapFree(GetProcessHeap(),0,deformated);
3334 value = load_dynamic_stringW(row,5);
3335 value_data = parse_value(package, value, &type, &size);
3337 deformat_string(package, name, &deformated);
3341 TRACE("Setting value %s\n",debugstr_w(deformated));
3342 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3344 uirow = MSI_CreateRecord(3);
3345 MSI_RecordSetStringW(uirow,2,deformated);
3346 MSI_RecordSetStringW(uirow,1,uikey);
3349 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3351 MSI_RecordSetStringW(uirow,3,value);
3353 ui_actiondata(package,szWriteRegistryValues,uirow);
3354 msiobj_release( &uirow->hdr );
3356 HeapFree(GetProcessHeap(),0,value_data);
3358 HeapFree(GetProcessHeap(),0,value);
3359 HeapFree(GetProcessHeap(),0,deformated);
3361 msiobj_release(&row->hdr);
3364 HeapFree(GetProcessHeap(),0,uikey);
3365 HeapFree(GetProcessHeap(),0,key);
3366 HeapFree(GetProcessHeap(),0,name);
3367 HeapFree(GetProcessHeap(),0,component);
3369 MSI_ViewClose(view);
3370 msiobj_release(&view->hdr);
3374 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3376 return ERROR_SUCCESS;
3380 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3384 static const WCHAR q1[]={
3385 'S','E','L','E','C','T',' ','*',' ',
3386 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3389 MSIRECORD * row = 0;
3392 TRACE(" InstallValidate \n");
3394 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3395 if (rc != ERROR_SUCCESS)
3396 return ERROR_SUCCESS;
3398 rc = MSI_ViewExecute(view, 0);
3399 if (rc != ERROR_SUCCESS)
3401 MSI_ViewClose(view);
3402 msiobj_release(&view->hdr);
3407 rc = MSI_ViewFetch(view,&row);
3408 if (rc != ERROR_SUCCESS)
3415 msiobj_release(&row->hdr);
3417 MSI_ViewClose(view);
3418 msiobj_release(&view->hdr);
3420 total = total + progress * REG_PROGRESS_VALUE;
3421 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3422 for (i=0; i < package->loaded_files; i++)
3423 total += package->files[i].FileSize;
3424 ui_progress(package,0,total,0,0);
3426 return ERROR_SUCCESS;
3429 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3432 MSIQUERY * view = NULL;
3433 MSIRECORD * row = 0;
3434 static const WCHAR ExecSeqQuery[] = {
3435 'S','E','L','E','C','T',' ','*',' ',
3436 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3437 static const WCHAR title[]=
3438 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3440 TRACE("Checking launch conditions\n");
3442 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3443 if (rc != ERROR_SUCCESS)
3444 return ERROR_SUCCESS;
3446 rc = MSI_ViewExecute(view, 0);
3447 if (rc != ERROR_SUCCESS)
3449 MSI_ViewClose(view);
3450 msiobj_release(&view->hdr);
3455 while (rc == ERROR_SUCCESS)
3458 LPWSTR message = NULL;
3460 rc = MSI_ViewFetch(view,&row);
3461 if (rc != ERROR_SUCCESS)
3467 cond = load_dynamic_stringW(row,1);
3469 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3472 message = load_dynamic_stringW(row,2);
3473 deformat_string(package,message,&deformated);
3474 MessageBoxW(NULL,deformated,title,MB_OK);
3475 HeapFree(GetProcessHeap(),0,message);
3476 HeapFree(GetProcessHeap(),0,deformated);
3477 rc = ERROR_FUNCTION_FAILED;
3479 HeapFree(GetProcessHeap(),0,cond);
3480 msiobj_release(&row->hdr);
3482 MSI_ViewClose(view);
3483 msiobj_release(&view->hdr);
3487 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3490 MSICOMPONENT* cmp = &package->components[component_index];
3492 if (cmp->KeyPath[0]==0)
3494 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3497 if (cmp->Attributes & 0x4)
3500 MSIRECORD * row = 0;
3502 LPWSTR key,deformated,buffer,name,deformated_name;
3503 static const WCHAR ExecSeqQuery[] = {
3504 's','e','l','e','c','t',' ','*',' ',
3505 'f','r','o','m',' ','R','e','g','i','s','t','r','y',' ',
3506 'w','h','e','r','e',' ','R','e','g','i','s','t','r','y',' ','=',' '
3507 ,'`','%','s','`',0 };
3508 static const WCHAR fmt[]={'%','0','2','i',':','%','s',0};
3509 static const WCHAR fmt2[]={'%','0','2','i',':','%','s','\\','%','s',0};
3511 rc = MSI_OpenQuery(package->db,&view,ExecSeqQuery,cmp->KeyPath);
3513 if (rc!=ERROR_SUCCESS)
3516 rc = MSI_ViewExecute(view, 0);
3517 if (rc != ERROR_SUCCESS)
3519 MSI_ViewClose(view);
3520 msiobj_release(&view->hdr);
3524 rc = MSI_ViewFetch(view,&row);
3525 if (rc != ERROR_SUCCESS)
3527 MSI_ViewClose(view);
3528 msiobj_release(&view->hdr);
3532 root = MSI_RecordGetInteger(row,2);
3533 key = load_dynamic_stringW(row, 3);
3534 name = load_dynamic_stringW(row, 4);
3535 deformat_string(package, key , &deformated);
3536 deformat_string(package, name, &deformated_name);
3538 len = strlenW(deformated) + 5;
3539 if (deformated_name)
3540 len+=strlenW(deformated_name);
3542 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3544 if (deformated_name)
3545 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3547 sprintfW(buffer,fmt,root,deformated);
3549 HeapFree(GetProcessHeap(),0,key);
3550 HeapFree(GetProcessHeap(),0,deformated);
3551 HeapFree(GetProcessHeap(),0,name);
3552 HeapFree(GetProcessHeap(),0,deformated_name);
3553 msiobj_release(&row->hdr);
3554 MSI_ViewClose(view);
3555 msiobj_release(&view->hdr);
3559 else if (cmp->Attributes & 0x20)
3561 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3567 j = get_loaded_file(package,cmp->KeyPath);
3571 LPWSTR p = dupstrW(package->files[j].TargetPath);
3579 * Ok further analysis makes me think that this work is
3580 * actually done in the PublishComponents and PublishFeatures
3581 * step, and not here. It appears like the keypath and all that is
3582 * resolved in this step, however actually written in the Publish steps.
3583 * But we will leave it here for now because it is unclear
3585 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3588 WCHAR squished_pc[GUID_SIZE];
3589 WCHAR squished_cc[GUID_SIZE];
3592 HKEY hkey=0,hkey2=0;
3593 static const WCHAR szProductCode[]=
3594 {'P','r','o','d','u','c','t','C','o','d','e',0};
3597 return ERROR_INVALID_HANDLE;
3599 /* writes the Component and Features values to the registry */
3600 productcode = load_dynamic_property(package,szProductCode,&rc);
3604 rc = MSIREG_OpenComponents(&hkey);
3605 if (rc != ERROR_SUCCESS)
3608 squash_guid(productcode,squished_pc);
3609 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
3610 for (i = 0; i < package->loaded_components; i++)
3612 ui_progress(package,2,0,0,0);
3613 if (package->components[i].ComponentId[0]!=0)
3615 WCHAR *keypath = NULL;
3618 squash_guid(package->components[i].ComponentId,squished_cc);
3619 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
3620 if (rc != ERROR_SUCCESS)
3623 keypath = resolve_keypath(package,i);
3626 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
3627 (strlenW(keypath)+1)*sizeof(WCHAR));
3631 uirow = MSI_CreateRecord(3);
3632 MSI_RecordSetStringW(uirow,1,productcode);
3633 MSI_RecordSetStringW(uirow,2,package->components[i].
3635 MSI_RecordSetStringW(uirow,3,keypath);
3636 ui_actiondata(package,szProcessComponents,uirow);
3637 msiobj_release( &uirow->hdr );
3638 HeapFree(GetProcessHeap(),0,keypath);
3643 HeapFree(GetProcessHeap(), 0, productcode);
3648 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
3651 * OK this is a bit confusing.. I am given a _Component key and I believe
3652 * that the file that is being registered as a type library is the "key file
3653 * of that component" which I interpret to mean "The file in the KeyPath of
3658 MSIRECORD * row = 0;
3659 static const WCHAR Query[] = {
3660 'S','E','L','E','C','T',' ','*',' ',
3661 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3666 return ERROR_INVALID_HANDLE;
3668 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3669 if (rc != ERROR_SUCCESS)
3670 return ERROR_SUCCESS;
3672 rc = MSI_ViewExecute(view, 0);
3673 if (rc != ERROR_SUCCESS)
3675 MSI_ViewClose(view);
3676 msiobj_release(&view->hdr);
3682 WCHAR component[0x100];
3686 rc = MSI_ViewFetch(view,&row);
3687 if (rc != ERROR_SUCCESS)
3694 MSI_RecordGetStringW(row,3,component,&sz);
3696 index = get_loaded_component(package,component);
3699 msiobj_release(&row->hdr);
3703 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
3705 TRACE("Skipping typelib reg due to disabled component\n");
3706 msiobj_release(&row->hdr);
3708 package->components[index].Action =
3709 package->components[index].Installed;
3714 package->components[index].Action = INSTALLSTATE_LOCAL;
3715 package->components[index].Installed = INSTALLSTATE_LOCAL;
3717 index = get_loaded_file(package,package->components[index].KeyPath);
3721 msiobj_release(&row->hdr);
3725 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
3729 WCHAR helpid[0x100];
3732 MSI_RecordGetStringW(row,6,helpid,&sz);
3734 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
3735 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
3736 HeapFree(GetProcessHeap(),0,help);
3738 if (!SUCCEEDED(res))
3739 ERR("Failed to register type library %s\n",
3740 debugstr_w(package->files[index].TargetPath));
3743 /* Yes the row has more fields than I need, but #1 is
3744 correct and the only one I need. Why make a new row? */
3746 ui_actiondata(package,szRegisterTypeLibraries,row);
3748 TRACE("Registered %s\n",
3749 debugstr_w(package->files[index].TargetPath));
3753 ITypeLib_Release(ptLib);
3756 ERR("Failed to load type library %s\n",
3757 debugstr_w(package->files[index].TargetPath));
3759 msiobj_release(&row->hdr);
3761 MSI_ViewClose(view);
3762 msiobj_release(&view->hdr);
3767 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
3769 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3772 MSIRECORD * row = 0;
3773 static const WCHAR ExecSeqQuery[] =
3774 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3775 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3780 return ERROR_INVALID_HANDLE;
3782 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
3783 if (rc != ERROR_SUCCESS)
3786 rc = MSI_ViewExecute(view, 0);
3787 if (rc != ERROR_SUCCESS)
3789 MSI_ViewClose(view);
3790 msiobj_release(&view->hdr);
3794 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
3795 RegCreateKeyW(hkey2,clsid,&hkey3);
3796 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
3797 (strlenW(app)+1)*sizeof(WCHAR));
3799 rc = MSI_ViewFetch(view,&row);
3800 if (rc != ERROR_SUCCESS)
3802 MSI_ViewClose(view);
3803 msiobj_release(&view->hdr);
3807 if (!MSI_RecordIsNull(row,2))
3809 LPWSTR deformated=0;
3811 static const WCHAR szRemoteServerName[] =
3812 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3813 buffer = load_dynamic_stringW(row,2);
3814 size = deformat_string(package,buffer,&deformated);
3815 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
3817 HeapFree(GetProcessHeap(),0,deformated);
3818 HeapFree(GetProcessHeap(),0,buffer);
3821 if (!MSI_RecordIsNull(row,3))
3823 static const WCHAR szLocalService[] =
3824 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3826 buffer = load_dynamic_stringW(row,3);
3827 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3828 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
3829 HeapFree(GetProcessHeap(),0,buffer);
3832 if (!MSI_RecordIsNull(row,4))
3834 static const WCHAR szService[] =
3835 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3837 buffer = load_dynamic_stringW(row,4);
3838 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3839 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
3840 HeapFree(GetProcessHeap(),0,buffer);
3843 if (!MSI_RecordIsNull(row,5))
3845 static const WCHAR szDLL[] =
3846 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3848 buffer = load_dynamic_stringW(row,5);
3849 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3850 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
3851 HeapFree(GetProcessHeap(),0,buffer);
3854 if (!MSI_RecordIsNull(row,6))
3856 static const WCHAR szActivate[] =
3857 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3858 static const WCHAR szY[] = {'Y',0};
3860 if (MSI_RecordGetInteger(row,6))
3861 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
3864 if (!MSI_RecordIsNull(row,7))
3866 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
3867 static const WCHAR szUser[] =
3868 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3870 if (MSI_RecordGetInteger(row,7))
3871 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
3874 msiobj_release(&row->hdr);
3875 MSI_ViewClose(view);
3876 msiobj_release(&view->hdr);
3882 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
3885 * Again I am assuming the words, "Whose key file represents" when referring
3886 * to a Component as to meaning that Components KeyPath file
3888 * Also there is a very strong connection between ClassInfo and ProgID
3889 * that I am mostly glossing over.
3890 * What would be more propper is to load the ClassInfo and the ProgID info
3891 * into memory data structures and then be able to enable and disable them
3892 * based on component.
3897 MSIRECORD * row = 0;
3898 static const WCHAR ExecSeqQuery[] = {
3899 'S','E','L','E','C','T',' ','*',' ',
3900 'f','r','o','m',' ','C','l','a','s','s',0};
3901 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3902 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
3903 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3904 static const WCHAR szSpace[] = {' ',0};
3905 HKEY hkey,hkey2,hkey3;
3906 LPWSTR argument,deformated;
3909 return ERROR_INVALID_HANDLE;
3911 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
3912 if (rc != ERROR_SUCCESS)
3913 return ERROR_FUNCTION_FAILED;
3915 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3916 if (rc != ERROR_SUCCESS)
3922 rc = MSI_ViewExecute(view, 0);
3923 if (rc != ERROR_SUCCESS)
3925 MSI_ViewClose(view);
3926 msiobj_release(&view->hdr);
3933 WCHAR buffer[0x100];
3939 rc = MSI_ViewFetch(view,&row);
3940 if (rc != ERROR_SUCCESS)
3947 MSI_RecordGetStringW(row,3,buffer,&sz);
3949 index = get_loaded_component(package,buffer);
3953 msiobj_release(&row->hdr);
3957 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
3959 TRACE("Skipping class reg due to disabled component\n");
3960 msiobj_release(&row->hdr);
3962 package->components[index].Action =
3963 package->components[index].Installed;
3968 package->components[index].Action = INSTALLSTATE_LOCAL;
3969 package->components[index].Installed = INSTALLSTATE_LOCAL;
3972 MSI_RecordGetStringW(row,1,clsid,&sz);
3973 RegCreateKeyW(hkey,clsid,&hkey2);
3975 if (!MSI_RecordIsNull(row,5))
3978 MSI_RecordGetStringW(row,5,desc,&sz);
3980 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
3981 (strlenW(desc)+1)*sizeof(WCHAR));
3987 MSI_RecordGetStringW(row,2,buffer,&sz);
3989 RegCreateKeyW(hkey2,buffer,&hkey3);
3991 index = get_loaded_file(package,package->components[index].KeyPath);
3993 argument = load_dynamic_stringW(row,11);
3994 size = deformat_string(package,argument,&deformated);
3996 size+=sizeof(WCHAR);
3997 HeapFree(GetProcessHeap(),0,argument);
3998 size += (strlenW(package->files[index].TargetPath))*sizeof(WCHAR);
4000 argument = (LPWSTR)HeapAlloc(GetProcessHeap(),0,size+sizeof(WCHAR));
4001 strcpyW(argument,package->files[index].TargetPath);
4004 strcatW(argument,szSpace);
4005 strcatW(argument,deformated);
4008 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4009 HeapFree(GetProcessHeap(),0,deformated);
4010 HeapFree(GetProcessHeap(),0,argument);
4014 if (!MSI_RecordIsNull(row,4))
4017 MSI_RecordGetStringW(row,4,buffer,&sz);
4019 RegCreateKeyW(hkey2,szProgID,&hkey3);
4021 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4022 (strlenW(buffer)+1)*sizeof(WCHAR));
4027 if (!MSI_RecordIsNull(row,6))
4030 MSI_RecordGetStringW(row,6,buffer,&sz);
4032 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4033 (strlenW(buffer)+1)*sizeof(WCHAR));
4035 register_appid(package,buffer,desc);
4039 if (!MSI_RecordIsNull(row,7))
4041 FIXME("Process field 7\n");
4044 if (!MSI_RecordIsNull(row,8))
4046 static const WCHAR szDefaultIcon[] =
4047 {'D','e','f','a','u','l','t','I','c','o','n',0};
4049 LPWSTR FileName = load_dynamic_stringW(row,8);
4053 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
4054 build_icon_path(package,FileName,&FilePath);
4055 if (!MSI_RecordIsNull(row,9))
4057 static const WCHAR index_fmt[] = {',','%','i',0};
4058 WCHAR index_buf[20];
4059 index = MSI_RecordGetInteger(row,9);
4060 sprintfW(index_buf,index_fmt,index);
4061 size = strlenW(FilePath)+strlenW(index_buf)+1;
4062 size *= sizeof(WCHAR);
4063 HeapReAlloc(GetProcessHeap(),0,FilePath,size);
4065 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)FilePath,
4066 (strlenW(FilePath)+1) * sizeof(WCHAR));
4067 HeapFree(GetProcessHeap(),0,FilePath);
4068 HeapFree(GetProcessHeap(),0,FileName);
4072 if (!MSI_RecordIsNull(row,10))
4074 static const WCHAR szInproc32[] = {
4075 'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',0};
4076 static const WCHAR szInproc[] = {
4077 'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
4078 INT i = MSI_RecordGetInteger(row,10);
4079 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4081 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4082 static const WCHAR ole32[] = {
4083 'o','l','e','3','2','.','d','l','l',0};
4087 size = strlenW(ole2) * sizeof(WCHAR);
4088 RegCreateKeyW(hkey2,szInproc,&hkey3);
4089 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4093 size = strlenW(ole32) * sizeof(WCHAR);
4094 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4095 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4099 size = strlenW(ole2) * sizeof(WCHAR);
4100 RegCreateKeyW(hkey2,szInproc,&hkey3);
4101 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4103 size = strlenW(ole32) * sizeof(WCHAR);
4104 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4105 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4113 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4114 argument = load_dynamic_stringW(row,10);
4115 reduce_to_longfilename(argument);
4116 size = strlenW(argument)*sizeof(WCHAR);
4118 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4119 HeapFree(GetProcessHeap(),0,argument);
4127 ui_actiondata(package,szRegisterClassInfo,row);
4129 msiobj_release(&row->hdr);
4131 MSI_ViewClose(view);
4132 msiobj_release(&view->hdr);
4139 static UINT register_progid_base(MSIPACKAGE* package, MSIRECORD * row,
4142 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4143 static const WCHAR szDefaultIcon[] = {
4144 'D','e','f','a','u','l','t','I','c','o','n',0};
4146 WCHAR buffer[0x100];
4151 MSI_RecordGetStringW(row,1,buffer,&sz);
4152 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4154 if (!MSI_RecordIsNull(row,4))
4157 MSI_RecordGetStringW(row,4,buffer,&sz);
4158 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4162 if (!MSI_RecordIsNull(row,3))
4166 MSI_RecordGetStringW(row,3,buffer,&sz);
4167 RegCreateKeyW(hkey,szCLSID,&hkey2);
4168 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4172 strcpyW(clsid,buffer);
4178 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4179 return ERROR_FUNCTION_FAILED;
4181 if (!MSI_RecordIsNull(row,5))
4183 INT index = MSI_RecordGetInteger(row,6);
4184 LPWSTR FileName = load_dynamic_stringW(row,5);
4185 LPWSTR FilePath,IconPath;
4186 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4188 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4189 build_icon_path(package,FileName,&FilePath);
4191 IconPath = HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4194 sprintfW(IconPath,fmt,FilePath,index);
4195 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)IconPath,
4196 (strlenW(IconPath)+1) * sizeof(WCHAR));
4197 HeapFree(GetProcessHeap(),0,FilePath);
4198 HeapFree(GetProcessHeap(),0,FileName);
4201 return ERROR_SUCCESS;
4204 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4206 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4211 MSIRECORD * row = 0;
4212 static const WCHAR Query_t[] =
4213 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
4214 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
4218 return ERROR_INVALID_HANDLE;
4220 rc = MSI_OpenQuery(package->db, &view, Query_t, parent);
4221 if (rc != ERROR_SUCCESS)
4224 rc = MSI_ViewExecute(view, 0);
4225 if (rc != ERROR_SUCCESS)
4227 MSI_ViewClose(view);
4228 msiobj_release(&view->hdr);
4232 rc = MSI_ViewFetch(view,&row);
4233 if (rc != ERROR_SUCCESS)
4235 MSI_ViewClose(view);
4236 msiobj_release(&view->hdr);
4240 register_progid(package,row,clsid);
4242 msiobj_release(&row->hdr);
4243 MSI_ViewClose(view);
4244 msiobj_release(&view->hdr);
4248 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4250 UINT rc = ERROR_SUCCESS;
4252 if (MSI_RecordIsNull(row,2))
4253 rc = register_progid_base(package,row,clsid);
4256 WCHAR buffer[0x1000];
4259 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4260 static const WCHAR szDefaultIcon[] = {
4261 'D','e','f','a','u','l','t','I','c','o','n',0};
4263 /* check if already registered */
4265 MSI_RecordGetStringW(row,1,buffer,&sz);
4266 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4267 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4268 if (disp == REG_OPENED_EXISTING_KEY)
4270 TRACE("Key already registered\n");
4276 MSI_RecordGetStringW(row,2,buffer,&sz);
4277 rc = register_parent_progid(package,buffer,clsid);
4279 /* clsid is same as parent */
4280 RegCreateKeyW(hkey,szCLSID,&hkey2);
4281 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4287 if (!MSI_RecordIsNull(row,4))
4290 MSI_RecordGetStringW(row,4,buffer,&sz);
4291 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4292 (strlenW(buffer)+1) * sizeof(WCHAR));
4295 if (!MSI_RecordIsNull(row,5))
4297 LPWSTR FileName = load_dynamic_stringW(row,5);
4299 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4300 build_icon_path(package,FileName,&FilePath);
4301 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)FilePath,
4302 (strlenW(FilePath)+1) * sizeof(WCHAR));
4303 HeapFree(GetProcessHeap(),0,FilePath);
4304 HeapFree(GetProcessHeap(),0,FileName);
4313 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4316 * Sigh, here I am just brute force registering all progids
4317 * this needs to be linked to the Classes that have been registered
4318 * but the easiest way to do that is to load all these stuff into
4319 * memory for easy checking.
4321 * Gives me something to continue to work toward.
4325 MSIRECORD * row = 0;
4326 static const WCHAR Query[] = {
4327 'S','E','L','E','C','T',' ','*',' ',
4328 'F','R','O','M',' ','P','r','o','g','I','d',0};
4331 return ERROR_INVALID_HANDLE;
4333 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4334 if (rc != ERROR_SUCCESS)
4335 return ERROR_SUCCESS;
4337 rc = MSI_ViewExecute(view, 0);
4338 if (rc != ERROR_SUCCESS)
4340 MSI_ViewClose(view);
4341 msiobj_release(&view->hdr);
4347 WCHAR clsid[0x1000];
4349 rc = MSI_ViewFetch(view,&row);
4350 if (rc != ERROR_SUCCESS)
4356 register_progid(package,row,clsid);
4357 ui_actiondata(package,szRegisterProgIdInfo,row);
4359 msiobj_release(&row->hdr);
4361 MSI_ViewClose(view);
4362 msiobj_release(&view->hdr);
4366 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4370 LPWSTR SystemFolder;
4374 static const WCHAR szInstaller[] =
4375 {'I','n','s','t','a','l','l','e','r','\\',0};
4376 static const WCHAR szProductCode[] =
4377 {'P','r','o','d','u','c','t','C','o','d','e',0};
4378 static const WCHAR szFolder[] =
4379 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4381 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4385 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4387 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4389 create_full_pathW(dest);
4391 *FilePath = build_directory_name(2, dest, icon_name);
4393 HeapFree(GetProcessHeap(),0,SystemFolder);
4394 HeapFree(GetProcessHeap(),0,ProductCode);
4395 HeapFree(GetProcessHeap(),0,dest);
4396 return ERROR_SUCCESS;
4399 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4403 MSIRECORD * row = 0;
4404 static const WCHAR Query[] = {
4405 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4406 'S','h','o','r','t','c','u','t',0};
4412 return ERROR_INVALID_HANDLE;
4414 res = CoInitialize( NULL );
4417 ERR("CoInitialize failed\n");
4418 return ERROR_FUNCTION_FAILED;
4421 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4422 if (rc != ERROR_SUCCESS)
4423 return ERROR_SUCCESS;
4425 rc = MSI_ViewExecute(view, 0);
4426 if (rc != ERROR_SUCCESS)
4428 MSI_ViewClose(view);
4429 msiobj_release(&view->hdr);
4435 LPWSTR target_file, target_folder;
4436 WCHAR buffer[0x100];
4439 static const WCHAR szlnk[]={'.','l','n','k',0};
4441 rc = MSI_ViewFetch(view,&row);
4442 if (rc != ERROR_SUCCESS)
4449 MSI_RecordGetStringW(row,4,buffer,&sz);
4451 index = get_loaded_component(package,buffer);
4455 msiobj_release(&row->hdr);
4459 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4461 TRACE("Skipping shortcut creation due to disabled component\n");
4462 msiobj_release(&row->hdr);
4464 package->components[index].Action =
4465 package->components[index].Installed;
4470 package->components[index].Action = INSTALLSTATE_LOCAL;
4471 package->components[index].Installed = INSTALLSTATE_LOCAL;
4473 ui_actiondata(package,szCreateShortcuts,row);
4475 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4476 &IID_IShellLinkW, (LPVOID *) &sl );
4480 ERR("Is IID_IShellLink\n");
4481 msiobj_release(&row->hdr);
4485 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4488 ERR("Is IID_IPersistFile\n");
4489 msiobj_release(&row->hdr);
4494 MSI_RecordGetStringW(row,2,buffer,&sz);
4495 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4497 /* may be needed because of a bug somehwere else */
4498 create_full_pathW(target_folder);
4501 MSI_RecordGetStringW(row,3,buffer,&sz);
4502 reduce_to_longfilename(buffer);
4503 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4504 strcatW(buffer,szlnk);
4505 target_file = build_directory_name(2, target_folder, buffer);
4506 HeapFree(GetProcessHeap(),0,target_folder);
4509 MSI_RecordGetStringW(row,5,buffer,&sz);
4510 if (strchrW(buffer,'['))
4513 deformat_string(package,buffer,&deformated);
4514 IShellLinkW_SetPath(sl,deformated);
4515 HeapFree(GetProcessHeap(),0,deformated);
4519 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4520 IPersistFile_Release( pf );
4521 IShellLinkW_Release( sl );
4522 msiobj_release(&row->hdr);
4526 if (!MSI_RecordIsNull(row,6))
4530 MSI_RecordGetStringW(row,6,buffer,&sz);
4531 deformat_string(package,buffer,&deformated);
4532 IShellLinkW_SetArguments(sl,deformated);
4533 HeapFree(GetProcessHeap(),0,deformated);
4536 if (!MSI_RecordIsNull(row,7))
4539 deformated = load_dynamic_stringW(row,7);
4540 IShellLinkW_SetDescription(sl,deformated);
4541 HeapFree(GetProcessHeap(),0,deformated);
4544 if (!MSI_RecordIsNull(row,8))
4545 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4547 if (!MSI_RecordIsNull(row,9))
4553 MSI_RecordGetStringW(row,9,buffer,&sz);
4555 build_icon_path(package,buffer,&Path);
4556 index = MSI_RecordGetInteger(row,10);
4558 IShellLinkW_SetIconLocation(sl,Path,index);
4559 HeapFree(GetProcessHeap(),0,Path);
4562 if (!MSI_RecordIsNull(row,11))
4563 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4565 if (!MSI_RecordIsNull(row,12))
4569 MSI_RecordGetStringW(row,12,buffer,&sz);
4570 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
4571 IShellLinkW_SetWorkingDirectory(sl,Path);
4572 HeapFree(GetProcessHeap(), 0, Path);
4575 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4576 IPersistFile_Save(pf,target_file,FALSE);
4578 HeapFree(GetProcessHeap(),0,target_file);
4580 IPersistFile_Release( pf );
4581 IShellLinkW_Release( sl );
4583 msiobj_release(&row->hdr);
4585 MSI_ViewClose(view);
4586 msiobj_release(&view->hdr);
4596 * 99% of the work done here is only done for
4597 * advertised installs. However this is where the
4598 * Icon table is processed and written out
4599 * so that is what I am going to do here.
4601 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4605 MSIRECORD * row = 0;
4606 static const WCHAR Query[]={
4607 'S','E','L','E','C','T',' ','*',' ',
4608 'f','r','o','m',' ','I','c','o','n',0};
4610 /* for registry stuff */
4614 static const WCHAR szProductCode[]=
4615 {'P','r','o','d','u','c','t','C','o','d','e',0};
4616 static const WCHAR szProductName[] = {
4617 'P','r','o','d','u','c','t','N','a','m','e',0};
4618 static const WCHAR szPackageCode[] = {
4619 'P','a','c','k','a','g','e','C','o','d','e',0};
4622 MSIHANDLE hDb, hSumInfo;
4625 return ERROR_INVALID_HANDLE;
4627 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4628 if (rc != ERROR_SUCCESS)
4631 rc = MSI_ViewExecute(view, 0);
4632 if (rc != ERROR_SUCCESS)
4634 MSI_ViewClose(view);
4635 msiobj_release(&view->hdr);
4642 WCHAR *FilePath=NULL;
4643 WCHAR *FileName=NULL;
4646 rc = MSI_ViewFetch(view,&row);
4647 if (rc != ERROR_SUCCESS)
4653 FileName = load_dynamic_stringW(row,1);
4656 ERR("Unable to get FileName\n");
4657 msiobj_release(&row->hdr);
4661 build_icon_path(package,FileName,&FilePath);
4663 HeapFree(GetProcessHeap(),0,FileName);
4665 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4667 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4668 FILE_ATTRIBUTE_NORMAL, NULL);
4670 if (the_file == INVALID_HANDLE_VALUE)
4672 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4673 msiobj_release(&row->hdr);
4674 HeapFree(GetProcessHeap(),0,FilePath);
4682 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4683 if (rc != ERROR_SUCCESS)
4685 ERR("Failed to get stream\n");
4686 CloseHandle(the_file);
4687 DeleteFileW(FilePath);
4690 WriteFile(the_file,buffer,sz,&write,NULL);
4691 } while (sz == 1024);
4693 HeapFree(GetProcessHeap(),0,FilePath);
4695 CloseHandle(the_file);
4696 msiobj_release(&row->hdr);
4698 MSI_ViewClose(view);
4699 msiobj_release(&view->hdr);
4702 /* ok there is a lot more done here but i need to figure out what */
4703 productcode = load_dynamic_property(package,szProductCode,&rc);
4707 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
4708 if (rc != ERROR_SUCCESS)
4711 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
4712 if (rc != ERROR_SUCCESS)
4716 buffer = load_dynamic_property(package,szProductName,NULL);
4717 size = strlenW(buffer)*sizeof(WCHAR);
4718 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
4719 HeapFree(GetProcessHeap(),0,buffer);
4720 FIXME("Need to write more keys to the user registry\n");
4722 hDb= msiobj_findhandle( &package->db->hdr );
4723 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
4724 if (rc == ERROR_SUCCESS)
4726 WCHAR guidbuffer[0x200];
4728 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 8, NULL, NULL, NULL,
4730 if (rc == ERROR_SUCCESS)
4732 WCHAR squashed[GUID_SIZE];
4733 /* for now we only care about the first guid */
4734 LPWSTR ptr = strchrW(guidbuffer,';');
4736 squash_guid(guidbuffer,squashed);
4737 size = strlenW(guidbuffer)*sizeof(WCHAR);
4738 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)guidbuffer,
4744 ERR("Unable to query Revision_Number... \n");
4747 MsiCloseHandle(hSumInfo);
4751 ERR("Unable to open Summary Information\n");
4757 HeapFree(GetProcessHeap(),0,productcode);
4764 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
4768 MSIRECORD * row = 0;
4769 static const WCHAR ExecSeqQuery[] = {'S','e','l','e','c','t',' ','*',
4770 ' ','f','r','o','m',' ','I','n','i','F','i','l','e',0};
4771 static const WCHAR szWindowsFolder[] =
4772 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4774 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4775 if (rc != ERROR_SUCCESS)
4777 TRACE("no IniFile table\n");
4778 return ERROR_SUCCESS;
4781 rc = MSI_ViewExecute(view, 0);
4782 if (rc != ERROR_SUCCESS)
4784 MSI_ViewClose(view);
4785 msiobj_release(&view->hdr);
4791 LPWSTR component,filename,dirproperty,section,key,value,identifier;
4792 LPWSTR deformated_section, deformated_key, deformated_value;
4793 LPWSTR folder, fullname = NULL;
4795 INT component_index,action;
4797 rc = MSI_ViewFetch(view,&row);
4798 if (rc != ERROR_SUCCESS)
4804 component = load_dynamic_stringW(row, 8);
4805 component_index = get_loaded_component(package,component);
4806 HeapFree(GetProcessHeap(),0,component);
4808 if (package->components[component_index].ActionRequest !=
4811 TRACE("Skipping ini file due to disabled component\n");
4812 msiobj_release(&row->hdr);
4814 package->components[component_index].Action =
4815 package->components[component_index].Installed;
4820 package->components[component_index].Action = INSTALLSTATE_LOCAL;
4821 package->components[component_index].Installed = INSTALLSTATE_LOCAL;
4823 identifier = load_dynamic_stringW(row,1);
4824 filename = load_dynamic_stringW(row,2);
4825 dirproperty = load_dynamic_stringW(row,3);
4826 section = load_dynamic_stringW(row,4);
4827 key = load_dynamic_stringW(row,5);
4828 value = load_dynamic_stringW(row,6);
4829 action = MSI_RecordGetInteger(row,7);
4831 deformat_string(package,section,&deformated_section);
4832 deformat_string(package,key,&deformated_key);
4833 deformat_string(package,value,&deformated_value);
4837 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
4839 folder = load_dynamic_property(package,dirproperty,NULL);
4842 folder = load_dynamic_property(package, szWindowsFolder, NULL);
4846 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
4850 fullname = build_directory_name(3, folder, filename, NULL);
4854 TRACE("Adding value %s to section %s in %s\n",
4855 debugstr_w(deformated_key), debugstr_w(deformated_section),
4856 debugstr_w(fullname));
4857 WritePrivateProfileStringW(deformated_section, deformated_key,
4858 deformated_value, fullname);
4860 else if (action == 1)
4863 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
4864 returned, 10, fullname);
4865 if (returned[0] == 0)
4867 TRACE("Adding value %s to section %s in %s\n",
4868 debugstr_w(deformated_key), debugstr_w(deformated_section),
4869 debugstr_w(fullname));
4871 WritePrivateProfileStringW(deformated_section, deformated_key,
4872 deformated_value, fullname);
4875 else if (action == 3)
4877 FIXME("Append to existing section not yet implemented\n");
4880 uirow = MSI_CreateRecord(4);
4881 MSI_RecordSetStringW(uirow,1,identifier);
4882 MSI_RecordSetStringW(uirow,2,deformated_section);
4883 MSI_RecordSetStringW(uirow,3,deformated_key);
4884 MSI_RecordSetStringW(uirow,4,deformated_value);
4885 ui_actiondata(package,szWriteIniValues,uirow);
4886 msiobj_release( &uirow->hdr );
4888 HeapFree(GetProcessHeap(),0,identifier);
4889 HeapFree(GetProcessHeap(),0,fullname);
4890 HeapFree(GetProcessHeap(),0,filename);
4891 HeapFree(GetProcessHeap(),0,key);
4892 HeapFree(GetProcessHeap(),0,value);
4893 HeapFree(GetProcessHeap(),0,section);
4894 HeapFree(GetProcessHeap(),0,dirproperty);
4895 HeapFree(GetProcessHeap(),0,folder);
4896 HeapFree(GetProcessHeap(),0,deformated_key);
4897 HeapFree(GetProcessHeap(),0,deformated_value);
4898 HeapFree(GetProcessHeap(),0,deformated_section);
4899 msiobj_release(&row->hdr);
4901 MSI_ViewClose(view);
4902 msiobj_release(&view->hdr);
4906 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
4910 MSIRECORD * row = 0;
4911 static const WCHAR ExecSeqQuery[] = {'S','e','l','e','c','t',' ','*',' ',
4912 'f','r','o','m',' ','S','e','l','f','R','e','g',0};
4914 static const WCHAR ExeStr[] = {
4915 'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ',0};
4917 PROCESS_INFORMATION info;
4920 memset(&si,0,sizeof(STARTUPINFOW));
4922 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4923 if (rc != ERROR_SUCCESS)
4925 TRACE("no SelfReg table\n");
4926 return ERROR_SUCCESS;
4929 rc = MSI_ViewExecute(view, 0);
4930 if (rc != ERROR_SUCCESS)
4932 MSI_ViewClose(view);
4933 msiobj_release(&view->hdr);
4943 rc = MSI_ViewFetch(view,&row);
4944 if (rc != ERROR_SUCCESS)
4950 filename = load_dynamic_stringW(row,1);
4951 index = get_loaded_file(package,filename);
4955 ERR("Unable to find file id %s\n",debugstr_w(filename));
4956 HeapFree(GetProcessHeap(),0,filename);
4957 msiobj_release(&row->hdr);
4960 HeapFree(GetProcessHeap(),0,filename);
4962 len = strlenW(ExeStr);
4963 len += strlenW(package->files[index].TargetPath);
4966 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
4967 strcpyW(filename,ExeStr);
4968 strcatW(filename,package->files[index].TargetPath);
4970 TRACE("Registering %s\n",debugstr_w(filename));
4971 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
4972 c_collen, &si, &info);
4975 WaitForSingleObject(info.hProcess,INFINITE);
4977 HeapFree(GetProcessHeap(),0,filename);
4978 msiobj_release(&row->hdr);
4980 MSI_ViewClose(view);
4981 msiobj_release(&view->hdr);
4985 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
4992 static const WCHAR szProductCode[]=
4993 {'P','r','o','d','u','c','t','C','o','d','e',0};
4996 return ERROR_INVALID_HANDLE;
4998 productcode = load_dynamic_property(package,szProductCode,&rc);
5002 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
5003 if (rc != ERROR_SUCCESS)
5006 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
5007 if (rc != ERROR_SUCCESS)
5010 /* here the guids are base 85 encoded */
5011 for (i = 0; i < package->loaded_features; i++)
5018 size = package->features[i].ComponentCount*21;
5020 if (package->features[i].Feature_Parent[0])
5021 size += strlenW(package->features[i].Feature_Parent)+2;
5023 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
5026 for (j = 0; j < package->features[i].ComponentCount; j++)
5029 memset(buf,0,sizeof(buf));
5030 TRACE("From %s\n",debugstr_w(package->components
5031 [package->features[i].Components[j]].ComponentId));
5032 CLSIDFromString(package->components
5033 [package->features[i].Components[j]].ComponentId,
5035 encode_base85_guid(&clsid,buf);
5036 TRACE("to %s\n",debugstr_w(buf));
5039 if (package->features[i].Feature_Parent[0])
5041 static const WCHAR sep[] = {'\2',0};
5043 strcatW(data,package->features[i].Feature_Parent);
5046 size = (strlenW(data)+1)*sizeof(WCHAR);
5047 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
5049 HeapFree(GetProcessHeap(),0,data);
5051 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
5052 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
5053 (LPSTR)package->features[i].Feature_Parent,size);
5059 HeapFree(GetProcessHeap(), 0, productcode);
5063 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
5065 static const WCHAR szProductCode[]=
5066 {'P','r','o','d','u','c','t','C','o','d','e',0};
5072 static WCHAR szNONE[] = {0};
5073 static const WCHAR szWindowsInstaler[] =
5074 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
5075 static const WCHAR szPropKeys[][80] =
5077 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
5078 {'A','R','P','C','O','N','T','A','C','T'},
5079 {'A','R','P','C','O','M','M','E','N','T','S',0},
5080 {'P','r','o','d','u','c','t','N','a','m','e',0},
5081 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
5082 {'A','R','P','H','E','L','P','L','I','N','K',0},
5083 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
5084 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
5085 {'S','O','U','R','C','E','D','I','R',0},
5086 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
5087 {'A','R','P','R','E','A','D','M','E',0},
5088 {'A','R','P','S','I','Z','E',0},
5089 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
5090 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
5094 static const WCHAR szRegKeys[][80] =
5096 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
5097 {'C','o','n','t','a','c','t',0},
5098 {'C','o','m','m','e','n','t','s',0},
5099 {'D','i','s','p','l','a','y','N','a','m','e',0},
5100 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
5101 {'H','e','l','p','L','i','n','k',0},
5102 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
5103 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
5104 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
5105 {'P','u','b','l','i','s','h','e','r',0},
5106 {'R','e','a','d','m','e',0},
5107 {'S','i','z','e',0},
5108 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
5109 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
5113 static const WCHAR path[] = {
5114 'C',':','\\','W','i','n','d','o','w','s','\\',
5115 'I','n','s','t','a','l','l','e','r','\\'};
5116 static const WCHAR fmt[] = {
5117 'C',':','\\','W','i','n','d','o','w','s','\\',
5118 'I','n','s','t','a','l','l','e','r','\\',
5119 '%','x','.','m','s','i',0};
5120 static const WCHAR szLocalPackage[]=
5121 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
5122 WCHAR packagefile[MAX_PATH];
5126 return ERROR_INVALID_HANDLE;
5128 productcode = load_dynamic_property(package,szProductCode,&rc);
5132 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
5133 if (rc != ERROR_SUCCESS)
5136 /* dump all the info i can grab */
5137 FIXME("Flesh out more information \n");
5140 while (szPropKeys[i][0]!=0)
5142 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
5143 if (rc != ERROR_SUCCESS)
5145 size = strlenW(buffer)*sizeof(WCHAR);
5146 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
5152 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
5154 /* copy the package locally */
5155 num = GetTickCount() & 0xffff;
5159 sprintfW(packagefile,fmt,num);
5162 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
5163 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
5164 if (handle != INVALID_HANDLE_VALUE)
5166 CloseHandle(handle);
5169 if (GetLastError() != ERROR_FILE_EXISTS &&
5170 GetLastError() != ERROR_SHARING_VIOLATION)
5172 if (!(++num & 0xffff)) num = 1;
5173 sprintfW(packagefile,fmt,num);
5174 } while (num != start);
5176 create_full_pathW(path);
5177 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
5178 CopyFileW(package->PackagePath,packagefile,FALSE);
5179 size = strlenW(packagefile)*sizeof(WCHAR);
5180 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
5183 HeapFree(GetProcessHeap(),0,productcode);
5186 return ERROR_SUCCESS;
5189 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
5193 return ERROR_INVALID_HANDLE;
5195 for (i = 0; i < package->DeferredActionCount; i++)
5198 action = package->DeferredAction[i];
5199 ui_actionstart(package, action);
5200 TRACE("Executing Action (%s)\n",debugstr_w(action));
5201 ACTION_CustomAction(package,action,TRUE);
5202 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
5204 HeapFree(GetProcessHeap(),0,package->DeferredAction);
5206 package->DeferredActionCount = 0;
5207 package->DeferredAction = NULL;
5209 return ERROR_SUCCESS;
5212 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
5216 return ERROR_INVALID_HANDLE;
5218 /* first do the same as an InstallExecute */
5219 ACTION_InstallExecute(package);
5221 /* then handle Commit Actions */
5222 for (i = 0; i < package->CommitActionCount; i++)
5225 action = package->CommitAction[i];
5226 ui_actionstart(package, action);
5227 TRACE("Executing Commit Action (%s)\n",debugstr_w(action));
5228 ACTION_CustomAction(package,action,TRUE);
5229 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
5231 HeapFree(GetProcessHeap(),0,package->CommitAction);
5233 package->CommitActionCount = 0;
5234 package->CommitAction = NULL;
5236 return ERROR_SUCCESS;
5239 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
5241 static const WCHAR RunOnce[] = {
5242 'S','o','f','t','w','a','r','e','\\',
5243 'M','i','c','r','o','s','o','f','t','\\',
5244 'W','i','n','d','o','w','s','\\',
5245 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5246 'R','u','n','O','n','c','e'};
5247 static const WCHAR InstallRunOnce[] = {
5248 'S','o','f','t','w','a','r','e','\\',
5249 'M','i','c','r','o','s','o','f','t','\\',
5250 'W','i','n','d','o','w','s','\\',
5251 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5252 'I','n','s','t','a','l','l','e','r','\\',
5253 'R','u','n','O','n','c','e','E','n','t','r','i','e','s'};
5255 static const WCHAR msiexec_fmt[] = {
5256 'C',':','\\','W','i','n','d','o','w','s','\\','S','y','s','t','e','m',
5257 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5258 '\"','%','s','\"',0};
5259 static const WCHAR install_fmt[] = {
5260 '/','I',' ','\"','%','s','\"',' ',
5261 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5262 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5266 WCHAR squished_pc[100];
5269 static const WCHAR szProductCode[]=
5270 {'P','r','o','d','u','c','t','C','o','d','e',0};
5271 static const WCHAR szLUS[] = {
5272 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
5273 static const WCHAR szSourceList[] = {
5274 'S','o','u','r','c','e','L','i','s','t',0};
5275 static const WCHAR szPackageName[] = {
5276 'P','a','c','k','a','g','e','N','a','m','e',0};
5279 return ERROR_INVALID_HANDLE;
5281 productcode = load_dynamic_property(package,szProductCode,&rc);
5285 squash_guid(productcode,squished_pc);
5287 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
5288 sprintfW(buffer,msiexec_fmt,squished_pc);
5290 size = strlenW(buffer)*sizeof(WCHAR);
5291 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5294 TRACE("Reboot command %s\n",debugstr_w(buffer));
5296 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
5297 sprintfW(buffer,install_fmt,productcode,squished_pc);
5298 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5301 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5302 if (rc == ERROR_SUCCESS)
5306 RegCreateKeyW(hukey, szSourceList, &hukey2);
5307 buf = load_dynamic_property(package,cszSourceDir,NULL);
5308 size = strlenW(buf)*sizeof(WCHAR);
5309 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
5310 HeapFree(GetProcessHeap(),0,buf);
5312 buf = strrchrW(package->PackagePath,'\\');
5316 size = strlenW(buf)*sizeof(WCHAR);
5317 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
5320 RegCloseKey(hukey2);
5322 HeapFree(GetProcessHeap(),0,productcode);
5324 return ERROR_INSTALL_SUSPEND;
5327 UINT ACTION_ResolveSource(MSIPACKAGE* package)
5330 * we are currently doing what should be done here in the top level Install
5331 * however for Adminastrative and uninstalls this step will be needed
5333 return ERROR_SUCCESS;
5336 /* Msi functions that seem appropriate here */
5337 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
5342 TRACE(" exteral attempt at action %s\n",szAction);
5345 return ERROR_FUNCTION_FAILED;
5347 return ERROR_FUNCTION_FAILED;
5349 szwAction = strdupAtoW(szAction);
5352 return ERROR_FUNCTION_FAILED;
5355 rc = MsiDoActionW(hInstall, szwAction);
5356 HeapFree(GetProcessHeap(),0,szwAction);
5360 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
5362 MSIPACKAGE *package;
5363 UINT ret = ERROR_INVALID_HANDLE;
5365 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
5367 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5370 ret = ACTION_PerformAction(package,szAction);
5371 msiobj_release( &package->hdr );
5376 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
5377 LPSTR szPathBuf, DWORD* pcchPathBuf)
5383 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
5386 return ERROR_FUNCTION_FAILED;
5388 return ERROR_FUNCTION_FAILED;
5390 szwFolder = strdupAtoW(szFolder);
5393 return ERROR_FUNCTION_FAILED;
5395 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
5397 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
5399 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
5400 *pcchPathBuf, NULL, NULL );
5402 HeapFree(GetProcessHeap(),0,szwFolder);
5403 HeapFree(GetProcessHeap(),0,szwPathBuf);
5408 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
5409 szPathBuf, DWORD* pcchPathBuf)
5412 UINT rc = ERROR_FUNCTION_FAILED;
5413 MSIPACKAGE *package;
5415 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5417 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5419 return ERROR_INVALID_HANDLE;
5420 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
5421 msiobj_release( &package->hdr );
5423 if (path && (strlenW(path) > *pcchPathBuf))
5425 *pcchPathBuf = strlenW(path)+1;
5426 rc = ERROR_MORE_DATA;
5430 *pcchPathBuf = strlenW(path)+1;
5431 strcpyW(szPathBuf,path);
5432 TRACE("Returning Path %s\n",debugstr_w(path));
5435 HeapFree(GetProcessHeap(),0,path);
5441 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
5442 LPSTR szPathBuf, DWORD* pcchPathBuf)
5448 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
5451 return ERROR_FUNCTION_FAILED;
5453 return ERROR_FUNCTION_FAILED;
5455 szwFolder = strdupAtoW(szFolder);
5457 return ERROR_FUNCTION_FAILED;
5459 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
5461 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
5463 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
5464 *pcchPathBuf, NULL, NULL );
5466 HeapFree(GetProcessHeap(),0,szwFolder);
5467 HeapFree(GetProcessHeap(),0,szwPathBuf);
5472 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
5473 szPathBuf, DWORD* pcchPathBuf)
5476 UINT rc = ERROR_FUNCTION_FAILED;
5477 MSIPACKAGE *package;
5479 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5481 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5483 return ERROR_INVALID_HANDLE;
5484 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
5485 msiobj_release( &package->hdr );
5487 if (path && strlenW(path) > *pcchPathBuf)
5489 *pcchPathBuf = strlenW(path)+1;
5490 rc = ERROR_MORE_DATA;
5494 *pcchPathBuf = strlenW(path)+1;
5495 strcpyW(szPathBuf,path);
5496 TRACE("Returning Path %s\n",debugstr_w(path));
5499 HeapFree(GetProcessHeap(),0,path);
5505 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
5506 LPCSTR szFolderPath)
5509 LPWSTR szwFolderPath;
5513 return ERROR_FUNCTION_FAILED;
5515 return ERROR_FUNCTION_FAILED;
5517 szwFolder = strdupAtoW(szFolder);
5519 return ERROR_FUNCTION_FAILED;
5521 szwFolderPath = strdupAtoW(szFolderPath);
5524 HeapFree(GetProcessHeap(),0,szwFolder);
5525 return ERROR_FUNCTION_FAILED;
5528 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
5530 HeapFree(GetProcessHeap(),0,szwFolder);
5531 HeapFree(GetProcessHeap(),0,szwFolderPath);
5536 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
5537 LPCWSTR szFolderPath)
5541 LPWSTR path2 = NULL;
5544 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
5547 return ERROR_INVALID_HANDLE;
5549 if (szFolderPath[0]==0)
5550 return ERROR_FUNCTION_FAILED;
5552 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
5553 return ERROR_FUNCTION_FAILED;
5555 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
5558 return ERROR_INVALID_PARAMETER;
5560 HeapFree(GetProcessHeap(),0,folder->Property);
5561 folder->Property = build_directory_name(2, szFolderPath, NULL);
5563 if (strcmpiW(path, folder->Property) == 0)
5566 * Resolved Target has not really changed, so just
5567 * set this folder and do not recalculate everything.
5569 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
5570 folder->ResolvedTarget = NULL;
5571 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
5572 HeapFree(GetProcessHeap(),0,path2);
5576 for (i = 0; i < package->loaded_folders; i++)
5578 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
5579 package->folders[i].ResolvedTarget=NULL;
5582 for (i = 0; i < package->loaded_folders; i++)
5584 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
5586 HeapFree(GetProcessHeap(),0,path2);
5589 HeapFree(GetProcessHeap(),0,path);
5591 return ERROR_SUCCESS;
5594 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
5595 LPCWSTR szFolderPath)
5597 MSIPACKAGE *package;
5600 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
5602 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5603 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
5604 msiobj_release( &package->hdr );
5608 /***********************************************************************
5609 * MsiGetMode (MSI.@)
5611 * Returns an internal installer state (if it is running in a mode iRunMode)
5614 * hInstall [I] Handle to the installation
5615 * hRunMode [I] Checking run mode
5616 * MSIRUNMODE_ADMIN Administrative mode
5617 * MSIRUNMODE_ADVERTISE Advertisement mode
5618 * MSIRUNMODE_MAINTENANCE Maintenance mode
5619 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
5620 * MSIRUNMODE_LOGENABLED Log file is writing
5621 * MSIRUNMODE_OPERATIONS Operations in progress??
5622 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
5623 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
5624 * MSIRUNMODE_CABINET Files from cabinet are installed
5625 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
5626 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
5627 * MSIRUNMODE_RESERVED11 Reserved
5628 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
5629 * MSIRUNMODE_ZAWENABLED Demand installation is supported
5630 * MSIRUNMODE_RESERVED14 Reserved
5631 * MSIRUNMODE_RESERVED15 Reserved
5632 * MSIRUNMODE_SCHEDULED called from install script
5633 * MSIRUNMODE_ROLLBACK called from rollback script
5634 * MSIRUNMODE_COMMIT called from commit script
5637 * In the state: TRUE
5638 * Not in the state: FALSE
5642 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
5644 FIXME("STUB (iRunMode=%i)\n",iRunMode);
5649 * According to the docs, when this is called it immediately recalculates
5650 * all the component states as well
5652 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
5653 INSTALLSTATE iState)
5655 LPWSTR szwFeature = NULL;
5658 szwFeature = strdupAtoW(szFeature);
5661 return ERROR_FUNCTION_FAILED;
5663 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
5665 HeapFree(GetProcessHeap(),0,szwFeature);
5670 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
5671 INSTALLSTATE iState)
5673 MSIPACKAGE* package;
5676 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
5678 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5680 return ERROR_INVALID_HANDLE;
5682 index = get_loaded_feature(package,szFeature);
5684 return ERROR_UNKNOWN_FEATURE;
5686 package->features[index].ActionRequest= iState;
5687 ACTION_UpdateComponentStates(package,szFeature);
5689 return ERROR_SUCCESS;
5692 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
5693 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5695 LPWSTR szwFeature = NULL;
5698 szwFeature = strdupAtoW(szFeature);
5700 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
5702 HeapFree( GetProcessHeap(), 0 , szwFeature);
5707 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
5708 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5712 index = get_loaded_feature(package,szFeature);
5714 return ERROR_UNKNOWN_FEATURE;
5717 *piInstalled = package->features[index].Installed;
5720 *piAction = package->features[index].Action;
5722 TRACE("returning %i %i\n",*piInstalled,*piAction);
5724 return ERROR_SUCCESS;
5727 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
5728 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5730 MSIPACKAGE* package;
5733 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
5736 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5738 return ERROR_INVALID_HANDLE;
5739 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
5740 msiobj_release( &package->hdr );
5744 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
5745 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5747 LPWSTR szwComponent= NULL;
5750 szwComponent= strdupAtoW(szComponent);
5752 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
5754 HeapFree( GetProcessHeap(), 0 , szwComponent);
5759 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
5760 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5764 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
5767 index = get_loaded_component(package,szComponent);
5769 return ERROR_UNKNOWN_COMPONENT;
5772 *piInstalled = package->components[index].Installed;
5775 *piAction = package->components[index].Action;
5777 TRACE("states (%i, %i)\n",
5778 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
5780 return ERROR_SUCCESS;
5783 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
5784 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5786 MSIPACKAGE* package;
5789 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
5790 piInstalled, piAction);
5792 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5794 return ERROR_INVALID_HANDLE;
5795 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
5796 msiobj_release( &package->hdr );
5801 static UINT ACTION_Template(MSIPACKAGE *package)
5805 MSIRECORD * row = 0;
5806 static const WCHAR ExecSeqQuery[] = {0};
5808 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5809 if (rc != ERROR_SUCCESS)
5812 rc = MSI_ViewExecute(view, 0);
5813 if (rc != ERROR_SUCCESS)
5815 MSI_ViewClose(view);
5816 msiobj_release(&view->hdr);
5822 rc = MSI_ViewFetch(view,&row);
5823 if (rc != ERROR_SUCCESS)
5829 msiobj_release(&row->hdr);
5831 MSI_ViewClose(view);
5832 msiobj_release(&view->hdr);