2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
38 #include "wine/debug.h"
43 #include "msvcrt/fcntl.h"
50 #include "wine/unicode.h"
54 #define REG_PROGRESS_VALUE 13200
55 #define COMPONENT_PROGRESS_VALUE 24000
57 WINE_DEFAULT_DEBUG_CHANNEL(msi);
62 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
63 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
64 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI);
65 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
71 typedef UINT (*STANDARDACTIONHANDLER)(MSIPACKAGE*);
73 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
74 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
75 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
76 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
77 static UINT ACTION_FileCost(MSIPACKAGE *package);
78 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
79 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
80 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
81 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
82 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
83 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
84 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
85 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
86 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
87 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package);
88 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package);
89 static UINT ACTION_RegisterUser(MSIPACKAGE *package);
90 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
91 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
92 static UINT ACTION_WriteIniValues(MSIPACKAGE *package);
93 static UINT ACTION_SelfRegModules(MSIPACKAGE *package);
94 static UINT ACTION_PublishFeatures(MSIPACKAGE *package);
95 static UINT ACTION_RegisterProduct(MSIPACKAGE *package);
96 static UINT ACTION_InstallExecute(MSIPACKAGE *package);
97 static UINT ACTION_InstallFinalize(MSIPACKAGE *package);
98 static UINT ACTION_ForceReboot(MSIPACKAGE *package);
99 static UINT ACTION_ResolveSource(MSIPACKAGE *package);
100 static UINT ACTION_ExecuteAction(MSIPACKAGE *package);
101 static UINT ACTION_RegisterFonts(MSIPACKAGE *package);
102 static UINT ACTION_PublishComponents(MSIPACKAGE *package);
106 * consts and values used
108 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
109 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
110 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
111 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
112 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
113 static const WCHAR c_colon[] = {'C',':','\\',0};
114 static const WCHAR szProductCode[]=
115 {'P','r','o','d','u','c','t','C','o','d','e',0};
116 static const WCHAR cszbs[]={'\\',0};
117 const static WCHAR szCreateFolders[] =
118 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
119 const static WCHAR szCostFinalize[] =
120 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
121 const static WCHAR szInstallFiles[] =
122 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
123 const static WCHAR szDuplicateFiles[] =
124 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
125 const static WCHAR szWriteRegistryValues[] =
126 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
127 'V','a','l','u','e','s',0};
128 const static WCHAR szCostInitialize[] =
129 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
130 const static WCHAR szFileCost[] =
131 {'F','i','l','e','C','o','s','t',0};
132 const static WCHAR szInstallInitialize[] =
133 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
134 const static WCHAR szInstallValidate[] =
135 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
136 const static WCHAR szLaunchConditions[] =
137 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
138 const static WCHAR szProcessComponents[] =
139 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
140 const static WCHAR szRegisterTypeLibraries[] =
141 {'R','e','g','i','s','t','e','r','T','y','p','e',
142 'L','i','b','r','a','r','i','e','s',0};
143 const static WCHAR szRegisterClassInfo[] =
144 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
145 const static WCHAR szRegisterProgIdInfo[] =
146 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
147 const static WCHAR szCreateShortcuts[] =
148 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
149 const static WCHAR szPublishProduct[] =
150 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
151 const static WCHAR szWriteIniValues[] =
152 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
153 const static WCHAR szSelfRegModules[] =
154 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
155 const static WCHAR szPublishFeatures[] =
156 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
157 const static WCHAR szRegisterProduct[] =
158 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
159 const static WCHAR szInstallExecute[] =
160 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
161 const static WCHAR szInstallExecuteAgain[] =
162 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
163 'A','g','a','i','n',0};
164 const static WCHAR szInstallFinalize[] =
165 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
166 const static WCHAR szForceReboot[] =
167 {'F','o','r','c','e','R','e','b','o','o','t',0};
168 const static WCHAR szResolveSource[] =
169 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
170 const static WCHAR szAppSearch[] =
171 {'A','p','p','S','e','a','r','c','h',0};
172 const static WCHAR szAllocateRegistrySpace[] =
173 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
174 'S','p','a','c','e',0};
175 const static WCHAR szBindImage[] =
176 {'B','i','n','d','I','m','a','g','e',0};
177 const static WCHAR szCCPSearch[] =
178 {'C','C','P','S','e','a','r','c','h',0};
179 const static WCHAR szDeleteServices[] =
180 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
181 const static WCHAR szDisableRollback[] =
182 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
183 const static WCHAR szExecuteAction[] =
184 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
185 const static WCHAR szFindRelatedProducts[] =
186 {'F','i','n','d','R','e','l','a','t','e','d',
187 'P','r','o','d','u','c','t','s',0};
188 const static WCHAR szInstallAdminPackage[] =
189 {'I','n','s','t','a','l','l','A','d','m','i','n',
190 'P','a','c','k','a','g','e',0};
191 const static WCHAR szInstallSFPCatalogFile[] =
192 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
194 const static WCHAR szIsolateComponents[] =
195 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
196 const static WCHAR szMigrateFeatureStates[] =
197 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
198 'S','t','a','t','e','s',0};
199 const static WCHAR szMoveFiles[] =
200 {'M','o','v','e','F','i','l','e','s',0};
201 const static WCHAR szMsiPublishAssemblies[] =
202 {'M','s','i','P','u','b','l','i','s','h',
203 'A','s','s','e','m','b','l','i','e','s',0};
204 const static WCHAR szMsiUnpublishAssemblies[] =
205 {'M','s','i','U','n','p','u','b','l','i','s','h',
206 'A','s','s','e','m','b','l','i','e','s',0};
207 const static WCHAR szInstallODBC[] =
208 {'I','n','s','t','a','l','l','O','D','B','C',0};
209 const static WCHAR szInstallServices[] =
210 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
211 const static WCHAR szPatchFiles[] =
212 {'P','a','t','c','h','F','i','l','e','s',0};
213 const static WCHAR szPublishComponents[] =
214 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
215 const static WCHAR szRegisterComPlus[] =
216 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
217 const static WCHAR szRegisterExtensionInfo[] =
218 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
220 const static WCHAR szRegisterFonts[] =
221 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
222 const static WCHAR szRegisterMIMEInfo[] =
223 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
224 const static WCHAR szRegisterUser[] =
225 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
226 const static WCHAR szRemoveDuplicateFiles[] =
227 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
228 'F','i','l','e','s',0};
229 const static WCHAR szRemoveEnvironmentStrings[] =
230 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
231 'S','t','r','i','n','g','s',0};
232 const static WCHAR szRemoveExistingProducts[] =
233 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
234 'P','r','o','d','u','c','t','s',0};
235 const static WCHAR szRemoveFiles[] =
236 {'R','e','m','o','v','e','F','i','l','e','s',0};
237 const static WCHAR szRemoveFolders[] =
238 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
239 const static WCHAR szRemoveIniValues[] =
240 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
241 const static WCHAR szRemoveODBC[] =
242 {'R','e','m','o','v','e','O','D','B','C',0};
243 const static WCHAR szRemoveRegistryValues[] =
244 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
245 'V','a','l','u','e','s',0};
246 const static WCHAR szRemoveShortcuts[] =
247 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
248 const static WCHAR szRMCCPSearch[] =
249 {'R','M','C','C','P','S','e','a','r','c','h',0};
250 const static WCHAR szScheduleReboot[] =
251 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
252 const static WCHAR szSelfUnregModules[] =
253 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
254 const static WCHAR szSetODBCFolders[] =
255 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
256 const static WCHAR szStartServices[] =
257 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
258 const static WCHAR szStopServices[] =
259 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
260 const static WCHAR szUnpublishComponents[] =
261 {'U','n','p','u','b','l','i','s','h',
262 'C','o','m','p','o','n','e','n','t','s',0};
263 const static WCHAR szUnpublishFeatures[] =
264 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
265 const static WCHAR szUnregisterClassInfo[] =
266 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
268 const static WCHAR szUnregisterComPlus[] =
269 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
270 const static WCHAR szUnregisterExtensionInfo[] =
271 {'U','n','r','e','g','i','s','t','e','r',
272 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
273 const static WCHAR szUnregisterFonts[] =
274 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
275 const static WCHAR szUnregisterMIMEInfo[] =
276 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
277 const static WCHAR szUnregisterProgIdInfo[] =
278 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
280 const static WCHAR szUnregisterTypeLibraries[] =
281 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
282 'L','i','b','r','a','r','i','e','s',0};
283 const static WCHAR szValidateProductID[] =
284 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
285 const static WCHAR szWriteEnvironmentStrings[] =
286 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
287 'S','t','r','i','n','g','s',0};
291 STANDARDACTIONHANDLER handler;
294 static struct _actions StandardActions[] = {
295 { szAllocateRegistrySpace, NULL},
296 { szAppSearch, ACTION_AppSearch },
297 { szBindImage, NULL},
298 { szCCPSearch, NULL},
299 { szCostFinalize, ACTION_CostFinalize },
300 { szCostInitialize, ACTION_CostInitialize },
301 { szCreateFolders, ACTION_CreateFolders },
302 { szCreateShortcuts, ACTION_CreateShortcuts },
303 { szDeleteServices, NULL},
304 { szDisableRollback, NULL},
305 { szDuplicateFiles, ACTION_DuplicateFiles },
306 { szExecuteAction, ACTION_ExecuteAction },
307 { szFileCost, ACTION_FileCost },
308 { szFindRelatedProducts, NULL},
309 { szForceReboot, ACTION_ForceReboot },
310 { szInstallAdminPackage, NULL},
311 { szInstallExecute, ACTION_InstallExecute },
312 { szInstallExecuteAgain, ACTION_InstallExecute },
313 { szInstallFiles, ACTION_InstallFiles},
314 { szInstallFinalize, ACTION_InstallFinalize },
315 { szInstallInitialize, ACTION_InstallInitialize },
316 { szInstallSFPCatalogFile, NULL},
317 { szInstallValidate, ACTION_InstallValidate },
318 { szIsolateComponents, NULL},
319 { szLaunchConditions, ACTION_LaunchConditions },
320 { szMigrateFeatureStates, NULL},
321 { szMoveFiles, NULL},
322 { szMsiPublishAssemblies, NULL},
323 { szMsiUnpublishAssemblies, NULL},
324 { szInstallODBC, NULL},
325 { szInstallServices, NULL},
326 { szPatchFiles, NULL},
327 { szProcessComponents, ACTION_ProcessComponents },
328 { szPublishComponents, ACTION_PublishComponents },
329 { szPublishFeatures, ACTION_PublishFeatures },
330 { szPublishProduct, ACTION_PublishProduct },
331 { szRegisterClassInfo, ACTION_RegisterClassInfo },
332 { szRegisterComPlus, NULL},
333 { szRegisterExtensionInfo, ACTION_RegisterExtensionInfo },
334 { szRegisterFonts, ACTION_RegisterFonts },
335 { szRegisterMIMEInfo, ACTION_RegisterMIMEInfo },
336 { szRegisterProduct, ACTION_RegisterProduct },
337 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
338 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
339 { szRegisterUser, ACTION_RegisterUser},
340 { szRemoveDuplicateFiles, NULL},
341 { szRemoveEnvironmentStrings, NULL},
342 { szRemoveExistingProducts, NULL},
343 { szRemoveFiles, NULL},
344 { szRemoveFolders, NULL},
345 { szRemoveIniValues, NULL},
346 { szRemoveODBC, NULL},
347 { szRemoveRegistryValues, NULL},
348 { szRemoveShortcuts, NULL},
349 { szResolveSource, ACTION_ResolveSource},
350 { szRMCCPSearch, NULL},
351 { szScheduleReboot, NULL},
352 { szSelfRegModules, ACTION_SelfRegModules },
353 { szSelfUnregModules, NULL},
354 { szSetODBCFolders, NULL},
355 { szStartServices, NULL},
356 { szStopServices, NULL},
357 { szUnpublishComponents, NULL},
358 { szUnpublishFeatures, NULL},
359 { szUnregisterClassInfo, NULL},
360 { szUnregisterComPlus, NULL},
361 { szUnregisterExtensionInfo, NULL},
362 { szUnregisterFonts, NULL},
363 { szUnregisterMIMEInfo, NULL},
364 { szUnregisterProgIdInfo, NULL},
365 { szUnregisterTypeLibraries, NULL},
366 { szValidateProductID, NULL},
367 { szWriteEnvironmentStrings, NULL},
368 { szWriteIniValues, ACTION_WriteIniValues },
369 { szWriteRegistryValues, ACTION_WriteRegistryValues},
374 /********************************************************
375 * helper functions to get around current HACKS and such
376 ********************************************************/
377 inline static void reduce_to_longfilename(WCHAR* filename)
379 LPWSTR p = strchrW(filename,'|');
381 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
384 WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
391 if (MSI_RecordIsNull(row,index))
394 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
396 /* having an empty string is different than NULL */
399 ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
405 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
406 rc = MSI_RecordGetStringW(row,index,ret,&sz);
407 if (rc!=ERROR_SUCCESS)
409 ERR("Unable to load dynamic string\n");
410 HeapFree(GetProcessHeap(), 0, ret);
416 LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop, UINT* rc)
422 r = MSI_GetPropertyW(package, prop, NULL, &sz);
423 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
430 str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
431 r = MSI_GetPropertyW(package, prop, str, &sz);
432 if (r != ERROR_SUCCESS)
434 HeapFree(GetProcessHeap(),0,str);
442 int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
447 for (i = 0; i < package->loaded_components; i++)
449 if (strcmpW(Component,package->components[i].Component)==0)
458 int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
463 for (i = 0; i < package->loaded_features; i++)
465 if (strcmpW(Feature,package->features[i].Feature)==0)
474 int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
479 for (i = 0; i < package->loaded_files; i++)
481 if (strcmpW(file,package->files[i].File)==0)
490 int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
498 for (i=0; i < package->loaded_files; i++)
499 if (strcmpW(package->files[i].File,name)==0)
502 index = package->loaded_files;
503 package->loaded_files++;
504 if (package->loaded_files== 1)
505 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
507 package->files = HeapReAlloc(GetProcessHeap(),0,
508 package->files , package->loaded_files * sizeof(MSIFILE));
510 memset(&package->files[index],0,sizeof(MSIFILE));
512 package->files[index].File = strdupW(name);
513 package->files[index].TargetPath = strdupW(path);
514 package->files[index].Temporary = TRUE;
516 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
521 static void remove_tracked_tempfiles(MSIPACKAGE* package)
528 for (i = 0; i < package->loaded_files; i++)
530 if (package->files[i].Temporary)
532 TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
533 DeleteFileW(package->files[i].TargetPath);
539 /* wrapper to resist a need for a full rewrite right now */
540 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
544 MSIRECORD *rec = MSI_CreateRecord(1);
547 MSI_RecordSetStringW(rec,0,ptr);
548 MSI_FormatRecordW(package,rec,NULL,&size);
552 *data = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
554 MSI_FormatRecordW(package,rec,*data,&size);
557 msiobj_release( &rec->hdr );
558 return sizeof(WCHAR)*size;
560 msiobj_release( &rec->hdr );
567 /* Called when the package is being closed */
568 void ACTION_free_package_structures( MSIPACKAGE* package)
572 TRACE("Freeing package action data\n");
574 remove_tracked_tempfiles(package);
576 /* No dynamic buffers in features */
577 if (package->features && package->loaded_features > 0)
578 HeapFree(GetProcessHeap(),0,package->features);
580 for (i = 0; i < package->loaded_folders; i++)
582 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
583 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
584 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
585 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
586 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
587 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
589 if (package->folders && package->loaded_folders > 0)
590 HeapFree(GetProcessHeap(),0,package->folders);
592 for (i = 0; i < package->loaded_components; i++)
593 HeapFree(GetProcessHeap(),0,package->components[i].FullKeypath);
595 if (package->components && package->loaded_components > 0)
596 HeapFree(GetProcessHeap(),0,package->components);
598 for (i = 0; i < package->loaded_files; i++)
600 HeapFree(GetProcessHeap(),0,package->files[i].File);
601 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
602 HeapFree(GetProcessHeap(),0,package->files[i].Version);
603 HeapFree(GetProcessHeap(),0,package->files[i].Language);
604 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
605 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
608 if (package->files && package->loaded_files > 0)
609 HeapFree(GetProcessHeap(),0,package->files);
611 for (i = 0; i < package->DeferredActionCount; i++)
612 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
613 HeapFree(GetProcessHeap(),0,package->DeferredAction);
615 for (i = 0; i < package->CommitActionCount; i++)
616 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
617 HeapFree(GetProcessHeap(),0,package->CommitAction);
619 HeapFree(GetProcessHeap(),0,package->PackagePath);
622 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
626 row = MSI_CreateRecord(4);
627 MSI_RecordSetInteger(row,1,a);
628 MSI_RecordSetInteger(row,2,b);
629 MSI_RecordSetInteger(row,3,c);
630 MSI_RecordSetInteger(row,4,d);
631 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
632 msiobj_release(&row->hdr);
634 msi_dialog_check_messages(NULL);
637 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
639 static const WCHAR Query_t[] =
640 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
641 'A','c','t','i','o', 'n','T','e','x','t',' ','W','H','E','R','E',' ',
642 'A','c','t','i','o','n',' ','=', ' ','\'','%','s','\'',0};
649 if (!package->LastAction || strcmpW(package->LastAction,action))
651 rc = MSI_OpenQuery(package->db, &view, Query_t, action);
652 if (rc != ERROR_SUCCESS)
655 rc = MSI_ViewExecute(view, 0);
656 if (rc != ERROR_SUCCESS)
659 msiobj_release(&view->hdr);
662 rc = MSI_ViewFetch(view,&row);
663 if (rc != ERROR_SUCCESS)
666 msiobj_release(&view->hdr);
670 if (MSI_RecordIsNull(row,3))
672 msiobj_release(&row->hdr);
674 msiobj_release(&view->hdr);
678 /* update the cached actionformat */
679 HeapFree(GetProcessHeap(),0,package->ActionFormat);
680 package->ActionFormat = load_dynamic_stringW(row,3);
682 HeapFree(GetProcessHeap(),0,package->LastAction);
683 package->LastAction = strdupW(action);
685 msiobj_release(&row->hdr);
687 msiobj_release(&view->hdr);
690 MSI_RecordSetStringW(record,0,package->ActionFormat);
692 MSI_FormatRecordW(package,record,message,&size);
694 row = MSI_CreateRecord(1);
695 MSI_RecordSetStringW(row,1,message);
697 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
698 msiobj_release(&row->hdr);
702 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
704 static const WCHAR template_s[]=
705 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
707 static const WCHAR format[] =
708 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
709 static const WCHAR Query_t[] =
710 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
711 'A','c','t','i','o', 'n','T','e','x','t',' ','W','H','E','R','E', ' ',
712 'A','c','t','i','o','n',' ','=', ' ','\'','%','s','\'',0};
718 WCHAR *ActionText=NULL;
720 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
722 rc = MSI_OpenQuery(package->db, &view, Query_t, action);
723 if (rc != ERROR_SUCCESS)
725 rc = MSI_ViewExecute(view, 0);
726 if (rc != ERROR_SUCCESS)
729 msiobj_release(&view->hdr);
732 rc = MSI_ViewFetch(view,&row);
733 if (rc != ERROR_SUCCESS)
736 msiobj_release(&view->hdr);
740 ActionText = load_dynamic_stringW(row,2);
741 msiobj_release(&row->hdr);
743 msiobj_release(&view->hdr);
745 sprintfW(message,template_s,timet,action,ActionText);
747 row = MSI_CreateRecord(1);
748 MSI_RecordSetStringW(row,1,message);
750 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
751 msiobj_release(&row->hdr);
752 HeapFree(GetProcessHeap(),0,ActionText);
755 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
759 static const WCHAR template_s[]=
760 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
762 static const WCHAR template_e[]=
763 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
764 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
766 static const WCHAR format[] =
767 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
771 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
773 sprintfW(message,template_s,timet,action);
775 sprintfW(message,template_e,timet,action,rc);
777 row = MSI_CreateRecord(1);
778 MSI_RecordSetStringW(row,1,message);
780 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
781 msiobj_release(&row->hdr);
785 * build_directory_name()
787 * This function is to save messing round with directory names
788 * It handles adding backslashes between path segments,
789 * and can add \ at the end of the directory name if told to.
791 * It takes a variable number of arguments.
792 * It always allocates a new string for the result, so make sure
793 * to free the return value when finished with it.
795 * The first arg is the number of path segments that follow.
796 * The arguments following count are a list of path segments.
797 * A path segment may be NULL.
799 * Path segments will be added with a \ separating them.
800 * A \ will not be added after the last segment, however if the
801 * last segment is NULL, then the last character will be a \
804 static LPWSTR build_directory_name(DWORD count, ...)
811 for(i=0; i<count; i++)
813 LPCWSTR str = va_arg(va,LPCWSTR);
815 sz += strlenW(str) + 1;
819 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
823 for(i=0; i<count; i++)
825 LPCWSTR str = va_arg(va,LPCWSTR);
829 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
835 static BOOL ACTION_VerifyComponentForAction(MSIPACKAGE* package, INT index,
838 if (package->components[index].Installed == check)
841 if (package->components[index].ActionRequest == check)
847 static BOOL ACTION_VerifyFeatureForAction(MSIPACKAGE* package, INT index,
850 if (package->features[index].Installed == check)
853 if (package->features[index].ActionRequest == check)
860 /****************************************************
861 * TOP level entry points
862 *****************************************************/
864 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
865 LPCWSTR szCommandLine)
871 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
872 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
873 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
875 MSI_SetPropertyW(package, szAction, szInstall);
876 package->ExecuteSequenceRun = FALSE;
880 LPWSTR p, check, path;
882 package->PackagePath = strdupW(szPackagePath);
883 path = strdupW(szPackagePath);
884 p = strrchrW(path,'\\');
892 HeapFree(GetProcessHeap(),0,path);
893 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
894 GetCurrentDirectoryW(MAX_PATH,path);
898 check = load_dynamic_property(package, cszSourceDir,NULL);
900 MSI_SetPropertyW(package, cszSourceDir, path);
902 HeapFree(GetProcessHeap(), 0, check);
904 HeapFree(GetProcessHeap(), 0, path);
910 ptr = (LPWSTR)szCommandLine;
917 TRACE("Looking at %s\n",debugstr_w(ptr));
919 ptr2 = strchrW(ptr,'=');
925 while (*ptr == ' ') ptr++;
927 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
928 memcpy(prop,ptr,len*sizeof(WCHAR));
934 while (*ptr && (quote || (!quote && *ptr!=' ')))
947 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
948 memcpy(val,ptr2,len*sizeof(WCHAR));
951 if (strlenW(prop) > 0)
953 TRACE("Found commandline property (%s) = (%s)\n",
954 debugstr_w(prop), debugstr_w(val));
955 MSI_SetPropertyW(package,prop,val);
957 HeapFree(GetProcessHeap(),0,val);
958 HeapFree(GetProcessHeap(),0,prop);
965 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
967 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
969 rc = ACTION_ProcessUISequence(package);
971 if (rc == ERROR_SUCCESS)
972 rc = ACTION_ProcessExecSequence(package,TRUE);
975 rc = ACTION_ProcessExecSequence(package,FALSE);
978 rc = ACTION_ProcessExecSequence(package,FALSE);
982 /* install was halted but should be considered a success */
986 /* process the ending type action */
987 if (rc == ERROR_SUCCESS)
988 ACTION_PerformActionSequence(package,-1,ui);
989 else if (rc == ERROR_INSTALL_USEREXIT)
990 ACTION_PerformActionSequence(package,-2,ui);
991 else if (rc == ERROR_FUNCTION_FAILED)
992 ACTION_PerformActionSequence(package,-3,ui);
993 else if (rc == ERROR_INSTALL_SUSPEND)
994 ACTION_PerformActionSequence(package,-4,ui);
996 /* finish up running custom actions */
997 ACTION_FinishCustomActions(package);
1002 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
1006 WCHAR buffer[0x100];
1008 MSIRECORD * row = 0;
1009 static const WCHAR ExecSeqQuery[] =
1010 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1011 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1012 'S','e','q','u','e','n','c','e',' ', 'W','H','E','R','E',' ',
1013 'S','e','q','u','e','n','c','e',' ', '=',' ','%','i',0};
1015 static const WCHAR UISeqQuery[] =
1016 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1017 'I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1018 ' ', 'W','H','E','R','E',' ', 'S','e','q','u','e','n','c','e',
1019 ' ', '=',' ','%','i',0};
1022 rc = MSI_OpenQuery(package->db, &view, UISeqQuery, seq);
1024 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1026 if (rc == ERROR_SUCCESS)
1028 rc = MSI_ViewExecute(view, 0);
1030 if (rc != ERROR_SUCCESS)
1032 MSI_ViewClose(view);
1033 msiobj_release(&view->hdr);
1037 TRACE("Running the actions\n");
1039 rc = MSI_ViewFetch(view,&row);
1040 if (rc != ERROR_SUCCESS)
1046 /* check conditions */
1047 if (!MSI_RecordIsNull(row,2))
1050 cond = load_dynamic_stringW(row,2);
1054 /* this is a hack to skip errors in the condition code */
1055 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1057 HeapFree(GetProcessHeap(),0,cond);
1058 msiobj_release(&row->hdr);
1062 HeapFree(GetProcessHeap(),0,cond);
1067 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1068 if (rc != ERROR_SUCCESS)
1070 ERR("Error is %x\n",rc);
1071 msiobj_release(&row->hdr);
1076 rc = ACTION_PerformUIAction(package,buffer);
1078 rc = ACTION_PerformAction(package,buffer);
1079 msiobj_release(&row->hdr);
1081 MSI_ViewClose(view);
1082 msiobj_release(&view->hdr);
1090 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1094 static const WCHAR ExecSeqQuery[] =
1095 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1096 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1097 'S','e','q','u','e','n','c','e',' ', 'W','H','E','R','E',' ',
1098 'S','e','q','u','e','n','c','e',' ', '>',' ','%','i',' ',
1099 'O','R','D','E','R',' ', 'B','Y',' ',
1100 'S','e','q','u','e','n','c','e',0 };
1101 MSIRECORD * row = 0;
1102 static const WCHAR IVQuery[] =
1103 {'S','E','L','E','C','T',' ','S','e','q','u','e','n','c','e',' ',
1104 'F','R','O','M',' ','I','n','s','t','a','l','l',
1105 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
1106 'W','H','E','R','E',' ','A','c','t','i','o','n',' ','=',' ','`',
1107 'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`', 0};
1111 if (package->ExecuteSequenceRun)
1113 TRACE("Execute Sequence already Run\n");
1114 return ERROR_SUCCESS;
1117 package->ExecuteSequenceRun = TRUE;
1119 /* get the sequence number */
1122 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
1123 if (rc != ERROR_SUCCESS)
1125 rc = MSI_ViewExecute(view, 0);
1126 if (rc != ERROR_SUCCESS)
1128 MSI_ViewClose(view);
1129 msiobj_release(&view->hdr);
1132 rc = MSI_ViewFetch(view,&row);
1133 if (rc != ERROR_SUCCESS)
1135 MSI_ViewClose(view);
1136 msiobj_release(&view->hdr);
1139 seq = MSI_RecordGetInteger(row,1);
1140 msiobj_release(&row->hdr);
1141 MSI_ViewClose(view);
1142 msiobj_release(&view->hdr);
1145 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1146 if (rc == ERROR_SUCCESS)
1148 rc = MSI_ViewExecute(view, 0);
1150 if (rc != ERROR_SUCCESS)
1152 MSI_ViewClose(view);
1153 msiobj_release(&view->hdr);
1157 TRACE("Running the actions\n");
1161 WCHAR buffer[0x100];
1164 rc = MSI_ViewFetch(view,&row);
1165 if (rc != ERROR_SUCCESS)
1171 /* check conditions */
1172 if (!MSI_RecordIsNull(row,2))
1175 cond = load_dynamic_stringW(row,2);
1179 /* this is a hack to skip errors in the condition code */
1180 if (MSI_EvaluateConditionW(package, cond) ==
1183 HeapFree(GetProcessHeap(),0,cond);
1184 msiobj_release(&row->hdr);
1188 HeapFree(GetProcessHeap(),0,cond);
1193 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1194 if (rc != ERROR_SUCCESS)
1196 ERR("Error is %x\n",rc);
1197 msiobj_release(&row->hdr);
1201 rc = ACTION_PerformAction(package,buffer);
1203 if (rc == ERROR_FUNCTION_NOT_CALLED)
1206 if (rc != ERROR_SUCCESS)
1208 ERR("Execution halted due to error (%i)\n",rc);
1209 msiobj_release(&row->hdr);
1213 msiobj_release(&row->hdr);
1216 MSI_ViewClose(view);
1217 msiobj_release(&view->hdr);
1225 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1229 static const WCHAR ExecSeqQuery [] =
1230 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1231 'I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1232 ' ','W','H','E','R','E',' ', 'S','e','q','u','e','n','c','e',' ',
1233 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1234 'S','e','q','u','e','n','c','e',0};
1236 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1238 if (rc == ERROR_SUCCESS)
1240 rc = MSI_ViewExecute(view, 0);
1242 if (rc != ERROR_SUCCESS)
1244 MSI_ViewClose(view);
1245 msiobj_release(&view->hdr);
1249 TRACE("Running the actions \n");
1253 WCHAR buffer[0x100];
1255 MSIRECORD * row = 0;
1257 rc = MSI_ViewFetch(view,&row);
1258 if (rc != ERROR_SUCCESS)
1264 /* check conditions */
1265 if (!MSI_RecordIsNull(row,2))
1268 cond = load_dynamic_stringW(row,2);
1272 /* this is a hack to skip errors in the condition code */
1273 if (MSI_EvaluateConditionW(package, cond) ==
1276 HeapFree(GetProcessHeap(),0,cond);
1277 msiobj_release(&row->hdr);
1281 HeapFree(GetProcessHeap(),0,cond);
1286 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1287 if (rc != ERROR_SUCCESS)
1289 ERR("Error is %x\n",rc);
1290 msiobj_release(&row->hdr);
1294 rc = ACTION_PerformUIAction(package,buffer);
1296 if (rc == ERROR_FUNCTION_NOT_CALLED)
1299 if (rc != ERROR_SUCCESS)
1301 ERR("Execution halted due to error (%i)\n",rc);
1302 msiobj_release(&row->hdr);
1306 msiobj_release(&row->hdr);
1309 MSI_ViewClose(view);
1310 msiobj_release(&view->hdr);
1317 /********************************************************
1318 * ACTION helper functions and functions that perform the actions
1319 *******************************************************/
1320 BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action, UINT* rc)
1326 while (StandardActions[i].action != NULL)
1328 if (strcmpW(StandardActions[i].action, action)==0)
1330 ui_actioninfo(package, action, TRUE, 0);
1331 ui_actionstart(package, action);
1332 if (StandardActions[i].handler)
1334 *rc = StandardActions[i].handler(package);
1338 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1339 *rc = ERROR_SUCCESS;
1341 ui_actioninfo(package, action, FALSE, *rc);
1350 BOOL ACTION_HandleDialogBox(MSIPACKAGE *package, LPCWSTR dialog, UINT* rc)
1355 * for the UI when we get that working
1357 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1359 *rc = package->CurrentInstallState;
1366 BOOL ACTION_HandleCustomAction(MSIPACKAGE* package, LPCWSTR action, UINT* rc)
1371 arc = ACTION_CustomAction(package,action,FALSE);
1373 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1382 * A lot of actions are really important even if they don't do anything
1383 * explicit... Lots of properties are set at the beginning of the installation
1384 * CostFinalize does a bunch of work to translate the directories and such
1386 * But until I get write access to the database that is hard, so I am going to
1387 * hack it to see if I can get something to run.
1389 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
1391 UINT rc = ERROR_SUCCESS;
1394 TRACE("Performing action (%s)\n",debugstr_w(action));
1396 handled = ACTION_HandleStandardAction(package, action, &rc);
1399 handled = ACTION_HandleCustomAction(package, action, &rc);
1403 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1404 rc = ERROR_FUNCTION_NOT_CALLED;
1407 package->CurrentInstallState = rc;
1411 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1413 UINT rc = ERROR_SUCCESS;
1414 BOOL handled = FALSE;
1416 TRACE("Performing action (%s)\n",debugstr_w(action));
1418 handled = ACTION_HandleStandardAction(package, action, &rc);
1421 handled = ACTION_HandleCustomAction(package, action, &rc);
1424 handled = ACTION_HandleDialogBox(package, action, &rc);
1426 msi_dialog_check_messages( NULL );
1430 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1431 rc = ERROR_FUNCTION_NOT_CALLED;
1434 package->CurrentInstallState = rc;
1438 /***********************************************************************
1441 * Recursively create all directories in the path.
1443 * shamelessly stolen from setupapi/queue.c
1445 static BOOL create_full_pathW(const WCHAR *path)
1451 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1454 strcpyW(new_path, path);
1456 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1457 new_path[len - 1] = 0;
1459 while(!CreateDirectoryW(new_path, NULL))
1462 DWORD last_error = GetLastError();
1463 if(last_error == ERROR_ALREADY_EXISTS)
1466 if(last_error != ERROR_PATH_NOT_FOUND)
1472 if(!(slash = strrchrW(new_path, '\\')))
1478 len = slash - new_path;
1480 if(!create_full_pathW(new_path))
1485 new_path[len] = '\\';
1488 HeapFree(GetProcessHeap(), 0, new_path);
1493 * Also we cannot enable/disable components either, so for now I am just going
1494 * to do all the directories for all the components.
1496 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1498 static const WCHAR ExecSeqQuery[] =
1499 {'S','E','L','E','C','T',' ','D','i','r','e','c','t','o','r','y','_',
1500 ' ','F','R','O','M',' ',
1501 'C','r','e','a','t','e','F','o','l','d','e','r',0 };
1506 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1507 if (rc != ERROR_SUCCESS)
1508 return ERROR_SUCCESS;
1510 rc = MSI_ViewExecute(view, 0);
1511 if (rc != ERROR_SUCCESS)
1513 MSI_ViewClose(view);
1514 msiobj_release(&view->hdr);
1523 MSIRECORD *row = NULL, *uirow;
1525 rc = MSI_ViewFetch(view,&row);
1526 if (rc != ERROR_SUCCESS)
1533 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1535 if (rc!= ERROR_SUCCESS)
1537 ERR("Unable to get folder id \n");
1538 msiobj_release(&row->hdr);
1543 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1546 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1547 msiobj_release(&row->hdr);
1551 TRACE("Folder is %s\n",debugstr_w(full_path));
1554 uirow = MSI_CreateRecord(1);
1555 MSI_RecordSetStringW(uirow,1,full_path);
1556 ui_actiondata(package,szCreateFolders,uirow);
1557 msiobj_release( &uirow->hdr );
1559 if (folder->State == 0)
1560 create_full_pathW(full_path);
1564 msiobj_release(&row->hdr);
1565 HeapFree(GetProcessHeap(),0,full_path);
1567 MSI_ViewClose(view);
1568 msiobj_release(&view->hdr);
1573 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1575 int index = package->loaded_components;
1578 /* fill in the data */
1580 package->loaded_components++;
1581 if (package->loaded_components == 1)
1582 package->components = HeapAlloc(GetProcessHeap(),0,
1583 sizeof(MSICOMPONENT));
1585 package->components = HeapReAlloc(GetProcessHeap(),0,
1586 package->components, package->loaded_components *
1587 sizeof(MSICOMPONENT));
1589 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1592 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1594 TRACE("Loading Component %s\n",
1595 debugstr_w(package->components[index].Component));
1598 if (!MSI_RecordIsNull(row,2))
1599 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1602 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1604 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1607 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1610 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1612 package->components[index].Installed = INSTALLSTATE_UNKNOWN;
1613 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1614 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1616 package->components[index].Enabled = TRUE;
1621 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1623 int index = package->loaded_features;
1625 static const WCHAR Query1[] =
1626 {'S','E','L','E','C','T',' ','C','o','m','p','o','n','e','n','t','_',
1627 ' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1628 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ',
1629 'F','e', 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1630 static const WCHAR Query2[] =
1631 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1632 'C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ',
1633 'C','o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1640 /* fill in the data */
1642 package->loaded_features ++;
1643 if (package->loaded_features == 1)
1644 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1646 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1647 package->loaded_features * sizeof(MSIFEATURE));
1649 memset(&package->features[index],0,sizeof(MSIFEATURE));
1652 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1654 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1657 if (!MSI_RecordIsNull(row,2))
1658 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1661 if (!MSI_RecordIsNull(row,3))
1662 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1665 if (!MSI_RecordIsNull(row,4))
1666 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1668 if (!MSI_RecordIsNull(row,5))
1669 package->features[index].Display = MSI_RecordGetInteger(row,5);
1671 package->features[index].Level= MSI_RecordGetInteger(row,6);
1674 if (!MSI_RecordIsNull(row,7))
1675 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1677 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1679 package->features[index].Installed = INSTALLSTATE_UNKNOWN;
1680 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1681 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1683 /* load feature components */
1685 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1686 if (rc != ERROR_SUCCESS)
1688 rc = MSI_ViewExecute(view,0);
1689 if (rc != ERROR_SUCCESS)
1691 MSI_ViewClose(view);
1692 msiobj_release(&view->hdr);
1698 WCHAR buffer[0x100];
1701 INT cnt = package->features[index].ComponentCount;
1703 rc = MSI_ViewFetch(view,&row2);
1704 if (rc != ERROR_SUCCESS)
1708 MSI_RecordGetStringW(row2,1,buffer,&sz);
1710 /* check to see if the component is already loaded */
1711 c_indx = get_loaded_component(package,buffer);
1714 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1716 package->features[index].Components[cnt] = c_indx;
1717 package->features[index].ComponentCount ++;
1718 msiobj_release( &row2->hdr );
1722 rc = MSI_OpenQuery(package->db, &view2, Query2, buffer);
1723 if (rc != ERROR_SUCCESS)
1725 msiobj_release( &row2->hdr );
1728 rc = MSI_ViewExecute(view2,0);
1729 if (rc != ERROR_SUCCESS)
1731 msiobj_release( &row2->hdr );
1732 MSI_ViewClose(view2);
1733 msiobj_release( &view2->hdr );
1740 rc = MSI_ViewFetch(view2,&row3);
1741 if (rc != ERROR_SUCCESS)
1743 c_indx = load_component(package,row3);
1744 msiobj_release( &row3->hdr );
1746 package->features[index].Components[cnt] = c_indx;
1747 package->features[index].ComponentCount ++;
1748 TRACE("Loaded new component to index %i\n",c_indx);
1750 MSI_ViewClose(view2);
1751 msiobj_release( &view2->hdr );
1752 msiobj_release( &row2->hdr );
1754 MSI_ViewClose(view);
1755 msiobj_release(&view->hdr);
1759 * I am not doing any of the costing functionality yet.
1760 * Mostly looking at doing the Component and Feature loading
1762 * The native MSI does A LOT of modification to tables here. Mostly adding
1763 * a lot of temporary columns to the Feature and Component tables.
1765 * note: Native msi also tracks the short filename. But I am only going to
1766 * track the long ones. Also looking at this directory table
1767 * it appears that the directory table does not get the parents
1768 * resolved base on property only based on their entries in the
1771 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1776 static const WCHAR Query_all[] =
1777 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1778 'F','e','a','t','u','r','e',0};
1779 static const WCHAR szCosting[] =
1780 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1781 static const WCHAR szZero[] = { '0', 0 };
1783 MSI_SetPropertyW(package, szCosting, szZero);
1784 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1786 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1787 if (rc != ERROR_SUCCESS)
1789 rc = MSI_ViewExecute(view,0);
1790 if (rc != ERROR_SUCCESS)
1792 MSI_ViewClose(view);
1793 msiobj_release(&view->hdr);
1800 rc = MSI_ViewFetch(view,&row);
1801 if (rc != ERROR_SUCCESS)
1804 load_feature(package,row);
1805 msiobj_release(&row->hdr);
1807 MSI_ViewClose(view);
1808 msiobj_release(&view->hdr);
1810 return ERROR_SUCCESS;
1813 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1815 DWORD index = package->loaded_files;
1819 /* fill in the data */
1821 package->loaded_files++;
1822 if (package->loaded_files== 1)
1823 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1825 package->files = HeapReAlloc(GetProcessHeap(),0,
1826 package->files , package->loaded_files * sizeof(MSIFILE));
1828 memset(&package->files[index],0,sizeof(MSIFILE));
1830 package->files[index].File = load_dynamic_stringW(row, 1);
1831 buffer = load_dynamic_stringW(row, 2);
1833 package->files[index].ComponentIndex = -1;
1834 for (i = 0; i < package->loaded_components; i++)
1835 if (strcmpW(package->components[i].Component,buffer)==0)
1837 package->files[index].ComponentIndex = i;
1840 if (package->files[index].ComponentIndex == -1)
1841 ERR("Unfound Component %s\n",debugstr_w(buffer));
1842 HeapFree(GetProcessHeap(), 0, buffer);
1844 package->files[index].FileName = load_dynamic_stringW(row,3);
1846 reduce_to_longfilename(package->files[index].FileName);
1848 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1849 package->files[index].Version = load_dynamic_stringW(row, 5);
1850 package->files[index].Language = load_dynamic_stringW(row, 6);
1851 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1852 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1854 package->files[index].Temporary = FALSE;
1855 package->files[index].State = 0;
1857 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1859 return ERROR_SUCCESS;
1862 static UINT ACTION_FileCost(MSIPACKAGE *package)
1867 static const WCHAR Query[] =
1868 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1869 'F','i','l','e',' ', 'O','R','D','E','R',' ','B','Y',' ',
1870 'S','e','q','u','e','n','c','e', 0};
1873 return ERROR_INVALID_HANDLE;
1875 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1876 if (rc != ERROR_SUCCESS)
1877 return ERROR_SUCCESS;
1879 rc = MSI_ViewExecute(view, 0);
1880 if (rc != ERROR_SUCCESS)
1882 MSI_ViewClose(view);
1883 msiobj_release(&view->hdr);
1884 return ERROR_SUCCESS;
1889 rc = MSI_ViewFetch(view,&row);
1890 if (rc != ERROR_SUCCESS)
1895 load_file(package,row);
1896 msiobj_release(&row->hdr);
1898 MSI_ViewClose(view);
1899 msiobj_release(&view->hdr);
1901 return ERROR_SUCCESS;
1904 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1906 static const WCHAR Query[] =
1907 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1908 'D','i','r','e','c', 't','o','r','y',' ','W','H','E','R','E',' ','`',
1909 'D','i','r','e','c','t', 'o','r','y','`',' ','=',' ','`','%','s','`',
1913 LPWSTR ptargetdir, targetdir, parent, srcdir;
1914 MSIRECORD * row = 0;
1918 TRACE("Looking for dir %s\n",debugstr_w(dir));
1920 for (i = 0; i < package->loaded_folders; i++)
1922 if (strcmpW(package->folders[i].Directory,dir)==0)
1924 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1929 TRACE("Working to load %s\n",debugstr_w(dir));
1931 index = package->loaded_folders++;
1932 if (package->loaded_folders==1)
1933 package->folders = HeapAlloc(GetProcessHeap(),0,
1936 package->folders= HeapReAlloc(GetProcessHeap(),0,
1937 package->folders, package->loaded_folders*
1940 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1942 package->folders[index].Directory = strdupW(dir);
1944 rc = MSI_OpenQuery(package->db, &view, Query, dir);
1945 if (rc != ERROR_SUCCESS)
1948 rc = MSI_ViewExecute(view, 0);
1949 if (rc != ERROR_SUCCESS)
1951 MSI_ViewClose(view);
1952 msiobj_release(&view->hdr);
1956 rc = MSI_ViewFetch(view,&row);
1957 if (rc != ERROR_SUCCESS)
1959 MSI_ViewClose(view);
1960 msiobj_release(&view->hdr);
1964 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1966 /* split src and target dir */
1967 if (strchrW(targetdir,':'))
1969 srcdir=strchrW(targetdir,':');
1976 /* for now only pick long filename versions */
1977 if (strchrW(targetdir,'|'))
1979 targetdir = strchrW(targetdir,'|');
1983 if (srcdir && strchrW(srcdir,'|'))
1985 srcdir= strchrW(srcdir,'|');
1990 /* now check for root dirs */
1991 if (targetdir[0] == '.' && targetdir[1] == 0)
1994 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1999 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2000 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2001 package->folders[index].TargetDefault = strdupW(targetdir);
2005 package->folders[index].SourceDefault = strdupW(srcdir);
2007 package->folders[index].SourceDefault = strdupW(targetdir);
2008 HeapFree(GetProcessHeap(), 0, ptargetdir);
2010 parent = load_dynamic_stringW(row,2);
2013 i = load_folder(package,parent);
2014 package->folders[index].ParentIndex = i;
2015 TRACE("Parent is index %i... %s %s\n",
2016 package->folders[index].ParentIndex,
2017 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2018 debugstr_w(parent));
2021 package->folders[index].ParentIndex = -2;
2022 HeapFree(GetProcessHeap(), 0, parent);
2024 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2026 msiobj_release(&row->hdr);
2027 MSI_ViewClose(view);
2028 msiobj_release(&view->hdr);
2029 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2034 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
2035 BOOL set_prop, MSIFOLDER **folder)
2038 LPWSTR p, path = NULL;
2040 TRACE("Working to resolve %s\n",debugstr_w(name));
2042 /* special resolving for Target and Source root dir */
2043 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2047 path = load_dynamic_property(package,cszTargetDir,NULL);
2050 path = load_dynamic_property(package,cszRootDrive,NULL);
2052 MSI_SetPropertyW(package,cszTargetDir,path);
2056 for (i = 0; i < package->loaded_folders; i++)
2058 if (strcmpW(package->folders[i].Directory,name)==0)
2061 *folder = &(package->folders[i]);
2067 path = load_dynamic_property(package,cszSourceDir,NULL);
2070 path = load_dynamic_property(package,cszDatabase,NULL);
2073 p = strrchrW(path,'\\');
2080 for (i = 0; i < package->loaded_folders; i++)
2082 if (strcmpW(package->folders[i].Directory,name)==0)
2085 *folder = &(package->folders[i]);
2091 for (i = 0; i < package->loaded_folders; i++)
2093 if (strcmpW(package->folders[i].Directory,name)==0)
2097 if (i >= package->loaded_folders)
2101 *folder = &(package->folders[i]);
2103 if (!source && package->folders[i].ResolvedTarget)
2105 path = strdupW(package->folders[i].ResolvedTarget);
2106 TRACE(" already resolved to %s\n",debugstr_w(path));
2109 else if (source && package->folders[i].ResolvedSource)
2111 path = strdupW(package->folders[i].ResolvedSource);
2114 else if (!source && package->folders[i].Property)
2116 path = build_directory_name(2, package->folders[i].Property, NULL);
2118 TRACE(" internally set to %s\n",debugstr_w(path));
2120 MSI_SetPropertyW(package,name,path);
2124 if (package->folders[i].ParentIndex >= 0)
2126 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2128 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2130 p = resolve_folder(package, parent, source, set_prop, NULL);
2133 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2134 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2135 package->folders[i].ResolvedTarget = strdupW(path);
2136 TRACE(" resolved into %s\n",debugstr_w(path));
2138 MSI_SetPropertyW(package,name,path);
2142 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2143 package->folders[i].ResolvedSource = strdupW(path);
2145 HeapFree(GetProcessHeap(),0,p);
2150 /* scan for and update current install states */
2151 void ACTION_UpdateInstallStates(MSIPACKAGE *package)
2156 productcode = load_dynamic_property(package,szProductCode,NULL);
2158 for (i = 0; i < package->loaded_components; i++)
2161 res = MsiGetComponentPathW(productcode,
2162 package->components[i].ComponentId , NULL, NULL);
2164 res = INSTALLSTATE_ABSENT;
2165 package->components[i].Installed = res;
2168 for (i = 0; i < package->loaded_features; i++)
2170 INSTALLSTATE res = -10;
2172 for (j = 0; j < package->features[i].ComponentCount; j++)
2174 MSICOMPONENT* component = &package->components[package->features[i].
2177 res = component->Installed;
2180 if (res == component->Installed)
2183 if (res != component->Installed)
2184 res = INSTALLSTATE_INCOMPLETE;
2190 /* update compoennt state based on a feature change */
2191 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2194 INSTALLSTATE newstate;
2195 MSIFEATURE *feature;
2197 i = get_loaded_feature(package,szFeature);
2201 feature = &package->features[i];
2202 newstate = feature->ActionRequest;
2204 for( i = 0; i < feature->ComponentCount; i++)
2206 MSICOMPONENT* component = &package->components[feature->Components[i]];
2208 if (!component->Enabled)
2212 if (newstate == INSTALLSTATE_LOCAL)
2213 component->ActionRequest = INSTALLSTATE_LOCAL;
2218 component->ActionRequest = newstate;
2220 /*if any other feature wants is local we need to set it local*/
2222 j < package->loaded_features &&
2223 component->ActionRequest != INSTALLSTATE_LOCAL;
2226 for (k = 0; k < package->features[j].ComponentCount; k++)
2227 if ( package->features[j].Components[k] ==
2228 feature->Components[i] )
2230 if (package->features[j].ActionRequest ==
2232 component->ActionRequest = INSTALLSTATE_LOCAL;
2241 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
2244 static const WCHAR all[]={'A','L','L',0};
2245 LPWSTR override = NULL;
2249 override = load_dynamic_property(package, property, NULL);
2253 for(i = 0; i < package->loaded_features; i++)
2255 if (strcmpiW(override,all)==0)
2257 package->features[i].ActionRequest= state;
2258 package->features[i].Action = state;
2262 LPWSTR ptr = override;
2263 LPWSTR ptr2 = strchrW(override,',');
2268 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2270 strcmpW(ptr,package->features[i].Feature)==0))
2272 package->features[i].ActionRequest= state;
2273 package->features[i].Action = state;
2279 ptr2 = strchrW(ptr,',');
2286 HeapFree(GetProcessHeap(),0,override);
2292 static UINT SetFeatureStates(MSIPACKAGE *package)
2298 static const WCHAR szlevel[] =
2299 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2300 static const WCHAR szAddLocal[] =
2301 {'A','D','D','L','O','C','A','L',0};
2302 static const WCHAR szRemove[] =
2303 {'R','E','M','O','V','E',0};
2304 BOOL override = FALSE;
2306 /* I do not know if this is where it should happen.. but */
2308 TRACE("Checking Install Level\n");
2310 level = load_dynamic_property(package,szlevel,NULL);
2313 install_level = atoiW(level);
2314 HeapFree(GetProcessHeap(), 0, level);
2319 /* ok hereis the _real_ rub
2320 * all these activation/deactivation things happen in order and things
2321 * later on the list override things earlier on the list.
2322 * 1) INSTALLLEVEL processing
2332 * 11) FILEADDDEFAULT
2333 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2334 * ignored for all the features. seems strange, especially since it is not
2335 * documented anywhere, but it is how it works.
2337 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2338 * REMOVE are the big ones, since we don't handle administrative installs
2341 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
2342 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
2346 for(i = 0; i < package->loaded_features; i++)
2348 BOOL feature_state = ((package->features[i].Level > 0) &&
2349 (package->features[i].Level <= install_level));
2353 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
2354 package->features[i].Action = INSTALLSTATE_LOCAL;
2360 * now we want to enable or disable components base on feature
2363 for(i = 0; i < package->loaded_features; i++)
2365 MSIFEATURE* feature = &package->features[i];
2366 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2367 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2368 feature->ActionRequest);
2370 for( j = 0; j < feature->ComponentCount; j++)
2372 MSICOMPONENT* component = &package->components[
2373 feature->Components[j]];
2375 if (!component->Enabled)
2377 component->Action = INSTALLSTATE_UNKNOWN;
2378 component->ActionRequest = INSTALLSTATE_UNKNOWN;
2382 if (feature->Action == INSTALLSTATE_LOCAL)
2384 component->Action = INSTALLSTATE_LOCAL;
2385 component->ActionRequest = INSTALLSTATE_LOCAL;
2387 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
2389 if (component->Action == INSTALLSTATE_UNKNOWN)
2391 component->Action = INSTALLSTATE_ABSENT;
2392 component->ActionRequest = INSTALLSTATE_ABSENT;
2399 for(i = 0; i < package->loaded_components; i++)
2401 MSICOMPONENT* component= &package->components[i];
2403 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2404 debugstr_w(component->Component), component->Installed,
2405 component->Action, component->ActionRequest);
2409 return ERROR_SUCCESS;
2413 * A lot is done in this function aside from just the costing.
2414 * The costing needs to be implemented at some point but for now I am going
2415 * to focus on the directory building
2418 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2420 static const WCHAR ExecSeqQuery[] =
2421 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2422 'D','i','r','e','c','t','o','r','y',0};
2423 static const WCHAR ConditionQuery[] =
2424 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2425 'C','o','n','d','i','t','i','o','n',0};
2426 static const WCHAR szCosting[] =
2427 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2428 static const WCHAR szlevel[] =
2429 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2430 static const WCHAR szOne[] = { '1', 0 };
2436 TRACE("Building Directory properties\n");
2438 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2439 if (rc == ERROR_SUCCESS)
2441 rc = MSI_ViewExecute(view, 0);
2442 if (rc != ERROR_SUCCESS)
2444 MSI_ViewClose(view);
2445 msiobj_release(&view->hdr);
2453 MSIRECORD * row = 0;
2456 rc = MSI_ViewFetch(view,&row);
2457 if (rc != ERROR_SUCCESS)
2464 MSI_RecordGetStringW(row,1,name,&sz);
2466 /* This helper function now does ALL the work */
2467 TRACE("Dir %s ...\n",debugstr_w(name));
2468 load_folder(package,name);
2469 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2470 TRACE("resolves to %s\n",debugstr_w(path));
2471 HeapFree( GetProcessHeap(), 0, path);
2473 msiobj_release(&row->hdr);
2475 MSI_ViewClose(view);
2476 msiobj_release(&view->hdr);
2479 TRACE("File calculations %i files\n",package->loaded_files);
2481 for (i = 0; i < package->loaded_files; i++)
2483 MSICOMPONENT* comp = NULL;
2484 MSIFILE* file= NULL;
2486 file = &package->files[i];
2487 if (file->ComponentIndex >= 0)
2488 comp = &package->components[file->ComponentIndex];
2490 if (file->Temporary == TRUE)
2497 /* calculate target */
2498 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2500 HeapFree(GetProcessHeap(),0,file->TargetPath);
2502 TRACE("file %s is named %s\n",
2503 debugstr_w(file->File),debugstr_w(file->FileName));
2505 file->TargetPath = build_directory_name(2, p, file->FileName);
2507 HeapFree(GetProcessHeap(),0,p);
2509 TRACE("file %s resolves to %s\n",
2510 debugstr_w(file->File),debugstr_w(file->TargetPath));
2512 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2515 comp->Cost += file->FileSize;
2525 static const WCHAR name[] =
2527 static const WCHAR name_fmt[] =
2528 {'%','u','.','%','u','.','%','u','.','%','u',0};
2529 WCHAR filever[0x100];
2530 VS_FIXEDFILEINFO *lpVer;
2532 TRACE("Version comparison.. \n");
2533 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2534 version = HeapAlloc(GetProcessHeap(),0,versize);
2535 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2537 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2539 sprintfW(filever,name_fmt,
2540 HIWORD(lpVer->dwFileVersionMS),
2541 LOWORD(lpVer->dwFileVersionMS),
2542 HIWORD(lpVer->dwFileVersionLS),
2543 LOWORD(lpVer->dwFileVersionLS));
2545 TRACE("new %s old %s\n", debugstr_w(file->Version),
2546 debugstr_w(filever));
2547 if (strcmpiW(filever,file->Version)<0)
2550 FIXME("cost should be diff in size\n");
2551 comp->Cost += file->FileSize;
2555 HeapFree(GetProcessHeap(),0,version);
2563 TRACE("Evaluating Condition Table\n");
2565 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2566 if (rc == ERROR_SUCCESS)
2568 rc = MSI_ViewExecute(view, 0);
2569 if (rc != ERROR_SUCCESS)
2571 MSI_ViewClose(view);
2572 msiobj_release(&view->hdr);
2578 WCHAR Feature[0x100];
2579 MSIRECORD * row = 0;
2583 rc = MSI_ViewFetch(view,&row);
2585 if (rc != ERROR_SUCCESS)
2592 MSI_RecordGetStringW(row,1,Feature,&sz);
2594 feature_index = get_loaded_feature(package,Feature);
2595 if (feature_index < 0)
2596 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2600 Condition = load_dynamic_stringW(row,3);
2602 if (MSI_EvaluateConditionW(package,Condition) ==
2605 int level = MSI_RecordGetInteger(row,2);
2606 TRACE("Reseting feature %s to level %i\n",
2607 debugstr_w(Feature), level);
2608 package->features[feature_index].Level = level;
2610 HeapFree(GetProcessHeap(),0,Condition);
2613 msiobj_release(&row->hdr);
2615 MSI_ViewClose(view);
2616 msiobj_release(&view->hdr);
2619 TRACE("Enabling or Disabling Components\n");
2620 for (i = 0; i < package->loaded_components; i++)
2622 if (package->components[i].Condition[0])
2624 if (MSI_EvaluateConditionW(package,
2625 package->components[i].Condition) == MSICONDITION_FALSE)
2627 TRACE("Disabling component %s\n",
2628 debugstr_w(package->components[i].Component));
2629 package->components[i].Enabled = FALSE;
2634 MSI_SetPropertyW(package,szCosting,szOne);
2635 /* set default run level if not set */
2636 level = load_dynamic_property(package,szlevel,NULL);
2638 MSI_SetPropertyW(package,szlevel, szOne);
2640 HeapFree(GetProcessHeap(),0,level);
2642 ACTION_UpdateInstallStates(package);
2644 return SetFeatureStates(package);
2648 * This is a helper function for handling embedded cabinet media
2650 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2658 WCHAR tmp[MAX_PATH];
2660 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2661 if (rc != ERROR_SUCCESS)
2665 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2666 GetTempPathW(MAX_PATH,tmp);
2668 GetTempFileNameW(tmp,stream_name,0,source);
2670 track_tempfile(package,strrchrW(source,'\\'), source);
2671 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2672 FILE_ATTRIBUTE_NORMAL, NULL);
2674 if (the_file == INVALID_HANDLE_VALUE)
2676 rc = ERROR_FUNCTION_FAILED;
2680 WriteFile(the_file,data,size,&write,NULL);
2681 CloseHandle(the_file);
2682 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2684 HeapFree(GetProcessHeap(),0,data);
2689 /* Support functions for FDI functions */
2692 MSIPACKAGE* package;
2697 static void * cabinet_alloc(ULONG cb)
2699 return HeapAlloc(GetProcessHeap(), 0, cb);
2702 static void cabinet_free(void *pv)
2704 HeapFree(GetProcessHeap(), 0, pv);
2707 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2710 DWORD dwShareMode = 0;
2711 DWORD dwCreateDisposition = OPEN_EXISTING;
2712 switch (oflag & _O_ACCMODE)
2715 dwAccess = GENERIC_READ;
2716 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2719 dwAccess = GENERIC_WRITE;
2720 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2723 dwAccess = GENERIC_READ | GENERIC_WRITE;
2724 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2727 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2728 dwCreateDisposition = CREATE_NEW;
2729 else if (oflag & _O_CREAT)
2730 dwCreateDisposition = CREATE_ALWAYS;
2731 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
2732 dwCreateDisposition, 0, NULL);
2735 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2738 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2743 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2746 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2751 static int cabinet_close(INT_PTR hf)
2753 return CloseHandle((HANDLE)hf) ? 0 : -1;
2756 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2758 /* flags are compatible and so are passed straight through */
2759 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2762 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2764 /* FIXME: try to do more processing in this function */
2767 case fdintCOPY_FILE:
2769 CabData *data = (CabData*) pfdin->pv;
2770 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2775 LPWSTR tracknametmp;
2776 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2778 if (data->file_name && strcmp(data->file_name,pfdin->psz1))
2781 file = cabinet_alloc((len+1)*sizeof(char));
2782 strcpy(file, data->cab_path);
2783 strcat(file, pfdin->psz1);
2785 TRACE("file: %s\n", debugstr_a(file));
2787 /* track this file so it can be deleted if not installed */
2788 trackpath=strdupAtoW(file);
2789 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2790 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2791 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2793 strcpyW(trackname,tmpprefix);
2794 strcatW(trackname,tracknametmp);
2796 track_tempfile(data->package, trackname, trackpath);
2798 HeapFree(GetProcessHeap(),0,trackpath);
2799 HeapFree(GetProcessHeap(),0,trackname);
2800 HeapFree(GetProcessHeap(),0,tracknametmp);
2802 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2804 case fdintCLOSE_FILE_INFO:
2808 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2810 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2812 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2815 cabinet_close(pfdin->hf);
2823 /***********************************************************************
2824 * extract_cabinet_file
2826 * Extract files from a cab file.
2828 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2829 const WCHAR* path, const WCHAR* file)
2839 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2840 debugstr_w(file), debugstr_w(path));
2842 hfdi = FDICreate(cabinet_alloc,
2853 ERR("FDICreate failed\n");
2857 if (!(cabinet = strdupWtoA( source )))
2862 if (!(cab_path = strdupWtoA( path )))
2865 HeapFree(GetProcessHeap(), 0, cabinet);
2869 data.package = package;
2870 data.cab_path = cab_path;
2872 file_name = strdupWtoA(file);
2875 data.file_name = file_name;
2877 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
2880 ERR("FDICopy failed\n");
2884 HeapFree(GetProcessHeap(), 0, cabinet);
2885 HeapFree(GetProcessHeap(), 0, cab_path);
2886 HeapFree(GetProcessHeap(), 0, file_name);
2891 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2892 WCHAR* path, WCHAR* file)
2896 MSIRECORD * row = 0;
2897 static WCHAR source[MAX_PATH];
2898 static const WCHAR ExecSeqQuery[] =
2899 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2900 'M','e','d','i','a',' ','W','H','E','R','E',' ',
2901 'L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%',
2902 'i',' ','O','R','D','E','R',' ','B','Y',' ',
2903 'L','a','s','t','S','e','q','u','e','n','c','e',0};
2908 static UINT last_sequence = 0;
2910 if (sequence <= last_sequence)
2912 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2913 /*extract_a_cabinet_file(package, source,path,file); */
2914 return ERROR_SUCCESS;
2917 sprintfW(Query,ExecSeqQuery,sequence);
2919 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2920 if (rc != ERROR_SUCCESS)
2923 rc = MSI_ViewExecute(view, 0);
2924 if (rc != ERROR_SUCCESS)
2926 MSI_ViewClose(view);
2927 msiobj_release(&view->hdr);
2931 rc = MSI_ViewFetch(view,&row);
2932 if (rc != ERROR_SUCCESS)
2934 MSI_ViewClose(view);
2935 msiobj_release(&view->hdr);
2938 seq = MSI_RecordGetInteger(row,2);
2939 last_sequence = seq;
2941 if (!MSI_RecordIsNull(row,4))
2944 MSI_RecordGetStringW(row,4,cab,&sz);
2945 TRACE("Source is CAB %s\n",debugstr_w(cab));
2946 /* the stream does not contain the # character */
2949 writeout_cabinet_stream(package,&cab[1],source);
2950 strcpyW(path,source);
2951 *(strrchrW(path,'\\')+1)=0;
2956 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2958 ERR("No Source dir defined \n");
2959 rc = ERROR_FUNCTION_FAILED;
2963 strcpyW(path,source);
2964 strcatW(source,cab);
2965 /* extract the cab file into a folder in the temp folder */
2967 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2969 GetTempPathW(MAX_PATH,path);
2972 rc = !extract_a_cabinet_file(package, source,path,NULL);
2977 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
2978 strcpyW(path,source);
2980 msiobj_release(&row->hdr);
2981 MSI_ViewClose(view);
2982 msiobj_release(&view->hdr);
2986 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2988 UINT rc = ERROR_SUCCESS;
2990 LPWSTR install_path;
2992 install_path = resolve_folder(package, package->components[component].Directory,
2993 FALSE, FALSE, &folder);
2995 return ERROR_FUNCTION_FAILED;
2997 /* create the path */
2998 if (folder->State == 0)
3000 create_full_pathW(install_path);
3003 HeapFree(GetProcessHeap(), 0, install_path);
3008 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3010 UINT rc = ERROR_SUCCESS;
3013 WCHAR uipath[MAX_PATH];
3016 return ERROR_INVALID_HANDLE;
3018 /* increment progress bar each time action data is sent */
3019 ui_progress(package,1,1,0,0);
3021 for (index = 0; index < package->loaded_files; index++)
3023 WCHAR path_to_source[MAX_PATH];
3026 file = &package->files[index];
3028 if (file->Temporary)
3032 if (!ACTION_VerifyComponentForAction(package, file->ComponentIndex,
3033 INSTALLSTATE_LOCAL))
3035 ui_progress(package,2,file->FileSize,0,0);
3036 TRACE("File %s is not scheduled for install\n",
3037 debugstr_w(file->File));
3042 if ((file->State == 1) || (file->State == 2))
3046 MSICOMPONENT* comp = NULL;
3048 TRACE("Installing %s\n",debugstr_w(file->File));
3049 rc = ready_media_for_file(package,file->Sequence,path_to_source,
3053 * our file table could change here because a new temp file
3054 * may have been created
3056 file = &package->files[index];
3057 if (rc != ERROR_SUCCESS)
3059 ERR("Unable to ready media\n");
3060 rc = ERROR_FUNCTION_FAILED;
3064 create_component_directory( package, file->ComponentIndex);
3066 /* recalculate file paths because things may have changed */
3068 if (file->ComponentIndex >= 0)
3069 comp = &package->components[file->ComponentIndex];
3071 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3072 HeapFree(GetProcessHeap(),0,file->TargetPath);
3074 file->TargetPath = build_directory_name(2, p, file->FileName);
3076 len = strlenW(path_to_source) + strlenW(file->File) + 2;
3077 file->SourcePath = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3078 strcpyW(file->SourcePath, path_to_source);
3079 strcatW(file->SourcePath, file->File);
3081 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3082 debugstr_w(file->TargetPath));
3085 uirow=MSI_CreateRecord(9);
3086 MSI_RecordSetStringW(uirow,1,file->File);
3087 strcpyW(uipath,file->TargetPath);
3088 *(strrchrW(uipath,'\\')+1)=0;
3089 MSI_RecordSetStringW(uirow,9,uipath);
3090 MSI_RecordSetInteger(uirow,6,file->FileSize);
3091 ui_actiondata(package,szInstallFiles,uirow);
3092 msiobj_release( &uirow->hdr );
3093 ui_progress(package,2,file->FileSize,0,0);
3095 if (!MoveFileW(file->SourcePath,file->TargetPath))
3097 rc = GetLastError();
3098 ERR("Unable to move file (%s -> %s) (error %d)\n",
3099 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3101 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3103 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3104 DeleteFileW(file->SourcePath);
3107 else if (rc == ERROR_FILE_NOT_FOUND)
3109 ERR("Source File Not Found! Continuing\n");
3114 ERR("Ignoring Error and continuing...\n");
3126 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3127 LPWSTR* file_source)
3132 return ERROR_INVALID_HANDLE;
3134 for (index = 0; index < package->loaded_files; index ++)
3136 if (strcmpW(file_key,package->files[index].File)==0)
3138 if (package->files[index].State >= 2)
3140 *file_source = strdupW(package->files[index].TargetPath);
3141 return ERROR_SUCCESS;
3144 return ERROR_FILE_NOT_FOUND;
3148 return ERROR_FUNCTION_FAILED;
3151 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3155 MSIRECORD * row = 0;
3156 static const WCHAR ExecSeqQuery[] =
3157 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3158 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
3161 return ERROR_INVALID_HANDLE;
3163 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3164 if (rc != ERROR_SUCCESS)
3165 return ERROR_SUCCESS;
3167 rc = MSI_ViewExecute(view, 0);
3168 if (rc != ERROR_SUCCESS)
3170 MSI_ViewClose(view);
3171 msiobj_release(&view->hdr);
3177 WCHAR file_key[0x100];
3178 WCHAR *file_source = NULL;
3179 WCHAR dest_name[0x100];
3180 LPWSTR dest_path, dest;
3181 WCHAR component[0x100];
3182 INT component_index;
3186 rc = MSI_ViewFetch(view,&row);
3187 if (rc != ERROR_SUCCESS)
3194 rc = MSI_RecordGetStringW(row,2,component,&sz);
3195 if (rc != ERROR_SUCCESS)
3197 ERR("Unable to get component\n");
3198 msiobj_release(&row->hdr);
3202 component_index = get_loaded_component(package,component);
3204 if (!ACTION_VerifyComponentForAction(package, component_index,
3205 INSTALLSTATE_LOCAL))
3207 TRACE("Skipping copy due to disabled component\n");
3209 /* the action taken was the same as the current install state */
3210 package->components[component_index].Action =
3211 package->components[component_index].Installed;
3213 msiobj_release(&row->hdr);
3217 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3220 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3221 if (rc != ERROR_SUCCESS)
3223 ERR("Unable to get file key\n");
3224 msiobj_release(&row->hdr);
3228 rc = get_file_target(package,file_key,&file_source);
3230 if (rc != ERROR_SUCCESS)
3232 ERR("Original file unknown %s\n",debugstr_w(file_key));
3233 msiobj_release(&row->hdr);
3234 HeapFree(GetProcessHeap(),0,file_source);
3238 if (MSI_RecordIsNull(row,4))
3240 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3245 MSI_RecordGetStringW(row,4,dest_name,&sz);
3246 reduce_to_longfilename(dest_name);
3249 if (MSI_RecordIsNull(row,5))
3252 dest_path = strdupW(file_source);
3253 p = strrchrW(dest_path,'\\');
3259 WCHAR destkey[0x100];
3261 MSI_RecordGetStringW(row,5,destkey,&sz);
3263 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3266 ERR("Unable to get destination folder\n");
3267 msiobj_release(&row->hdr);
3268 HeapFree(GetProcessHeap(),0,file_source);
3273 dest = build_directory_name(2, dest_path, dest_name);
3275 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3278 if (strcmpW(file_source,dest))
3279 rc = !CopyFileW(file_source,dest,TRUE);
3283 if (rc != ERROR_SUCCESS)
3284 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
3286 FIXME("We should track these duplicate files as well\n");
3288 msiobj_release(&row->hdr);
3289 HeapFree(GetProcessHeap(),0,dest_path);
3290 HeapFree(GetProcessHeap(),0,dest);
3291 HeapFree(GetProcessHeap(),0,file_source);
3293 MSI_ViewClose(view);
3294 msiobj_release(&view->hdr);
3299 /* OK this value is "interpreted" and then formatted based on the
3300 first few characters */
3301 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3305 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3314 deformat_string(package, &value[2], &deformated);
3316 /* binary value type */
3319 *size = strlenW(ptr)/2;
3320 data = HeapAlloc(GetProcessHeap(),0,*size);
3332 data[count] = (BYTE)strtol(byte,NULL,0);
3335 HeapFree(GetProcessHeap(),0,deformated);
3337 TRACE("Data %li bytes(%i)\n",*size,count);
3344 deformat_string(package, &value[1], &deformated);
3347 *size = sizeof(DWORD);
3348 data = HeapAlloc(GetProcessHeap(),0,*size);
3354 if ( (*p < '0') || (*p > '9') )
3360 if (deformated[0] == '-')
3363 TRACE("DWORD %li\n",*(LPDWORD)data);
3365 HeapFree(GetProcessHeap(),0,deformated);
3370 static const WCHAR szMulti[] = {'[','~',']',0};
3379 *type=REG_EXPAND_SZ;
3387 if (strstrW(value,szMulti))
3388 *type = REG_MULTI_SZ;
3390 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3395 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3399 MSIRECORD * row = 0;
3400 static const WCHAR ExecSeqQuery[] =
3401 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3402 'R','e','g','i','s','t','r','y',0 };
3405 return ERROR_INVALID_HANDLE;
3407 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3408 if (rc != ERROR_SUCCESS)
3409 return ERROR_SUCCESS;
3411 rc = MSI_ViewExecute(view, 0);
3412 if (rc != ERROR_SUCCESS)
3414 MSI_ViewClose(view);
3415 msiobj_release(&view->hdr);
3419 /* increment progress bar each time action data is sent */
3420 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3424 static const WCHAR szHCR[] =
3425 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3426 'R','O','O','T','\\',0};
3427 static const WCHAR szHCU[] =
3428 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3429 'U','S','E','R','\\',0};
3430 static const WCHAR szHLM[] =
3431 {'H','K','E','Y','_','L','O','C','A','L','_',
3432 'M','A','C','H','I','N','E','\\',0};
3433 static const WCHAR szHU[] =
3434 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3436 LPSTR value_data = NULL;
3437 HKEY root_key, hkey;
3439 LPWSTR value, key, name, component, deformated;
3441 INT component_index;
3446 rc = MSI_ViewFetch(view,&row);
3447 if (rc != ERROR_SUCCESS)
3452 ui_progress(package,2,0,0,0);
3459 component = load_dynamic_stringW(row, 6);
3460 component_index = get_loaded_component(package,component);
3462 if (!ACTION_VerifyComponentForAction(package, component_index,
3463 INSTALLSTATE_LOCAL))
3465 TRACE("Skipping write due to disabled component\n");
3466 msiobj_release(&row->hdr);
3468 package->components[component_index].Action =
3469 package->components[component_index].Installed;
3474 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3476 name = load_dynamic_stringW(row, 4);
3477 if( MSI_RecordIsNull(row,5) && name )
3479 /* null values can have special meanings */
3480 if (name[0]=='-' && name[1] == 0)
3482 msiobj_release(&row->hdr);
3485 else if ((name[0]=='+' && name[1] == 0) ||
3486 (name[0] == '*' && name[1] == 0))
3488 HeapFree(GetProcessHeap(),0,name);
3493 root = MSI_RecordGetInteger(row,2);
3494 key = load_dynamic_stringW(row, 3);
3497 /* get the root key */
3500 case 0: root_key = HKEY_CLASSES_ROOT;
3503 case 1: root_key = HKEY_CURRENT_USER;
3506 case 2: root_key = HKEY_LOCAL_MACHINE;
3509 case 3: root_key = HKEY_USERS;
3513 ERR("Unknown root %i\n",root);
3520 msiobj_release(&row->hdr);
3524 deformat_string(package, key , &deformated);
3525 size = strlenW(deformated) + strlenW(szRoot) + 1;
3526 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3527 strcpyW(uikey,szRoot);
3528 strcatW(uikey,deformated);
3530 if (RegCreateKeyW( root_key, deformated, &hkey))
3532 ERR("Could not create key %s\n",debugstr_w(deformated));
3533 msiobj_release(&row->hdr);
3534 HeapFree(GetProcessHeap(),0,deformated);
3537 HeapFree(GetProcessHeap(),0,deformated);
3539 value = load_dynamic_stringW(row,5);
3541 value_data = parse_value(package, value, &type, &size);
3544 static const WCHAR szEmpty[] = {0};
3545 value_data = (LPSTR)strdupW(szEmpty);
3550 deformat_string(package, name, &deformated);
3552 TRACE("Setting value %s\n",debugstr_w(deformated));
3553 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3555 uirow = MSI_CreateRecord(3);
3556 MSI_RecordSetStringW(uirow,2,deformated);
3557 MSI_RecordSetStringW(uirow,1,uikey);
3560 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3562 MSI_RecordSetStringW(uirow,3,value);
3564 ui_actiondata(package,szWriteRegistryValues,uirow);
3565 msiobj_release( &uirow->hdr );
3567 HeapFree(GetProcessHeap(),0,value_data);
3568 HeapFree(GetProcessHeap(),0,value);
3569 HeapFree(GetProcessHeap(),0,deformated);
3571 msiobj_release(&row->hdr);
3574 HeapFree(GetProcessHeap(),0,uikey);
3575 HeapFree(GetProcessHeap(),0,key);
3576 HeapFree(GetProcessHeap(),0,name);
3577 HeapFree(GetProcessHeap(),0,component);
3579 MSI_ViewClose(view);
3580 msiobj_release(&view->hdr);
3584 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3586 return ERROR_SUCCESS;
3590 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3594 static const WCHAR q1[]=
3595 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3596 'R','e','g','i','s','t','r','y',0};
3599 MSIRECORD * row = 0;
3602 TRACE(" InstallValidate \n");
3604 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3605 if (rc != ERROR_SUCCESS)
3606 return ERROR_SUCCESS;
3608 rc = MSI_ViewExecute(view, 0);
3609 if (rc != ERROR_SUCCESS)
3611 MSI_ViewClose(view);
3612 msiobj_release(&view->hdr);
3617 rc = MSI_ViewFetch(view,&row);
3618 if (rc != ERROR_SUCCESS)
3625 msiobj_release(&row->hdr);
3627 MSI_ViewClose(view);
3628 msiobj_release(&view->hdr);
3630 total = total + progress * REG_PROGRESS_VALUE;
3631 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3632 for (i=0; i < package->loaded_files; i++)
3633 total += package->files[i].FileSize;
3634 ui_progress(package,0,total,0,0);
3636 return ERROR_SUCCESS;
3639 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3642 MSIQUERY * view = NULL;
3643 MSIRECORD * row = 0;
3644 static const WCHAR ExecSeqQuery[] =
3645 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3646 'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3647 static const WCHAR title[]=
3648 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3650 TRACE("Checking launch conditions\n");
3652 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3653 if (rc != ERROR_SUCCESS)
3654 return ERROR_SUCCESS;
3656 rc = MSI_ViewExecute(view, 0);
3657 if (rc != ERROR_SUCCESS)
3659 MSI_ViewClose(view);
3660 msiobj_release(&view->hdr);
3665 while (rc == ERROR_SUCCESS)
3668 LPWSTR message = NULL;
3670 rc = MSI_ViewFetch(view,&row);
3671 if (rc != ERROR_SUCCESS)
3677 cond = load_dynamic_stringW(row,1);
3679 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3682 message = load_dynamic_stringW(row,2);
3683 deformat_string(package,message,&deformated);
3684 MessageBoxW(NULL,deformated,title,MB_OK);
3685 HeapFree(GetProcessHeap(),0,message);
3686 HeapFree(GetProcessHeap(),0,deformated);
3687 rc = ERROR_FUNCTION_FAILED;
3689 HeapFree(GetProcessHeap(),0,cond);
3690 msiobj_release(&row->hdr);
3692 MSI_ViewClose(view);
3693 msiobj_release(&view->hdr);
3697 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3700 MSICOMPONENT* cmp = &package->components[component_index];
3702 if (cmp->KeyPath[0]==0)
3704 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3707 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
3710 MSIRECORD * row = 0;
3712 LPWSTR key,deformated,buffer,name,deformated_name;
3713 static const WCHAR ExecSeqQuery[] =
3714 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3715 'R','e','g','i','s','t','r','y',' ','W','H','E','R','E',' ',
3716 'R','e','g','i','s','t','r','y',' ','=',' ' ,'`','%','s','`',0 };
3717 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
3718 static const WCHAR fmt2[]=
3719 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3721 rc = MSI_OpenQuery(package->db,&view,ExecSeqQuery,cmp->KeyPath);
3723 if (rc!=ERROR_SUCCESS)
3726 rc = MSI_ViewExecute(view, 0);
3727 if (rc != ERROR_SUCCESS)
3729 MSI_ViewClose(view);
3730 msiobj_release(&view->hdr);
3734 rc = MSI_ViewFetch(view,&row);
3735 if (rc != ERROR_SUCCESS)
3737 MSI_ViewClose(view);
3738 msiobj_release(&view->hdr);
3742 root = MSI_RecordGetInteger(row,2);
3743 key = load_dynamic_stringW(row, 3);
3744 name = load_dynamic_stringW(row, 4);
3745 deformat_string(package, key , &deformated);
3746 deformat_string(package, name, &deformated_name);
3748 len = strlenW(deformated) + 6;
3749 if (deformated_name)
3750 len+=strlenW(deformated_name);
3752 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3754 if (deformated_name)
3755 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3757 sprintfW(buffer,fmt,root,deformated);
3759 HeapFree(GetProcessHeap(),0,key);
3760 HeapFree(GetProcessHeap(),0,deformated);
3761 HeapFree(GetProcessHeap(),0,name);
3762 HeapFree(GetProcessHeap(),0,deformated_name);
3763 msiobj_release(&row->hdr);
3764 MSI_ViewClose(view);
3765 msiobj_release(&view->hdr);
3769 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
3771 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3777 j = get_loaded_file(package,cmp->KeyPath);
3781 LPWSTR p = strdupW(package->files[j].TargetPath);
3788 static HKEY openSharedDLLsKey()
3791 static const WCHAR path[] =
3792 {'S','o','f','t','w','a','r','e','\\',
3793 'M','i','c','r','o','s','o','f','t','\\',
3794 'W','i','n','d','o','w','s','\\',
3795 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3796 'S','h','a','r','e','d','D','L','L','s',0};
3798 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
3802 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
3807 DWORD sz = sizeof(count);
3810 hkey = openSharedDLLsKey();
3811 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
3812 if (rc != ERROR_SUCCESS)
3818 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
3822 hkey = openSharedDLLsKey();
3824 RegSetValueExW(hkey,path,0,REG_DWORD,
3825 (LPBYTE)&count,sizeof(count));
3827 RegDeleteValueW(hkey,path);
3833 * Return TRUE if the count should be written out and FALSE if not
3835 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
3841 /* only refcount DLLs */
3842 if (package->components[index].KeyPath[0]==0 ||
3843 package->components[index].Attributes &
3844 msidbComponentAttributesRegistryKeyPath ||
3845 package->components[index].Attributes &
3846 msidbComponentAttributesODBCDataSource)
3850 count = ACTION_GetSharedDLLsCount(package->components[index].
3852 write = (count > 0);
3854 if (package->components[index].Attributes &
3855 msidbComponentAttributesSharedDllRefCount)
3859 /* increment counts */
3860 for (j = 0; j < package->loaded_features; j++)
3864 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
3867 for (i = 0; i < package->features[j].ComponentCount; i++)
3869 if (package->features[j].Components[i] == index)
3873 /* decrement counts */
3874 for (j = 0; j < package->loaded_features; j++)
3877 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
3880 for (i = 0; i < package->features[j].ComponentCount; i++)
3882 if (package->features[j].Components[i] == index)
3887 /* ref count all the files in the component */
3889 for (j = 0; j < package->loaded_files; j++)
3891 if (package->files[j].Temporary)
3893 if (package->files[j].ComponentIndex == index)
3894 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
3897 /* add a count for permenent */
3898 if (package->components[index].Attributes &
3899 msidbComponentAttributesPermanent)
3902 package->components[index].RefCount = count;
3905 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
3906 package->components[index].RefCount);
3910 * Ok further analysis makes me think that this work is
3911 * actually done in the PublishComponents and PublishFeatures
3912 * step, and not here. It appears like the keypath and all that is
3913 * resolved in this step, however actually written in the Publish steps.
3914 * But we will leave it here for now because it is unclear
3916 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3919 WCHAR squished_pc[GUID_SIZE];
3920 WCHAR squished_cc[GUID_SIZE];
3923 HKEY hkey=0,hkey2=0;
3926 return ERROR_INVALID_HANDLE;
3928 /* writes the Component and Features values to the registry */
3929 productcode = load_dynamic_property(package,szProductCode,&rc);
3933 rc = MSIREG_OpenComponents(&hkey);
3934 if (rc != ERROR_SUCCESS)
3937 squash_guid(productcode,squished_pc);
3938 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
3939 for (i = 0; i < package->loaded_components; i++)
3941 ui_progress(package,2,0,0,0);
3942 if (package->components[i].ComponentId[0]!=0)
3944 WCHAR *keypath = NULL;
3947 squash_guid(package->components[i].ComponentId,squished_cc);
3948 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
3949 if (rc != ERROR_SUCCESS)
3952 keypath = resolve_keypath(package,i);
3953 package->components[i].FullKeypath = keypath;
3955 /* do the refcounting */
3956 ACTION_RefCountComponent( package, i);
3958 TRACE("Component %s, Keypath=%s, RefCount=%i\n",
3959 debugstr_w(package->components[i].Component),
3960 debugstr_w(package->components[i].FullKeypath),
3961 package->components[i].RefCount);
3963 * Write the keypath out if the component is to be registered
3964 * and delete the key if the component is to be deregistered
3966 if (ACTION_VerifyComponentForAction(package, i,
3967 INSTALLSTATE_LOCAL))
3971 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
3972 (strlenW(keypath)+1)*sizeof(WCHAR));
3974 if (package->components[i].Attributes &
3975 msidbComponentAttributesPermanent)
3977 static const WCHAR szPermKey[] =
3978 { '0','0','0','0','0','0','0','0','0','0','0','0',
3979 '0','0','0','0','0','0','0', '0','0','0','0','0',
3980 '0','0','0','0','0','0','0','0',0};
3982 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
3984 (strlenW(keypath)+1)*sizeof(WCHAR));
3990 uirow = MSI_CreateRecord(3);
3991 MSI_RecordSetStringW(uirow,1,productcode);
3992 MSI_RecordSetStringW(uirow,2,package->components[i].
3994 MSI_RecordSetStringW(uirow,3,keypath);
3995 ui_actiondata(package,szProcessComponents,uirow);
3996 msiobj_release( &uirow->hdr );
3999 else if (ACTION_VerifyComponentForAction(package, i,
4000 INSTALLSTATE_ABSENT))
4003 RegDeleteValueW(hkey2,squished_pc);
4005 /* if the key is empty delete it */
4006 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
4008 if (res == ERROR_NO_MORE_ITEMS)
4009 RegDeleteKeyW(hkey,squished_cc);
4012 uirow = MSI_CreateRecord(2);
4013 MSI_RecordSetStringW(uirow,1,productcode);
4014 MSI_RecordSetStringW(uirow,2,package->components[i].
4016 ui_actiondata(package,szProcessComponents,uirow);
4017 msiobj_release( &uirow->hdr );
4022 HeapFree(GetProcessHeap(), 0, productcode);
4035 BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
4036 LPWSTR lpszName, LONG_PTR lParam)
4039 typelib_struct *tl_struct = (typelib_struct*) lParam;
4040 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
4044 if (!IS_INTRESOURCE(lpszName))
4046 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
4050 sz = strlenW(tl_struct->source)+4;
4051 sz *= sizeof(WCHAR);
4053 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
4054 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
4056 TRACE("trying %s\n", debugstr_w(tl_struct->path));
4057 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
4058 if (!SUCCEEDED(res))
4060 HeapFree(GetProcessHeap(),0,tl_struct->path);
4061 tl_struct->path = NULL;
4066 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
4067 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
4069 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4073 HeapFree(GetProcessHeap(),0,tl_struct->path);
4074 tl_struct->path = NULL;
4076 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4077 ITypeLib_Release(tl_struct->ptLib);
4082 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4085 * OK this is a bit confusing.. I am given a _Component key and I believe
4086 * that the file that is being registered as a type library is the "key file
4087 * of that component" which I interpret to mean "The file in the KeyPath of
4092 MSIRECORD * row = 0;
4093 static const WCHAR Query[] =
4094 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4095 'T','y','p','e','L','i','b',0};
4098 return ERROR_INVALID_HANDLE;
4100 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4101 if (rc != ERROR_SUCCESS)
4102 return ERROR_SUCCESS;
4104 rc = MSI_ViewExecute(view, 0);
4105 if (rc != ERROR_SUCCESS)
4107 MSI_ViewClose(view);
4108 msiobj_release(&view->hdr);
4114 WCHAR component[0x100];
4118 typelib_struct tl_struct;
4120 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
4122 rc = MSI_ViewFetch(view,&row);
4123 if (rc != ERROR_SUCCESS)
4130 MSI_RecordGetStringW(row,3,component,&sz);
4132 index = get_loaded_component(package,component);
4135 msiobj_release(&row->hdr);
4139 if (!ACTION_VerifyComponentForAction(package, index,
4140 INSTALLSTATE_LOCAL))
4142 TRACE("Skipping typelib reg due to disabled component\n");
4143 msiobj_release(&row->hdr);
4145 package->components[index].Action =
4146 package->components[index].Installed;
4151 package->components[index].Action = INSTALLSTATE_LOCAL;
4153 index = get_loaded_file(package,package->components[index].KeyPath);
4157 msiobj_release(&row->hdr);
4161 guid = load_dynamic_stringW(row,1);
4162 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
4163 LOAD_LIBRARY_AS_DATAFILE);
4166 CLSIDFromString(guid, &tl_struct.clsid);
4167 tl_struct.source = strdupW(package->files[index].TargetPath);
4168 tl_struct.path = NULL;
4170 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
4171 (LONG_PTR)&tl_struct);
4173 if (tl_struct.path != NULL)
4176 WCHAR helpid[0x100];
4180 MSI_RecordGetStringW(row,6,helpid,&sz);
4182 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4183 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
4184 HeapFree(GetProcessHeap(),0,help);
4186 if (!SUCCEEDED(res))
4187 ERR("Failed to register type library %s\n",
4188 debugstr_w(tl_struct.path));
4191 ui_actiondata(package,szRegisterTypeLibraries,row);
4193 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
4196 ITypeLib_Release(tl_struct.ptLib);
4197 HeapFree(GetProcessHeap(),0,tl_struct.path);
4200 ERR("Failed to load type library %s\n",
4201 debugstr_w(tl_struct.source));
4203 FreeLibrary(module);
4204 HeapFree(GetProcessHeap(),0,tl_struct.source);
4207 ERR("Could not load file! %s\n",
4208 debugstr_w(package->files[index].TargetPath));
4209 msiobj_release(&row->hdr);
4211 MSI_ViewClose(view);
4212 msiobj_release(&view->hdr);
4216 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
4218 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4221 MSIRECORD * row = 0;
4222 static const WCHAR ExecSeqQuery[] =
4223 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4224 'A','p','p','I' ,'d',' ','w','h','e','r','e',' ',
4225 'A','p','p','I','d','=','`','%','s','`',0};
4230 return ERROR_INVALID_HANDLE;
4232 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
4233 if (rc != ERROR_SUCCESS)
4236 rc = MSI_ViewExecute(view, 0);
4237 if (rc != ERROR_SUCCESS)
4239 MSI_ViewClose(view);
4240 msiobj_release(&view->hdr);
4244 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
4245 RegCreateKeyW(hkey2,clsid,&hkey3);
4246 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
4247 (strlenW(app)+1)*sizeof(WCHAR));
4249 rc = MSI_ViewFetch(view,&row);
4250 if (rc != ERROR_SUCCESS)
4252 MSI_ViewClose(view);
4253 msiobj_release(&view->hdr);
4257 if (!MSI_RecordIsNull(row,2))
4259 LPWSTR deformated=0;
4261 static const WCHAR szRemoteServerName[] =
4262 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
4264 buffer = load_dynamic_stringW(row,2);
4265 size = deformat_string(package,buffer,&deformated);
4266 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
4268 HeapFree(GetProcessHeap(),0,deformated);
4269 HeapFree(GetProcessHeap(),0,buffer);
4272 if (!MSI_RecordIsNull(row,3))
4274 static const WCHAR szLocalService[] =
4275 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
4277 buffer = load_dynamic_stringW(row,3);
4278 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4279 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
4280 HeapFree(GetProcessHeap(),0,buffer);
4283 if (!MSI_RecordIsNull(row,4))
4285 static const WCHAR szService[] =
4286 {'S','e','r','v','i','c','e',
4287 'P','a','r','a','m','e','t','e','r','s',0};
4289 buffer = load_dynamic_stringW(row,4);
4290 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4291 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
4292 HeapFree(GetProcessHeap(),0,buffer);
4295 if (!MSI_RecordIsNull(row,5))
4297 static const WCHAR szDLL[] =
4298 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
4300 buffer = load_dynamic_stringW(row,5);
4301 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4302 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
4303 HeapFree(GetProcessHeap(),0,buffer);
4306 if (!MSI_RecordIsNull(row,6))
4308 static const WCHAR szActivate[] =
4309 {'A','c','t','i','v','a','t','e','A','s',
4310 'S','t','o','r','a','g','e',0};
4311 static const WCHAR szY[] = {'Y',0};
4313 if (MSI_RecordGetInteger(row,6))
4314 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
4317 if (!MSI_RecordIsNull(row,7))
4319 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
4320 static const WCHAR szUser[] =
4321 {'I','n','t','e','r','a','c','t','i','v','e',' ',
4324 if (MSI_RecordGetInteger(row,7))
4325 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
4328 msiobj_release(&row->hdr);
4329 MSI_ViewClose(view);
4330 msiobj_release(&view->hdr);
4336 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
4339 * Again I am assuming the words, "Whose key file represents" when referring
4340 * to a Component as to meaning that Components KeyPath file
4342 * Also there is a very strong connection between ClassInfo and ProgID
4343 * that I am mostly glossing over.
4344 * What would be more propper is to load the ClassInfo and the ProgID info
4345 * into memory data structures and then be able to enable and disable them
4346 * based on component.
4351 MSIRECORD * row = 0;
4352 static const WCHAR ExecSeqQuery[] =
4353 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4354 'C','l','a','s','s',0};
4355 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4356 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
4357 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4358 static const WCHAR szSpace[] = {' ',0};
4359 HKEY hkey,hkey2,hkey3;
4360 LPWSTR argument,deformated;
4363 return ERROR_INVALID_HANDLE;
4365 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
4366 if (rc != ERROR_SUCCESS)
4367 return ERROR_FUNCTION_FAILED;
4369 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4370 if (rc != ERROR_SUCCESS)
4376 rc = MSI_ViewExecute(view, 0);
4377 if (rc != ERROR_SUCCESS)
4379 MSI_ViewClose(view);
4380 msiobj_release(&view->hdr);
4387 WCHAR buffer[0x100];
4393 rc = MSI_ViewFetch(view,&row);
4394 if (rc != ERROR_SUCCESS)
4401 MSI_RecordGetStringW(row,3,buffer,&sz);
4403 index = get_loaded_component(package,buffer);
4407 msiobj_release(&row->hdr);
4411 if (!ACTION_VerifyComponentForAction(package, index,
4412 INSTALLSTATE_LOCAL))
4414 TRACE("Skipping class reg due to disabled component\n");
4415 msiobj_release(&row->hdr);
4417 package->components[index].Action =
4418 package->components[index].Installed;
4423 package->components[index].Action = INSTALLSTATE_LOCAL;
4426 MSI_RecordGetStringW(row,1,clsid,&sz);
4427 RegCreateKeyW(hkey,clsid,&hkey2);
4429 if (!MSI_RecordIsNull(row,5))
4432 MSI_RecordGetStringW(row,5,desc,&sz);
4434 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
4435 (strlenW(desc)+1)*sizeof(WCHAR));
4441 MSI_RecordGetStringW(row,2,buffer,&sz);
4443 RegCreateKeyW(hkey2,buffer,&hkey3);
4445 index = get_loaded_file(package,package->components[index].KeyPath);
4447 argument = load_dynamic_stringW(row,11);
4448 size = deformat_string(package,argument,&deformated);
4450 size+=sizeof(WCHAR);
4451 HeapFree(GetProcessHeap(),0,argument);
4452 size += (strlenW(package->files[index].TargetPath))*sizeof(WCHAR);
4454 argument = HeapAlloc(GetProcessHeap(),0,size+sizeof(WCHAR));
4455 strcpyW(argument,package->files[index].TargetPath);
4458 strcatW(argument,szSpace);
4459 strcatW(argument,deformated);
4462 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4463 HeapFree(GetProcessHeap(),0,deformated);
4464 HeapFree(GetProcessHeap(),0,argument);
4468 if (!MSI_RecordIsNull(row,4))
4471 MSI_RecordGetStringW(row,4,buffer,&sz);
4473 RegCreateKeyW(hkey2,szProgID,&hkey3);
4475 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4476 (strlenW(buffer)+1)*sizeof(WCHAR));
4481 if (!MSI_RecordIsNull(row,6))
4484 MSI_RecordGetStringW(row,6,buffer,&sz);
4486 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4487 (strlenW(buffer)+1)*sizeof(WCHAR));
4489 register_appid(package,buffer,desc);
4493 if (!MSI_RecordIsNull(row,7))
4495 FIXME("Process field 7\n");
4498 if (!MSI_RecordIsNull(row,8))
4500 static const WCHAR szDefaultIcon[] =
4501 {'D','e','f','a','u','l','t','I','c','o','n',0};
4503 LPWSTR FileName = load_dynamic_stringW(row,8);
4507 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
4508 build_icon_path(package,FileName,&FilePath);
4509 if (!MSI_RecordIsNull(row,9))
4511 static const WCHAR index_fmt[] = {',','%','i',0};
4512 WCHAR index_buf[20];
4513 index = MSI_RecordGetInteger(row,9);
4514 sprintfW(index_buf,index_fmt,index);
4515 size = strlenW(FilePath)+strlenW(index_buf)+1;
4516 size *= sizeof(WCHAR);
4517 HeapReAlloc(GetProcessHeap(),0,FilePath,size);
4519 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)FilePath,
4520 (strlenW(FilePath)+1) * sizeof(WCHAR));
4521 HeapFree(GetProcessHeap(),0,FilePath);
4522 HeapFree(GetProcessHeap(),0,FileName);
4526 if (!MSI_RecordIsNull(row,10))
4528 static const WCHAR szInproc32[] =
4529 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
4531 static const WCHAR szInproc[] =
4532 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
4533 INT i = MSI_RecordGetInteger(row,10);
4534 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4536 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4537 static const WCHAR ole32[] =
4538 {'o','l','e','3','2','.','d','l','l',0};
4542 size = strlenW(ole2) * sizeof(WCHAR);
4543 RegCreateKeyW(hkey2,szInproc,&hkey3);
4544 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4548 size = strlenW(ole32) * sizeof(WCHAR);
4549 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4550 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4554 size = strlenW(ole2) * sizeof(WCHAR);
4555 RegCreateKeyW(hkey2,szInproc,&hkey3);
4556 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4558 size = strlenW(ole32) * sizeof(WCHAR);
4559 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4560 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4568 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4569 argument = load_dynamic_stringW(row,10);
4570 reduce_to_longfilename(argument);
4571 size = strlenW(argument)*sizeof(WCHAR);
4573 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4574 HeapFree(GetProcessHeap(),0,argument);
4582 ui_actiondata(package,szRegisterClassInfo,row);
4584 msiobj_release(&row->hdr);
4586 MSI_ViewClose(view);
4587 msiobj_release(&view->hdr);
4594 static UINT register_progid_base(MSIPACKAGE* package, MSIRECORD * row,
4597 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4598 static const WCHAR szDefaultIcon[] =
4599 {'D','e','f','a','u','l','t','I','c','o','n',0};
4601 WCHAR buffer[0x100];
4606 MSI_RecordGetStringW(row,1,buffer,&sz);
4607 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4609 if (!MSI_RecordIsNull(row,4))
4612 MSI_RecordGetStringW(row,4,buffer,&sz);
4613 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4617 if (!MSI_RecordIsNull(row,3))
4621 MSI_RecordGetStringW(row,3,buffer,&sz);
4622 RegCreateKeyW(hkey,szCLSID,&hkey2);
4623 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4627 strcpyW(clsid,buffer);
4633 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4634 return ERROR_FUNCTION_FAILED;
4636 if (!MSI_RecordIsNull(row,5))
4638 INT index = MSI_RecordGetInteger(row,6);
4639 LPWSTR FileName = load_dynamic_stringW(row,5);
4640 LPWSTR FilePath,IconPath;
4641 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4643 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4644 build_icon_path(package,FileName,&FilePath);
4646 IconPath = HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4649 sprintfW(IconPath,fmt,FilePath,index);
4650 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)IconPath,
4651 (strlenW(IconPath)+1) * sizeof(WCHAR));
4652 HeapFree(GetProcessHeap(),0,FilePath);
4653 HeapFree(GetProcessHeap(),0,FileName);
4656 return ERROR_SUCCESS;
4659 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4661 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4666 MSIRECORD * row = 0;
4667 static const WCHAR Query_t[] =
4668 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4669 'P','r','o','g' ,'I','d',' ','W','H','E','R','E',' ',
4670 'P','r','o','g','I','d',' ','=',' ','`' ,'%','s','`',0};
4673 return ERROR_INVALID_HANDLE;
4675 rc = MSI_OpenQuery(package->db, &view, Query_t, parent);
4676 if (rc != ERROR_SUCCESS)
4679 rc = MSI_ViewExecute(view, 0);
4680 if (rc != ERROR_SUCCESS)
4682 MSI_ViewClose(view);
4683 msiobj_release(&view->hdr);
4687 rc = MSI_ViewFetch(view,&row);
4688 if (rc != ERROR_SUCCESS)
4690 MSI_ViewClose(view);
4691 msiobj_release(&view->hdr);
4695 register_progid(package,row,clsid);
4697 msiobj_release(&row->hdr);
4698 MSI_ViewClose(view);
4699 msiobj_release(&view->hdr);
4703 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4705 UINT rc = ERROR_SUCCESS;
4707 if (MSI_RecordIsNull(row,2))
4708 rc = register_progid_base(package,row,clsid);
4711 WCHAR buffer[0x1000];
4714 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4715 static const WCHAR szDefaultIcon[] =
4716 {'D','e','f','a','u','l','t','I','c','o','n',0};
4718 /* check if already registered */
4720 MSI_RecordGetStringW(row,1,buffer,&sz);
4721 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4722 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4723 if (disp == REG_OPENED_EXISTING_KEY)
4725 TRACE("Key already registered\n");
4731 MSI_RecordGetStringW(row,2,buffer,&sz);
4732 rc = register_parent_progid(package,buffer,clsid);
4734 /* clsid is same as parent */
4735 RegCreateKeyW(hkey,szCLSID,&hkey2);
4736 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4742 if (!MSI_RecordIsNull(row,4))
4745 MSI_RecordGetStringW(row,4,buffer,&sz);
4746 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4747 (strlenW(buffer)+1) * sizeof(WCHAR));
4750 if (!MSI_RecordIsNull(row,5))
4752 LPWSTR FileName = load_dynamic_stringW(row,5);
4754 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4755 build_icon_path(package,FileName,&FilePath);
4756 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)FilePath,
4757 (strlenW(FilePath)+1) * sizeof(WCHAR));
4758 HeapFree(GetProcessHeap(),0,FilePath);
4759 HeapFree(GetProcessHeap(),0,FileName);
4768 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4771 * Sigh, here I am just brute force registering all progids
4772 * this needs to be linked to the Classes that have been registered
4773 * but the easiest way to do that is to load all these stuff into
4774 * memory for easy checking.
4776 * Gives me something to continue to work toward.
4780 MSIRECORD * row = 0;
4781 static const WCHAR Query[] =
4782 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
4783 'P','r','o','g','I','d',0};
4786 return ERROR_INVALID_HANDLE;
4788 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4789 if (rc != ERROR_SUCCESS)
4790 return ERROR_SUCCESS;
4792 rc = MSI_ViewExecute(view, 0);
4793 if (rc != ERROR_SUCCESS)
4795 MSI_ViewClose(view);
4796 msiobj_release(&view->hdr);
4802 WCHAR clsid[0x1000];
4804 rc = MSI_ViewFetch(view,&row);
4805 if (rc != ERROR_SUCCESS)
4811 register_progid(package,row,clsid);
4812 ui_actiondata(package,szRegisterProgIdInfo,row);
4814 msiobj_release(&row->hdr);
4816 MSI_ViewClose(view);
4817 msiobj_release(&view->hdr);
4821 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4825 LPWSTR SystemFolder;
4829 static const WCHAR szInstaller[] =
4830 {'I','n','s','t','a','l','l','e','r','\\',0};
4831 static const WCHAR szFolder[] =
4832 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4834 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4838 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4840 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4842 create_full_pathW(dest);
4844 *FilePath = build_directory_name(2, dest, icon_name);
4846 HeapFree(GetProcessHeap(),0,SystemFolder);
4847 HeapFree(GetProcessHeap(),0,ProductCode);
4848 HeapFree(GetProcessHeap(),0,dest);
4849 return ERROR_SUCCESS;
4852 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4856 MSIRECORD * row = 0;
4857 static const WCHAR Query[] =
4858 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4859 'S','h','o','r','t','c','u','t',0};
4865 return ERROR_INVALID_HANDLE;
4867 res = CoInitialize( NULL );
4870 ERR("CoInitialize failed\n");
4871 return ERROR_FUNCTION_FAILED;
4874 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4875 if (rc != ERROR_SUCCESS)
4876 return ERROR_SUCCESS;
4878 rc = MSI_ViewExecute(view, 0);
4879 if (rc != ERROR_SUCCESS)
4881 MSI_ViewClose(view);
4882 msiobj_release(&view->hdr);
4888 LPWSTR target_file, target_folder;
4889 WCHAR buffer[0x100];
4892 static const WCHAR szlnk[]={'.','l','n','k',0};
4894 rc = MSI_ViewFetch(view,&row);
4895 if (rc != ERROR_SUCCESS)
4902 MSI_RecordGetStringW(row,4,buffer,&sz);
4904 index = get_loaded_component(package,buffer);
4908 msiobj_release(&row->hdr);
4912 if (!ACTION_VerifyComponentForAction(package, index,
4913 INSTALLSTATE_LOCAL))
4915 TRACE("Skipping shortcut creation due to disabled component\n");
4916 msiobj_release(&row->hdr);
4918 package->components[index].Action =
4919 package->components[index].Installed;
4924 package->components[index].Action = INSTALLSTATE_LOCAL;
4926 ui_actiondata(package,szCreateShortcuts,row);
4928 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4929 &IID_IShellLinkW, (LPVOID *) &sl );
4933 ERR("Is IID_IShellLink\n");
4934 msiobj_release(&row->hdr);
4938 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4941 ERR("Is IID_IPersistFile\n");
4942 msiobj_release(&row->hdr);
4947 MSI_RecordGetStringW(row,2,buffer,&sz);
4948 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4950 /* may be needed because of a bug somehwere else */
4951 create_full_pathW(target_folder);
4954 MSI_RecordGetStringW(row,3,buffer,&sz);
4955 reduce_to_longfilename(buffer);
4956 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4957 strcatW(buffer,szlnk);
4958 target_file = build_directory_name(2, target_folder, buffer);
4959 HeapFree(GetProcessHeap(),0,target_folder);
4962 MSI_RecordGetStringW(row,5,buffer,&sz);
4963 if (strchrW(buffer,'['))
4966 deformat_string(package,buffer,&deformated);
4967 IShellLinkW_SetPath(sl,deformated);
4968 HeapFree(GetProcessHeap(),0,deformated);
4973 FIXME("poorly handled shortcut format, advertised shortcut\n");
4974 keypath = strdupW(package->components[index].FullKeypath);
4975 IShellLinkW_SetPath(sl,keypath);
4976 HeapFree(GetProcessHeap(),0,keypath);
4979 if (!MSI_RecordIsNull(row,6))
4983 MSI_RecordGetStringW(row,6,buffer,&sz);
4984 deformat_string(package,buffer,&deformated);
4985 IShellLinkW_SetArguments(sl,deformated);
4986 HeapFree(GetProcessHeap(),0,deformated);
4989 if (!MSI_RecordIsNull(row,7))
4992 deformated = load_dynamic_stringW(row,7);
4993 IShellLinkW_SetDescription(sl,deformated);
4994 HeapFree(GetProcessHeap(),0,deformated);
4997 if (!MSI_RecordIsNull(row,8))
4998 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
5000 if (!MSI_RecordIsNull(row,9))
5006 MSI_RecordGetStringW(row,9,buffer,&sz);
5008 build_icon_path(package,buffer,&Path);
5009 index = MSI_RecordGetInteger(row,10);
5011 IShellLinkW_SetIconLocation(sl,Path,index);
5012 HeapFree(GetProcessHeap(),0,Path);
5015 if (!MSI_RecordIsNull(row,11))
5016 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
5018 if (!MSI_RecordIsNull(row,12))
5022 MSI_RecordGetStringW(row,12,buffer,&sz);
5023 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
5024 IShellLinkW_SetWorkingDirectory(sl,Path);
5025 HeapFree(GetProcessHeap(), 0, Path);
5028 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
5029 IPersistFile_Save(pf,target_file,FALSE);
5031 HeapFree(GetProcessHeap(),0,target_file);
5033 IPersistFile_Release( pf );
5034 IShellLinkW_Release( sl );
5036 msiobj_release(&row->hdr);
5038 MSI_ViewClose(view);
5039 msiobj_release(&view->hdr);
5049 * 99% of the work done here is only done for
5050 * advertised installs. However this is where the
5051 * Icon table is processed and written out
5052 * so that is what I am going to do here.
5054 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
5058 MSIRECORD * row = 0;
5059 static const WCHAR Query[]=
5060 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5063 /* for registry stuff */
5067 static const WCHAR szProductName[] =
5068 {'P','r','o','d','u','c','t','N','a','m','e',0};
5069 static const WCHAR szPackageCode[] =
5070 {'P','a','c','k','a','g','e','C','o','d','e',0};
5073 MSIHANDLE hDb, hSumInfo;
5076 return ERROR_INVALID_HANDLE;
5078 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5079 if (rc != ERROR_SUCCESS)
5082 rc = MSI_ViewExecute(view, 0);
5083 if (rc != ERROR_SUCCESS)
5085 MSI_ViewClose(view);
5086 msiobj_release(&view->hdr);
5093 WCHAR *FilePath=NULL;
5094 WCHAR *FileName=NULL;
5097 rc = MSI_ViewFetch(view,&row);
5098 if (rc != ERROR_SUCCESS)
5104 FileName = load_dynamic_stringW(row,1);
5107 ERR("Unable to get FileName\n");
5108 msiobj_release(&row->hdr);
5112 build_icon_path(package,FileName,&FilePath);
5114 HeapFree(GetProcessHeap(),0,FileName);
5116 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
5118 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
5119 FILE_ATTRIBUTE_NORMAL, NULL);
5121 if (the_file == INVALID_HANDLE_VALUE)
5123 ERR("Unable to create file %s\n",debugstr_w(FilePath));
5124 msiobj_release(&row->hdr);
5125 HeapFree(GetProcessHeap(),0,FilePath);
5133 rc = MSI_RecordReadStream(row,2,buffer,&sz);
5134 if (rc != ERROR_SUCCESS)
5136 ERR("Failed to get stream\n");
5137 CloseHandle(the_file);
5138 DeleteFileW(FilePath);
5141 WriteFile(the_file,buffer,sz,&write,NULL);
5142 } while (sz == 1024);
5144 HeapFree(GetProcessHeap(),0,FilePath);
5146 CloseHandle(the_file);
5147 msiobj_release(&row->hdr);
5149 MSI_ViewClose(view);
5150 msiobj_release(&view->hdr);
5153 /* ok there is a lot more done here but i need to figure out what */
5154 productcode = load_dynamic_property(package,szProductCode,&rc);
5158 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
5159 if (rc != ERROR_SUCCESS)
5162 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5163 if (rc != ERROR_SUCCESS)
5167 buffer = load_dynamic_property(package,szProductName,NULL);
5168 size = strlenW(buffer)*sizeof(WCHAR);
5169 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
5170 HeapFree(GetProcessHeap(),0,buffer);
5171 FIXME("Need to write more keys to the user registry\n");
5173 hDb= alloc_msihandle( &package->db->hdr );
5174 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
5175 MsiCloseHandle(hDb);
5176 if (rc == ERROR_SUCCESS)
5178 WCHAR guidbuffer[0x200];
5180 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
5182 if (rc == ERROR_SUCCESS)
5184 WCHAR squashed[GUID_SIZE];
5185 /* for now we only care about the first guid */
5186 LPWSTR ptr = strchrW(guidbuffer,';');
5188 squash_guid(guidbuffer,squashed);
5189 size = strlenW(squashed)*sizeof(WCHAR);
5190 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
5195 ERR("Unable to query Revision_Number... \n");
5198 MsiCloseHandle(hSumInfo);
5202 ERR("Unable to open Summary Information\n");
5208 HeapFree(GetProcessHeap(),0,productcode);
5215 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
5219 MSIRECORD * row = 0;
5220 static const WCHAR ExecSeqQuery[] =
5221 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5222 'I','n','i','F','i','l','e',0};
5223 static const WCHAR szWindowsFolder[] =
5224 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
5226 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5227 if (rc != ERROR_SUCCESS)
5229 TRACE("no IniFile table\n");
5230 return ERROR_SUCCESS;
5233 rc = MSI_ViewExecute(view, 0);
5234 if (rc != ERROR_SUCCESS)
5236 MSI_ViewClose(view);
5237 msiobj_release(&view->hdr);
5243 LPWSTR component,filename,dirproperty,section,key,value,identifier;
5244 LPWSTR deformated_section, deformated_key, deformated_value;
5245 LPWSTR folder, fullname = NULL;
5247 INT component_index,action;
5249 rc = MSI_ViewFetch(view,&row);
5250 if (rc != ERROR_SUCCESS)
5256 component = load_dynamic_stringW(row, 8);
5257 component_index = get_loaded_component(package,component);
5258 HeapFree(GetProcessHeap(),0,component);
5260 if (!ACTION_VerifyComponentForAction(package, component_index,
5261 INSTALLSTATE_LOCAL))
5263 TRACE("Skipping ini file due to disabled component\n");
5264 msiobj_release(&row->hdr);
5266 package->components[component_index].Action =
5267 package->components[component_index].Installed;
5272 package->components[component_index].Action = INSTALLSTATE_LOCAL;
5274 identifier = load_dynamic_stringW(row,1);
5275 filename = load_dynamic_stringW(row,2);
5276 dirproperty = load_dynamic_stringW(row,3);
5277 section = load_dynamic_stringW(row,4);
5278 key = load_dynamic_stringW(row,5);
5279 value = load_dynamic_stringW(row,6);
5280 action = MSI_RecordGetInteger(row,7);
5282 deformat_string(package,section,&deformated_section);
5283 deformat_string(package,key,&deformated_key);
5284 deformat_string(package,value,&deformated_value);
5288 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
5290 folder = load_dynamic_property(package,dirproperty,NULL);
5293 folder = load_dynamic_property(package, szWindowsFolder, NULL);
5297 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
5301 fullname = build_directory_name(3, folder, filename, NULL);
5305 TRACE("Adding value %s to section %s in %s\n",
5306 debugstr_w(deformated_key), debugstr_w(deformated_section),
5307 debugstr_w(fullname));
5308 WritePrivateProfileStringW(deformated_section, deformated_key,
5309 deformated_value, fullname);
5311 else if (action == 1)
5314 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
5315 returned, 10, fullname);
5316 if (returned[0] == 0)
5318 TRACE("Adding value %s to section %s in %s\n",
5319 debugstr_w(deformated_key), debugstr_w(deformated_section),
5320 debugstr_w(fullname));
5322 WritePrivateProfileStringW(deformated_section, deformated_key,
5323 deformated_value, fullname);
5326 else if (action == 3)
5328 FIXME("Append to existing section not yet implemented\n");
5331 uirow = MSI_CreateRecord(4);
5332 MSI_RecordSetStringW(uirow,1,identifier);
5333 MSI_RecordSetStringW(uirow,2,deformated_section);
5334 MSI_RecordSetStringW(uirow,3,deformated_key);
5335 MSI_RecordSetStringW(uirow,4,deformated_value);
5336 ui_actiondata(package,szWriteIniValues,uirow);
5337 msiobj_release( &uirow->hdr );
5339 HeapFree(GetProcessHeap(),0,identifier);
5340 HeapFree(GetProcessHeap(),0,fullname);
5341 HeapFree(GetProcessHeap(),0,filename);
5342 HeapFree(GetProcessHeap(),0,key);
5343 HeapFree(GetProcessHeap(),0,value);
5344 HeapFree(GetProcessHeap(),0,section);
5345 HeapFree(GetProcessHeap(),0,dirproperty);
5346 HeapFree(GetProcessHeap(),0,folder);
5347 HeapFree(GetProcessHeap(),0,deformated_key);
5348 HeapFree(GetProcessHeap(),0,deformated_value);
5349 HeapFree(GetProcessHeap(),0,deformated_section);
5350 msiobj_release(&row->hdr);
5352 MSI_ViewClose(view);
5353 msiobj_release(&view->hdr);
5357 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
5361 MSIRECORD * row = 0;
5362 static const WCHAR ExecSeqQuery[] =
5363 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5364 'S','e','l','f','R','e','g',0};
5366 static const WCHAR ExeStr[] =
5367 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ',0};
5369 PROCESS_INFORMATION info;
5372 memset(&si,0,sizeof(STARTUPINFOW));
5374 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5375 if (rc != ERROR_SUCCESS)
5377 TRACE("no SelfReg table\n");
5378 return ERROR_SUCCESS;
5381 rc = MSI_ViewExecute(view, 0);
5382 if (rc != ERROR_SUCCESS)
5384 MSI_ViewClose(view);
5385 msiobj_release(&view->hdr);
5395 rc = MSI_ViewFetch(view,&row);
5396 if (rc != ERROR_SUCCESS)
5402 filename = load_dynamic_stringW(row,1);
5403 index = get_loaded_file(package,filename);
5407 ERR("Unable to find file id %s\n",debugstr_w(filename));
5408 HeapFree(GetProcessHeap(),0,filename);
5409 msiobj_release(&row->hdr);
5412 HeapFree(GetProcessHeap(),0,filename);
5414 len = strlenW(ExeStr);
5415 len += strlenW(package->files[index].TargetPath);
5418 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
5419 strcpyW(filename,ExeStr);
5420 strcatW(filename,package->files[index].TargetPath);
5422 TRACE("Registering %s\n",debugstr_w(filename));
5423 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
5424 c_colon, &si, &info);
5427 msi_dialog_check_messages(info.hProcess);
5429 HeapFree(GetProcessHeap(),0,filename);
5430 msiobj_release(&row->hdr);
5432 MSI_ViewClose(view);
5433 msiobj_release(&view->hdr);
5437 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
5446 return ERROR_INVALID_HANDLE;
5448 productcode = load_dynamic_property(package,szProductCode,&rc);
5452 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
5453 if (rc != ERROR_SUCCESS)
5456 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
5457 if (rc != ERROR_SUCCESS)
5460 /* here the guids are base 85 encoded */
5461 for (i = 0; i < package->loaded_features; i++)
5468 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL))
5471 size = package->features[i].ComponentCount*21;
5473 if (package->features[i].Feature_Parent[0])
5474 size += strlenW(package->features[i].Feature_Parent)+2;
5476 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
5479 for (j = 0; j < package->features[i].ComponentCount; j++)
5482 memset(buf,0,sizeof(buf));
5483 TRACE("From %s\n",debugstr_w(package->components
5484 [package->features[i].Components[j]].ComponentId));
5485 CLSIDFromString(package->components
5486 [package->features[i].Components[j]].ComponentId,
5488 encode_base85_guid(&clsid,buf);
5489 TRACE("to %s\n",debugstr_w(buf));
5492 if (package->features[i].Feature_Parent[0])
5494 static const WCHAR sep[] = {'\2',0};
5496 strcatW(data,package->features[i].Feature_Parent);
5499 size = (strlenW(data)+1)*sizeof(WCHAR);
5500 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
5502 HeapFree(GetProcessHeap(),0,data);
5504 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
5505 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
5506 (LPSTR)package->features[i].Feature_Parent,size);
5512 HeapFree(GetProcessHeap(), 0, productcode);
5516 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
5523 static WCHAR szNONE[] = {0};
5524 static const WCHAR szWindowsInstaler[] =
5525 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
5526 static const WCHAR szPropKeys[][80] =
5528 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
5529 {'A','R','P','C','O','N','T','A','C','T',0},
5530 {'A','R','P','C','O','M','M','E','N','T','S',0},
5531 {'P','r','o','d','u','c','t','N','a','m','e',0},
5532 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
5533 {'A','R','P','H','E','L','P','L','I','N','K',0},
5534 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
5535 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
5536 {'S','o','u','r','c','e','D','i','r',0},
5537 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
5538 {'A','R','P','R','E','A','D','M','E',0},
5539 {'A','R','P','S','I','Z','E',0},
5540 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
5541 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
5545 static const WCHAR szRegKeys[][80] =
5547 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
5548 {'C','o','n','t','a','c','t',0},
5549 {'C','o','m','m','e','n','t','s',0},
5550 {'D','i','s','p','l','a','y','N','a','m','e',0},
5551 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
5552 {'H','e','l','p','L','i','n','k',0},
5553 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
5554 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
5555 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
5556 {'P','u','b','l','i','s','h','e','r',0},
5557 {'R','e','a','d','m','e',0},
5558 {'S','i','z','e',0},
5559 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
5560 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
5564 static const WCHAR installerPathFmt[] = {
5566 'I','n','s','t','a','l','l','e','r','\\',0};
5567 static const WCHAR fmt[] = {
5569 'I','n','s','t','a','l','l','e','r','\\',
5570 '%','x','.','m','s','i',0};
5571 static const WCHAR szLocalPackage[]=
5572 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
5573 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
5577 return ERROR_INVALID_HANDLE;
5579 productcode = load_dynamic_property(package,szProductCode,&rc);
5583 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
5584 if (rc != ERROR_SUCCESS)
5587 /* dump all the info i can grab */
5588 FIXME("Flesh out more information \n");
5591 while (szPropKeys[i][0]!=0)
5593 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
5594 if (rc != ERROR_SUCCESS)
5596 size = strlenW(buffer)*sizeof(WCHAR);
5597 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
5603 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
5605 /* copy the package locally */
5606 num = GetTickCount() & 0xffff;
5610 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
5611 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
5615 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
5616 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
5617 if (handle != INVALID_HANDLE_VALUE)
5619 CloseHandle(handle);
5622 if (GetLastError() != ERROR_FILE_EXISTS &&
5623 GetLastError() != ERROR_SHARING_VIOLATION)
5625 if (!(++num & 0xffff)) num = 1;
5626 sprintfW(packagefile,fmt,num);
5627 } while (num != start);
5629 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
5630 create_full_pathW(path);
5631 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
5632 CopyFileW(package->PackagePath,packagefile,FALSE);
5633 size = strlenW(packagefile)*sizeof(WCHAR);
5634 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
5637 HeapFree(GetProcessHeap(),0,productcode);
5640 return ERROR_SUCCESS;
5643 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
5647 return ERROR_INVALID_HANDLE;
5649 for (i = 0; i < package->DeferredActionCount; i++)
5652 action = package->DeferredAction[i];
5653 ui_actionstart(package, action);
5654 TRACE("Executing Action (%s)\n",debugstr_w(action));
5655 ACTION_CustomAction(package,action,TRUE);
5656 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
5658 HeapFree(GetProcessHeap(),0,package->DeferredAction);
5660 package->DeferredActionCount = 0;
5661 package->DeferredAction = NULL;
5663 return ERROR_SUCCESS;
5666 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
5670 return ERROR_INVALID_HANDLE;
5672 /* first do the same as an InstallExecute */
5673 ACTION_InstallExecute(package);
5675 /* then handle Commit Actions */
5676 for (i = 0; i < package->CommitActionCount; i++)
5679 action = package->CommitAction[i];
5680 ui_actionstart(package, action);
5681 TRACE("Executing Commit Action (%s)\n",debugstr_w(action));
5682 ACTION_CustomAction(package,action,TRUE);
5683 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
5685 HeapFree(GetProcessHeap(),0,package->CommitAction);
5687 package->CommitActionCount = 0;
5688 package->CommitAction = NULL;
5690 return ERROR_SUCCESS;
5693 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
5695 static const WCHAR RunOnce[] = {
5696 'S','o','f','t','w','a','r','e','\\',
5697 'M','i','c','r','o','s','o','f','t','\\',
5698 'W','i','n','d','o','w','s','\\',
5699 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5700 'R','u','n','O','n','c','e',0};
5701 static const WCHAR InstallRunOnce[] = {
5702 'S','o','f','t','w','a','r','e','\\',
5703 'M','i','c','r','o','s','o','f','t','\\',
5704 'W','i','n','d','o','w','s','\\',
5705 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5706 'I','n','s','t','a','l','l','e','r','\\',
5707 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
5709 static const WCHAR msiexec_fmt[] = {
5711 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5712 '\"','%','s','\"',0};
5713 static const WCHAR install_fmt[] = {
5714 '/','I',' ','\"','%','s','\"',' ',
5715 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5716 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5717 WCHAR buffer[256], sysdir[MAX_PATH];
5720 WCHAR squished_pc[100];
5723 static const WCHAR szLUS[] = {
5724 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
5725 static const WCHAR szSourceList[] = {
5726 'S','o','u','r','c','e','L','i','s','t',0};
5727 static const WCHAR szPackageName[] = {
5728 'P','a','c','k','a','g','e','N','a','m','e',0};
5731 return ERROR_INVALID_HANDLE;
5733 productcode = load_dynamic_property(package,szProductCode,&rc);
5737 squash_guid(productcode,squished_pc);
5739 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
5740 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
5741 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
5744 size = strlenW(buffer)*sizeof(WCHAR);
5745 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5748 TRACE("Reboot command %s\n",debugstr_w(buffer));
5750 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
5751 sprintfW(buffer,install_fmt,productcode,squished_pc);
5753 size = strlenW(buffer)*sizeof(WCHAR);
5754 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5757 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5758 if (rc == ERROR_SUCCESS)
5762 RegCreateKeyW(hukey, szSourceList, &hukey2);
5763 buf = load_dynamic_property(package,cszSourceDir,NULL);
5764 size = strlenW(buf)*sizeof(WCHAR);
5765 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
5766 HeapFree(GetProcessHeap(),0,buf);
5768 buf = strrchrW(package->PackagePath,'\\');
5772 size = strlenW(buf)*sizeof(WCHAR);
5773 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
5776 RegCloseKey(hukey2);
5778 HeapFree(GetProcessHeap(),0,productcode);
5780 return ERROR_INSTALL_SUSPEND;
5783 UINT ACTION_ResolveSource(MSIPACKAGE* package)
5786 * we are currently doing what should be done here in the top level Install
5787 * however for Adminastrative and uninstalls this step will be needed
5789 return ERROR_SUCCESS;
5793 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
5797 MSIRECORD * row = 0;
5798 static const WCHAR ExecSeqQuery[] =
5799 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5800 'E','x','t','e','n','s','i','o','n',0};
5801 static const WCHAR szContentType[] =
5802 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
5806 return ERROR_INVALID_HANDLE;
5808 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5809 if (rc != ERROR_SUCCESS)
5815 rc = MSI_ViewExecute(view, 0);
5816 if (rc != ERROR_SUCCESS)
5818 MSI_ViewClose(view);
5819 msiobj_release(&view->hdr);
5825 WCHAR buffer[0x100];
5826 WCHAR extension[257];
5831 rc = MSI_ViewFetch(view,&row);
5832 if (rc != ERROR_SUCCESS)
5839 MSI_RecordGetStringW(row,2,buffer,&sz);
5841 index = get_loaded_component(package,buffer);
5845 msiobj_release(&row->hdr);
5849 if (!ACTION_VerifyComponentForAction(package, index,
5850 INSTALLSTATE_LOCAL))
5852 TRACE("Skipping extension reg due to disabled component\n");
5853 msiobj_release(&row->hdr);
5855 package->components[index].Action =
5856 package->components[index].Installed;
5861 package->components[index].Action = INSTALLSTATE_LOCAL;
5863 exten = load_dynamic_stringW(row,1);
5866 strcatW(extension,exten);
5867 HeapFree(GetProcessHeap(),0,exten);
5869 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
5871 if (!MSI_RecordIsNull(row,4))
5873 LPWSTR mime = load_dynamic_stringW(row,4);
5874 RegSetValueExW(hkey,szContentType,0,REG_SZ,(LPVOID)mime,
5875 (strlenW(mime)+1)*sizeof(WCHAR));
5876 HeapFree(GetProcessHeap(),0,mime);
5879 if (!MSI_RecordIsNull(row,3))
5881 static const WCHAR szSN[] =
5882 {'\\','S','h','e','l','l','N','e','w',0};
5885 LPWSTR progid= load_dynamic_stringW(row,3);
5887 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
5888 (strlenW(progid)+1)*sizeof(WCHAR));
5890 newkey = HeapAlloc(GetProcessHeap(),0,
5891 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
5893 strcpyW(newkey,progid);
5894 strcatW(newkey,szSN);
5895 RegCreateKeyW(hkey,newkey,&hkey2);
5898 HeapFree(GetProcessHeap(),0,progid);
5899 HeapFree(GetProcessHeap(),0,newkey);
5905 ui_actiondata(package,szRegisterExtensionInfo,row);
5907 msiobj_release(&row->hdr);
5909 MSI_ViewClose(view);
5910 msiobj_release(&view->hdr);
5916 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
5920 MSIRECORD * row = 0;
5921 static const WCHAR ExecSeqQuery[] =
5922 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5924 static const WCHAR szExten[] =
5925 {'E','x','t','e','n','s','i','o','n',0 };
5929 return ERROR_INVALID_HANDLE;
5931 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5932 if (rc != ERROR_SUCCESS)
5938 rc = MSI_ViewExecute(view, 0);
5939 if (rc != ERROR_SUCCESS)
5941 MSI_ViewClose(view);
5942 msiobj_release(&view->hdr);
5948 WCHAR extension[257];
5951 static const WCHAR fmt[] =
5952 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
5953 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
5956 rc = MSI_ViewFetch(view,&row);
5957 if (rc != ERROR_SUCCESS)
5963 mime = load_dynamic_stringW(row,1);
5964 exten = load_dynamic_stringW(row,2);
5967 strcatW(extension,exten);
5968 HeapFree(GetProcessHeap(),0,exten);
5970 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
5972 sprintfW(key,fmt,mime);
5973 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
5974 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
5975 (strlenW(extension)+1)*sizeof(WCHAR));
5977 HeapFree(GetProcessHeap(),0,mime);
5978 HeapFree(GetProcessHeap(),0,key);
5980 if (!MSI_RecordIsNull(row,3))
5982 FIXME("Handle non null for field 3\n");
5987 ui_actiondata(package,szRegisterMIMEInfo,row);
5989 msiobj_release(&row->hdr);
5991 MSI_ViewClose(view);
5992 msiobj_release(&view->hdr);
5998 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
6000 static const WCHAR szProductID[]=
6001 {'P','r','o','d','u','c','t','I','D',0};
6009 static const WCHAR szPropKeys[][80] =
6011 {'P','r','o','d','u','c','t','I','D',0},
6012 {'U','S','E','R','N','A','M','E',0},
6013 {'C','O','M','P','A','N','Y','N','A','M','E',0},
6017 static const WCHAR szRegKeys[][80] =
6019 {'P','r','o','d','u','c','t','I','D',0},
6020 {'R','e','g','O','w','n','e','r',0},
6021 {'R','e','g','C','o','m','p','a','n','y',0},
6026 return ERROR_INVALID_HANDLE;
6028 productid = load_dynamic_property(package,szProductID,&rc);
6030 return ERROR_SUCCESS;
6032 productcode = load_dynamic_property(package,szProductCode,&rc);
6036 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
6037 if (rc != ERROR_SUCCESS)
6041 while (szPropKeys[i][0]!=0)
6043 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
6044 if (rc == ERROR_SUCCESS)
6046 size = strlenW(buffer)*sizeof(WCHAR);
6047 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
6053 HeapFree(GetProcessHeap(),0,productcode);
6054 HeapFree(GetProcessHeap(),0,productid);
6057 return ERROR_SUCCESS;
6061 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
6064 rc = ACTION_ProcessExecSequence(package,TRUE);
6070 * Code based off of code located here
6071 * http://www.codeproject.com/gdi/fontnamefromfile.asp
6073 * Using string index 4 (full font name) instead of 1 (family name)
6075 static LPWSTR load_ttfname_from(LPCWSTR filename)
6081 typedef struct _tagTT_OFFSET_TABLE{
6082 USHORT uMajorVersion;
6083 USHORT uMinorVersion;
6084 USHORT uNumOfTables;
6085 USHORT uSearchRange;
6086 USHORT uEntrySelector;
6090 typedef struct _tagTT_TABLE_DIRECTORY{
6091 char szTag[4]; /* table name */
6092 ULONG uCheckSum; /* Check sum */
6093 ULONG uOffset; /* Offset from beginning of file */
6094 ULONG uLength; /* length of the table in bytes */
6095 }TT_TABLE_DIRECTORY;
6097 typedef struct _tagTT_NAME_TABLE_HEADER{
6098 USHORT uFSelector; /* format selector. Always 0 */
6099 USHORT uNRCount; /* Name Records count */
6100 USHORT uStorageOffset; /* Offset for strings storage,
6101 * from start of the table */
6102 }TT_NAME_TABLE_HEADER;
6104 typedef struct _tagTT_NAME_RECORD{
6109 USHORT uStringLength;
6110 USHORT uStringOffset; /* from start of storage area */
6113 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
6114 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
6116 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
6117 FILE_ATTRIBUTE_NORMAL, 0 );
6118 if (handle != INVALID_HANDLE_VALUE)
6120 TT_TABLE_DIRECTORY tblDir;
6121 BOOL bFound = FALSE;
6122 TT_OFFSET_TABLE ttOffsetTable;
6124 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
6125 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
6126 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
6127 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
6129 if (ttOffsetTable.uMajorVersion != 1 ||
6130 ttOffsetTable.uMinorVersion != 0)
6133 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
6135 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
6136 if (strncmp(tblDir.szTag,"name",4)==0)
6139 tblDir.uLength = SWAPLONG(tblDir.uLength);
6140 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
6147 TT_NAME_TABLE_HEADER ttNTHeader;
6148 TT_NAME_RECORD ttRecord;
6150 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
6151 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
6154 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
6155 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
6157 for(i=0; i<ttNTHeader.uNRCount; i++)
6159 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
6160 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
6161 /* 4 is the Full Font Name */
6162 if(ttRecord.uNameID == 4)
6166 static const LPSTR tt = " (TrueType)";
6168 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
6169 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
6170 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
6171 SetFilePointer(handle, tblDir.uOffset +
6172 ttRecord.uStringOffset +
6173 ttNTHeader.uStorageOffset,
6175 buf = HeapAlloc(GetProcessHeap(), 0,
6176 ttRecord.uStringLength + 1 + strlen(tt));
6177 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
6178 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
6179 if (strlen(buf) > 0)
6182 ret = strdupAtoW(buf);
6183 HeapFree(GetProcessHeap(),0,buf);
6187 HeapFree(GetProcessHeap(),0,buf);
6188 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
6192 CloseHandle(handle);
6195 TRACE("Returning fontname %s\n",debugstr_w(ret));
6199 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
6203 MSIRECORD * row = 0;
6204 static const WCHAR ExecSeqQuery[] =
6205 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6207 static const WCHAR regfont1[] =
6208 {'S','o','f','t','w','a','r','e','\\',
6209 'M','i','c','r','o','s','o','f','t','\\',
6210 'W','i','n','d','o','w','s',' ','N','T','\\',
6211 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6212 'F','o','n','t','s',0};
6213 static const WCHAR regfont2[] =
6214 {'S','o','f','t','w','a','r','e','\\',
6215 'M','i','c','r','o','s','o','f','t','\\',
6216 'W','i','n','d','o','w','s','\\',
6217 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6218 'F','o','n','t','s',0};
6222 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6223 if (rc != ERROR_SUCCESS)
6226 rc = MSI_ViewExecute(view, 0);
6227 if (rc != ERROR_SUCCESS)
6229 MSI_ViewClose(view);
6230 msiobj_release(&view->hdr);
6234 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
6235 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
6244 rc = MSI_ViewFetch(view,&row);
6245 if (rc != ERROR_SUCCESS)
6251 file = load_dynamic_stringW(row,1);
6252 index = get_loaded_file(package,file);
6255 ERR("Unable to load file\n");
6256 HeapFree(GetProcessHeap(),0,file);
6260 /* check to make sure that component is installed */
6261 if (!ACTION_VerifyComponentForAction(package,
6262 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
6264 TRACE("Skipping: Component not scheduled for install\n");
6265 HeapFree(GetProcessHeap(),0,file);
6267 msiobj_release(&row->hdr);
6272 if (MSI_RecordIsNull(row,2))
6273 name = load_ttfname_from(package->files[index].TargetPath);
6275 name = load_dynamic_stringW(row,2);
6279 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
6280 RegSetValueExW(hkey1,name,0,REG_SZ,
6281 (LPBYTE)package->files[index].FileName,size);
6282 RegSetValueExW(hkey2,name,0,REG_SZ,
6283 (LPBYTE)package->files[index].FileName,size);
6286 HeapFree(GetProcessHeap(),0,file);
6287 HeapFree(GetProcessHeap(),0,name);
6288 msiobj_release(&row->hdr);
6290 MSI_ViewClose(view);
6291 msiobj_release(&view->hdr);
6299 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
6301 MSIPACKAGE *package = (MSIPACKAGE*)param;
6302 LPWSTR productid=NULL, compgroupid=NULL;
6303 LPWSTR feature=NULL;
6305 LPWSTR qualifier = NULL;
6306 LPWSTR component = NULL;
6308 WCHAR productid_85[21];
6309 WCHAR component_85[21];
6311 UINT rc = ERROR_SUCCESS;
6314 * I have a fair bit of confusion as to when a < is used and when a > is
6315 * used. I do not think i have it right...
6317 * Ok it appears that the > is used if there is a guid for the compoenent
6318 * and the < is used if not.
6320 static WCHAR fmt1[] = {'%','s','%','s','<',0,0};
6321 static WCHAR fmt2[] = {'%','s','%','s','>','%','s',0,0};
6322 LPWSTR output = NULL;
6325 memset(productid_85,0,sizeof(productid_85));
6326 memset(component_85,0,sizeof(component_85));
6327 compgroupid = load_dynamic_stringW(rec,1);
6329 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
6330 if (rc != ERROR_SUCCESS)
6333 productid = load_dynamic_property(package,szProductCode,NULL);
6334 CLSIDFromString(productid, &clsid);
6336 encode_base85_guid(&clsid,productid_85);
6338 text = load_dynamic_stringW(rec,4);
6339 qualifier = load_dynamic_stringW(rec,2);
6341 feature = load_dynamic_stringW(rec,5);
6342 component = load_dynamic_stringW(rec,3);
6344 index = get_loaded_component(package, component);
6345 CLSIDFromString(package->components[index].ComponentId, &clsid);
6346 encode_base85_guid(&clsid,component_85);
6348 TRACE("Doing something with this... %s = %s %s %s %s\n",
6349 debugstr_w(qualifier), debugstr_w(productid_85),
6350 debugstr_w(feature), debugstr_w(text), debugstr_w(component_85));
6352 sz = lstrlenW(productid_85) + lstrlenW(feature);
6354 sz += lstrlenW(text);
6355 if (component && index >= 0)
6356 sz += lstrlenW(component_85);
6359 sz *= sizeof(WCHAR);
6361 output = HeapAlloc(GetProcessHeap(),0,sz);
6362 memset(output,0,sz);
6364 if (component && index >= 0)
6365 sprintfW(output,fmt2,productid_85,feature,component_85);
6367 sprintfW(output,fmt1,productid_85,feature);
6370 strcatW(output,text);
6372 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
6373 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
6377 HeapFree(GetProcessHeap(),0,output);
6378 HeapFree(GetProcessHeap(),0,compgroupid);
6379 HeapFree(GetProcessHeap(),0,component);
6380 HeapFree(GetProcessHeap(),0,productid);
6381 HeapFree(GetProcessHeap(),0,feature);
6382 HeapFree(GetProcessHeap(),0,text);
6383 HeapFree(GetProcessHeap(),0,qualifier);
6389 * At present I am ignorning the advertised components part of this and only
6390 * focusing on the qualified component sets
6392 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
6396 static const WCHAR ExecSeqQuery[] =
6397 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6398 'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t',0};
6400 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6401 if (rc != ERROR_SUCCESS)
6402 return ERROR_SUCCESS;
6404 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
6405 msiobj_release(&view->hdr);
6410 /* Msi functions that seem appropriate here */
6412 /***********************************************************************
6413 * MsiDoActionA (MSI.@)
6415 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
6420 TRACE(" exteral attempt at action %s\n",szAction);
6423 return ERROR_FUNCTION_FAILED;
6425 return ERROR_FUNCTION_FAILED;
6427 szwAction = strdupAtoW(szAction);
6430 return ERROR_FUNCTION_FAILED;
6433 rc = MsiDoActionW(hInstall, szwAction);
6434 HeapFree(GetProcessHeap(),0,szwAction);
6438 /***********************************************************************
6439 * MsiDoActionW (MSI.@)
6441 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
6443 MSIPACKAGE *package;
6444 UINT ret = ERROR_INVALID_HANDLE;
6446 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
6448 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6451 ret = ACTION_PerformUIAction(package,szAction);
6452 msiobj_release( &package->hdr );
6457 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
6458 LPSTR szPathBuf, DWORD* pcchPathBuf)
6464 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
6467 return ERROR_FUNCTION_FAILED;
6469 return ERROR_FUNCTION_FAILED;
6471 szwFolder = strdupAtoW(szFolder);
6474 return ERROR_FUNCTION_FAILED;
6476 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
6478 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
6480 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
6481 *pcchPathBuf, NULL, NULL );
6483 HeapFree(GetProcessHeap(),0,szwFolder);
6484 HeapFree(GetProcessHeap(),0,szwPathBuf);
6489 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
6490 szPathBuf, DWORD* pcchPathBuf)
6493 UINT rc = ERROR_FUNCTION_FAILED;
6494 MSIPACKAGE *package;
6496 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
6498 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6500 return ERROR_INVALID_HANDLE;
6501 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
6502 msiobj_release( &package->hdr );
6504 if (path && (strlenW(path) > *pcchPathBuf))
6506 *pcchPathBuf = strlenW(path)+1;
6507 rc = ERROR_MORE_DATA;
6511 *pcchPathBuf = strlenW(path)+1;
6512 strcpyW(szPathBuf,path);
6513 TRACE("Returning Path %s\n",debugstr_w(path));
6516 HeapFree(GetProcessHeap(),0,path);
6522 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
6523 LPSTR szPathBuf, DWORD* pcchPathBuf)
6529 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
6532 return ERROR_FUNCTION_FAILED;
6534 return ERROR_FUNCTION_FAILED;
6536 szwFolder = strdupAtoW(szFolder);
6538 return ERROR_FUNCTION_FAILED;
6540 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
6542 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
6544 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
6545 *pcchPathBuf, NULL, NULL );
6547 HeapFree(GetProcessHeap(),0,szwFolder);
6548 HeapFree(GetProcessHeap(),0,szwPathBuf);
6553 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
6554 szPathBuf, DWORD* pcchPathBuf)
6557 UINT rc = ERROR_FUNCTION_FAILED;
6558 MSIPACKAGE *package;
6560 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
6562 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6564 return ERROR_INVALID_HANDLE;
6565 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
6566 msiobj_release( &package->hdr );
6568 if (path && strlenW(path) > *pcchPathBuf)
6570 *pcchPathBuf = strlenW(path)+1;
6571 rc = ERROR_MORE_DATA;
6575 *pcchPathBuf = strlenW(path)+1;
6576 strcpyW(szPathBuf,path);
6577 TRACE("Returning Path %s\n",debugstr_w(path));
6580 HeapFree(GetProcessHeap(),0,path);
6586 /***********************************************************************
6587 * MsiSetTargetPathA (MSI.@)
6589 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
6590 LPCSTR szFolderPath)
6593 LPWSTR szwFolderPath;
6597 return ERROR_FUNCTION_FAILED;
6599 return ERROR_FUNCTION_FAILED;
6601 szwFolder = strdupAtoW(szFolder);
6603 return ERROR_FUNCTION_FAILED;
6605 szwFolderPath = strdupAtoW(szFolderPath);
6608 HeapFree(GetProcessHeap(),0,szwFolder);
6609 return ERROR_FUNCTION_FAILED;
6612 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
6614 HeapFree(GetProcessHeap(),0,szwFolder);
6615 HeapFree(GetProcessHeap(),0,szwFolderPath);
6620 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
6621 LPCWSTR szFolderPath)
6625 LPWSTR path2 = NULL;
6628 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
6631 return ERROR_INVALID_HANDLE;
6633 if (szFolderPath[0]==0)
6634 return ERROR_FUNCTION_FAILED;
6636 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
6637 return ERROR_FUNCTION_FAILED;
6639 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
6642 return ERROR_INVALID_PARAMETER;
6644 HeapFree(GetProcessHeap(),0,folder->Property);
6645 folder->Property = build_directory_name(2, szFolderPath, NULL);
6647 if (strcmpiW(path, folder->Property) == 0)
6650 * Resolved Target has not really changed, so just
6651 * set this folder and do not recalculate everything.
6653 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
6654 folder->ResolvedTarget = NULL;
6655 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
6656 HeapFree(GetProcessHeap(),0,path2);
6660 for (i = 0; i < package->loaded_folders; i++)
6662 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
6663 package->folders[i].ResolvedTarget=NULL;
6666 for (i = 0; i < package->loaded_folders; i++)
6668 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
6670 HeapFree(GetProcessHeap(),0,path2);
6673 HeapFree(GetProcessHeap(),0,path);
6675 return ERROR_SUCCESS;
6678 /***********************************************************************
6679 * MsiSetTargetPathW (MSI.@)
6681 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
6682 LPCWSTR szFolderPath)
6684 MSIPACKAGE *package;
6687 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
6689 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6690 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
6691 msiobj_release( &package->hdr );
6695 /***********************************************************************
6696 * MsiGetMode (MSI.@)
6698 * Returns an internal installer state (if it is running in a mode iRunMode)
6701 * hInstall [I] Handle to the installation
6702 * hRunMode [I] Checking run mode
6703 * MSIRUNMODE_ADMIN Administrative mode
6704 * MSIRUNMODE_ADVERTISE Advertisement mode
6705 * MSIRUNMODE_MAINTENANCE Maintenance mode
6706 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
6707 * MSIRUNMODE_LOGENABLED Log file is writing
6708 * MSIRUNMODE_OPERATIONS Operations in progress??
6709 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
6710 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
6711 * MSIRUNMODE_CABINET Files from cabinet are installed
6712 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
6713 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
6714 * MSIRUNMODE_RESERVED11 Reserved
6715 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
6716 * MSIRUNMODE_ZAWENABLED Demand installation is supported
6717 * MSIRUNMODE_RESERVED14 Reserved
6718 * MSIRUNMODE_RESERVED15 Reserved
6719 * MSIRUNMODE_SCHEDULED called from install script
6720 * MSIRUNMODE_ROLLBACK called from rollback script
6721 * MSIRUNMODE_COMMIT called from commit script
6724 * In the state: TRUE
6725 * Not in the state: FALSE
6729 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
6731 FIXME("STUB (iRunMode=%i)\n",iRunMode);
6735 /***********************************************************************
6736 * MsiSetFeatureStateA (MSI.@)
6738 * According to the docs, when this is called it immediately recalculates
6739 * all the component states as well
6741 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
6742 INSTALLSTATE iState)
6744 LPWSTR szwFeature = NULL;
6747 szwFeature = strdupAtoW(szFeature);
6750 return ERROR_FUNCTION_FAILED;
6752 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
6754 HeapFree(GetProcessHeap(),0,szwFeature);
6759 /***********************************************************************
6760 * MsiSetFeatureStateW (MSI.@)
6762 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
6763 INSTALLSTATE iState)
6765 MSIPACKAGE* package;
6767 UINT rc = ERROR_SUCCESS;
6769 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
6771 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6773 return ERROR_INVALID_HANDLE;
6775 index = get_loaded_feature(package,szFeature);
6778 rc = ERROR_UNKNOWN_FEATURE;
6782 package->features[index].ActionRequest= iState;
6783 ACTION_UpdateComponentStates(package,szFeature);
6786 msiobj_release( &package->hdr );
6790 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
6791 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6793 LPWSTR szwFeature = NULL;
6796 szwFeature = strdupAtoW(szFeature);
6798 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
6800 HeapFree( GetProcessHeap(), 0 , szwFeature);
6805 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
6806 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6810 index = get_loaded_feature(package,szFeature);
6812 return ERROR_UNKNOWN_FEATURE;
6815 *piInstalled = package->features[index].Installed;
6818 *piAction = package->features[index].Action;
6820 TRACE("returning %i %i\n",*piInstalled,*piAction);
6822 return ERROR_SUCCESS;
6825 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
6826 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6828 MSIPACKAGE* package;
6831 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
6834 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6836 return ERROR_INVALID_HANDLE;
6837 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
6838 msiobj_release( &package->hdr );
6842 /***********************************************************************
6843 * MsiGetComponentStateA (MSI.@)
6845 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
6846 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6848 LPWSTR szwComponent= NULL;
6851 szwComponent= strdupAtoW(szComponent);
6853 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
6855 HeapFree( GetProcessHeap(), 0 , szwComponent);
6860 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
6861 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6865 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
6868 index = get_loaded_component(package,szComponent);
6870 return ERROR_UNKNOWN_COMPONENT;
6873 *piInstalled = package->components[index].Installed;
6876 *piAction = package->components[index].Action;
6878 TRACE("states (%i, %i)\n",
6879 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
6881 return ERROR_SUCCESS;
6884 /***********************************************************************
6885 * MsiGetComponentStateW (MSI.@)
6887 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
6888 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6890 MSIPACKAGE* package;
6893 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
6894 piInstalled, piAction);
6896 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6898 return ERROR_INVALID_HANDLE;
6899 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
6900 msiobj_release( &package->hdr );
6905 static UINT ACTION_Template(MSIPACKAGE *package)
6909 MSIRECORD * row = 0;
6910 static const WCHAR ExecSeqQuery[] = {0};
6912 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6913 if (rc != ERROR_SUCCESS)
6916 rc = MSI_ViewExecute(view, 0);
6917 if (rc != ERROR_SUCCESS)
6919 MSI_ViewClose(view);
6920 msiobj_release(&view->hdr);
6926 rc = MSI_ViewFetch(view,&row);
6927 if (rc != ERROR_SUCCESS)
6933 msiobj_release(&row->hdr);
6935 MSI_ViewClose(view);
6936 msiobj_release(&view->hdr);