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 inline static void reduce_to_shortfilename(WCHAR* filename)
386 LPWSTR p = strchrW(filename,'|');
391 WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
398 if (MSI_RecordIsNull(row,index))
401 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
403 /* having an empty string is different than NULL */
406 ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
412 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
413 rc = MSI_RecordGetStringW(row,index,ret,&sz);
414 if (rc!=ERROR_SUCCESS)
416 ERR("Unable to load dynamic string\n");
417 HeapFree(GetProcessHeap(), 0, ret);
423 LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop, UINT* rc)
429 r = MSI_GetPropertyW(package, prop, NULL, &sz);
430 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
437 str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
438 r = MSI_GetPropertyW(package, prop, str, &sz);
439 if (r != ERROR_SUCCESS)
441 HeapFree(GetProcessHeap(),0,str);
449 int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
454 for (i = 0; i < package->loaded_components; i++)
456 if (strcmpW(Component,package->components[i].Component)==0)
465 int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
470 for (i = 0; i < package->loaded_features; i++)
472 if (strcmpW(Feature,package->features[i].Feature)==0)
481 int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
486 for (i = 0; i < package->loaded_files; i++)
488 if (strcmpW(file,package->files[i].File)==0)
497 int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
505 for (i=0; i < package->loaded_files; i++)
506 if (strcmpW(package->files[i].File,name)==0)
509 index = package->loaded_files;
510 package->loaded_files++;
511 if (package->loaded_files== 1)
512 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
514 package->files = HeapReAlloc(GetProcessHeap(),0,
515 package->files , package->loaded_files * sizeof(MSIFILE));
517 memset(&package->files[index],0,sizeof(MSIFILE));
519 package->files[index].File = strdupW(name);
520 package->files[index].TargetPath = strdupW(path);
521 package->files[index].Temporary = TRUE;
523 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
528 static void remove_tracked_tempfiles(MSIPACKAGE* package)
535 for (i = 0; i < package->loaded_files; i++)
537 if (package->files[i].Temporary)
539 TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
540 DeleteFileW(package->files[i].TargetPath);
546 /* wrapper to resist a need for a full rewrite right now */
547 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
551 MSIRECORD *rec = MSI_CreateRecord(1);
554 MSI_RecordSetStringW(rec,0,ptr);
555 MSI_FormatRecordW(package,rec,NULL,&size);
559 *data = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
561 MSI_FormatRecordW(package,rec,*data,&size);
564 msiobj_release( &rec->hdr );
565 return sizeof(WCHAR)*size;
567 msiobj_release( &rec->hdr );
574 /* Called when the package is being closed */
575 void ACTION_free_package_structures( MSIPACKAGE* package)
579 TRACE("Freeing package action data\n");
581 remove_tracked_tempfiles(package);
583 /* No dynamic buffers in features */
584 if (package->features && package->loaded_features > 0)
585 HeapFree(GetProcessHeap(),0,package->features);
587 for (i = 0; i < package->loaded_folders; i++)
589 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
590 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
591 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
592 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
593 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
594 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
596 if (package->folders && package->loaded_folders > 0)
597 HeapFree(GetProcessHeap(),0,package->folders);
599 for (i = 0; i < package->loaded_components; i++)
600 HeapFree(GetProcessHeap(),0,package->components[i].FullKeypath);
602 if (package->components && package->loaded_components > 0)
603 HeapFree(GetProcessHeap(),0,package->components);
605 for (i = 0; i < package->loaded_files; i++)
607 HeapFree(GetProcessHeap(),0,package->files[i].File);
608 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
609 HeapFree(GetProcessHeap(),0,package->files[i].ShortName);
610 HeapFree(GetProcessHeap(),0,package->files[i].Version);
611 HeapFree(GetProcessHeap(),0,package->files[i].Language);
612 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
613 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
616 if (package->files && package->loaded_files > 0)
617 HeapFree(GetProcessHeap(),0,package->files);
619 /* clean up extension, progid, class and verb structures */
620 for (i = 0; i < package->loaded_classes; i++)
622 HeapFree(GetProcessHeap(),0,package->classes[i].Description);
623 HeapFree(GetProcessHeap(),0,package->classes[i].FileTypeMask);
624 HeapFree(GetProcessHeap(),0,package->classes[i].IconPath);
625 HeapFree(GetProcessHeap(),0,package->classes[i].DefInprocHandler);
626 HeapFree(GetProcessHeap(),0,package->classes[i].DefInprocHandler32);
627 HeapFree(GetProcessHeap(),0,package->classes[i].Argument);
628 HeapFree(GetProcessHeap(),0,package->classes[i].ProgIDText);
631 if (package->classes && package->loaded_classes > 0)
632 HeapFree(GetProcessHeap(),0,package->classes);
634 for (i = 0; i < package->loaded_extensions; i++)
636 HeapFree(GetProcessHeap(),0,package->extensions[i].ProgIDText);
639 if (package->extensions && package->loaded_extensions > 0)
640 HeapFree(GetProcessHeap(),0,package->extensions);
642 for (i = 0; i < package->loaded_progids; i++)
644 HeapFree(GetProcessHeap(),0,package->progids[i].ProgID);
645 HeapFree(GetProcessHeap(),0,package->progids[i].Description);
646 HeapFree(GetProcessHeap(),0,package->progids[i].IconPath);
649 if (package->progids && package->loaded_progids > 0)
650 HeapFree(GetProcessHeap(),0,package->progids);
652 for (i = 0; i < package->loaded_verbs; i++)
654 HeapFree(GetProcessHeap(),0,package->verbs[i].Verb);
655 HeapFree(GetProcessHeap(),0,package->verbs[i].Command);
656 HeapFree(GetProcessHeap(),0,package->verbs[i].Argument);
659 if (package->verbs && package->loaded_verbs > 0)
660 HeapFree(GetProcessHeap(),0,package->verbs);
662 for (i = 0; i < package->loaded_mimes; i++)
663 HeapFree(GetProcessHeap(),0,package->mimes[i].ContentType);
665 if (package->mimes && package->loaded_mimes > 0)
666 HeapFree(GetProcessHeap(),0,package->mimes);
668 for (i = 0; i < package->loaded_appids; i++)
670 HeapFree(GetProcessHeap(),0,package->appids[i].RemoteServerName);
671 HeapFree(GetProcessHeap(),0,package->appids[i].LocalServer);
672 HeapFree(GetProcessHeap(),0,package->appids[i].ServiceParameters);
673 HeapFree(GetProcessHeap(),0,package->appids[i].DllSurrogate);
676 if (package->appids && package->loaded_appids > 0)
677 HeapFree(GetProcessHeap(),0,package->appids);
681 for (i = 0; i < TOTAL_SCRIPTS; i++)
684 for (j = 0; j < package->script->ActionCount[i]; j++)
685 HeapFree(GetProcessHeap(),0,package->script->Actions[i][j]);
687 HeapFree(GetProcessHeap(),0,package->script->Actions[i]);
689 HeapFree(GetProcessHeap(),0,package->script);
692 HeapFree(GetProcessHeap(),0,package->PackagePath);
694 /* cleanup control event subscriptions */
695 ControlEvent_CleanupSubscriptions(package);
698 static void ce_actiontext(MSIPACKAGE* package, LPCWSTR action)
700 static const WCHAR szActionText[] =
701 {'A','c','t','i','o','n','T','e','x','t',0};
704 row = MSI_CreateRecord(1);
705 MSI_RecordSetStringW(row,1,action);
706 ControlEvent_FireSubscribedEvent(package,szActionText, row);
707 msiobj_release(&row->hdr);
710 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
714 row = MSI_CreateRecord(4);
715 MSI_RecordSetInteger(row,1,a);
716 MSI_RecordSetInteger(row,2,b);
717 MSI_RecordSetInteger(row,3,c);
718 MSI_RecordSetInteger(row,4,d);
719 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
720 msiobj_release(&row->hdr);
722 msi_dialog_check_messages(NULL);
725 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
727 static const WCHAR Query_t[] =
728 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
729 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
730 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
731 ' ','\'','%','s','\'',0};
735 static const WCHAR szActionData[] =
736 {'A','c','t','i','o','n','D','a','t','a',0};
738 if (!package->LastAction || strcmpW(package->LastAction,action))
740 row = MSI_QueryGetRecord(package->db, Query_t, action);
744 if (MSI_RecordIsNull(row,3))
746 msiobj_release(&row->hdr);
750 /* update the cached actionformat */
751 HeapFree(GetProcessHeap(),0,package->ActionFormat);
752 package->ActionFormat = load_dynamic_stringW(row,3);
754 HeapFree(GetProcessHeap(),0,package->LastAction);
755 package->LastAction = strdupW(action);
757 msiobj_release(&row->hdr);
760 MSI_RecordSetStringW(record,0,package->ActionFormat);
762 MSI_FormatRecordW(package,record,message,&size);
764 row = MSI_CreateRecord(1);
765 MSI_RecordSetStringW(row,1,message);
767 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
769 ControlEvent_FireSubscribedEvent(package,szActionData, row);
771 msiobj_release(&row->hdr);
775 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
777 static const WCHAR template_s[]=
778 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
780 static const WCHAR format[] =
781 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
782 static const WCHAR Query_t[] =
783 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
784 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
785 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
786 ' ','\'','%','s','\'',0};
790 WCHAR *ActionText=NULL;
792 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
794 row = MSI_QueryGetRecord( package->db, Query_t, action );
798 ActionText = load_dynamic_stringW(row,2);
799 msiobj_release(&row->hdr);
801 sprintfW(message,template_s,timet,action,ActionText);
803 row = MSI_CreateRecord(1);
804 MSI_RecordSetStringW(row,1,message);
806 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
807 msiobj_release(&row->hdr);
808 HeapFree(GetProcessHeap(),0,ActionText);
811 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
815 static const WCHAR template_s[]=
816 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
818 static const WCHAR template_e[]=
819 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
820 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
822 static const WCHAR format[] =
823 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
827 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
829 sprintfW(message,template_s,timet,action);
831 sprintfW(message,template_e,timet,action,rc);
833 row = MSI_CreateRecord(1);
834 MSI_RecordSetStringW(row,1,message);
836 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
837 msiobj_release(&row->hdr);
841 * build_directory_name()
843 * This function is to save messing round with directory names
844 * It handles adding backslashes between path segments,
845 * and can add \ at the end of the directory name if told to.
847 * It takes a variable number of arguments.
848 * It always allocates a new string for the result, so make sure
849 * to free the return value when finished with it.
851 * The first arg is the number of path segments that follow.
852 * The arguments following count are a list of path segments.
853 * A path segment may be NULL.
855 * Path segments will be added with a \ separating them.
856 * A \ will not be added after the last segment, however if the
857 * last segment is NULL, then the last character will be a \
860 static LPWSTR build_directory_name(DWORD count, ...)
867 for(i=0; i<count; i++)
869 LPCWSTR str = va_arg(va,LPCWSTR);
871 sz += strlenW(str) + 1;
875 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
879 for(i=0; i<count; i++)
881 LPCWSTR str = va_arg(va,LPCWSTR);
885 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
891 static BOOL ACTION_VerifyComponentForAction(MSIPACKAGE* package, INT index,
894 if (package->components[index].Installed == check)
897 if (package->components[index].ActionRequest == check)
903 static BOOL ACTION_VerifyFeatureForAction(MSIPACKAGE* package, INT index,
906 if (package->features[index].Installed == check)
909 if (package->features[index].ActionRequest == check)
916 /****************************************************
917 * TOP level entry points
918 *****************************************************/
920 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
921 LPCWSTR szCommandLine)
927 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
928 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
929 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
931 MSI_SetPropertyW(package, szAction, szInstall);
933 package->script = HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT));
934 memset(package->script,0,sizeof(MSISCRIPT));
938 LPWSTR p, check, path;
940 package->PackagePath = strdupW(szPackagePath);
941 path = strdupW(szPackagePath);
942 p = strrchrW(path,'\\');
950 HeapFree(GetProcessHeap(),0,path);
951 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
952 GetCurrentDirectoryW(MAX_PATH,path);
956 check = load_dynamic_property(package, cszSourceDir,NULL);
958 MSI_SetPropertyW(package, cszSourceDir, path);
960 HeapFree(GetProcessHeap(), 0, check);
962 HeapFree(GetProcessHeap(), 0, path);
968 ptr = (LPWSTR)szCommandLine;
975 TRACE("Looking at %s\n",debugstr_w(ptr));
977 ptr2 = strchrW(ptr,'=');
983 while (*ptr == ' ') ptr++;
985 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
986 memcpy(prop,ptr,len*sizeof(WCHAR));
992 while (*ptr && (quote || (!quote && *ptr!=' ')))
1005 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
1006 memcpy(val,ptr2,len*sizeof(WCHAR));
1009 if (strlenW(prop) > 0)
1011 TRACE("Found commandline property (%s) = (%s)\n",
1012 debugstr_w(prop), debugstr_w(val));
1013 MSI_SetPropertyW(package,prop,val);
1015 HeapFree(GetProcessHeap(),0,val);
1016 HeapFree(GetProcessHeap(),0,prop);
1023 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
1025 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
1027 rc = ACTION_ProcessUISequence(package);
1029 if (rc == ERROR_SUCCESS)
1030 rc = ACTION_ProcessExecSequence(package,TRUE);
1033 rc = ACTION_ProcessExecSequence(package,FALSE);
1036 rc = ACTION_ProcessExecSequence(package,FALSE);
1040 /* install was halted but should be considered a success */
1044 package->script->CurrentlyScripting= FALSE;
1046 /* process the ending type action */
1047 if (rc == ERROR_SUCCESS)
1048 ACTION_PerformActionSequence(package,-1,ui);
1049 else if (rc == ERROR_INSTALL_USEREXIT)
1050 ACTION_PerformActionSequence(package,-2,ui);
1051 else if (rc == ERROR_INSTALL_SUSPEND)
1052 ACTION_PerformActionSequence(package,-4,ui);
1054 ACTION_PerformActionSequence(package,-3,ui);
1056 /* finish up running custom actions */
1057 ACTION_FinishCustomActions(package);
1062 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
1064 UINT rc = ERROR_SUCCESS;
1065 WCHAR buffer[0x100];
1067 MSIRECORD * row = 0;
1068 static const WCHAR ExecSeqQuery[] =
1069 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1070 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1071 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1072 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
1074 static const WCHAR UISeqQuery[] =
1075 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1076 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1077 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
1078 ' ', '=',' ','%','i',0};
1081 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
1083 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
1087 TRACE("Running the actions\n");
1089 /* check conditions */
1090 if (!MSI_RecordIsNull(row,2))
1093 cond = load_dynamic_stringW(row,2);
1097 /* this is a hack to skip errors in the condition code */
1098 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1100 HeapFree(GetProcessHeap(),0,cond);
1104 HeapFree(GetProcessHeap(),0,cond);
1109 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1110 if (rc != ERROR_SUCCESS)
1112 ERR("Error is %x\n",rc);
1113 msiobj_release(&row->hdr);
1118 rc = ACTION_PerformUIAction(package,buffer);
1120 rc = ACTION_PerformAction(package,buffer, FALSE);
1122 msiobj_release(&row->hdr);
1130 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1134 static const WCHAR ExecSeqQuery[] =
1135 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1136 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1137 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1138 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
1139 'O','R','D','E','R',' ', 'B','Y',' ',
1140 '`','S','e','q','u','e','n','c','e','`',0 };
1141 MSIRECORD * row = 0;
1142 static const WCHAR IVQuery[] =
1143 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
1144 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
1145 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
1146 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
1147 ' ','\'', 'I','n','s','t','a','l','l',
1148 'V','a','l','i','d','a','t','e','\'', 0};
1152 if (package->script->ExecuteSequenceRun)
1154 TRACE("Execute Sequence already Run\n");
1155 return ERROR_SUCCESS;
1158 package->script->ExecuteSequenceRun = TRUE;
1160 /* get the sequence number */
1163 row = MSI_QueryGetRecord(package->db, IVQuery);
1165 return ERROR_FUNCTION_FAILED;
1166 seq = MSI_RecordGetInteger(row,1);
1167 msiobj_release(&row->hdr);
1170 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1171 if (rc == ERROR_SUCCESS)
1173 rc = MSI_ViewExecute(view, 0);
1175 if (rc != ERROR_SUCCESS)
1177 MSI_ViewClose(view);
1178 msiobj_release(&view->hdr);
1182 TRACE("Running the actions\n");
1186 WCHAR buffer[0x100];
1189 rc = MSI_ViewFetch(view,&row);
1190 if (rc != ERROR_SUCCESS)
1197 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1198 if (rc != ERROR_SUCCESS)
1200 ERR("Error is %x\n",rc);
1201 msiobj_release(&row->hdr);
1205 /* check conditions */
1206 if (!MSI_RecordIsNull(row,2))
1209 cond = load_dynamic_stringW(row,2);
1213 /* this is a hack to skip errors in the condition code */
1214 if (MSI_EvaluateConditionW(package, cond) ==
1217 HeapFree(GetProcessHeap(),0,cond);
1218 msiobj_release(&row->hdr);
1219 TRACE("Skipping action: %s (condition is false)\n",
1220 debugstr_w(buffer));
1224 HeapFree(GetProcessHeap(),0,cond);
1228 rc = ACTION_PerformAction(package,buffer, FALSE);
1230 if (rc == ERROR_FUNCTION_NOT_CALLED)
1233 if (rc != ERROR_SUCCESS)
1235 ERR("Execution halted due to error (%i)\n",rc);
1236 msiobj_release(&row->hdr);
1240 msiobj_release(&row->hdr);
1243 MSI_ViewClose(view);
1244 msiobj_release(&view->hdr);
1252 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1256 static const WCHAR ExecSeqQuery [] =
1257 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1258 '`','I','n','s','t','a','l','l',
1259 'U','I','S','e','q','u','e','n','c','e','`',
1260 ' ','W','H','E','R','E',' ',
1261 '`','S','e','q','u','e','n','c','e','`',' ',
1262 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1263 '`','S','e','q','u','e','n','c','e','`',0};
1265 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1267 if (rc == ERROR_SUCCESS)
1269 rc = MSI_ViewExecute(view, 0);
1271 if (rc != ERROR_SUCCESS)
1273 MSI_ViewClose(view);
1274 msiobj_release(&view->hdr);
1278 TRACE("Running the actions \n");
1282 WCHAR buffer[0x100];
1284 MSIRECORD * row = 0;
1286 rc = MSI_ViewFetch(view,&row);
1287 if (rc != ERROR_SUCCESS)
1294 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1295 if (rc != ERROR_SUCCESS)
1297 ERR("Error is %x\n",rc);
1298 msiobj_release(&row->hdr);
1303 /* check conditions */
1304 if (!MSI_RecordIsNull(row,2))
1307 cond = load_dynamic_stringW(row,2);
1311 /* this is a hack to skip errors in the condition code */
1312 if (MSI_EvaluateConditionW(package, cond) ==
1315 HeapFree(GetProcessHeap(),0,cond);
1316 msiobj_release(&row->hdr);
1317 TRACE("Skipping action: %s (condition is false)\n",
1318 debugstr_w(buffer));
1322 HeapFree(GetProcessHeap(),0,cond);
1326 rc = ACTION_PerformUIAction(package,buffer);
1328 if (rc == ERROR_FUNCTION_NOT_CALLED)
1331 if (rc != ERROR_SUCCESS)
1333 ERR("Execution halted due to error (%i)\n",rc);
1334 msiobj_release(&row->hdr);
1338 msiobj_release(&row->hdr);
1341 MSI_ViewClose(view);
1342 msiobj_release(&view->hdr);
1349 /********************************************************
1350 * ACTION helper functions and functions that perform the actions
1351 *******************************************************/
1352 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
1353 UINT* rc, BOOL force )
1359 if (!run && !package->script->CurrentlyScripting)
1364 if (strcmpW(action,szInstallFinalize) == 0 ||
1365 strcmpW(action,szInstallExecute) == 0 ||
1366 strcmpW(action,szInstallExecuteAgain) == 0)
1371 while (StandardActions[i].action != NULL)
1373 if (strcmpW(StandardActions[i].action, action)==0)
1375 ce_actiontext(package, action);
1378 ui_actioninfo(package, action, TRUE, 0);
1379 *rc = schedule_action(package,INSTALL_SCRIPT,action);
1380 ui_actioninfo(package, action, FALSE, *rc);
1384 ui_actionstart(package, action);
1385 if (StandardActions[i].handler)
1387 *rc = StandardActions[i].handler(package);
1391 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1392 *rc = ERROR_SUCCESS;
1403 BOOL ACTION_HandleDialogBox(MSIPACKAGE *package, LPCWSTR dialog, UINT* rc)
1407 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1409 *rc = package->CurrentInstallState;
1415 BOOL ACTION_HandleCustomAction(MSIPACKAGE* package, LPCWSTR action, UINT* rc,
1421 arc = ACTION_CustomAction(package,action, force);
1423 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1432 * A lot of actions are really important even if they don't do anything
1433 * explicit... Lots of properties are set at the beginning of the installation
1434 * CostFinalize does a bunch of work to translate the directories and such
1436 * But until I get write access to the database that is hard, so I am going to
1437 * hack it to see if I can get something to run.
1439 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
1441 UINT rc = ERROR_SUCCESS;
1444 TRACE("Performing action (%s)\n",debugstr_w(action));
1446 handled = ACTION_HandleStandardAction(package, action, &rc, force);
1449 handled = ACTION_HandleCustomAction(package, action, &rc, force);
1453 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1454 rc = ERROR_FUNCTION_NOT_CALLED;
1457 package->CurrentInstallState = rc;
1461 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1463 UINT rc = ERROR_SUCCESS;
1464 BOOL handled = FALSE;
1466 TRACE("Performing action (%s)\n",debugstr_w(action));
1468 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
1471 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
1474 handled = ACTION_HandleDialogBox(package, action, &rc);
1476 msi_dialog_check_messages( NULL );
1480 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1481 rc = ERROR_FUNCTION_NOT_CALLED;
1484 package->CurrentInstallState = rc;
1488 /***********************************************************************
1491 * Recursively create all directories in the path.
1493 * shamelessly stolen from setupapi/queue.c
1495 static BOOL create_full_pathW(const WCHAR *path)
1501 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1504 strcpyW(new_path, path);
1506 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1507 new_path[len - 1] = 0;
1509 while(!CreateDirectoryW(new_path, NULL))
1512 DWORD last_error = GetLastError();
1513 if(last_error == ERROR_ALREADY_EXISTS)
1516 if(last_error != ERROR_PATH_NOT_FOUND)
1522 if(!(slash = strrchrW(new_path, '\\')))
1528 len = slash - new_path;
1530 if(!create_full_pathW(new_path))
1535 new_path[len] = '\\';
1538 HeapFree(GetProcessHeap(), 0, new_path);
1543 * Also we cannot enable/disable components either, so for now I am just going
1544 * to do all the directories for all the components.
1546 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1548 static const WCHAR ExecSeqQuery[] =
1549 {'S','E','L','E','C','T',' ',
1550 '`','D','i','r','e','c','t','o','r','y','_','`',
1551 ' ','F','R','O','M',' ',
1552 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
1557 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1558 if (rc != ERROR_SUCCESS)
1559 return ERROR_SUCCESS;
1561 rc = MSI_ViewExecute(view, 0);
1562 if (rc != ERROR_SUCCESS)
1564 MSI_ViewClose(view);
1565 msiobj_release(&view->hdr);
1574 MSIRECORD *row = NULL, *uirow;
1576 rc = MSI_ViewFetch(view,&row);
1577 if (rc != ERROR_SUCCESS)
1584 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1586 if (rc!= ERROR_SUCCESS)
1588 ERR("Unable to get folder id \n");
1589 msiobj_release(&row->hdr);
1594 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1597 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1598 msiobj_release(&row->hdr);
1602 TRACE("Folder is %s\n",debugstr_w(full_path));
1605 uirow = MSI_CreateRecord(1);
1606 MSI_RecordSetStringW(uirow,1,full_path);
1607 ui_actiondata(package,szCreateFolders,uirow);
1608 msiobj_release( &uirow->hdr );
1610 if (folder->State == 0)
1611 create_full_pathW(full_path);
1615 msiobj_release(&row->hdr);
1616 HeapFree(GetProcessHeap(),0,full_path);
1618 MSI_ViewClose(view);
1619 msiobj_release(&view->hdr);
1624 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1626 int index = package->loaded_components;
1629 /* fill in the data */
1631 package->loaded_components++;
1632 if (package->loaded_components == 1)
1633 package->components = HeapAlloc(GetProcessHeap(),0,
1634 sizeof(MSICOMPONENT));
1636 package->components = HeapReAlloc(GetProcessHeap(),0,
1637 package->components, package->loaded_components *
1638 sizeof(MSICOMPONENT));
1640 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1642 sz = IDENTIFIER_SIZE;
1643 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1645 TRACE("Loading Component %s\n",
1646 debugstr_w(package->components[index].Component));
1649 if (!MSI_RecordIsNull(row,2))
1650 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1652 sz = IDENTIFIER_SIZE;
1653 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1655 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1658 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1660 sz = IDENTIFIER_SIZE;
1661 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1663 package->components[index].Installed = INSTALLSTATE_ABSENT;
1664 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1665 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1667 package->components[index].Enabled = TRUE;
1672 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1674 int index = package->loaded_features;
1676 static const WCHAR Query1[] =
1677 {'S','E','L','E','C','T',' ',
1678 '`','C','o','m','p','o','n','e','n','t','_','`',
1679 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1680 'C','o','m','p','o','n','e','n','t','s','`',' ',
1681 'W','H','E','R','E',' ',
1682 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1683 static const WCHAR Query2[] =
1684 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1685 '`','C','o','m','p','o','n','e','n','t','`',' ',
1686 'W','H','E','R','E',' ',
1687 '`','C','o','m','p','o','n','e','n','t','`',' ',
1688 '=','\'','%','s','\'',0};
1695 /* fill in the data */
1697 package->loaded_features ++;
1698 if (package->loaded_features == 1)
1699 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1701 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1702 package->loaded_features * sizeof(MSIFEATURE));
1704 memset(&package->features[index],0,sizeof(MSIFEATURE));
1706 sz = IDENTIFIER_SIZE;
1707 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1709 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1711 sz = IDENTIFIER_SIZE;
1712 if (!MSI_RecordIsNull(row,2))
1713 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1716 if (!MSI_RecordIsNull(row,3))
1717 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1720 if (!MSI_RecordIsNull(row,4))
1721 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1723 if (!MSI_RecordIsNull(row,5))
1724 package->features[index].Display = MSI_RecordGetInteger(row,5);
1726 package->features[index].Level= MSI_RecordGetInteger(row,6);
1728 sz = IDENTIFIER_SIZE;
1729 if (!MSI_RecordIsNull(row,7))
1730 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1732 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1734 package->features[index].Installed = INSTALLSTATE_ABSENT;
1735 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1736 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1738 /* load feature components */
1740 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1741 if (rc != ERROR_SUCCESS)
1743 rc = MSI_ViewExecute(view,0);
1744 if (rc != ERROR_SUCCESS)
1746 MSI_ViewClose(view);
1747 msiobj_release(&view->hdr);
1753 WCHAR buffer[0x100];
1756 INT cnt = package->features[index].ComponentCount;
1758 rc = MSI_ViewFetch(view,&row2);
1759 if (rc != ERROR_SUCCESS)
1763 MSI_RecordGetStringW(row2,1,buffer,&sz);
1765 /* check to see if the component is already loaded */
1766 c_indx = get_loaded_component(package,buffer);
1769 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1771 package->features[index].Components[cnt] = c_indx;
1772 package->features[index].ComponentCount ++;
1773 msiobj_release( &row2->hdr );
1777 rc = MSI_OpenQuery(package->db, &view2, Query2, buffer);
1778 if (rc != ERROR_SUCCESS)
1780 msiobj_release( &row2->hdr );
1783 rc = MSI_ViewExecute(view2,0);
1784 if (rc != ERROR_SUCCESS)
1786 msiobj_release( &row2->hdr );
1787 MSI_ViewClose(view2);
1788 msiobj_release( &view2->hdr );
1795 rc = MSI_ViewFetch(view2,&row3);
1796 if (rc != ERROR_SUCCESS)
1798 c_indx = load_component(package,row3);
1799 msiobj_release( &row3->hdr );
1801 package->features[index].Components[cnt] = c_indx;
1802 package->features[index].ComponentCount ++;
1803 TRACE("Loaded new component to index %i\n",c_indx);
1805 MSI_ViewClose(view2);
1806 msiobj_release( &view2->hdr );
1807 msiobj_release( &row2->hdr );
1809 MSI_ViewClose(view);
1810 msiobj_release(&view->hdr);
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);
1845 reduce_to_longfilename(package->files[index].FileName);
1847 package->files[index].ShortName = load_dynamic_stringW(row,3);
1848 reduce_to_shortfilename(package->files[index].ShortName);
1850 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1851 package->files[index].Version = load_dynamic_stringW(row, 5);
1852 package->files[index].Language = load_dynamic_stringW(row, 6);
1853 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1854 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1856 package->files[index].Temporary = FALSE;
1857 package->files[index].State = 0;
1859 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1861 return ERROR_SUCCESS;
1864 static UINT load_all_files(MSIPACKAGE *package)
1869 static const WCHAR Query[] =
1870 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1871 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1872 '`','S','e','q','u','e','n','c','e','`', 0};
1875 return ERROR_INVALID_HANDLE;
1877 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1878 if (rc != ERROR_SUCCESS)
1879 return ERROR_SUCCESS;
1881 rc = MSI_ViewExecute(view, 0);
1882 if (rc != ERROR_SUCCESS)
1884 MSI_ViewClose(view);
1885 msiobj_release(&view->hdr);
1886 return ERROR_SUCCESS;
1891 rc = MSI_ViewFetch(view,&row);
1892 if (rc != ERROR_SUCCESS)
1897 load_file(package,row);
1898 msiobj_release(&row->hdr);
1900 MSI_ViewClose(view);
1901 msiobj_release(&view->hdr);
1903 return ERROR_SUCCESS;
1908 * I am not doing any of the costing functionality yet.
1909 * Mostly looking at doing the Component and Feature loading
1911 * The native MSI does A LOT of modification to tables here. Mostly adding
1912 * a lot of temporary columns to the Feature and Component tables.
1914 * note: Native msi also tracks the short filename. But I am only going to
1915 * track the long ones. Also looking at this directory table
1916 * it appears that the directory table does not get the parents
1917 * resolved base on property only based on their entries in the
1920 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1925 static const WCHAR Query_all[] =
1926 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1927 '`','F','e','a','t','u','r','e','`',0};
1928 static const WCHAR szCosting[] =
1929 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1930 static const WCHAR szZero[] = { '0', 0 };
1934 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1936 return ERROR_SUCCESS;
1938 MSI_SetPropertyW(package, szCosting, szZero);
1939 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1941 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1942 if (rc != ERROR_SUCCESS)
1944 rc = MSI_ViewExecute(view,0);
1945 if (rc != ERROR_SUCCESS)
1947 MSI_ViewClose(view);
1948 msiobj_release(&view->hdr);
1955 rc = MSI_ViewFetch(view,&row);
1956 if (rc != ERROR_SUCCESS)
1959 load_feature(package,row);
1960 msiobj_release(&row->hdr);
1962 MSI_ViewClose(view);
1963 msiobj_release(&view->hdr);
1965 load_all_files(package);
1967 return ERROR_SUCCESS;
1970 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
1973 LPWSTR *newbuf = NULL;
1974 if (script >= TOTAL_SCRIPTS)
1976 FIXME("Unknown script requested %i\n",script);
1977 return ERROR_FUNCTION_FAILED;
1979 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
1981 count = package->script->ActionCount[script];
1982 package->script->ActionCount[script]++;
1984 newbuf = HeapReAlloc(GetProcessHeap(),0,
1985 package->script->Actions[script],
1986 package->script->ActionCount[script]* sizeof(LPWSTR));
1988 newbuf = HeapAlloc(GetProcessHeap(),0, sizeof(LPWSTR));
1990 newbuf[count] = strdupW(action);
1991 package->script->Actions[script] = newbuf;
1993 return ERROR_SUCCESS;
1996 UINT execute_script(MSIPACKAGE *package, UINT script )
1999 UINT rc = ERROR_SUCCESS;
2001 TRACE("Executing Script %i\n",script);
2003 for (i = 0; i < package->script->ActionCount[script]; i++)
2006 action = package->script->Actions[script][i];
2007 ui_actionstart(package, action);
2008 TRACE("Executing Action (%s)\n",debugstr_w(action));
2009 rc = ACTION_PerformAction(package, action, TRUE);
2010 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
2011 if (rc != ERROR_SUCCESS)
2014 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
2016 package->script->ActionCount[script] = 0;
2017 package->script->Actions[script] = NULL;
2021 static UINT ACTION_FileCost(MSIPACKAGE *package)
2023 return ERROR_SUCCESS;
2027 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
2029 static const WCHAR Query[] =
2030 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2031 '`','D','i','r','e','c', 't','o','r','y','`',' ',
2032 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
2033 ' ','=',' ','\'','%','s','\'',
2035 LPWSTR ptargetdir, targetdir, parent, srcdir;
2036 LPWSTR shortname = NULL;
2037 MSIRECORD * row = 0;
2041 TRACE("Looking for dir %s\n",debugstr_w(dir));
2043 for (i = 0; i < package->loaded_folders; i++)
2045 if (strcmpW(package->folders[i].Directory,dir)==0)
2047 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
2052 TRACE("Working to load %s\n",debugstr_w(dir));
2054 index = package->loaded_folders++;
2055 if (package->loaded_folders==1)
2056 package->folders = HeapAlloc(GetProcessHeap(),0,
2059 package->folders= HeapReAlloc(GetProcessHeap(),0,
2060 package->folders, package->loaded_folders*
2063 memset(&package->folders[index],0,sizeof(MSIFOLDER));
2065 package->folders[index].Directory = strdupW(dir);
2067 row = MSI_QueryGetRecord(package->db, Query, dir);
2071 ptargetdir = targetdir = load_dynamic_stringW(row,3);
2073 /* split src and target dir */
2074 if (strchrW(targetdir,':'))
2076 srcdir=strchrW(targetdir,':');
2083 /* for now only pick long filename versions */
2084 if (strchrW(targetdir,'|'))
2086 shortname = targetdir;
2087 targetdir = strchrW(targetdir,'|');
2091 /* for the sourcedir pick the short filename */
2092 if (srcdir && strchrW(srcdir,'|'))
2094 LPWSTR p = strchrW(srcdir,'|');
2098 /* now check for root dirs */
2099 if (targetdir[0] == '.' && targetdir[1] == 0)
2102 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
2107 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2108 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2109 package->folders[index].TargetDefault = strdupW(targetdir);
2113 package->folders[index].SourceDefault = strdupW(srcdir);
2115 package->folders[index].SourceDefault = strdupW(shortname);
2117 package->folders[index].SourceDefault = strdupW(targetdir);
2118 HeapFree(GetProcessHeap(), 0, ptargetdir);
2119 TRACE(" SourceDefault = %s\n",debugstr_w(package->folders[index].SourceDefault));
2121 parent = load_dynamic_stringW(row,2);
2124 i = load_folder(package,parent);
2125 package->folders[index].ParentIndex = i;
2126 TRACE("Parent is index %i... %s %s\n",
2127 package->folders[index].ParentIndex,
2128 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2129 debugstr_w(parent));
2132 package->folders[index].ParentIndex = -2;
2133 HeapFree(GetProcessHeap(), 0, parent);
2135 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2137 msiobj_release(&row->hdr);
2138 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2143 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
2144 BOOL set_prop, MSIFOLDER **folder)
2147 LPWSTR p, path = NULL;
2149 TRACE("Working to resolve %s\n",debugstr_w(name));
2151 /* special resolving for Target and Source root dir */
2152 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2156 path = load_dynamic_property(package,cszTargetDir,NULL);
2159 path = load_dynamic_property(package,cszRootDrive,NULL);
2161 MSI_SetPropertyW(package,cszTargetDir,path);
2165 for (i = 0; i < package->loaded_folders; i++)
2167 if (strcmpW(package->folders[i].Directory,name)==0)
2170 *folder = &(package->folders[i]);
2176 path = load_dynamic_property(package,cszSourceDir,NULL);
2179 path = load_dynamic_property(package,cszDatabase,NULL);
2182 p = strrchrW(path,'\\');
2189 for (i = 0; i < package->loaded_folders; i++)
2191 if (strcmpW(package->folders[i].Directory,name)==0)
2194 *folder = &(package->folders[i]);
2200 for (i = 0; i < package->loaded_folders; i++)
2202 if (strcmpW(package->folders[i].Directory,name)==0)
2206 if (i >= package->loaded_folders)
2210 *folder = &(package->folders[i]);
2212 if (!source && package->folders[i].ResolvedTarget)
2214 path = strdupW(package->folders[i].ResolvedTarget);
2215 TRACE(" already resolved to %s\n",debugstr_w(path));
2218 else if (source && package->folders[i].ResolvedSource)
2220 path = strdupW(package->folders[i].ResolvedSource);
2221 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
2224 else if (!source && package->folders[i].Property)
2226 path = build_directory_name(2, package->folders[i].Property, NULL);
2228 TRACE(" internally set to %s\n",debugstr_w(path));
2230 MSI_SetPropertyW(package,name,path);
2234 if (package->folders[i].ParentIndex >= 0)
2236 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2238 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2240 p = resolve_folder(package, parent, source, set_prop, NULL);
2243 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2244 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2245 package->folders[i].ResolvedTarget = strdupW(path);
2246 TRACE(" resolved into %s\n",debugstr_w(path));
2248 MSI_SetPropertyW(package,name,path);
2252 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2253 TRACE(" (source)resolved into %s\n",debugstr_w(path));
2254 package->folders[i].ResolvedSource = strdupW(path);
2256 HeapFree(GetProcessHeap(),0,p);
2261 /* scan for and update current install states */
2262 void ACTION_UpdateInstallStates(MSIPACKAGE *package)
2267 productcode = load_dynamic_property(package,szProductCode,NULL);
2269 for (i = 0; i < package->loaded_components; i++)
2272 res = MsiGetComponentPathW(productcode,
2273 package->components[i].ComponentId , NULL, NULL);
2275 res = INSTALLSTATE_ABSENT;
2276 package->components[i].Installed = res;
2279 for (i = 0; i < package->loaded_features; i++)
2281 INSTALLSTATE res = -10;
2283 for (j = 0; j < package->features[i].ComponentCount; j++)
2285 MSICOMPONENT* component = &package->components[package->features[i].
2288 res = component->Installed;
2291 if (res == component->Installed)
2294 if (res != component->Installed)
2295 res = INSTALLSTATE_INCOMPLETE;
2301 /* update compoennt state based on a feature change */
2302 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2305 INSTALLSTATE newstate;
2306 MSIFEATURE *feature;
2308 i = get_loaded_feature(package,szFeature);
2312 feature = &package->features[i];
2313 newstate = feature->ActionRequest;
2315 for( i = 0; i < feature->ComponentCount; i++)
2317 MSICOMPONENT* component = &package->components[feature->Components[i]];
2319 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
2320 newstate, debugstr_w(component->Component), component->Installed,
2321 component->Action, component->ActionRequest);
2323 if (!component->Enabled)
2327 if (newstate == INSTALLSTATE_LOCAL)
2329 component->ActionRequest = INSTALLSTATE_LOCAL;
2330 component->Action = INSTALLSTATE_LOCAL;
2336 component->ActionRequest = newstate;
2337 component->Action = newstate;
2339 /*if any other feature wants is local we need to set it local*/
2341 j < package->loaded_features &&
2342 component->ActionRequest != INSTALLSTATE_LOCAL;
2345 for (k = 0; k < package->features[j].ComponentCount; k++)
2346 if ( package->features[j].Components[k] ==
2347 feature->Components[i] )
2349 if (package->features[j].ActionRequest ==
2352 TRACE("Saved by %s\n", debugstr_w(package->features[j].Feature));
2353 component->ActionRequest = INSTALLSTATE_LOCAL;
2354 component->Action = INSTALLSTATE_LOCAL;
2361 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
2362 newstate, debugstr_w(component->Component), component->Installed,
2363 component->Action, component->ActionRequest);
2367 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
2370 static const WCHAR all[]={'A','L','L',0};
2371 LPWSTR override = NULL;
2375 override = load_dynamic_property(package, property, NULL);
2379 for(i = 0; i < package->loaded_features; i++)
2381 if (strcmpiW(override,all)==0)
2383 package->features[i].ActionRequest= state;
2384 package->features[i].Action = state;
2388 LPWSTR ptr = override;
2389 LPWSTR ptr2 = strchrW(override,',');
2394 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2396 strcmpW(ptr,package->features[i].Feature)==0))
2398 package->features[i].ActionRequest= state;
2399 package->features[i].Action = state;
2405 ptr2 = strchrW(ptr,',');
2412 HeapFree(GetProcessHeap(),0,override);
2418 static UINT SetFeatureStates(MSIPACKAGE *package)
2424 static const WCHAR szlevel[] =
2425 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2426 static const WCHAR szAddLocal[] =
2427 {'A','D','D','L','O','C','A','L',0};
2428 static const WCHAR szRemove[] =
2429 {'R','E','M','O','V','E',0};
2430 BOOL override = FALSE;
2432 /* I do not know if this is where it should happen.. but */
2434 TRACE("Checking Install Level\n");
2436 level = load_dynamic_property(package,szlevel,NULL);
2439 install_level = atoiW(level);
2440 HeapFree(GetProcessHeap(), 0, level);
2445 /* ok hereis the _real_ rub
2446 * all these activation/deactivation things happen in order and things
2447 * later on the list override things earlier on the list.
2448 * 1) INSTALLLEVEL processing
2458 * 11) FILEADDDEFAULT
2459 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2460 * ignored for all the features. seems strange, especially since it is not
2461 * documented anywhere, but it is how it works.
2463 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2464 * REMOVE are the big ones, since we don't handle administrative installs
2467 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
2468 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
2472 for(i = 0; i < package->loaded_features; i++)
2474 BOOL feature_state = ((package->features[i].Level > 0) &&
2475 (package->features[i].Level <= install_level));
2477 if ((feature_state) &&
2478 (package->features[i].Action == INSTALLSTATE_UNKNOWN))
2480 if (package->features[i].Attributes &
2481 msidbFeatureAttributesFavorSource)
2483 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
2484 package->features[i].Action = INSTALLSTATE_SOURCE;
2486 else if (package->features[i].Attributes &
2487 msidbFeatureAttributesFavorAdvertise)
2489 package->features[i].ActionRequest =INSTALLSTATE_ADVERTISED;
2490 package->features[i].Action =INSTALLSTATE_ADVERTISED;
2494 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
2495 package->features[i].Action = INSTALLSTATE_LOCAL;
2502 * now we want to enable or disable components base on feature
2505 for(i = 0; i < package->loaded_features; i++)
2507 MSIFEATURE* feature = &package->features[i];
2508 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2509 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2510 feature->ActionRequest);
2512 for( j = 0; j < feature->ComponentCount; j++)
2514 MSICOMPONENT* component = &package->components[
2515 feature->Components[j]];
2517 if (!component->Enabled)
2519 component->Action = INSTALLSTATE_UNKNOWN;
2520 component->ActionRequest = INSTALLSTATE_UNKNOWN;
2524 if (feature->Action == INSTALLSTATE_LOCAL)
2526 component->Action = INSTALLSTATE_LOCAL;
2527 component->ActionRequest = INSTALLSTATE_LOCAL;
2529 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
2531 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2532 (component->Action == INSTALLSTATE_ABSENT) ||
2533 (component->Action == INSTALLSTATE_ADVERTISED))
2536 component->Action = INSTALLSTATE_SOURCE;
2537 component->ActionRequest = INSTALLSTATE_SOURCE;
2540 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
2542 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2543 (component->Action == INSTALLSTATE_ABSENT))
2546 component->Action = INSTALLSTATE_ADVERTISED;
2547 component->ActionRequest = INSTALLSTATE_ADVERTISED;
2550 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
2552 if (component->Action == INSTALLSTATE_UNKNOWN)
2554 component->Action = INSTALLSTATE_ABSENT;
2555 component->ActionRequest = INSTALLSTATE_ABSENT;
2562 for(i = 0; i < package->loaded_components; i++)
2564 MSICOMPONENT* component= &package->components[i];
2566 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2567 debugstr_w(component->Component), component->Installed,
2568 component->Action, component->ActionRequest);
2572 return ERROR_SUCCESS;
2576 * A lot is done in this function aside from just the costing.
2577 * The costing needs to be implemented at some point but for now I am going
2578 * to focus on the directory building
2581 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2583 static const WCHAR ExecSeqQuery[] =
2584 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2585 '`','D','i','r','e','c','t','o','r','y','`',0};
2586 static const WCHAR ConditionQuery[] =
2587 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2588 '`','C','o','n','d','i','t','i','o','n','`',0};
2589 static const WCHAR szCosting[] =
2590 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2591 static const WCHAR szlevel[] =
2592 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2593 static const WCHAR szOne[] = { '1', 0 };
2601 MSI_GetPropertyW(package, szCosting, buffer, &sz);
2603 return ERROR_SUCCESS;
2605 TRACE("Building Directory properties\n");
2607 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2608 if (rc == ERROR_SUCCESS)
2610 rc = MSI_ViewExecute(view, 0);
2611 if (rc != ERROR_SUCCESS)
2613 MSI_ViewClose(view);
2614 msiobj_release(&view->hdr);
2622 MSIRECORD * row = 0;
2625 rc = MSI_ViewFetch(view,&row);
2626 if (rc != ERROR_SUCCESS)
2633 MSI_RecordGetStringW(row,1,name,&sz);
2635 /* This helper function now does ALL the work */
2636 TRACE("Dir %s ...\n",debugstr_w(name));
2637 load_folder(package,name);
2638 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2639 TRACE("resolves to %s\n",debugstr_w(path));
2640 HeapFree( GetProcessHeap(), 0, path);
2642 msiobj_release(&row->hdr);
2644 MSI_ViewClose(view);
2645 msiobj_release(&view->hdr);
2648 TRACE("File calculations %i files\n",package->loaded_files);
2650 for (i = 0; i < package->loaded_files; i++)
2652 MSICOMPONENT* comp = NULL;
2653 MSIFILE* file= NULL;
2655 file = &package->files[i];
2656 if (file->ComponentIndex >= 0)
2657 comp = &package->components[file->ComponentIndex];
2659 if (file->Temporary == TRUE)
2666 /* calculate target */
2667 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2669 HeapFree(GetProcessHeap(),0,file->TargetPath);
2671 TRACE("file %s is named %s\n",
2672 debugstr_w(file->File),debugstr_w(file->FileName));
2674 file->TargetPath = build_directory_name(2, p, file->FileName);
2676 HeapFree(GetProcessHeap(),0,p);
2678 TRACE("file %s resolves to %s\n",
2679 debugstr_w(file->File),debugstr_w(file->TargetPath));
2681 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2684 comp->Cost += file->FileSize;
2694 static const WCHAR name[] =
2696 static const WCHAR name_fmt[] =
2697 {'%','u','.','%','u','.','%','u','.','%','u',0};
2698 WCHAR filever[0x100];
2699 VS_FIXEDFILEINFO *lpVer;
2701 TRACE("Version comparison.. \n");
2702 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2703 version = HeapAlloc(GetProcessHeap(),0,versize);
2704 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2706 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2708 sprintfW(filever,name_fmt,
2709 HIWORD(lpVer->dwFileVersionMS),
2710 LOWORD(lpVer->dwFileVersionMS),
2711 HIWORD(lpVer->dwFileVersionLS),
2712 LOWORD(lpVer->dwFileVersionLS));
2714 TRACE("new %s old %s\n", debugstr_w(file->Version),
2715 debugstr_w(filever));
2716 if (strcmpiW(filever,file->Version)<0)
2719 FIXME("cost should be diff in size\n");
2720 comp->Cost += file->FileSize;
2724 HeapFree(GetProcessHeap(),0,version);
2732 TRACE("Evaluating Condition Table\n");
2734 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2735 if (rc == ERROR_SUCCESS)
2737 rc = MSI_ViewExecute(view, 0);
2738 if (rc != ERROR_SUCCESS)
2740 MSI_ViewClose(view);
2741 msiobj_release(&view->hdr);
2747 WCHAR Feature[0x100];
2748 MSIRECORD * row = 0;
2752 rc = MSI_ViewFetch(view,&row);
2754 if (rc != ERROR_SUCCESS)
2761 MSI_RecordGetStringW(row,1,Feature,&sz);
2763 feature_index = get_loaded_feature(package,Feature);
2764 if (feature_index < 0)
2765 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2769 Condition = load_dynamic_stringW(row,3);
2771 if (MSI_EvaluateConditionW(package,Condition) ==
2774 int level = MSI_RecordGetInteger(row,2);
2775 TRACE("Reseting feature %s to level %i\n",
2776 debugstr_w(Feature), level);
2777 package->features[feature_index].Level = level;
2779 HeapFree(GetProcessHeap(),0,Condition);
2782 msiobj_release(&row->hdr);
2784 MSI_ViewClose(view);
2785 msiobj_release(&view->hdr);
2788 TRACE("Enabling or Disabling Components\n");
2789 for (i = 0; i < package->loaded_components; i++)
2791 if (package->components[i].Condition[0])
2793 if (MSI_EvaluateConditionW(package,
2794 package->components[i].Condition) == MSICONDITION_FALSE)
2796 TRACE("Disabling component %s\n",
2797 debugstr_w(package->components[i].Component));
2798 package->components[i].Enabled = FALSE;
2803 MSI_SetPropertyW(package,szCosting,szOne);
2804 /* set default run level if not set */
2805 level = load_dynamic_property(package,szlevel,NULL);
2807 MSI_SetPropertyW(package,szlevel, szOne);
2809 HeapFree(GetProcessHeap(),0,level);
2811 ACTION_UpdateInstallStates(package);
2813 return SetFeatureStates(package);
2817 * This is a helper function for handling embedded cabinet media
2819 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2827 WCHAR tmp[MAX_PATH];
2829 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2830 if (rc != ERROR_SUCCESS)
2834 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2835 GetTempPathW(MAX_PATH,tmp);
2837 GetTempFileNameW(tmp,stream_name,0,source);
2839 track_tempfile(package,strrchrW(source,'\\'), source);
2840 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2841 FILE_ATTRIBUTE_NORMAL, NULL);
2843 if (the_file == INVALID_HANDLE_VALUE)
2845 ERR("Unable to create file %s\n",debugstr_w(source));
2846 rc = ERROR_FUNCTION_FAILED;
2850 WriteFile(the_file,data,size,&write,NULL);
2851 CloseHandle(the_file);
2852 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2854 HeapFree(GetProcessHeap(),0,data);
2859 /* Support functions for FDI functions */
2862 MSIPACKAGE* package;
2867 static void * cabinet_alloc(ULONG cb)
2869 return HeapAlloc(GetProcessHeap(), 0, cb);
2872 static void cabinet_free(void *pv)
2874 HeapFree(GetProcessHeap(), 0, pv);
2877 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2880 DWORD dwShareMode = 0;
2881 DWORD dwCreateDisposition = OPEN_EXISTING;
2882 switch (oflag & _O_ACCMODE)
2885 dwAccess = GENERIC_READ;
2886 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2889 dwAccess = GENERIC_WRITE;
2890 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2893 dwAccess = GENERIC_READ | GENERIC_WRITE;
2894 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2897 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2898 dwCreateDisposition = CREATE_NEW;
2899 else if (oflag & _O_CREAT)
2900 dwCreateDisposition = CREATE_ALWAYS;
2901 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
2902 dwCreateDisposition, 0, NULL);
2905 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2908 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2913 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2916 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2921 static int cabinet_close(INT_PTR hf)
2923 return CloseHandle((HANDLE)hf) ? 0 : -1;
2926 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2928 /* flags are compatible and so are passed straight through */
2929 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2932 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2934 /* FIXME: try to do more processing in this function */
2937 case fdintCOPY_FILE:
2939 CabData *data = (CabData*) pfdin->pv;
2940 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2945 LPWSTR tracknametmp;
2946 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2948 if (data->file_name && lstrcmpiA(data->file_name,pfdin->psz1))
2951 file = cabinet_alloc((len+1)*sizeof(char));
2952 strcpy(file, data->cab_path);
2953 strcat(file, pfdin->psz1);
2955 TRACE("file: %s\n", debugstr_a(file));
2957 /* track this file so it can be deleted if not installed */
2958 trackpath=strdupAtoW(file);
2959 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2960 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2961 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2963 strcpyW(trackname,tmpprefix);
2964 strcatW(trackname,tracknametmp);
2966 track_tempfile(data->package, trackname, trackpath);
2968 HeapFree(GetProcessHeap(),0,trackpath);
2969 HeapFree(GetProcessHeap(),0,trackname);
2970 HeapFree(GetProcessHeap(),0,tracknametmp);
2972 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2974 case fdintCLOSE_FILE_INFO:
2978 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2980 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2982 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2985 cabinet_close(pfdin->hf);
2993 /***********************************************************************
2994 * extract_cabinet_file
2996 * Extract files from a cab file.
2998 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2999 const WCHAR* path, const WCHAR* file)
3009 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
3010 debugstr_w(file), debugstr_w(path));
3012 hfdi = FDICreate(cabinet_alloc,
3023 ERR("FDICreate failed\n");
3027 if (!(cabinet = strdupWtoA( source )))
3032 if (!(cab_path = strdupWtoA( path )))
3035 HeapFree(GetProcessHeap(), 0, cabinet);
3039 data.package = package;
3040 data.cab_path = cab_path;
3042 file_name = strdupWtoA(file);
3045 data.file_name = file_name;
3047 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
3050 ERR("FDICopy failed\n");
3054 HeapFree(GetProcessHeap(), 0, cabinet);
3055 HeapFree(GetProcessHeap(), 0, cab_path);
3056 HeapFree(GetProcessHeap(), 0, file_name);
3061 static UINT ready_media_for_file(MSIPACKAGE *package, WCHAR* path,
3064 UINT rc = ERROR_SUCCESS;
3065 MSIRECORD * row = 0;
3066 static WCHAR source[MAX_PATH];
3067 static const WCHAR ExecSeqQuery[] =
3068 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3069 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3070 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
3071 ' ','%', 'i',' ','O','R','D','E','R',' ','B','Y',' ',
3072 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',0};
3076 static UINT last_sequence = 0;
3078 if (file->Attributes & msidbFileAttributesNoncompressed)
3080 TRACE("Uncompressed File, no media to ready.\n");
3081 return ERROR_SUCCESS;
3084 if (file->Sequence <= last_sequence)
3086 TRACE("Media already ready (%u, %u)\n",file->Sequence,last_sequence);
3087 /*extract_a_cabinet_file(package, source,path,file->File); */
3088 return ERROR_SUCCESS;
3091 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, file->Sequence);
3093 return ERROR_FUNCTION_FAILED;
3095 seq = MSI_RecordGetInteger(row,2);
3096 last_sequence = seq;
3098 if (!MSI_RecordIsNull(row,4))
3101 MSI_RecordGetStringW(row,4,cab,&sz);
3102 TRACE("Source is CAB %s\n",debugstr_w(cab));
3103 /* the stream does not contain the # character */
3106 writeout_cabinet_stream(package,&cab[1],source);
3107 strcpyW(path,source);
3108 *(strrchrW(path,'\\')+1)=0;
3113 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
3115 ERR("No Source dir defined \n");
3116 rc = ERROR_FUNCTION_FAILED;
3120 strcpyW(path,source);
3121 strcatW(source,cab);
3122 /* extract the cab file into a folder in the temp folder */
3124 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
3126 GetTempPathW(MAX_PATH,path);
3129 rc = !extract_a_cabinet_file(package, source,path,NULL);
3134 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
3135 strcpyW(path,source);
3137 msiobj_release(&row->hdr);
3141 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
3143 UINT rc = ERROR_SUCCESS;
3145 LPWSTR install_path;
3147 install_path = resolve_folder(package, package->components[component].Directory,
3148 FALSE, FALSE, &folder);
3150 return ERROR_FUNCTION_FAILED;
3152 /* create the path */
3153 if (folder->State == 0)
3155 create_full_pathW(install_path);
3158 HeapFree(GetProcessHeap(), 0, install_path);
3163 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3165 UINT rc = ERROR_SUCCESS;
3168 WCHAR uipath[MAX_PATH];
3171 return ERROR_INVALID_HANDLE;
3173 /* increment progress bar each time action data is sent */
3174 ui_progress(package,1,1,0,0);
3176 for (index = 0; index < package->loaded_files; index++)
3178 WCHAR path_to_source[MAX_PATH];
3181 file = &package->files[index];
3183 if (file->Temporary)
3187 if (!ACTION_VerifyComponentForAction(package, file->ComponentIndex,
3188 INSTALLSTATE_LOCAL))
3190 ui_progress(package,2,file->FileSize,0,0);
3191 TRACE("File %s is not scheduled for install\n",
3192 debugstr_w(file->File));
3197 if ((file->State == 1) || (file->State == 2))
3200 MSICOMPONENT* comp = NULL;
3202 TRACE("Installing %s\n",debugstr_w(file->File));
3203 rc = ready_media_for_file(package, path_to_source, file);
3206 * our file table could change here because a new temp file
3207 * may have been created
3209 file = &package->files[index];
3210 if (rc != ERROR_SUCCESS)
3212 ERR("Unable to ready media\n");
3213 rc = ERROR_FUNCTION_FAILED;
3217 create_component_directory( package, file->ComponentIndex);
3219 /* recalculate file paths because things may have changed */
3221 if (file->ComponentIndex >= 0)
3222 comp = &package->components[file->ComponentIndex];
3224 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3225 HeapFree(GetProcessHeap(),0,file->TargetPath);
3227 file->TargetPath = build_directory_name(2, p, file->FileName);
3228 HeapFree(GetProcessHeap(),0,p);
3230 if (file->Attributes & msidbFileAttributesNoncompressed)
3232 p = resolve_folder(package, comp->Directory, TRUE, FALSE, NULL);
3233 file->SourcePath = build_directory_name(2, p, file->ShortName);
3234 HeapFree(GetProcessHeap(),0,p);
3237 file->SourcePath = build_directory_name(2, path_to_source,
3241 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3242 debugstr_w(file->TargetPath));
3245 uirow=MSI_CreateRecord(9);
3246 MSI_RecordSetStringW(uirow,1,file->File);
3247 strcpyW(uipath,file->TargetPath);
3248 *(strrchrW(uipath,'\\')+1)=0;
3249 MSI_RecordSetStringW(uirow,9,uipath);
3250 MSI_RecordSetInteger(uirow,6,file->FileSize);
3251 ui_actiondata(package,szInstallFiles,uirow);
3252 msiobj_release( &uirow->hdr );
3253 ui_progress(package,2,file->FileSize,0,0);
3256 if (file->Attributes & msidbFileAttributesNoncompressed)
3257 rc = CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3259 rc = MoveFileW(file->SourcePath, file->TargetPath);
3263 rc = GetLastError();
3264 ERR("Unable to move/copy file (%s -> %s) (error %d)\n",
3265 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3267 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3269 if (!CopyFileW(file->SourcePath,file->TargetPath,FALSE))
3270 ERR("Unable to copy file (%s -> %s) (error %ld)\n",
3271 debugstr_w(file->SourcePath),
3272 debugstr_w(file->TargetPath), GetLastError());
3273 if (!(file->Attributes & msidbFileAttributesNoncompressed))
3274 DeleteFileW(file->SourcePath);
3277 else if (rc == ERROR_FILE_NOT_FOUND)
3279 ERR("Source File Not Found! Continuing\n");
3282 else if (file->Attributes & msidbFileAttributesVital)
3284 ERR("Ignoring Error and continuing (nonvital file)...\n");
3299 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3300 LPWSTR* file_source)
3305 return ERROR_INVALID_HANDLE;
3307 for (index = 0; index < package->loaded_files; index ++)
3309 if (strcmpW(file_key,package->files[index].File)==0)
3311 if (package->files[index].State >= 2)
3313 *file_source = strdupW(package->files[index].TargetPath);
3314 return ERROR_SUCCESS;
3317 return ERROR_FILE_NOT_FOUND;
3321 return ERROR_FUNCTION_FAILED;
3324 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3328 MSIRECORD * row = 0;
3329 static const WCHAR ExecSeqQuery[] =
3330 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3331 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
3334 return ERROR_INVALID_HANDLE;
3336 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3337 if (rc != ERROR_SUCCESS)
3338 return ERROR_SUCCESS;
3340 rc = MSI_ViewExecute(view, 0);
3341 if (rc != ERROR_SUCCESS)
3343 MSI_ViewClose(view);
3344 msiobj_release(&view->hdr);
3350 WCHAR file_key[0x100];
3351 WCHAR *file_source = NULL;
3352 WCHAR dest_name[0x100];
3353 LPWSTR dest_path, dest;
3354 WCHAR component[0x100];
3355 INT component_index;
3359 rc = MSI_ViewFetch(view,&row);
3360 if (rc != ERROR_SUCCESS)
3367 rc = MSI_RecordGetStringW(row,2,component,&sz);
3368 if (rc != ERROR_SUCCESS)
3370 ERR("Unable to get component\n");
3371 msiobj_release(&row->hdr);
3375 component_index = get_loaded_component(package,component);
3377 if (!ACTION_VerifyComponentForAction(package, component_index,
3378 INSTALLSTATE_LOCAL))
3380 TRACE("Skipping copy due to disabled component\n");
3382 /* the action taken was the same as the current install state */
3383 package->components[component_index].Action =
3384 package->components[component_index].Installed;
3386 msiobj_release(&row->hdr);
3390 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3393 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3394 if (rc != ERROR_SUCCESS)
3396 ERR("Unable to get file key\n");
3397 msiobj_release(&row->hdr);
3401 rc = get_file_target(package,file_key,&file_source);
3403 if (rc != ERROR_SUCCESS)
3405 ERR("Original file unknown %s\n",debugstr_w(file_key));
3406 msiobj_release(&row->hdr);
3407 HeapFree(GetProcessHeap(),0,file_source);
3411 if (MSI_RecordIsNull(row,4))
3413 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3418 MSI_RecordGetStringW(row,4,dest_name,&sz);
3419 reduce_to_longfilename(dest_name);
3422 if (MSI_RecordIsNull(row,5))
3425 dest_path = strdupW(file_source);
3426 p = strrchrW(dest_path,'\\');
3432 WCHAR destkey[0x100];
3434 MSI_RecordGetStringW(row,5,destkey,&sz);
3436 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3439 ERR("Unable to get destination folder\n");
3440 msiobj_release(&row->hdr);
3441 HeapFree(GetProcessHeap(),0,file_source);
3446 dest = build_directory_name(2, dest_path, dest_name);
3448 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3451 if (strcmpW(file_source,dest))
3452 rc = !CopyFileW(file_source,dest,TRUE);
3456 if (rc != ERROR_SUCCESS)
3457 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
3459 FIXME("We should track these duplicate files as well\n");
3461 msiobj_release(&row->hdr);
3462 HeapFree(GetProcessHeap(),0,dest_path);
3463 HeapFree(GetProcessHeap(),0,dest);
3464 HeapFree(GetProcessHeap(),0,file_source);
3466 MSI_ViewClose(view);
3467 msiobj_release(&view->hdr);
3472 /* OK this value is "interpreted" and then formatted based on the
3473 first few characters */
3474 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3478 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3484 LPWSTR deformated = NULL;
3487 deformat_string(package, &value[2], &deformated);
3489 /* binary value type */
3493 *size = (strlenW(ptr)/2)+1;
3495 *size = strlenW(ptr)/2;
3497 data = HeapAlloc(GetProcessHeap(),0,*size);
3503 /* if uneven pad with a zero in front */
3509 data[count] = (BYTE)strtol(byte,NULL,0);
3511 TRACE("Uneven byte count\n");
3519 data[count] = (BYTE)strtol(byte,NULL,0);
3522 HeapFree(GetProcessHeap(),0,deformated);
3524 TRACE("Data %li bytes(%i)\n",*size,count);
3531 deformat_string(package, &value[1], &deformated);
3534 *size = sizeof(DWORD);
3535 data = HeapAlloc(GetProcessHeap(),0,*size);
3541 if ( (*p < '0') || (*p > '9') )
3547 if (deformated[0] == '-')
3550 TRACE("DWORD %li\n",*(LPDWORD)data);
3552 HeapFree(GetProcessHeap(),0,deformated);
3557 static const WCHAR szMulti[] = {'[','~',']',0};
3566 *type=REG_EXPAND_SZ;
3574 if (strstrW(value,szMulti))
3575 *type = REG_MULTI_SZ;
3577 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3582 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3586 MSIRECORD * row = 0;
3587 static const WCHAR ExecSeqQuery[] =
3588 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3589 '`','R','e','g','i','s','t','r','y','`',0 };
3592 return ERROR_INVALID_HANDLE;
3594 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3595 if (rc != ERROR_SUCCESS)
3596 return ERROR_SUCCESS;
3598 rc = MSI_ViewExecute(view, 0);
3599 if (rc != ERROR_SUCCESS)
3601 MSI_ViewClose(view);
3602 msiobj_release(&view->hdr);
3606 /* increment progress bar each time action data is sent */
3607 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3611 static const WCHAR szHCR[] =
3612 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3613 'R','O','O','T','\\',0};
3614 static const WCHAR szHCU[] =
3615 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3616 'U','S','E','R','\\',0};
3617 static const WCHAR szHLM[] =
3618 {'H','K','E','Y','_','L','O','C','A','L','_',
3619 'M','A','C','H','I','N','E','\\',0};
3620 static const WCHAR szHU[] =
3621 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3623 LPSTR value_data = NULL;
3624 HKEY root_key, hkey;
3626 LPWSTR value, key, name, component, deformated;
3628 INT component_index;
3632 BOOL check_first = FALSE;
3634 rc = MSI_ViewFetch(view,&row);
3635 if (rc != ERROR_SUCCESS)
3640 ui_progress(package,2,0,0,0);
3647 component = load_dynamic_stringW(row, 6);
3648 component_index = get_loaded_component(package,component);
3650 if (!ACTION_VerifyComponentForAction(package, component_index,
3651 INSTALLSTATE_LOCAL))
3653 TRACE("Skipping write due to disabled component\n");
3654 msiobj_release(&row->hdr);
3656 package->components[component_index].Action =
3657 package->components[component_index].Installed;
3662 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3664 name = load_dynamic_stringW(row, 4);
3665 if( MSI_RecordIsNull(row,5) && name )
3667 /* null values can have special meanings */
3668 if (name[0]=='-' && name[1] == 0)
3670 msiobj_release(&row->hdr);
3673 else if ((name[0]=='+' && name[1] == 0) ||
3674 (name[0] == '*' && name[1] == 0))
3676 HeapFree(GetProcessHeap(),0,name);
3682 root = MSI_RecordGetInteger(row,2);
3683 key = load_dynamic_stringW(row, 3);
3686 /* get the root key */
3689 case 0: root_key = HKEY_CLASSES_ROOT;
3692 case 1: root_key = HKEY_CURRENT_USER;
3695 case 2: root_key = HKEY_LOCAL_MACHINE;
3698 case 3: root_key = HKEY_USERS;
3702 ERR("Unknown root %i\n",root);
3709 msiobj_release(&row->hdr);
3713 deformat_string(package, key , &deformated);
3714 size = strlenW(deformated) + strlenW(szRoot) + 1;
3715 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3716 strcpyW(uikey,szRoot);
3717 strcatW(uikey,deformated);
3719 if (RegCreateKeyW( root_key, deformated, &hkey))
3721 ERR("Could not create key %s\n",debugstr_w(deformated));
3722 msiobj_release(&row->hdr);
3723 HeapFree(GetProcessHeap(),0,deformated);
3726 HeapFree(GetProcessHeap(),0,deformated);
3728 value = load_dynamic_stringW(row,5);
3730 value_data = parse_value(package, value, &type, &size);
3733 static const WCHAR szEmpty[] = {0};
3734 value_data = (LPSTR)strdupW(szEmpty);
3739 deformat_string(package, name, &deformated);
3741 /* get the double nulls to terminate SZ_MULTI */
3742 if (type == REG_MULTI_SZ)
3743 size +=sizeof(WCHAR);
3747 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
3749 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3754 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
3755 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3757 TRACE("value %s of %s checked already exists\n",
3758 debugstr_w(deformated), debugstr_w(uikey));
3762 TRACE("Checked and setting value %s of %s\n",
3763 debugstr_w(deformated), debugstr_w(uikey));
3764 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3768 uirow = MSI_CreateRecord(3);
3769 MSI_RecordSetStringW(uirow,2,deformated);
3770 MSI_RecordSetStringW(uirow,1,uikey);
3773 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3775 MSI_RecordSetStringW(uirow,3,value);
3777 ui_actiondata(package,szWriteRegistryValues,uirow);
3778 msiobj_release( &uirow->hdr );
3780 HeapFree(GetProcessHeap(),0,value_data);
3781 HeapFree(GetProcessHeap(),0,value);
3782 HeapFree(GetProcessHeap(),0,deformated);
3784 msiobj_release(&row->hdr);
3787 HeapFree(GetProcessHeap(),0,uikey);
3788 HeapFree(GetProcessHeap(),0,key);
3789 HeapFree(GetProcessHeap(),0,name);
3790 HeapFree(GetProcessHeap(),0,component);
3792 MSI_ViewClose(view);
3793 msiobj_release(&view->hdr);
3797 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3799 package->script->CurrentlyScripting = TRUE;
3801 return ERROR_SUCCESS;
3805 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3809 static const WCHAR q1[]=
3810 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3811 '`','R','e','g','i','s','t','r','y','`',0};
3814 MSIRECORD * row = 0;
3817 TRACE(" InstallValidate \n");
3819 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3820 if (rc != ERROR_SUCCESS)
3821 return ERROR_SUCCESS;
3823 rc = MSI_ViewExecute(view, 0);
3824 if (rc != ERROR_SUCCESS)
3826 MSI_ViewClose(view);
3827 msiobj_release(&view->hdr);
3832 rc = MSI_ViewFetch(view,&row);
3833 if (rc != ERROR_SUCCESS)
3840 msiobj_release(&row->hdr);
3842 MSI_ViewClose(view);
3843 msiobj_release(&view->hdr);
3845 total = total + progress * REG_PROGRESS_VALUE;
3846 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3847 for (i=0; i < package->loaded_files; i++)
3848 total += package->files[i].FileSize;
3849 ui_progress(package,0,total,0,0);
3851 for(i = 0; i < package->loaded_features; i++)
3853 MSIFEATURE* feature = &package->features[i];
3854 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
3855 debugstr_w(feature->Feature), feature->Installed, feature->Action,
3856 feature->ActionRequest);
3859 return ERROR_SUCCESS;
3862 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3865 MSIQUERY * view = NULL;
3866 MSIRECORD * row = 0;
3867 static const WCHAR ExecSeqQuery[] =
3868 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3869 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
3870 static const WCHAR title[]=
3871 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3873 TRACE("Checking launch conditions\n");
3875 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3876 if (rc != ERROR_SUCCESS)
3877 return ERROR_SUCCESS;
3879 rc = MSI_ViewExecute(view, 0);
3880 if (rc != ERROR_SUCCESS)
3882 MSI_ViewClose(view);
3883 msiobj_release(&view->hdr);
3888 while (rc == ERROR_SUCCESS)
3891 LPWSTR message = NULL;
3893 rc = MSI_ViewFetch(view,&row);
3894 if (rc != ERROR_SUCCESS)
3900 cond = load_dynamic_stringW(row,1);
3902 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3905 message = load_dynamic_stringW(row,2);
3906 deformat_string(package,message,&deformated);
3907 MessageBoxW(NULL,deformated,title,MB_OK);
3908 HeapFree(GetProcessHeap(),0,message);
3909 HeapFree(GetProcessHeap(),0,deformated);
3910 rc = ERROR_FUNCTION_FAILED;
3912 HeapFree(GetProcessHeap(),0,cond);
3913 msiobj_release(&row->hdr);
3915 MSI_ViewClose(view);
3916 msiobj_release(&view->hdr);
3920 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3923 MSICOMPONENT* cmp = &package->components[component_index];
3925 if (cmp->KeyPath[0]==0)
3927 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3930 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
3932 MSIRECORD * row = 0;
3934 LPWSTR key,deformated,buffer,name,deformated_name;
3935 static const WCHAR ExecSeqQuery[] =
3936 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3937 '`','R','e','g','i','s','t','r','y','`',' ',
3938 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
3939 ' ','=',' ' ,'\'','%','s','\'',0 };
3940 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
3941 static const WCHAR fmt2[]=
3942 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3944 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
3948 root = MSI_RecordGetInteger(row,2);
3949 key = load_dynamic_stringW(row, 3);
3950 name = load_dynamic_stringW(row, 4);
3951 deformat_string(package, key , &deformated);
3952 deformat_string(package, name, &deformated_name);
3954 len = strlenW(deformated) + 6;
3955 if (deformated_name)
3956 len+=strlenW(deformated_name);
3958 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3960 if (deformated_name)
3961 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3963 sprintfW(buffer,fmt,root,deformated);
3965 HeapFree(GetProcessHeap(),0,key);
3966 HeapFree(GetProcessHeap(),0,deformated);
3967 HeapFree(GetProcessHeap(),0,name);
3968 HeapFree(GetProcessHeap(),0,deformated_name);
3969 msiobj_release(&row->hdr);
3973 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
3975 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3981 j = get_loaded_file(package,cmp->KeyPath);
3985 LPWSTR p = strdupW(package->files[j].TargetPath);
3992 static HKEY openSharedDLLsKey()
3995 static const WCHAR path[] =
3996 {'S','o','f','t','w','a','r','e','\\',
3997 'M','i','c','r','o','s','o','f','t','\\',
3998 'W','i','n','d','o','w','s','\\',
3999 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4000 'S','h','a','r','e','d','D','L','L','s',0};
4002 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
4006 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
4011 DWORD sz = sizeof(count);
4014 hkey = openSharedDLLsKey();
4015 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
4016 if (rc != ERROR_SUCCESS)
4022 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
4026 hkey = openSharedDLLsKey();
4028 RegSetValueExW(hkey,path,0,REG_DWORD,
4029 (LPBYTE)&count,sizeof(count));
4031 RegDeleteValueW(hkey,path);
4037 * Return TRUE if the count should be written out and FALSE if not
4039 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
4045 /* only refcount DLLs */
4046 if (package->components[index].KeyPath[0]==0 ||
4047 package->components[index].Attributes &
4048 msidbComponentAttributesRegistryKeyPath ||
4049 package->components[index].Attributes &
4050 msidbComponentAttributesODBCDataSource)
4054 count = ACTION_GetSharedDLLsCount(package->components[index].
4056 write = (count > 0);
4058 if (package->components[index].Attributes &
4059 msidbComponentAttributesSharedDllRefCount)
4063 /* increment counts */
4064 for (j = 0; j < package->loaded_features; j++)
4068 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
4071 for (i = 0; i < package->features[j].ComponentCount; i++)
4073 if (package->features[j].Components[i] == index)
4077 /* decrement counts */
4078 for (j = 0; j < package->loaded_features; j++)
4081 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
4084 for (i = 0; i < package->features[j].ComponentCount; i++)
4086 if (package->features[j].Components[i] == index)
4091 /* ref count all the files in the component */
4093 for (j = 0; j < package->loaded_files; j++)
4095 if (package->files[j].Temporary)
4097 if (package->files[j].ComponentIndex == index)
4098 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
4101 /* add a count for permenent */
4102 if (package->components[index].Attributes &
4103 msidbComponentAttributesPermanent)
4106 package->components[index].RefCount = count;
4109 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
4110 package->components[index].RefCount);
4114 * Ok further analysis makes me think that this work is
4115 * actually done in the PublishComponents and PublishFeatures
4116 * step, and not here. It appears like the keypath and all that is
4117 * resolved in this step, however actually written in the Publish steps.
4118 * But we will leave it here for now because it is unclear
4120 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
4123 WCHAR squished_pc[GUID_SIZE];
4124 WCHAR squished_cc[GUID_SIZE];
4127 HKEY hkey=0,hkey2=0;
4130 return ERROR_INVALID_HANDLE;
4132 /* writes the Component and Features values to the registry */
4133 productcode = load_dynamic_property(package,szProductCode,&rc);
4137 rc = MSIREG_OpenComponents(&hkey);
4138 if (rc != ERROR_SUCCESS)
4141 squash_guid(productcode,squished_pc);
4142 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
4143 for (i = 0; i < package->loaded_components; i++)
4145 ui_progress(package,2,0,0,0);
4146 if (package->components[i].ComponentId[0]!=0)
4148 WCHAR *keypath = NULL;
4151 squash_guid(package->components[i].ComponentId,squished_cc);
4153 keypath = resolve_keypath(package,i);
4154 package->components[i].FullKeypath = keypath;
4156 /* do the refcounting */
4157 ACTION_RefCountComponent( package, i);
4159 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
4160 debugstr_w(package->components[i].Component),
4161 debugstr_w(squished_cc),
4162 debugstr_w(package->components[i].FullKeypath),
4163 package->components[i].RefCount);
4165 * Write the keypath out if the component is to be registered
4166 * and delete the key if the component is to be deregistered
4168 if (ACTION_VerifyComponentForAction(package, i,
4169 INSTALLSTATE_LOCAL))
4171 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
4172 if (rc != ERROR_SUCCESS)
4177 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
4178 (strlenW(keypath)+1)*sizeof(WCHAR));
4180 if (package->components[i].Attributes &
4181 msidbComponentAttributesPermanent)
4183 static const WCHAR szPermKey[] =
4184 { '0','0','0','0','0','0','0','0','0','0','0','0',
4185 '0','0','0','0','0','0','0', '0','0','0','0','0',
4186 '0','0','0','0','0','0','0','0',0};
4188 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
4190 (strlenW(keypath)+1)*sizeof(WCHAR));
4196 uirow = MSI_CreateRecord(3);
4197 MSI_RecordSetStringW(uirow,1,productcode);
4198 MSI_RecordSetStringW(uirow,2,package->components[i].
4200 MSI_RecordSetStringW(uirow,3,keypath);
4201 ui_actiondata(package,szProcessComponents,uirow);
4202 msiobj_release( &uirow->hdr );
4205 else if (ACTION_VerifyComponentForAction(package, i,
4206 INSTALLSTATE_ABSENT))
4210 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
4211 if (rc != ERROR_SUCCESS)
4214 RegDeleteValueW(hkey2,squished_pc);
4216 /* if the key is empty delete it */
4217 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
4219 if (res == ERROR_NO_MORE_ITEMS)
4220 RegDeleteKeyW(hkey,squished_cc);
4223 uirow = MSI_CreateRecord(2);
4224 MSI_RecordSetStringW(uirow,1,productcode);
4225 MSI_RecordSetStringW(uirow,2,package->components[i].
4227 ui_actiondata(package,szProcessComponents,uirow);
4228 msiobj_release( &uirow->hdr );
4233 HeapFree(GetProcessHeap(), 0, productcode);
4246 BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
4247 LPWSTR lpszName, LONG_PTR lParam)
4250 typelib_struct *tl_struct = (typelib_struct*) lParam;
4251 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
4255 if (!IS_INTRESOURCE(lpszName))
4257 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
4261 sz = strlenW(tl_struct->source)+4;
4262 sz *= sizeof(WCHAR);
4264 if ((INT)lpszName == 1)
4265 tl_struct->path = strdupW(tl_struct->source);
4268 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
4269 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
4272 TRACE("trying %s\n", debugstr_w(tl_struct->path));
4273 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
4274 if (!SUCCEEDED(res))
4276 HeapFree(GetProcessHeap(),0,tl_struct->path);
4277 tl_struct->path = NULL;
4282 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
4283 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
4285 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4289 HeapFree(GetProcessHeap(),0,tl_struct->path);
4290 tl_struct->path = NULL;
4292 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4293 ITypeLib_Release(tl_struct->ptLib);
4298 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4301 * OK this is a bit confusing.. I am given a _Component key and I believe
4302 * that the file that is being registered as a type library is the "key file
4303 * of that component" which I interpret to mean "The file in the KeyPath of
4308 MSIRECORD * row = 0;
4309 static const WCHAR Query[] =
4310 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4311 '`','T','y','p','e','L','i','b','`',0};
4314 return ERROR_INVALID_HANDLE;
4316 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4317 if (rc != ERROR_SUCCESS)
4318 return ERROR_SUCCESS;
4320 rc = MSI_ViewExecute(view, 0);
4321 if (rc != ERROR_SUCCESS)
4323 MSI_ViewClose(view);
4324 msiobj_release(&view->hdr);
4330 WCHAR component[0x100];
4334 typelib_struct tl_struct;
4336 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
4338 rc = MSI_ViewFetch(view,&row);
4339 if (rc != ERROR_SUCCESS)
4346 MSI_RecordGetStringW(row,3,component,&sz);
4348 index = get_loaded_component(package,component);
4351 msiobj_release(&row->hdr);
4355 if (!ACTION_VerifyComponentForAction(package, index,
4356 INSTALLSTATE_LOCAL))
4358 TRACE("Skipping typelib reg due to disabled component\n");
4359 msiobj_release(&row->hdr);
4361 package->components[index].Action =
4362 package->components[index].Installed;
4367 package->components[index].Action = INSTALLSTATE_LOCAL;
4369 index = get_loaded_file(package,package->components[index].KeyPath);
4373 msiobj_release(&row->hdr);
4377 guid = load_dynamic_stringW(row,1);
4378 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
4379 LOAD_LIBRARY_AS_DATAFILE);
4382 CLSIDFromString(guid, &tl_struct.clsid);
4383 tl_struct.source = strdupW(package->files[index].TargetPath);
4384 tl_struct.path = NULL;
4386 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
4387 (LONG_PTR)&tl_struct);
4389 if (tl_struct.path != NULL)
4392 WCHAR helpid[0x100];
4396 MSI_RecordGetStringW(row,6,helpid,&sz);
4398 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4399 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
4400 HeapFree(GetProcessHeap(),0,help);
4402 if (!SUCCEEDED(res))
4403 ERR("Failed to register type library %s\n",
4404 debugstr_w(tl_struct.path));
4407 ui_actiondata(package,szRegisterTypeLibraries,row);
4409 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
4412 ITypeLib_Release(tl_struct.ptLib);
4413 HeapFree(GetProcessHeap(),0,tl_struct.path);
4416 ERR("Failed to load type library %s\n",
4417 debugstr_w(tl_struct.source));
4419 FreeLibrary(module);
4420 HeapFree(GetProcessHeap(),0,tl_struct.source);
4423 ERR("Could not load file! %s\n",
4424 debugstr_w(package->files[index].TargetPath));
4425 msiobj_release(&row->hdr);
4427 MSI_ViewClose(view);
4428 msiobj_release(&view->hdr);
4432 static INT load_appid(MSIPACKAGE* package, MSIRECORD *row)
4434 DWORD index = package->loaded_appids;
4438 /* fill in the data */
4440 package->loaded_appids++;
4441 if (package->loaded_appids == 1)
4442 package->appids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIAPPID));
4444 package->appids = HeapReAlloc(GetProcessHeap(),0,
4445 package->appids, package->loaded_appids * sizeof(MSIAPPID));
4447 memset(&package->appids[index],0,sizeof(MSIAPPID));
4449 sz = IDENTIFIER_SIZE;
4450 MSI_RecordGetStringW(row, 1, package->appids[index].AppID, &sz);
4451 TRACE("loading appid %s\n",debugstr_w(package->appids[index].AppID));
4453 buffer = load_dynamic_stringW(row,2);
4454 deformat_string(package,buffer,&package->appids[index].RemoteServerName);
4455 HeapFree(GetProcessHeap(),0,buffer);
4457 package->appids[index].LocalServer = load_dynamic_stringW(row,3);
4458 package->appids[index].ServiceParameters = load_dynamic_stringW(row,4);
4459 package->appids[index].DllSurrogate = load_dynamic_stringW(row,5);
4461 package->appids[index].ActivateAtStorage = !MSI_RecordIsNull(row,6);
4462 package->appids[index].RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
4467 static INT load_given_appid(MSIPACKAGE *package, LPCWSTR appid)
4472 static const WCHAR ExecSeqQuery[] =
4473 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4474 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
4475 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
4480 /* check for appids already loaded */
4481 for (i = 0; i < package->loaded_appids; i++)
4482 if (strcmpiW(package->appids[i].AppID,appid)==0)
4484 TRACE("found appid %s at index %i\n",debugstr_w(appid),i);
4488 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, appid);
4492 rc = load_appid(package, row);
4493 msiobj_release(&row->hdr);
4498 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
4499 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid);
4501 static INT load_progid(MSIPACKAGE* package, MSIRECORD *row)
4503 DWORD index = package->loaded_progids;
4506 /* fill in the data */
4508 package->loaded_progids++;
4509 if (package->loaded_progids == 1)
4510 package->progids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIPROGID));
4512 package->progids = HeapReAlloc(GetProcessHeap(),0,
4513 package->progids , package->loaded_progids * sizeof(MSIPROGID));
4515 memset(&package->progids[index],0,sizeof(MSIPROGID));
4517 package->progids[index].ProgID = load_dynamic_stringW(row,1);
4518 TRACE("loading progid %s\n",debugstr_w(package->progids[index].ProgID));
4520 buffer = load_dynamic_stringW(row,2);
4521 package->progids[index].ParentIndex = load_given_progid(package,buffer);
4522 if (package->progids[index].ParentIndex < 0 && buffer)
4523 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
4524 HeapFree(GetProcessHeap(),0,buffer);
4526 buffer = load_dynamic_stringW(row,3);
4527 package->progids[index].ClassIndex = load_given_class(package,buffer);
4528 if (package->progids[index].ClassIndex< 0 && buffer)
4529 FIXME("Unknown class %s\n",debugstr_w(buffer));
4530 HeapFree(GetProcessHeap(),0,buffer);
4532 package->progids[index].Description = load_dynamic_stringW(row,4);
4534 if (!MSI_RecordIsNull(row,6))
4536 INT icon_index = MSI_RecordGetInteger(row,6);
4537 LPWSTR FileName = load_dynamic_stringW(row,5);
4539 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4541 build_icon_path(package,FileName,&FilePath);
4543 package->progids[index].IconPath =
4544 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+10)*
4547 sprintfW(package->progids[index].IconPath,fmt,FilePath,icon_index);
4549 HeapFree(GetProcessHeap(),0,FilePath);
4550 HeapFree(GetProcessHeap(),0,FileName);
4554 buffer = load_dynamic_stringW(row,5);
4556 build_icon_path(package,buffer,&(package->progids[index].IconPath));
4557 HeapFree(GetProcessHeap(),0,buffer);
4560 package->progids[index].CurVerIndex = -1;
4561 package->progids[index].VersionIndIndex = -1;
4563 /* if we have a parent then we may be that parents CurVer */
4564 if (package->progids[index].ParentIndex >= 0 &&
4565 package->progids[index].ParentIndex != index)
4567 int pindex = package->progids[index].ParentIndex;
4568 while (package->progids[pindex].ParentIndex>= 0)
4569 pindex = package->progids[pindex].ParentIndex;
4571 FIXME("BAD BAD need to determing if we are really the CurVer\n");
4573 package->progids[index].CurVerIndex = pindex;
4574 package->progids[pindex].VersionIndIndex = index;
4580 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid)
4585 static const WCHAR ExecSeqQuery[] =
4586 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4587 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
4588 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
4593 /* check for progids already loaded */
4594 for (i = 0; i < package->loaded_progids; i++)
4595 if (strcmpiW(package->progids[i].ProgID,progid)==0)
4597 TRACE("found progid %s at index %i\n",debugstr_w(progid), i);
4601 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, progid);
4605 rc = load_progid(package, row);
4606 msiobj_release(&row->hdr);
4611 static INT load_class(MSIPACKAGE* package, MSIRECORD *row)
4613 DWORD index = package->loaded_classes;
4617 /* fill in the data */
4619 package->loaded_classes++;
4620 if (package->loaded_classes== 1)
4621 package->classes = HeapAlloc(GetProcessHeap(),0,sizeof(MSICLASS));
4623 package->classes = HeapReAlloc(GetProcessHeap(),0,
4624 package->classes, package->loaded_classes * sizeof(MSICLASS));
4626 memset(&package->classes[index],0,sizeof(MSICLASS));
4628 sz = IDENTIFIER_SIZE;
4629 MSI_RecordGetStringW(row, 1, package->classes[index].CLSID, &sz);
4630 TRACE("loading class %s\n",debugstr_w(package->classes[index].CLSID));
4631 sz = IDENTIFIER_SIZE;
4632 MSI_RecordGetStringW(row, 2, package->classes[index].Context, &sz);
4633 buffer = load_dynamic_stringW(row,3);
4634 package->classes[index].ComponentIndex = get_loaded_component(package,
4636 HeapFree(GetProcessHeap(),0,buffer);
4638 package->classes[index].ProgIDText = load_dynamic_stringW(row,4);
4639 package->classes[index].ProgIDIndex =
4640 load_given_progid(package, package->classes[index].ProgIDText);
4642 package->classes[index].Description = load_dynamic_stringW(row,5);
4644 buffer = load_dynamic_stringW(row,6);
4646 package->classes[index].AppIDIndex =
4647 load_given_appid(package, buffer);
4649 package->classes[index].AppIDIndex = -1;
4650 HeapFree(GetProcessHeap(),0,buffer);
4652 package->classes[index].FileTypeMask = load_dynamic_stringW(row,7);
4654 if (!MSI_RecordIsNull(row,9))
4657 INT icon_index = MSI_RecordGetInteger(row,9);
4658 LPWSTR FileName = load_dynamic_stringW(row,8);
4660 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4662 build_icon_path(package,FileName,&FilePath);
4664 package->classes[index].IconPath =
4665 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4668 sprintfW(package->classes[index].IconPath,fmt,FilePath,icon_index);
4670 HeapFree(GetProcessHeap(),0,FilePath);
4671 HeapFree(GetProcessHeap(),0,FileName);
4675 buffer = load_dynamic_stringW(row,8);
4677 build_icon_path(package,buffer,&(package->classes[index].IconPath));
4678 HeapFree(GetProcessHeap(),0,buffer);
4681 if (!MSI_RecordIsNull(row,10))
4683 i = MSI_RecordGetInteger(row,10);
4684 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4686 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4687 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
4692 package->classes[index].DefInprocHandler = strdupW(ole2);
4695 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4698 package->classes[index].DefInprocHandler = strdupW(ole2);
4699 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4705 package->classes[index].DefInprocHandler32 = load_dynamic_stringW(
4707 reduce_to_longfilename(package->classes[index].DefInprocHandler32);
4710 buffer = load_dynamic_stringW(row,11);
4711 deformat_string(package,buffer,&package->classes[index].Argument);
4712 HeapFree(GetProcessHeap(),0,buffer);
4714 buffer = load_dynamic_stringW(row,12);
4715 package->classes[index].FeatureIndex = get_loaded_feature(package,buffer);
4716 HeapFree(GetProcessHeap(),0,buffer);
4718 package->classes[index].Attributes = MSI_RecordGetInteger(row,13);
4724 * the Class table has 3 primary keys. Generally it is only
4725 * referenced through the first CLSID key. However when loading
4726 * all of the classes we need to make sure we do not ignore rows
4727 * with other Context and ComponentIndexs
4729 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid)
4734 static const WCHAR ExecSeqQuery[] =
4735 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4736 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
4737 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
4743 /* check for classes already loaded */
4744 for (i = 0; i < package->loaded_classes; i++)
4745 if (strcmpiW(package->classes[i].CLSID,classid)==0)
4747 TRACE("found class %s at index %i\n",debugstr_w(classid), i);
4751 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
4755 rc = load_class(package, row);
4756 msiobj_release(&row->hdr);
4761 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension);
4763 static INT load_mime(MSIPACKAGE* package, MSIRECORD *row)
4765 DWORD index = package->loaded_mimes;
4769 /* fill in the data */
4771 package->loaded_mimes++;
4772 if (package->loaded_mimes== 1)
4773 package->mimes= HeapAlloc(GetProcessHeap(),0,sizeof(MSIMIME));
4775 package->mimes= HeapReAlloc(GetProcessHeap(),0,
4776 package->mimes, package->loaded_mimes*
4779 memset(&package->mimes[index],0,sizeof(MSIMIME));
4781 package->mimes[index].ContentType = load_dynamic_stringW(row,1);
4782 TRACE("loading mime %s\n",debugstr_w(package->mimes[index].ContentType));
4784 buffer = load_dynamic_stringW(row,2);
4785 package->mimes[index].ExtensionIndex = load_given_extension(package,
4787 HeapFree(GetProcessHeap(),0,buffer);
4789 sz = IDENTIFIER_SIZE;
4790 MSI_RecordGetStringW(row,3,package->mimes[index].CLSID,&sz);
4791 package->mimes[index].ClassIndex= load_given_class(package,
4792 package->mimes[index].CLSID);
4797 static INT load_given_mime(MSIPACKAGE *package, LPCWSTR mime)
4802 static const WCHAR ExecSeqQuery[] =
4803 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4804 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
4805 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
4806 '\'','%','s','\'',0};
4811 /* check for mime already loaded */
4812 for (i = 0; i < package->loaded_mimes; i++)
4813 if (strcmpiW(package->mimes[i].ContentType,mime)==0)
4815 TRACE("found mime %s at index %i\n",debugstr_w(mime), i);
4819 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
4823 rc = load_mime(package, row);
4824 msiobj_release(&row->hdr);
4829 static INT load_extension(MSIPACKAGE* package, MSIRECORD *row)
4831 DWORD index = package->loaded_extensions;
4835 /* fill in the data */
4837 package->loaded_extensions++;
4838 if (package->loaded_extensions == 1)
4839 package->extensions = HeapAlloc(GetProcessHeap(),0,sizeof(MSIEXTENSION));
4841 package->extensions = HeapReAlloc(GetProcessHeap(),0,
4842 package->extensions, package->loaded_extensions*
4843 sizeof(MSIEXTENSION));
4845 memset(&package->extensions[index],0,sizeof(MSIEXTENSION));
4848 MSI_RecordGetStringW(row,1,package->extensions[index].Extension,&sz);
4849 TRACE("loading extension %s\n",
4850 debugstr_w(package->extensions[index].Extension));
4852 buffer = load_dynamic_stringW(row,2);
4853 package->extensions[index].ComponentIndex =
4854 get_loaded_component(package,buffer);
4855 HeapFree(GetProcessHeap(),0,buffer);
4857 package->extensions[index].ProgIDText = load_dynamic_stringW(row,3);
4858 package->extensions[index].ProgIDIndex = load_given_progid(package,
4859 package->extensions[index].ProgIDText);
4861 buffer = load_dynamic_stringW(row,4);
4862 package->extensions[index].MIMEIndex = load_given_mime(package,buffer);
4863 HeapFree(GetProcessHeap(),0,buffer);
4865 buffer = load_dynamic_stringW(row,5);
4866 package->extensions[index].FeatureIndex =
4867 get_loaded_feature(package,buffer);
4868 HeapFree(GetProcessHeap(),0,buffer);
4874 * While the extension table has 2 primary keys, this function is only looking
4875 * at the Extension key which is what is referenced as a forign key
4877 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension)
4882 static const WCHAR ExecSeqQuery[] =
4883 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4884 '`','E','x','t','e','n','s','i','o','n','`',' ',
4885 'W','H','E','R','E',' ',
4886 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
4887 '\'','%','s','\'',0};
4892 /* check for extensions already loaded */
4893 for (i = 0; i < package->loaded_extensions; i++)
4894 if (strcmpiW(package->extensions[i].Extension,extension)==0)
4896 TRACE("extension %s already loaded at %i\n",debugstr_w(extension),
4901 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, extension);
4905 rc = load_extension(package, row);
4906 msiobj_release(&row->hdr);
4911 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
4913 MSIPACKAGE* package = (MSIPACKAGE*)param;
4914 DWORD index = package->loaded_verbs;
4917 /* fill in the data */
4919 package->loaded_verbs++;
4920 if (package->loaded_verbs == 1)
4921 package->verbs = HeapAlloc(GetProcessHeap(),0,sizeof(MSIVERB));
4923 package->verbs = HeapReAlloc(GetProcessHeap(),0,
4924 package->verbs , package->loaded_verbs * sizeof(MSIVERB));
4926 memset(&package->verbs[index],0,sizeof(MSIVERB));
4928 buffer = load_dynamic_stringW(row,1);
4929 package->verbs[index].ExtensionIndex = load_given_extension(package,buffer);
4930 if (package->verbs[index].ExtensionIndex < 0 && buffer)
4931 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
4932 HeapFree(GetProcessHeap(),0,buffer);
4934 package->verbs[index].Verb = load_dynamic_stringW(row,2);
4935 TRACE("loading verb %s\n",debugstr_w(package->verbs[index].Verb));
4936 package->verbs[index].Sequence = MSI_RecordGetInteger(row,3);
4938 buffer = load_dynamic_stringW(row,4);
4939 deformat_string(package,buffer,&package->verbs[index].Command);
4940 HeapFree(GetProcessHeap(),0,buffer);
4942 buffer = load_dynamic_stringW(row,5);
4943 deformat_string(package,buffer,&package->verbs[index].Argument);
4944 HeapFree(GetProcessHeap(),0,buffer);
4946 /* assosiate the verb with the correct extension */
4947 if (package->verbs[index].ExtensionIndex >= 0)
4949 MSIEXTENSION* extension = &package->extensions[package->verbs[index].
4951 int count = extension->VerbCount;
4954 FIXME("Exceeding max verb count! Increase that limit!!!\n");
4957 extension->VerbCount++;
4958 extension->Verbs[count] = index;
4962 return ERROR_SUCCESS;
4965 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
4970 INT component_index;
4971 MSIPACKAGE* package =(MSIPACKAGE*)param;
4975 clsid = load_dynamic_stringW(rec,1);
4976 context = load_dynamic_stringW(rec,2);
4977 buffer = load_dynamic_stringW(rec,3);
4978 component_index = get_loaded_component(package,buffer);
4980 for (i = 0; i < package->loaded_classes; i++)
4982 if (strcmpiW(clsid,package->classes[i].CLSID))
4984 if (strcmpW(context,package->classes[i].Context))
4986 if (component_index == package->classes[i].ComponentIndex)
4993 HeapFree(GetProcessHeap(),0,buffer);
4994 HeapFree(GetProcessHeap(),0,clsid);
4995 HeapFree(GetProcessHeap(),0,context);
4998 load_class(package, rec);
5000 return ERROR_SUCCESS;
5003 static VOID load_all_classes(MSIPACKAGE *package)
5005 UINT rc = ERROR_SUCCESS;
5008 static const WCHAR ExecSeqQuery[] =
5009 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
5010 '`','C','l','a','s','s','`',0};
5012 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5013 if (rc != ERROR_SUCCESS)
5016 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
5017 msiobj_release(&view->hdr);
5020 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
5024 INT component_index;
5025 MSIPACKAGE* package =(MSIPACKAGE*)param;
5029 extension = load_dynamic_stringW(rec,1);
5030 buffer = load_dynamic_stringW(rec,2);
5031 component_index = get_loaded_component(package,buffer);
5033 for (i = 0; i < package->loaded_extensions; i++)
5035 if (strcmpiW(extension,package->extensions[i].Extension))
5037 if (component_index == package->extensions[i].ComponentIndex)
5044 HeapFree(GetProcessHeap(),0,buffer);
5045 HeapFree(GetProcessHeap(),0,extension);
5048 load_extension(package, rec);
5050 return ERROR_SUCCESS;
5053 static VOID load_all_extensions(MSIPACKAGE *package)
5055 UINT rc = ERROR_SUCCESS;
5058 static const WCHAR ExecSeqQuery[] =
5059 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5060 '`','E','x','t','e','n','s','i','o','n','`',0};
5062 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5063 if (rc != ERROR_SUCCESS)
5066 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
5067 msiobj_release(&view->hdr);
5070 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
5073 MSIPACKAGE* package =(MSIPACKAGE*)param;
5075 buffer = load_dynamic_stringW(rec,1);
5076 load_given_progid(package,buffer);
5077 HeapFree(GetProcessHeap(),0,buffer);
5078 return ERROR_SUCCESS;
5081 static VOID load_all_progids(MSIPACKAGE *package)
5083 UINT rc = ERROR_SUCCESS;
5086 static const WCHAR ExecSeqQuery[] =
5087 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
5088 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
5090 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5091 if (rc != ERROR_SUCCESS)
5094 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
5095 msiobj_release(&view->hdr);
5098 static VOID load_all_verbs(MSIPACKAGE *package)
5100 UINT rc = ERROR_SUCCESS;
5103 static const WCHAR ExecSeqQuery[] =
5104 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5105 '`','V','e','r','b','`',0};
5107 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5108 if (rc != ERROR_SUCCESS)
5111 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
5112 msiobj_release(&view->hdr);
5115 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
5118 MSIPACKAGE* package =(MSIPACKAGE*)param;
5120 buffer = load_dynamic_stringW(rec,1);
5121 load_given_mime(package,buffer);
5122 HeapFree(GetProcessHeap(),0,buffer);
5123 return ERROR_SUCCESS;
5126 static VOID load_all_mimes(MSIPACKAGE *package)
5128 UINT rc = ERROR_SUCCESS;
5131 static const WCHAR ExecSeqQuery[] =
5132 {'S','E','L','E','C','T',' ',
5133 '`','C','o','n','t','e','n','t','T','y','p','e','`',
5134 ' ','F','R','O','M',' ',
5135 '`','M','I','M','E','`',0};
5137 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5138 if (rc != ERROR_SUCCESS)
5141 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
5142 msiobj_release(&view->hdr);
5145 static void load_classes_and_such(MSIPACKAGE *package)
5147 TRACE("Loading all the class info and related tables\n");
5149 /* check if already loaded */
5150 if (package->classes || package->extensions || package->progids ||
5151 package->verbs || package->mimes)
5154 load_all_classes(package);
5155 load_all_extensions(package);
5156 load_all_progids(package);
5157 /* these loads must come after the other loads */
5158 load_all_verbs(package);
5159 load_all_mimes(package);
5162 static void mark_progid_for_install(MSIPACKAGE* package, INT index)
5167 if (index < 0 || index >= package->loaded_progids)
5170 progid = &package->progids[index];
5172 if (progid->InstallMe == TRUE)
5175 progid->InstallMe = TRUE;
5177 /* all children if this is a parent also install */
5178 for (i = 0; i < package->loaded_progids; i++)
5179 if (package->progids[i].ParentIndex == index)
5180 mark_progid_for_install(package,i);
5183 static void mark_mime_for_install(MSIPACKAGE* package, INT index)
5187 if (index < 0 || index >= package->loaded_mimes)
5190 mime = &package->mimes[index];
5192 if (mime->InstallMe == TRUE)
5195 mime->InstallMe = TRUE;
5198 static UINT register_appid(MSIPACKAGE *package, int appidIndex, LPCWSTR app )
5200 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5204 return ERROR_INVALID_HANDLE;
5206 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
5207 RegCreateKeyW(hkey2,package->appids[appidIndex].AppID,&hkey3);
5208 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
5209 (strlenW(app)+1)*sizeof(WCHAR));
5211 if (package->appids[appidIndex].RemoteServerName)
5214 static const WCHAR szRemoteServerName[] =
5215 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
5218 size = (strlenW(package->appids[appidIndex].RemoteServerName)+1) *
5221 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,
5222 (LPVOID)package->appids[appidIndex].RemoteServerName,
5226 if (package->appids[appidIndex].LocalServer)
5228 static const WCHAR szLocalService[] =
5229 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
5231 size = (strlenW(package->appids[appidIndex].LocalServer)+1) *
5234 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,
5235 (LPVOID)package->appids[appidIndex].LocalServer,size);
5238 if (package->appids[appidIndex].ServiceParameters)
5240 static const WCHAR szService[] =
5241 {'S','e','r','v','i','c','e',
5242 'P','a','r','a','m','e','t','e','r','s',0};
5244 size = (strlenW(package->appids[appidIndex].ServiceParameters)+1) *
5246 RegSetValueExW(hkey3,szService,0,REG_SZ,
5247 (LPVOID)package->appids[appidIndex].ServiceParameters,
5251 if (package->appids[appidIndex].DllSurrogate)
5253 static const WCHAR szDLL[] =
5254 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
5256 size = (strlenW(package->appids[appidIndex].DllSurrogate)+1) *
5258 RegSetValueExW(hkey3,szDLL,0,REG_SZ,
5259 (LPVOID)package->appids[appidIndex].DllSurrogate,size);
5262 if (package->appids[appidIndex].ActivateAtStorage)
5264 static const WCHAR szActivate[] =
5265 {'A','c','t','i','v','a','t','e','A','s',
5266 'S','t','o','r','a','g','e',0};
5267 static const WCHAR szY[] = {'Y',0};
5269 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
5272 if (package->appids[appidIndex].RunAsInteractiveUser)
5274 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
5275 static const WCHAR szUser[] =
5276 {'I','n','t','e','r','a','c','t','i','v','e',' ',
5279 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,sizeof(szUser));
5284 return ERROR_SUCCESS;
5287 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
5290 * Again I am assuming the words, "Whose key file represents" when referring
5291 * to a Component as to meaning that Components KeyPath file
5296 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5297 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
5298 static const WCHAR szVIProgID[] = { 'V','e','r','s','i','o','n','I','n','d','e','p','e','n','d','e','n','t','P','r','o','g','I','D',0 };
5299 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5300 static const WCHAR szSpace[] = {' ',0};
5301 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
5302 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
5303 HKEY hkey,hkey2,hkey3;
5304 BOOL install_on_demand = FALSE;
5308 return ERROR_INVALID_HANDLE;
5310 load_classes_and_such(package);
5311 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
5312 if (rc != ERROR_SUCCESS)
5313 return ERROR_FUNCTION_FAILED;
5315 /* install_on_demand should be set if OLE supports install on demand OLE
5316 * servers. For now i am defaulting to FALSE because i do not know how to
5317 * check, and i am told our builtin OLE does not support it
5320 for (i = 0; i < package->loaded_classes; i++)
5326 if (package->classes[i].ComponentIndex < 0)
5331 index = package->classes[i].ComponentIndex;
5332 f_index = package->classes[i].FeatureIndex;
5335 * yes. MSDN says that these are based on _Feature_ not on
5336 * Component. So verify the feature is to be installed
5338 if ((!ACTION_VerifyFeatureForAction(package, f_index,
5339 INSTALLSTATE_LOCAL)) &&
5340 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
5341 f_index, INSTALLSTATE_ADVERTISED)))
5343 TRACE("Skipping class %s reg due to disabled feature %s\n",
5344 debugstr_w(package->classes[i].CLSID),
5345 debugstr_w(package->features[f_index].Feature));
5350 TRACE("Registering index %i class %s\n",i,
5351 debugstr_w(package->classes[i].CLSID));
5353 package->classes[i].Installed = TRUE;
5354 if (package->classes[i].ProgIDIndex >= 0)
5355 mark_progid_for_install(package, package->classes[i].ProgIDIndex);
5357 RegCreateKeyW(hkey,package->classes[i].CLSID,&hkey2);
5359 if (package->classes[i].Description)
5360 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)package->classes[i].
5361 Description, (strlenW(package->classes[i].
5362 Description)+1)*sizeof(WCHAR));
5364 RegCreateKeyW(hkey2,package->classes[i].Context,&hkey3);
5365 index = get_loaded_file(package,package->components[index].KeyPath);
5368 /* the context server is a short path name
5369 * except for if it is InprocServer32...
5371 if (strcmpiW(package->classes[i].Context,szInprocServer32)!=0)
5374 sz = GetShortPathNameW(package->files[index].TargetPath, NULL, 0);
5377 ERR("Unable to find short path for CLSID COM Server\n");
5382 size = sz * sizeof(WCHAR);
5384 if (package->classes[i].Argument)
5386 size += strlenW(package->classes[i].Argument) *
5388 size += sizeof(WCHAR);
5391 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5392 GetShortPathNameW(package->files[index].TargetPath, argument,
5395 if (package->classes[i].Argument)
5397 strcatW(argument,szSpace);
5398 strcatW(argument,package->classes[i].Argument);
5404 size = lstrlenW(package->files[index].TargetPath) * sizeof(WCHAR);
5406 if (package->classes[i].Argument)
5408 size += strlenW(package->classes[i].Argument) * sizeof(WCHAR);
5409 size += sizeof(WCHAR);
5412 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5413 strcpyW(argument, package->files[index].TargetPath);
5415 if (package->classes[i].Argument)
5417 strcatW(argument,szSpace);
5418 strcatW(argument,package->classes[i].Argument);
5424 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
5425 HeapFree(GetProcessHeap(),0,argument);
5430 if (package->classes[i].ProgIDIndex >= 0 ||
5431 package->classes[i].ProgIDText)
5435 if (package->classes[i].ProgIDIndex >= 0)
5436 progid = package->progids[
5437 package->classes[i].ProgIDIndex].ProgID;
5439 progid = package->classes[i].ProgIDText;
5441 RegCreateKeyW(hkey2,szProgID,&hkey3);
5442 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)progid,
5443 (strlenW(progid)+1) *sizeof(WCHAR));
5446 if (package->classes[i].ProgIDIndex >= 0 &&
5447 package->progids[package->classes[i].ProgIDIndex].
5448 VersionIndIndex >= 0)
5450 LPWSTR viprogid = strdupW(package->progids[package->progids[
5451 package->classes[i].ProgIDIndex].VersionIndIndex].
5453 RegCreateKeyW(hkey2,szVIProgID,&hkey3);
5454 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)viprogid,
5455 (strlenW(viprogid)+1) *sizeof(WCHAR));
5457 HeapFree(GetProcessHeap(), 0, viprogid);
5461 if (package->classes[i].AppIDIndex >= 0)
5463 RegSetValueExW(hkey2,szAppID,0,REG_SZ,
5464 (LPVOID)package->appids[package->classes[i].AppIDIndex].AppID,
5465 (strlenW(package->appids[package->classes[i].AppIDIndex].AppID)+1)
5468 register_appid(package,package->classes[i].AppIDIndex,
5469 package->classes[i].Description);
5472 if (package->classes[i].IconPath)
5474 static const WCHAR szDefaultIcon[] =
5475 {'D','e','f','a','u','l','t','I','c','o','n',0};
5477 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
5479 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5480 (LPVOID)package->classes[i].IconPath,
5481 (strlenW(package->classes[i].IconPath)+1) *
5487 if (package->classes[i].DefInprocHandler)
5489 static const WCHAR szInproc[] =
5490 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
5492 size = (strlenW(package->classes[i].DefInprocHandler) + 1) *
5494 RegCreateKeyW(hkey2,szInproc,&hkey3);
5495 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5496 (LPVOID)package->classes[i].DefInprocHandler, size);
5500 if (package->classes[i].DefInprocHandler32)
5502 static const WCHAR szInproc32[] =
5503 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
5505 size = (strlenW(package->classes[i].DefInprocHandler32) + 1) *
5508 RegCreateKeyW(hkey2,szInproc32,&hkey3);
5509 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5510 (LPVOID)package->classes[i].DefInprocHandler32,size);
5516 /* if there is a FileTypeMask, register the FileType */
5517 if (package->classes[i].FileTypeMask)
5522 ptr = package->classes[i].FileTypeMask;
5525 ptr2 = strchrW(ptr,';');
5528 keyname = HeapAlloc(GetProcessHeap(),0,(strlenW(szFileType_fmt)+
5529 strlenW(package->classes[i].CLSID) + 4)
5531 sprintfW(keyname,szFileType_fmt, package->classes[i].CLSID,
5534 RegCreateKeyW(HKEY_CLASSES_ROOT,keyname,&hkey2);
5535 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPVOID)ptr,
5536 strlenW(ptr)*sizeof(WCHAR));
5538 HeapFree(GetProcessHeap(), 0, keyname);
5549 uirow = MSI_CreateRecord(1);
5551 MSI_RecordSetStringW(uirow,1,package->classes[i].CLSID);
5552 ui_actiondata(package,szRegisterClassInfo,uirow);
5553 msiobj_release(&uirow->hdr);
5560 static UINT register_progid_base(MSIPACKAGE* package, MSIPROGID* progid,
5563 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5564 static const WCHAR szDefaultIcon[] =
5565 {'D','e','f','a','u','l','t','I','c','o','n',0};
5568 RegCreateKeyW(HKEY_CLASSES_ROOT,progid->ProgID,&hkey);
5570 if (progid->Description)
5572 RegSetValueExW(hkey,NULL,0,REG_SZ,
5573 (LPVOID)progid->Description,
5574 (strlenW(progid->Description)+1) *
5578 if (progid->ClassIndex >= 0)
5580 RegCreateKeyW(hkey,szCLSID,&hkey2);
5581 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5582 (LPVOID)package->classes[progid->ClassIndex].CLSID,
5583 (strlenW(package->classes[progid->ClassIndex].CLSID)+1)
5587 strcpyW(clsid,package->classes[progid->ClassIndex].CLSID);
5593 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
5596 if (progid->IconPath)
5598 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5600 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5601 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5604 return ERROR_SUCCESS;
5607 static UINT register_progid(MSIPACKAGE *package, MSIPROGID* progid,
5610 UINT rc = ERROR_SUCCESS;
5612 if (progid->ParentIndex < 0)
5613 rc = register_progid_base(package, progid, clsid);
5618 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5619 static const WCHAR szDefaultIcon[] =
5620 {'D','e','f','a','u','l','t','I','c','o','n',0};
5621 static const WCHAR szCurVer[] =
5622 {'C','u','r','V','e','r',0};
5624 /* check if already registered */
5625 RegCreateKeyExW(HKEY_CLASSES_ROOT, progid->ProgID, 0, NULL, 0,
5626 KEY_ALL_ACCESS, NULL, &hkey, &disp );
5627 if (disp == REG_OPENED_EXISTING_KEY)
5629 TRACE("Key already registered\n");
5634 TRACE("Registering Parent %s index %i\n",
5635 debugstr_w(package->progids[progid->ParentIndex].ProgID),
5636 progid->ParentIndex);
5637 rc = register_progid(package,&package->progids[progid->ParentIndex],
5640 /* clsid is same as parent */
5641 RegCreateKeyW(hkey,szCLSID,&hkey2);
5642 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
5648 if (progid->Description)
5650 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid->Description,
5651 (strlenW(progid->Description)+1) * sizeof(WCHAR));
5654 if (progid->IconPath)
5656 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5657 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5658 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5662 /* write out the current version */
5663 if (progid->CurVerIndex >= 0)
5665 RegCreateKeyW(hkey,szCurVer,&hkey2);
5666 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5667 (LPVOID)package->progids[progid->CurVerIndex].ProgID,
5668 (strlenW(package->progids[progid->CurVerIndex].ProgID)+1) *
5678 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
5684 return ERROR_INVALID_HANDLE;
5686 load_classes_and_such(package);
5688 for (i = 0; i < package->loaded_progids; i++)
5690 WCHAR clsid[0x1000];
5692 /* check if this progid is to be installed */
5694 if (!package->progids[i].InstallMe)
5696 TRACE("progid %s not scheduled to be installed\n",
5697 debugstr_w(package->progids[i].ProgID));
5701 TRACE("Registering progid %s index %i\n",
5702 debugstr_w(package->progids[i].ProgID), i);
5704 register_progid(package,&package->progids[i],clsid);
5706 uirow = MSI_CreateRecord(1);
5707 MSI_RecordSetStringW(uirow,1,package->progids[i].ProgID);
5708 ui_actiondata(package,szRegisterProgIdInfo,uirow);
5709 msiobj_release(&uirow->hdr);
5712 return ERROR_SUCCESS;
5715 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
5719 LPWSTR SystemFolder;
5723 static const WCHAR szInstaller[] =
5724 {'M','i','c','r','o','s','o','f','t','\\',
5725 'I','n','s','t','a','l','l','e','r','\\',0};
5726 static const WCHAR szFolder[] =
5727 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
5729 ProductCode = load_dynamic_property(package,szProductCode,&rc);
5733 SystemFolder = load_dynamic_property(package,szFolder,NULL);
5735 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
5737 create_full_pathW(dest);
5739 *FilePath = build_directory_name(2, dest, icon_name);
5741 HeapFree(GetProcessHeap(),0,SystemFolder);
5742 HeapFree(GetProcessHeap(),0,ProductCode);
5743 HeapFree(GetProcessHeap(),0,dest);
5744 return ERROR_SUCCESS;
5747 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
5751 MSIRECORD * row = 0;
5752 static const WCHAR Query[] =
5753 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5754 '`','S','h','o','r','t','c','u','t','`',0};
5760 return ERROR_INVALID_HANDLE;
5762 res = CoInitialize( NULL );
5765 ERR("CoInitialize failed\n");
5766 return ERROR_FUNCTION_FAILED;
5769 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5770 if (rc != ERROR_SUCCESS)
5771 return ERROR_SUCCESS;
5773 rc = MSI_ViewExecute(view, 0);
5774 if (rc != ERROR_SUCCESS)
5776 MSI_ViewClose(view);
5777 msiobj_release(&view->hdr);
5783 LPWSTR target_file, target_folder;
5784 WCHAR buffer[0x100];
5787 static const WCHAR szlnk[]={'.','l','n','k',0};
5789 rc = MSI_ViewFetch(view,&row);
5790 if (rc != ERROR_SUCCESS)
5797 MSI_RecordGetStringW(row,4,buffer,&sz);
5799 index = get_loaded_component(package,buffer);
5803 msiobj_release(&row->hdr);
5807 if (!ACTION_VerifyComponentForAction(package, index,
5808 INSTALLSTATE_LOCAL))
5810 TRACE("Skipping shortcut creation due to disabled component\n");
5811 msiobj_release(&row->hdr);
5813 package->components[index].Action =
5814 package->components[index].Installed;
5819 package->components[index].Action = INSTALLSTATE_LOCAL;
5821 ui_actiondata(package,szCreateShortcuts,row);
5823 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
5824 &IID_IShellLinkW, (LPVOID *) &sl );
5828 ERR("Is IID_IShellLink\n");
5829 msiobj_release(&row->hdr);
5833 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
5836 ERR("Is IID_IPersistFile\n");
5837 msiobj_release(&row->hdr);
5842 MSI_RecordGetStringW(row,2,buffer,&sz);
5843 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
5845 /* may be needed because of a bug somehwere else */
5846 create_full_pathW(target_folder);
5849 MSI_RecordGetStringW(row,3,buffer,&sz);
5850 reduce_to_longfilename(buffer);
5851 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
5852 strcatW(buffer,szlnk);
5853 target_file = build_directory_name(2, target_folder, buffer);
5854 HeapFree(GetProcessHeap(),0,target_folder);
5857 MSI_RecordGetStringW(row,5,buffer,&sz);
5858 if (strchrW(buffer,'['))
5861 deformat_string(package,buffer,&deformated);
5862 IShellLinkW_SetPath(sl,deformated);
5863 HeapFree(GetProcessHeap(),0,deformated);
5868 FIXME("poorly handled shortcut format, advertised shortcut\n");
5869 keypath = strdupW(package->components[index].FullKeypath);
5870 IShellLinkW_SetPath(sl,keypath);
5871 HeapFree(GetProcessHeap(),0,keypath);
5874 if (!MSI_RecordIsNull(row,6))
5878 MSI_RecordGetStringW(row,6,buffer,&sz);
5879 deformat_string(package,buffer,&deformated);
5880 IShellLinkW_SetArguments(sl,deformated);
5881 HeapFree(GetProcessHeap(),0,deformated);
5884 if (!MSI_RecordIsNull(row,7))
5887 deformated = load_dynamic_stringW(row,7);
5888 IShellLinkW_SetDescription(sl,deformated);
5889 HeapFree(GetProcessHeap(),0,deformated);
5892 if (!MSI_RecordIsNull(row,8))
5893 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
5895 if (!MSI_RecordIsNull(row,9))
5901 MSI_RecordGetStringW(row,9,buffer,&sz);
5903 build_icon_path(package,buffer,&Path);
5904 index = MSI_RecordGetInteger(row,10);
5906 IShellLinkW_SetIconLocation(sl,Path,index);
5907 HeapFree(GetProcessHeap(),0,Path);
5910 if (!MSI_RecordIsNull(row,11))
5911 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
5913 if (!MSI_RecordIsNull(row,12))
5917 MSI_RecordGetStringW(row,12,buffer,&sz);
5918 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
5919 IShellLinkW_SetWorkingDirectory(sl,Path);
5920 HeapFree(GetProcessHeap(), 0, Path);
5923 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
5924 IPersistFile_Save(pf,target_file,FALSE);
5926 HeapFree(GetProcessHeap(),0,target_file);
5928 IPersistFile_Release( pf );
5929 IShellLinkW_Release( sl );
5931 msiobj_release(&row->hdr);
5933 MSI_ViewClose(view);
5934 msiobj_release(&view->hdr);
5944 * 99% of the work done here is only done for
5945 * advertised installs. However this is where the
5946 * Icon table is processed and written out
5947 * so that is what I am going to do here.
5949 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
5953 MSIRECORD * row = 0;
5954 static const WCHAR Query[]=
5955 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5956 '`','I','c','o','n','`',0};
5958 /* for registry stuff */
5962 static const WCHAR szProductName[] =
5963 {'P','r','o','d','u','c','t','N','a','m','e',0};
5964 static const WCHAR szPackageCode[] =
5965 {'P','a','c','k','a','g','e','C','o','d','e',0};
5968 MSIHANDLE hDb, hSumInfo;
5971 return ERROR_INVALID_HANDLE;
5973 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5974 if (rc != ERROR_SUCCESS)
5977 rc = MSI_ViewExecute(view, 0);
5978 if (rc != ERROR_SUCCESS)
5980 MSI_ViewClose(view);
5981 msiobj_release(&view->hdr);
5988 WCHAR *FilePath=NULL;
5989 WCHAR *FileName=NULL;
5992 rc = MSI_ViewFetch(view,&row);
5993 if (rc != ERROR_SUCCESS)
5999 FileName = load_dynamic_stringW(row,1);
6002 ERR("Unable to get FileName\n");
6003 msiobj_release(&row->hdr);
6007 build_icon_path(package,FileName,&FilePath);
6009 HeapFree(GetProcessHeap(),0,FileName);
6011 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
6013 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
6014 FILE_ATTRIBUTE_NORMAL, NULL);
6016 if (the_file == INVALID_HANDLE_VALUE)
6018 ERR("Unable to create file %s\n",debugstr_w(FilePath));
6019 msiobj_release(&row->hdr);
6020 HeapFree(GetProcessHeap(),0,FilePath);
6028 rc = MSI_RecordReadStream(row,2,buffer,&sz);
6029 if (rc != ERROR_SUCCESS)
6031 ERR("Failed to get stream\n");
6032 CloseHandle(the_file);
6033 DeleteFileW(FilePath);
6036 WriteFile(the_file,buffer,sz,&write,NULL);
6037 } while (sz == 1024);
6039 HeapFree(GetProcessHeap(),0,FilePath);
6041 CloseHandle(the_file);
6042 msiobj_release(&row->hdr);
6044 MSI_ViewClose(view);
6045 msiobj_release(&view->hdr);
6048 /* ok there is a lot more done here but i need to figure out what */
6049 productcode = load_dynamic_property(package,szProductCode,&rc);
6053 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
6054 if (rc != ERROR_SUCCESS)
6057 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6058 if (rc != ERROR_SUCCESS)
6062 buffer = load_dynamic_property(package,szProductName,NULL);
6063 size = strlenW(buffer)*sizeof(WCHAR);
6064 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
6065 HeapFree(GetProcessHeap(),0,buffer);
6066 FIXME("Need to write more keys to the user registry\n");
6068 hDb= alloc_msihandle( &package->db->hdr );
6069 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
6070 MsiCloseHandle(hDb);
6071 if (rc == ERROR_SUCCESS)
6073 WCHAR guidbuffer[0x200];
6075 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
6077 if (rc == ERROR_SUCCESS)
6079 WCHAR squashed[GUID_SIZE];
6080 /* for now we only care about the first guid */
6081 LPWSTR ptr = strchrW(guidbuffer,';');
6083 squash_guid(guidbuffer,squashed);
6084 size = strlenW(squashed)*sizeof(WCHAR);
6085 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
6090 ERR("Unable to query Revision_Number... \n");
6093 MsiCloseHandle(hSumInfo);
6097 ERR("Unable to open Summary Information\n");
6103 HeapFree(GetProcessHeap(),0,productcode);
6110 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
6114 MSIRECORD * row = 0;
6115 static const WCHAR ExecSeqQuery[] =
6116 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6117 '`','I','n','i','F','i','l','e','`',0};
6118 static const WCHAR szWindowsFolder[] =
6119 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
6121 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6122 if (rc != ERROR_SUCCESS)
6124 TRACE("no IniFile table\n");
6125 return ERROR_SUCCESS;
6128 rc = MSI_ViewExecute(view, 0);
6129 if (rc != ERROR_SUCCESS)
6131 MSI_ViewClose(view);
6132 msiobj_release(&view->hdr);
6138 LPWSTR component,filename,dirproperty,section,key,value,identifier;
6139 LPWSTR deformated_section, deformated_key, deformated_value;
6140 LPWSTR folder, fullname = NULL;
6142 INT component_index,action;
6144 rc = MSI_ViewFetch(view,&row);
6145 if (rc != ERROR_SUCCESS)
6151 component = load_dynamic_stringW(row, 8);
6152 component_index = get_loaded_component(package,component);
6153 HeapFree(GetProcessHeap(),0,component);
6155 if (!ACTION_VerifyComponentForAction(package, component_index,
6156 INSTALLSTATE_LOCAL))
6158 TRACE("Skipping ini file due to disabled component\n");
6159 msiobj_release(&row->hdr);
6161 package->components[component_index].Action =
6162 package->components[component_index].Installed;
6167 package->components[component_index].Action = INSTALLSTATE_LOCAL;
6169 identifier = load_dynamic_stringW(row,1);
6170 filename = load_dynamic_stringW(row,2);
6171 dirproperty = load_dynamic_stringW(row,3);
6172 section = load_dynamic_stringW(row,4);
6173 key = load_dynamic_stringW(row,5);
6174 value = load_dynamic_stringW(row,6);
6175 action = MSI_RecordGetInteger(row,7);
6177 deformat_string(package,section,&deformated_section);
6178 deformat_string(package,key,&deformated_key);
6179 deformat_string(package,value,&deformated_value);
6183 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
6185 folder = load_dynamic_property(package,dirproperty,NULL);
6188 folder = load_dynamic_property(package, szWindowsFolder, NULL);
6192 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
6196 fullname = build_directory_name(3, folder, filename, NULL);
6200 TRACE("Adding value %s to section %s in %s\n",
6201 debugstr_w(deformated_key), debugstr_w(deformated_section),
6202 debugstr_w(fullname));
6203 WritePrivateProfileStringW(deformated_section, deformated_key,
6204 deformated_value, fullname);
6206 else if (action == 1)
6209 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
6210 returned, 10, fullname);
6211 if (returned[0] == 0)
6213 TRACE("Adding value %s to section %s in %s\n",
6214 debugstr_w(deformated_key), debugstr_w(deformated_section),
6215 debugstr_w(fullname));
6217 WritePrivateProfileStringW(deformated_section, deformated_key,
6218 deformated_value, fullname);
6221 else if (action == 3)
6223 FIXME("Append to existing section not yet implemented\n");
6226 uirow = MSI_CreateRecord(4);
6227 MSI_RecordSetStringW(uirow,1,identifier);
6228 MSI_RecordSetStringW(uirow,2,deformated_section);
6229 MSI_RecordSetStringW(uirow,3,deformated_key);
6230 MSI_RecordSetStringW(uirow,4,deformated_value);
6231 ui_actiondata(package,szWriteIniValues,uirow);
6232 msiobj_release( &uirow->hdr );
6234 HeapFree(GetProcessHeap(),0,identifier);
6235 HeapFree(GetProcessHeap(),0,fullname);
6236 HeapFree(GetProcessHeap(),0,filename);
6237 HeapFree(GetProcessHeap(),0,key);
6238 HeapFree(GetProcessHeap(),0,value);
6239 HeapFree(GetProcessHeap(),0,section);
6240 HeapFree(GetProcessHeap(),0,dirproperty);
6241 HeapFree(GetProcessHeap(),0,folder);
6242 HeapFree(GetProcessHeap(),0,deformated_key);
6243 HeapFree(GetProcessHeap(),0,deformated_value);
6244 HeapFree(GetProcessHeap(),0,deformated_section);
6245 msiobj_release(&row->hdr);
6247 MSI_ViewClose(view);
6248 msiobj_release(&view->hdr);
6252 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
6256 MSIRECORD * row = 0;
6257 static const WCHAR ExecSeqQuery[] =
6258 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6259 '`','S','e','l','f','R','e','g','`',0};
6261 static const WCHAR ExeStr[] =
6262 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
6263 static const WCHAR close[] = {'\"',0};
6265 PROCESS_INFORMATION info;
6268 memset(&si,0,sizeof(STARTUPINFOW));
6270 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6271 if (rc != ERROR_SUCCESS)
6273 TRACE("no SelfReg table\n");
6274 return ERROR_SUCCESS;
6277 rc = MSI_ViewExecute(view, 0);
6278 if (rc != ERROR_SUCCESS)
6280 MSI_ViewClose(view);
6281 msiobj_release(&view->hdr);
6291 rc = MSI_ViewFetch(view,&row);
6292 if (rc != ERROR_SUCCESS)
6298 filename = load_dynamic_stringW(row,1);
6299 index = get_loaded_file(package,filename);
6303 ERR("Unable to find file id %s\n",debugstr_w(filename));
6304 HeapFree(GetProcessHeap(),0,filename);
6305 msiobj_release(&row->hdr);
6308 HeapFree(GetProcessHeap(),0,filename);
6310 len = strlenW(ExeStr);
6311 len += strlenW(package->files[index].TargetPath);
6314 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
6315 strcpyW(filename,ExeStr);
6316 strcatW(filename,package->files[index].TargetPath);
6317 strcatW(filename,close);
6319 TRACE("Registering %s\n",debugstr_w(filename));
6320 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
6321 c_colon, &si, &info);
6324 msi_dialog_check_messages(info.hProcess);
6326 HeapFree(GetProcessHeap(),0,filename);
6327 msiobj_release(&row->hdr);
6329 MSI_ViewClose(view);
6330 msiobj_release(&view->hdr);
6334 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
6343 return ERROR_INVALID_HANDLE;
6345 productcode = load_dynamic_property(package,szProductCode,&rc);
6349 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
6350 if (rc != ERROR_SUCCESS)
6353 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
6354 if (rc != ERROR_SUCCESS)
6357 /* here the guids are base 85 encoded */
6358 for (i = 0; i < package->loaded_features; i++)
6364 BOOL absent = FALSE;
6366 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL) &&
6367 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_SOURCE) &&
6368 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_ADVERTISED))
6371 size = package->features[i].ComponentCount*21;
6373 if (package->features[i].Feature_Parent[0])
6374 size += strlenW(package->features[i].Feature_Parent)+2;
6376 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
6379 for (j = 0; j < package->features[i].ComponentCount; j++)
6382 memset(buf,0,sizeof(buf));
6383 if (package->components
6384 [package->features[i].Components[j]].ComponentId[0]!=0)
6386 TRACE("From %s\n",debugstr_w(package->components
6387 [package->features[i].Components[j]].ComponentId));
6388 CLSIDFromString(package->components
6389 [package->features[i].Components[j]].ComponentId,
6391 encode_base85_guid(&clsid,buf);
6392 TRACE("to %s\n",debugstr_w(buf));
6396 if (package->features[i].Feature_Parent[0])
6398 static const WCHAR sep[] = {'\2',0};
6400 strcatW(data,package->features[i].Feature_Parent);
6403 size = (strlenW(data)+1)*sizeof(WCHAR);
6404 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
6406 HeapFree(GetProcessHeap(),0,data);
6410 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
6411 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6412 (LPSTR)package->features[i].Feature_Parent,size);
6416 size = (strlenW(package->features[i].Feature_Parent)+2)*
6418 data = HeapAlloc(GetProcessHeap(),0,size);
6420 strcpyW(&data[1],package->features[i].Feature_Parent);
6421 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6423 HeapFree(GetProcessHeap(),0,data);
6430 HeapFree(GetProcessHeap(), 0, productcode);
6434 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
6441 static WCHAR szNONE[] = {0};
6442 static const WCHAR szWindowsInstaler[] =
6443 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
6444 static const WCHAR szPropKeys[][80] =
6446 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
6447 {'A','R','P','C','O','N','T','A','C','T',0},
6448 {'A','R','P','C','O','M','M','E','N','T','S',0},
6449 {'P','r','o','d','u','c','t','N','a','m','e',0},
6450 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
6451 {'A','R','P','H','E','L','P','L','I','N','K',0},
6452 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
6453 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
6454 {'S','o','u','r','c','e','D','i','r',0},
6455 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
6456 {'A','R','P','R','E','A','D','M','E',0},
6457 {'A','R','P','S','I','Z','E',0},
6458 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
6459 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
6463 static const WCHAR szRegKeys[][80] =
6465 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
6466 {'C','o','n','t','a','c','t',0},
6467 {'C','o','m','m','e','n','t','s',0},
6468 {'D','i','s','p','l','a','y','N','a','m','e',0},
6469 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
6470 {'H','e','l','p','L','i','n','k',0},
6471 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
6472 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
6473 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
6474 {'P','u','b','l','i','s','h','e','r',0},
6475 {'R','e','a','d','m','e',0},
6476 {'S','i','z','e',0},
6477 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
6478 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
6482 static const WCHAR installerPathFmt[] = {
6484 'I','n','s','t','a','l','l','e','r','\\',0};
6485 static const WCHAR fmt[] = {
6487 'I','n','s','t','a','l','l','e','r','\\',
6488 '%','x','.','m','s','i',0};
6489 static const WCHAR szLocalPackage[]=
6490 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
6491 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
6495 return ERROR_INVALID_HANDLE;
6497 productcode = load_dynamic_property(package,szProductCode,&rc);
6501 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
6502 if (rc != ERROR_SUCCESS)
6505 /* dump all the info i can grab */
6506 FIXME("Flesh out more information \n");
6509 while (szPropKeys[i][0]!=0)
6511 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
6512 if (rc != ERROR_SUCCESS)
6514 size = strlenW(buffer)*sizeof(WCHAR);
6515 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
6521 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
6523 /* copy the package locally */
6524 num = GetTickCount() & 0xffff;
6528 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
6529 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
6533 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
6534 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
6535 if (handle != INVALID_HANDLE_VALUE)
6537 CloseHandle(handle);
6540 if (GetLastError() != ERROR_FILE_EXISTS &&
6541 GetLastError() != ERROR_SHARING_VIOLATION)
6543 if (!(++num & 0xffff)) num = 1;
6544 sprintfW(packagefile,fmt,num);
6545 } while (num != start);
6547 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
6548 create_full_pathW(path);
6549 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
6550 if (!CopyFileW(package->PackagePath,packagefile,FALSE))
6551 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
6552 debugstr_w(package->PackagePath), debugstr_w(packagefile),
6554 size = strlenW(packagefile)*sizeof(WCHAR);
6555 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
6558 HeapFree(GetProcessHeap(),0,productcode);
6561 return ERROR_SUCCESS;
6564 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
6569 return ERROR_INVALID_HANDLE;
6571 rc = execute_script(package,INSTALL_SCRIPT);
6576 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
6581 return ERROR_INVALID_HANDLE;
6583 /* turn off scheduleing */
6584 package->script->CurrentlyScripting= FALSE;
6586 /* first do the same as an InstallExecute */
6587 rc = ACTION_InstallExecute(package);
6588 if (rc != ERROR_SUCCESS)
6591 /* then handle Commit Actions */
6592 rc = execute_script(package,COMMIT_SCRIPT);
6597 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
6599 static const WCHAR RunOnce[] = {
6600 'S','o','f','t','w','a','r','e','\\',
6601 'M','i','c','r','o','s','o','f','t','\\',
6602 'W','i','n','d','o','w','s','\\',
6603 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6604 'R','u','n','O','n','c','e',0};
6605 static const WCHAR InstallRunOnce[] = {
6606 'S','o','f','t','w','a','r','e','\\',
6607 'M','i','c','r','o','s','o','f','t','\\',
6608 'W','i','n','d','o','w','s','\\',
6609 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6610 'I','n','s','t','a','l','l','e','r','\\',
6611 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
6613 static const WCHAR msiexec_fmt[] = {
6615 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
6616 '\"','%','s','\"',0};
6617 static const WCHAR install_fmt[] = {
6618 '/','I',' ','\"','%','s','\"',' ',
6619 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
6620 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
6621 WCHAR buffer[256], sysdir[MAX_PATH];
6624 WCHAR squished_pc[100];
6627 static const WCHAR szLUS[] = {
6628 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
6629 static const WCHAR szSourceList[] = {
6630 'S','o','u','r','c','e','L','i','s','t',0};
6631 static const WCHAR szPackageName[] = {
6632 'P','a','c','k','a','g','e','N','a','m','e',0};
6635 return ERROR_INVALID_HANDLE;
6637 productcode = load_dynamic_property(package,szProductCode,&rc);
6641 squash_guid(productcode,squished_pc);
6643 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
6644 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
6645 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
6648 size = strlenW(buffer)*sizeof(WCHAR);
6649 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6652 TRACE("Reboot command %s\n",debugstr_w(buffer));
6654 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
6655 sprintfW(buffer,install_fmt,productcode,squished_pc);
6657 size = strlenW(buffer)*sizeof(WCHAR);
6658 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6661 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6662 if (rc == ERROR_SUCCESS)
6666 RegCreateKeyW(hukey, szSourceList, &hukey2);
6667 buf = load_dynamic_property(package,cszSourceDir,NULL);
6668 size = strlenW(buf)*sizeof(WCHAR);
6669 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
6670 HeapFree(GetProcessHeap(),0,buf);
6672 buf = strrchrW(package->PackagePath,'\\');
6676 size = strlenW(buf)*sizeof(WCHAR);
6677 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
6680 RegCloseKey(hukey2);
6682 HeapFree(GetProcessHeap(),0,productcode);
6684 return ERROR_INSTALL_SUSPEND;
6687 UINT ACTION_ResolveSource(MSIPACKAGE* package)
6690 * we are currently doing what should be done here in the top level Install
6691 * however for Adminastrative and uninstalls this step will be needed
6693 return ERROR_SUCCESS;
6696 static LPWSTR create_component_advertise_string(MSIPACKAGE* package,
6697 MSICOMPONENT* component, LPCWSTR feature)
6699 LPWSTR productid=NULL;
6701 WCHAR productid_85[21];
6702 WCHAR component_85[21];
6704 * I have a fair bit of confusion as to when a < is used and when a > is
6705 * used. I do not think i have it right...
6707 * Ok it appears that the > is used if there is a guid for the compoenent
6708 * and the < is used if not.
6710 static WCHAR fmt1[] = {'%','s','%','s','<',0,0};
6711 static WCHAR fmt2[] = {'%','s','%','s','>','%','s',0,0};
6712 LPWSTR output = NULL;
6715 memset(productid_85,0,sizeof(productid_85));
6716 memset(component_85,0,sizeof(component_85));
6718 productid = load_dynamic_property(package,szProductCode,NULL);
6719 CLSIDFromString(productid, &clsid);
6721 encode_base85_guid(&clsid,productid_85);
6723 CLSIDFromString(component->ComponentId, &clsid);
6724 encode_base85_guid(&clsid,component_85);
6726 TRACE("Doing something with this... %s %s %s\n",
6727 debugstr_w(productid_85), debugstr_w(feature),
6728 debugstr_w(component_85));
6730 sz = lstrlenW(productid_85) + lstrlenW(feature);
6732 sz += lstrlenW(component_85);
6735 sz *= sizeof(WCHAR);
6737 output = HeapAlloc(GetProcessHeap(),0,sz);
6738 memset(output,0,sz);
6741 sprintfW(output,fmt2,productid_85,feature,component_85);
6743 sprintfW(output,fmt1,productid_85,feature);
6745 HeapFree(GetProcessHeap(),0,productid);
6750 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
6751 MSICOMPONENT* component, MSIEXTENSION* extension,
6752 MSIVERB* verb, INT* Sequence )
6756 static const WCHAR szShell[] = {'s','h','e','l','l',0};
6757 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
6758 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
6759 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
6764 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
6766 TRACE("Making Key %s\n",debugstr_w(keyname));
6767 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6768 size = strlenW(component->FullKeypath);
6770 size += strlenW(verb->Argument);
6773 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6775 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
6777 sprintfW(command, fmt2, component->FullKeypath);
6779 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)command, (strlenW(command)+1)*
6781 HeapFree(GetProcessHeap(),0,command);
6783 advertise = create_component_advertise_string(package, component,
6784 package->features[extension->FeatureIndex].Feature);
6786 size = strlenW(advertise);
6789 size += strlenW(verb->Argument);
6792 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6793 memset(command,0,size*sizeof(WCHAR));
6795 strcpyW(command,advertise);
6798 static const WCHAR szSpace[] = {' ',0};
6799 strcatW(command,szSpace);
6800 strcatW(command,verb->Argument);
6803 RegSetValueExW(key, szCommand, 0, REG_MULTI_SZ, (LPBYTE)command,
6804 (strlenW(command)+2)*sizeof(WCHAR));
6807 HeapFree(GetProcessHeap(),0,keyname);
6808 HeapFree(GetProcessHeap(),0,advertise);
6809 HeapFree(GetProcessHeap(),0,command);
6813 keyname = build_directory_name(3, progid, szShell, verb->Verb);
6814 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6815 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Command,
6816 (strlenW(verb->Command)+1) *sizeof(WCHAR));
6818 HeapFree(GetProcessHeap(),0,keyname);
6821 if (verb->Sequence != MSI_NULL_INTEGER)
6823 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
6825 *Sequence = verb->Sequence;
6826 keyname = build_directory_name(2, progid, szShell);
6827 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6828 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Verb,
6829 (strlenW(verb->Verb)+1) *sizeof(WCHAR));
6831 HeapFree(GetProcessHeap(),0,keyname);
6834 return ERROR_SUCCESS;
6837 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
6839 static const WCHAR szContentType[] =
6840 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
6846 return ERROR_INVALID_HANDLE;
6848 load_classes_and_such(package);
6850 for (i = 0; i < package->loaded_extensions; i++)
6852 WCHAR extension[257];
6855 index = package->extensions[i].ComponentIndex;
6856 f_index = package->extensions[i].FeatureIndex;
6862 * yes. MSDN says that these are based on _Feature_ not on
6863 * Component. So verify the feature is to be installed
6865 if ((!ACTION_VerifyFeatureForAction(package, f_index,
6866 INSTALLSTATE_LOCAL)) &&
6867 (!ACTION_VerifyFeatureForAction(package, f_index,
6868 INSTALLSTATE_ADVERTISED)))
6870 TRACE("Skipping extension %s reg due to disabled feature %s\n",
6871 debugstr_w(package->extensions[i].Extension),
6872 debugstr_w(package->features[f_index].Feature));
6877 TRACE("Registering extension %s index %i\n",
6878 debugstr_w(package->extensions[i].Extension), i);
6880 package->extensions[i].Installed = TRUE;
6882 if (package->extensions[i].ProgIDIndex >= 0)
6883 mark_progid_for_install(package, package->extensions[i].ProgIDIndex);
6885 if (package->extensions[i].MIMEIndex >= 0)
6886 mark_mime_for_install(package, package->extensions[i].MIMEIndex);
6890 strcatW(extension,package->extensions[i].Extension);
6892 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
6894 if (package->extensions[i].MIMEIndex >= 0)
6896 RegSetValueExW(hkey,szContentType,0,REG_SZ,
6897 (LPVOID)package->mimes[package->extensions[i].
6898 MIMEIndex].ContentType,
6899 (strlenW(package->mimes[package->extensions[i].
6900 MIMEIndex].ContentType)+1)*sizeof(WCHAR));
6903 if (package->extensions[i].ProgIDIndex >= 0 ||
6904 package->extensions[i].ProgIDText)
6906 static const WCHAR szSN[] =
6907 {'\\','S','h','e','l','l','N','e','w',0};
6912 INT Sequence = MSI_NULL_INTEGER;
6914 if (package->extensions[i].ProgIDIndex >= 0)
6915 progid = package->progids[package->extensions[i].
6916 ProgIDIndex].ProgID;
6918 progid = package->extensions[i].ProgIDText;
6920 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
6921 (strlenW(progid)+1)*sizeof(WCHAR));
6923 newkey = HeapAlloc(GetProcessHeap(),0,
6924 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
6926 strcpyW(newkey,progid);
6927 strcatW(newkey,szSN);
6928 RegCreateKeyW(hkey,newkey,&hkey2);
6931 HeapFree(GetProcessHeap(),0,newkey);
6933 /* do all the verbs */
6934 for (v = 0; v < package->extensions[i].VerbCount; v++)
6935 register_verb(package, progid,
6936 &package->components[index],
6937 &package->extensions[i],
6938 &package->verbs[package->extensions[i].Verbs[v]],
6944 uirow = MSI_CreateRecord(1);
6945 MSI_RecordSetStringW(uirow,1,package->extensions[i].Extension);
6946 ui_actiondata(package,szRegisterExtensionInfo,uirow);
6947 msiobj_release(&uirow->hdr);
6950 return ERROR_SUCCESS;
6953 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
6955 static const WCHAR szExten[] =
6956 {'E','x','t','e','n','s','i','o','n',0 };
6962 return ERROR_INVALID_HANDLE;
6964 load_classes_and_such(package);
6966 for (i = 0; i < package->loaded_mimes; i++)
6968 WCHAR extension[257];
6971 static const WCHAR fmt[] =
6972 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
6973 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
6977 * check if the MIME is to be installed. Either as requesed by an
6978 * extension or Class
6980 package->mimes[i].InstallMe = ((package->mimes[i].InstallMe) ||
6981 (package->mimes[i].ClassIndex >= 0 &&
6982 package->classes[package->mimes[i].ClassIndex].Installed) ||
6983 (package->mimes[i].ExtensionIndex >=0 &&
6984 package->extensions[package->mimes[i].ExtensionIndex].Installed));
6986 if (!package->mimes[i].InstallMe)
6988 TRACE("MIME %s not scheduled to be installed\n",
6989 debugstr_w(package->mimes[i].ContentType));
6993 mime = package->mimes[i].ContentType;
6994 exten = package->extensions[package->mimes[i].ExtensionIndex].Extension;
6997 strcatW(extension,exten);
6999 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
7001 sprintfW(key,fmt,mime);
7002 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
7003 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
7004 (strlenW(extension)+1)*sizeof(WCHAR));
7006 HeapFree(GetProcessHeap(),0,key);
7008 if (package->mimes[i].CLSID[0])
7010 FIXME("Handle non null for field 3\n");
7015 uirow = MSI_CreateRecord(2);
7016 MSI_RecordSetStringW(uirow,1,package->mimes[i].ContentType);
7017 MSI_RecordSetStringW(uirow,2,exten);
7018 ui_actiondata(package,szRegisterMIMEInfo,uirow);
7019 msiobj_release(&uirow->hdr);
7022 return ERROR_SUCCESS;
7025 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
7027 static const WCHAR szProductID[]=
7028 {'P','r','o','d','u','c','t','I','D',0};
7036 static const WCHAR szPropKeys[][80] =
7038 {'P','r','o','d','u','c','t','I','D',0},
7039 {'U','S','E','R','N','A','M','E',0},
7040 {'C','O','M','P','A','N','Y','N','A','M','E',0},
7044 static const WCHAR szRegKeys[][80] =
7046 {'P','r','o','d','u','c','t','I','D',0},
7047 {'R','e','g','O','w','n','e','r',0},
7048 {'R','e','g','C','o','m','p','a','n','y',0},
7053 return ERROR_INVALID_HANDLE;
7055 productid = load_dynamic_property(package,szProductID,&rc);
7057 return ERROR_SUCCESS;
7059 productcode = load_dynamic_property(package,szProductCode,&rc);
7063 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
7064 if (rc != ERROR_SUCCESS)
7068 while (szPropKeys[i][0]!=0)
7070 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
7071 if (rc == ERROR_SUCCESS)
7073 size = strlenW(buffer)*sizeof(WCHAR);
7074 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
7077 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
7082 HeapFree(GetProcessHeap(),0,productcode);
7083 HeapFree(GetProcessHeap(),0,productid);
7086 return ERROR_SUCCESS;
7090 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
7093 rc = ACTION_ProcessExecSequence(package,FALSE);
7099 * Code based off of code located here
7100 * http://www.codeproject.com/gdi/fontnamefromfile.asp
7102 * Using string index 4 (full font name) instead of 1 (family name)
7104 static LPWSTR load_ttfname_from(LPCWSTR filename)
7110 typedef struct _tagTT_OFFSET_TABLE{
7111 USHORT uMajorVersion;
7112 USHORT uMinorVersion;
7113 USHORT uNumOfTables;
7114 USHORT uSearchRange;
7115 USHORT uEntrySelector;
7119 typedef struct _tagTT_TABLE_DIRECTORY{
7120 char szTag[4]; /* table name */
7121 ULONG uCheckSum; /* Check sum */
7122 ULONG uOffset; /* Offset from beginning of file */
7123 ULONG uLength; /* length of the table in bytes */
7124 }TT_TABLE_DIRECTORY;
7126 typedef struct _tagTT_NAME_TABLE_HEADER{
7127 USHORT uFSelector; /* format selector. Always 0 */
7128 USHORT uNRCount; /* Name Records count */
7129 USHORT uStorageOffset; /* Offset for strings storage,
7130 * from start of the table */
7131 }TT_NAME_TABLE_HEADER;
7133 typedef struct _tagTT_NAME_RECORD{
7138 USHORT uStringLength;
7139 USHORT uStringOffset; /* from start of storage area */
7142 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
7143 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
7145 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
7146 FILE_ATTRIBUTE_NORMAL, 0 );
7147 if (handle != INVALID_HANDLE_VALUE)
7149 TT_TABLE_DIRECTORY tblDir;
7150 BOOL bFound = FALSE;
7151 TT_OFFSET_TABLE ttOffsetTable;
7153 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
7154 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
7155 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
7156 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
7158 if (ttOffsetTable.uMajorVersion != 1 ||
7159 ttOffsetTable.uMinorVersion != 0)
7162 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
7164 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
7165 if (strncmp(tblDir.szTag,"name",4)==0)
7168 tblDir.uLength = SWAPLONG(tblDir.uLength);
7169 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
7176 TT_NAME_TABLE_HEADER ttNTHeader;
7177 TT_NAME_RECORD ttRecord;
7179 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
7180 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
7183 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
7184 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
7186 for(i=0; i<ttNTHeader.uNRCount; i++)
7188 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
7189 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
7190 /* 4 is the Full Font Name */
7191 if(ttRecord.uNameID == 4)
7195 static const LPSTR tt = " (TrueType)";
7197 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
7198 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
7199 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
7200 SetFilePointer(handle, tblDir.uOffset +
7201 ttRecord.uStringOffset +
7202 ttNTHeader.uStorageOffset,
7204 buf = HeapAlloc(GetProcessHeap(), 0,
7205 ttRecord.uStringLength + 1 + strlen(tt));
7206 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
7207 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
7208 if (strlen(buf) > 0)
7211 ret = strdupAtoW(buf);
7212 HeapFree(GetProcessHeap(),0,buf);
7216 HeapFree(GetProcessHeap(),0,buf);
7217 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
7221 CloseHandle(handle);
7224 ERR("Unable to open font file %s\n", debugstr_w(filename));
7226 TRACE("Returning fontname %s\n",debugstr_w(ret));
7230 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
7234 MSIRECORD * row = 0;
7235 static const WCHAR ExecSeqQuery[] =
7236 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7237 '`','F','o','n','t','`',0};
7238 static const WCHAR regfont1[] =
7239 {'S','o','f','t','w','a','r','e','\\',
7240 'M','i','c','r','o','s','o','f','t','\\',
7241 'W','i','n','d','o','w','s',' ','N','T','\\',
7242 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7243 'F','o','n','t','s',0};
7244 static const WCHAR regfont2[] =
7245 {'S','o','f','t','w','a','r','e','\\',
7246 'M','i','c','r','o','s','o','f','t','\\',
7247 'W','i','n','d','o','w','s','\\',
7248 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7249 'F','o','n','t','s',0};
7253 TRACE("%p\n", package);
7255 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7256 if (rc != ERROR_SUCCESS)
7258 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
7259 return ERROR_SUCCESS;
7262 rc = MSI_ViewExecute(view, 0);
7263 if (rc != ERROR_SUCCESS)
7265 MSI_ViewClose(view);
7266 msiobj_release(&view->hdr);
7267 TRACE("MSI_ViewExecute returned %d\n", rc);
7268 return ERROR_SUCCESS;
7271 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
7272 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
7281 rc = MSI_ViewFetch(view,&row);
7282 if (rc != ERROR_SUCCESS)
7288 file = load_dynamic_stringW(row,1);
7289 index = get_loaded_file(package,file);
7292 ERR("Unable to load file\n");
7293 HeapFree(GetProcessHeap(),0,file);
7297 /* check to make sure that component is installed */
7298 if (!ACTION_VerifyComponentForAction(package,
7299 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
7301 TRACE("Skipping: Component not scheduled for install\n");
7302 HeapFree(GetProcessHeap(),0,file);
7304 msiobj_release(&row->hdr);
7309 if (MSI_RecordIsNull(row,2))
7310 name = load_ttfname_from(package->files[index].TargetPath);
7312 name = load_dynamic_stringW(row,2);
7316 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
7317 RegSetValueExW(hkey1,name,0,REG_SZ,
7318 (LPBYTE)package->files[index].FileName,size);
7319 RegSetValueExW(hkey2,name,0,REG_SZ,
7320 (LPBYTE)package->files[index].FileName,size);
7323 HeapFree(GetProcessHeap(),0,file);
7324 HeapFree(GetProcessHeap(),0,name);
7325 msiobj_release(&row->hdr);
7327 MSI_ViewClose(view);
7328 msiobj_release(&view->hdr);
7333 TRACE("returning %d\n", rc);
7337 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
7339 MSIPACKAGE *package = (MSIPACKAGE*)param;
7340 LPWSTR compgroupid=NULL;
7341 LPWSTR feature=NULL;
7343 LPWSTR qualifier = NULL;
7344 LPWSTR component = NULL;
7345 LPWSTR advertise = NULL;
7346 LPWSTR output = NULL;
7348 UINT rc = ERROR_SUCCESS;
7352 component = load_dynamic_stringW(rec,3);
7353 index = get_loaded_component(package,component);
7355 if (!ACTION_VerifyComponentForAction(package, index,
7356 INSTALLSTATE_LOCAL) &&
7357 !ACTION_VerifyComponentForAction(package, index,
7358 INSTALLSTATE_SOURCE) &&
7359 !ACTION_VerifyComponentForAction(package, index,
7360 INSTALLSTATE_ADVERTISED))
7362 TRACE("Skipping: Component %s not scheduled for install\n",
7363 debugstr_w(component));
7365 HeapFree(GetProcessHeap(),0,component);
7366 return ERROR_SUCCESS;
7369 compgroupid = load_dynamic_stringW(rec,1);
7371 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
7372 if (rc != ERROR_SUCCESS)
7375 text = load_dynamic_stringW(rec,4);
7376 qualifier = load_dynamic_stringW(rec,2);
7377 feature = load_dynamic_stringW(rec,5);
7379 advertise = create_component_advertise_string(package,
7380 &package->components[index], feature);
7382 sz = strlenW(advertise);
7385 sz += lstrlenW(text);
7388 sz *= sizeof(WCHAR);
7390 output = HeapAlloc(GetProcessHeap(),0,sz);
7391 memset(output,0,sz);
7392 strcpyW(output,advertise);
7395 strcatW(output,text);
7397 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
7398 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
7402 HeapFree(GetProcessHeap(),0,output);
7403 HeapFree(GetProcessHeap(),0,compgroupid);
7404 HeapFree(GetProcessHeap(),0,component);
7405 HeapFree(GetProcessHeap(),0,feature);
7406 HeapFree(GetProcessHeap(),0,text);
7407 HeapFree(GetProcessHeap(),0,qualifier);
7413 * At present I am ignorning the advertised components part of this and only
7414 * focusing on the qualified component sets
7416 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
7420 static const WCHAR ExecSeqQuery[] =
7421 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7422 '`','P','u','b','l','i','s','h',
7423 'C','o','m','p','o','n','e','n','t','`',0};
7425 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7426 if (rc != ERROR_SUCCESS)
7427 return ERROR_SUCCESS;
7429 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
7430 msiobj_release(&view->hdr);
7435 /* Msi functions that seem appropriate here */
7437 /***********************************************************************
7438 * MsiDoActionA (MSI.@)
7440 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
7445 TRACE(" exteral attempt at action %s\n",szAction);
7448 return ERROR_FUNCTION_FAILED;
7450 return ERROR_FUNCTION_FAILED;
7452 szwAction = strdupAtoW(szAction);
7455 return ERROR_FUNCTION_FAILED;
7458 rc = MsiDoActionW(hInstall, szwAction);
7459 HeapFree(GetProcessHeap(),0,szwAction);
7463 /***********************************************************************
7464 * MsiDoActionW (MSI.@)
7466 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
7468 MSIPACKAGE *package;
7469 UINT ret = ERROR_INVALID_HANDLE;
7471 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
7473 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7476 ret = ACTION_PerformUIAction(package,szAction);
7477 msiobj_release( &package->hdr );
7482 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
7483 LPSTR szPathBuf, DWORD* pcchPathBuf)
7489 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7492 return ERROR_FUNCTION_FAILED;
7494 return ERROR_FUNCTION_FAILED;
7496 szwFolder = strdupAtoW(szFolder);
7499 return ERROR_FUNCTION_FAILED;
7501 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7503 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7505 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7506 *pcchPathBuf, NULL, NULL );
7508 HeapFree(GetProcessHeap(),0,szwFolder);
7509 HeapFree(GetProcessHeap(),0,szwPathBuf);
7514 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7515 szPathBuf, DWORD* pcchPathBuf)
7518 UINT rc = ERROR_FUNCTION_FAILED;
7519 MSIPACKAGE *package;
7521 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7523 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7525 return ERROR_INVALID_HANDLE;
7526 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
7527 msiobj_release( &package->hdr );
7529 if (path && (strlenW(path) > *pcchPathBuf))
7531 *pcchPathBuf = strlenW(path)+1;
7532 rc = ERROR_MORE_DATA;
7536 *pcchPathBuf = strlenW(path)+1;
7537 strcpyW(szPathBuf,path);
7538 TRACE("Returning Path %s\n",debugstr_w(path));
7541 HeapFree(GetProcessHeap(),0,path);
7547 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
7548 LPSTR szPathBuf, DWORD* pcchPathBuf)
7554 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7557 return ERROR_FUNCTION_FAILED;
7559 return ERROR_FUNCTION_FAILED;
7561 szwFolder = strdupAtoW(szFolder);
7563 return ERROR_FUNCTION_FAILED;
7565 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7567 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7569 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7570 *pcchPathBuf, NULL, NULL );
7572 HeapFree(GetProcessHeap(),0,szwFolder);
7573 HeapFree(GetProcessHeap(),0,szwPathBuf);
7578 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7579 szPathBuf, DWORD* pcchPathBuf)
7582 UINT rc = ERROR_FUNCTION_FAILED;
7583 MSIPACKAGE *package;
7585 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7587 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7589 return ERROR_INVALID_HANDLE;
7590 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
7591 msiobj_release( &package->hdr );
7593 if (path && strlenW(path) > *pcchPathBuf)
7595 *pcchPathBuf = strlenW(path)+1;
7596 rc = ERROR_MORE_DATA;
7600 *pcchPathBuf = strlenW(path)+1;
7601 strcpyW(szPathBuf,path);
7602 TRACE("Returning Path %s\n",debugstr_w(path));
7605 HeapFree(GetProcessHeap(),0,path);
7611 /***********************************************************************
7612 * MsiSetTargetPathA (MSI.@)
7614 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
7615 LPCSTR szFolderPath)
7618 LPWSTR szwFolderPath;
7622 return ERROR_FUNCTION_FAILED;
7624 return ERROR_FUNCTION_FAILED;
7626 szwFolder = strdupAtoW(szFolder);
7628 return ERROR_FUNCTION_FAILED;
7630 szwFolderPath = strdupAtoW(szFolderPath);
7633 HeapFree(GetProcessHeap(),0,szwFolder);
7634 return ERROR_FUNCTION_FAILED;
7637 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
7639 HeapFree(GetProcessHeap(),0,szwFolder);
7640 HeapFree(GetProcessHeap(),0,szwFolderPath);
7645 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
7646 LPCWSTR szFolderPath)
7650 LPWSTR path2 = NULL;
7653 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
7656 return ERROR_INVALID_HANDLE;
7658 if (szFolderPath[0]==0)
7659 return ERROR_FUNCTION_FAILED;
7661 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
7662 return ERROR_FUNCTION_FAILED;
7664 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
7667 return ERROR_INVALID_PARAMETER;
7669 HeapFree(GetProcessHeap(),0,folder->Property);
7670 folder->Property = build_directory_name(2, szFolderPath, NULL);
7672 if (lstrcmpiW(path, folder->Property) == 0)
7675 * Resolved Target has not really changed, so just
7676 * set this folder and do not recalculate everything.
7678 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
7679 folder->ResolvedTarget = NULL;
7680 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
7681 HeapFree(GetProcessHeap(),0,path2);
7685 for (i = 0; i < package->loaded_folders; i++)
7687 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
7688 package->folders[i].ResolvedTarget=NULL;
7691 for (i = 0; i < package->loaded_folders; i++)
7693 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
7695 HeapFree(GetProcessHeap(),0,path2);
7698 HeapFree(GetProcessHeap(),0,path);
7700 return ERROR_SUCCESS;
7703 /***********************************************************************
7704 * MsiSetTargetPathW (MSI.@)
7706 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
7707 LPCWSTR szFolderPath)
7709 MSIPACKAGE *package;
7712 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
7714 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7715 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
7716 msiobj_release( &package->hdr );
7720 /***********************************************************************
7721 * MsiGetMode (MSI.@)
7723 * Returns an internal installer state (if it is running in a mode iRunMode)
7726 * hInstall [I] Handle to the installation
7727 * hRunMode [I] Checking run mode
7728 * MSIRUNMODE_ADMIN Administrative mode
7729 * MSIRUNMODE_ADVERTISE Advertisement mode
7730 * MSIRUNMODE_MAINTENANCE Maintenance mode
7731 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
7732 * MSIRUNMODE_LOGENABLED Log file is writing
7733 * MSIRUNMODE_OPERATIONS Operations in progress??
7734 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
7735 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
7736 * MSIRUNMODE_CABINET Files from cabinet are installed
7737 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
7738 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
7739 * MSIRUNMODE_RESERVED11 Reserved
7740 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
7741 * MSIRUNMODE_ZAWENABLED Demand installation is supported
7742 * MSIRUNMODE_RESERVED14 Reserved
7743 * MSIRUNMODE_RESERVED15 Reserved
7744 * MSIRUNMODE_SCHEDULED called from install script
7745 * MSIRUNMODE_ROLLBACK called from rollback script
7746 * MSIRUNMODE_COMMIT called from commit script
7749 * In the state: TRUE
7750 * Not in the state: FALSE
7754 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
7756 FIXME("STUB (iRunMode=%i)\n",iRunMode);
7760 /***********************************************************************
7761 * MsiSetFeatureStateA (MSI.@)
7763 * According to the docs, when this is called it immediately recalculates
7764 * all the component states as well
7766 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
7767 INSTALLSTATE iState)
7769 LPWSTR szwFeature = NULL;
7772 szwFeature = strdupAtoW(szFeature);
7775 return ERROR_FUNCTION_FAILED;
7777 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
7779 HeapFree(GetProcessHeap(),0,szwFeature);
7786 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
7787 INSTALLSTATE iState)
7790 UINT rc = ERROR_SUCCESS;
7792 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7794 index = get_loaded_feature(package,szFeature);
7796 return ERROR_UNKNOWN_FEATURE;
7798 if (iState == INSTALLSTATE_ADVERTISED &&
7799 package->features[index].Attributes &
7800 msidbFeatureAttributesDisallowAdvertise)
7801 return ERROR_FUNCTION_FAILED;
7803 package->features[index].ActionRequest= iState;
7804 package->features[index].Action= iState;
7806 ACTION_UpdateComponentStates(package,szFeature);
7808 /* update all the features that are children of this feature */
7809 for (i = 0; i < package->loaded_features; i++)
7811 if (strcmpW(szFeature, package->features[i].Feature_Parent) == 0)
7812 MSI_SetFeatureStateW(package, package->features[i].Feature, iState);
7818 /***********************************************************************
7819 * MsiSetFeatureStateW (MSI.@)
7821 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
7822 INSTALLSTATE iState)
7824 MSIPACKAGE* package;
7825 UINT rc = ERROR_SUCCESS;
7827 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7829 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7831 return ERROR_INVALID_HANDLE;
7833 rc = MSI_SetFeatureStateW(package,szFeature,iState);
7835 msiobj_release( &package->hdr );
7839 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
7840 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7842 LPWSTR szwFeature = NULL;
7845 szwFeature = strdupAtoW(szFeature);
7847 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
7849 HeapFree( GetProcessHeap(), 0 , szwFeature);
7854 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
7855 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7859 index = get_loaded_feature(package,szFeature);
7861 return ERROR_UNKNOWN_FEATURE;
7864 *piInstalled = package->features[index].Installed;
7867 *piAction = package->features[index].Action;
7869 TRACE("returning %i %i\n",*piInstalled,*piAction);
7871 return ERROR_SUCCESS;
7874 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
7875 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7877 MSIPACKAGE* package;
7880 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
7883 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7885 return ERROR_INVALID_HANDLE;
7886 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
7887 msiobj_release( &package->hdr );
7891 /***********************************************************************
7892 * MsiGetComponentStateA (MSI.@)
7894 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
7895 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7897 LPWSTR szwComponent= NULL;
7900 szwComponent= strdupAtoW(szComponent);
7902 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
7904 HeapFree( GetProcessHeap(), 0 , szwComponent);
7909 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
7910 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7914 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
7917 index = get_loaded_component(package,szComponent);
7919 return ERROR_UNKNOWN_COMPONENT;
7922 *piInstalled = package->components[index].Installed;
7925 *piAction = package->components[index].Action;
7927 TRACE("states (%i, %i)\n",
7928 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
7930 return ERROR_SUCCESS;
7933 /***********************************************************************
7934 * MsiGetComponentStateW (MSI.@)
7936 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
7937 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7939 MSIPACKAGE* package;
7942 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
7943 piInstalled, piAction);
7945 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7947 return ERROR_INVALID_HANDLE;
7948 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
7949 msiobj_release( &package->hdr );