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 memcpy(prop,ptr,len*sizeof(WCHAR));
931 while (*ptr && (quote || (!quote && *ptr!=' ')))
944 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
945 memcpy(val,ptr2,len*sizeof(WCHAR));
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);
4031 BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
4032 LPWSTR lpszName, LONG_PTR lParam)
4035 typelib_struct *tl_struct = (typelib_struct*) lParam;
4036 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
4040 if (!IS_INTRESOURCE(lpszName))
4042 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
4046 sz = strlenW(tl_struct->source)+4;
4047 sz *= sizeof(WCHAR);
4049 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
4050 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
4052 TRACE("trying %s\n", debugstr_w(tl_struct->path));
4053 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
4054 if (!SUCCEEDED(res))
4056 HeapFree(GetProcessHeap(),0,tl_struct->path);
4057 tl_struct->path = NULL;
4062 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
4063 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
4065 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4069 HeapFree(GetProcessHeap(),0,tl_struct->path);
4070 tl_struct->path = NULL;
4072 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4073 ITypeLib_Release(tl_struct->ptLib);
4078 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4081 * OK this is a bit confusing.. I am given a _Component key and I believe
4082 * that the file that is being registered as a type library is the "key file
4083 * of that component" which I interpret to mean "The file in the KeyPath of
4088 MSIRECORD * row = 0;
4089 static const WCHAR Query[] =
4090 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4091 'T','y','p','e','L','i','b',0};
4094 return ERROR_INVALID_HANDLE;
4096 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4097 if (rc != ERROR_SUCCESS)
4098 return ERROR_SUCCESS;
4100 rc = MSI_ViewExecute(view, 0);
4101 if (rc != ERROR_SUCCESS)
4103 MSI_ViewClose(view);
4104 msiobj_release(&view->hdr);
4110 WCHAR component[0x100];
4114 typelib_struct tl_struct;
4116 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
4118 rc = MSI_ViewFetch(view,&row);
4119 if (rc != ERROR_SUCCESS)
4126 MSI_RecordGetStringW(row,3,component,&sz);
4128 index = get_loaded_component(package,component);
4131 msiobj_release(&row->hdr);
4135 if (!ACTION_VerifyComponentForAction(package, index,
4136 INSTALLSTATE_LOCAL))
4138 TRACE("Skipping typelib reg due to disabled component\n");
4139 msiobj_release(&row->hdr);
4141 package->components[index].Action =
4142 package->components[index].Installed;
4147 package->components[index].Action = INSTALLSTATE_LOCAL;
4149 index = get_loaded_file(package,package->components[index].KeyPath);
4153 msiobj_release(&row->hdr);
4157 guid = load_dynamic_stringW(row,1);
4158 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
4159 LOAD_LIBRARY_AS_DATAFILE);
4162 CLSIDFromString(guid, &tl_struct.clsid);
4163 tl_struct.source = strdupW(package->files[index].TargetPath);
4164 tl_struct.path = NULL;
4166 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
4167 (LONG_PTR)&tl_struct);
4169 if (tl_struct.path != NULL)
4172 WCHAR helpid[0x100];
4176 MSI_RecordGetStringW(row,6,helpid,&sz);
4178 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4179 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
4180 HeapFree(GetProcessHeap(),0,help);
4182 if (!SUCCEEDED(res))
4183 ERR("Failed to register type library %s\n",
4184 debugstr_w(tl_struct.path));
4187 ui_actiondata(package,szRegisterTypeLibraries,row);
4189 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
4192 ITypeLib_Release(tl_struct.ptLib);
4193 HeapFree(GetProcessHeap(),0,tl_struct.path);
4196 ERR("Failed to load type library %s\n",
4197 debugstr_w(tl_struct.source));
4199 FreeLibrary(module);
4200 HeapFree(GetProcessHeap(),0,tl_struct.source);
4203 ERR("Could not load file! %s\n",
4204 debugstr_w(package->files[index].TargetPath));
4205 msiobj_release(&row->hdr);
4207 MSI_ViewClose(view);
4208 msiobj_release(&view->hdr);
4212 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
4214 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4217 MSIRECORD * row = 0;
4218 static const WCHAR ExecSeqQuery[] =
4219 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4220 'A','p','p','I' ,'d',' ','w','h','e','r','e',' ',
4221 'A','p','p','I','d','=','`','%','s','`',0};
4226 return ERROR_INVALID_HANDLE;
4228 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
4229 if (rc != ERROR_SUCCESS)
4232 rc = MSI_ViewExecute(view, 0);
4233 if (rc != ERROR_SUCCESS)
4235 MSI_ViewClose(view);
4236 msiobj_release(&view->hdr);
4240 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
4241 RegCreateKeyW(hkey2,clsid,&hkey3);
4242 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
4243 (strlenW(app)+1)*sizeof(WCHAR));
4245 rc = MSI_ViewFetch(view,&row);
4246 if (rc != ERROR_SUCCESS)
4248 MSI_ViewClose(view);
4249 msiobj_release(&view->hdr);
4253 if (!MSI_RecordIsNull(row,2))
4255 LPWSTR deformated=0;
4257 static const WCHAR szRemoteServerName[] =
4258 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
4260 buffer = load_dynamic_stringW(row,2);
4261 size = deformat_string(package,buffer,&deformated);
4262 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
4264 HeapFree(GetProcessHeap(),0,deformated);
4265 HeapFree(GetProcessHeap(),0,buffer);
4268 if (!MSI_RecordIsNull(row,3))
4270 static const WCHAR szLocalService[] =
4271 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
4273 buffer = load_dynamic_stringW(row,3);
4274 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4275 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
4276 HeapFree(GetProcessHeap(),0,buffer);
4279 if (!MSI_RecordIsNull(row,4))
4281 static const WCHAR szService[] =
4282 {'S','e','r','v','i','c','e',
4283 'P','a','r','a','m','e','t','e','r','s',0};
4285 buffer = load_dynamic_stringW(row,4);
4286 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4287 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
4288 HeapFree(GetProcessHeap(),0,buffer);
4291 if (!MSI_RecordIsNull(row,5))
4293 static const WCHAR szDLL[] =
4294 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
4296 buffer = load_dynamic_stringW(row,5);
4297 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4298 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
4299 HeapFree(GetProcessHeap(),0,buffer);
4302 if (!MSI_RecordIsNull(row,6))
4304 static const WCHAR szActivate[] =
4305 {'A','c','t','i','v','a','t','e','A','s',
4306 'S','t','o','r','a','g','e',0};
4307 static const WCHAR szY[] = {'Y',0};
4309 if (MSI_RecordGetInteger(row,6))
4310 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
4313 if (!MSI_RecordIsNull(row,7))
4315 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
4316 static const WCHAR szUser[] =
4317 {'I','n','t','e','r','a','c','t','i','v','e',' ',
4320 if (MSI_RecordGetInteger(row,7))
4321 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
4324 msiobj_release(&row->hdr);
4325 MSI_ViewClose(view);
4326 msiobj_release(&view->hdr);
4332 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
4335 * Again I am assuming the words, "Whose key file represents" when referring
4336 * to a Component as to meaning that Components KeyPath file
4338 * Also there is a very strong connection between ClassInfo and ProgID
4339 * that I am mostly glossing over.
4340 * What would be more propper is to load the ClassInfo and the ProgID info
4341 * into memory data structures and then be able to enable and disable them
4342 * based on component.
4347 MSIRECORD * row = 0;
4348 static const WCHAR ExecSeqQuery[] =
4349 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4350 'C','l','a','s','s',0};
4351 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4352 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
4353 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4354 static const WCHAR szSpace[] = {' ',0};
4355 HKEY hkey,hkey2,hkey3;
4356 LPWSTR argument,deformated;
4359 return ERROR_INVALID_HANDLE;
4361 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
4362 if (rc != ERROR_SUCCESS)
4363 return ERROR_FUNCTION_FAILED;
4365 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4366 if (rc != ERROR_SUCCESS)
4372 rc = MSI_ViewExecute(view, 0);
4373 if (rc != ERROR_SUCCESS)
4375 MSI_ViewClose(view);
4376 msiobj_release(&view->hdr);
4383 WCHAR buffer[0x100];
4389 rc = MSI_ViewFetch(view,&row);
4390 if (rc != ERROR_SUCCESS)
4397 MSI_RecordGetStringW(row,3,buffer,&sz);
4399 index = get_loaded_component(package,buffer);
4403 msiobj_release(&row->hdr);
4407 if (!ACTION_VerifyComponentForAction(package, index,
4408 INSTALLSTATE_LOCAL))
4410 TRACE("Skipping class reg due to disabled component\n");
4411 msiobj_release(&row->hdr);
4413 package->components[index].Action =
4414 package->components[index].Installed;
4419 package->components[index].Action = INSTALLSTATE_LOCAL;
4422 MSI_RecordGetStringW(row,1,clsid,&sz);
4423 RegCreateKeyW(hkey,clsid,&hkey2);
4425 if (!MSI_RecordIsNull(row,5))
4428 MSI_RecordGetStringW(row,5,desc,&sz);
4430 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
4431 (strlenW(desc)+1)*sizeof(WCHAR));
4437 MSI_RecordGetStringW(row,2,buffer,&sz);
4439 RegCreateKeyW(hkey2,buffer,&hkey3);
4441 index = get_loaded_file(package,package->components[index].KeyPath);
4443 argument = load_dynamic_stringW(row,11);
4444 size = deformat_string(package,argument,&deformated);
4446 size+=sizeof(WCHAR);
4447 HeapFree(GetProcessHeap(),0,argument);
4448 size += (strlenW(package->files[index].TargetPath))*sizeof(WCHAR);
4450 argument = HeapAlloc(GetProcessHeap(),0,size+sizeof(WCHAR));
4451 strcpyW(argument,package->files[index].TargetPath);
4454 strcatW(argument,szSpace);
4455 strcatW(argument,deformated);
4458 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4459 HeapFree(GetProcessHeap(),0,deformated);
4460 HeapFree(GetProcessHeap(),0,argument);
4464 if (!MSI_RecordIsNull(row,4))
4467 MSI_RecordGetStringW(row,4,buffer,&sz);
4469 RegCreateKeyW(hkey2,szProgID,&hkey3);
4471 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4472 (strlenW(buffer)+1)*sizeof(WCHAR));
4477 if (!MSI_RecordIsNull(row,6))
4480 MSI_RecordGetStringW(row,6,buffer,&sz);
4482 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4483 (strlenW(buffer)+1)*sizeof(WCHAR));
4485 register_appid(package,buffer,desc);
4489 if (!MSI_RecordIsNull(row,7))
4491 FIXME("Process field 7\n");
4494 if (!MSI_RecordIsNull(row,8))
4496 static const WCHAR szDefaultIcon[] =
4497 {'D','e','f','a','u','l','t','I','c','o','n',0};
4499 LPWSTR FileName = load_dynamic_stringW(row,8);
4503 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
4504 build_icon_path(package,FileName,&FilePath);
4505 if (!MSI_RecordIsNull(row,9))
4507 static const WCHAR index_fmt[] = {',','%','i',0};
4508 WCHAR index_buf[20];
4509 index = MSI_RecordGetInteger(row,9);
4510 sprintfW(index_buf,index_fmt,index);
4511 size = strlenW(FilePath)+strlenW(index_buf)+1;
4512 size *= sizeof(WCHAR);
4513 HeapReAlloc(GetProcessHeap(),0,FilePath,size);
4515 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)FilePath,
4516 (strlenW(FilePath)+1) * sizeof(WCHAR));
4517 HeapFree(GetProcessHeap(),0,FilePath);
4518 HeapFree(GetProcessHeap(),0,FileName);
4522 if (!MSI_RecordIsNull(row,10))
4524 static const WCHAR szInproc32[] =
4525 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
4527 static const WCHAR szInproc[] =
4528 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
4529 INT i = MSI_RecordGetInteger(row,10);
4530 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4532 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4533 static const WCHAR ole32[] =
4534 {'o','l','e','3','2','.','d','l','l',0};
4538 size = strlenW(ole2) * sizeof(WCHAR);
4539 RegCreateKeyW(hkey2,szInproc,&hkey3);
4540 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4544 size = strlenW(ole32) * sizeof(WCHAR);
4545 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4546 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4550 size = strlenW(ole2) * sizeof(WCHAR);
4551 RegCreateKeyW(hkey2,szInproc,&hkey3);
4552 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4554 size = strlenW(ole32) * sizeof(WCHAR);
4555 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4556 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4564 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4565 argument = load_dynamic_stringW(row,10);
4566 reduce_to_longfilename(argument);
4567 size = strlenW(argument)*sizeof(WCHAR);
4569 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4570 HeapFree(GetProcessHeap(),0,argument);
4578 ui_actiondata(package,szRegisterClassInfo,row);
4580 msiobj_release(&row->hdr);
4582 MSI_ViewClose(view);
4583 msiobj_release(&view->hdr);
4590 static UINT register_progid_base(MSIPACKAGE* package, MSIRECORD * row,
4593 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4594 static const WCHAR szDefaultIcon[] =
4595 {'D','e','f','a','u','l','t','I','c','o','n',0};
4597 WCHAR buffer[0x100];
4602 MSI_RecordGetStringW(row,1,buffer,&sz);
4603 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4605 if (!MSI_RecordIsNull(row,4))
4608 MSI_RecordGetStringW(row,4,buffer,&sz);
4609 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4613 if (!MSI_RecordIsNull(row,3))
4617 MSI_RecordGetStringW(row,3,buffer,&sz);
4618 RegCreateKeyW(hkey,szCLSID,&hkey2);
4619 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4623 strcpyW(clsid,buffer);
4629 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4630 return ERROR_FUNCTION_FAILED;
4632 if (!MSI_RecordIsNull(row,5))
4634 INT index = MSI_RecordGetInteger(row,6);
4635 LPWSTR FileName = load_dynamic_stringW(row,5);
4636 LPWSTR FilePath,IconPath;
4637 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4639 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4640 build_icon_path(package,FileName,&FilePath);
4642 IconPath = HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4645 sprintfW(IconPath,fmt,FilePath,index);
4646 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)IconPath,
4647 (strlenW(IconPath)+1) * sizeof(WCHAR));
4648 HeapFree(GetProcessHeap(),0,FilePath);
4649 HeapFree(GetProcessHeap(),0,FileName);
4652 return ERROR_SUCCESS;
4655 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4657 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4662 MSIRECORD * row = 0;
4663 static const WCHAR Query_t[] =
4664 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4665 'P','r','o','g' ,'I','d',' ','W','H','E','R','E',' ',
4666 'P','r','o','g','I','d',' ','=',' ','`' ,'%','s','`',0};
4669 return ERROR_INVALID_HANDLE;
4671 rc = MSI_OpenQuery(package->db, &view, Query_t, parent);
4672 if (rc != ERROR_SUCCESS)
4675 rc = MSI_ViewExecute(view, 0);
4676 if (rc != ERROR_SUCCESS)
4678 MSI_ViewClose(view);
4679 msiobj_release(&view->hdr);
4683 rc = MSI_ViewFetch(view,&row);
4684 if (rc != ERROR_SUCCESS)
4686 MSI_ViewClose(view);
4687 msiobj_release(&view->hdr);
4691 register_progid(package,row,clsid);
4693 msiobj_release(&row->hdr);
4694 MSI_ViewClose(view);
4695 msiobj_release(&view->hdr);
4699 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4701 UINT rc = ERROR_SUCCESS;
4703 if (MSI_RecordIsNull(row,2))
4704 rc = register_progid_base(package,row,clsid);
4707 WCHAR buffer[0x1000];
4710 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4711 static const WCHAR szDefaultIcon[] =
4712 {'D','e','f','a','u','l','t','I','c','o','n',0};
4714 /* check if already registered */
4716 MSI_RecordGetStringW(row,1,buffer,&sz);
4717 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4718 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4719 if (disp == REG_OPENED_EXISTING_KEY)
4721 TRACE("Key already registered\n");
4727 MSI_RecordGetStringW(row,2,buffer,&sz);
4728 rc = register_parent_progid(package,buffer,clsid);
4730 /* clsid is same as parent */
4731 RegCreateKeyW(hkey,szCLSID,&hkey2);
4732 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4738 if (!MSI_RecordIsNull(row,4))
4741 MSI_RecordGetStringW(row,4,buffer,&sz);
4742 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4743 (strlenW(buffer)+1) * sizeof(WCHAR));
4746 if (!MSI_RecordIsNull(row,5))
4748 LPWSTR FileName = load_dynamic_stringW(row,5);
4750 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4751 build_icon_path(package,FileName,&FilePath);
4752 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)FilePath,
4753 (strlenW(FilePath)+1) * sizeof(WCHAR));
4754 HeapFree(GetProcessHeap(),0,FilePath);
4755 HeapFree(GetProcessHeap(),0,FileName);
4764 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4767 * Sigh, here I am just brute force registering all progids
4768 * this needs to be linked to the Classes that have been registered
4769 * but the easiest way to do that is to load all these stuff into
4770 * memory for easy checking.
4772 * Gives me something to continue to work toward.
4776 MSIRECORD * row = 0;
4777 static const WCHAR Query[] =
4778 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
4779 'P','r','o','g','I','d',0};
4782 return ERROR_INVALID_HANDLE;
4784 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4785 if (rc != ERROR_SUCCESS)
4786 return ERROR_SUCCESS;
4788 rc = MSI_ViewExecute(view, 0);
4789 if (rc != ERROR_SUCCESS)
4791 MSI_ViewClose(view);
4792 msiobj_release(&view->hdr);
4798 WCHAR clsid[0x1000];
4800 rc = MSI_ViewFetch(view,&row);
4801 if (rc != ERROR_SUCCESS)
4807 register_progid(package,row,clsid);
4808 ui_actiondata(package,szRegisterProgIdInfo,row);
4810 msiobj_release(&row->hdr);
4812 MSI_ViewClose(view);
4813 msiobj_release(&view->hdr);
4817 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4821 LPWSTR SystemFolder;
4825 static const WCHAR szInstaller[] =
4826 {'I','n','s','t','a','l','l','e','r','\\',0};
4827 static const WCHAR szFolder[] =
4828 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4830 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4834 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4836 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4838 create_full_pathW(dest);
4840 *FilePath = build_directory_name(2, dest, icon_name);
4842 HeapFree(GetProcessHeap(),0,SystemFolder);
4843 HeapFree(GetProcessHeap(),0,ProductCode);
4844 HeapFree(GetProcessHeap(),0,dest);
4845 return ERROR_SUCCESS;
4848 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4852 MSIRECORD * row = 0;
4853 static const WCHAR Query[] =
4854 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4855 'S','h','o','r','t','c','u','t',0};
4861 return ERROR_INVALID_HANDLE;
4863 res = CoInitialize( NULL );
4866 ERR("CoInitialize failed\n");
4867 return ERROR_FUNCTION_FAILED;
4870 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4871 if (rc != ERROR_SUCCESS)
4872 return ERROR_SUCCESS;
4874 rc = MSI_ViewExecute(view, 0);
4875 if (rc != ERROR_SUCCESS)
4877 MSI_ViewClose(view);
4878 msiobj_release(&view->hdr);
4884 LPWSTR target_file, target_folder;
4885 WCHAR buffer[0x100];
4888 static const WCHAR szlnk[]={'.','l','n','k',0};
4890 rc = MSI_ViewFetch(view,&row);
4891 if (rc != ERROR_SUCCESS)
4898 MSI_RecordGetStringW(row,4,buffer,&sz);
4900 index = get_loaded_component(package,buffer);
4904 msiobj_release(&row->hdr);
4908 if (!ACTION_VerifyComponentForAction(package, index,
4909 INSTALLSTATE_LOCAL))
4911 TRACE("Skipping shortcut creation due to disabled component\n");
4912 msiobj_release(&row->hdr);
4914 package->components[index].Action =
4915 package->components[index].Installed;
4920 package->components[index].Action = INSTALLSTATE_LOCAL;
4922 ui_actiondata(package,szCreateShortcuts,row);
4924 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4925 &IID_IShellLinkW, (LPVOID *) &sl );
4929 ERR("Is IID_IShellLink\n");
4930 msiobj_release(&row->hdr);
4934 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4937 ERR("Is IID_IPersistFile\n");
4938 msiobj_release(&row->hdr);
4943 MSI_RecordGetStringW(row,2,buffer,&sz);
4944 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4946 /* may be needed because of a bug somehwere else */
4947 create_full_pathW(target_folder);
4950 MSI_RecordGetStringW(row,3,buffer,&sz);
4951 reduce_to_longfilename(buffer);
4952 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4953 strcatW(buffer,szlnk);
4954 target_file = build_directory_name(2, target_folder, buffer);
4955 HeapFree(GetProcessHeap(),0,target_folder);
4958 MSI_RecordGetStringW(row,5,buffer,&sz);
4959 if (strchrW(buffer,'['))
4962 deformat_string(package,buffer,&deformated);
4963 IShellLinkW_SetPath(sl,deformated);
4964 HeapFree(GetProcessHeap(),0,deformated);
4969 FIXME("poorly handled shortcut format, advertised shortcut\n");
4970 keypath = strdupW(package->components[index].FullKeypath);
4971 IShellLinkW_SetPath(sl,keypath);
4972 HeapFree(GetProcessHeap(),0,keypath);
4975 if (!MSI_RecordIsNull(row,6))
4979 MSI_RecordGetStringW(row,6,buffer,&sz);
4980 deformat_string(package,buffer,&deformated);
4981 IShellLinkW_SetArguments(sl,deformated);
4982 HeapFree(GetProcessHeap(),0,deformated);
4985 if (!MSI_RecordIsNull(row,7))
4988 deformated = load_dynamic_stringW(row,7);
4989 IShellLinkW_SetDescription(sl,deformated);
4990 HeapFree(GetProcessHeap(),0,deformated);
4993 if (!MSI_RecordIsNull(row,8))
4994 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4996 if (!MSI_RecordIsNull(row,9))
5002 MSI_RecordGetStringW(row,9,buffer,&sz);
5004 build_icon_path(package,buffer,&Path);
5005 index = MSI_RecordGetInteger(row,10);
5007 IShellLinkW_SetIconLocation(sl,Path,index);
5008 HeapFree(GetProcessHeap(),0,Path);
5011 if (!MSI_RecordIsNull(row,11))
5012 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
5014 if (!MSI_RecordIsNull(row,12))
5018 MSI_RecordGetStringW(row,12,buffer,&sz);
5019 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
5020 IShellLinkW_SetWorkingDirectory(sl,Path);
5021 HeapFree(GetProcessHeap(), 0, Path);
5024 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
5025 IPersistFile_Save(pf,target_file,FALSE);
5027 HeapFree(GetProcessHeap(),0,target_file);
5029 IPersistFile_Release( pf );
5030 IShellLinkW_Release( sl );
5032 msiobj_release(&row->hdr);
5034 MSI_ViewClose(view);
5035 msiobj_release(&view->hdr);
5045 * 99% of the work done here is only done for
5046 * advertised installs. However this is where the
5047 * Icon table is processed and written out
5048 * so that is what I am going to do here.
5050 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
5054 MSIRECORD * row = 0;
5055 static const WCHAR Query[]=
5056 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5059 /* for registry stuff */
5063 static const WCHAR szProductName[] =
5064 {'P','r','o','d','u','c','t','N','a','m','e',0};
5065 static const WCHAR szPackageCode[] =
5066 {'P','a','c','k','a','g','e','C','o','d','e',0};
5069 MSIHANDLE hDb, hSumInfo;
5072 return ERROR_INVALID_HANDLE;
5074 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5075 if (rc != ERROR_SUCCESS)
5078 rc = MSI_ViewExecute(view, 0);
5079 if (rc != ERROR_SUCCESS)
5081 MSI_ViewClose(view);
5082 msiobj_release(&view->hdr);
5089 WCHAR *FilePath=NULL;
5090 WCHAR *FileName=NULL;
5093 rc = MSI_ViewFetch(view,&row);
5094 if (rc != ERROR_SUCCESS)
5100 FileName = load_dynamic_stringW(row,1);
5103 ERR("Unable to get FileName\n");
5104 msiobj_release(&row->hdr);
5108 build_icon_path(package,FileName,&FilePath);
5110 HeapFree(GetProcessHeap(),0,FileName);
5112 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
5114 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
5115 FILE_ATTRIBUTE_NORMAL, NULL);
5117 if (the_file == INVALID_HANDLE_VALUE)
5119 ERR("Unable to create file %s\n",debugstr_w(FilePath));
5120 msiobj_release(&row->hdr);
5121 HeapFree(GetProcessHeap(),0,FilePath);
5129 rc = MSI_RecordReadStream(row,2,buffer,&sz);
5130 if (rc != ERROR_SUCCESS)
5132 ERR("Failed to get stream\n");
5133 CloseHandle(the_file);
5134 DeleteFileW(FilePath);
5137 WriteFile(the_file,buffer,sz,&write,NULL);
5138 } while (sz == 1024);
5140 HeapFree(GetProcessHeap(),0,FilePath);
5142 CloseHandle(the_file);
5143 msiobj_release(&row->hdr);
5145 MSI_ViewClose(view);
5146 msiobj_release(&view->hdr);
5149 /* ok there is a lot more done here but i need to figure out what */
5150 productcode = load_dynamic_property(package,szProductCode,&rc);
5154 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
5155 if (rc != ERROR_SUCCESS)
5158 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5159 if (rc != ERROR_SUCCESS)
5163 buffer = load_dynamic_property(package,szProductName,NULL);
5164 size = strlenW(buffer)*sizeof(WCHAR);
5165 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
5166 HeapFree(GetProcessHeap(),0,buffer);
5167 FIXME("Need to write more keys to the user registry\n");
5169 hDb= alloc_msihandle( &package->db->hdr );
5170 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
5171 MsiCloseHandle(hDb);
5172 if (rc == ERROR_SUCCESS)
5174 WCHAR guidbuffer[0x200];
5176 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
5178 if (rc == ERROR_SUCCESS)
5180 WCHAR squashed[GUID_SIZE];
5181 /* for now we only care about the first guid */
5182 LPWSTR ptr = strchrW(guidbuffer,';');
5184 squash_guid(guidbuffer,squashed);
5185 size = strlenW(squashed)*sizeof(WCHAR);
5186 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
5191 ERR("Unable to query Revision_Number... \n");
5194 MsiCloseHandle(hSumInfo);
5198 ERR("Unable to open Summary Information\n");
5204 HeapFree(GetProcessHeap(),0,productcode);
5211 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
5215 MSIRECORD * row = 0;
5216 static const WCHAR ExecSeqQuery[] =
5217 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5218 'I','n','i','F','i','l','e',0};
5219 static const WCHAR szWindowsFolder[] =
5220 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
5222 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5223 if (rc != ERROR_SUCCESS)
5225 TRACE("no IniFile table\n");
5226 return ERROR_SUCCESS;
5229 rc = MSI_ViewExecute(view, 0);
5230 if (rc != ERROR_SUCCESS)
5232 MSI_ViewClose(view);
5233 msiobj_release(&view->hdr);
5239 LPWSTR component,filename,dirproperty,section,key,value,identifier;
5240 LPWSTR deformated_section, deformated_key, deformated_value;
5241 LPWSTR folder, fullname = NULL;
5243 INT component_index,action;
5245 rc = MSI_ViewFetch(view,&row);
5246 if (rc != ERROR_SUCCESS)
5252 component = load_dynamic_stringW(row, 8);
5253 component_index = get_loaded_component(package,component);
5254 HeapFree(GetProcessHeap(),0,component);
5256 if (!ACTION_VerifyComponentForAction(package, component_index,
5257 INSTALLSTATE_LOCAL))
5259 TRACE("Skipping ini file due to disabled component\n");
5260 msiobj_release(&row->hdr);
5262 package->components[component_index].Action =
5263 package->components[component_index].Installed;
5268 package->components[component_index].Action = INSTALLSTATE_LOCAL;
5270 identifier = load_dynamic_stringW(row,1);
5271 filename = load_dynamic_stringW(row,2);
5272 dirproperty = load_dynamic_stringW(row,3);
5273 section = load_dynamic_stringW(row,4);
5274 key = load_dynamic_stringW(row,5);
5275 value = load_dynamic_stringW(row,6);
5276 action = MSI_RecordGetInteger(row,7);
5278 deformat_string(package,section,&deformated_section);
5279 deformat_string(package,key,&deformated_key);
5280 deformat_string(package,value,&deformated_value);
5284 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
5286 folder = load_dynamic_property(package,dirproperty,NULL);
5289 folder = load_dynamic_property(package, szWindowsFolder, NULL);
5293 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
5297 fullname = build_directory_name(3, folder, filename, NULL);
5301 TRACE("Adding value %s to section %s in %s\n",
5302 debugstr_w(deformated_key), debugstr_w(deformated_section),
5303 debugstr_w(fullname));
5304 WritePrivateProfileStringW(deformated_section, deformated_key,
5305 deformated_value, fullname);
5307 else if (action == 1)
5310 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
5311 returned, 10, fullname);
5312 if (returned[0] == 0)
5314 TRACE("Adding value %s to section %s in %s\n",
5315 debugstr_w(deformated_key), debugstr_w(deformated_section),
5316 debugstr_w(fullname));
5318 WritePrivateProfileStringW(deformated_section, deformated_key,
5319 deformated_value, fullname);
5322 else if (action == 3)
5324 FIXME("Append to existing section not yet implemented\n");
5327 uirow = MSI_CreateRecord(4);
5328 MSI_RecordSetStringW(uirow,1,identifier);
5329 MSI_RecordSetStringW(uirow,2,deformated_section);
5330 MSI_RecordSetStringW(uirow,3,deformated_key);
5331 MSI_RecordSetStringW(uirow,4,deformated_value);
5332 ui_actiondata(package,szWriteIniValues,uirow);
5333 msiobj_release( &uirow->hdr );
5335 HeapFree(GetProcessHeap(),0,identifier);
5336 HeapFree(GetProcessHeap(),0,fullname);
5337 HeapFree(GetProcessHeap(),0,filename);
5338 HeapFree(GetProcessHeap(),0,key);
5339 HeapFree(GetProcessHeap(),0,value);
5340 HeapFree(GetProcessHeap(),0,section);
5341 HeapFree(GetProcessHeap(),0,dirproperty);
5342 HeapFree(GetProcessHeap(),0,folder);
5343 HeapFree(GetProcessHeap(),0,deformated_key);
5344 HeapFree(GetProcessHeap(),0,deformated_value);
5345 HeapFree(GetProcessHeap(),0,deformated_section);
5346 msiobj_release(&row->hdr);
5348 MSI_ViewClose(view);
5349 msiobj_release(&view->hdr);
5353 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
5357 MSIRECORD * row = 0;
5358 static const WCHAR ExecSeqQuery[] =
5359 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5360 'S','e','l','f','R','e','g',0};
5362 static const WCHAR ExeStr[] =
5363 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ',0};
5365 PROCESS_INFORMATION info;
5368 memset(&si,0,sizeof(STARTUPINFOW));
5370 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5371 if (rc != ERROR_SUCCESS)
5373 TRACE("no SelfReg table\n");
5374 return ERROR_SUCCESS;
5377 rc = MSI_ViewExecute(view, 0);
5378 if (rc != ERROR_SUCCESS)
5380 MSI_ViewClose(view);
5381 msiobj_release(&view->hdr);
5391 rc = MSI_ViewFetch(view,&row);
5392 if (rc != ERROR_SUCCESS)
5398 filename = load_dynamic_stringW(row,1);
5399 index = get_loaded_file(package,filename);
5403 ERR("Unable to find file id %s\n",debugstr_w(filename));
5404 HeapFree(GetProcessHeap(),0,filename);
5405 msiobj_release(&row->hdr);
5408 HeapFree(GetProcessHeap(),0,filename);
5410 len = strlenW(ExeStr);
5411 len += strlenW(package->files[index].TargetPath);
5414 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
5415 strcpyW(filename,ExeStr);
5416 strcatW(filename,package->files[index].TargetPath);
5418 TRACE("Registering %s\n",debugstr_w(filename));
5419 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
5420 c_colon, &si, &info);
5423 msi_dialog_check_messages(package->dialog, info.hProcess);
5425 HeapFree(GetProcessHeap(),0,filename);
5426 msiobj_release(&row->hdr);
5428 MSI_ViewClose(view);
5429 msiobj_release(&view->hdr);
5433 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
5442 return ERROR_INVALID_HANDLE;
5444 productcode = load_dynamic_property(package,szProductCode,&rc);
5448 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
5449 if (rc != ERROR_SUCCESS)
5452 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
5453 if (rc != ERROR_SUCCESS)
5456 /* here the guids are base 85 encoded */
5457 for (i = 0; i < package->loaded_features; i++)
5464 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL))
5467 size = package->features[i].ComponentCount*21;
5469 if (package->features[i].Feature_Parent[0])
5470 size += strlenW(package->features[i].Feature_Parent)+2;
5472 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
5475 for (j = 0; j < package->features[i].ComponentCount; j++)
5478 memset(buf,0,sizeof(buf));
5479 TRACE("From %s\n",debugstr_w(package->components
5480 [package->features[i].Components[j]].ComponentId));
5481 CLSIDFromString(package->components
5482 [package->features[i].Components[j]].ComponentId,
5484 encode_base85_guid(&clsid,buf);
5485 TRACE("to %s\n",debugstr_w(buf));
5488 if (package->features[i].Feature_Parent[0])
5490 static const WCHAR sep[] = {'\2',0};
5492 strcatW(data,package->features[i].Feature_Parent);
5495 size = (strlenW(data)+1)*sizeof(WCHAR);
5496 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
5498 HeapFree(GetProcessHeap(),0,data);
5500 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
5501 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
5502 (LPSTR)package->features[i].Feature_Parent,size);
5508 HeapFree(GetProcessHeap(), 0, productcode);
5512 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
5519 static WCHAR szNONE[] = {0};
5520 static const WCHAR szWindowsInstaler[] =
5521 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
5522 static const WCHAR szPropKeys[][80] =
5524 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
5525 {'A','R','P','C','O','N','T','A','C','T',0},
5526 {'A','R','P','C','O','M','M','E','N','T','S',0},
5527 {'P','r','o','d','u','c','t','N','a','m','e',0},
5528 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
5529 {'A','R','P','H','E','L','P','L','I','N','K',0},
5530 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
5531 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
5532 {'S','o','u','r','c','e','D','i','r',0},
5533 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
5534 {'A','R','P','R','E','A','D','M','E',0},
5535 {'A','R','P','S','I','Z','E',0},
5536 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
5537 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
5541 static const WCHAR szRegKeys[][80] =
5543 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
5544 {'C','o','n','t','a','c','t',0},
5545 {'C','o','m','m','e','n','t','s',0},
5546 {'D','i','s','p','l','a','y','N','a','m','e',0},
5547 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
5548 {'H','e','l','p','L','i','n','k',0},
5549 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
5550 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
5551 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
5552 {'P','u','b','l','i','s','h','e','r',0},
5553 {'R','e','a','d','m','e',0},
5554 {'S','i','z','e',0},
5555 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
5556 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
5560 static const WCHAR installerPathFmt[] = {
5562 'I','n','s','t','a','l','l','e','r','\\',0};
5563 static const WCHAR fmt[] = {
5565 'I','n','s','t','a','l','l','e','r','\\',
5566 '%','x','.','m','s','i',0};
5567 static const WCHAR szLocalPackage[]=
5568 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
5569 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
5573 return ERROR_INVALID_HANDLE;
5575 productcode = load_dynamic_property(package,szProductCode,&rc);
5579 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
5580 if (rc != ERROR_SUCCESS)
5583 /* dump all the info i can grab */
5584 FIXME("Flesh out more information \n");
5587 while (szPropKeys[i][0]!=0)
5589 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
5590 if (rc != ERROR_SUCCESS)
5592 size = strlenW(buffer)*sizeof(WCHAR);
5593 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
5599 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
5601 /* copy the package locally */
5602 num = GetTickCount() & 0xffff;
5606 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
5607 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
5611 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
5612 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
5613 if (handle != INVALID_HANDLE_VALUE)
5615 CloseHandle(handle);
5618 if (GetLastError() != ERROR_FILE_EXISTS &&
5619 GetLastError() != ERROR_SHARING_VIOLATION)
5621 if (!(++num & 0xffff)) num = 1;
5622 sprintfW(packagefile,fmt,num);
5623 } while (num != start);
5625 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
5626 create_full_pathW(path);
5627 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
5628 CopyFileW(package->PackagePath,packagefile,FALSE);
5629 size = strlenW(packagefile)*sizeof(WCHAR);
5630 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
5633 HeapFree(GetProcessHeap(),0,productcode);
5636 return ERROR_SUCCESS;
5639 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
5643 return ERROR_INVALID_HANDLE;
5645 for (i = 0; i < package->DeferredActionCount; i++)
5648 action = package->DeferredAction[i];
5649 ui_actionstart(package, action);
5650 TRACE("Executing Action (%s)\n",debugstr_w(action));
5651 ACTION_CustomAction(package,action,TRUE);
5652 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
5654 HeapFree(GetProcessHeap(),0,package->DeferredAction);
5656 package->DeferredActionCount = 0;
5657 package->DeferredAction = NULL;
5659 return ERROR_SUCCESS;
5662 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
5666 return ERROR_INVALID_HANDLE;
5668 /* first do the same as an InstallExecute */
5669 ACTION_InstallExecute(package);
5671 /* then handle Commit Actions */
5672 for (i = 0; i < package->CommitActionCount; i++)
5675 action = package->CommitAction[i];
5676 ui_actionstart(package, action);
5677 TRACE("Executing Commit Action (%s)\n",debugstr_w(action));
5678 ACTION_CustomAction(package,action,TRUE);
5679 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
5681 HeapFree(GetProcessHeap(),0,package->CommitAction);
5683 package->CommitActionCount = 0;
5684 package->CommitAction = NULL;
5686 return ERROR_SUCCESS;
5689 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
5691 static const WCHAR RunOnce[] = {
5692 'S','o','f','t','w','a','r','e','\\',
5693 'M','i','c','r','o','s','o','f','t','\\',
5694 'W','i','n','d','o','w','s','\\',
5695 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5696 'R','u','n','O','n','c','e',0};
5697 static const WCHAR InstallRunOnce[] = {
5698 'S','o','f','t','w','a','r','e','\\',
5699 'M','i','c','r','o','s','o','f','t','\\',
5700 'W','i','n','d','o','w','s','\\',
5701 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5702 'I','n','s','t','a','l','l','e','r','\\',
5703 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
5705 static const WCHAR msiexec_fmt[] = {
5707 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5708 '\"','%','s','\"',0};
5709 static const WCHAR install_fmt[] = {
5710 '/','I',' ','\"','%','s','\"',' ',
5711 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5712 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5713 WCHAR buffer[256], sysdir[MAX_PATH];
5716 WCHAR squished_pc[100];
5719 static const WCHAR szLUS[] = {
5720 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
5721 static const WCHAR szSourceList[] = {
5722 'S','o','u','r','c','e','L','i','s','t',0};
5723 static const WCHAR szPackageName[] = {
5724 'P','a','c','k','a','g','e','N','a','m','e',0};
5727 return ERROR_INVALID_HANDLE;
5729 productcode = load_dynamic_property(package,szProductCode,&rc);
5733 squash_guid(productcode,squished_pc);
5735 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
5736 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
5737 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
5740 size = strlenW(buffer)*sizeof(WCHAR);
5741 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5744 TRACE("Reboot command %s\n",debugstr_w(buffer));
5746 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
5747 sprintfW(buffer,install_fmt,productcode,squished_pc);
5749 size = strlenW(buffer)*sizeof(WCHAR);
5750 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5753 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5754 if (rc == ERROR_SUCCESS)
5758 RegCreateKeyW(hukey, szSourceList, &hukey2);
5759 buf = load_dynamic_property(package,cszSourceDir,NULL);
5760 size = strlenW(buf)*sizeof(WCHAR);
5761 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
5762 HeapFree(GetProcessHeap(),0,buf);
5764 buf = strrchrW(package->PackagePath,'\\');
5768 size = strlenW(buf)*sizeof(WCHAR);
5769 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
5772 RegCloseKey(hukey2);
5774 HeapFree(GetProcessHeap(),0,productcode);
5776 return ERROR_INSTALL_SUSPEND;
5779 UINT ACTION_ResolveSource(MSIPACKAGE* package)
5782 * we are currently doing what should be done here in the top level Install
5783 * however for Adminastrative and uninstalls this step will be needed
5785 return ERROR_SUCCESS;
5789 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
5793 MSIRECORD * row = 0;
5794 static const WCHAR ExecSeqQuery[] =
5795 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5796 'E','x','t','e','n','s','i','o','n',0};
5797 static const WCHAR szContentType[] =
5798 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
5802 return ERROR_INVALID_HANDLE;
5804 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5805 if (rc != ERROR_SUCCESS)
5811 rc = MSI_ViewExecute(view, 0);
5812 if (rc != ERROR_SUCCESS)
5814 MSI_ViewClose(view);
5815 msiobj_release(&view->hdr);
5821 WCHAR buffer[0x100];
5822 WCHAR extension[257];
5827 rc = MSI_ViewFetch(view,&row);
5828 if (rc != ERROR_SUCCESS)
5835 MSI_RecordGetStringW(row,2,buffer,&sz);
5837 index = get_loaded_component(package,buffer);
5841 msiobj_release(&row->hdr);
5845 if (!ACTION_VerifyComponentForAction(package, index,
5846 INSTALLSTATE_LOCAL))
5848 TRACE("Skipping extension reg due to disabled component\n");
5849 msiobj_release(&row->hdr);
5851 package->components[index].Action =
5852 package->components[index].Installed;
5857 package->components[index].Action = INSTALLSTATE_LOCAL;
5859 exten = load_dynamic_stringW(row,1);
5862 strcatW(extension,exten);
5863 HeapFree(GetProcessHeap(),0,exten);
5865 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
5867 if (!MSI_RecordIsNull(row,4))
5869 LPWSTR mime = load_dynamic_stringW(row,4);
5870 RegSetValueExW(hkey,szContentType,0,REG_SZ,(LPVOID)mime,
5871 (strlenW(mime)+1)*sizeof(WCHAR));
5872 HeapFree(GetProcessHeap(),0,mime);
5875 if (!MSI_RecordIsNull(row,3))
5877 static const WCHAR szSN[] =
5878 {'\\','S','h','e','l','l','N','e','w',0};
5881 LPWSTR progid= load_dynamic_stringW(row,3);
5883 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
5884 (strlenW(progid)+1)*sizeof(WCHAR));
5886 newkey = HeapAlloc(GetProcessHeap(),0,
5887 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
5889 strcpyW(newkey,progid);
5890 strcatW(newkey,szSN);
5891 RegCreateKeyW(hkey,newkey,&hkey2);
5894 HeapFree(GetProcessHeap(),0,progid);
5895 HeapFree(GetProcessHeap(),0,newkey);
5901 ui_actiondata(package,szRegisterExtensionInfo,row);
5903 msiobj_release(&row->hdr);
5905 MSI_ViewClose(view);
5906 msiobj_release(&view->hdr);
5912 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
5916 MSIRECORD * row = 0;
5917 static const WCHAR ExecSeqQuery[] =
5918 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5920 static const WCHAR szExten[] =
5921 {'E','x','t','e','n','s','i','o','n',0 };
5925 return ERROR_INVALID_HANDLE;
5927 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5928 if (rc != ERROR_SUCCESS)
5934 rc = MSI_ViewExecute(view, 0);
5935 if (rc != ERROR_SUCCESS)
5937 MSI_ViewClose(view);
5938 msiobj_release(&view->hdr);
5944 WCHAR extension[257];
5947 static const WCHAR fmt[] =
5948 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
5949 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
5952 rc = MSI_ViewFetch(view,&row);
5953 if (rc != ERROR_SUCCESS)
5959 mime = load_dynamic_stringW(row,1);
5960 exten = load_dynamic_stringW(row,2);
5963 strcatW(extension,exten);
5964 HeapFree(GetProcessHeap(),0,exten);
5966 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
5968 sprintfW(key,fmt,mime);
5969 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
5970 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
5971 (strlenW(extension)+1)*sizeof(WCHAR));
5973 HeapFree(GetProcessHeap(),0,mime);
5974 HeapFree(GetProcessHeap(),0,key);
5976 if (!MSI_RecordIsNull(row,3))
5978 FIXME("Handle non null for field 3\n");
5983 ui_actiondata(package,szRegisterMIMEInfo,row);
5985 msiobj_release(&row->hdr);
5987 MSI_ViewClose(view);
5988 msiobj_release(&view->hdr);
5994 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
5996 static const WCHAR szProductID[]=
5997 {'P','r','o','d','u','c','t','I','D',0};
6005 static const WCHAR szPropKeys[][80] =
6007 {'P','r','o','d','u','c','t','I','D',0},
6008 {'U','S','E','R','N','A','M','E',0},
6009 {'C','O','M','P','A','N','Y','N','A','M','E',0},
6013 static const WCHAR szRegKeys[][80] =
6015 {'P','r','o','d','u','c','t','I','D',0},
6016 {'R','e','g','O','w','n','e','r',0},
6017 {'R','e','g','C','o','m','p','a','n','y',0},
6022 return ERROR_INVALID_HANDLE;
6024 productid = load_dynamic_property(package,szProductID,&rc);
6026 return ERROR_SUCCESS;
6028 productcode = load_dynamic_property(package,szProductCode,&rc);
6032 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
6033 if (rc != ERROR_SUCCESS)
6037 while (szPropKeys[i][0]!=0)
6039 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
6040 if (rc == ERROR_SUCCESS)
6042 size = strlenW(buffer)*sizeof(WCHAR);
6043 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
6049 HeapFree(GetProcessHeap(),0,productcode);
6050 HeapFree(GetProcessHeap(),0,productid);
6053 return ERROR_SUCCESS;
6057 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
6060 rc = ACTION_ProcessExecSequence(package,TRUE);
6066 * Code based off of code located here
6067 * http://www.codeproject.com/gdi/fontnamefromfile.asp
6069 * Using string index 4 (full font name) instead of 1 (family name)
6071 static LPWSTR load_ttfname_from(LPCWSTR filename)
6077 typedef struct _tagTT_OFFSET_TABLE{
6078 USHORT uMajorVersion;
6079 USHORT uMinorVersion;
6080 USHORT uNumOfTables;
6081 USHORT uSearchRange;
6082 USHORT uEntrySelector;
6086 typedef struct _tagTT_TABLE_DIRECTORY{
6087 char szTag[4]; /* table name */
6088 ULONG uCheckSum; /* Check sum */
6089 ULONG uOffset; /* Offset from beginning of file */
6090 ULONG uLength; /* length of the table in bytes */
6091 }TT_TABLE_DIRECTORY;
6093 typedef struct _tagTT_NAME_TABLE_HEADER{
6094 USHORT uFSelector; /* format selector. Always 0 */
6095 USHORT uNRCount; /* Name Records count */
6096 USHORT uStorageOffset; /* Offset for strings storage,
6097 * from start of the table */
6098 }TT_NAME_TABLE_HEADER;
6100 typedef struct _tagTT_NAME_RECORD{
6105 USHORT uStringLength;
6106 USHORT uStringOffset; /* from start of storage area */
6109 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
6110 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
6112 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
6113 FILE_ATTRIBUTE_NORMAL, 0 );
6114 if (handle != INVALID_HANDLE_VALUE)
6116 TT_TABLE_DIRECTORY tblDir;
6117 BOOL bFound = FALSE;
6118 TT_OFFSET_TABLE ttOffsetTable;
6120 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
6121 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
6122 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
6123 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
6125 if (ttOffsetTable.uMajorVersion != 1 ||
6126 ttOffsetTable.uMinorVersion != 0)
6129 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
6131 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
6132 if (strncmp(tblDir.szTag,"name",4)==0)
6135 tblDir.uLength = SWAPLONG(tblDir.uLength);
6136 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
6143 TT_NAME_TABLE_HEADER ttNTHeader;
6144 TT_NAME_RECORD ttRecord;
6146 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
6147 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
6150 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
6151 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
6153 for(i=0; i<ttNTHeader.uNRCount; i++)
6155 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
6156 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
6157 /* 4 is the Full Font Name */
6158 if(ttRecord.uNameID == 4)
6162 static const LPSTR tt = " (TrueType)";
6164 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
6165 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
6166 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
6167 SetFilePointer(handle, tblDir.uOffset +
6168 ttRecord.uStringOffset +
6169 ttNTHeader.uStorageOffset,
6171 buf = HeapAlloc(GetProcessHeap(), 0,
6172 ttRecord.uStringLength + 1 + strlen(tt));
6173 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
6174 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
6175 if (strlen(buf) > 0)
6178 ret = strdupAtoW(buf);
6179 HeapFree(GetProcessHeap(),0,buf);
6183 HeapFree(GetProcessHeap(),0,buf);
6184 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
6188 CloseHandle(handle);
6191 TRACE("Returning fontname %s\n",debugstr_w(ret));
6195 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
6199 MSIRECORD * row = 0;
6200 static const WCHAR ExecSeqQuery[] =
6201 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6203 static const WCHAR regfont1[] =
6204 {'S','o','f','t','w','a','r','e','\\',
6205 'M','i','c','r','o','s','o','f','t','\\',
6206 'W','i','n','d','o','w','s',' ','N','T','\\',
6207 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6208 'F','o','n','t','s',0};
6209 static const WCHAR regfont2[] =
6210 {'S','o','f','t','w','a','r','e','\\',
6211 'M','i','c','r','o','s','o','f','t','\\',
6212 'W','i','n','d','o','w','s','\\',
6213 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6214 'F','o','n','t','s',0};
6218 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6219 if (rc != ERROR_SUCCESS)
6222 rc = MSI_ViewExecute(view, 0);
6223 if (rc != ERROR_SUCCESS)
6225 MSI_ViewClose(view);
6226 msiobj_release(&view->hdr);
6230 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
6231 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
6240 rc = MSI_ViewFetch(view,&row);
6241 if (rc != ERROR_SUCCESS)
6247 file = load_dynamic_stringW(row,1);
6248 index = get_loaded_file(package,file);
6251 ERR("Unable to load file\n");
6252 HeapFree(GetProcessHeap(),0,file);
6256 /* check to make sure that component is installed */
6257 if (!ACTION_VerifyComponentForAction(package,
6258 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
6260 TRACE("Skipping: Component not scheduled for install\n");
6261 HeapFree(GetProcessHeap(),0,file);
6263 msiobj_release(&row->hdr);
6268 if (MSI_RecordIsNull(row,2))
6269 name = load_ttfname_from(package->files[index].TargetPath);
6271 name = load_dynamic_stringW(row,2);
6275 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
6276 RegSetValueExW(hkey1,name,0,REG_SZ,
6277 (LPBYTE)package->files[index].FileName,size);
6278 RegSetValueExW(hkey2,name,0,REG_SZ,
6279 (LPBYTE)package->files[index].FileName,size);
6282 HeapFree(GetProcessHeap(),0,file);
6283 HeapFree(GetProcessHeap(),0,name);
6284 msiobj_release(&row->hdr);
6286 MSI_ViewClose(view);
6287 msiobj_release(&view->hdr);
6295 /* Msi functions that seem appropriate here */
6296 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
6301 TRACE(" exteral attempt at action %s\n",szAction);
6304 return ERROR_FUNCTION_FAILED;
6306 return ERROR_FUNCTION_FAILED;
6308 szwAction = strdupAtoW(szAction);
6311 return ERROR_FUNCTION_FAILED;
6314 rc = MsiDoActionW(hInstall, szwAction);
6315 HeapFree(GetProcessHeap(),0,szwAction);
6319 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
6321 MSIPACKAGE *package;
6322 UINT ret = ERROR_INVALID_HANDLE;
6324 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
6326 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6329 ret = ACTION_PerformUIAction(package,szAction);
6330 msiobj_release( &package->hdr );
6335 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
6336 LPSTR szPathBuf, DWORD* pcchPathBuf)
6342 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
6345 return ERROR_FUNCTION_FAILED;
6347 return ERROR_FUNCTION_FAILED;
6349 szwFolder = strdupAtoW(szFolder);
6352 return ERROR_FUNCTION_FAILED;
6354 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
6356 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
6358 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
6359 *pcchPathBuf, NULL, NULL );
6361 HeapFree(GetProcessHeap(),0,szwFolder);
6362 HeapFree(GetProcessHeap(),0,szwPathBuf);
6367 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
6368 szPathBuf, DWORD* pcchPathBuf)
6371 UINT rc = ERROR_FUNCTION_FAILED;
6372 MSIPACKAGE *package;
6374 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
6376 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6378 return ERROR_INVALID_HANDLE;
6379 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
6380 msiobj_release( &package->hdr );
6382 if (path && (strlenW(path) > *pcchPathBuf))
6384 *pcchPathBuf = strlenW(path)+1;
6385 rc = ERROR_MORE_DATA;
6389 *pcchPathBuf = strlenW(path)+1;
6390 strcpyW(szPathBuf,path);
6391 TRACE("Returning Path %s\n",debugstr_w(path));
6394 HeapFree(GetProcessHeap(),0,path);
6400 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
6401 LPSTR szPathBuf, DWORD* pcchPathBuf)
6407 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
6410 return ERROR_FUNCTION_FAILED;
6412 return ERROR_FUNCTION_FAILED;
6414 szwFolder = strdupAtoW(szFolder);
6416 return ERROR_FUNCTION_FAILED;
6418 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
6420 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
6422 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
6423 *pcchPathBuf, NULL, NULL );
6425 HeapFree(GetProcessHeap(),0,szwFolder);
6426 HeapFree(GetProcessHeap(),0,szwPathBuf);
6431 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
6432 szPathBuf, DWORD* pcchPathBuf)
6435 UINT rc = ERROR_FUNCTION_FAILED;
6436 MSIPACKAGE *package;
6438 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
6440 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6442 return ERROR_INVALID_HANDLE;
6443 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
6444 msiobj_release( &package->hdr );
6446 if (path && strlenW(path) > *pcchPathBuf)
6448 *pcchPathBuf = strlenW(path)+1;
6449 rc = ERROR_MORE_DATA;
6453 *pcchPathBuf = strlenW(path)+1;
6454 strcpyW(szPathBuf,path);
6455 TRACE("Returning Path %s\n",debugstr_w(path));
6458 HeapFree(GetProcessHeap(),0,path);
6464 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
6465 LPCSTR szFolderPath)
6468 LPWSTR szwFolderPath;
6472 return ERROR_FUNCTION_FAILED;
6474 return ERROR_FUNCTION_FAILED;
6476 szwFolder = strdupAtoW(szFolder);
6478 return ERROR_FUNCTION_FAILED;
6480 szwFolderPath = strdupAtoW(szFolderPath);
6483 HeapFree(GetProcessHeap(),0,szwFolder);
6484 return ERROR_FUNCTION_FAILED;
6487 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
6489 HeapFree(GetProcessHeap(),0,szwFolder);
6490 HeapFree(GetProcessHeap(),0,szwFolderPath);
6495 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
6496 LPCWSTR szFolderPath)
6500 LPWSTR path2 = NULL;
6503 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
6506 return ERROR_INVALID_HANDLE;
6508 if (szFolderPath[0]==0)
6509 return ERROR_FUNCTION_FAILED;
6511 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
6512 return ERROR_FUNCTION_FAILED;
6514 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
6517 return ERROR_INVALID_PARAMETER;
6519 HeapFree(GetProcessHeap(),0,folder->Property);
6520 folder->Property = build_directory_name(2, szFolderPath, NULL);
6522 if (strcmpiW(path, folder->Property) == 0)
6525 * Resolved Target has not really changed, so just
6526 * set this folder and do not recalculate everything.
6528 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
6529 folder->ResolvedTarget = NULL;
6530 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
6531 HeapFree(GetProcessHeap(),0,path2);
6535 for (i = 0; i < package->loaded_folders; i++)
6537 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
6538 package->folders[i].ResolvedTarget=NULL;
6541 for (i = 0; i < package->loaded_folders; i++)
6543 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
6545 HeapFree(GetProcessHeap(),0,path2);
6548 HeapFree(GetProcessHeap(),0,path);
6550 return ERROR_SUCCESS;
6553 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
6554 LPCWSTR szFolderPath)
6556 MSIPACKAGE *package;
6559 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
6561 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6562 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
6563 msiobj_release( &package->hdr );
6567 /***********************************************************************
6568 * MsiGetMode (MSI.@)
6570 * Returns an internal installer state (if it is running in a mode iRunMode)
6573 * hInstall [I] Handle to the installation
6574 * hRunMode [I] Checking run mode
6575 * MSIRUNMODE_ADMIN Administrative mode
6576 * MSIRUNMODE_ADVERTISE Advertisement mode
6577 * MSIRUNMODE_MAINTENANCE Maintenance mode
6578 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
6579 * MSIRUNMODE_LOGENABLED Log file is writing
6580 * MSIRUNMODE_OPERATIONS Operations in progress??
6581 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
6582 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
6583 * MSIRUNMODE_CABINET Files from cabinet are installed
6584 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
6585 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
6586 * MSIRUNMODE_RESERVED11 Reserved
6587 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
6588 * MSIRUNMODE_ZAWENABLED Demand installation is supported
6589 * MSIRUNMODE_RESERVED14 Reserved
6590 * MSIRUNMODE_RESERVED15 Reserved
6591 * MSIRUNMODE_SCHEDULED called from install script
6592 * MSIRUNMODE_ROLLBACK called from rollback script
6593 * MSIRUNMODE_COMMIT called from commit script
6596 * In the state: TRUE
6597 * Not in the state: FALSE
6601 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
6603 FIXME("STUB (iRunMode=%i)\n",iRunMode);
6608 * According to the docs, when this is called it immediately recalculates
6609 * all the component states as well
6611 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
6612 INSTALLSTATE iState)
6614 LPWSTR szwFeature = NULL;
6617 szwFeature = strdupAtoW(szFeature);
6620 return ERROR_FUNCTION_FAILED;
6622 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
6624 HeapFree(GetProcessHeap(),0,szwFeature);
6629 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
6630 INSTALLSTATE iState)
6632 MSIPACKAGE* package;
6634 UINT rc = ERROR_SUCCESS;
6636 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
6638 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6640 return ERROR_INVALID_HANDLE;
6642 index = get_loaded_feature(package,szFeature);
6645 rc = ERROR_UNKNOWN_FEATURE;
6649 package->features[index].ActionRequest= iState;
6650 ACTION_UpdateComponentStates(package,szFeature);
6653 msiobj_release( &package->hdr );
6657 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
6658 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6660 LPWSTR szwFeature = NULL;
6663 szwFeature = strdupAtoW(szFeature);
6665 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
6667 HeapFree( GetProcessHeap(), 0 , szwFeature);
6672 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
6673 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6677 index = get_loaded_feature(package,szFeature);
6679 return ERROR_UNKNOWN_FEATURE;
6682 *piInstalled = package->features[index].Installed;
6685 *piAction = package->features[index].Action;
6687 TRACE("returning %i %i\n",*piInstalled,*piAction);
6689 return ERROR_SUCCESS;
6692 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
6693 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6695 MSIPACKAGE* package;
6698 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
6701 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6703 return ERROR_INVALID_HANDLE;
6704 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
6705 msiobj_release( &package->hdr );
6709 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
6710 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6712 LPWSTR szwComponent= NULL;
6715 szwComponent= strdupAtoW(szComponent);
6717 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
6719 HeapFree( GetProcessHeap(), 0 , szwComponent);
6724 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
6725 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6729 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
6732 index = get_loaded_component(package,szComponent);
6734 return ERROR_UNKNOWN_COMPONENT;
6737 *piInstalled = package->components[index].Installed;
6740 *piAction = package->components[index].Action;
6742 TRACE("states (%i, %i)\n",
6743 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
6745 return ERROR_SUCCESS;
6748 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
6749 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6751 MSIPACKAGE* package;
6754 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
6755 piInstalled, piAction);
6757 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6759 return ERROR_INVALID_HANDLE;
6760 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
6761 msiobj_release( &package->hdr );
6766 static UINT ACTION_Template(MSIPACKAGE *package)
6770 MSIRECORD * row = 0;
6771 static const WCHAR ExecSeqQuery[] = {0};
6773 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6774 if (rc != ERROR_SUCCESS)
6777 rc = MSI_ViewExecute(view, 0);
6778 if (rc != ERROR_SUCCESS)
6780 MSI_ViewClose(view);
6781 msiobj_release(&view->hdr);
6787 rc = MSI_ViewFetch(view,&row);
6788 if (rc != ERROR_SUCCESS)
6794 msiobj_release(&row->hdr);
6796 MSI_ViewClose(view);
6797 msiobj_release(&view->hdr);