2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
38 #include "wine/debug.h"
43 #include "msvcrt/fcntl.h"
50 #include "wine/unicode.h"
54 #define REG_PROGRESS_VALUE 13200
55 #define COMPONENT_PROGRESS_VALUE 24000
57 WINE_DEFAULT_DEBUG_CHANNEL(msi);
62 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
63 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
64 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI);
65 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
71 typedef UINT (*STANDARDACTIONHANDLER)(MSIPACKAGE*);
73 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
74 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
75 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
76 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
77 static UINT ACTION_FileCost(MSIPACKAGE *package);
78 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
79 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
80 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
81 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
82 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
83 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
84 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
85 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
86 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
87 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package);
88 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package);
89 static UINT ACTION_RegisterUser(MSIPACKAGE *package);
90 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
91 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
92 static UINT ACTION_WriteIniValues(MSIPACKAGE *package);
93 static UINT ACTION_SelfRegModules(MSIPACKAGE *package);
94 static UINT ACTION_PublishFeatures(MSIPACKAGE *package);
95 static UINT ACTION_RegisterProduct(MSIPACKAGE *package);
96 static UINT ACTION_InstallExecute(MSIPACKAGE *package);
97 static UINT ACTION_InstallFinalize(MSIPACKAGE *package);
98 static UINT ACTION_ForceReboot(MSIPACKAGE *package);
99 static UINT ACTION_ResolveSource(MSIPACKAGE *package);
100 static UINT ACTION_ExecuteAction(MSIPACKAGE *package);
101 static UINT ACTION_RegisterFonts(MSIPACKAGE *package);
105 * consts and values used
107 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
108 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
109 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
110 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
111 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
112 static const WCHAR c_colon[] = {'C',':','\\',0};
113 static const WCHAR szProductCode[]=
114 {'P','r','o','d','u','c','t','C','o','d','e',0};
115 static const WCHAR cszbs[]={'\\',0};
116 const static WCHAR szCreateFolders[] =
117 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
118 const static WCHAR szCostFinalize[] =
119 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
120 const static WCHAR szInstallFiles[] =
121 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
122 const static WCHAR szDuplicateFiles[] =
123 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
124 const static WCHAR szWriteRegistryValues[] =
125 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
126 'V','a','l','u','e','s',0};
127 const static WCHAR szCostInitialize[] =
128 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
129 const static WCHAR szFileCost[] =
130 {'F','i','l','e','C','o','s','t',0};
131 const static WCHAR szInstallInitialize[] =
132 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
133 const static WCHAR szInstallValidate[] =
134 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
135 const static WCHAR szLaunchConditions[] =
136 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
137 const static WCHAR szProcessComponents[] =
138 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
139 const static WCHAR szRegisterTypeLibraries[] =
140 {'R','e','g','i','s','t','e','r','T','y','p','e',
141 'L','i','b','r','a','r','i','e','s',0};
142 const static WCHAR szRegisterClassInfo[] =
143 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
144 const static WCHAR szRegisterProgIdInfo[] =
145 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
146 const static WCHAR szCreateShortcuts[] =
147 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
148 const static WCHAR szPublishProduct[] =
149 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
150 const static WCHAR szWriteIniValues[] =
151 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
152 const static WCHAR szSelfRegModules[] =
153 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
154 const static WCHAR szPublishFeatures[] =
155 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
156 const static WCHAR szRegisterProduct[] =
157 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
158 const static WCHAR szInstallExecute[] =
159 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
160 const static WCHAR szInstallExecuteAgain[] =
161 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
162 'A','g','a','i','n',0};
163 const static WCHAR szInstallFinalize[] =
164 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
165 const static WCHAR szForceReboot[] =
166 {'F','o','r','c','e','R','e','b','o','o','t',0};
167 const static WCHAR szResolveSource[] =
168 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
169 const static WCHAR szAppSearch[] =
170 {'A','p','p','S','e','a','r','c','h',0};
171 const static WCHAR szAllocateRegistrySpace[] =
172 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
173 'S','p','a','c','e',0};
174 const static WCHAR szBindImage[] =
175 {'B','i','n','d','I','m','a','g','e',0};
176 const static WCHAR szCCPSearch[] =
177 {'C','C','P','S','e','a','r','c','h',0};
178 const static WCHAR szDeleteServices[] =
179 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
180 const static WCHAR szDisableRollback[] =
181 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
182 const static WCHAR szExecuteAction[] =
183 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
184 const static WCHAR szFindRelatedProducts[] =
185 {'F','i','n','d','R','e','l','a','t','e','d',
186 'P','r','o','d','u','c','t','s',0};
187 const static WCHAR szInstallAdminPackage[] =
188 {'I','n','s','t','a','l','l','A','d','m','i','n',
189 'P','a','c','k','a','g','e',0};
190 const static WCHAR szInstallSFPCatalogFile[] =
191 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
193 const static WCHAR szIsolateComponents[] =
194 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
195 const static WCHAR szMigrateFeatureStates[] =
196 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
197 'S','t','a','t','e','s',0};
198 const static WCHAR szMoveFiles[] =
199 {'M','o','v','e','F','i','l','e','s',0};
200 const static WCHAR szMsiPublishAssemblies[] =
201 {'M','s','i','P','u','b','l','i','s','h',
202 'A','s','s','e','m','b','l','i','e','s',0};
203 const static WCHAR szMsiUnpublishAssemblies[] =
204 {'M','s','i','U','n','p','u','b','l','i','s','h',
205 'A','s','s','e','m','b','l','i','e','s',0};
206 const static WCHAR szInstallODBC[] =
207 {'I','n','s','t','a','l','l','O','D','B','C',0};
208 const static WCHAR szInstallServices[] =
209 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
210 const static WCHAR szPatchFiles[] =
211 {'P','a','t','c','h','F','i','l','e','s',0};
212 const static WCHAR szPublishComponents[] =
213 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
214 const static WCHAR szRegisterComPlus[] =
215 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
216 const static WCHAR szRegisterExtensionInfo[] =
217 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
219 const static WCHAR szRegisterFonts[] =
220 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
221 const static WCHAR szRegisterMIMEInfo[] =
222 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
223 const static WCHAR szRegisterUser[] =
224 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
225 const static WCHAR szRemoveDuplicateFiles[] =
226 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
227 'F','i','l','e','s',0};
228 const static WCHAR szRemoveEnvironmentStrings[] =
229 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
230 'S','t','r','i','n','g','s',0};
231 const static WCHAR szRemoveExistingProducts[] =
232 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
233 'P','r','o','d','u','c','t','s',0};
234 const static WCHAR szRemoveFiles[] =
235 {'R','e','m','o','v','e','F','i','l','e','s',0};
236 const static WCHAR szRemoveFolders[] =
237 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
238 const static WCHAR szRemoveIniValues[] =
239 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
240 const static WCHAR szRemoveODBC[] =
241 {'R','e','m','o','v','e','O','D','B','C',0};
242 const static WCHAR szRemoveRegistryValues[] =
243 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
244 'V','a','l','u','e','s',0};
245 const static WCHAR szRemoveShortcuts[] =
246 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
247 const static WCHAR szRMCCPSearch[] =
248 {'R','M','C','C','P','S','e','a','r','c','h',0};
249 const static WCHAR szScheduleReboot[] =
250 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
251 const static WCHAR szSelfUnregModules[] =
252 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
253 const static WCHAR szSetODBCFolders[] =
254 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
255 const static WCHAR szStartServices[] =
256 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
257 const static WCHAR szStopServices[] =
258 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
259 const static WCHAR szUnpublishComponents[] =
260 {'U','n','p','u','b','l','i','s','h',
261 'C','o','m','p','o','n','e','n','t','s',0};
262 const static WCHAR szUnpublishFeatures[] =
263 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
264 const static WCHAR szUnregisterClassInfo[] =
265 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
267 const static WCHAR szUnregisterComPlus[] =
268 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
269 const static WCHAR szUnregisterExtensionInfo[] =
270 {'U','n','r','e','g','i','s','t','e','r',
271 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
272 const static WCHAR szUnregisterFonts[] =
273 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
274 const static WCHAR szUnregisterMIMEInfo[] =
275 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
276 const static WCHAR szUnregisterProgIdInfo[] =
277 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
279 const static WCHAR szUnregisterTypeLibraries[] =
280 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
281 'L','i','b','r','a','r','i','e','s',0};
282 const static WCHAR szValidateProductID[] =
283 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
284 const static WCHAR szWriteEnvironmentStrings[] =
285 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
286 'S','t','r','i','n','g','s',0};
290 STANDARDACTIONHANDLER handler;
293 static struct _actions StandardActions[] = {
294 { szAllocateRegistrySpace, NULL},
295 { szAppSearch, ACTION_AppSearch },
296 { szBindImage, NULL},
297 { szCCPSearch, NULL},
298 { szCostFinalize, ACTION_CostFinalize },
299 { szCostInitialize, ACTION_CostInitialize },
300 { szCreateFolders, ACTION_CreateFolders },
301 { szCreateShortcuts, ACTION_CreateShortcuts },
302 { szDeleteServices, NULL},
303 { szDisableRollback, NULL},
304 { szDuplicateFiles, ACTION_DuplicateFiles },
305 { szExecuteAction, ACTION_ExecuteAction },
306 { szFileCost, ACTION_FileCost },
307 { szFindRelatedProducts, NULL},
308 { szForceReboot, ACTION_ForceReboot },
309 { szInstallAdminPackage, NULL},
310 { szInstallExecute, ACTION_InstallExecute },
311 { szInstallExecuteAgain, ACTION_InstallExecute },
312 { szInstallFiles, ACTION_InstallFiles},
313 { szInstallFinalize, ACTION_InstallFinalize },
314 { szInstallInitialize, ACTION_InstallInitialize },
315 { szInstallSFPCatalogFile, NULL},
316 { szInstallValidate, ACTION_InstallValidate },
317 { szIsolateComponents, NULL},
318 { szLaunchConditions, ACTION_LaunchConditions },
319 { szMigrateFeatureStates, NULL},
320 { szMoveFiles, NULL},
321 { szMsiPublishAssemblies, NULL},
322 { szMsiUnpublishAssemblies, NULL},
323 { szInstallODBC, NULL},
324 { szInstallServices, NULL},
325 { szPatchFiles, NULL},
326 { szProcessComponents, ACTION_ProcessComponents },
327 { szPublishComponents, NULL},
328 { szPublishFeatures, ACTION_PublishFeatures },
329 { szPublishProduct, ACTION_PublishProduct },
330 { szRegisterClassInfo, ACTION_RegisterClassInfo },
331 { szRegisterComPlus, NULL},
332 { szRegisterExtensionInfo, ACTION_RegisterExtensionInfo },
333 { szRegisterFonts, ACTION_RegisterFonts },
334 { szRegisterMIMEInfo, ACTION_RegisterMIMEInfo },
335 { szRegisterProduct, ACTION_RegisterProduct },
336 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
337 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
338 { szRegisterUser, ACTION_RegisterUser},
339 { szRemoveDuplicateFiles, NULL},
340 { szRemoveEnvironmentStrings, NULL},
341 { szRemoveExistingProducts, NULL},
342 { szRemoveFiles, NULL},
343 { szRemoveFolders, NULL},
344 { szRemoveIniValues, NULL},
345 { szRemoveODBC, NULL},
346 { szRemoveRegistryValues, NULL},
347 { szRemoveShortcuts, NULL},
348 { szResolveSource, ACTION_ResolveSource},
349 { szRMCCPSearch, NULL},
350 { szScheduleReboot, NULL},
351 { szSelfRegModules, ACTION_SelfRegModules },
352 { szSelfUnregModules, NULL},
353 { szSetODBCFolders, NULL},
354 { szStartServices, NULL},
355 { szStopServices, NULL},
356 { szUnpublishComponents, NULL},
357 { szUnpublishFeatures, NULL},
358 { szUnregisterClassInfo, NULL},
359 { szUnregisterComPlus, NULL},
360 { szUnregisterExtensionInfo, NULL},
361 { szUnregisterFonts, NULL},
362 { szUnregisterMIMEInfo, NULL},
363 { szUnregisterProgIdInfo, NULL},
364 { szUnregisterTypeLibraries, NULL},
365 { szValidateProductID, NULL},
366 { szWriteEnvironmentStrings, NULL},
367 { szWriteIniValues, ACTION_WriteIniValues },
368 { szWriteRegistryValues, ACTION_WriteRegistryValues},
373 /********************************************************
374 * helper functions to get around current HACKS and such
375 ********************************************************/
376 inline static void reduce_to_longfilename(WCHAR* filename)
378 LPWSTR p = strchrW(filename,'|');
380 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
383 WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
390 if (MSI_RecordIsNull(row,index))
393 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
395 /* having an empty string is different than NULL */
398 ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
404 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
405 rc = MSI_RecordGetStringW(row,index,ret,&sz);
406 if (rc!=ERROR_SUCCESS)
408 ERR("Unable to load dynamic string\n");
409 HeapFree(GetProcessHeap(), 0, ret);
415 LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop, UINT* rc)
421 r = MSI_GetPropertyW(package, prop, NULL, &sz);
422 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
429 str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
430 r = MSI_GetPropertyW(package, prop, str, &sz);
431 if (r != ERROR_SUCCESS)
433 HeapFree(GetProcessHeap(),0,str);
441 int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
446 for (i = 0; i < package->loaded_components; i++)
448 if (strcmpW(Component,package->components[i].Component)==0)
457 int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
462 for (i = 0; i < package->loaded_features; i++)
464 if (strcmpW(Feature,package->features[i].Feature)==0)
473 int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
478 for (i = 0; i < package->loaded_files; i++)
480 if (strcmpW(file,package->files[i].File)==0)
489 int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
497 for (i=0; i < package->loaded_files; i++)
498 if (strcmpW(package->files[i].File,name)==0)
501 index = package->loaded_files;
502 package->loaded_files++;
503 if (package->loaded_files== 1)
504 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
506 package->files = HeapReAlloc(GetProcessHeap(),0,
507 package->files , package->loaded_files * sizeof(MSIFILE));
509 memset(&package->files[index],0,sizeof(MSIFILE));
511 package->files[index].File = strdupW(name);
512 package->files[index].TargetPath = strdupW(path);
513 package->files[index].Temporary = TRUE;
515 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
520 static void remove_tracked_tempfiles(MSIPACKAGE* package)
527 for (i = 0; i < package->loaded_files; i++)
529 if (package->files[i].Temporary)
531 TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
532 DeleteFileW(package->files[i].TargetPath);
538 /* wrapper to resist a need for a full rewrite right now */
539 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
543 MSIRECORD *rec = MSI_CreateRecord(1);
546 MSI_RecordSetStringW(rec,0,ptr);
547 MSI_FormatRecordW(package,rec,NULL,&size);
551 *data = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
553 MSI_FormatRecordW(package,rec,*data,&size);
556 msiobj_release( &rec->hdr );
557 return sizeof(WCHAR)*size;
559 msiobj_release( &rec->hdr );
566 /* Called when the package is being closed */
567 void ACTION_free_package_structures( MSIPACKAGE* package)
571 TRACE("Freeing package action data\n");
573 remove_tracked_tempfiles(package);
575 /* No dynamic buffers in features */
576 if (package->features && package->loaded_features > 0)
577 HeapFree(GetProcessHeap(),0,package->features);
579 for (i = 0; i < package->loaded_folders; i++)
581 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
582 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
583 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
584 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
585 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
586 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
588 if (package->folders && package->loaded_folders > 0)
589 HeapFree(GetProcessHeap(),0,package->folders);
591 for (i = 0; i < package->loaded_components; i++)
592 HeapFree(GetProcessHeap(),0,package->components[i].FullKeypath);
594 if (package->components && package->loaded_components > 0)
595 HeapFree(GetProcessHeap(),0,package->components);
597 for (i = 0; i < package->loaded_files; i++)
599 HeapFree(GetProcessHeap(),0,package->files[i].File);
600 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
601 HeapFree(GetProcessHeap(),0,package->files[i].Version);
602 HeapFree(GetProcessHeap(),0,package->files[i].Language);
603 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
604 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
607 if (package->files && package->loaded_files > 0)
608 HeapFree(GetProcessHeap(),0,package->files);
610 for (i = 0; i < package->DeferredActionCount; i++)
611 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
612 HeapFree(GetProcessHeap(),0,package->DeferredAction);
614 for (i = 0; i < package->CommitActionCount; i++)
615 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
616 HeapFree(GetProcessHeap(),0,package->CommitAction);
618 HeapFree(GetProcessHeap(),0,package->PackagePath);
621 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
625 row = MSI_CreateRecord(4);
626 MSI_RecordSetInteger(row,1,a);
627 MSI_RecordSetInteger(row,2,b);
628 MSI_RecordSetInteger(row,3,c);
629 MSI_RecordSetInteger(row,4,d);
630 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
631 msiobj_release(&row->hdr);
633 msi_dialog_check_messages(package->dialog, NULL);
636 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
638 static const WCHAR Query_t[] =
639 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
640 'A','c','t','i','o', 'n','T','e','x','t',' ','W','H','E','R','E',' ',
641 'A','c','t','i','o','n',' ','=', ' ','\'','%','s','\'',0};
648 if (!package->LastAction || strcmpW(package->LastAction,action))
650 rc = MSI_OpenQuery(package->db, &view, Query_t, action);
651 if (rc != ERROR_SUCCESS)
654 rc = MSI_ViewExecute(view, 0);
655 if (rc != ERROR_SUCCESS)
660 rc = MSI_ViewFetch(view,&row);
661 if (rc != ERROR_SUCCESS)
667 if (MSI_RecordIsNull(row,3))
669 msiobj_release(&row->hdr);
671 msiobj_release(&view->hdr);
675 /* update the cached actionformat */
676 HeapFree(GetProcessHeap(),0,package->ActionFormat);
677 package->ActionFormat = load_dynamic_stringW(row,3);
679 HeapFree(GetProcessHeap(),0,package->LastAction);
680 package->LastAction = strdupW(action);
682 msiobj_release(&row->hdr);
684 msiobj_release(&view->hdr);
687 MSI_RecordSetStringW(record,0,package->ActionFormat);
689 MSI_FormatRecordW(package,record,message,&size);
691 row = MSI_CreateRecord(1);
692 MSI_RecordSetStringW(row,1,message);
694 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
695 msiobj_release(&row->hdr);
699 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
701 static const WCHAR template_s[]=
702 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
704 static const WCHAR format[] =
705 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
706 static const WCHAR Query_t[] =
707 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
708 'A','c','t','i','o', 'n','T','e','x','t',' ','W','H','E','R','E', ' ',
709 'A','c','t','i','o','n',' ','=', ' ','\'','%','s','\'',0};
715 WCHAR *ActionText=NULL;
717 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
719 rc = MSI_OpenQuery(package->db, &view, Query_t, action);
720 if (rc != ERROR_SUCCESS)
722 rc = MSI_ViewExecute(view, 0);
723 if (rc != ERROR_SUCCESS)
726 msiobj_release(&view->hdr);
729 rc = MSI_ViewFetch(view,&row);
730 if (rc != ERROR_SUCCESS)
733 msiobj_release(&view->hdr);
737 ActionText = load_dynamic_stringW(row,2);
738 msiobj_release(&row->hdr);
740 msiobj_release(&view->hdr);
742 sprintfW(message,template_s,timet,action,ActionText);
744 row = MSI_CreateRecord(1);
745 MSI_RecordSetStringW(row,1,message);
747 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
748 msiobj_release(&row->hdr);
749 HeapFree(GetProcessHeap(),0,ActionText);
752 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
756 static const WCHAR template_s[]=
757 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
759 static const WCHAR template_e[]=
760 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
761 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
763 static const WCHAR format[] =
764 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
768 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
770 sprintfW(message,template_s,timet,action);
772 sprintfW(message,template_e,timet,action,rc);
774 row = MSI_CreateRecord(1);
775 MSI_RecordSetStringW(row,1,message);
777 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
778 msiobj_release(&row->hdr);
782 * build_directory_name()
784 * This function is to save messing round with directory names
785 * It handles adding backslashes between path segments,
786 * and can add \ at the end of the directory name if told to.
788 * It takes a variable number of arguments.
789 * It always allocates a new string for the result, so make sure
790 * to free the return value when finished with it.
792 * The first arg is the number of path segments that follow.
793 * The arguments following count are a list of path segments.
794 * A path segment may be NULL.
796 * Path segments will be added with a \ separating them.
797 * A \ will not be added after the last segment, however if the
798 * last segment is NULL, then the last character will be a \
801 static LPWSTR build_directory_name(DWORD count, ...)
808 for(i=0; i<count; i++)
810 LPCWSTR str = va_arg(va,LPCWSTR);
812 sz += strlenW(str) + 1;
816 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
820 for(i=0; i<count; i++)
822 LPCWSTR str = va_arg(va,LPCWSTR);
826 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
832 static BOOL ACTION_VerifyComponentForAction(MSIPACKAGE* package, INT index,
835 if (package->components[index].Installed == check)
838 if (package->components[index].ActionRequest == check)
844 static BOOL ACTION_VerifyFeatureForAction(MSIPACKAGE* package, INT index,
847 if (package->features[index].Installed == check)
850 if (package->features[index].ActionRequest == check)
857 /****************************************************
858 * TOP level entry points
859 *****************************************************/
861 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
862 LPCWSTR szCommandLine)
868 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
869 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
870 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
872 MSI_SetPropertyW(package, szAction, szInstall);
873 package->ExecuteSequenceRun = FALSE;
877 LPWSTR p, check, path;
879 package->PackagePath = strdupW(szPackagePath);
880 path = strdupW(szPackagePath);
881 p = strrchrW(path,'\\');
889 HeapFree(GetProcessHeap(),0,path);
890 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
891 GetCurrentDirectoryW(MAX_PATH,path);
895 check = load_dynamic_property(package, cszSourceDir,NULL);
897 MSI_SetPropertyW(package, cszSourceDir, path);
899 HeapFree(GetProcessHeap(), 0, check);
901 HeapFree(GetProcessHeap(), 0, path);
907 ptr = (LPWSTR)szCommandLine;
914 TRACE("Looking at %s\n",debugstr_w(ptr));
916 ptr2 = strchrW(ptr,'=');
922 while (*ptr == ' ') ptr++;
924 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
925 strncpyW(prop,ptr,len);
931 while (*ptr && (quote || (!quote && *ptr!=' ')))
944 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
945 strncpyW(val,ptr2,len);
948 if (strlenW(prop) > 0)
950 TRACE("Found commandline property (%s) = (%s)\n",
951 debugstr_w(prop), debugstr_w(val));
952 MSI_SetPropertyW(package,prop,val);
954 HeapFree(GetProcessHeap(),0,val);
955 HeapFree(GetProcessHeap(),0,prop);
962 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
964 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
966 rc = ACTION_ProcessUISequence(package);
968 if (rc == ERROR_SUCCESS)
969 rc = ACTION_ProcessExecSequence(package,TRUE);
972 rc = ACTION_ProcessExecSequence(package,FALSE);
975 rc = ACTION_ProcessExecSequence(package,FALSE);
979 /* install was halted but should be considered a success */
983 /* process the ending type action */
984 if (rc == ERROR_SUCCESS)
985 ACTION_PerformActionSequence(package,-1,ui);
986 else if (rc == ERROR_INSTALL_USEREXIT)
987 ACTION_PerformActionSequence(package,-2,ui);
988 else if (rc == ERROR_FUNCTION_FAILED)
989 ACTION_PerformActionSequence(package,-3,ui);
990 else if (rc == ERROR_INSTALL_SUSPEND)
991 ACTION_PerformActionSequence(package,-4,ui);
993 /* finish up running custom actions */
994 ACTION_FinishCustomActions(package);
999 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
1003 WCHAR buffer[0x100];
1005 MSIRECORD * row = 0;
1006 static const WCHAR ExecSeqQuery[] =
1007 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1008 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1009 'S','e','q','u','e','n','c','e',' ', 'W','H','E','R','E',' ',
1010 'S','e','q','u','e','n','c','e',' ', '=',' ','%','i',0};
1012 static const WCHAR UISeqQuery[] =
1013 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1014 'I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1015 ' ', 'W','H','E','R','E',' ', 'S','e','q','u','e','n','c','e',
1016 ' ', '=',' ','%','i',0};
1019 rc = MSI_OpenQuery(package->db, &view, UISeqQuery, seq);
1021 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1023 if (rc == ERROR_SUCCESS)
1025 rc = MSI_ViewExecute(view, 0);
1027 if (rc != ERROR_SUCCESS)
1029 MSI_ViewClose(view);
1030 msiobj_release(&view->hdr);
1034 TRACE("Running the actions\n");
1036 rc = MSI_ViewFetch(view,&row);
1037 if (rc != ERROR_SUCCESS)
1043 /* check conditions */
1044 if (!MSI_RecordIsNull(row,2))
1047 cond = load_dynamic_stringW(row,2);
1051 /* this is a hack to skip errors in the condition code */
1052 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1054 HeapFree(GetProcessHeap(),0,cond);
1055 msiobj_release(&row->hdr);
1059 HeapFree(GetProcessHeap(),0,cond);
1064 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1065 if (rc != ERROR_SUCCESS)
1067 ERR("Error is %x\n",rc);
1068 msiobj_release(&row->hdr);
1073 rc = ACTION_PerformUIAction(package,buffer);
1075 rc = ACTION_PerformAction(package,buffer);
1076 msiobj_release(&row->hdr);
1078 MSI_ViewClose(view);
1079 msiobj_release(&view->hdr);
1087 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1091 static const WCHAR ExecSeqQuery[] =
1092 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1093 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1094 'S','e','q','u','e','n','c','e',' ', 'W','H','E','R','E',' ',
1095 'S','e','q','u','e','n','c','e',' ', '>',' ','%','i',' ',
1096 'O','R','D','E','R',' ', 'B','Y',' ',
1097 'S','e','q','u','e','n','c','e',0 };
1098 MSIRECORD * row = 0;
1099 static const WCHAR IVQuery[] =
1100 {'S','E','L','E','C','T',' ','S','e','q','u','e','n','c','e',' ',
1101 'F','R','O','M',' ','I','n','s','t','a','l','l',
1102 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
1103 'W','H','E','R','E',' ','A','c','t','i','o','n',' ','=',' ','`',
1104 'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`', 0};
1108 if (package->ExecuteSequenceRun)
1110 TRACE("Execute Sequence already Run\n");
1111 return ERROR_SUCCESS;
1114 package->ExecuteSequenceRun = TRUE;
1116 /* get the sequence number */
1119 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
1120 if (rc != ERROR_SUCCESS)
1122 rc = MSI_ViewExecute(view, 0);
1123 if (rc != ERROR_SUCCESS)
1125 MSI_ViewClose(view);
1126 msiobj_release(&view->hdr);
1129 rc = MSI_ViewFetch(view,&row);
1130 if (rc != ERROR_SUCCESS)
1132 MSI_ViewClose(view);
1133 msiobj_release(&view->hdr);
1136 seq = MSI_RecordGetInteger(row,1);
1137 msiobj_release(&row->hdr);
1138 MSI_ViewClose(view);
1139 msiobj_release(&view->hdr);
1142 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1143 if (rc == ERROR_SUCCESS)
1145 rc = MSI_ViewExecute(view, 0);
1147 if (rc != ERROR_SUCCESS)
1149 MSI_ViewClose(view);
1150 msiobj_release(&view->hdr);
1154 TRACE("Running the actions\n");
1158 WCHAR buffer[0x100];
1161 rc = MSI_ViewFetch(view,&row);
1162 if (rc != ERROR_SUCCESS)
1168 /* check conditions */
1169 if (!MSI_RecordIsNull(row,2))
1172 cond = load_dynamic_stringW(row,2);
1176 /* this is a hack to skip errors in the condition code */
1177 if (MSI_EvaluateConditionW(package, cond) ==
1180 HeapFree(GetProcessHeap(),0,cond);
1181 msiobj_release(&row->hdr);
1185 HeapFree(GetProcessHeap(),0,cond);
1190 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1191 if (rc != ERROR_SUCCESS)
1193 ERR("Error is %x\n",rc);
1194 msiobj_release(&row->hdr);
1198 rc = ACTION_PerformAction(package,buffer);
1200 if (rc == ERROR_FUNCTION_NOT_CALLED)
1203 if (rc != ERROR_SUCCESS)
1205 ERR("Execution halted due to error (%i)\n",rc);
1206 msiobj_release(&row->hdr);
1210 msiobj_release(&row->hdr);
1213 MSI_ViewClose(view);
1214 msiobj_release(&view->hdr);
1222 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1226 static const WCHAR ExecSeqQuery [] =
1227 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1228 'I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1229 ' ','W','H','E','R','E',' ', 'S','e','q','u','e','n','c','e',' ',
1230 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1231 'S','e','q','u','e','n','c','e',0};
1233 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1235 if (rc == ERROR_SUCCESS)
1237 rc = MSI_ViewExecute(view, 0);
1239 if (rc != ERROR_SUCCESS)
1241 MSI_ViewClose(view);
1242 msiobj_release(&view->hdr);
1246 TRACE("Running the actions \n");
1250 WCHAR buffer[0x100];
1252 MSIRECORD * row = 0;
1254 rc = MSI_ViewFetch(view,&row);
1255 if (rc != ERROR_SUCCESS)
1261 /* check conditions */
1262 if (!MSI_RecordIsNull(row,2))
1265 cond = load_dynamic_stringW(row,2);
1269 /* this is a hack to skip errors in the condition code */
1270 if (MSI_EvaluateConditionW(package, cond) ==
1273 HeapFree(GetProcessHeap(),0,cond);
1274 msiobj_release(&row->hdr);
1278 HeapFree(GetProcessHeap(),0,cond);
1283 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1284 if (rc != ERROR_SUCCESS)
1286 ERR("Error is %x\n",rc);
1287 msiobj_release(&row->hdr);
1291 rc = ACTION_PerformUIAction(package,buffer);
1293 if (rc == ERROR_FUNCTION_NOT_CALLED)
1296 if (rc != ERROR_SUCCESS)
1298 ERR("Execution halted due to error (%i)\n",rc);
1299 msiobj_release(&row->hdr);
1303 msiobj_release(&row->hdr);
1306 MSI_ViewClose(view);
1307 msiobj_release(&view->hdr);
1314 /********************************************************
1315 * ACTION helper functions and functions that perform the actions
1316 *******************************************************/
1317 BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action, UINT* rc)
1323 while (StandardActions[i].action != NULL)
1325 if (strcmpW(StandardActions[i].action, action)==0)
1327 ui_actioninfo(package, action, TRUE, 0);
1328 ui_actionstart(package, action);
1329 if (StandardActions[i].handler)
1331 *rc = StandardActions[i].handler(package);
1335 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1336 *rc = ERROR_SUCCESS;
1338 ui_actioninfo(package, action, FALSE, *rc);
1347 BOOL ACTION_HandleDialogBox(MSIPACKAGE *package, LPCWSTR dialog, UINT* rc)
1352 * for the UI when we get that working
1354 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1356 *rc = package->CurrentInstallState;
1363 BOOL ACTION_HandleCustomAction(MSIPACKAGE* package, LPCWSTR action, UINT* rc)
1368 arc = ACTION_CustomAction(package,action,FALSE);
1370 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1379 * A lot of actions are really important even if they don't do anything
1380 * explicit... Lots of properties are set at the beginning of the installation
1381 * CostFinalize does a bunch of work to translate the directories and such
1383 * But until I get write access to the database that is hard, so I am going to
1384 * hack it to see if I can get something to run.
1386 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
1388 UINT rc = ERROR_SUCCESS;
1391 TRACE("Performing action (%s)\n",debugstr_w(action));
1393 handled = ACTION_HandleStandardAction(package, action, &rc);
1396 handled = ACTION_HandleCustomAction(package, action, &rc);
1400 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1401 rc = ERROR_FUNCTION_NOT_CALLED;
1404 package->CurrentInstallState = rc;
1408 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1410 UINT rc = ERROR_SUCCESS;
1411 BOOL handled = FALSE;
1413 TRACE("Performing action (%s)\n",debugstr_w(action));
1415 handled = ACTION_HandleStandardAction(package, action, &rc);
1418 handled = ACTION_HandleCustomAction(package, action, &rc);
1421 handled = ACTION_HandleDialogBox(package, action, &rc);
1423 msi_dialog_check_messages( package->dialog, NULL );
1427 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1428 rc = ERROR_FUNCTION_NOT_CALLED;
1431 package->CurrentInstallState = rc;
1435 /***********************************************************************
1438 * Recursively create all directories in the path.
1440 * shamelessly stolen from setupapi/queue.c
1442 static BOOL create_full_pathW(const WCHAR *path)
1448 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1451 strcpyW(new_path, path);
1453 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1454 new_path[len - 1] = 0;
1456 while(!CreateDirectoryW(new_path, NULL))
1459 DWORD last_error = GetLastError();
1460 if(last_error == ERROR_ALREADY_EXISTS)
1463 if(last_error != ERROR_PATH_NOT_FOUND)
1469 if(!(slash = strrchrW(new_path, '\\')))
1475 len = slash - new_path;
1477 if(!create_full_pathW(new_path))
1482 new_path[len] = '\\';
1485 HeapFree(GetProcessHeap(), 0, new_path);
1490 * Also we cannot enable/disable components either, so for now I am just going
1491 * to do all the directories for all the components.
1493 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1495 static const WCHAR ExecSeqQuery[] =
1496 {'S','E','L','E','C','T',' ','D','i','r','e','c','t','o','r','y','_',
1497 ' ','F','R','O','M',' ',
1498 'C','r','e','a','t','e','F','o','l','d','e','r',0 };
1503 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1504 if (rc != ERROR_SUCCESS)
1505 return ERROR_SUCCESS;
1507 rc = MSI_ViewExecute(view, 0);
1508 if (rc != ERROR_SUCCESS)
1510 MSI_ViewClose(view);
1511 msiobj_release(&view->hdr);
1520 MSIRECORD *row = NULL, *uirow;
1522 rc = MSI_ViewFetch(view,&row);
1523 if (rc != ERROR_SUCCESS)
1530 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1532 if (rc!= ERROR_SUCCESS)
1534 ERR("Unable to get folder id \n");
1535 msiobj_release(&row->hdr);
1540 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1543 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1544 msiobj_release(&row->hdr);
1548 TRACE("Folder is %s\n",debugstr_w(full_path));
1551 uirow = MSI_CreateRecord(1);
1552 MSI_RecordSetStringW(uirow,1,full_path);
1553 ui_actiondata(package,szCreateFolders,uirow);
1554 msiobj_release( &uirow->hdr );
1556 if (folder->State == 0)
1557 create_full_pathW(full_path);
1561 msiobj_release(&row->hdr);
1562 HeapFree(GetProcessHeap(),0,full_path);
1564 MSI_ViewClose(view);
1565 msiobj_release(&view->hdr);
1570 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1572 int index = package->loaded_components;
1575 /* fill in the data */
1577 package->loaded_components++;
1578 if (package->loaded_components == 1)
1579 package->components = HeapAlloc(GetProcessHeap(),0,
1580 sizeof(MSICOMPONENT));
1582 package->components = HeapReAlloc(GetProcessHeap(),0,
1583 package->components, package->loaded_components *
1584 sizeof(MSICOMPONENT));
1586 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1589 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1591 TRACE("Loading Component %s\n",
1592 debugstr_w(package->components[index].Component));
1595 if (!MSI_RecordIsNull(row,2))
1596 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1599 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1601 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1604 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1607 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1609 package->components[index].Installed = INSTALLSTATE_UNKNOWN;
1610 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1611 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1613 package->components[index].Enabled = TRUE;
1618 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1620 int index = package->loaded_features;
1622 static const WCHAR Query1[] =
1623 {'S','E','L','E','C','T',' ','C','o','m','p','o','n','e','n','t','_',
1624 ' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1625 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ',
1626 'F','e', 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1627 static const WCHAR Query2[] =
1628 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1629 'C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ',
1630 'C','o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1637 /* fill in the data */
1639 package->loaded_features ++;
1640 if (package->loaded_features == 1)
1641 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1643 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1644 package->loaded_features * sizeof(MSIFEATURE));
1646 memset(&package->features[index],0,sizeof(MSIFEATURE));
1649 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1651 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1654 if (!MSI_RecordIsNull(row,2))
1655 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1658 if (!MSI_RecordIsNull(row,3))
1659 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1662 if (!MSI_RecordIsNull(row,4))
1663 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1665 if (!MSI_RecordIsNull(row,5))
1666 package->features[index].Display = MSI_RecordGetInteger(row,5);
1668 package->features[index].Level= MSI_RecordGetInteger(row,6);
1671 if (!MSI_RecordIsNull(row,7))
1672 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1674 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1676 package->features[index].Installed = INSTALLSTATE_UNKNOWN;
1677 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1678 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1680 /* load feature components */
1682 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1683 if (rc != ERROR_SUCCESS)
1685 rc = MSI_ViewExecute(view,0);
1686 if (rc != ERROR_SUCCESS)
1688 MSI_ViewClose(view);
1689 msiobj_release(&view->hdr);
1695 WCHAR buffer[0x100];
1698 INT cnt = package->features[index].ComponentCount;
1700 rc = MSI_ViewFetch(view,&row2);
1701 if (rc != ERROR_SUCCESS)
1705 MSI_RecordGetStringW(row2,1,buffer,&sz);
1707 /* check to see if the component is already loaded */
1708 c_indx = get_loaded_component(package,buffer);
1711 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1713 package->features[index].Components[cnt] = c_indx;
1714 package->features[index].ComponentCount ++;
1718 rc = MSI_OpenQuery(package->db, &view2, Query2, buffer);
1719 if (rc != ERROR_SUCCESS)
1721 msiobj_release( &row2->hdr );
1724 rc = MSI_ViewExecute(view2,0);
1725 if (rc != ERROR_SUCCESS)
1727 msiobj_release( &row2->hdr );
1728 MSI_ViewClose(view2);
1729 msiobj_release( &view2->hdr );
1736 rc = MSI_ViewFetch(view2,&row3);
1737 if (rc != ERROR_SUCCESS)
1739 c_indx = load_component(package,row3);
1740 msiobj_release( &row3->hdr );
1742 package->features[index].Components[cnt] = c_indx;
1743 package->features[index].ComponentCount ++;
1744 TRACE("Loaded new component to index %i\n",c_indx);
1746 MSI_ViewClose(view2);
1747 msiobj_release( &view2->hdr );
1748 msiobj_release( &row2->hdr );
1750 MSI_ViewClose(view);
1751 msiobj_release(&view->hdr);
1755 * I am not doing any of the costing functionality yet.
1756 * Mostly looking at doing the Component and Feature loading
1758 * The native MSI does A LOT of modification to tables here. Mostly adding
1759 * a lot of temporary columns to the Feature and Component tables.
1761 * note: Native msi also tracks the short filename. But I am only going to
1762 * track the long ones. Also looking at this directory table
1763 * it appears that the directory table does not get the parents
1764 * resolved base on property only based on their entries in the
1767 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1772 static const WCHAR Query_all[] =
1773 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1774 'F','e','a','t','u','r','e',0};
1775 static const WCHAR szCosting[] =
1776 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1777 static const WCHAR szZero[] = { '0', 0 };
1779 MSI_SetPropertyW(package, szCosting, szZero);
1780 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1782 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1783 if (rc != ERROR_SUCCESS)
1785 rc = MSI_ViewExecute(view,0);
1786 if (rc != ERROR_SUCCESS)
1788 MSI_ViewClose(view);
1789 msiobj_release(&view->hdr);
1796 rc = MSI_ViewFetch(view,&row);
1797 if (rc != ERROR_SUCCESS)
1800 load_feature(package,row);
1801 msiobj_release(&row->hdr);
1803 MSI_ViewClose(view);
1804 msiobj_release(&view->hdr);
1806 return ERROR_SUCCESS;
1809 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1811 DWORD index = package->loaded_files;
1815 /* fill in the data */
1817 package->loaded_files++;
1818 if (package->loaded_files== 1)
1819 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1821 package->files = HeapReAlloc(GetProcessHeap(),0,
1822 package->files , package->loaded_files * sizeof(MSIFILE));
1824 memset(&package->files[index],0,sizeof(MSIFILE));
1826 package->files[index].File = load_dynamic_stringW(row, 1);
1827 buffer = load_dynamic_stringW(row, 2);
1829 package->files[index].ComponentIndex = -1;
1830 for (i = 0; i < package->loaded_components; i++)
1831 if (strcmpW(package->components[i].Component,buffer)==0)
1833 package->files[index].ComponentIndex = i;
1836 if (package->files[index].ComponentIndex == -1)
1837 ERR("Unfound Component %s\n",debugstr_w(buffer));
1838 HeapFree(GetProcessHeap(), 0, buffer);
1840 package->files[index].FileName = load_dynamic_stringW(row,3);
1842 reduce_to_longfilename(package->files[index].FileName);
1844 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1845 package->files[index].Version = load_dynamic_stringW(row, 5);
1846 package->files[index].Language = load_dynamic_stringW(row, 6);
1847 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1848 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1850 package->files[index].Temporary = FALSE;
1851 package->files[index].State = 0;
1853 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1855 return ERROR_SUCCESS;
1858 static UINT ACTION_FileCost(MSIPACKAGE *package)
1863 static const WCHAR Query[] =
1864 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1865 'F','i','l','e',' ', 'O','R','D','E','R',' ','B','Y',' ',
1866 'S','e','q','u','e','n','c','e', 0};
1869 return ERROR_INVALID_HANDLE;
1871 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1872 if (rc != ERROR_SUCCESS)
1873 return ERROR_SUCCESS;
1875 rc = MSI_ViewExecute(view, 0);
1876 if (rc != ERROR_SUCCESS)
1878 MSI_ViewClose(view);
1879 msiobj_release(&view->hdr);
1880 return ERROR_SUCCESS;
1885 rc = MSI_ViewFetch(view,&row);
1886 if (rc != ERROR_SUCCESS)
1891 load_file(package,row);
1892 msiobj_release(&row->hdr);
1894 MSI_ViewClose(view);
1895 msiobj_release(&view->hdr);
1897 return ERROR_SUCCESS;
1900 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1902 static const WCHAR Query[] =
1903 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1904 'D','i','r','e','c', 't','o','r','y',' ','W','H','E','R','E',' ','`',
1905 'D','i','r','e','c','t', 'o','r','y','`',' ','=',' ','`','%','s','`',
1909 LPWSTR ptargetdir, targetdir, parent, srcdir;
1910 MSIRECORD * row = 0;
1914 TRACE("Looking for dir %s\n",debugstr_w(dir));
1916 for (i = 0; i < package->loaded_folders; i++)
1918 if (strcmpW(package->folders[i].Directory,dir)==0)
1920 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1925 TRACE("Working to load %s\n",debugstr_w(dir));
1927 index = package->loaded_folders++;
1928 if (package->loaded_folders==1)
1929 package->folders = HeapAlloc(GetProcessHeap(),0,
1932 package->folders= HeapReAlloc(GetProcessHeap(),0,
1933 package->folders, package->loaded_folders*
1936 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1938 package->folders[index].Directory = strdupW(dir);
1940 rc = MSI_OpenQuery(package->db, &view, Query, dir);
1941 if (rc != ERROR_SUCCESS)
1944 rc = MSI_ViewExecute(view, 0);
1945 if (rc != ERROR_SUCCESS)
1947 MSI_ViewClose(view);
1948 msiobj_release(&view->hdr);
1952 rc = MSI_ViewFetch(view,&row);
1953 if (rc != ERROR_SUCCESS)
1955 MSI_ViewClose(view);
1956 msiobj_release(&view->hdr);
1960 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1962 /* split src and target dir */
1963 if (strchrW(targetdir,':'))
1965 srcdir=strchrW(targetdir,':');
1972 /* for now only pick long filename versions */
1973 if (strchrW(targetdir,'|'))
1975 targetdir = strchrW(targetdir,'|');
1979 if (srcdir && strchrW(srcdir,'|'))
1981 srcdir= strchrW(srcdir,'|');
1986 /* now check for root dirs */
1987 if (targetdir[0] == '.' && targetdir[1] == 0)
1990 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1995 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1996 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
1997 package->folders[index].TargetDefault = strdupW(targetdir);
2001 package->folders[index].SourceDefault = strdupW(srcdir);
2003 package->folders[index].SourceDefault = strdupW(targetdir);
2004 HeapFree(GetProcessHeap(), 0, ptargetdir);
2006 parent = load_dynamic_stringW(row,2);
2009 i = load_folder(package,parent);
2010 package->folders[index].ParentIndex = i;
2011 TRACE("Parent is index %i... %s %s\n",
2012 package->folders[index].ParentIndex,
2013 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2014 debugstr_w(parent));
2017 package->folders[index].ParentIndex = -2;
2018 HeapFree(GetProcessHeap(), 0, parent);
2020 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2022 msiobj_release(&row->hdr);
2023 MSI_ViewClose(view);
2024 msiobj_release(&view->hdr);
2025 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2030 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
2031 BOOL set_prop, MSIFOLDER **folder)
2034 LPWSTR p, path = NULL;
2036 TRACE("Working to resolve %s\n",debugstr_w(name));
2038 /* special resolving for Target and Source root dir */
2039 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2043 path = load_dynamic_property(package,cszTargetDir,NULL);
2046 path = load_dynamic_property(package,cszRootDrive,NULL);
2048 MSI_SetPropertyW(package,cszTargetDir,path);
2052 for (i = 0; i < package->loaded_folders; i++)
2054 if (strcmpW(package->folders[i].Directory,name)==0)
2057 *folder = &(package->folders[i]);
2063 path = load_dynamic_property(package,cszSourceDir,NULL);
2066 path = load_dynamic_property(package,cszDatabase,NULL);
2069 p = strrchrW(path,'\\');
2076 for (i = 0; i < package->loaded_folders; i++)
2078 if (strcmpW(package->folders[i].Directory,name)==0)
2081 *folder = &(package->folders[i]);
2087 for (i = 0; i < package->loaded_folders; i++)
2089 if (strcmpW(package->folders[i].Directory,name)==0)
2093 if (i >= package->loaded_folders)
2097 *folder = &(package->folders[i]);
2099 if (!source && package->folders[i].ResolvedTarget)
2101 path = strdupW(package->folders[i].ResolvedTarget);
2102 TRACE(" already resolved to %s\n",debugstr_w(path));
2105 else if (source && package->folders[i].ResolvedSource)
2107 path = strdupW(package->folders[i].ResolvedSource);
2110 else if (!source && package->folders[i].Property)
2112 path = build_directory_name(2, package->folders[i].Property, NULL);
2114 TRACE(" internally set to %s\n",debugstr_w(path));
2116 MSI_SetPropertyW(package,name,path);
2120 if (package->folders[i].ParentIndex >= 0)
2122 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2124 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2126 p = resolve_folder(package, parent, source, set_prop, NULL);
2129 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2130 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2131 package->folders[i].ResolvedTarget = strdupW(path);
2132 TRACE(" resolved into %s\n",debugstr_w(path));
2134 MSI_SetPropertyW(package,name,path);
2138 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2139 package->folders[i].ResolvedSource = strdupW(path);
2141 HeapFree(GetProcessHeap(),0,p);
2146 /* scan for and update current install states */
2147 void ACTION_UpdateInstallStates(MSIPACKAGE *package)
2152 productcode = load_dynamic_property(package,szProductCode,NULL);
2154 for (i = 0; i < package->loaded_components; i++)
2157 res = MsiGetComponentPathW(productcode,
2158 package->components[i].ComponentId , NULL, NULL);
2160 res = INSTALLSTATE_ABSENT;
2161 package->components[i].Installed = res;
2164 for (i = 0; i < package->loaded_features; i++)
2166 INSTALLSTATE res = -10;
2168 for (j = 0; j < package->features[i].ComponentCount; j++)
2170 MSICOMPONENT* component = &package->components[package->features[i].
2173 res = component->Installed;
2176 if (res == component->Installed)
2179 if (res != component->Installed)
2180 res = INSTALLSTATE_INCOMPLETE;
2186 /* update compoennt state based on a feature change */
2187 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2190 INSTALLSTATE newstate;
2191 MSIFEATURE *feature;
2193 i = get_loaded_feature(package,szFeature);
2197 feature = &package->features[i];
2198 newstate = feature->ActionRequest;
2200 for( i = 0; i < feature->ComponentCount; i++)
2202 MSICOMPONENT* component = &package->components[feature->Components[i]];
2204 if (!component->Enabled)
2208 if (newstate == INSTALLSTATE_LOCAL)
2209 component->ActionRequest = INSTALLSTATE_LOCAL;
2214 component->ActionRequest = newstate;
2216 /*if any other feature wants is local we need to set it local*/
2218 j < package->loaded_features &&
2219 component->ActionRequest != INSTALLSTATE_LOCAL;
2222 for (k = 0; k < package->features[j].ComponentCount; k++)
2223 if ( package->features[j].Components[k] ==
2224 feature->Components[i] )
2226 if (package->features[j].ActionRequest ==
2228 component->ActionRequest = INSTALLSTATE_LOCAL;
2237 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
2240 static const WCHAR all[]={'A','L','L',0};
2241 LPWSTR override = NULL;
2245 override = load_dynamic_property(package, property, NULL);
2249 for(i = 0; i < package->loaded_features; i++)
2251 if (strcmpiW(override,all)==0)
2253 package->features[i].ActionRequest= state;
2254 package->features[i].Action = state;
2258 LPWSTR ptr = override;
2259 LPWSTR ptr2 = strchrW(override,',');
2264 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2266 strcmpW(ptr,package->features[i].Feature)==0))
2268 package->features[i].ActionRequest= state;
2269 package->features[i].Action = state;
2275 ptr2 = strchrW(ptr,',');
2282 HeapFree(GetProcessHeap(),0,override);
2288 static UINT SetFeatureStates(MSIPACKAGE *package)
2294 static const WCHAR szlevel[] =
2295 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2296 static const WCHAR szAddLocal[] =
2297 {'A','D','D','L','O','C','A','L',0};
2298 static const WCHAR szRemove[] =
2299 {'R','E','M','O','V','E',0};
2300 BOOL override = FALSE;
2302 /* I do not know if this is where it should happen.. but */
2304 TRACE("Checking Install Level\n");
2306 level = load_dynamic_property(package,szlevel,NULL);
2309 install_level = atoiW(level);
2310 HeapFree(GetProcessHeap(), 0, level);
2315 /* ok hereis the _real_ rub
2316 * all these activation/deactivation things happen in order and things
2317 * later on the list override things earlier on the list.
2318 * 1) INSTALLLEVEL processing
2328 * 11) FILEADDDEFAULT
2329 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2330 * ignored for all the features. seems strange, especially since it is not
2331 * documented anywhere, but it is how it works.
2333 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2334 * REMOVE are the big ones, since we don't handle administrative installs
2337 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
2338 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
2342 for(i = 0; i < package->loaded_features; i++)
2344 BOOL feature_state = ((package->features[i].Level > 0) &&
2345 (package->features[i].Level <= install_level));
2349 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
2350 package->features[i].Action = INSTALLSTATE_LOCAL;
2356 * now we want to enable or disable components base on feature
2359 for(i = 0; i < package->loaded_features; i++)
2361 MSIFEATURE* feature = &package->features[i];
2362 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2363 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2364 feature->ActionRequest);
2366 for( j = 0; j < feature->ComponentCount; j++)
2368 MSICOMPONENT* component = &package->components[
2369 feature->Components[j]];
2371 if (!component->Enabled)
2373 component->Action = INSTALLSTATE_UNKNOWN;
2374 component->ActionRequest = INSTALLSTATE_UNKNOWN;
2378 if (feature->Action == INSTALLSTATE_LOCAL)
2380 component->Action = INSTALLSTATE_LOCAL;
2381 component->ActionRequest = INSTALLSTATE_LOCAL;
2383 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
2385 if (component->Action == INSTALLSTATE_UNKNOWN)
2387 component->Action = INSTALLSTATE_ABSENT;
2388 component->ActionRequest = INSTALLSTATE_ABSENT;
2395 for(i = 0; i < package->loaded_components; i++)
2397 MSICOMPONENT* component= &package->components[i];
2399 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2400 debugstr_w(component->Component), component->Installed,
2401 component->Action, component->ActionRequest);
2405 return ERROR_SUCCESS;
2409 * A lot is done in this function aside from just the costing.
2410 * The costing needs to be implemented at some point but for now I am going
2411 * to focus on the directory building
2414 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2416 static const WCHAR ExecSeqQuery[] =
2417 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2418 'D','i','r','e','c','t','o','r','y',0};
2419 static const WCHAR ConditionQuery[] =
2420 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2421 'C','o','n','d','i','t','i','o','n',0};
2422 static const WCHAR szCosting[] =
2423 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2424 static const WCHAR szlevel[] =
2425 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2426 static const WCHAR szOne[] = { '1', 0 };
2432 TRACE("Building Directory properties\n");
2434 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2435 if (rc == ERROR_SUCCESS)
2437 rc = MSI_ViewExecute(view, 0);
2438 if (rc != ERROR_SUCCESS)
2440 MSI_ViewClose(view);
2441 msiobj_release(&view->hdr);
2449 MSIRECORD * row = 0;
2452 rc = MSI_ViewFetch(view,&row);
2453 if (rc != ERROR_SUCCESS)
2460 MSI_RecordGetStringW(row,1,name,&sz);
2462 /* This helper function now does ALL the work */
2463 TRACE("Dir %s ...\n",debugstr_w(name));
2464 load_folder(package,name);
2465 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2466 TRACE("resolves to %s\n",debugstr_w(path));
2467 HeapFree( GetProcessHeap(), 0, path);
2469 msiobj_release(&row->hdr);
2471 MSI_ViewClose(view);
2472 msiobj_release(&view->hdr);
2475 TRACE("File calculations %i files\n",package->loaded_files);
2477 for (i = 0; i < package->loaded_files; i++)
2479 MSICOMPONENT* comp = NULL;
2480 MSIFILE* file= NULL;
2482 file = &package->files[i];
2483 if (file->ComponentIndex >= 0)
2484 comp = &package->components[file->ComponentIndex];
2486 if (file->Temporary == TRUE)
2493 /* calculate target */
2494 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2496 HeapFree(GetProcessHeap(),0,file->TargetPath);
2498 TRACE("file %s is named %s\n",
2499 debugstr_w(file->File),debugstr_w(file->FileName));
2501 file->TargetPath = build_directory_name(2, p, file->FileName);
2503 HeapFree(GetProcessHeap(),0,p);
2505 TRACE("file %s resolves to %s\n",
2506 debugstr_w(file->File),debugstr_w(file->TargetPath));
2508 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2511 comp->Cost += file->FileSize;
2521 static const WCHAR name[] =
2523 static const WCHAR name_fmt[] =
2524 {'%','u','.','%','u','.','%','u','.','%','u',0};
2525 WCHAR filever[0x100];
2526 VS_FIXEDFILEINFO *lpVer;
2528 TRACE("Version comparison.. \n");
2529 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2530 version = HeapAlloc(GetProcessHeap(),0,versize);
2531 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2533 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2535 sprintfW(filever,name_fmt,
2536 HIWORD(lpVer->dwFileVersionMS),
2537 LOWORD(lpVer->dwFileVersionMS),
2538 HIWORD(lpVer->dwFileVersionLS),
2539 LOWORD(lpVer->dwFileVersionLS));
2541 TRACE("new %s old %s\n", debugstr_w(file->Version),
2542 debugstr_w(filever));
2543 if (strcmpiW(filever,file->Version)<0)
2546 FIXME("cost should be diff in size\n");
2547 comp->Cost += file->FileSize;
2551 HeapFree(GetProcessHeap(),0,version);
2559 TRACE("Evaluating Condition Table\n");
2561 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2562 if (rc == ERROR_SUCCESS)
2564 rc = MSI_ViewExecute(view, 0);
2565 if (rc != ERROR_SUCCESS)
2567 MSI_ViewClose(view);
2568 msiobj_release(&view->hdr);
2574 WCHAR Feature[0x100];
2575 MSIRECORD * row = 0;
2579 rc = MSI_ViewFetch(view,&row);
2581 if (rc != ERROR_SUCCESS)
2588 MSI_RecordGetStringW(row,1,Feature,&sz);
2590 feature_index = get_loaded_feature(package,Feature);
2591 if (feature_index < 0)
2592 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2596 Condition = load_dynamic_stringW(row,3);
2598 if (MSI_EvaluateConditionW(package,Condition) ==
2601 int level = MSI_RecordGetInteger(row,2);
2602 TRACE("Reseting feature %s to level %i\n",
2603 debugstr_w(Feature), level);
2604 package->features[feature_index].Level = level;
2606 HeapFree(GetProcessHeap(),0,Condition);
2609 msiobj_release(&row->hdr);
2611 MSI_ViewClose(view);
2612 msiobj_release(&view->hdr);
2615 TRACE("Enabling or Disabling Components\n");
2616 for (i = 0; i < package->loaded_components; i++)
2618 if (package->components[i].Condition[0])
2620 if (MSI_EvaluateConditionW(package,
2621 package->components[i].Condition) == MSICONDITION_FALSE)
2623 TRACE("Disabling component %s\n",
2624 debugstr_w(package->components[i].Component));
2625 package->components[i].Enabled = FALSE;
2630 MSI_SetPropertyW(package,szCosting,szOne);
2631 /* set default run level if not set */
2632 level = load_dynamic_property(package,szlevel,NULL);
2634 MSI_SetPropertyW(package,szlevel, szOne);
2636 HeapFree(GetProcessHeap(),0,level);
2638 ACTION_UpdateInstallStates(package);
2640 return SetFeatureStates(package);
2644 * This is a helper function for handling embedded cabinet media
2646 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2654 WCHAR tmp[MAX_PATH];
2656 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2657 if (rc != ERROR_SUCCESS)
2661 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2662 GetTempPathW(MAX_PATH,tmp);
2664 GetTempFileNameW(tmp,stream_name,0,source);
2666 track_tempfile(package,strrchrW(source,'\\'), source);
2667 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2668 FILE_ATTRIBUTE_NORMAL, NULL);
2670 if (the_file == INVALID_HANDLE_VALUE)
2672 rc = ERROR_FUNCTION_FAILED;
2676 WriteFile(the_file,data,size,&write,NULL);
2677 CloseHandle(the_file);
2678 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2680 HeapFree(GetProcessHeap(),0,data);
2685 /* Support functions for FDI functions */
2688 MSIPACKAGE* package;
2693 static void * cabinet_alloc(ULONG cb)
2695 return HeapAlloc(GetProcessHeap(), 0, cb);
2698 static void cabinet_free(void *pv)
2700 HeapFree(GetProcessHeap(), 0, pv);
2703 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2706 DWORD dwShareMode = 0;
2707 DWORD dwCreateDisposition = OPEN_EXISTING;
2708 switch (oflag & _O_ACCMODE)
2711 dwAccess = GENERIC_READ;
2712 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2715 dwAccess = GENERIC_WRITE;
2716 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2719 dwAccess = GENERIC_READ | GENERIC_WRITE;
2720 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2723 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2724 dwCreateDisposition = CREATE_NEW;
2725 else if (oflag & _O_CREAT)
2726 dwCreateDisposition = CREATE_ALWAYS;
2727 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
2728 dwCreateDisposition, 0, NULL);
2731 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2734 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2739 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2742 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2747 static int cabinet_close(INT_PTR hf)
2749 return CloseHandle((HANDLE)hf) ? 0 : -1;
2752 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2754 /* flags are compatible and so are passed straight through */
2755 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2758 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2760 /* FIXME: try to do more processing in this function */
2763 case fdintCOPY_FILE:
2765 CabData *data = (CabData*) pfdin->pv;
2766 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2771 LPWSTR tracknametmp;
2772 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2774 if (data->file_name && strcmp(data->file_name,pfdin->psz1))
2777 file = cabinet_alloc((len+1)*sizeof(char));
2778 strcpy(file, data->cab_path);
2779 strcat(file, pfdin->psz1);
2781 TRACE("file: %s\n", debugstr_a(file));
2783 /* track this file so it can be deleted if not installed */
2784 trackpath=strdupAtoW(file);
2785 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2786 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2787 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2789 strcpyW(trackname,tmpprefix);
2790 strcatW(trackname,tracknametmp);
2792 track_tempfile(data->package, trackname, trackpath);
2794 HeapFree(GetProcessHeap(),0,trackpath);
2795 HeapFree(GetProcessHeap(),0,trackname);
2796 HeapFree(GetProcessHeap(),0,tracknametmp);
2798 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2800 case fdintCLOSE_FILE_INFO:
2804 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2806 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2808 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2811 cabinet_close(pfdin->hf);
2819 /***********************************************************************
2820 * extract_cabinet_file
2822 * Extract files from a cab file.
2824 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2825 const WCHAR* path, const WCHAR* file)
2835 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2836 debugstr_w(file), debugstr_w(path));
2838 hfdi = FDICreate(cabinet_alloc,
2849 ERR("FDICreate failed\n");
2853 if (!(cabinet = strdupWtoA( source )))
2858 if (!(cab_path = strdupWtoA( path )))
2861 HeapFree(GetProcessHeap(), 0, cabinet);
2865 data.package = package;
2866 data.cab_path = cab_path;
2868 file_name = strdupWtoA(file);
2871 data.file_name = file_name;
2873 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
2876 ERR("FDICopy failed\n");
2880 HeapFree(GetProcessHeap(), 0, cabinet);
2881 HeapFree(GetProcessHeap(), 0, cab_path);
2882 HeapFree(GetProcessHeap(), 0, file_name);
2887 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2888 WCHAR* path, WCHAR* file)
2892 MSIRECORD * row = 0;
2893 static WCHAR source[MAX_PATH];
2894 static const WCHAR ExecSeqQuery[] =
2895 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2896 'M','e','d','i','a',' ','W','H','E','R','E',' ',
2897 'L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%',
2898 'i',' ','O','R','D','E','R',' ','B','Y',' ',
2899 'L','a','s','t','S','e','q','u','e','n','c','e',0};
2904 static UINT last_sequence = 0;
2906 if (sequence <= last_sequence)
2908 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2909 /*extract_a_cabinet_file(package, source,path,file); */
2910 return ERROR_SUCCESS;
2913 sprintfW(Query,ExecSeqQuery,sequence);
2915 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2916 if (rc != ERROR_SUCCESS)
2919 rc = MSI_ViewExecute(view, 0);
2920 if (rc != ERROR_SUCCESS)
2922 MSI_ViewClose(view);
2923 msiobj_release(&view->hdr);
2927 rc = MSI_ViewFetch(view,&row);
2928 if (rc != ERROR_SUCCESS)
2930 MSI_ViewClose(view);
2931 msiobj_release(&view->hdr);
2934 seq = MSI_RecordGetInteger(row,2);
2935 last_sequence = seq;
2937 if (!MSI_RecordIsNull(row,4))
2940 MSI_RecordGetStringW(row,4,cab,&sz);
2941 TRACE("Source is CAB %s\n",debugstr_w(cab));
2942 /* the stream does not contain the # character */
2945 writeout_cabinet_stream(package,&cab[1],source);
2946 strcpyW(path,source);
2947 *(strrchrW(path,'\\')+1)=0;
2952 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2954 ERR("No Source dir defined \n");
2955 rc = ERROR_FUNCTION_FAILED;
2959 strcpyW(path,source);
2960 strcatW(source,cab);
2961 /* extract the cab file into a folder in the temp folder */
2963 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2965 GetTempPathW(MAX_PATH,path);
2968 rc = !extract_a_cabinet_file(package, source,path,NULL);
2973 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
2974 strcpyW(path,source);
2976 msiobj_release(&row->hdr);
2977 MSI_ViewClose(view);
2978 msiobj_release(&view->hdr);
2982 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2984 UINT rc = ERROR_SUCCESS;
2986 LPWSTR install_path;
2988 install_path = resolve_folder(package, package->components[component].Directory,
2989 FALSE, FALSE, &folder);
2991 return ERROR_FUNCTION_FAILED;
2993 /* create the path */
2994 if (folder->State == 0)
2996 create_full_pathW(install_path);
2999 HeapFree(GetProcessHeap(), 0, install_path);
3004 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3006 UINT rc = ERROR_SUCCESS;
3009 WCHAR uipath[MAX_PATH];
3012 return ERROR_INVALID_HANDLE;
3014 /* increment progress bar each time action data is sent */
3015 ui_progress(package,1,1,0,0);
3017 for (index = 0; index < package->loaded_files; index++)
3019 WCHAR path_to_source[MAX_PATH];
3022 file = &package->files[index];
3024 if (file->Temporary)
3028 if (!ACTION_VerifyComponentForAction(package, file->ComponentIndex,
3029 INSTALLSTATE_LOCAL))
3031 ui_progress(package,2,file->FileSize,0,0);
3032 TRACE("File %s is not scheduled for install\n",
3033 debugstr_w(file->File));
3038 if ((file->State == 1) || (file->State == 2))
3042 MSICOMPONENT* comp = NULL;
3044 TRACE("Installing %s\n",debugstr_w(file->File));
3045 rc = ready_media_for_file(package,file->Sequence,path_to_source,
3049 * our file table could change here because a new temp file
3050 * may have been created
3052 file = &package->files[index];
3053 if (rc != ERROR_SUCCESS)
3055 ERR("Unable to ready media\n");
3056 rc = ERROR_FUNCTION_FAILED;
3060 create_component_directory( package, file->ComponentIndex);
3062 /* recalculate file paths because things may have changed */
3064 if (file->ComponentIndex >= 0)
3065 comp = &package->components[file->ComponentIndex];
3067 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3068 HeapFree(GetProcessHeap(),0,file->TargetPath);
3070 file->TargetPath = build_directory_name(2, p, file->FileName);
3072 len = strlenW(path_to_source) + strlenW(file->File) + 2;
3073 file->SourcePath = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3074 strcpyW(file->SourcePath, path_to_source);
3075 strcatW(file->SourcePath, file->File);
3077 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3078 debugstr_w(file->TargetPath));
3081 uirow=MSI_CreateRecord(9);
3082 MSI_RecordSetStringW(uirow,1,file->File);
3083 strcpyW(uipath,file->TargetPath);
3084 *(strrchrW(uipath,'\\')+1)=0;
3085 MSI_RecordSetStringW(uirow,9,uipath);
3086 MSI_RecordSetInteger(uirow,6,file->FileSize);
3087 ui_actiondata(package,szInstallFiles,uirow);
3088 msiobj_release( &uirow->hdr );
3089 ui_progress(package,2,file->FileSize,0,0);
3091 if (!MoveFileW(file->SourcePath,file->TargetPath))
3093 rc = GetLastError();
3094 ERR("Unable to move file (%s -> %s) (error %d)\n",
3095 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3097 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3099 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3100 DeleteFileW(file->SourcePath);
3103 else if (rc == ERROR_FILE_NOT_FOUND)
3105 ERR("Source File Not Found! Continuing\n");
3110 ERR("Ignoring Error and continuing...\n");
3122 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3123 LPWSTR* file_source)
3128 return ERROR_INVALID_HANDLE;
3130 for (index = 0; index < package->loaded_files; index ++)
3132 if (strcmpW(file_key,package->files[index].File)==0)
3134 if (package->files[index].State >= 2)
3136 *file_source = strdupW(package->files[index].TargetPath);
3137 return ERROR_SUCCESS;
3140 return ERROR_FILE_NOT_FOUND;
3144 return ERROR_FUNCTION_FAILED;
3147 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3151 MSIRECORD * row = 0;
3152 static const WCHAR ExecSeqQuery[] =
3153 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3154 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
3157 return ERROR_INVALID_HANDLE;
3159 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3160 if (rc != ERROR_SUCCESS)
3161 return ERROR_SUCCESS;
3163 rc = MSI_ViewExecute(view, 0);
3164 if (rc != ERROR_SUCCESS)
3166 MSI_ViewClose(view);
3167 msiobj_release(&view->hdr);
3173 WCHAR file_key[0x100];
3174 WCHAR *file_source = NULL;
3175 WCHAR dest_name[0x100];
3176 LPWSTR dest_path, dest;
3177 WCHAR component[0x100];
3178 INT component_index;
3182 rc = MSI_ViewFetch(view,&row);
3183 if (rc != ERROR_SUCCESS)
3190 rc = MSI_RecordGetStringW(row,2,component,&sz);
3191 if (rc != ERROR_SUCCESS)
3193 ERR("Unable to get component\n");
3194 msiobj_release(&row->hdr);
3198 component_index = get_loaded_component(package,component);
3200 if (!ACTION_VerifyComponentForAction(package, component_index,
3201 INSTALLSTATE_LOCAL))
3203 TRACE("Skipping copy due to disabled component\n");
3205 /* the action taken was the same as the current install state */
3206 package->components[component_index].Action =
3207 package->components[component_index].Installed;
3209 msiobj_release(&row->hdr);
3213 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3216 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3217 if (rc != ERROR_SUCCESS)
3219 ERR("Unable to get file key\n");
3220 msiobj_release(&row->hdr);
3224 rc = get_file_target(package,file_key,&file_source);
3226 if (rc != ERROR_SUCCESS)
3228 ERR("Original file unknown %s\n",debugstr_w(file_key));
3229 msiobj_release(&row->hdr);
3230 HeapFree(GetProcessHeap(),0,file_source);
3234 if (MSI_RecordIsNull(row,4))
3236 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3241 MSI_RecordGetStringW(row,4,dest_name,&sz);
3242 reduce_to_longfilename(dest_name);
3245 if (MSI_RecordIsNull(row,5))
3248 dest_path = strdupW(file_source);
3249 p = strrchrW(dest_path,'\\');
3255 WCHAR destkey[0x100];
3257 MSI_RecordGetStringW(row,5,destkey,&sz);
3259 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3262 ERR("Unable to get destination folder\n");
3263 msiobj_release(&row->hdr);
3264 HeapFree(GetProcessHeap(),0,file_source);
3269 dest = build_directory_name(2, dest_path, dest_name);
3271 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3274 if (strcmpW(file_source,dest))
3275 rc = !CopyFileW(file_source,dest,TRUE);
3279 if (rc != ERROR_SUCCESS)
3280 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
3282 FIXME("We should track these duplicate files as well\n");
3284 msiobj_release(&row->hdr);
3285 HeapFree(GetProcessHeap(),0,dest_path);
3286 HeapFree(GetProcessHeap(),0,dest);
3287 HeapFree(GetProcessHeap(),0,file_source);
3289 MSI_ViewClose(view);
3290 msiobj_release(&view->hdr);
3295 /* OK this value is "interpreted" and then formatted based on the
3296 first few characters */
3297 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3301 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3310 deformat_string(package, &value[2], &deformated);
3312 /* binary value type */
3315 *size = strlenW(ptr)/2;
3316 data = HeapAlloc(GetProcessHeap(),0,*size);
3328 data[count] = (BYTE)strtol(byte,NULL,0);
3331 HeapFree(GetProcessHeap(),0,deformated);
3333 TRACE("Data %li bytes(%i)\n",*size,count);
3340 deformat_string(package, &value[1], &deformated);
3343 *size = sizeof(DWORD);
3344 data = HeapAlloc(GetProcessHeap(),0,*size);
3350 if ( (*p < '0') || (*p > '9') )
3356 if (deformated[0] == '-')
3359 TRACE("DWORD %li\n",*(LPDWORD)data);
3361 HeapFree(GetProcessHeap(),0,deformated);
3366 static const WCHAR szMulti[] = {'[','~',']',0};
3375 *type=REG_EXPAND_SZ;
3383 if (strstrW(value,szMulti))
3384 *type = REG_MULTI_SZ;
3386 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3391 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3395 MSIRECORD * row = 0;
3396 static const WCHAR ExecSeqQuery[] =
3397 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3398 'R','e','g','i','s','t','r','y',0 };
3401 return ERROR_INVALID_HANDLE;
3403 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3404 if (rc != ERROR_SUCCESS)
3405 return ERROR_SUCCESS;
3407 rc = MSI_ViewExecute(view, 0);
3408 if (rc != ERROR_SUCCESS)
3410 MSI_ViewClose(view);
3411 msiobj_release(&view->hdr);
3415 /* increment progress bar each time action data is sent */
3416 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3420 static const WCHAR szHCR[] =
3421 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3422 'R','O','O','T','\\',0};
3423 static const WCHAR szHCU[] =
3424 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3425 'U','S','E','R','\\',0};
3426 static const WCHAR szHLM[] =
3427 {'H','K','E','Y','_','L','O','C','A','L','_',
3428 'M','A','C','H','I','N','E','\\',0};
3429 static const WCHAR szHU[] =
3430 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3432 LPSTR value_data = NULL;
3433 HKEY root_key, hkey;
3435 LPWSTR value, key, name, component, deformated;
3437 INT component_index;
3442 rc = MSI_ViewFetch(view,&row);
3443 if (rc != ERROR_SUCCESS)
3448 ui_progress(package,2,0,0,0);
3455 component = load_dynamic_stringW(row, 6);
3456 component_index = get_loaded_component(package,component);
3458 if (!ACTION_VerifyComponentForAction(package, component_index,
3459 INSTALLSTATE_LOCAL))
3461 TRACE("Skipping write due to disabled component\n");
3462 msiobj_release(&row->hdr);
3464 package->components[component_index].Action =
3465 package->components[component_index].Installed;
3470 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3472 name = load_dynamic_stringW(row, 4);
3473 if( MSI_RecordIsNull(row,5) && name )
3475 /* null values can have special meanings */
3476 if (name[0]=='-' && name[1] == 0)
3478 msiobj_release(&row->hdr);
3481 else if ((name[0]=='+' && name[1] == 0) ||
3482 (name[0] == '*' && name[1] == 0))
3484 HeapFree(GetProcessHeap(),0,name);
3489 root = MSI_RecordGetInteger(row,2);
3490 key = load_dynamic_stringW(row, 3);
3493 /* get the root key */
3496 case 0: root_key = HKEY_CLASSES_ROOT;
3499 case 1: root_key = HKEY_CURRENT_USER;
3502 case 2: root_key = HKEY_LOCAL_MACHINE;
3505 case 3: root_key = HKEY_USERS;
3509 ERR("Unknown root %i\n",root);
3516 msiobj_release(&row->hdr);
3520 deformat_string(package, key , &deformated);
3521 size = strlenW(deformated) + strlenW(szRoot) + 1;
3522 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3523 strcpyW(uikey,szRoot);
3524 strcatW(uikey,deformated);
3526 if (RegCreateKeyW( root_key, deformated, &hkey))
3528 ERR("Could not create key %s\n",debugstr_w(deformated));
3529 msiobj_release(&row->hdr);
3530 HeapFree(GetProcessHeap(),0,deformated);
3533 HeapFree(GetProcessHeap(),0,deformated);
3535 value = load_dynamic_stringW(row,5);
3537 value_data = parse_value(package, value, &type, &size);
3540 static const WCHAR szEmpty[] = {0};
3541 value_data = (LPSTR)strdupW(szEmpty);
3546 deformat_string(package, name, &deformated);
3548 TRACE("Setting value %s\n",debugstr_w(deformated));
3549 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3551 uirow = MSI_CreateRecord(3);
3552 MSI_RecordSetStringW(uirow,2,deformated);
3553 MSI_RecordSetStringW(uirow,1,uikey);
3556 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3558 MSI_RecordSetStringW(uirow,3,value);
3560 ui_actiondata(package,szWriteRegistryValues,uirow);
3561 msiobj_release( &uirow->hdr );
3563 HeapFree(GetProcessHeap(),0,value_data);
3564 HeapFree(GetProcessHeap(),0,value);
3565 HeapFree(GetProcessHeap(),0,deformated);
3567 msiobj_release(&row->hdr);
3570 HeapFree(GetProcessHeap(),0,uikey);
3571 HeapFree(GetProcessHeap(),0,key);
3572 HeapFree(GetProcessHeap(),0,name);
3573 HeapFree(GetProcessHeap(),0,component);
3575 MSI_ViewClose(view);
3576 msiobj_release(&view->hdr);
3580 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3582 return ERROR_SUCCESS;
3586 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3590 static const WCHAR q1[]=
3591 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3592 'R','e','g','i','s','t','r','y',0};
3595 MSIRECORD * row = 0;
3598 TRACE(" InstallValidate \n");
3600 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3601 if (rc != ERROR_SUCCESS)
3602 return ERROR_SUCCESS;
3604 rc = MSI_ViewExecute(view, 0);
3605 if (rc != ERROR_SUCCESS)
3607 MSI_ViewClose(view);
3608 msiobj_release(&view->hdr);
3613 rc = MSI_ViewFetch(view,&row);
3614 if (rc != ERROR_SUCCESS)
3621 msiobj_release(&row->hdr);
3623 MSI_ViewClose(view);
3624 msiobj_release(&view->hdr);
3626 total = total + progress * REG_PROGRESS_VALUE;
3627 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3628 for (i=0; i < package->loaded_files; i++)
3629 total += package->files[i].FileSize;
3630 ui_progress(package,0,total,0,0);
3632 return ERROR_SUCCESS;
3635 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3638 MSIQUERY * view = NULL;
3639 MSIRECORD * row = 0;
3640 static const WCHAR ExecSeqQuery[] =
3641 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3642 'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3643 static const WCHAR title[]=
3644 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3646 TRACE("Checking launch conditions\n");
3648 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3649 if (rc != ERROR_SUCCESS)
3650 return ERROR_SUCCESS;
3652 rc = MSI_ViewExecute(view, 0);
3653 if (rc != ERROR_SUCCESS)
3655 MSI_ViewClose(view);
3656 msiobj_release(&view->hdr);
3661 while (rc == ERROR_SUCCESS)
3664 LPWSTR message = NULL;
3666 rc = MSI_ViewFetch(view,&row);
3667 if (rc != ERROR_SUCCESS)
3673 cond = load_dynamic_stringW(row,1);
3675 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3678 message = load_dynamic_stringW(row,2);
3679 deformat_string(package,message,&deformated);
3680 MessageBoxW(NULL,deformated,title,MB_OK);
3681 HeapFree(GetProcessHeap(),0,message);
3682 HeapFree(GetProcessHeap(),0,deformated);
3683 rc = ERROR_FUNCTION_FAILED;
3685 HeapFree(GetProcessHeap(),0,cond);
3686 msiobj_release(&row->hdr);
3688 MSI_ViewClose(view);
3689 msiobj_release(&view->hdr);
3693 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3696 MSICOMPONENT* cmp = &package->components[component_index];
3698 if (cmp->KeyPath[0]==0)
3700 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3703 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
3706 MSIRECORD * row = 0;
3708 LPWSTR key,deformated,buffer,name,deformated_name;
3709 static const WCHAR ExecSeqQuery[] =
3710 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3711 'R','e','g','i','s','t','r','y',' ','W','H','E','R','E',' ',
3712 'R','e','g','i','s','t','r','y',' ','=',' ' ,'`','%','s','`',0 };
3713 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
3714 static const WCHAR fmt2[]=
3715 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3717 rc = MSI_OpenQuery(package->db,&view,ExecSeqQuery,cmp->KeyPath);
3719 if (rc!=ERROR_SUCCESS)
3722 rc = MSI_ViewExecute(view, 0);
3723 if (rc != ERROR_SUCCESS)
3725 MSI_ViewClose(view);
3726 msiobj_release(&view->hdr);
3730 rc = MSI_ViewFetch(view,&row);
3731 if (rc != ERROR_SUCCESS)
3733 MSI_ViewClose(view);
3734 msiobj_release(&view->hdr);
3738 root = MSI_RecordGetInteger(row,2);
3739 key = load_dynamic_stringW(row, 3);
3740 name = load_dynamic_stringW(row, 4);
3741 deformat_string(package, key , &deformated);
3742 deformat_string(package, name, &deformated_name);
3744 len = strlenW(deformated) + 6;
3745 if (deformated_name)
3746 len+=strlenW(deformated_name);
3748 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3750 if (deformated_name)
3751 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3753 sprintfW(buffer,fmt,root,deformated);
3755 HeapFree(GetProcessHeap(),0,key);
3756 HeapFree(GetProcessHeap(),0,deformated);
3757 HeapFree(GetProcessHeap(),0,name);
3758 HeapFree(GetProcessHeap(),0,deformated_name);
3759 msiobj_release(&row->hdr);
3760 MSI_ViewClose(view);
3761 msiobj_release(&view->hdr);
3765 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
3767 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3773 j = get_loaded_file(package,cmp->KeyPath);
3777 LPWSTR p = strdupW(package->files[j].TargetPath);
3784 static HKEY openSharedDLLsKey()
3787 static const WCHAR path[] =
3788 {'S','o','f','t','w','a','r','e','\\',
3789 'M','i','c','r','o','s','o','f','t','\\',
3790 'W','i','n','d','o','w','s','\\',
3791 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3792 'S','h','a','r','e','d','D','L','L','s',0};
3794 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
3798 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
3803 DWORD sz = sizeof(count);
3806 hkey = openSharedDLLsKey();
3807 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
3808 if (rc != ERROR_SUCCESS)
3814 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
3818 hkey = openSharedDLLsKey();
3820 RegSetValueExW(hkey,path,0,REG_DWORD,
3821 (LPBYTE)&count,sizeof(count));
3823 RegDeleteValueW(hkey,path);
3829 * Return TRUE if the count should be written out and FALSE if not
3831 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
3837 /* only refcount DLLs */
3838 if (package->components[index].KeyPath[0]==0 ||
3839 package->components[index].Attributes &
3840 msidbComponentAttributesRegistryKeyPath ||
3841 package->components[index].Attributes &
3842 msidbComponentAttributesODBCDataSource)
3846 count = ACTION_GetSharedDLLsCount(package->components[index].
3848 write = (count > 0);
3850 if (package->components[index].Attributes &
3851 msidbComponentAttributesSharedDllRefCount)
3855 /* increment counts */
3856 for (j = 0; j < package->loaded_features; j++)
3860 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
3863 for (i = 0; i < package->features[j].ComponentCount; i++)
3865 if (package->features[j].Components[i] == index)
3869 /* decrement counts */
3870 for (j = 0; j < package->loaded_features; j++)
3873 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
3876 for (i = 0; i < package->features[j].ComponentCount; i++)
3878 if (package->features[j].Components[i] == index)
3883 /* ref count all the files in the component */
3885 for (j = 0; j < package->loaded_files; j++)
3887 if (package->files[j].Temporary)
3889 if (package->files[j].ComponentIndex == index)
3890 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
3893 /* add a count for permenent */
3894 if (package->components[index].Attributes &
3895 msidbComponentAttributesPermanent)
3898 package->components[index].RefCount = count;
3901 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
3902 package->components[index].RefCount);
3906 * Ok further analysis makes me think that this work is
3907 * actually done in the PublishComponents and PublishFeatures
3908 * step, and not here. It appears like the keypath and all that is
3909 * resolved in this step, however actually written in the Publish steps.
3910 * But we will leave it here for now because it is unclear
3912 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3915 WCHAR squished_pc[GUID_SIZE];
3916 WCHAR squished_cc[GUID_SIZE];
3919 HKEY hkey=0,hkey2=0;
3922 return ERROR_INVALID_HANDLE;
3924 /* writes the Component and Features values to the registry */
3925 productcode = load_dynamic_property(package,szProductCode,&rc);
3929 rc = MSIREG_OpenComponents(&hkey);
3930 if (rc != ERROR_SUCCESS)
3933 squash_guid(productcode,squished_pc);
3934 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
3935 for (i = 0; i < package->loaded_components; i++)
3937 ui_progress(package,2,0,0,0);
3938 if (package->components[i].ComponentId[0]!=0)
3940 WCHAR *keypath = NULL;
3943 squash_guid(package->components[i].ComponentId,squished_cc);
3944 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
3945 if (rc != ERROR_SUCCESS)
3948 keypath = resolve_keypath(package,i);
3949 package->components[i].FullKeypath = keypath;
3951 /* do the refcounting */
3952 ACTION_RefCountComponent( package, i);
3954 TRACE("Component %s, Keypath=%s, RefCount=%i\n",
3955 debugstr_w(package->components[i].Component),
3956 debugstr_w(package->components[i].FullKeypath),
3957 package->components[i].RefCount);
3959 * Write the keypath out if the component is to be registered
3960 * and delete the key if the component is to be deregistered
3962 if (ACTION_VerifyComponentForAction(package, i,
3963 INSTALLSTATE_LOCAL))
3967 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
3968 (strlenW(keypath)+1)*sizeof(WCHAR));
3970 if (package->components[i].Attributes &
3971 msidbComponentAttributesPermanent)
3973 static const WCHAR szPermKey[] =
3974 { '0','0','0','0','0','0','0','0','0','0','0','0',
3975 '0','0','0','0','0','0','0', '0','0','0','0','0',
3976 '0','0','0','0','0','0','0','0',0};
3978 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
3980 (strlenW(keypath)+1)*sizeof(WCHAR));
3986 uirow = MSI_CreateRecord(3);
3987 MSI_RecordSetStringW(uirow,1,productcode);
3988 MSI_RecordSetStringW(uirow,2,package->components[i].
3990 MSI_RecordSetStringW(uirow,3,keypath);
3991 ui_actiondata(package,szProcessComponents,uirow);
3992 msiobj_release( &uirow->hdr );
3995 else if (ACTION_VerifyComponentForAction(package, i,
3996 INSTALLSTATE_ABSENT))
3999 RegDeleteValueW(hkey2,squished_pc);
4001 /* if the key is empty delete it */
4002 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
4004 if (res == ERROR_NO_MORE_ITEMS)
4005 RegDeleteKeyW(hkey,squished_cc);
4008 uirow = MSI_CreateRecord(2);
4009 MSI_RecordSetStringW(uirow,1,productcode);
4010 MSI_RecordSetStringW(uirow,2,package->components[i].
4012 ui_actiondata(package,szProcessComponents,uirow);
4013 msiobj_release( &uirow->hdr );
4018 HeapFree(GetProcessHeap(), 0, productcode);
4023 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4026 * OK this is a bit confusing.. I am given a _Component key and I believe
4027 * that the file that is being registered as a type library is the "key file
4028 * of that component" which I interpret to mean "The file in the KeyPath of
4033 MSIRECORD * row = 0;
4034 static const WCHAR Query[] =
4035 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4036 'T','y','p','e','L','i','b',0};
4041 return ERROR_INVALID_HANDLE;
4043 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4044 if (rc != ERROR_SUCCESS)
4045 return ERROR_SUCCESS;
4047 rc = MSI_ViewExecute(view, 0);
4048 if (rc != ERROR_SUCCESS)
4050 MSI_ViewClose(view);
4051 msiobj_release(&view->hdr);
4057 WCHAR component[0x100];
4061 rc = MSI_ViewFetch(view,&row);
4062 if (rc != ERROR_SUCCESS)
4069 MSI_RecordGetStringW(row,3,component,&sz);
4071 index = get_loaded_component(package,component);
4074 msiobj_release(&row->hdr);
4078 if (!ACTION_VerifyComponentForAction(package, index,
4079 INSTALLSTATE_LOCAL))
4081 TRACE("Skipping typelib reg due to disabled component\n");
4082 msiobj_release(&row->hdr);
4084 package->components[index].Action =
4085 package->components[index].Installed;
4090 package->components[index].Action = INSTALLSTATE_LOCAL;
4092 index = get_loaded_file(package,package->components[index].KeyPath);
4096 msiobj_release(&row->hdr);
4100 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
4104 WCHAR helpid[0x100];
4107 MSI_RecordGetStringW(row,6,helpid,&sz);
4109 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4110 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
4111 HeapFree(GetProcessHeap(),0,help);
4113 if (!SUCCEEDED(res))
4114 ERR("Failed to register type library %s\n",
4115 debugstr_w(package->files[index].TargetPath));
4118 /* Yes the row has more fields than I need, but #1 is
4119 correct and the only one I need. Why make a new row? */
4121 ui_actiondata(package,szRegisterTypeLibraries,row);
4123 TRACE("Registered %s\n",
4124 debugstr_w(package->files[index].TargetPath));
4128 ITypeLib_Release(ptLib);
4131 ERR("Failed to load type library %s\n",
4132 debugstr_w(package->files[index].TargetPath));
4134 msiobj_release(&row->hdr);
4136 MSI_ViewClose(view);
4137 msiobj_release(&view->hdr);
4142 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
4144 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4147 MSIRECORD * row = 0;
4148 static const WCHAR ExecSeqQuery[] =
4149 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4150 'A','p','p','I' ,'d',' ','w','h','e','r','e',' ',
4151 'A','p','p','I','d','=','`','%','s','`',0};
4156 return ERROR_INVALID_HANDLE;
4158 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
4159 if (rc != ERROR_SUCCESS)
4162 rc = MSI_ViewExecute(view, 0);
4163 if (rc != ERROR_SUCCESS)
4165 MSI_ViewClose(view);
4166 msiobj_release(&view->hdr);
4170 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
4171 RegCreateKeyW(hkey2,clsid,&hkey3);
4172 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
4173 (strlenW(app)+1)*sizeof(WCHAR));
4175 rc = MSI_ViewFetch(view,&row);
4176 if (rc != ERROR_SUCCESS)
4178 MSI_ViewClose(view);
4179 msiobj_release(&view->hdr);
4183 if (!MSI_RecordIsNull(row,2))
4185 LPWSTR deformated=0;
4187 static const WCHAR szRemoteServerName[] =
4188 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
4190 buffer = load_dynamic_stringW(row,2);
4191 size = deformat_string(package,buffer,&deformated);
4192 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
4194 HeapFree(GetProcessHeap(),0,deformated);
4195 HeapFree(GetProcessHeap(),0,buffer);
4198 if (!MSI_RecordIsNull(row,3))
4200 static const WCHAR szLocalService[] =
4201 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
4203 buffer = load_dynamic_stringW(row,3);
4204 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4205 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
4206 HeapFree(GetProcessHeap(),0,buffer);
4209 if (!MSI_RecordIsNull(row,4))
4211 static const WCHAR szService[] =
4212 {'S','e','r','v','i','c','e',
4213 'P','a','r','a','m','e','t','e','r','s',0};
4215 buffer = load_dynamic_stringW(row,4);
4216 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4217 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
4218 HeapFree(GetProcessHeap(),0,buffer);
4221 if (!MSI_RecordIsNull(row,5))
4223 static const WCHAR szDLL[] =
4224 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
4226 buffer = load_dynamic_stringW(row,5);
4227 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4228 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
4229 HeapFree(GetProcessHeap(),0,buffer);
4232 if (!MSI_RecordIsNull(row,6))
4234 static const WCHAR szActivate[] =
4235 {'A','c','t','i','v','a','t','e','A','s',
4236 'S','t','o','r','a','g','e',0};
4237 static const WCHAR szY[] = {'Y',0};
4239 if (MSI_RecordGetInteger(row,6))
4240 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
4243 if (!MSI_RecordIsNull(row,7))
4245 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
4246 static const WCHAR szUser[] =
4247 {'I','n','t','e','r','a','c','t','i','v','e',' ',
4250 if (MSI_RecordGetInteger(row,7))
4251 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
4254 msiobj_release(&row->hdr);
4255 MSI_ViewClose(view);
4256 msiobj_release(&view->hdr);
4262 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
4265 * Again I am assuming the words, "Whose key file represents" when referring
4266 * to a Component as to meaning that Components KeyPath file
4268 * Also there is a very strong connection between ClassInfo and ProgID
4269 * that I am mostly glossing over.
4270 * What would be more propper is to load the ClassInfo and the ProgID info
4271 * into memory data structures and then be able to enable and disable them
4272 * based on component.
4277 MSIRECORD * row = 0;
4278 static const WCHAR ExecSeqQuery[] =
4279 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4280 'C','l','a','s','s',0};
4281 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4282 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
4283 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4284 static const WCHAR szSpace[] = {' ',0};
4285 HKEY hkey,hkey2,hkey3;
4286 LPWSTR argument,deformated;
4289 return ERROR_INVALID_HANDLE;
4291 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
4292 if (rc != ERROR_SUCCESS)
4293 return ERROR_FUNCTION_FAILED;
4295 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4296 if (rc != ERROR_SUCCESS)
4302 rc = MSI_ViewExecute(view, 0);
4303 if (rc != ERROR_SUCCESS)
4305 MSI_ViewClose(view);
4306 msiobj_release(&view->hdr);
4313 WCHAR buffer[0x100];
4319 rc = MSI_ViewFetch(view,&row);
4320 if (rc != ERROR_SUCCESS)
4327 MSI_RecordGetStringW(row,3,buffer,&sz);
4329 index = get_loaded_component(package,buffer);
4333 msiobj_release(&row->hdr);
4337 if (!ACTION_VerifyComponentForAction(package, index,
4338 INSTALLSTATE_LOCAL))
4340 TRACE("Skipping class reg due to disabled component\n");
4341 msiobj_release(&row->hdr);
4343 package->components[index].Action =
4344 package->components[index].Installed;
4349 package->components[index].Action = INSTALLSTATE_LOCAL;
4352 MSI_RecordGetStringW(row,1,clsid,&sz);
4353 RegCreateKeyW(hkey,clsid,&hkey2);
4355 if (!MSI_RecordIsNull(row,5))
4358 MSI_RecordGetStringW(row,5,desc,&sz);
4360 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
4361 (strlenW(desc)+1)*sizeof(WCHAR));
4367 MSI_RecordGetStringW(row,2,buffer,&sz);
4369 RegCreateKeyW(hkey2,buffer,&hkey3);
4371 index = get_loaded_file(package,package->components[index].KeyPath);
4373 argument = load_dynamic_stringW(row,11);
4374 size = deformat_string(package,argument,&deformated);
4376 size+=sizeof(WCHAR);
4377 HeapFree(GetProcessHeap(),0,argument);
4378 size += (strlenW(package->files[index].TargetPath))*sizeof(WCHAR);
4380 argument = HeapAlloc(GetProcessHeap(),0,size+sizeof(WCHAR));
4381 strcpyW(argument,package->files[index].TargetPath);
4384 strcatW(argument,szSpace);
4385 strcatW(argument,deformated);
4388 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4389 HeapFree(GetProcessHeap(),0,deformated);
4390 HeapFree(GetProcessHeap(),0,argument);
4394 if (!MSI_RecordIsNull(row,4))
4397 MSI_RecordGetStringW(row,4,buffer,&sz);
4399 RegCreateKeyW(hkey2,szProgID,&hkey3);
4401 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4402 (strlenW(buffer)+1)*sizeof(WCHAR));
4407 if (!MSI_RecordIsNull(row,6))
4410 MSI_RecordGetStringW(row,6,buffer,&sz);
4412 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4413 (strlenW(buffer)+1)*sizeof(WCHAR));
4415 register_appid(package,buffer,desc);
4419 if (!MSI_RecordIsNull(row,7))
4421 FIXME("Process field 7\n");
4424 if (!MSI_RecordIsNull(row,8))
4426 static const WCHAR szDefaultIcon[] =
4427 {'D','e','f','a','u','l','t','I','c','o','n',0};
4429 LPWSTR FileName = load_dynamic_stringW(row,8);
4433 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
4434 build_icon_path(package,FileName,&FilePath);
4435 if (!MSI_RecordIsNull(row,9))
4437 static const WCHAR index_fmt[] = {',','%','i',0};
4438 WCHAR index_buf[20];
4439 index = MSI_RecordGetInteger(row,9);
4440 sprintfW(index_buf,index_fmt,index);
4441 size = strlenW(FilePath)+strlenW(index_buf)+1;
4442 size *= sizeof(WCHAR);
4443 HeapReAlloc(GetProcessHeap(),0,FilePath,size);
4445 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)FilePath,
4446 (strlenW(FilePath)+1) * sizeof(WCHAR));
4447 HeapFree(GetProcessHeap(),0,FilePath);
4448 HeapFree(GetProcessHeap(),0,FileName);
4452 if (!MSI_RecordIsNull(row,10))
4454 static const WCHAR szInproc32[] =
4455 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
4457 static const WCHAR szInproc[] =
4458 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
4459 INT i = MSI_RecordGetInteger(row,10);
4460 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4462 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4463 static const WCHAR ole32[] =
4464 {'o','l','e','3','2','.','d','l','l',0};
4468 size = strlenW(ole2) * sizeof(WCHAR);
4469 RegCreateKeyW(hkey2,szInproc,&hkey3);
4470 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4474 size = strlenW(ole32) * sizeof(WCHAR);
4475 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4476 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4480 size = strlenW(ole2) * sizeof(WCHAR);
4481 RegCreateKeyW(hkey2,szInproc,&hkey3);
4482 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4484 size = strlenW(ole32) * sizeof(WCHAR);
4485 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4486 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4494 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4495 argument = load_dynamic_stringW(row,10);
4496 reduce_to_longfilename(argument);
4497 size = strlenW(argument)*sizeof(WCHAR);
4499 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4500 HeapFree(GetProcessHeap(),0,argument);
4508 ui_actiondata(package,szRegisterClassInfo,row);
4510 msiobj_release(&row->hdr);
4512 MSI_ViewClose(view);
4513 msiobj_release(&view->hdr);
4520 static UINT register_progid_base(MSIPACKAGE* package, MSIRECORD * row,
4523 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4524 static const WCHAR szDefaultIcon[] =
4525 {'D','e','f','a','u','l','t','I','c','o','n',0};
4527 WCHAR buffer[0x100];
4532 MSI_RecordGetStringW(row,1,buffer,&sz);
4533 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4535 if (!MSI_RecordIsNull(row,4))
4538 MSI_RecordGetStringW(row,4,buffer,&sz);
4539 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4543 if (!MSI_RecordIsNull(row,3))
4547 MSI_RecordGetStringW(row,3,buffer,&sz);
4548 RegCreateKeyW(hkey,szCLSID,&hkey2);
4549 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4553 strcpyW(clsid,buffer);
4559 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4560 return ERROR_FUNCTION_FAILED;
4562 if (!MSI_RecordIsNull(row,5))
4564 INT index = MSI_RecordGetInteger(row,6);
4565 LPWSTR FileName = load_dynamic_stringW(row,5);
4566 LPWSTR FilePath,IconPath;
4567 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4569 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4570 build_icon_path(package,FileName,&FilePath);
4572 IconPath = HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4575 sprintfW(IconPath,fmt,FilePath,index);
4576 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)IconPath,
4577 (strlenW(IconPath)+1) * sizeof(WCHAR));
4578 HeapFree(GetProcessHeap(),0,FilePath);
4579 HeapFree(GetProcessHeap(),0,FileName);
4582 return ERROR_SUCCESS;
4585 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4587 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4592 MSIRECORD * row = 0;
4593 static const WCHAR Query_t[] =
4594 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4595 'P','r','o','g' ,'I','d',' ','W','H','E','R','E',' ',
4596 'P','r','o','g','I','d',' ','=',' ','`' ,'%','s','`',0};
4599 return ERROR_INVALID_HANDLE;
4601 rc = MSI_OpenQuery(package->db, &view, Query_t, parent);
4602 if (rc != ERROR_SUCCESS)
4605 rc = MSI_ViewExecute(view, 0);
4606 if (rc != ERROR_SUCCESS)
4608 MSI_ViewClose(view);
4609 msiobj_release(&view->hdr);
4613 rc = MSI_ViewFetch(view,&row);
4614 if (rc != ERROR_SUCCESS)
4616 MSI_ViewClose(view);
4617 msiobj_release(&view->hdr);
4621 register_progid(package,row,clsid);
4623 msiobj_release(&row->hdr);
4624 MSI_ViewClose(view);
4625 msiobj_release(&view->hdr);
4629 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4631 UINT rc = ERROR_SUCCESS;
4633 if (MSI_RecordIsNull(row,2))
4634 rc = register_progid_base(package,row,clsid);
4637 WCHAR buffer[0x1000];
4640 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4641 static const WCHAR szDefaultIcon[] =
4642 {'D','e','f','a','u','l','t','I','c','o','n',0};
4644 /* check if already registered */
4646 MSI_RecordGetStringW(row,1,buffer,&sz);
4647 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4648 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4649 if (disp == REG_OPENED_EXISTING_KEY)
4651 TRACE("Key already registered\n");
4657 MSI_RecordGetStringW(row,2,buffer,&sz);
4658 rc = register_parent_progid(package,buffer,clsid);
4660 /* clsid is same as parent */
4661 RegCreateKeyW(hkey,szCLSID,&hkey2);
4662 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4668 if (!MSI_RecordIsNull(row,4))
4671 MSI_RecordGetStringW(row,4,buffer,&sz);
4672 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4673 (strlenW(buffer)+1) * sizeof(WCHAR));
4676 if (!MSI_RecordIsNull(row,5))
4678 LPWSTR FileName = load_dynamic_stringW(row,5);
4680 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4681 build_icon_path(package,FileName,&FilePath);
4682 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)FilePath,
4683 (strlenW(FilePath)+1) * sizeof(WCHAR));
4684 HeapFree(GetProcessHeap(),0,FilePath);
4685 HeapFree(GetProcessHeap(),0,FileName);
4694 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4697 * Sigh, here I am just brute force registering all progids
4698 * this needs to be linked to the Classes that have been registered
4699 * but the easiest way to do that is to load all these stuff into
4700 * memory for easy checking.
4702 * Gives me something to continue to work toward.
4706 MSIRECORD * row = 0;
4707 static const WCHAR Query[] =
4708 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
4709 'P','r','o','g','I','d',0};
4712 return ERROR_INVALID_HANDLE;
4714 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4715 if (rc != ERROR_SUCCESS)
4716 return ERROR_SUCCESS;
4718 rc = MSI_ViewExecute(view, 0);
4719 if (rc != ERROR_SUCCESS)
4721 MSI_ViewClose(view);
4722 msiobj_release(&view->hdr);
4728 WCHAR clsid[0x1000];
4730 rc = MSI_ViewFetch(view,&row);
4731 if (rc != ERROR_SUCCESS)
4737 register_progid(package,row,clsid);
4738 ui_actiondata(package,szRegisterProgIdInfo,row);
4740 msiobj_release(&row->hdr);
4742 MSI_ViewClose(view);
4743 msiobj_release(&view->hdr);
4747 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4751 LPWSTR SystemFolder;
4755 static const WCHAR szInstaller[] =
4756 {'I','n','s','t','a','l','l','e','r','\\',0};
4757 static const WCHAR szFolder[] =
4758 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4760 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4764 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4766 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4768 create_full_pathW(dest);
4770 *FilePath = build_directory_name(2, dest, icon_name);
4772 HeapFree(GetProcessHeap(),0,SystemFolder);
4773 HeapFree(GetProcessHeap(),0,ProductCode);
4774 HeapFree(GetProcessHeap(),0,dest);
4775 return ERROR_SUCCESS;
4778 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4782 MSIRECORD * row = 0;
4783 static const WCHAR Query[] =
4784 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4785 'S','h','o','r','t','c','u','t',0};
4791 return ERROR_INVALID_HANDLE;
4793 res = CoInitialize( NULL );
4796 ERR("CoInitialize failed\n");
4797 return ERROR_FUNCTION_FAILED;
4800 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4801 if (rc != ERROR_SUCCESS)
4802 return ERROR_SUCCESS;
4804 rc = MSI_ViewExecute(view, 0);
4805 if (rc != ERROR_SUCCESS)
4807 MSI_ViewClose(view);
4808 msiobj_release(&view->hdr);
4814 LPWSTR target_file, target_folder;
4815 WCHAR buffer[0x100];
4818 static const WCHAR szlnk[]={'.','l','n','k',0};
4820 rc = MSI_ViewFetch(view,&row);
4821 if (rc != ERROR_SUCCESS)
4828 MSI_RecordGetStringW(row,4,buffer,&sz);
4830 index = get_loaded_component(package,buffer);
4834 msiobj_release(&row->hdr);
4838 if (!ACTION_VerifyComponentForAction(package, index,
4839 INSTALLSTATE_LOCAL))
4841 TRACE("Skipping shortcut creation due to disabled component\n");
4842 msiobj_release(&row->hdr);
4844 package->components[index].Action =
4845 package->components[index].Installed;
4850 package->components[index].Action = INSTALLSTATE_LOCAL;
4852 ui_actiondata(package,szCreateShortcuts,row);
4854 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4855 &IID_IShellLinkW, (LPVOID *) &sl );
4859 ERR("Is IID_IShellLink\n");
4860 msiobj_release(&row->hdr);
4864 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4867 ERR("Is IID_IPersistFile\n");
4868 msiobj_release(&row->hdr);
4873 MSI_RecordGetStringW(row,2,buffer,&sz);
4874 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4876 /* may be needed because of a bug somehwere else */
4877 create_full_pathW(target_folder);
4880 MSI_RecordGetStringW(row,3,buffer,&sz);
4881 reduce_to_longfilename(buffer);
4882 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4883 strcatW(buffer,szlnk);
4884 target_file = build_directory_name(2, target_folder, buffer);
4885 HeapFree(GetProcessHeap(),0,target_folder);
4888 MSI_RecordGetStringW(row,5,buffer,&sz);
4889 if (strchrW(buffer,'['))
4892 deformat_string(package,buffer,&deformated);
4893 IShellLinkW_SetPath(sl,deformated);
4894 HeapFree(GetProcessHeap(),0,deformated);
4899 FIXME("poorly handled shortcut format, advertised shortcut\n");
4900 keypath = strdupW(package->components[index].FullKeypath);
4901 IShellLinkW_SetPath(sl,keypath);
4902 HeapFree(GetProcessHeap(),0,keypath);
4905 if (!MSI_RecordIsNull(row,6))
4909 MSI_RecordGetStringW(row,6,buffer,&sz);
4910 deformat_string(package,buffer,&deformated);
4911 IShellLinkW_SetArguments(sl,deformated);
4912 HeapFree(GetProcessHeap(),0,deformated);
4915 if (!MSI_RecordIsNull(row,7))
4918 deformated = load_dynamic_stringW(row,7);
4919 IShellLinkW_SetDescription(sl,deformated);
4920 HeapFree(GetProcessHeap(),0,deformated);
4923 if (!MSI_RecordIsNull(row,8))
4924 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4926 if (!MSI_RecordIsNull(row,9))
4932 MSI_RecordGetStringW(row,9,buffer,&sz);
4934 build_icon_path(package,buffer,&Path);
4935 index = MSI_RecordGetInteger(row,10);
4937 IShellLinkW_SetIconLocation(sl,Path,index);
4938 HeapFree(GetProcessHeap(),0,Path);
4941 if (!MSI_RecordIsNull(row,11))
4942 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4944 if (!MSI_RecordIsNull(row,12))
4948 MSI_RecordGetStringW(row,12,buffer,&sz);
4949 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
4950 IShellLinkW_SetWorkingDirectory(sl,Path);
4951 HeapFree(GetProcessHeap(), 0, Path);
4954 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4955 IPersistFile_Save(pf,target_file,FALSE);
4957 HeapFree(GetProcessHeap(),0,target_file);
4959 IPersistFile_Release( pf );
4960 IShellLinkW_Release( sl );
4962 msiobj_release(&row->hdr);
4964 MSI_ViewClose(view);
4965 msiobj_release(&view->hdr);
4975 * 99% of the work done here is only done for
4976 * advertised installs. However this is where the
4977 * Icon table is processed and written out
4978 * so that is what I am going to do here.
4980 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4984 MSIRECORD * row = 0;
4985 static const WCHAR Query[]=
4986 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4989 /* for registry stuff */
4993 static const WCHAR szProductName[] =
4994 {'P','r','o','d','u','c','t','N','a','m','e',0};
4995 static const WCHAR szPackageCode[] =
4996 {'P','a','c','k','a','g','e','C','o','d','e',0};
4999 MSIHANDLE hDb, hSumInfo;
5002 return ERROR_INVALID_HANDLE;
5004 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5005 if (rc != ERROR_SUCCESS)
5008 rc = MSI_ViewExecute(view, 0);
5009 if (rc != ERROR_SUCCESS)
5011 MSI_ViewClose(view);
5012 msiobj_release(&view->hdr);
5019 WCHAR *FilePath=NULL;
5020 WCHAR *FileName=NULL;
5023 rc = MSI_ViewFetch(view,&row);
5024 if (rc != ERROR_SUCCESS)
5030 FileName = load_dynamic_stringW(row,1);
5033 ERR("Unable to get FileName\n");
5034 msiobj_release(&row->hdr);
5038 build_icon_path(package,FileName,&FilePath);
5040 HeapFree(GetProcessHeap(),0,FileName);
5042 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
5044 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
5045 FILE_ATTRIBUTE_NORMAL, NULL);
5047 if (the_file == INVALID_HANDLE_VALUE)
5049 ERR("Unable to create file %s\n",debugstr_w(FilePath));
5050 msiobj_release(&row->hdr);
5051 HeapFree(GetProcessHeap(),0,FilePath);
5059 rc = MSI_RecordReadStream(row,2,buffer,&sz);
5060 if (rc != ERROR_SUCCESS)
5062 ERR("Failed to get stream\n");
5063 CloseHandle(the_file);
5064 DeleteFileW(FilePath);
5067 WriteFile(the_file,buffer,sz,&write,NULL);
5068 } while (sz == 1024);
5070 HeapFree(GetProcessHeap(),0,FilePath);
5072 CloseHandle(the_file);
5073 msiobj_release(&row->hdr);
5075 MSI_ViewClose(view);
5076 msiobj_release(&view->hdr);
5079 /* ok there is a lot more done here but i need to figure out what */
5080 productcode = load_dynamic_property(package,szProductCode,&rc);
5084 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
5085 if (rc != ERROR_SUCCESS)
5088 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5089 if (rc != ERROR_SUCCESS)
5093 buffer = load_dynamic_property(package,szProductName,NULL);
5094 size = strlenW(buffer)*sizeof(WCHAR);
5095 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
5096 HeapFree(GetProcessHeap(),0,buffer);
5097 FIXME("Need to write more keys to the user registry\n");
5099 hDb= alloc_msihandle( &package->db->hdr );
5100 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
5101 MsiCloseHandle(hDb);
5102 if (rc == ERROR_SUCCESS)
5104 WCHAR guidbuffer[0x200];
5106 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
5108 if (rc == ERROR_SUCCESS)
5110 WCHAR squashed[GUID_SIZE];
5111 /* for now we only care about the first guid */
5112 LPWSTR ptr = strchrW(guidbuffer,';');
5114 squash_guid(guidbuffer,squashed);
5115 size = strlenW(squashed)*sizeof(WCHAR);
5116 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
5121 ERR("Unable to query Revision_Number... \n");
5124 MsiCloseHandle(hSumInfo);
5128 ERR("Unable to open Summary Information\n");
5134 HeapFree(GetProcessHeap(),0,productcode);
5141 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
5145 MSIRECORD * row = 0;
5146 static const WCHAR ExecSeqQuery[] =
5147 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5148 'I','n','i','F','i','l','e',0};
5149 static const WCHAR szWindowsFolder[] =
5150 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
5152 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5153 if (rc != ERROR_SUCCESS)
5155 TRACE("no IniFile table\n");
5156 return ERROR_SUCCESS;
5159 rc = MSI_ViewExecute(view, 0);
5160 if (rc != ERROR_SUCCESS)
5162 MSI_ViewClose(view);
5163 msiobj_release(&view->hdr);
5169 LPWSTR component,filename,dirproperty,section,key,value,identifier;
5170 LPWSTR deformated_section, deformated_key, deformated_value;
5171 LPWSTR folder, fullname = NULL;
5173 INT component_index,action;
5175 rc = MSI_ViewFetch(view,&row);
5176 if (rc != ERROR_SUCCESS)
5182 component = load_dynamic_stringW(row, 8);
5183 component_index = get_loaded_component(package,component);
5184 HeapFree(GetProcessHeap(),0,component);
5186 if (!ACTION_VerifyComponentForAction(package, component_index,
5187 INSTALLSTATE_LOCAL))
5189 TRACE("Skipping ini file due to disabled component\n");
5190 msiobj_release(&row->hdr);
5192 package->components[component_index].Action =
5193 package->components[component_index].Installed;
5198 package->components[component_index].Action = INSTALLSTATE_LOCAL;
5200 identifier = load_dynamic_stringW(row,1);
5201 filename = load_dynamic_stringW(row,2);
5202 dirproperty = load_dynamic_stringW(row,3);
5203 section = load_dynamic_stringW(row,4);
5204 key = load_dynamic_stringW(row,5);
5205 value = load_dynamic_stringW(row,6);
5206 action = MSI_RecordGetInteger(row,7);
5208 deformat_string(package,section,&deformated_section);
5209 deformat_string(package,key,&deformated_key);
5210 deformat_string(package,value,&deformated_value);
5214 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
5216 folder = load_dynamic_property(package,dirproperty,NULL);
5219 folder = load_dynamic_property(package, szWindowsFolder, NULL);
5223 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
5227 fullname = build_directory_name(3, folder, filename, NULL);
5231 TRACE("Adding value %s to section %s in %s\n",
5232 debugstr_w(deformated_key), debugstr_w(deformated_section),
5233 debugstr_w(fullname));
5234 WritePrivateProfileStringW(deformated_section, deformated_key,
5235 deformated_value, fullname);
5237 else if (action == 1)
5240 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
5241 returned, 10, fullname);
5242 if (returned[0] == 0)
5244 TRACE("Adding value %s to section %s in %s\n",
5245 debugstr_w(deformated_key), debugstr_w(deformated_section),
5246 debugstr_w(fullname));
5248 WritePrivateProfileStringW(deformated_section, deformated_key,
5249 deformated_value, fullname);
5252 else if (action == 3)
5254 FIXME("Append to existing section not yet implemented\n");
5257 uirow = MSI_CreateRecord(4);
5258 MSI_RecordSetStringW(uirow,1,identifier);
5259 MSI_RecordSetStringW(uirow,2,deformated_section);
5260 MSI_RecordSetStringW(uirow,3,deformated_key);
5261 MSI_RecordSetStringW(uirow,4,deformated_value);
5262 ui_actiondata(package,szWriteIniValues,uirow);
5263 msiobj_release( &uirow->hdr );
5265 HeapFree(GetProcessHeap(),0,identifier);
5266 HeapFree(GetProcessHeap(),0,fullname);
5267 HeapFree(GetProcessHeap(),0,filename);
5268 HeapFree(GetProcessHeap(),0,key);
5269 HeapFree(GetProcessHeap(),0,value);
5270 HeapFree(GetProcessHeap(),0,section);
5271 HeapFree(GetProcessHeap(),0,dirproperty);
5272 HeapFree(GetProcessHeap(),0,folder);
5273 HeapFree(GetProcessHeap(),0,deformated_key);
5274 HeapFree(GetProcessHeap(),0,deformated_value);
5275 HeapFree(GetProcessHeap(),0,deformated_section);
5276 msiobj_release(&row->hdr);
5278 MSI_ViewClose(view);
5279 msiobj_release(&view->hdr);
5283 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
5287 MSIRECORD * row = 0;
5288 static const WCHAR ExecSeqQuery[] =
5289 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5290 'S','e','l','f','R','e','g',0};
5292 static const WCHAR ExeStr[] =
5293 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ',0};
5295 PROCESS_INFORMATION info;
5298 memset(&si,0,sizeof(STARTUPINFOW));
5300 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5301 if (rc != ERROR_SUCCESS)
5303 TRACE("no SelfReg table\n");
5304 return ERROR_SUCCESS;
5307 rc = MSI_ViewExecute(view, 0);
5308 if (rc != ERROR_SUCCESS)
5310 MSI_ViewClose(view);
5311 msiobj_release(&view->hdr);
5321 rc = MSI_ViewFetch(view,&row);
5322 if (rc != ERROR_SUCCESS)
5328 filename = load_dynamic_stringW(row,1);
5329 index = get_loaded_file(package,filename);
5333 ERR("Unable to find file id %s\n",debugstr_w(filename));
5334 HeapFree(GetProcessHeap(),0,filename);
5335 msiobj_release(&row->hdr);
5338 HeapFree(GetProcessHeap(),0,filename);
5340 len = strlenW(ExeStr);
5341 len += strlenW(package->files[index].TargetPath);
5344 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
5345 strcpyW(filename,ExeStr);
5346 strcatW(filename,package->files[index].TargetPath);
5348 TRACE("Registering %s\n",debugstr_w(filename));
5349 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
5350 c_colon, &si, &info);
5353 msi_dialog_check_messages(package->dialog, info.hProcess);
5355 HeapFree(GetProcessHeap(),0,filename);
5356 msiobj_release(&row->hdr);
5358 MSI_ViewClose(view);
5359 msiobj_release(&view->hdr);
5363 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
5372 return ERROR_INVALID_HANDLE;
5374 productcode = load_dynamic_property(package,szProductCode,&rc);
5378 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
5379 if (rc != ERROR_SUCCESS)
5382 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
5383 if (rc != ERROR_SUCCESS)
5386 /* here the guids are base 85 encoded */
5387 for (i = 0; i < package->loaded_features; i++)
5394 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL))
5397 size = package->features[i].ComponentCount*21;
5399 if (package->features[i].Feature_Parent[0])
5400 size += strlenW(package->features[i].Feature_Parent)+2;
5402 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
5405 for (j = 0; j < package->features[i].ComponentCount; j++)
5408 memset(buf,0,sizeof(buf));
5409 TRACE("From %s\n",debugstr_w(package->components
5410 [package->features[i].Components[j]].ComponentId));
5411 CLSIDFromString(package->components
5412 [package->features[i].Components[j]].ComponentId,
5414 encode_base85_guid(&clsid,buf);
5415 TRACE("to %s\n",debugstr_w(buf));
5418 if (package->features[i].Feature_Parent[0])
5420 static const WCHAR sep[] = {'\2',0};
5422 strcatW(data,package->features[i].Feature_Parent);
5425 size = (strlenW(data)+1)*sizeof(WCHAR);
5426 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
5428 HeapFree(GetProcessHeap(),0,data);
5430 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
5431 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
5432 (LPSTR)package->features[i].Feature_Parent,size);
5438 HeapFree(GetProcessHeap(), 0, productcode);
5442 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
5449 static WCHAR szNONE[] = {0};
5450 static const WCHAR szWindowsInstaler[] =
5451 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
5452 static const WCHAR szPropKeys[][80] =
5454 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
5455 {'A','R','P','C','O','N','T','A','C','T',0},
5456 {'A','R','P','C','O','M','M','E','N','T','S',0},
5457 {'P','r','o','d','u','c','t','N','a','m','e',0},
5458 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
5459 {'A','R','P','H','E','L','P','L','I','N','K',0},
5460 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
5461 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
5462 {'S','o','u','r','c','e','D','i','r',0},
5463 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
5464 {'A','R','P','R','E','A','D','M','E',0},
5465 {'A','R','P','S','I','Z','E',0},
5466 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
5467 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
5471 static const WCHAR szRegKeys[][80] =
5473 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
5474 {'C','o','n','t','a','c','t',0},
5475 {'C','o','m','m','e','n','t','s',0},
5476 {'D','i','s','p','l','a','y','N','a','m','e',0},
5477 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
5478 {'H','e','l','p','L','i','n','k',0},
5479 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
5480 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
5481 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
5482 {'P','u','b','l','i','s','h','e','r',0},
5483 {'R','e','a','d','m','e',0},
5484 {'S','i','z','e',0},
5485 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
5486 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
5490 static const WCHAR installerPathFmt[] = {
5492 'I','n','s','t','a','l','l','e','r','\\',0};
5493 static const WCHAR fmt[] = {
5495 'I','n','s','t','a','l','l','e','r','\\',
5496 '%','x','.','m','s','i',0};
5497 static const WCHAR szLocalPackage[]=
5498 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
5499 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
5503 return ERROR_INVALID_HANDLE;
5505 productcode = load_dynamic_property(package,szProductCode,&rc);
5509 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
5510 if (rc != ERROR_SUCCESS)
5513 /* dump all the info i can grab */
5514 FIXME("Flesh out more information \n");
5517 while (szPropKeys[i][0]!=0)
5519 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
5520 if (rc != ERROR_SUCCESS)
5522 size = strlenW(buffer)*sizeof(WCHAR);
5523 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
5529 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
5531 /* copy the package locally */
5532 num = GetTickCount() & 0xffff;
5536 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
5537 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
5541 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
5542 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
5543 if (handle != INVALID_HANDLE_VALUE)
5545 CloseHandle(handle);
5548 if (GetLastError() != ERROR_FILE_EXISTS &&
5549 GetLastError() != ERROR_SHARING_VIOLATION)
5551 if (!(++num & 0xffff)) num = 1;
5552 sprintfW(packagefile,fmt,num);
5553 } while (num != start);
5555 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
5556 create_full_pathW(path);
5557 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
5558 CopyFileW(package->PackagePath,packagefile,FALSE);
5559 size = strlenW(packagefile)*sizeof(WCHAR);
5560 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
5563 HeapFree(GetProcessHeap(),0,productcode);
5566 return ERROR_SUCCESS;
5569 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
5573 return ERROR_INVALID_HANDLE;
5575 for (i = 0; i < package->DeferredActionCount; i++)
5578 action = package->DeferredAction[i];
5579 ui_actionstart(package, action);
5580 TRACE("Executing Action (%s)\n",debugstr_w(action));
5581 ACTION_CustomAction(package,action,TRUE);
5582 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
5584 HeapFree(GetProcessHeap(),0,package->DeferredAction);
5586 package->DeferredActionCount = 0;
5587 package->DeferredAction = NULL;
5589 return ERROR_SUCCESS;
5592 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
5596 return ERROR_INVALID_HANDLE;
5598 /* first do the same as an InstallExecute */
5599 ACTION_InstallExecute(package);
5601 /* then handle Commit Actions */
5602 for (i = 0; i < package->CommitActionCount; i++)
5605 action = package->CommitAction[i];
5606 ui_actionstart(package, action);
5607 TRACE("Executing Commit Action (%s)\n",debugstr_w(action));
5608 ACTION_CustomAction(package,action,TRUE);
5609 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
5611 HeapFree(GetProcessHeap(),0,package->CommitAction);
5613 package->CommitActionCount = 0;
5614 package->CommitAction = NULL;
5616 return ERROR_SUCCESS;
5619 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
5621 static const WCHAR RunOnce[] = {
5622 'S','o','f','t','w','a','r','e','\\',
5623 'M','i','c','r','o','s','o','f','t','\\',
5624 'W','i','n','d','o','w','s','\\',
5625 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5626 'R','u','n','O','n','c','e',0};
5627 static const WCHAR InstallRunOnce[] = {
5628 'S','o','f','t','w','a','r','e','\\',
5629 'M','i','c','r','o','s','o','f','t','\\',
5630 'W','i','n','d','o','w','s','\\',
5631 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5632 'I','n','s','t','a','l','l','e','r','\\',
5633 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
5635 static const WCHAR msiexec_fmt[] = {
5637 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5638 '\"','%','s','\"',0};
5639 static const WCHAR install_fmt[] = {
5640 '/','I',' ','\"','%','s','\"',' ',
5641 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5642 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5643 WCHAR buffer[256], sysdir[MAX_PATH];
5646 WCHAR squished_pc[100];
5649 static const WCHAR szLUS[] = {
5650 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
5651 static const WCHAR szSourceList[] = {
5652 'S','o','u','r','c','e','L','i','s','t',0};
5653 static const WCHAR szPackageName[] = {
5654 'P','a','c','k','a','g','e','N','a','m','e',0};
5657 return ERROR_INVALID_HANDLE;
5659 productcode = load_dynamic_property(package,szProductCode,&rc);
5663 squash_guid(productcode,squished_pc);
5665 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
5666 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
5667 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
5670 size = strlenW(buffer)*sizeof(WCHAR);
5671 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5674 TRACE("Reboot command %s\n",debugstr_w(buffer));
5676 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
5677 sprintfW(buffer,install_fmt,productcode,squished_pc);
5679 size = strlenW(buffer)*sizeof(WCHAR);
5680 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5683 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5684 if (rc == ERROR_SUCCESS)
5688 RegCreateKeyW(hukey, szSourceList, &hukey2);
5689 buf = load_dynamic_property(package,cszSourceDir,NULL);
5690 size = strlenW(buf)*sizeof(WCHAR);
5691 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
5692 HeapFree(GetProcessHeap(),0,buf);
5694 buf = strrchrW(package->PackagePath,'\\');
5698 size = strlenW(buf)*sizeof(WCHAR);
5699 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
5702 RegCloseKey(hukey2);
5704 HeapFree(GetProcessHeap(),0,productcode);
5706 return ERROR_INSTALL_SUSPEND;
5709 UINT ACTION_ResolveSource(MSIPACKAGE* package)
5712 * we are currently doing what should be done here in the top level Install
5713 * however for Adminastrative and uninstalls this step will be needed
5715 return ERROR_SUCCESS;
5719 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
5723 MSIRECORD * row = 0;
5724 static const WCHAR ExecSeqQuery[] =
5725 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5726 'E','x','t','e','n','s','i','o','n',0};
5727 static const WCHAR szContentType[] =
5728 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
5732 return ERROR_INVALID_HANDLE;
5734 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5735 if (rc != ERROR_SUCCESS)
5741 rc = MSI_ViewExecute(view, 0);
5742 if (rc != ERROR_SUCCESS)
5744 MSI_ViewClose(view);
5745 msiobj_release(&view->hdr);
5751 WCHAR buffer[0x100];
5752 WCHAR extension[257];
5757 rc = MSI_ViewFetch(view,&row);
5758 if (rc != ERROR_SUCCESS)
5765 MSI_RecordGetStringW(row,2,buffer,&sz);
5767 index = get_loaded_component(package,buffer);
5771 msiobj_release(&row->hdr);
5775 if (!ACTION_VerifyComponentForAction(package, index,
5776 INSTALLSTATE_LOCAL))
5778 TRACE("Skipping extension reg due to disabled component\n");
5779 msiobj_release(&row->hdr);
5781 package->components[index].Action =
5782 package->components[index].Installed;
5787 package->components[index].Action = INSTALLSTATE_LOCAL;
5789 exten = load_dynamic_stringW(row,1);
5792 strcatW(extension,exten);
5793 HeapFree(GetProcessHeap(),0,exten);
5795 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
5797 if (!MSI_RecordIsNull(row,4))
5799 LPWSTR mime = load_dynamic_stringW(row,4);
5800 RegSetValueExW(hkey,szContentType,0,REG_SZ,(LPVOID)mime,
5801 (strlenW(mime)+1)*sizeof(WCHAR));
5802 HeapFree(GetProcessHeap(),0,mime);
5805 if (!MSI_RecordIsNull(row,3))
5807 static const WCHAR szSN[] =
5808 {'\\','S','h','e','l','l','N','e','w',0};
5811 LPWSTR progid= load_dynamic_stringW(row,3);
5813 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
5814 (strlenW(progid)+1)*sizeof(WCHAR));
5816 newkey = HeapAlloc(GetProcessHeap(),0,
5817 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
5819 strcpyW(newkey,progid);
5820 strcatW(newkey,szSN);
5821 RegCreateKeyW(hkey,newkey,&hkey2);
5824 HeapFree(GetProcessHeap(),0,progid);
5825 HeapFree(GetProcessHeap(),0,newkey);
5831 ui_actiondata(package,szRegisterExtensionInfo,row);
5833 msiobj_release(&row->hdr);
5835 MSI_ViewClose(view);
5836 msiobj_release(&view->hdr);
5842 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
5846 MSIRECORD * row = 0;
5847 static const WCHAR ExecSeqQuery[] =
5848 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5850 static const WCHAR szExten[] =
5851 {'E','x','t','e','n','s','i','o','n',0 };
5855 return ERROR_INVALID_HANDLE;
5857 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5858 if (rc != ERROR_SUCCESS)
5864 rc = MSI_ViewExecute(view, 0);
5865 if (rc != ERROR_SUCCESS)
5867 MSI_ViewClose(view);
5868 msiobj_release(&view->hdr);
5874 WCHAR extension[257];
5877 static const WCHAR fmt[] =
5878 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
5879 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
5882 rc = MSI_ViewFetch(view,&row);
5883 if (rc != ERROR_SUCCESS)
5889 mime = load_dynamic_stringW(row,1);
5890 exten = load_dynamic_stringW(row,2);
5893 strcatW(extension,exten);
5894 HeapFree(GetProcessHeap(),0,exten);
5896 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
5898 sprintfW(key,fmt,mime);
5899 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
5900 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
5901 (strlenW(extension)+1)*sizeof(WCHAR));
5903 HeapFree(GetProcessHeap(),0,mime);
5904 HeapFree(GetProcessHeap(),0,key);
5906 if (!MSI_RecordIsNull(row,3))
5908 FIXME("Handle non null for field 3\n");
5913 ui_actiondata(package,szRegisterMIMEInfo,row);
5915 msiobj_release(&row->hdr);
5917 MSI_ViewClose(view);
5918 msiobj_release(&view->hdr);
5924 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
5926 static const WCHAR szProductID[]=
5927 {'P','r','o','d','u','c','t','I','D',0};
5935 static const WCHAR szPropKeys[][80] =
5937 {'P','r','o','d','u','c','t','I','D',0},
5938 {'U','S','E','R','N','A','M','E',0},
5939 {'C','O','M','P','A','N','Y','N','A','M','E',0},
5943 static const WCHAR szRegKeys[][80] =
5945 {'P','r','o','d','u','c','t','I','D',0},
5946 {'R','e','g','O','w','n','e','r',0},
5947 {'R','e','g','C','o','m','p','a','n','y',0},
5952 return ERROR_INVALID_HANDLE;
5954 productid = load_dynamic_property(package,szProductID,&rc);
5956 return ERROR_SUCCESS;
5958 productcode = load_dynamic_property(package,szProductCode,&rc);
5962 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
5963 if (rc != ERROR_SUCCESS)
5967 while (szPropKeys[i][0]!=0)
5969 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
5970 if (rc == ERROR_SUCCESS)
5972 size = strlenW(buffer)*sizeof(WCHAR);
5973 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
5979 HeapFree(GetProcessHeap(),0,productcode);
5980 HeapFree(GetProcessHeap(),0,productid);
5983 return ERROR_SUCCESS;
5987 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
5990 rc = ACTION_ProcessExecSequence(package,TRUE);
5996 * Code based off of code located here
5997 * http://www.codeproject.com/gdi/fontnamefromfile.asp
5999 * Using string index 4 (full font name) instead of 1 (family name)
6001 static LPWSTR load_ttfname_from(LPCWSTR filename)
6007 typedef struct _tagTT_OFFSET_TABLE{
6008 USHORT uMajorVersion;
6009 USHORT uMinorVersion;
6010 USHORT uNumOfTables;
6011 USHORT uSearchRange;
6012 USHORT uEntrySelector;
6016 typedef struct _tagTT_TABLE_DIRECTORY{
6017 char szTag[4]; /* table name */
6018 ULONG uCheckSum; /* Check sum */
6019 ULONG uOffset; /* Offset from beginning of file */
6020 ULONG uLength; /* length of the table in bytes */
6021 }TT_TABLE_DIRECTORY;
6023 typedef struct _tagTT_NAME_TABLE_HEADER{
6024 USHORT uFSelector; /* format selector. Always 0 */
6025 USHORT uNRCount; /* Name Records count */
6026 USHORT uStorageOffset; /* Offset for strings storage,
6027 * from start of the table */
6028 }TT_NAME_TABLE_HEADER;
6030 typedef struct _tagTT_NAME_RECORD{
6035 USHORT uStringLength;
6036 USHORT uStringOffset; /* from start of storage area */
6039 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
6040 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
6042 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
6043 FILE_ATTRIBUTE_NORMAL, 0 );
6044 if (handle != INVALID_HANDLE_VALUE)
6046 TT_TABLE_DIRECTORY tblDir;
6047 BOOL bFound = FALSE;
6048 TT_OFFSET_TABLE ttOffsetTable;
6050 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
6051 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
6052 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
6053 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
6055 if (ttOffsetTable.uMajorVersion != 1 ||
6056 ttOffsetTable.uMinorVersion != 0)
6059 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
6061 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
6062 if (strncmp(tblDir.szTag,"name",4)==0)
6065 tblDir.uLength = SWAPLONG(tblDir.uLength);
6066 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
6073 TT_NAME_TABLE_HEADER ttNTHeader;
6074 TT_NAME_RECORD ttRecord;
6076 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
6077 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
6080 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
6081 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
6083 for(i=0; i<ttNTHeader.uNRCount; i++)
6085 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
6086 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
6087 /* 4 is the Full Font Name */
6088 if(ttRecord.uNameID == 4)
6092 static const LPSTR tt = " (TrueType)";
6094 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
6095 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
6096 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
6097 SetFilePointer(handle, tblDir.uOffset +
6098 ttRecord.uStringOffset +
6099 ttNTHeader.uStorageOffset,
6101 buf = HeapAlloc(GetProcessHeap(), 0,
6102 ttRecord.uStringLength + 1 + strlen(tt));
6103 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
6104 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
6105 if (strlen(buf) > 0)
6108 ret = strdupAtoW(buf);
6109 HeapFree(GetProcessHeap(),0,buf);
6113 HeapFree(GetProcessHeap(),0,buf);
6114 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
6118 CloseHandle(handle);
6121 TRACE("Returning fontname %s\n",debugstr_w(ret));
6125 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
6129 MSIRECORD * row = 0;
6130 static const WCHAR ExecSeqQuery[] =
6131 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6133 static const WCHAR regfont1[] =
6134 {'S','o','f','t','w','a','r','e','\\',
6135 'M','i','c','r','o','s','o','f','t','\\',
6136 'W','i','n','d','o','w','s',' ','N','T','\\',
6137 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6138 'F','o','n','t','s',0};
6139 static const WCHAR regfont2[] =
6140 {'S','o','f','t','w','a','r','e','\\',
6141 'M','i','c','r','o','s','o','f','t','\\',
6142 'W','i','n','d','o','w','s','\\',
6143 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6144 'F','o','n','t','s',0};
6148 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6149 if (rc != ERROR_SUCCESS)
6152 rc = MSI_ViewExecute(view, 0);
6153 if (rc != ERROR_SUCCESS)
6155 MSI_ViewClose(view);
6156 msiobj_release(&view->hdr);
6160 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
6161 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
6170 rc = MSI_ViewFetch(view,&row);
6171 if (rc != ERROR_SUCCESS)
6177 file = load_dynamic_stringW(row,1);
6178 index = get_loaded_file(package,file);
6181 ERR("Unable to load file\n");
6182 HeapFree(GetProcessHeap(),0,file);
6186 /* check to make sure that component is installed */
6187 if (!ACTION_VerifyComponentForAction(package,
6188 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
6190 TRACE("Skipping: Component not scheduled for install\n");
6191 HeapFree(GetProcessHeap(),0,file);
6193 msiobj_release(&row->hdr);
6198 if (MSI_RecordIsNull(row,2))
6199 name = load_ttfname_from(package->files[index].TargetPath);
6201 name = load_dynamic_stringW(row,2);
6205 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
6206 RegSetValueExW(hkey1,name,0,REG_SZ,
6207 (LPBYTE)package->files[index].FileName,size);
6208 RegSetValueExW(hkey2,name,0,REG_SZ,
6209 (LPBYTE)package->files[index].FileName,size);
6212 HeapFree(GetProcessHeap(),0,file);
6213 HeapFree(GetProcessHeap(),0,name);
6214 msiobj_release(&row->hdr);
6216 MSI_ViewClose(view);
6217 msiobj_release(&view->hdr);
6225 /* Msi functions that seem appropriate here */
6226 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
6231 TRACE(" exteral attempt at action %s\n",szAction);
6234 return ERROR_FUNCTION_FAILED;
6236 return ERROR_FUNCTION_FAILED;
6238 szwAction = strdupAtoW(szAction);
6241 return ERROR_FUNCTION_FAILED;
6244 rc = MsiDoActionW(hInstall, szwAction);
6245 HeapFree(GetProcessHeap(),0,szwAction);
6249 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
6251 MSIPACKAGE *package;
6252 UINT ret = ERROR_INVALID_HANDLE;
6254 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
6256 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6259 ret = ACTION_PerformUIAction(package,szAction);
6260 msiobj_release( &package->hdr );
6265 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
6266 LPSTR szPathBuf, DWORD* pcchPathBuf)
6272 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
6275 return ERROR_FUNCTION_FAILED;
6277 return ERROR_FUNCTION_FAILED;
6279 szwFolder = strdupAtoW(szFolder);
6282 return ERROR_FUNCTION_FAILED;
6284 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
6286 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
6288 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
6289 *pcchPathBuf, NULL, NULL );
6291 HeapFree(GetProcessHeap(),0,szwFolder);
6292 HeapFree(GetProcessHeap(),0,szwPathBuf);
6297 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
6298 szPathBuf, DWORD* pcchPathBuf)
6301 UINT rc = ERROR_FUNCTION_FAILED;
6302 MSIPACKAGE *package;
6304 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
6306 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6308 return ERROR_INVALID_HANDLE;
6309 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
6310 msiobj_release( &package->hdr );
6312 if (path && (strlenW(path) > *pcchPathBuf))
6314 *pcchPathBuf = strlenW(path)+1;
6315 rc = ERROR_MORE_DATA;
6319 *pcchPathBuf = strlenW(path)+1;
6320 strcpyW(szPathBuf,path);
6321 TRACE("Returning Path %s\n",debugstr_w(path));
6324 HeapFree(GetProcessHeap(),0,path);
6330 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
6331 LPSTR szPathBuf, DWORD* pcchPathBuf)
6337 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
6340 return ERROR_FUNCTION_FAILED;
6342 return ERROR_FUNCTION_FAILED;
6344 szwFolder = strdupAtoW(szFolder);
6346 return ERROR_FUNCTION_FAILED;
6348 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
6350 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
6352 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
6353 *pcchPathBuf, NULL, NULL );
6355 HeapFree(GetProcessHeap(),0,szwFolder);
6356 HeapFree(GetProcessHeap(),0,szwPathBuf);
6361 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
6362 szPathBuf, DWORD* pcchPathBuf)
6365 UINT rc = ERROR_FUNCTION_FAILED;
6366 MSIPACKAGE *package;
6368 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
6370 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6372 return ERROR_INVALID_HANDLE;
6373 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
6374 msiobj_release( &package->hdr );
6376 if (path && strlenW(path) > *pcchPathBuf)
6378 *pcchPathBuf = strlenW(path)+1;
6379 rc = ERROR_MORE_DATA;
6383 *pcchPathBuf = strlenW(path)+1;
6384 strcpyW(szPathBuf,path);
6385 TRACE("Returning Path %s\n",debugstr_w(path));
6388 HeapFree(GetProcessHeap(),0,path);
6394 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
6395 LPCSTR szFolderPath)
6398 LPWSTR szwFolderPath;
6402 return ERROR_FUNCTION_FAILED;
6404 return ERROR_FUNCTION_FAILED;
6406 szwFolder = strdupAtoW(szFolder);
6408 return ERROR_FUNCTION_FAILED;
6410 szwFolderPath = strdupAtoW(szFolderPath);
6413 HeapFree(GetProcessHeap(),0,szwFolder);
6414 return ERROR_FUNCTION_FAILED;
6417 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
6419 HeapFree(GetProcessHeap(),0,szwFolder);
6420 HeapFree(GetProcessHeap(),0,szwFolderPath);
6425 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
6426 LPCWSTR szFolderPath)
6430 LPWSTR path2 = NULL;
6433 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
6436 return ERROR_INVALID_HANDLE;
6438 if (szFolderPath[0]==0)
6439 return ERROR_FUNCTION_FAILED;
6441 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
6442 return ERROR_FUNCTION_FAILED;
6444 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
6447 return ERROR_INVALID_PARAMETER;
6449 HeapFree(GetProcessHeap(),0,folder->Property);
6450 folder->Property = build_directory_name(2, szFolderPath, NULL);
6452 if (strcmpiW(path, folder->Property) == 0)
6455 * Resolved Target has not really changed, so just
6456 * set this folder and do not recalculate everything.
6458 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
6459 folder->ResolvedTarget = NULL;
6460 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
6461 HeapFree(GetProcessHeap(),0,path2);
6465 for (i = 0; i < package->loaded_folders; i++)
6467 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
6468 package->folders[i].ResolvedTarget=NULL;
6471 for (i = 0; i < package->loaded_folders; i++)
6473 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
6475 HeapFree(GetProcessHeap(),0,path2);
6478 HeapFree(GetProcessHeap(),0,path);
6480 return ERROR_SUCCESS;
6483 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
6484 LPCWSTR szFolderPath)
6486 MSIPACKAGE *package;
6489 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
6491 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6492 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
6493 msiobj_release( &package->hdr );
6497 /***********************************************************************
6498 * MsiGetMode (MSI.@)
6500 * Returns an internal installer state (if it is running in a mode iRunMode)
6503 * hInstall [I] Handle to the installation
6504 * hRunMode [I] Checking run mode
6505 * MSIRUNMODE_ADMIN Administrative mode
6506 * MSIRUNMODE_ADVERTISE Advertisement mode
6507 * MSIRUNMODE_MAINTENANCE Maintenance mode
6508 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
6509 * MSIRUNMODE_LOGENABLED Log file is writing
6510 * MSIRUNMODE_OPERATIONS Operations in progress??
6511 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
6512 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
6513 * MSIRUNMODE_CABINET Files from cabinet are installed
6514 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
6515 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
6516 * MSIRUNMODE_RESERVED11 Reserved
6517 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
6518 * MSIRUNMODE_ZAWENABLED Demand installation is supported
6519 * MSIRUNMODE_RESERVED14 Reserved
6520 * MSIRUNMODE_RESERVED15 Reserved
6521 * MSIRUNMODE_SCHEDULED called from install script
6522 * MSIRUNMODE_ROLLBACK called from rollback script
6523 * MSIRUNMODE_COMMIT called from commit script
6526 * In the state: TRUE
6527 * Not in the state: FALSE
6531 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
6533 FIXME("STUB (iRunMode=%i)\n",iRunMode);
6538 * According to the docs, when this is called it immediately recalculates
6539 * all the component states as well
6541 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
6542 INSTALLSTATE iState)
6544 LPWSTR szwFeature = NULL;
6547 szwFeature = strdupAtoW(szFeature);
6550 return ERROR_FUNCTION_FAILED;
6552 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
6554 HeapFree(GetProcessHeap(),0,szwFeature);
6559 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
6560 INSTALLSTATE iState)
6562 MSIPACKAGE* package;
6564 UINT rc = ERROR_SUCCESS;
6566 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
6568 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6570 return ERROR_INVALID_HANDLE;
6572 index = get_loaded_feature(package,szFeature);
6575 rc = ERROR_UNKNOWN_FEATURE;
6579 package->features[index].ActionRequest= iState;
6580 ACTION_UpdateComponentStates(package,szFeature);
6583 msiobj_release( &package->hdr );
6587 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
6588 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6590 LPWSTR szwFeature = NULL;
6593 szwFeature = strdupAtoW(szFeature);
6595 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
6597 HeapFree( GetProcessHeap(), 0 , szwFeature);
6602 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
6603 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6607 index = get_loaded_feature(package,szFeature);
6609 return ERROR_UNKNOWN_FEATURE;
6612 *piInstalled = package->features[index].Installed;
6615 *piAction = package->features[index].Action;
6617 TRACE("returning %i %i\n",*piInstalled,*piAction);
6619 return ERROR_SUCCESS;
6622 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
6623 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6625 MSIPACKAGE* package;
6628 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
6631 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6633 return ERROR_INVALID_HANDLE;
6634 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
6635 msiobj_release( &package->hdr );
6639 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
6640 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6642 LPWSTR szwComponent= NULL;
6645 szwComponent= strdupAtoW(szComponent);
6647 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
6649 HeapFree( GetProcessHeap(), 0 , szwComponent);
6654 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
6655 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6659 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
6662 index = get_loaded_component(package,szComponent);
6664 return ERROR_UNKNOWN_COMPONENT;
6667 *piInstalled = package->components[index].Installed;
6670 *piAction = package->components[index].Action;
6672 TRACE("states (%i, %i)\n",
6673 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
6675 return ERROR_SUCCESS;
6678 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
6679 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6681 MSIPACKAGE* package;
6684 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
6685 piInstalled, piAction);
6687 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6689 return ERROR_INVALID_HANDLE;
6690 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
6691 msiobj_release( &package->hdr );
6696 static UINT ACTION_Template(MSIPACKAGE *package)
6700 MSIRECORD * row = 0;
6701 static const WCHAR ExecSeqQuery[] = {0};
6703 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6704 if (rc != ERROR_SUCCESS)
6707 rc = MSI_ViewExecute(view, 0);
6708 if (rc != ERROR_SUCCESS)
6710 MSI_ViewClose(view);
6711 msiobj_release(&view->hdr);
6717 rc = MSI_ViewFetch(view,&row);
6718 if (rc != ERROR_SUCCESS)
6724 msiobj_release(&row->hdr);
6726 MSI_ViewClose(view);
6727 msiobj_release(&view->hdr);