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};
792 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
794 row = MSI_QueryGetRecord( package->db, Query_t, action );
798 ActionText = MSI_RecordGetString(row,2);
800 sprintfW(message,template_s,timet,action,ActionText);
801 msiobj_release(&row->hdr);
803 row = MSI_CreateRecord(1);
804 MSI_RecordSetStringW(row,1,message);
806 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
807 msiobj_release(&row->hdr);
810 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
814 static const WCHAR template_s[]=
815 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
817 static const WCHAR template_e[]=
818 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
819 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
821 static const WCHAR format[] =
822 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
826 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
828 sprintfW(message,template_s,timet,action);
830 sprintfW(message,template_e,timet,action,rc);
832 row = MSI_CreateRecord(1);
833 MSI_RecordSetStringW(row,1,message);
835 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
836 msiobj_release(&row->hdr);
840 * build_directory_name()
842 * This function is to save messing round with directory names
843 * It handles adding backslashes between path segments,
844 * and can add \ at the end of the directory name if told to.
846 * It takes a variable number of arguments.
847 * It always allocates a new string for the result, so make sure
848 * to free the return value when finished with it.
850 * The first arg is the number of path segments that follow.
851 * The arguments following count are a list of path segments.
852 * A path segment may be NULL.
854 * Path segments will be added with a \ separating them.
855 * A \ will not be added after the last segment, however if the
856 * last segment is NULL, then the last character will be a \
859 static LPWSTR build_directory_name(DWORD count, ...)
866 for(i=0; i<count; i++)
868 LPCWSTR str = va_arg(va,LPCWSTR);
870 sz += strlenW(str) + 1;
874 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
878 for(i=0; i<count; i++)
880 LPCWSTR str = va_arg(va,LPCWSTR);
884 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
890 static BOOL ACTION_VerifyComponentForAction(MSIPACKAGE* package, INT index,
893 if (package->components[index].Installed == check)
896 if (package->components[index].ActionRequest == check)
902 static BOOL ACTION_VerifyFeatureForAction(MSIPACKAGE* package, INT index,
905 if (package->features[index].Installed == check)
908 if (package->features[index].ActionRequest == check)
915 /****************************************************
916 * TOP level entry points
917 *****************************************************/
919 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
920 LPCWSTR szCommandLine)
926 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
927 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
928 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
930 MSI_SetPropertyW(package, szAction, szInstall);
932 package->script = HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT));
933 memset(package->script,0,sizeof(MSISCRIPT));
937 LPWSTR p, check, path;
939 package->PackagePath = strdupW(szPackagePath);
940 path = strdupW(szPackagePath);
941 p = strrchrW(path,'\\');
949 HeapFree(GetProcessHeap(),0,path);
950 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
951 GetCurrentDirectoryW(MAX_PATH,path);
955 check = load_dynamic_property(package, cszSourceDir,NULL);
957 MSI_SetPropertyW(package, cszSourceDir, path);
959 HeapFree(GetProcessHeap(), 0, check);
961 HeapFree(GetProcessHeap(), 0, path);
967 ptr = (LPWSTR)szCommandLine;
974 TRACE("Looking at %s\n",debugstr_w(ptr));
976 ptr2 = strchrW(ptr,'=');
982 while (*ptr == ' ') ptr++;
984 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
985 memcpy(prop,ptr,len*sizeof(WCHAR));
991 while (*ptr && (quote || (!quote && *ptr!=' ')))
1004 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
1005 memcpy(val,ptr2,len*sizeof(WCHAR));
1008 if (strlenW(prop) > 0)
1010 TRACE("Found commandline property (%s) = (%s)\n",
1011 debugstr_w(prop), debugstr_w(val));
1012 MSI_SetPropertyW(package,prop,val);
1014 HeapFree(GetProcessHeap(),0,val);
1015 HeapFree(GetProcessHeap(),0,prop);
1022 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
1024 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
1026 rc = ACTION_ProcessUISequence(package);
1028 if (rc == ERROR_SUCCESS)
1029 rc = ACTION_ProcessExecSequence(package,TRUE);
1032 rc = ACTION_ProcessExecSequence(package,FALSE);
1035 rc = ACTION_ProcessExecSequence(package,FALSE);
1039 /* install was halted but should be considered a success */
1043 package->script->CurrentlyScripting= FALSE;
1045 /* process the ending type action */
1046 if (rc == ERROR_SUCCESS)
1047 ACTION_PerformActionSequence(package,-1,ui);
1048 else if (rc == ERROR_INSTALL_USEREXIT)
1049 ACTION_PerformActionSequence(package,-2,ui);
1050 else if (rc == ERROR_INSTALL_SUSPEND)
1051 ACTION_PerformActionSequence(package,-4,ui);
1053 ACTION_PerformActionSequence(package,-3,ui);
1055 /* finish up running custom actions */
1056 ACTION_FinishCustomActions(package);
1061 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
1063 UINT rc = ERROR_SUCCESS;
1064 MSIRECORD * row = 0;
1065 static const WCHAR ExecSeqQuery[] =
1066 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1067 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1068 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1069 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
1071 static const WCHAR UISeqQuery[] =
1072 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1073 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1074 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
1075 ' ', '=',' ','%','i',0};
1078 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
1080 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
1084 LPCWSTR action, cond;
1086 TRACE("Running the actions\n");
1088 /* check conditions */
1089 cond = MSI_RecordGetString(row,2);
1092 /* this is a hack to skip errors in the condition code */
1093 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1097 action = MSI_RecordGetString(row,1);
1100 ERR("failed to fetch action\n");
1101 rc = ERROR_FUNCTION_FAILED;
1106 rc = ACTION_PerformUIAction(package,action);
1108 rc = ACTION_PerformAction(package,action,FALSE);
1110 msiobj_release(&row->hdr);
1118 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1122 static const WCHAR ExecSeqQuery[] =
1123 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1124 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1125 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1126 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
1127 'O','R','D','E','R',' ', 'B','Y',' ',
1128 '`','S','e','q','u','e','n','c','e','`',0 };
1129 MSIRECORD * row = 0;
1130 static const WCHAR IVQuery[] =
1131 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
1132 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
1133 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
1134 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
1135 ' ','\'', 'I','n','s','t','a','l','l',
1136 'V','a','l','i','d','a','t','e','\'', 0};
1140 if (package->script->ExecuteSequenceRun)
1142 TRACE("Execute Sequence already Run\n");
1143 return ERROR_SUCCESS;
1146 package->script->ExecuteSequenceRun = TRUE;
1148 /* get the sequence number */
1151 row = MSI_QueryGetRecord(package->db, IVQuery);
1153 return ERROR_FUNCTION_FAILED;
1154 seq = MSI_RecordGetInteger(row,1);
1155 msiobj_release(&row->hdr);
1158 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1159 if (rc == ERROR_SUCCESS)
1161 rc = MSI_ViewExecute(view, 0);
1163 if (rc != ERROR_SUCCESS)
1165 MSI_ViewClose(view);
1166 msiobj_release(&view->hdr);
1170 TRACE("Running the actions\n");
1174 LPCWSTR cond, action;
1176 rc = MSI_ViewFetch(view,&row);
1177 if (rc != ERROR_SUCCESS)
1183 action = MSI_RecordGetString(row,1);
1186 rc = ERROR_FUNCTION_FAILED;
1187 msiobj_release(&row->hdr);
1191 /* check conditions */
1192 cond = MSI_RecordGetString(row,2);
1195 /* this is a hack to skip errors in the condition code */
1196 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1198 msiobj_release(&row->hdr);
1199 TRACE("Skipping action: %s (condition is false)\n",
1200 debugstr_w(action));
1205 rc = ACTION_PerformAction(package,action,FALSE);
1207 if (rc == ERROR_FUNCTION_NOT_CALLED)
1210 if (rc != ERROR_SUCCESS)
1212 ERR("Execution halted due to error (%i)\n",rc);
1213 msiobj_release(&row->hdr);
1217 msiobj_release(&row->hdr);
1220 MSI_ViewClose(view);
1221 msiobj_release(&view->hdr);
1229 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1233 static const WCHAR ExecSeqQuery [] =
1234 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1235 '`','I','n','s','t','a','l','l',
1236 'U','I','S','e','q','u','e','n','c','e','`',
1237 ' ','W','H','E','R','E',' ',
1238 '`','S','e','q','u','e','n','c','e','`',' ',
1239 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1240 '`','S','e','q','u','e','n','c','e','`',0};
1242 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1244 if (rc == ERROR_SUCCESS)
1246 rc = MSI_ViewExecute(view, 0);
1248 if (rc != ERROR_SUCCESS)
1250 MSI_ViewClose(view);
1251 msiobj_release(&view->hdr);
1255 TRACE("Running the actions \n");
1259 LPCWSTR action, cond;
1260 MSIRECORD * row = 0;
1262 rc = MSI_ViewFetch(view,&row);
1263 if (rc != ERROR_SUCCESS)
1269 action = MSI_RecordGetString(row,1);
1272 ERR("failed to fetch action\n");
1273 rc = ERROR_FUNCTION_FAILED;
1274 msiobj_release(&row->hdr);
1278 /* check conditions */
1279 cond = MSI_RecordGetString(row,2);
1282 /* this is a hack to skip errors in the condition code */
1283 if (MSI_EvaluateConditionW(package,cond) == MSICONDITION_FALSE)
1285 msiobj_release(&row->hdr);
1286 TRACE("Skipping action: %s (condition is false)\n",
1287 debugstr_w(action));
1292 rc = ACTION_PerformUIAction(package,action);
1294 if (rc == ERROR_FUNCTION_NOT_CALLED)
1297 if (rc != ERROR_SUCCESS)
1299 ERR("Execution halted due to error (%i)\n",rc);
1300 msiobj_release(&row->hdr);
1304 msiobj_release(&row->hdr);
1307 MSI_ViewClose(view);
1308 msiobj_release(&view->hdr);
1315 /********************************************************
1316 * ACTION helper functions and functions that perform the actions
1317 *******************************************************/
1318 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
1319 UINT* rc, BOOL force )
1325 if (!run && !package->script->CurrentlyScripting)
1330 if (strcmpW(action,szInstallFinalize) == 0 ||
1331 strcmpW(action,szInstallExecute) == 0 ||
1332 strcmpW(action,szInstallExecuteAgain) == 0)
1337 while (StandardActions[i].action != NULL)
1339 if (strcmpW(StandardActions[i].action, action)==0)
1341 ce_actiontext(package, action);
1344 ui_actioninfo(package, action, TRUE, 0);
1345 *rc = schedule_action(package,INSTALL_SCRIPT,action);
1346 ui_actioninfo(package, action, FALSE, *rc);
1350 ui_actionstart(package, action);
1351 if (StandardActions[i].handler)
1353 *rc = StandardActions[i].handler(package);
1357 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1358 *rc = ERROR_SUCCESS;
1369 static BOOL ACTION_HandleDialogBox( MSIPACKAGE *package, LPCWSTR dialog, UINT* rc )
1373 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1375 *rc = package->CurrentInstallState;
1381 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
1382 UINT* rc, BOOL force )
1387 arc = ACTION_CustomAction(package,action, force);
1389 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1398 * A lot of actions are really important even if they don't do anything
1399 * explicit... Lots of properties are set at the beginning of the installation
1400 * CostFinalize does a bunch of work to translate the directories and such
1402 * But until I get write access to the database that is hard, so I am going to
1403 * hack it to see if I can get something to run.
1405 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
1407 UINT rc = ERROR_SUCCESS;
1410 TRACE("Performing action (%s)\n",debugstr_w(action));
1412 handled = ACTION_HandleStandardAction(package, action, &rc, force);
1415 handled = ACTION_HandleCustomAction(package, action, &rc, force);
1419 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1420 rc = ERROR_FUNCTION_NOT_CALLED;
1423 package->CurrentInstallState = rc;
1427 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1429 UINT rc = ERROR_SUCCESS;
1430 BOOL handled = FALSE;
1432 TRACE("Performing action (%s)\n",debugstr_w(action));
1434 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
1437 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
1440 handled = ACTION_HandleDialogBox(package, action, &rc);
1442 msi_dialog_check_messages( NULL );
1446 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1447 rc = ERROR_FUNCTION_NOT_CALLED;
1450 package->CurrentInstallState = rc;
1454 /***********************************************************************
1457 * Recursively create all directories in the path.
1459 * shamelessly stolen from setupapi/queue.c
1461 static BOOL create_full_pathW(const WCHAR *path)
1467 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1470 strcpyW(new_path, path);
1472 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1473 new_path[len - 1] = 0;
1475 while(!CreateDirectoryW(new_path, NULL))
1478 DWORD last_error = GetLastError();
1479 if(last_error == ERROR_ALREADY_EXISTS)
1482 if(last_error != ERROR_PATH_NOT_FOUND)
1488 if(!(slash = strrchrW(new_path, '\\')))
1494 len = slash - new_path;
1496 if(!create_full_pathW(new_path))
1501 new_path[len] = '\\';
1504 HeapFree(GetProcessHeap(), 0, new_path);
1509 * Also we cannot enable/disable components either, so for now I am just going
1510 * to do all the directories for all the components.
1512 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1514 static const WCHAR ExecSeqQuery[] =
1515 {'S','E','L','E','C','T',' ',
1516 '`','D','i','r','e','c','t','o','r','y','_','`',
1517 ' ','F','R','O','M',' ',
1518 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
1523 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1524 if (rc != ERROR_SUCCESS)
1525 return ERROR_SUCCESS;
1527 rc = MSI_ViewExecute(view, 0);
1528 if (rc != ERROR_SUCCESS)
1530 MSI_ViewClose(view);
1531 msiobj_release(&view->hdr);
1540 MSIRECORD *row = NULL, *uirow;
1542 rc = MSI_ViewFetch(view,&row);
1543 if (rc != ERROR_SUCCESS)
1550 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1552 if (rc!= ERROR_SUCCESS)
1554 ERR("Unable to get folder id \n");
1555 msiobj_release(&row->hdr);
1560 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1563 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1564 msiobj_release(&row->hdr);
1568 TRACE("Folder is %s\n",debugstr_w(full_path));
1571 uirow = MSI_CreateRecord(1);
1572 MSI_RecordSetStringW(uirow,1,full_path);
1573 ui_actiondata(package,szCreateFolders,uirow);
1574 msiobj_release( &uirow->hdr );
1576 if (folder->State == 0)
1577 create_full_pathW(full_path);
1581 msiobj_release(&row->hdr);
1582 HeapFree(GetProcessHeap(),0,full_path);
1584 MSI_ViewClose(view);
1585 msiobj_release(&view->hdr);
1590 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1592 int index = package->loaded_components;
1595 /* fill in the data */
1597 package->loaded_components++;
1598 if (package->loaded_components == 1)
1599 package->components = HeapAlloc(GetProcessHeap(),0,
1600 sizeof(MSICOMPONENT));
1602 package->components = HeapReAlloc(GetProcessHeap(),0,
1603 package->components, package->loaded_components *
1604 sizeof(MSICOMPONENT));
1606 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1608 sz = IDENTIFIER_SIZE;
1609 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1611 TRACE("Loading Component %s\n",
1612 debugstr_w(package->components[index].Component));
1615 if (!MSI_RecordIsNull(row,2))
1616 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1618 sz = IDENTIFIER_SIZE;
1619 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1621 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1624 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1626 sz = IDENTIFIER_SIZE;
1627 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1629 package->components[index].Installed = INSTALLSTATE_ABSENT;
1630 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1631 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1633 package->components[index].Enabled = TRUE;
1638 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1640 int index = package->loaded_features;
1642 static const WCHAR Query1[] =
1643 {'S','E','L','E','C','T',' ',
1644 '`','C','o','m','p','o','n','e','n','t','_','`',
1645 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1646 'C','o','m','p','o','n','e','n','t','s','`',' ',
1647 'W','H','E','R','E',' ',
1648 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1649 static const WCHAR Query2[] =
1650 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1651 '`','C','o','m','p','o','n','e','n','t','`',' ',
1652 'W','H','E','R','E',' ',
1653 '`','C','o','m','p','o','n','e','n','t','`',' ',
1654 '=','\'','%','s','\'',0};
1661 /* fill in the data */
1663 package->loaded_features ++;
1664 if (package->loaded_features == 1)
1665 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1667 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1668 package->loaded_features * sizeof(MSIFEATURE));
1670 memset(&package->features[index],0,sizeof(MSIFEATURE));
1672 sz = IDENTIFIER_SIZE;
1673 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1675 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1677 sz = IDENTIFIER_SIZE;
1678 if (!MSI_RecordIsNull(row,2))
1679 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1682 if (!MSI_RecordIsNull(row,3))
1683 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1686 if (!MSI_RecordIsNull(row,4))
1687 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1689 if (!MSI_RecordIsNull(row,5))
1690 package->features[index].Display = MSI_RecordGetInteger(row,5);
1692 package->features[index].Level= MSI_RecordGetInteger(row,6);
1694 sz = IDENTIFIER_SIZE;
1695 if (!MSI_RecordIsNull(row,7))
1696 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1698 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1700 package->features[index].Installed = INSTALLSTATE_ABSENT;
1701 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1702 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1704 /* load feature components */
1706 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1707 if (rc != ERROR_SUCCESS)
1709 rc = MSI_ViewExecute(view,0);
1710 if (rc != ERROR_SUCCESS)
1712 MSI_ViewClose(view);
1713 msiobj_release(&view->hdr);
1719 WCHAR buffer[0x100];
1722 INT cnt = package->features[index].ComponentCount;
1724 rc = MSI_ViewFetch(view,&row2);
1725 if (rc != ERROR_SUCCESS)
1729 MSI_RecordGetStringW(row2,1,buffer,&sz);
1731 /* check to see if the component is already loaded */
1732 c_indx = get_loaded_component(package,buffer);
1735 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1737 package->features[index].Components[cnt] = c_indx;
1738 package->features[index].ComponentCount ++;
1739 msiobj_release( &row2->hdr );
1743 rc = MSI_OpenQuery(package->db, &view2, Query2, buffer);
1744 if (rc != ERROR_SUCCESS)
1746 msiobj_release( &row2->hdr );
1749 rc = MSI_ViewExecute(view2,0);
1750 if (rc != ERROR_SUCCESS)
1752 msiobj_release( &row2->hdr );
1753 MSI_ViewClose(view2);
1754 msiobj_release( &view2->hdr );
1761 rc = MSI_ViewFetch(view2,&row3);
1762 if (rc != ERROR_SUCCESS)
1764 c_indx = load_component(package,row3);
1765 msiobj_release( &row3->hdr );
1767 package->features[index].Components[cnt] = c_indx;
1768 package->features[index].ComponentCount ++;
1769 TRACE("Loaded new component to index %i\n",c_indx);
1771 MSI_ViewClose(view2);
1772 msiobj_release( &view2->hdr );
1773 msiobj_release( &row2->hdr );
1775 MSI_ViewClose(view);
1776 msiobj_release(&view->hdr);
1779 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1781 DWORD index = package->loaded_files;
1785 /* fill in the data */
1787 package->loaded_files++;
1788 if (package->loaded_files== 1)
1789 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1791 package->files = HeapReAlloc(GetProcessHeap(),0,
1792 package->files , package->loaded_files * sizeof(MSIFILE));
1794 memset(&package->files[index],0,sizeof(MSIFILE));
1796 package->files[index].File = load_dynamic_stringW(row, 1);
1797 buffer = load_dynamic_stringW(row, 2);
1799 package->files[index].ComponentIndex = -1;
1800 for (i = 0; i < package->loaded_components; i++)
1801 if (strcmpW(package->components[i].Component,buffer)==0)
1803 package->files[index].ComponentIndex = i;
1806 if (package->files[index].ComponentIndex == -1)
1807 ERR("Unfound Component %s\n",debugstr_w(buffer));
1808 HeapFree(GetProcessHeap(), 0, buffer);
1810 package->files[index].FileName = load_dynamic_stringW(row,3);
1811 reduce_to_longfilename(package->files[index].FileName);
1813 package->files[index].ShortName = load_dynamic_stringW(row,3);
1814 reduce_to_shortfilename(package->files[index].ShortName);
1816 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1817 package->files[index].Version = load_dynamic_stringW(row, 5);
1818 package->files[index].Language = load_dynamic_stringW(row, 6);
1819 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1820 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1822 package->files[index].Temporary = FALSE;
1823 package->files[index].State = 0;
1825 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1827 return ERROR_SUCCESS;
1830 static UINT load_all_files(MSIPACKAGE *package)
1835 static const WCHAR Query[] =
1836 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1837 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1838 '`','S','e','q','u','e','n','c','e','`', 0};
1841 return ERROR_INVALID_HANDLE;
1843 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1844 if (rc != ERROR_SUCCESS)
1845 return ERROR_SUCCESS;
1847 rc = MSI_ViewExecute(view, 0);
1848 if (rc != ERROR_SUCCESS)
1850 MSI_ViewClose(view);
1851 msiobj_release(&view->hdr);
1852 return ERROR_SUCCESS;
1857 rc = MSI_ViewFetch(view,&row);
1858 if (rc != ERROR_SUCCESS)
1863 load_file(package,row);
1864 msiobj_release(&row->hdr);
1866 MSI_ViewClose(view);
1867 msiobj_release(&view->hdr);
1869 return ERROR_SUCCESS;
1874 * I am not doing any of the costing functionality yet.
1875 * Mostly looking at doing the Component and Feature loading
1877 * The native MSI does A LOT of modification to tables here. Mostly adding
1878 * a lot of temporary columns to the Feature and Component tables.
1880 * note: Native msi also tracks the short filename. But I am only going to
1881 * track the long ones. Also looking at this directory table
1882 * it appears that the directory table does not get the parents
1883 * resolved base on property only based on their entries in the
1886 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1891 static const WCHAR Query_all[] =
1892 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1893 '`','F','e','a','t','u','r','e','`',0};
1894 static const WCHAR szCosting[] =
1895 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1896 static const WCHAR szZero[] = { '0', 0 };
1900 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1902 return ERROR_SUCCESS;
1904 MSI_SetPropertyW(package, szCosting, szZero);
1905 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1907 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1908 if (rc != ERROR_SUCCESS)
1910 rc = MSI_ViewExecute(view,0);
1911 if (rc != ERROR_SUCCESS)
1913 MSI_ViewClose(view);
1914 msiobj_release(&view->hdr);
1921 rc = MSI_ViewFetch(view,&row);
1922 if (rc != ERROR_SUCCESS)
1925 load_feature(package,row);
1926 msiobj_release(&row->hdr);
1928 MSI_ViewClose(view);
1929 msiobj_release(&view->hdr);
1931 load_all_files(package);
1933 return ERROR_SUCCESS;
1936 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
1939 LPWSTR *newbuf = NULL;
1940 if (script >= TOTAL_SCRIPTS)
1942 FIXME("Unknown script requested %i\n",script);
1943 return ERROR_FUNCTION_FAILED;
1945 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
1947 count = package->script->ActionCount[script];
1948 package->script->ActionCount[script]++;
1950 newbuf = HeapReAlloc(GetProcessHeap(),0,
1951 package->script->Actions[script],
1952 package->script->ActionCount[script]* sizeof(LPWSTR));
1954 newbuf = HeapAlloc(GetProcessHeap(),0, sizeof(LPWSTR));
1956 newbuf[count] = strdupW(action);
1957 package->script->Actions[script] = newbuf;
1959 return ERROR_SUCCESS;
1962 static UINT execute_script(MSIPACKAGE *package, UINT script )
1965 UINT rc = ERROR_SUCCESS;
1967 TRACE("Executing Script %i\n",script);
1969 for (i = 0; i < package->script->ActionCount[script]; i++)
1972 action = package->script->Actions[script][i];
1973 ui_actionstart(package, action);
1974 TRACE("Executing Action (%s)\n",debugstr_w(action));
1975 rc = ACTION_PerformAction(package, action, TRUE);
1976 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1977 if (rc != ERROR_SUCCESS)
1980 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1982 package->script->ActionCount[script] = 0;
1983 package->script->Actions[script] = NULL;
1987 static UINT ACTION_FileCost(MSIPACKAGE *package)
1989 return ERROR_SUCCESS;
1993 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1995 static const WCHAR Query[] =
1996 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1997 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1998 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1999 ' ','=',' ','\'','%','s','\'',
2001 LPWSTR ptargetdir, targetdir, parent, srcdir;
2002 LPWSTR shortname = NULL;
2003 MSIRECORD * row = 0;
2007 TRACE("Looking for dir %s\n",debugstr_w(dir));
2009 for (i = 0; i < package->loaded_folders; i++)
2011 if (strcmpW(package->folders[i].Directory,dir)==0)
2013 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
2018 TRACE("Working to load %s\n",debugstr_w(dir));
2020 index = package->loaded_folders++;
2021 if (package->loaded_folders==1)
2022 package->folders = HeapAlloc(GetProcessHeap(),0,
2025 package->folders= HeapReAlloc(GetProcessHeap(),0,
2026 package->folders, package->loaded_folders*
2029 memset(&package->folders[index],0,sizeof(MSIFOLDER));
2031 package->folders[index].Directory = strdupW(dir);
2033 row = MSI_QueryGetRecord(package->db, Query, dir);
2037 ptargetdir = targetdir = load_dynamic_stringW(row,3);
2039 /* split src and target dir */
2040 if (strchrW(targetdir,':'))
2042 srcdir=strchrW(targetdir,':');
2049 /* for now only pick long filename versions */
2050 if (strchrW(targetdir,'|'))
2052 shortname = targetdir;
2053 targetdir = strchrW(targetdir,'|');
2057 /* for the sourcedir pick the short filename */
2058 if (srcdir && strchrW(srcdir,'|'))
2060 LPWSTR p = strchrW(srcdir,'|');
2064 /* now check for root dirs */
2065 if (targetdir[0] == '.' && targetdir[1] == 0)
2068 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
2073 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2074 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2075 package->folders[index].TargetDefault = strdupW(targetdir);
2079 package->folders[index].SourceDefault = strdupW(srcdir);
2081 package->folders[index].SourceDefault = strdupW(shortname);
2083 package->folders[index].SourceDefault = strdupW(targetdir);
2084 HeapFree(GetProcessHeap(), 0, ptargetdir);
2085 TRACE(" SourceDefault = %s\n",debugstr_w(package->folders[index].SourceDefault));
2087 parent = load_dynamic_stringW(row,2);
2090 i = load_folder(package,parent);
2091 package->folders[index].ParentIndex = i;
2092 TRACE("Parent is index %i... %s %s\n",
2093 package->folders[index].ParentIndex,
2094 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2095 debugstr_w(parent));
2098 package->folders[index].ParentIndex = -2;
2099 HeapFree(GetProcessHeap(), 0, parent);
2101 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2103 msiobj_release(&row->hdr);
2104 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2109 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
2110 BOOL set_prop, MSIFOLDER **folder)
2113 LPWSTR p, path = NULL;
2115 TRACE("Working to resolve %s\n",debugstr_w(name));
2117 /* special resolving for Target and Source root dir */
2118 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2122 path = load_dynamic_property(package,cszTargetDir,NULL);
2125 path = load_dynamic_property(package,cszRootDrive,NULL);
2127 MSI_SetPropertyW(package,cszTargetDir,path);
2131 for (i = 0; i < package->loaded_folders; i++)
2133 if (strcmpW(package->folders[i].Directory,name)==0)
2136 *folder = &(package->folders[i]);
2142 path = load_dynamic_property(package,cszSourceDir,NULL);
2145 path = load_dynamic_property(package,cszDatabase,NULL);
2148 p = strrchrW(path,'\\');
2155 for (i = 0; i < package->loaded_folders; i++)
2157 if (strcmpW(package->folders[i].Directory,name)==0)
2160 *folder = &(package->folders[i]);
2166 for (i = 0; i < package->loaded_folders; i++)
2168 if (strcmpW(package->folders[i].Directory,name)==0)
2172 if (i >= package->loaded_folders)
2176 *folder = &(package->folders[i]);
2178 if (!source && package->folders[i].ResolvedTarget)
2180 path = strdupW(package->folders[i].ResolvedTarget);
2181 TRACE(" already resolved to %s\n",debugstr_w(path));
2184 else if (source && package->folders[i].ResolvedSource)
2186 path = strdupW(package->folders[i].ResolvedSource);
2187 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
2190 else if (!source && package->folders[i].Property)
2192 path = build_directory_name(2, package->folders[i].Property, NULL);
2194 TRACE(" internally set to %s\n",debugstr_w(path));
2196 MSI_SetPropertyW(package,name,path);
2200 if (package->folders[i].ParentIndex >= 0)
2202 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2204 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2206 p = resolve_folder(package, parent, source, set_prop, NULL);
2209 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2210 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2211 package->folders[i].ResolvedTarget = strdupW(path);
2212 TRACE(" resolved into %s\n",debugstr_w(path));
2214 MSI_SetPropertyW(package,name,path);
2218 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2219 TRACE(" (source)resolved into %s\n",debugstr_w(path));
2220 package->folders[i].ResolvedSource = strdupW(path);
2222 HeapFree(GetProcessHeap(),0,p);
2227 /* scan for and update current install states */
2228 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
2233 productcode = load_dynamic_property(package,szProductCode,NULL);
2235 for (i = 0; i < package->loaded_components; i++)
2238 res = MsiGetComponentPathW(productcode,
2239 package->components[i].ComponentId , NULL, NULL);
2241 res = INSTALLSTATE_ABSENT;
2242 package->components[i].Installed = res;
2245 for (i = 0; i < package->loaded_features; i++)
2247 INSTALLSTATE res = -10;
2249 for (j = 0; j < package->features[i].ComponentCount; j++)
2251 MSICOMPONENT* component = &package->components[package->features[i].
2254 res = component->Installed;
2257 if (res == component->Installed)
2260 if (res != component->Installed)
2261 res = INSTALLSTATE_INCOMPLETE;
2267 /* update compoennt state based on a feature change */
2268 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2271 INSTALLSTATE newstate;
2272 MSIFEATURE *feature;
2274 i = get_loaded_feature(package,szFeature);
2278 feature = &package->features[i];
2279 newstate = feature->ActionRequest;
2281 for( i = 0; i < feature->ComponentCount; i++)
2283 MSICOMPONENT* component = &package->components[feature->Components[i]];
2285 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
2286 newstate, debugstr_w(component->Component), component->Installed,
2287 component->Action, component->ActionRequest);
2289 if (!component->Enabled)
2293 if (newstate == INSTALLSTATE_LOCAL)
2295 component->ActionRequest = INSTALLSTATE_LOCAL;
2296 component->Action = INSTALLSTATE_LOCAL;
2302 component->ActionRequest = newstate;
2303 component->Action = newstate;
2305 /*if any other feature wants is local we need to set it local*/
2307 j < package->loaded_features &&
2308 component->ActionRequest != INSTALLSTATE_LOCAL;
2311 for (k = 0; k < package->features[j].ComponentCount; k++)
2312 if ( package->features[j].Components[k] ==
2313 feature->Components[i] )
2315 if (package->features[j].ActionRequest ==
2318 TRACE("Saved by %s\n", debugstr_w(package->features[j].Feature));
2319 component->ActionRequest = INSTALLSTATE_LOCAL;
2320 component->Action = INSTALLSTATE_LOCAL;
2327 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
2328 newstate, debugstr_w(component->Component), component->Installed,
2329 component->Action, component->ActionRequest);
2333 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
2336 static const WCHAR all[]={'A','L','L',0};
2337 LPWSTR override = NULL;
2341 override = load_dynamic_property(package, property, NULL);
2345 for(i = 0; i < package->loaded_features; i++)
2347 if (strcmpiW(override,all)==0)
2349 package->features[i].ActionRequest= state;
2350 package->features[i].Action = state;
2354 LPWSTR ptr = override;
2355 LPWSTR ptr2 = strchrW(override,',');
2360 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2362 strcmpW(ptr,package->features[i].Feature)==0))
2364 package->features[i].ActionRequest= state;
2365 package->features[i].Action = state;
2371 ptr2 = strchrW(ptr,',');
2378 HeapFree(GetProcessHeap(),0,override);
2384 static UINT SetFeatureStates(MSIPACKAGE *package)
2390 static const WCHAR szlevel[] =
2391 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2392 static const WCHAR szAddLocal[] =
2393 {'A','D','D','L','O','C','A','L',0};
2394 static const WCHAR szRemove[] =
2395 {'R','E','M','O','V','E',0};
2396 BOOL override = FALSE;
2398 /* I do not know if this is where it should happen.. but */
2400 TRACE("Checking Install Level\n");
2402 level = load_dynamic_property(package,szlevel,NULL);
2405 install_level = atoiW(level);
2406 HeapFree(GetProcessHeap(), 0, level);
2411 /* ok hereis the _real_ rub
2412 * all these activation/deactivation things happen in order and things
2413 * later on the list override things earlier on the list.
2414 * 1) INSTALLLEVEL processing
2424 * 11) FILEADDDEFAULT
2425 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2426 * ignored for all the features. seems strange, especially since it is not
2427 * documented anywhere, but it is how it works.
2429 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2430 * REMOVE are the big ones, since we don't handle administrative installs
2433 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
2434 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
2438 for(i = 0; i < package->loaded_features; i++)
2440 BOOL feature_state = ((package->features[i].Level > 0) &&
2441 (package->features[i].Level <= install_level));
2443 if ((feature_state) &&
2444 (package->features[i].Action == INSTALLSTATE_UNKNOWN))
2446 if (package->features[i].Attributes &
2447 msidbFeatureAttributesFavorSource)
2449 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
2450 package->features[i].Action = INSTALLSTATE_SOURCE;
2452 else if (package->features[i].Attributes &
2453 msidbFeatureAttributesFavorAdvertise)
2455 package->features[i].ActionRequest =INSTALLSTATE_ADVERTISED;
2456 package->features[i].Action =INSTALLSTATE_ADVERTISED;
2460 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
2461 package->features[i].Action = INSTALLSTATE_LOCAL;
2468 * now we want to enable or disable components base on feature
2471 for(i = 0; i < package->loaded_features; i++)
2473 MSIFEATURE* feature = &package->features[i];
2474 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2475 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2476 feature->ActionRequest);
2478 for( j = 0; j < feature->ComponentCount; j++)
2480 MSICOMPONENT* component = &package->components[
2481 feature->Components[j]];
2483 if (!component->Enabled)
2485 component->Action = INSTALLSTATE_UNKNOWN;
2486 component->ActionRequest = INSTALLSTATE_UNKNOWN;
2490 if (feature->Action == INSTALLSTATE_LOCAL)
2492 component->Action = INSTALLSTATE_LOCAL;
2493 component->ActionRequest = INSTALLSTATE_LOCAL;
2495 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
2497 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2498 (component->Action == INSTALLSTATE_ABSENT) ||
2499 (component->Action == INSTALLSTATE_ADVERTISED))
2502 component->Action = INSTALLSTATE_SOURCE;
2503 component->ActionRequest = INSTALLSTATE_SOURCE;
2506 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
2508 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2509 (component->Action == INSTALLSTATE_ABSENT))
2512 component->Action = INSTALLSTATE_ADVERTISED;
2513 component->ActionRequest = INSTALLSTATE_ADVERTISED;
2516 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
2518 if (component->Action == INSTALLSTATE_UNKNOWN)
2520 component->Action = INSTALLSTATE_ABSENT;
2521 component->ActionRequest = INSTALLSTATE_ABSENT;
2528 for(i = 0; i < package->loaded_components; i++)
2530 MSICOMPONENT* component= &package->components[i];
2532 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2533 debugstr_w(component->Component), component->Installed,
2534 component->Action, component->ActionRequest);
2538 return ERROR_SUCCESS;
2542 * A lot is done in this function aside from just the costing.
2543 * The costing needs to be implemented at some point but for now I am going
2544 * to focus on the directory building
2547 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2549 static const WCHAR ExecSeqQuery[] =
2550 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2551 '`','D','i','r','e','c','t','o','r','y','`',0};
2552 static const WCHAR ConditionQuery[] =
2553 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2554 '`','C','o','n','d','i','t','i','o','n','`',0};
2555 static const WCHAR szCosting[] =
2556 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2557 static const WCHAR szlevel[] =
2558 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2559 static const WCHAR szOne[] = { '1', 0 };
2567 MSI_GetPropertyW(package, szCosting, buffer, &sz);
2569 return ERROR_SUCCESS;
2571 TRACE("Building Directory properties\n");
2573 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2574 if (rc == ERROR_SUCCESS)
2576 rc = MSI_ViewExecute(view, 0);
2577 if (rc != ERROR_SUCCESS)
2579 MSI_ViewClose(view);
2580 msiobj_release(&view->hdr);
2588 MSIRECORD * row = 0;
2591 rc = MSI_ViewFetch(view,&row);
2592 if (rc != ERROR_SUCCESS)
2599 MSI_RecordGetStringW(row,1,name,&sz);
2601 /* This helper function now does ALL the work */
2602 TRACE("Dir %s ...\n",debugstr_w(name));
2603 load_folder(package,name);
2604 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2605 TRACE("resolves to %s\n",debugstr_w(path));
2606 HeapFree( GetProcessHeap(), 0, path);
2608 msiobj_release(&row->hdr);
2610 MSI_ViewClose(view);
2611 msiobj_release(&view->hdr);
2614 TRACE("File calculations %i files\n",package->loaded_files);
2616 for (i = 0; i < package->loaded_files; i++)
2618 MSICOMPONENT* comp = NULL;
2619 MSIFILE* file= NULL;
2621 file = &package->files[i];
2622 if (file->ComponentIndex >= 0)
2623 comp = &package->components[file->ComponentIndex];
2625 if (file->Temporary == TRUE)
2632 /* calculate target */
2633 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2635 HeapFree(GetProcessHeap(),0,file->TargetPath);
2637 TRACE("file %s is named %s\n",
2638 debugstr_w(file->File),debugstr_w(file->FileName));
2640 file->TargetPath = build_directory_name(2, p, file->FileName);
2642 HeapFree(GetProcessHeap(),0,p);
2644 TRACE("file %s resolves to %s\n",
2645 debugstr_w(file->File),debugstr_w(file->TargetPath));
2647 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2650 comp->Cost += file->FileSize;
2660 static const WCHAR name[] =
2662 static const WCHAR name_fmt[] =
2663 {'%','u','.','%','u','.','%','u','.','%','u',0};
2664 WCHAR filever[0x100];
2665 VS_FIXEDFILEINFO *lpVer;
2667 TRACE("Version comparison.. \n");
2668 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2669 version = HeapAlloc(GetProcessHeap(),0,versize);
2670 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2672 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2674 sprintfW(filever,name_fmt,
2675 HIWORD(lpVer->dwFileVersionMS),
2676 LOWORD(lpVer->dwFileVersionMS),
2677 HIWORD(lpVer->dwFileVersionLS),
2678 LOWORD(lpVer->dwFileVersionLS));
2680 TRACE("new %s old %s\n", debugstr_w(file->Version),
2681 debugstr_w(filever));
2682 if (strcmpiW(filever,file->Version)<0)
2685 FIXME("cost should be diff in size\n");
2686 comp->Cost += file->FileSize;
2690 HeapFree(GetProcessHeap(),0,version);
2698 TRACE("Evaluating Condition Table\n");
2700 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2701 if (rc == ERROR_SUCCESS)
2703 rc = MSI_ViewExecute(view, 0);
2704 if (rc != ERROR_SUCCESS)
2706 MSI_ViewClose(view);
2707 msiobj_release(&view->hdr);
2713 WCHAR Feature[0x100];
2714 MSIRECORD * row = 0;
2718 rc = MSI_ViewFetch(view,&row);
2720 if (rc != ERROR_SUCCESS)
2727 MSI_RecordGetStringW(row,1,Feature,&sz);
2729 feature_index = get_loaded_feature(package,Feature);
2730 if (feature_index < 0)
2731 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2735 Condition = load_dynamic_stringW(row,3);
2737 if (MSI_EvaluateConditionW(package,Condition) ==
2740 int level = MSI_RecordGetInteger(row,2);
2741 TRACE("Reseting feature %s to level %i\n",
2742 debugstr_w(Feature), level);
2743 package->features[feature_index].Level = level;
2745 HeapFree(GetProcessHeap(),0,Condition);
2748 msiobj_release(&row->hdr);
2750 MSI_ViewClose(view);
2751 msiobj_release(&view->hdr);
2754 TRACE("Enabling or Disabling Components\n");
2755 for (i = 0; i < package->loaded_components; i++)
2757 if (package->components[i].Condition[0])
2759 if (MSI_EvaluateConditionW(package,
2760 package->components[i].Condition) == MSICONDITION_FALSE)
2762 TRACE("Disabling component %s\n",
2763 debugstr_w(package->components[i].Component));
2764 package->components[i].Enabled = FALSE;
2769 MSI_SetPropertyW(package,szCosting,szOne);
2770 /* set default run level if not set */
2771 level = load_dynamic_property(package,szlevel,NULL);
2773 MSI_SetPropertyW(package,szlevel, szOne);
2775 HeapFree(GetProcessHeap(),0,level);
2777 ACTION_UpdateInstallStates(package);
2779 return SetFeatureStates(package);
2783 * This is a helper function for handling embedded cabinet media
2785 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2793 WCHAR tmp[MAX_PATH];
2795 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2796 if (rc != ERROR_SUCCESS)
2800 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2801 GetTempPathW(MAX_PATH,tmp);
2803 GetTempFileNameW(tmp,stream_name,0,source);
2805 track_tempfile(package,strrchrW(source,'\\'), source);
2806 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2807 FILE_ATTRIBUTE_NORMAL, NULL);
2809 if (the_file == INVALID_HANDLE_VALUE)
2811 ERR("Unable to create file %s\n",debugstr_w(source));
2812 rc = ERROR_FUNCTION_FAILED;
2816 WriteFile(the_file,data,size,&write,NULL);
2817 CloseHandle(the_file);
2818 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2820 HeapFree(GetProcessHeap(),0,data);
2825 /* Support functions for FDI functions */
2828 MSIPACKAGE* package;
2833 static void * cabinet_alloc(ULONG cb)
2835 return HeapAlloc(GetProcessHeap(), 0, cb);
2838 static void cabinet_free(void *pv)
2840 HeapFree(GetProcessHeap(), 0, pv);
2843 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2846 DWORD dwShareMode = 0;
2847 DWORD dwCreateDisposition = OPEN_EXISTING;
2848 switch (oflag & _O_ACCMODE)
2851 dwAccess = GENERIC_READ;
2852 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2855 dwAccess = GENERIC_WRITE;
2856 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2859 dwAccess = GENERIC_READ | GENERIC_WRITE;
2860 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2863 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2864 dwCreateDisposition = CREATE_NEW;
2865 else if (oflag & _O_CREAT)
2866 dwCreateDisposition = CREATE_ALWAYS;
2867 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
2868 dwCreateDisposition, 0, NULL);
2871 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2874 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2879 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2882 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2887 static int cabinet_close(INT_PTR hf)
2889 return CloseHandle((HANDLE)hf) ? 0 : -1;
2892 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2894 /* flags are compatible and so are passed straight through */
2895 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2898 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2900 /* FIXME: try to do more processing in this function */
2903 case fdintCOPY_FILE:
2905 CabData *data = (CabData*) pfdin->pv;
2906 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2911 LPWSTR tracknametmp;
2912 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2914 if (data->file_name && lstrcmpiA(data->file_name,pfdin->psz1))
2917 file = cabinet_alloc((len+1)*sizeof(char));
2918 strcpy(file, data->cab_path);
2919 strcat(file, pfdin->psz1);
2921 TRACE("file: %s\n", debugstr_a(file));
2923 /* track this file so it can be deleted if not installed */
2924 trackpath=strdupAtoW(file);
2925 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2926 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2927 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2929 strcpyW(trackname,tmpprefix);
2930 strcatW(trackname,tracknametmp);
2932 track_tempfile(data->package, trackname, trackpath);
2934 HeapFree(GetProcessHeap(),0,trackpath);
2935 HeapFree(GetProcessHeap(),0,trackname);
2936 HeapFree(GetProcessHeap(),0,tracknametmp);
2938 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2940 case fdintCLOSE_FILE_INFO:
2944 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2946 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2948 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2951 cabinet_close(pfdin->hf);
2959 /***********************************************************************
2960 * extract_cabinet_file
2962 * Extract files from a cab file.
2964 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2965 const WCHAR* path, const WCHAR* file)
2975 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2976 debugstr_w(file), debugstr_w(path));
2978 hfdi = FDICreate(cabinet_alloc,
2989 ERR("FDICreate failed\n");
2993 if (!(cabinet = strdupWtoA( source )))
2998 if (!(cab_path = strdupWtoA( path )))
3001 HeapFree(GetProcessHeap(), 0, cabinet);
3005 data.package = package;
3006 data.cab_path = cab_path;
3008 file_name = strdupWtoA(file);
3011 data.file_name = file_name;
3013 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
3016 ERR("FDICopy failed\n");
3020 HeapFree(GetProcessHeap(), 0, cabinet);
3021 HeapFree(GetProcessHeap(), 0, cab_path);
3022 HeapFree(GetProcessHeap(), 0, file_name);
3027 static UINT ready_media_for_file(MSIPACKAGE *package, WCHAR* path,
3030 UINT rc = ERROR_SUCCESS;
3031 MSIRECORD * row = 0;
3032 static WCHAR source[MAX_PATH];
3033 static const WCHAR ExecSeqQuery[] =
3034 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3035 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3036 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
3037 ' ','%', 'i',' ','O','R','D','E','R',' ','B','Y',' ',
3038 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',0};
3042 static UINT last_sequence = 0;
3044 if (file->Attributes & msidbFileAttributesNoncompressed)
3046 TRACE("Uncompressed File, no media to ready.\n");
3047 return ERROR_SUCCESS;
3050 if (file->Sequence <= last_sequence)
3052 TRACE("Media already ready (%u, %u)\n",file->Sequence,last_sequence);
3053 /*extract_a_cabinet_file(package, source,path,file->File); */
3054 return ERROR_SUCCESS;
3057 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, file->Sequence);
3059 return ERROR_FUNCTION_FAILED;
3061 seq = MSI_RecordGetInteger(row,2);
3062 last_sequence = seq;
3064 if (!MSI_RecordIsNull(row,4))
3067 MSI_RecordGetStringW(row,4,cab,&sz);
3068 TRACE("Source is CAB %s\n",debugstr_w(cab));
3069 /* the stream does not contain the # character */
3072 writeout_cabinet_stream(package,&cab[1],source);
3073 strcpyW(path,source);
3074 *(strrchrW(path,'\\')+1)=0;
3079 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
3081 ERR("No Source dir defined \n");
3082 rc = ERROR_FUNCTION_FAILED;
3086 strcpyW(path,source);
3087 strcatW(source,cab);
3088 /* extract the cab file into a folder in the temp folder */
3090 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
3092 GetTempPathW(MAX_PATH,path);
3095 rc = !extract_a_cabinet_file(package, source,path,NULL);
3100 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
3101 strcpyW(path,source);
3103 msiobj_release(&row->hdr);
3107 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
3109 UINT rc = ERROR_SUCCESS;
3111 LPWSTR install_path;
3113 install_path = resolve_folder(package, package->components[component].Directory,
3114 FALSE, FALSE, &folder);
3116 return ERROR_FUNCTION_FAILED;
3118 /* create the path */
3119 if (folder->State == 0)
3121 create_full_pathW(install_path);
3124 HeapFree(GetProcessHeap(), 0, install_path);
3129 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3131 UINT rc = ERROR_SUCCESS;
3134 WCHAR uipath[MAX_PATH];
3137 return ERROR_INVALID_HANDLE;
3139 /* increment progress bar each time action data is sent */
3140 ui_progress(package,1,1,0,0);
3142 for (index = 0; index < package->loaded_files; index++)
3144 WCHAR path_to_source[MAX_PATH];
3147 file = &package->files[index];
3149 if (file->Temporary)
3153 if (!ACTION_VerifyComponentForAction(package, file->ComponentIndex,
3154 INSTALLSTATE_LOCAL))
3156 ui_progress(package,2,file->FileSize,0,0);
3157 TRACE("File %s is not scheduled for install\n",
3158 debugstr_w(file->File));
3163 if ((file->State == 1) || (file->State == 2))
3166 MSICOMPONENT* comp = NULL;
3168 TRACE("Installing %s\n",debugstr_w(file->File));
3169 rc = ready_media_for_file(package, path_to_source, file);
3172 * our file table could change here because a new temp file
3173 * may have been created
3175 file = &package->files[index];
3176 if (rc != ERROR_SUCCESS)
3178 ERR("Unable to ready media\n");
3179 rc = ERROR_FUNCTION_FAILED;
3183 create_component_directory( package, file->ComponentIndex);
3185 /* recalculate file paths because things may have changed */
3187 if (file->ComponentIndex >= 0)
3188 comp = &package->components[file->ComponentIndex];
3190 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3191 HeapFree(GetProcessHeap(),0,file->TargetPath);
3193 file->TargetPath = build_directory_name(2, p, file->FileName);
3194 HeapFree(GetProcessHeap(),0,p);
3196 if (file->Attributes & msidbFileAttributesNoncompressed)
3198 p = resolve_folder(package, comp->Directory, TRUE, FALSE, NULL);
3199 file->SourcePath = build_directory_name(2, p, file->ShortName);
3200 HeapFree(GetProcessHeap(),0,p);
3203 file->SourcePath = build_directory_name(2, path_to_source,
3207 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3208 debugstr_w(file->TargetPath));
3211 uirow=MSI_CreateRecord(9);
3212 MSI_RecordSetStringW(uirow,1,file->File);
3213 strcpyW(uipath,file->TargetPath);
3214 *(strrchrW(uipath,'\\')+1)=0;
3215 MSI_RecordSetStringW(uirow,9,uipath);
3216 MSI_RecordSetInteger(uirow,6,file->FileSize);
3217 ui_actiondata(package,szInstallFiles,uirow);
3218 msiobj_release( &uirow->hdr );
3219 ui_progress(package,2,file->FileSize,0,0);
3222 if (file->Attributes & msidbFileAttributesNoncompressed)
3223 rc = CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3225 rc = MoveFileW(file->SourcePath, file->TargetPath);
3229 rc = GetLastError();
3230 ERR("Unable to move/copy file (%s -> %s) (error %d)\n",
3231 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3233 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3235 if (!CopyFileW(file->SourcePath,file->TargetPath,FALSE))
3236 ERR("Unable to copy file (%s -> %s) (error %ld)\n",
3237 debugstr_w(file->SourcePath),
3238 debugstr_w(file->TargetPath), GetLastError());
3239 if (!(file->Attributes & msidbFileAttributesNoncompressed))
3240 DeleteFileW(file->SourcePath);
3243 else if (rc == ERROR_FILE_NOT_FOUND)
3245 ERR("Source File Not Found! Continuing\n");
3248 else if (file->Attributes & msidbFileAttributesVital)
3250 ERR("Ignoring Error and continuing (nonvital file)...\n");
3265 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3266 LPWSTR* file_source)
3271 return ERROR_INVALID_HANDLE;
3273 for (index = 0; index < package->loaded_files; index ++)
3275 if (strcmpW(file_key,package->files[index].File)==0)
3277 if (package->files[index].State >= 2)
3279 *file_source = strdupW(package->files[index].TargetPath);
3280 return ERROR_SUCCESS;
3283 return ERROR_FILE_NOT_FOUND;
3287 return ERROR_FUNCTION_FAILED;
3290 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3294 MSIRECORD * row = 0;
3295 static const WCHAR ExecSeqQuery[] =
3296 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3297 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
3300 return ERROR_INVALID_HANDLE;
3302 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3303 if (rc != ERROR_SUCCESS)
3304 return ERROR_SUCCESS;
3306 rc = MSI_ViewExecute(view, 0);
3307 if (rc != ERROR_SUCCESS)
3309 MSI_ViewClose(view);
3310 msiobj_release(&view->hdr);
3316 WCHAR file_key[0x100];
3317 WCHAR *file_source = NULL;
3318 WCHAR dest_name[0x100];
3319 LPWSTR dest_path, dest;
3320 WCHAR component[0x100];
3321 INT component_index;
3325 rc = MSI_ViewFetch(view,&row);
3326 if (rc != ERROR_SUCCESS)
3333 rc = MSI_RecordGetStringW(row,2,component,&sz);
3334 if (rc != ERROR_SUCCESS)
3336 ERR("Unable to get component\n");
3337 msiobj_release(&row->hdr);
3341 component_index = get_loaded_component(package,component);
3343 if (!ACTION_VerifyComponentForAction(package, component_index,
3344 INSTALLSTATE_LOCAL))
3346 TRACE("Skipping copy due to disabled component\n");
3348 /* the action taken was the same as the current install state */
3349 package->components[component_index].Action =
3350 package->components[component_index].Installed;
3352 msiobj_release(&row->hdr);
3356 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3359 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3360 if (rc != ERROR_SUCCESS)
3362 ERR("Unable to get file key\n");
3363 msiobj_release(&row->hdr);
3367 rc = get_file_target(package,file_key,&file_source);
3369 if (rc != ERROR_SUCCESS)
3371 ERR("Original file unknown %s\n",debugstr_w(file_key));
3372 msiobj_release(&row->hdr);
3373 HeapFree(GetProcessHeap(),0,file_source);
3377 if (MSI_RecordIsNull(row,4))
3379 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3384 MSI_RecordGetStringW(row,4,dest_name,&sz);
3385 reduce_to_longfilename(dest_name);
3388 if (MSI_RecordIsNull(row,5))
3391 dest_path = strdupW(file_source);
3392 p = strrchrW(dest_path,'\\');
3398 WCHAR destkey[0x100];
3400 MSI_RecordGetStringW(row,5,destkey,&sz);
3402 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3405 ERR("Unable to get destination folder\n");
3406 msiobj_release(&row->hdr);
3407 HeapFree(GetProcessHeap(),0,file_source);
3412 dest = build_directory_name(2, dest_path, dest_name);
3414 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3417 if (strcmpW(file_source,dest))
3418 rc = !CopyFileW(file_source,dest,TRUE);
3422 if (rc != ERROR_SUCCESS)
3423 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
3425 FIXME("We should track these duplicate files as well\n");
3427 msiobj_release(&row->hdr);
3428 HeapFree(GetProcessHeap(),0,dest_path);
3429 HeapFree(GetProcessHeap(),0,dest);
3430 HeapFree(GetProcessHeap(),0,file_source);
3432 MSI_ViewClose(view);
3433 msiobj_release(&view->hdr);
3438 /* OK this value is "interpreted" and then formatted based on the
3439 first few characters */
3440 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3444 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3450 LPWSTR deformated = NULL;
3453 deformat_string(package, &value[2], &deformated);
3455 /* binary value type */
3459 *size = (strlenW(ptr)/2)+1;
3461 *size = strlenW(ptr)/2;
3463 data = HeapAlloc(GetProcessHeap(),0,*size);
3469 /* if uneven pad with a zero in front */
3475 data[count] = (BYTE)strtol(byte,NULL,0);
3477 TRACE("Uneven byte count\n");
3485 data[count] = (BYTE)strtol(byte,NULL,0);
3488 HeapFree(GetProcessHeap(),0,deformated);
3490 TRACE("Data %li bytes(%i)\n",*size,count);
3497 deformat_string(package, &value[1], &deformated);
3500 *size = sizeof(DWORD);
3501 data = HeapAlloc(GetProcessHeap(),0,*size);
3507 if ( (*p < '0') || (*p > '9') )
3513 if (deformated[0] == '-')
3516 TRACE("DWORD %li\n",*(LPDWORD)data);
3518 HeapFree(GetProcessHeap(),0,deformated);
3523 static const WCHAR szMulti[] = {'[','~',']',0};
3532 *type=REG_EXPAND_SZ;
3540 if (strstrW(value,szMulti))
3541 *type = REG_MULTI_SZ;
3543 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3548 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3552 MSIRECORD * row = 0;
3553 static const WCHAR ExecSeqQuery[] =
3554 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3555 '`','R','e','g','i','s','t','r','y','`',0 };
3558 return ERROR_INVALID_HANDLE;
3560 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3561 if (rc != ERROR_SUCCESS)
3562 return ERROR_SUCCESS;
3564 rc = MSI_ViewExecute(view, 0);
3565 if (rc != ERROR_SUCCESS)
3567 MSI_ViewClose(view);
3568 msiobj_release(&view->hdr);
3572 /* increment progress bar each time action data is sent */
3573 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3577 static const WCHAR szHCR[] =
3578 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3579 'R','O','O','T','\\',0};
3580 static const WCHAR szHCU[] =
3581 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3582 'U','S','E','R','\\',0};
3583 static const WCHAR szHLM[] =
3584 {'H','K','E','Y','_','L','O','C','A','L','_',
3585 'M','A','C','H','I','N','E','\\',0};
3586 static const WCHAR szHU[] =
3587 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3589 LPSTR value_data = NULL;
3590 HKEY root_key, hkey;
3592 LPWSTR value, key, name, component, deformated;
3594 INT component_index;
3598 BOOL check_first = FALSE;
3600 rc = MSI_ViewFetch(view,&row);
3601 if (rc != ERROR_SUCCESS)
3606 ui_progress(package,2,0,0,0);
3613 component = load_dynamic_stringW(row, 6);
3614 component_index = get_loaded_component(package,component);
3616 if (!ACTION_VerifyComponentForAction(package, component_index,
3617 INSTALLSTATE_LOCAL))
3619 TRACE("Skipping write due to disabled component\n");
3620 msiobj_release(&row->hdr);
3622 package->components[component_index].Action =
3623 package->components[component_index].Installed;
3628 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3630 name = load_dynamic_stringW(row, 4);
3631 if( MSI_RecordIsNull(row,5) && name )
3633 /* null values can have special meanings */
3634 if (name[0]=='-' && name[1] == 0)
3636 msiobj_release(&row->hdr);
3639 else if ((name[0]=='+' && name[1] == 0) ||
3640 (name[0] == '*' && name[1] == 0))
3642 HeapFree(GetProcessHeap(),0,name);
3648 root = MSI_RecordGetInteger(row,2);
3649 key = load_dynamic_stringW(row, 3);
3652 /* get the root key */
3655 case 0: root_key = HKEY_CLASSES_ROOT;
3658 case 1: root_key = HKEY_CURRENT_USER;
3661 case 2: root_key = HKEY_LOCAL_MACHINE;
3664 case 3: root_key = HKEY_USERS;
3668 ERR("Unknown root %i\n",root);
3675 msiobj_release(&row->hdr);
3679 deformat_string(package, key , &deformated);
3680 size = strlenW(deformated) + strlenW(szRoot) + 1;
3681 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3682 strcpyW(uikey,szRoot);
3683 strcatW(uikey,deformated);
3685 if (RegCreateKeyW( root_key, deformated, &hkey))
3687 ERR("Could not create key %s\n",debugstr_w(deformated));
3688 msiobj_release(&row->hdr);
3689 HeapFree(GetProcessHeap(),0,deformated);
3692 HeapFree(GetProcessHeap(),0,deformated);
3694 value = load_dynamic_stringW(row,5);
3696 value_data = parse_value(package, value, &type, &size);
3699 static const WCHAR szEmpty[] = {0};
3700 value_data = (LPSTR)strdupW(szEmpty);
3705 deformat_string(package, name, &deformated);
3707 /* get the double nulls to terminate SZ_MULTI */
3708 if (type == REG_MULTI_SZ)
3709 size +=sizeof(WCHAR);
3713 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
3715 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3720 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
3721 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3723 TRACE("value %s of %s checked already exists\n",
3724 debugstr_w(deformated), debugstr_w(uikey));
3728 TRACE("Checked and setting value %s of %s\n",
3729 debugstr_w(deformated), debugstr_w(uikey));
3730 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3734 uirow = MSI_CreateRecord(3);
3735 MSI_RecordSetStringW(uirow,2,deformated);
3736 MSI_RecordSetStringW(uirow,1,uikey);
3739 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3741 MSI_RecordSetStringW(uirow,3,value);
3743 ui_actiondata(package,szWriteRegistryValues,uirow);
3744 msiobj_release( &uirow->hdr );
3746 HeapFree(GetProcessHeap(),0,value_data);
3747 HeapFree(GetProcessHeap(),0,value);
3748 HeapFree(GetProcessHeap(),0,deformated);
3750 msiobj_release(&row->hdr);
3753 HeapFree(GetProcessHeap(),0,uikey);
3754 HeapFree(GetProcessHeap(),0,key);
3755 HeapFree(GetProcessHeap(),0,name);
3756 HeapFree(GetProcessHeap(),0,component);
3758 MSI_ViewClose(view);
3759 msiobj_release(&view->hdr);
3763 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3765 package->script->CurrentlyScripting = TRUE;
3767 return ERROR_SUCCESS;
3771 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3775 static const WCHAR q1[]=
3776 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3777 '`','R','e','g','i','s','t','r','y','`',0};
3780 MSIRECORD * row = 0;
3783 TRACE(" InstallValidate \n");
3785 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3786 if (rc != ERROR_SUCCESS)
3787 return ERROR_SUCCESS;
3789 rc = MSI_ViewExecute(view, 0);
3790 if (rc != ERROR_SUCCESS)
3792 MSI_ViewClose(view);
3793 msiobj_release(&view->hdr);
3798 rc = MSI_ViewFetch(view,&row);
3799 if (rc != ERROR_SUCCESS)
3806 msiobj_release(&row->hdr);
3808 MSI_ViewClose(view);
3809 msiobj_release(&view->hdr);
3811 total = total + progress * REG_PROGRESS_VALUE;
3812 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3813 for (i=0; i < package->loaded_files; i++)
3814 total += package->files[i].FileSize;
3815 ui_progress(package,0,total,0,0);
3817 for(i = 0; i < package->loaded_features; i++)
3819 MSIFEATURE* feature = &package->features[i];
3820 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
3821 debugstr_w(feature->Feature), feature->Installed, feature->Action,
3822 feature->ActionRequest);
3825 return ERROR_SUCCESS;
3828 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3831 MSIQUERY * view = NULL;
3832 MSIRECORD * row = 0;
3833 static const WCHAR ExecSeqQuery[] =
3834 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3835 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
3836 static const WCHAR title[]=
3837 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3839 TRACE("Checking launch conditions\n");
3841 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3842 if (rc != ERROR_SUCCESS)
3843 return ERROR_SUCCESS;
3845 rc = MSI_ViewExecute(view, 0);
3846 if (rc != ERROR_SUCCESS)
3848 MSI_ViewClose(view);
3849 msiobj_release(&view->hdr);
3854 while (rc == ERROR_SUCCESS)
3857 LPWSTR message = NULL;
3859 rc = MSI_ViewFetch(view,&row);
3860 if (rc != ERROR_SUCCESS)
3866 cond = load_dynamic_stringW(row,1);
3868 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3871 message = load_dynamic_stringW(row,2);
3872 deformat_string(package,message,&deformated);
3873 MessageBoxW(NULL,deformated,title,MB_OK);
3874 HeapFree(GetProcessHeap(),0,message);
3875 HeapFree(GetProcessHeap(),0,deformated);
3876 rc = ERROR_FUNCTION_FAILED;
3878 HeapFree(GetProcessHeap(),0,cond);
3879 msiobj_release(&row->hdr);
3881 MSI_ViewClose(view);
3882 msiobj_release(&view->hdr);
3886 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3889 MSICOMPONENT* cmp = &package->components[component_index];
3891 if (cmp->KeyPath[0]==0)
3893 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3896 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
3898 MSIRECORD * row = 0;
3900 LPWSTR key,deformated,buffer,name,deformated_name;
3901 static const WCHAR ExecSeqQuery[] =
3902 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3903 '`','R','e','g','i','s','t','r','y','`',' ',
3904 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
3905 ' ','=',' ' ,'\'','%','s','\'',0 };
3906 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
3907 static const WCHAR fmt2[]=
3908 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3910 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
3914 root = MSI_RecordGetInteger(row,2);
3915 key = load_dynamic_stringW(row, 3);
3916 name = load_dynamic_stringW(row, 4);
3917 deformat_string(package, key , &deformated);
3918 deformat_string(package, name, &deformated_name);
3920 len = strlenW(deformated) + 6;
3921 if (deformated_name)
3922 len+=strlenW(deformated_name);
3924 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3926 if (deformated_name)
3927 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3929 sprintfW(buffer,fmt,root,deformated);
3931 HeapFree(GetProcessHeap(),0,key);
3932 HeapFree(GetProcessHeap(),0,deformated);
3933 HeapFree(GetProcessHeap(),0,name);
3934 HeapFree(GetProcessHeap(),0,deformated_name);
3935 msiobj_release(&row->hdr);
3939 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
3941 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3947 j = get_loaded_file(package,cmp->KeyPath);
3951 LPWSTR p = strdupW(package->files[j].TargetPath);
3958 static HKEY openSharedDLLsKey()
3961 static const WCHAR path[] =
3962 {'S','o','f','t','w','a','r','e','\\',
3963 'M','i','c','r','o','s','o','f','t','\\',
3964 'W','i','n','d','o','w','s','\\',
3965 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3966 'S','h','a','r','e','d','D','L','L','s',0};
3968 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
3972 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
3977 DWORD sz = sizeof(count);
3980 hkey = openSharedDLLsKey();
3981 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
3982 if (rc != ERROR_SUCCESS)
3988 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
3992 hkey = openSharedDLLsKey();
3994 RegSetValueExW(hkey,path,0,REG_DWORD,
3995 (LPBYTE)&count,sizeof(count));
3997 RegDeleteValueW(hkey,path);
4003 * Return TRUE if the count should be written out and FALSE if not
4005 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
4011 /* only refcount DLLs */
4012 if (package->components[index].KeyPath[0]==0 ||
4013 package->components[index].Attributes &
4014 msidbComponentAttributesRegistryKeyPath ||
4015 package->components[index].Attributes &
4016 msidbComponentAttributesODBCDataSource)
4020 count = ACTION_GetSharedDLLsCount(package->components[index].
4022 write = (count > 0);
4024 if (package->components[index].Attributes &
4025 msidbComponentAttributesSharedDllRefCount)
4029 /* increment counts */
4030 for (j = 0; j < package->loaded_features; j++)
4034 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
4037 for (i = 0; i < package->features[j].ComponentCount; i++)
4039 if (package->features[j].Components[i] == index)
4043 /* decrement counts */
4044 for (j = 0; j < package->loaded_features; j++)
4047 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
4050 for (i = 0; i < package->features[j].ComponentCount; i++)
4052 if (package->features[j].Components[i] == index)
4057 /* ref count all the files in the component */
4059 for (j = 0; j < package->loaded_files; j++)
4061 if (package->files[j].Temporary)
4063 if (package->files[j].ComponentIndex == index)
4064 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
4067 /* add a count for permenent */
4068 if (package->components[index].Attributes &
4069 msidbComponentAttributesPermanent)
4072 package->components[index].RefCount = count;
4075 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
4076 package->components[index].RefCount);
4080 * Ok further analysis makes me think that this work is
4081 * actually done in the PublishComponents and PublishFeatures
4082 * step, and not here. It appears like the keypath and all that is
4083 * resolved in this step, however actually written in the Publish steps.
4084 * But we will leave it here for now because it is unclear
4086 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
4089 WCHAR squished_pc[GUID_SIZE];
4090 WCHAR squished_cc[GUID_SIZE];
4093 HKEY hkey=0,hkey2=0;
4096 return ERROR_INVALID_HANDLE;
4098 /* writes the Component and Features values to the registry */
4099 productcode = load_dynamic_property(package,szProductCode,&rc);
4103 rc = MSIREG_OpenComponents(&hkey);
4104 if (rc != ERROR_SUCCESS)
4107 squash_guid(productcode,squished_pc);
4108 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
4109 for (i = 0; i < package->loaded_components; i++)
4111 ui_progress(package,2,0,0,0);
4112 if (package->components[i].ComponentId[0]!=0)
4114 WCHAR *keypath = NULL;
4117 squash_guid(package->components[i].ComponentId,squished_cc);
4119 keypath = resolve_keypath(package,i);
4120 package->components[i].FullKeypath = keypath;
4122 /* do the refcounting */
4123 ACTION_RefCountComponent( package, i);
4125 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
4126 debugstr_w(package->components[i].Component),
4127 debugstr_w(squished_cc),
4128 debugstr_w(package->components[i].FullKeypath),
4129 package->components[i].RefCount);
4131 * Write the keypath out if the component is to be registered
4132 * and delete the key if the component is to be deregistered
4134 if (ACTION_VerifyComponentForAction(package, i,
4135 INSTALLSTATE_LOCAL))
4137 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
4138 if (rc != ERROR_SUCCESS)
4143 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
4144 (strlenW(keypath)+1)*sizeof(WCHAR));
4146 if (package->components[i].Attributes &
4147 msidbComponentAttributesPermanent)
4149 static const WCHAR szPermKey[] =
4150 { '0','0','0','0','0','0','0','0','0','0','0','0',
4151 '0','0','0','0','0','0','0', '0','0','0','0','0',
4152 '0','0','0','0','0','0','0','0',0};
4154 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
4156 (strlenW(keypath)+1)*sizeof(WCHAR));
4162 uirow = MSI_CreateRecord(3);
4163 MSI_RecordSetStringW(uirow,1,productcode);
4164 MSI_RecordSetStringW(uirow,2,package->components[i].
4166 MSI_RecordSetStringW(uirow,3,keypath);
4167 ui_actiondata(package,szProcessComponents,uirow);
4168 msiobj_release( &uirow->hdr );
4171 else if (ACTION_VerifyComponentForAction(package, i,
4172 INSTALLSTATE_ABSENT))
4176 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
4177 if (rc != ERROR_SUCCESS)
4180 RegDeleteValueW(hkey2,squished_pc);
4182 /* if the key is empty delete it */
4183 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
4185 if (res == ERROR_NO_MORE_ITEMS)
4186 RegDeleteKeyW(hkey,squished_cc);
4189 uirow = MSI_CreateRecord(2);
4190 MSI_RecordSetStringW(uirow,1,productcode);
4191 MSI_RecordSetStringW(uirow,2,package->components[i].
4193 ui_actiondata(package,szProcessComponents,uirow);
4194 msiobj_release( &uirow->hdr );
4199 HeapFree(GetProcessHeap(), 0, productcode);
4212 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
4213 LPWSTR lpszName, LONG_PTR lParam)
4216 typelib_struct *tl_struct = (typelib_struct*) lParam;
4217 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
4221 if (!IS_INTRESOURCE(lpszName))
4223 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
4227 sz = strlenW(tl_struct->source)+4;
4228 sz *= sizeof(WCHAR);
4230 if ((INT)lpszName == 1)
4231 tl_struct->path = strdupW(tl_struct->source);
4234 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
4235 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
4238 TRACE("trying %s\n", debugstr_w(tl_struct->path));
4239 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
4240 if (!SUCCEEDED(res))
4242 HeapFree(GetProcessHeap(),0,tl_struct->path);
4243 tl_struct->path = NULL;
4248 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
4249 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
4251 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4255 HeapFree(GetProcessHeap(),0,tl_struct->path);
4256 tl_struct->path = NULL;
4258 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4259 ITypeLib_Release(tl_struct->ptLib);
4264 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4267 * OK this is a bit confusing.. I am given a _Component key and I believe
4268 * that the file that is being registered as a type library is the "key file
4269 * of that component" which I interpret to mean "The file in the KeyPath of
4274 MSIRECORD * row = 0;
4275 static const WCHAR Query[] =
4276 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4277 '`','T','y','p','e','L','i','b','`',0};
4280 return ERROR_INVALID_HANDLE;
4282 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4283 if (rc != ERROR_SUCCESS)
4284 return ERROR_SUCCESS;
4286 rc = MSI_ViewExecute(view, 0);
4287 if (rc != ERROR_SUCCESS)
4289 MSI_ViewClose(view);
4290 msiobj_release(&view->hdr);
4296 WCHAR component[0x100];
4300 typelib_struct tl_struct;
4302 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
4304 rc = MSI_ViewFetch(view,&row);
4305 if (rc != ERROR_SUCCESS)
4312 MSI_RecordGetStringW(row,3,component,&sz);
4314 index = get_loaded_component(package,component);
4317 msiobj_release(&row->hdr);
4321 if (!ACTION_VerifyComponentForAction(package, index,
4322 INSTALLSTATE_LOCAL))
4324 TRACE("Skipping typelib reg due to disabled component\n");
4325 msiobj_release(&row->hdr);
4327 package->components[index].Action =
4328 package->components[index].Installed;
4333 package->components[index].Action = INSTALLSTATE_LOCAL;
4335 index = get_loaded_file(package,package->components[index].KeyPath);
4339 msiobj_release(&row->hdr);
4343 guid = load_dynamic_stringW(row,1);
4344 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
4345 LOAD_LIBRARY_AS_DATAFILE);
4348 CLSIDFromString(guid, &tl_struct.clsid);
4349 tl_struct.source = strdupW(package->files[index].TargetPath);
4350 tl_struct.path = NULL;
4352 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
4353 (LONG_PTR)&tl_struct);
4355 if (tl_struct.path != NULL)
4358 WCHAR helpid[0x100];
4362 MSI_RecordGetStringW(row,6,helpid,&sz);
4364 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4365 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
4366 HeapFree(GetProcessHeap(),0,help);
4368 if (!SUCCEEDED(res))
4369 ERR("Failed to register type library %s\n",
4370 debugstr_w(tl_struct.path));
4373 ui_actiondata(package,szRegisterTypeLibraries,row);
4375 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
4378 ITypeLib_Release(tl_struct.ptLib);
4379 HeapFree(GetProcessHeap(),0,tl_struct.path);
4382 ERR("Failed to load type library %s\n",
4383 debugstr_w(tl_struct.source));
4385 FreeLibrary(module);
4386 HeapFree(GetProcessHeap(),0,tl_struct.source);
4389 ERR("Could not load file! %s\n",
4390 debugstr_w(package->files[index].TargetPath));
4391 msiobj_release(&row->hdr);
4393 MSI_ViewClose(view);
4394 msiobj_release(&view->hdr);
4398 static INT load_appid(MSIPACKAGE* package, MSIRECORD *row)
4400 DWORD index = package->loaded_appids;
4404 /* fill in the data */
4406 package->loaded_appids++;
4407 if (package->loaded_appids == 1)
4408 package->appids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIAPPID));
4410 package->appids = HeapReAlloc(GetProcessHeap(),0,
4411 package->appids, package->loaded_appids * sizeof(MSIAPPID));
4413 memset(&package->appids[index],0,sizeof(MSIAPPID));
4415 sz = IDENTIFIER_SIZE;
4416 MSI_RecordGetStringW(row, 1, package->appids[index].AppID, &sz);
4417 TRACE("loading appid %s\n",debugstr_w(package->appids[index].AppID));
4419 buffer = load_dynamic_stringW(row,2);
4420 deformat_string(package,buffer,&package->appids[index].RemoteServerName);
4421 HeapFree(GetProcessHeap(),0,buffer);
4423 package->appids[index].LocalServer = load_dynamic_stringW(row,3);
4424 package->appids[index].ServiceParameters = load_dynamic_stringW(row,4);
4425 package->appids[index].DllSurrogate = load_dynamic_stringW(row,5);
4427 package->appids[index].ActivateAtStorage = !MSI_RecordIsNull(row,6);
4428 package->appids[index].RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
4433 static INT load_given_appid(MSIPACKAGE *package, LPCWSTR appid)
4438 static const WCHAR ExecSeqQuery[] =
4439 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4440 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
4441 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
4446 /* check for appids already loaded */
4447 for (i = 0; i < package->loaded_appids; i++)
4448 if (strcmpiW(package->appids[i].AppID,appid)==0)
4450 TRACE("found appid %s at index %i\n",debugstr_w(appid),i);
4454 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, appid);
4458 rc = load_appid(package, row);
4459 msiobj_release(&row->hdr);
4464 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
4465 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid);
4467 static INT load_progid(MSIPACKAGE* package, MSIRECORD *row)
4469 DWORD index = package->loaded_progids;
4472 /* fill in the data */
4474 package->loaded_progids++;
4475 if (package->loaded_progids == 1)
4476 package->progids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIPROGID));
4478 package->progids = HeapReAlloc(GetProcessHeap(),0,
4479 package->progids , package->loaded_progids * sizeof(MSIPROGID));
4481 memset(&package->progids[index],0,sizeof(MSIPROGID));
4483 package->progids[index].ProgID = load_dynamic_stringW(row,1);
4484 TRACE("loading progid %s\n",debugstr_w(package->progids[index].ProgID));
4486 buffer = load_dynamic_stringW(row,2);
4487 package->progids[index].ParentIndex = load_given_progid(package,buffer);
4488 if (package->progids[index].ParentIndex < 0 && buffer)
4489 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
4490 HeapFree(GetProcessHeap(),0,buffer);
4492 buffer = load_dynamic_stringW(row,3);
4493 package->progids[index].ClassIndex = load_given_class(package,buffer);
4494 if (package->progids[index].ClassIndex< 0 && buffer)
4495 FIXME("Unknown class %s\n",debugstr_w(buffer));
4496 HeapFree(GetProcessHeap(),0,buffer);
4498 package->progids[index].Description = load_dynamic_stringW(row,4);
4500 if (!MSI_RecordIsNull(row,6))
4502 INT icon_index = MSI_RecordGetInteger(row,6);
4503 LPWSTR FileName = load_dynamic_stringW(row,5);
4505 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4507 build_icon_path(package,FileName,&FilePath);
4509 package->progids[index].IconPath =
4510 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+10)*
4513 sprintfW(package->progids[index].IconPath,fmt,FilePath,icon_index);
4515 HeapFree(GetProcessHeap(),0,FilePath);
4516 HeapFree(GetProcessHeap(),0,FileName);
4520 buffer = load_dynamic_stringW(row,5);
4522 build_icon_path(package,buffer,&(package->progids[index].IconPath));
4523 HeapFree(GetProcessHeap(),0,buffer);
4526 package->progids[index].CurVerIndex = -1;
4527 package->progids[index].VersionIndIndex = -1;
4529 /* if we have a parent then we may be that parents CurVer */
4530 if (package->progids[index].ParentIndex >= 0 &&
4531 package->progids[index].ParentIndex != index)
4533 int pindex = package->progids[index].ParentIndex;
4534 while (package->progids[pindex].ParentIndex>= 0 &&
4535 package->progids[pindex].ParentIndex != pindex)
4536 pindex = package->progids[pindex].ParentIndex;
4538 FIXME("BAD BAD need to determing if we are really the CurVer\n");
4540 package->progids[index].CurVerIndex = pindex;
4541 package->progids[pindex].VersionIndIndex = index;
4547 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid)
4552 static const WCHAR ExecSeqQuery[] =
4553 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4554 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
4555 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
4560 /* check for progids already loaded */
4561 for (i = 0; i < package->loaded_progids; i++)
4562 if (strcmpiW(package->progids[i].ProgID,progid)==0)
4564 TRACE("found progid %s at index %i\n",debugstr_w(progid), i);
4568 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, progid);
4572 rc = load_progid(package, row);
4573 msiobj_release(&row->hdr);
4578 static INT load_class(MSIPACKAGE* package, MSIRECORD *row)
4580 DWORD index = package->loaded_classes;
4584 /* fill in the data */
4586 package->loaded_classes++;
4587 if (package->loaded_classes== 1)
4588 package->classes = HeapAlloc(GetProcessHeap(),0,sizeof(MSICLASS));
4590 package->classes = HeapReAlloc(GetProcessHeap(),0,
4591 package->classes, package->loaded_classes * sizeof(MSICLASS));
4593 memset(&package->classes[index],0,sizeof(MSICLASS));
4595 sz = IDENTIFIER_SIZE;
4596 MSI_RecordGetStringW(row, 1, package->classes[index].CLSID, &sz);
4597 TRACE("loading class %s\n",debugstr_w(package->classes[index].CLSID));
4598 sz = IDENTIFIER_SIZE;
4599 MSI_RecordGetStringW(row, 2, package->classes[index].Context, &sz);
4600 buffer = load_dynamic_stringW(row,3);
4601 package->classes[index].ComponentIndex = get_loaded_component(package,
4603 HeapFree(GetProcessHeap(),0,buffer);
4605 package->classes[index].ProgIDText = load_dynamic_stringW(row,4);
4606 package->classes[index].ProgIDIndex =
4607 load_given_progid(package, package->classes[index].ProgIDText);
4609 package->classes[index].Description = load_dynamic_stringW(row,5);
4611 buffer = load_dynamic_stringW(row,6);
4613 package->classes[index].AppIDIndex =
4614 load_given_appid(package, buffer);
4616 package->classes[index].AppIDIndex = -1;
4617 HeapFree(GetProcessHeap(),0,buffer);
4619 package->classes[index].FileTypeMask = load_dynamic_stringW(row,7);
4621 if (!MSI_RecordIsNull(row,9))
4624 INT icon_index = MSI_RecordGetInteger(row,9);
4625 LPWSTR FileName = load_dynamic_stringW(row,8);
4627 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4629 build_icon_path(package,FileName,&FilePath);
4631 package->classes[index].IconPath =
4632 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4635 sprintfW(package->classes[index].IconPath,fmt,FilePath,icon_index);
4637 HeapFree(GetProcessHeap(),0,FilePath);
4638 HeapFree(GetProcessHeap(),0,FileName);
4642 buffer = load_dynamic_stringW(row,8);
4644 build_icon_path(package,buffer,&(package->classes[index].IconPath));
4645 HeapFree(GetProcessHeap(),0,buffer);
4648 if (!MSI_RecordIsNull(row,10))
4650 i = MSI_RecordGetInteger(row,10);
4651 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4653 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4654 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
4659 package->classes[index].DefInprocHandler = strdupW(ole2);
4662 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4665 package->classes[index].DefInprocHandler = strdupW(ole2);
4666 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4672 package->classes[index].DefInprocHandler32 = load_dynamic_stringW(
4674 reduce_to_longfilename(package->classes[index].DefInprocHandler32);
4677 buffer = load_dynamic_stringW(row,11);
4678 deformat_string(package,buffer,&package->classes[index].Argument);
4679 HeapFree(GetProcessHeap(),0,buffer);
4681 buffer = load_dynamic_stringW(row,12);
4682 package->classes[index].FeatureIndex = get_loaded_feature(package,buffer);
4683 HeapFree(GetProcessHeap(),0,buffer);
4685 package->classes[index].Attributes = MSI_RecordGetInteger(row,13);
4691 * the Class table has 3 primary keys. Generally it is only
4692 * referenced through the first CLSID key. However when loading
4693 * all of the classes we need to make sure we do not ignore rows
4694 * with other Context and ComponentIndexs
4696 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid)
4701 static const WCHAR ExecSeqQuery[] =
4702 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4703 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
4704 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
4710 /* check for classes already loaded */
4711 for (i = 0; i < package->loaded_classes; i++)
4712 if (strcmpiW(package->classes[i].CLSID,classid)==0)
4714 TRACE("found class %s at index %i\n",debugstr_w(classid), i);
4718 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
4722 rc = load_class(package, row);
4723 msiobj_release(&row->hdr);
4728 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension);
4730 static INT load_mime(MSIPACKAGE* package, MSIRECORD *row)
4732 DWORD index = package->loaded_mimes;
4736 /* fill in the data */
4738 package->loaded_mimes++;
4739 if (package->loaded_mimes== 1)
4740 package->mimes= HeapAlloc(GetProcessHeap(),0,sizeof(MSIMIME));
4742 package->mimes= HeapReAlloc(GetProcessHeap(),0,
4743 package->mimes, package->loaded_mimes*
4746 memset(&package->mimes[index],0,sizeof(MSIMIME));
4748 package->mimes[index].ContentType = load_dynamic_stringW(row,1);
4749 TRACE("loading mime %s\n",debugstr_w(package->mimes[index].ContentType));
4751 buffer = load_dynamic_stringW(row,2);
4752 package->mimes[index].ExtensionIndex = load_given_extension(package,
4754 HeapFree(GetProcessHeap(),0,buffer);
4756 sz = IDENTIFIER_SIZE;
4757 MSI_RecordGetStringW(row,3,package->mimes[index].CLSID,&sz);
4758 package->mimes[index].ClassIndex= load_given_class(package,
4759 package->mimes[index].CLSID);
4764 static INT load_given_mime(MSIPACKAGE *package, LPCWSTR mime)
4769 static const WCHAR ExecSeqQuery[] =
4770 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4771 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
4772 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
4773 '\'','%','s','\'',0};
4778 /* check for mime already loaded */
4779 for (i = 0; i < package->loaded_mimes; i++)
4780 if (strcmpiW(package->mimes[i].ContentType,mime)==0)
4782 TRACE("found mime %s at index %i\n",debugstr_w(mime), i);
4786 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
4790 rc = load_mime(package, row);
4791 msiobj_release(&row->hdr);
4796 static INT load_extension(MSIPACKAGE* package, MSIRECORD *row)
4798 DWORD index = package->loaded_extensions;
4802 /* fill in the data */
4804 package->loaded_extensions++;
4805 if (package->loaded_extensions == 1)
4806 package->extensions = HeapAlloc(GetProcessHeap(),0,sizeof(MSIEXTENSION));
4808 package->extensions = HeapReAlloc(GetProcessHeap(),0,
4809 package->extensions, package->loaded_extensions*
4810 sizeof(MSIEXTENSION));
4812 memset(&package->extensions[index],0,sizeof(MSIEXTENSION));
4815 MSI_RecordGetStringW(row,1,package->extensions[index].Extension,&sz);
4816 TRACE("loading extension %s\n",
4817 debugstr_w(package->extensions[index].Extension));
4819 buffer = load_dynamic_stringW(row,2);
4820 package->extensions[index].ComponentIndex =
4821 get_loaded_component(package,buffer);
4822 HeapFree(GetProcessHeap(),0,buffer);
4824 package->extensions[index].ProgIDText = load_dynamic_stringW(row,3);
4825 package->extensions[index].ProgIDIndex = load_given_progid(package,
4826 package->extensions[index].ProgIDText);
4828 buffer = load_dynamic_stringW(row,4);
4829 package->extensions[index].MIMEIndex = load_given_mime(package,buffer);
4830 HeapFree(GetProcessHeap(),0,buffer);
4832 buffer = load_dynamic_stringW(row,5);
4833 package->extensions[index].FeatureIndex =
4834 get_loaded_feature(package,buffer);
4835 HeapFree(GetProcessHeap(),0,buffer);
4841 * While the extension table has 2 primary keys, this function is only looking
4842 * at the Extension key which is what is referenced as a forign key
4844 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension)
4849 static const WCHAR ExecSeqQuery[] =
4850 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4851 '`','E','x','t','e','n','s','i','o','n','`',' ',
4852 'W','H','E','R','E',' ',
4853 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
4854 '\'','%','s','\'',0};
4859 /* check for extensions already loaded */
4860 for (i = 0; i < package->loaded_extensions; i++)
4861 if (strcmpiW(package->extensions[i].Extension,extension)==0)
4863 TRACE("extension %s already loaded at %i\n",debugstr_w(extension),
4868 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, extension);
4872 rc = load_extension(package, row);
4873 msiobj_release(&row->hdr);
4878 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
4880 MSIPACKAGE* package = (MSIPACKAGE*)param;
4881 DWORD index = package->loaded_verbs;
4884 /* fill in the data */
4886 package->loaded_verbs++;
4887 if (package->loaded_verbs == 1)
4888 package->verbs = HeapAlloc(GetProcessHeap(),0,sizeof(MSIVERB));
4890 package->verbs = HeapReAlloc(GetProcessHeap(),0,
4891 package->verbs , package->loaded_verbs * sizeof(MSIVERB));
4893 memset(&package->verbs[index],0,sizeof(MSIVERB));
4895 buffer = load_dynamic_stringW(row,1);
4896 package->verbs[index].ExtensionIndex = load_given_extension(package,buffer);
4897 if (package->verbs[index].ExtensionIndex < 0 && buffer)
4898 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
4899 HeapFree(GetProcessHeap(),0,buffer);
4901 package->verbs[index].Verb = load_dynamic_stringW(row,2);
4902 TRACE("loading verb %s\n",debugstr_w(package->verbs[index].Verb));
4903 package->verbs[index].Sequence = MSI_RecordGetInteger(row,3);
4905 buffer = load_dynamic_stringW(row,4);
4906 deformat_string(package,buffer,&package->verbs[index].Command);
4907 HeapFree(GetProcessHeap(),0,buffer);
4909 buffer = load_dynamic_stringW(row,5);
4910 deformat_string(package,buffer,&package->verbs[index].Argument);
4911 HeapFree(GetProcessHeap(),0,buffer);
4913 /* assosiate the verb with the correct extension */
4914 if (package->verbs[index].ExtensionIndex >= 0)
4916 MSIEXTENSION* extension = &package->extensions[package->verbs[index].
4918 int count = extension->VerbCount;
4921 FIXME("Exceeding max verb count! Increase that limit!!!\n");
4924 extension->VerbCount++;
4925 extension->Verbs[count] = index;
4929 return ERROR_SUCCESS;
4932 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
4937 INT component_index;
4938 MSIPACKAGE* package =(MSIPACKAGE*)param;
4942 clsid = load_dynamic_stringW(rec,1);
4943 context = load_dynamic_stringW(rec,2);
4944 buffer = load_dynamic_stringW(rec,3);
4945 component_index = get_loaded_component(package,buffer);
4947 for (i = 0; i < package->loaded_classes; i++)
4949 if (strcmpiW(clsid,package->classes[i].CLSID))
4951 if (strcmpW(context,package->classes[i].Context))
4953 if (component_index == package->classes[i].ComponentIndex)
4960 HeapFree(GetProcessHeap(),0,buffer);
4961 HeapFree(GetProcessHeap(),0,clsid);
4962 HeapFree(GetProcessHeap(),0,context);
4965 load_class(package, rec);
4967 return ERROR_SUCCESS;
4970 static VOID load_all_classes(MSIPACKAGE *package)
4972 UINT rc = ERROR_SUCCESS;
4975 static const WCHAR ExecSeqQuery[] =
4976 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
4977 '`','C','l','a','s','s','`',0};
4979 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4980 if (rc != ERROR_SUCCESS)
4983 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
4984 msiobj_release(&view->hdr);
4987 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
4991 INT component_index;
4992 MSIPACKAGE* package =(MSIPACKAGE*)param;
4996 extension = load_dynamic_stringW(rec,1);
4997 buffer = load_dynamic_stringW(rec,2);
4998 component_index = get_loaded_component(package,buffer);
5000 for (i = 0; i < package->loaded_extensions; i++)
5002 if (strcmpiW(extension,package->extensions[i].Extension))
5004 if (component_index == package->extensions[i].ComponentIndex)
5011 HeapFree(GetProcessHeap(),0,buffer);
5012 HeapFree(GetProcessHeap(),0,extension);
5015 load_extension(package, rec);
5017 return ERROR_SUCCESS;
5020 static VOID load_all_extensions(MSIPACKAGE *package)
5022 UINT rc = ERROR_SUCCESS;
5025 static const WCHAR ExecSeqQuery[] =
5026 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5027 '`','E','x','t','e','n','s','i','o','n','`',0};
5029 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5030 if (rc != ERROR_SUCCESS)
5033 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
5034 msiobj_release(&view->hdr);
5037 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
5040 MSIPACKAGE* package =(MSIPACKAGE*)param;
5042 buffer = load_dynamic_stringW(rec,1);
5043 load_given_progid(package,buffer);
5044 HeapFree(GetProcessHeap(),0,buffer);
5045 return ERROR_SUCCESS;
5048 static VOID load_all_progids(MSIPACKAGE *package)
5050 UINT rc = ERROR_SUCCESS;
5053 static const WCHAR ExecSeqQuery[] =
5054 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
5055 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
5057 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5058 if (rc != ERROR_SUCCESS)
5061 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
5062 msiobj_release(&view->hdr);
5065 static VOID load_all_verbs(MSIPACKAGE *package)
5067 UINT rc = ERROR_SUCCESS;
5070 static const WCHAR ExecSeqQuery[] =
5071 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5072 '`','V','e','r','b','`',0};
5074 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5075 if (rc != ERROR_SUCCESS)
5078 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
5079 msiobj_release(&view->hdr);
5082 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
5085 MSIPACKAGE* package =(MSIPACKAGE*)param;
5087 buffer = load_dynamic_stringW(rec,1);
5088 load_given_mime(package,buffer);
5089 HeapFree(GetProcessHeap(),0,buffer);
5090 return ERROR_SUCCESS;
5093 static VOID load_all_mimes(MSIPACKAGE *package)
5095 UINT rc = ERROR_SUCCESS;
5098 static const WCHAR ExecSeqQuery[] =
5099 {'S','E','L','E','C','T',' ',
5100 '`','C','o','n','t','e','n','t','T','y','p','e','`',
5101 ' ','F','R','O','M',' ',
5102 '`','M','I','M','E','`',0};
5104 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5105 if (rc != ERROR_SUCCESS)
5108 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
5109 msiobj_release(&view->hdr);
5112 static void load_classes_and_such(MSIPACKAGE *package)
5114 TRACE("Loading all the class info and related tables\n");
5116 /* check if already loaded */
5117 if (package->classes || package->extensions || package->progids ||
5118 package->verbs || package->mimes)
5121 load_all_classes(package);
5122 load_all_extensions(package);
5123 load_all_progids(package);
5124 /* these loads must come after the other loads */
5125 load_all_verbs(package);
5126 load_all_mimes(package);
5129 static void mark_progid_for_install(MSIPACKAGE* package, INT index)
5134 if (index < 0 || index >= package->loaded_progids)
5137 progid = &package->progids[index];
5139 if (progid->InstallMe == TRUE)
5142 progid->InstallMe = TRUE;
5144 /* all children if this is a parent also install */
5145 for (i = 0; i < package->loaded_progids; i++)
5146 if (package->progids[i].ParentIndex == index)
5147 mark_progid_for_install(package,i);
5150 static void mark_mime_for_install(MSIPACKAGE* package, INT index)
5154 if (index < 0 || index >= package->loaded_mimes)
5157 mime = &package->mimes[index];
5159 if (mime->InstallMe == TRUE)
5162 mime->InstallMe = TRUE;
5165 static UINT register_appid(MSIPACKAGE *package, int appidIndex, LPCWSTR app )
5167 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5171 return ERROR_INVALID_HANDLE;
5173 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
5174 RegCreateKeyW(hkey2,package->appids[appidIndex].AppID,&hkey3);
5175 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
5176 (strlenW(app)+1)*sizeof(WCHAR));
5178 if (package->appids[appidIndex].RemoteServerName)
5181 static const WCHAR szRemoteServerName[] =
5182 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
5185 size = (strlenW(package->appids[appidIndex].RemoteServerName)+1) *
5188 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,
5189 (LPVOID)package->appids[appidIndex].RemoteServerName,
5193 if (package->appids[appidIndex].LocalServer)
5195 static const WCHAR szLocalService[] =
5196 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
5198 size = (strlenW(package->appids[appidIndex].LocalServer)+1) *
5201 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,
5202 (LPVOID)package->appids[appidIndex].LocalServer,size);
5205 if (package->appids[appidIndex].ServiceParameters)
5207 static const WCHAR szService[] =
5208 {'S','e','r','v','i','c','e',
5209 'P','a','r','a','m','e','t','e','r','s',0};
5211 size = (strlenW(package->appids[appidIndex].ServiceParameters)+1) *
5213 RegSetValueExW(hkey3,szService,0,REG_SZ,
5214 (LPVOID)package->appids[appidIndex].ServiceParameters,
5218 if (package->appids[appidIndex].DllSurrogate)
5220 static const WCHAR szDLL[] =
5221 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
5223 size = (strlenW(package->appids[appidIndex].DllSurrogate)+1) *
5225 RegSetValueExW(hkey3,szDLL,0,REG_SZ,
5226 (LPVOID)package->appids[appidIndex].DllSurrogate,size);
5229 if (package->appids[appidIndex].ActivateAtStorage)
5231 static const WCHAR szActivate[] =
5232 {'A','c','t','i','v','a','t','e','A','s',
5233 'S','t','o','r','a','g','e',0};
5234 static const WCHAR szY[] = {'Y',0};
5236 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
5239 if (package->appids[appidIndex].RunAsInteractiveUser)
5241 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
5242 static const WCHAR szUser[] =
5243 {'I','n','t','e','r','a','c','t','i','v','e',' ',
5246 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,sizeof(szUser));
5251 return ERROR_SUCCESS;
5254 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
5257 * Again I am assuming the words, "Whose key file represents" when referring
5258 * to a Component as to meaning that Components KeyPath file
5263 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5264 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
5265 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 };
5266 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5267 static const WCHAR szSpace[] = {' ',0};
5268 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
5269 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
5270 HKEY hkey,hkey2,hkey3;
5271 BOOL install_on_demand = FALSE;
5275 return ERROR_INVALID_HANDLE;
5277 load_classes_and_such(package);
5278 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
5279 if (rc != ERROR_SUCCESS)
5280 return ERROR_FUNCTION_FAILED;
5282 /* install_on_demand should be set if OLE supports install on demand OLE
5283 * servers. For now i am defaulting to FALSE because i do not know how to
5284 * check, and i am told our builtin OLE does not support it
5287 for (i = 0; i < package->loaded_classes; i++)
5293 if (package->classes[i].ComponentIndex < 0)
5298 index = package->classes[i].ComponentIndex;
5299 f_index = package->classes[i].FeatureIndex;
5302 * yes. MSDN says that these are based on _Feature_ not on
5303 * Component. So verify the feature is to be installed
5305 if ((!ACTION_VerifyFeatureForAction(package, f_index,
5306 INSTALLSTATE_LOCAL)) &&
5307 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
5308 f_index, INSTALLSTATE_ADVERTISED)))
5310 TRACE("Skipping class %s reg due to disabled feature %s\n",
5311 debugstr_w(package->classes[i].CLSID),
5312 debugstr_w(package->features[f_index].Feature));
5317 TRACE("Registering index %i class %s\n",i,
5318 debugstr_w(package->classes[i].CLSID));
5320 package->classes[i].Installed = TRUE;
5321 if (package->classes[i].ProgIDIndex >= 0)
5322 mark_progid_for_install(package, package->classes[i].ProgIDIndex);
5324 RegCreateKeyW(hkey,package->classes[i].CLSID,&hkey2);
5326 if (package->classes[i].Description)
5327 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)package->classes[i].
5328 Description, (strlenW(package->classes[i].
5329 Description)+1)*sizeof(WCHAR));
5331 RegCreateKeyW(hkey2,package->classes[i].Context,&hkey3);
5332 index = get_loaded_file(package,package->components[index].KeyPath);
5335 /* the context server is a short path name
5336 * except for if it is InprocServer32...
5338 if (strcmpiW(package->classes[i].Context,szInprocServer32)!=0)
5341 sz = GetShortPathNameW(package->files[index].TargetPath, NULL, 0);
5344 ERR("Unable to find short path for CLSID COM Server\n");
5349 size = sz * sizeof(WCHAR);
5351 if (package->classes[i].Argument)
5353 size += strlenW(package->classes[i].Argument) *
5355 size += sizeof(WCHAR);
5358 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5359 GetShortPathNameW(package->files[index].TargetPath, argument,
5362 if (package->classes[i].Argument)
5364 strcatW(argument,szSpace);
5365 strcatW(argument,package->classes[i].Argument);
5371 size = lstrlenW(package->files[index].TargetPath) * sizeof(WCHAR);
5373 if (package->classes[i].Argument)
5375 size += strlenW(package->classes[i].Argument) * sizeof(WCHAR);
5376 size += sizeof(WCHAR);
5379 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5380 strcpyW(argument, package->files[index].TargetPath);
5382 if (package->classes[i].Argument)
5384 strcatW(argument,szSpace);
5385 strcatW(argument,package->classes[i].Argument);
5391 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
5392 HeapFree(GetProcessHeap(),0,argument);
5397 if (package->classes[i].ProgIDIndex >= 0 ||
5398 package->classes[i].ProgIDText)
5402 if (package->classes[i].ProgIDIndex >= 0)
5403 progid = package->progids[
5404 package->classes[i].ProgIDIndex].ProgID;
5406 progid = package->classes[i].ProgIDText;
5408 RegCreateKeyW(hkey2,szProgID,&hkey3);
5409 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)progid,
5410 (strlenW(progid)+1) *sizeof(WCHAR));
5413 if (package->classes[i].ProgIDIndex >= 0 &&
5414 package->progids[package->classes[i].ProgIDIndex].
5415 VersionIndIndex >= 0)
5417 LPWSTR viprogid = strdupW(package->progids[package->progids[
5418 package->classes[i].ProgIDIndex].VersionIndIndex].
5420 RegCreateKeyW(hkey2,szVIProgID,&hkey3);
5421 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)viprogid,
5422 (strlenW(viprogid)+1) *sizeof(WCHAR));
5424 HeapFree(GetProcessHeap(), 0, viprogid);
5428 if (package->classes[i].AppIDIndex >= 0)
5430 RegSetValueExW(hkey2,szAppID,0,REG_SZ,
5431 (LPVOID)package->appids[package->classes[i].AppIDIndex].AppID,
5432 (strlenW(package->appids[package->classes[i].AppIDIndex].AppID)+1)
5435 register_appid(package,package->classes[i].AppIDIndex,
5436 package->classes[i].Description);
5439 if (package->classes[i].IconPath)
5441 static const WCHAR szDefaultIcon[] =
5442 {'D','e','f','a','u','l','t','I','c','o','n',0};
5444 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
5446 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5447 (LPVOID)package->classes[i].IconPath,
5448 (strlenW(package->classes[i].IconPath)+1) *
5454 if (package->classes[i].DefInprocHandler)
5456 static const WCHAR szInproc[] =
5457 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
5459 size = (strlenW(package->classes[i].DefInprocHandler) + 1) *
5461 RegCreateKeyW(hkey2,szInproc,&hkey3);
5462 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5463 (LPVOID)package->classes[i].DefInprocHandler, size);
5467 if (package->classes[i].DefInprocHandler32)
5469 static const WCHAR szInproc32[] =
5470 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
5472 size = (strlenW(package->classes[i].DefInprocHandler32) + 1) *
5475 RegCreateKeyW(hkey2,szInproc32,&hkey3);
5476 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5477 (LPVOID)package->classes[i].DefInprocHandler32,size);
5483 /* if there is a FileTypeMask, register the FileType */
5484 if (package->classes[i].FileTypeMask)
5489 ptr = package->classes[i].FileTypeMask;
5492 ptr2 = strchrW(ptr,';');
5495 keyname = HeapAlloc(GetProcessHeap(),0,(strlenW(szFileType_fmt)+
5496 strlenW(package->classes[i].CLSID) + 4)
5498 sprintfW(keyname,szFileType_fmt, package->classes[i].CLSID,
5501 RegCreateKeyW(HKEY_CLASSES_ROOT,keyname,&hkey2);
5502 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPVOID)ptr,
5503 strlenW(ptr)*sizeof(WCHAR));
5505 HeapFree(GetProcessHeap(), 0, keyname);
5516 uirow = MSI_CreateRecord(1);
5518 MSI_RecordSetStringW(uirow,1,package->classes[i].CLSID);
5519 ui_actiondata(package,szRegisterClassInfo,uirow);
5520 msiobj_release(&uirow->hdr);
5527 static UINT register_progid_base(MSIPACKAGE* package, MSIPROGID* progid,
5530 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5531 static const WCHAR szDefaultIcon[] =
5532 {'D','e','f','a','u','l','t','I','c','o','n',0};
5535 RegCreateKeyW(HKEY_CLASSES_ROOT,progid->ProgID,&hkey);
5537 if (progid->Description)
5539 RegSetValueExW(hkey,NULL,0,REG_SZ,
5540 (LPVOID)progid->Description,
5541 (strlenW(progid->Description)+1) *
5545 if (progid->ClassIndex >= 0)
5547 RegCreateKeyW(hkey,szCLSID,&hkey2);
5548 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5549 (LPVOID)package->classes[progid->ClassIndex].CLSID,
5550 (strlenW(package->classes[progid->ClassIndex].CLSID)+1)
5554 strcpyW(clsid,package->classes[progid->ClassIndex].CLSID);
5560 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
5563 if (progid->IconPath)
5565 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5567 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5568 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5571 return ERROR_SUCCESS;
5574 static UINT register_progid(MSIPACKAGE *package, MSIPROGID* progid,
5577 UINT rc = ERROR_SUCCESS;
5579 if (progid->ParentIndex < 0)
5580 rc = register_progid_base(package, progid, clsid);
5585 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5586 static const WCHAR szDefaultIcon[] =
5587 {'D','e','f','a','u','l','t','I','c','o','n',0};
5588 static const WCHAR szCurVer[] =
5589 {'C','u','r','V','e','r',0};
5591 /* check if already registered */
5592 RegCreateKeyExW(HKEY_CLASSES_ROOT, progid->ProgID, 0, NULL, 0,
5593 KEY_ALL_ACCESS, NULL, &hkey, &disp );
5594 if (disp == REG_OPENED_EXISTING_KEY)
5596 TRACE("Key already registered\n");
5601 TRACE("Registering Parent %s index %i\n",
5602 debugstr_w(package->progids[progid->ParentIndex].ProgID),
5603 progid->ParentIndex);
5604 rc = register_progid(package,&package->progids[progid->ParentIndex],
5607 /* clsid is same as parent */
5608 RegCreateKeyW(hkey,szCLSID,&hkey2);
5609 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
5615 if (progid->Description)
5617 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid->Description,
5618 (strlenW(progid->Description)+1) * sizeof(WCHAR));
5621 if (progid->IconPath)
5623 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5624 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5625 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5629 /* write out the current version */
5630 if (progid->CurVerIndex >= 0)
5632 RegCreateKeyW(hkey,szCurVer,&hkey2);
5633 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5634 (LPVOID)package->progids[progid->CurVerIndex].ProgID,
5635 (strlenW(package->progids[progid->CurVerIndex].ProgID)+1) *
5645 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
5651 return ERROR_INVALID_HANDLE;
5653 load_classes_and_such(package);
5655 for (i = 0; i < package->loaded_progids; i++)
5657 WCHAR clsid[0x1000];
5659 /* check if this progid is to be installed */
5660 package->progids[i].InstallMe = ((package->progids[i].InstallMe) ||
5661 (package->progids[i].ClassIndex >= 0 &&
5662 package->classes[package->progids[i].ClassIndex].Installed));
5664 if (!package->progids[i].InstallMe)
5666 TRACE("progid %s not scheduled to be installed\n",
5667 debugstr_w(package->progids[i].ProgID));
5671 TRACE("Registering progid %s index %i\n",
5672 debugstr_w(package->progids[i].ProgID), i);
5674 register_progid(package,&package->progids[i],clsid);
5676 uirow = MSI_CreateRecord(1);
5677 MSI_RecordSetStringW(uirow,1,package->progids[i].ProgID);
5678 ui_actiondata(package,szRegisterProgIdInfo,uirow);
5679 msiobj_release(&uirow->hdr);
5682 return ERROR_SUCCESS;
5685 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
5689 LPWSTR SystemFolder;
5693 static const WCHAR szInstaller[] =
5694 {'M','i','c','r','o','s','o','f','t','\\',
5695 'I','n','s','t','a','l','l','e','r','\\',0};
5696 static const WCHAR szFolder[] =
5697 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
5699 ProductCode = load_dynamic_property(package,szProductCode,&rc);
5703 SystemFolder = load_dynamic_property(package,szFolder,NULL);
5705 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
5707 create_full_pathW(dest);
5709 *FilePath = build_directory_name(2, dest, icon_name);
5711 HeapFree(GetProcessHeap(),0,SystemFolder);
5712 HeapFree(GetProcessHeap(),0,ProductCode);
5713 HeapFree(GetProcessHeap(),0,dest);
5714 return ERROR_SUCCESS;
5717 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
5721 MSIRECORD * row = 0;
5722 static const WCHAR Query[] =
5723 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5724 '`','S','h','o','r','t','c','u','t','`',0};
5730 return ERROR_INVALID_HANDLE;
5732 res = CoInitialize( NULL );
5735 ERR("CoInitialize failed\n");
5736 return ERROR_FUNCTION_FAILED;
5739 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5740 if (rc != ERROR_SUCCESS)
5741 return ERROR_SUCCESS;
5743 rc = MSI_ViewExecute(view, 0);
5744 if (rc != ERROR_SUCCESS)
5746 MSI_ViewClose(view);
5747 msiobj_release(&view->hdr);
5753 LPWSTR target_file, target_folder;
5754 WCHAR buffer[0x100];
5757 static const WCHAR szlnk[]={'.','l','n','k',0};
5759 rc = MSI_ViewFetch(view,&row);
5760 if (rc != ERROR_SUCCESS)
5767 MSI_RecordGetStringW(row,4,buffer,&sz);
5769 index = get_loaded_component(package,buffer);
5773 msiobj_release(&row->hdr);
5777 if (!ACTION_VerifyComponentForAction(package, index,
5778 INSTALLSTATE_LOCAL))
5780 TRACE("Skipping shortcut creation due to disabled component\n");
5781 msiobj_release(&row->hdr);
5783 package->components[index].Action =
5784 package->components[index].Installed;
5789 package->components[index].Action = INSTALLSTATE_LOCAL;
5791 ui_actiondata(package,szCreateShortcuts,row);
5793 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
5794 &IID_IShellLinkW, (LPVOID *) &sl );
5798 ERR("Is IID_IShellLink\n");
5799 msiobj_release(&row->hdr);
5803 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
5806 ERR("Is IID_IPersistFile\n");
5807 msiobj_release(&row->hdr);
5812 MSI_RecordGetStringW(row,2,buffer,&sz);
5813 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
5815 /* may be needed because of a bug somehwere else */
5816 create_full_pathW(target_folder);
5819 MSI_RecordGetStringW(row,3,buffer,&sz);
5820 reduce_to_longfilename(buffer);
5821 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
5822 strcatW(buffer,szlnk);
5823 target_file = build_directory_name(2, target_folder, buffer);
5824 HeapFree(GetProcessHeap(),0,target_folder);
5827 MSI_RecordGetStringW(row,5,buffer,&sz);
5828 if (strchrW(buffer,'['))
5831 deformat_string(package,buffer,&deformated);
5832 IShellLinkW_SetPath(sl,deformated);
5833 HeapFree(GetProcessHeap(),0,deformated);
5838 FIXME("poorly handled shortcut format, advertised shortcut\n");
5839 keypath = strdupW(package->components[index].FullKeypath);
5840 IShellLinkW_SetPath(sl,keypath);
5841 HeapFree(GetProcessHeap(),0,keypath);
5844 if (!MSI_RecordIsNull(row,6))
5848 MSI_RecordGetStringW(row,6,buffer,&sz);
5849 deformat_string(package,buffer,&deformated);
5850 IShellLinkW_SetArguments(sl,deformated);
5851 HeapFree(GetProcessHeap(),0,deformated);
5854 if (!MSI_RecordIsNull(row,7))
5857 deformated = load_dynamic_stringW(row,7);
5858 IShellLinkW_SetDescription(sl,deformated);
5859 HeapFree(GetProcessHeap(),0,deformated);
5862 if (!MSI_RecordIsNull(row,8))
5863 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
5865 if (!MSI_RecordIsNull(row,9))
5871 MSI_RecordGetStringW(row,9,buffer,&sz);
5873 build_icon_path(package,buffer,&Path);
5874 index = MSI_RecordGetInteger(row,10);
5876 IShellLinkW_SetIconLocation(sl,Path,index);
5877 HeapFree(GetProcessHeap(),0,Path);
5880 if (!MSI_RecordIsNull(row,11))
5881 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
5883 if (!MSI_RecordIsNull(row,12))
5887 MSI_RecordGetStringW(row,12,buffer,&sz);
5888 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
5889 IShellLinkW_SetWorkingDirectory(sl,Path);
5890 HeapFree(GetProcessHeap(), 0, Path);
5893 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
5894 IPersistFile_Save(pf,target_file,FALSE);
5896 HeapFree(GetProcessHeap(),0,target_file);
5898 IPersistFile_Release( pf );
5899 IShellLinkW_Release( sl );
5901 msiobj_release(&row->hdr);
5903 MSI_ViewClose(view);
5904 msiobj_release(&view->hdr);
5914 * 99% of the work done here is only done for
5915 * advertised installs. However this is where the
5916 * Icon table is processed and written out
5917 * so that is what I am going to do here.
5919 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
5923 MSIRECORD * row = 0;
5924 static const WCHAR Query[]=
5925 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5926 '`','I','c','o','n','`',0};
5928 /* for registry stuff */
5932 static const WCHAR szProductName[] =
5933 {'P','r','o','d','u','c','t','N','a','m','e',0};
5934 static const WCHAR szPackageCode[] =
5935 {'P','a','c','k','a','g','e','C','o','d','e',0};
5938 MSIHANDLE hDb, hSumInfo;
5941 return ERROR_INVALID_HANDLE;
5943 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5944 if (rc != ERROR_SUCCESS)
5947 rc = MSI_ViewExecute(view, 0);
5948 if (rc != ERROR_SUCCESS)
5950 MSI_ViewClose(view);
5951 msiobj_release(&view->hdr);
5958 WCHAR *FilePath=NULL;
5959 WCHAR *FileName=NULL;
5962 rc = MSI_ViewFetch(view,&row);
5963 if (rc != ERROR_SUCCESS)
5969 FileName = load_dynamic_stringW(row,1);
5972 ERR("Unable to get FileName\n");
5973 msiobj_release(&row->hdr);
5977 build_icon_path(package,FileName,&FilePath);
5979 HeapFree(GetProcessHeap(),0,FileName);
5981 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
5983 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
5984 FILE_ATTRIBUTE_NORMAL, NULL);
5986 if (the_file == INVALID_HANDLE_VALUE)
5988 ERR("Unable to create file %s\n",debugstr_w(FilePath));
5989 msiobj_release(&row->hdr);
5990 HeapFree(GetProcessHeap(),0,FilePath);
5998 rc = MSI_RecordReadStream(row,2,buffer,&sz);
5999 if (rc != ERROR_SUCCESS)
6001 ERR("Failed to get stream\n");
6002 CloseHandle(the_file);
6003 DeleteFileW(FilePath);
6006 WriteFile(the_file,buffer,sz,&write,NULL);
6007 } while (sz == 1024);
6009 HeapFree(GetProcessHeap(),0,FilePath);
6011 CloseHandle(the_file);
6012 msiobj_release(&row->hdr);
6014 MSI_ViewClose(view);
6015 msiobj_release(&view->hdr);
6018 /* ok there is a lot more done here but i need to figure out what */
6019 productcode = load_dynamic_property(package,szProductCode,&rc);
6023 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
6024 if (rc != ERROR_SUCCESS)
6027 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6028 if (rc != ERROR_SUCCESS)
6032 buffer = load_dynamic_property(package,szProductName,NULL);
6033 size = strlenW(buffer)*sizeof(WCHAR);
6034 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
6035 HeapFree(GetProcessHeap(),0,buffer);
6036 FIXME("Need to write more keys to the user registry\n");
6038 hDb= alloc_msihandle( &package->db->hdr );
6039 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
6040 MsiCloseHandle(hDb);
6041 if (rc == ERROR_SUCCESS)
6043 WCHAR guidbuffer[0x200];
6045 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
6047 if (rc == ERROR_SUCCESS)
6049 WCHAR squashed[GUID_SIZE];
6050 /* for now we only care about the first guid */
6051 LPWSTR ptr = strchrW(guidbuffer,';');
6053 squash_guid(guidbuffer,squashed);
6054 size = strlenW(squashed)*sizeof(WCHAR);
6055 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
6060 ERR("Unable to query Revision_Number... \n");
6063 MsiCloseHandle(hSumInfo);
6067 ERR("Unable to open Summary Information\n");
6073 HeapFree(GetProcessHeap(),0,productcode);
6080 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
6084 MSIRECORD * row = 0;
6085 static const WCHAR ExecSeqQuery[] =
6086 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6087 '`','I','n','i','F','i','l','e','`',0};
6088 static const WCHAR szWindowsFolder[] =
6089 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
6091 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6092 if (rc != ERROR_SUCCESS)
6094 TRACE("no IniFile table\n");
6095 return ERROR_SUCCESS;
6098 rc = MSI_ViewExecute(view, 0);
6099 if (rc != ERROR_SUCCESS)
6101 MSI_ViewClose(view);
6102 msiobj_release(&view->hdr);
6108 LPWSTR component,filename,dirproperty,section,key,value,identifier;
6109 LPWSTR deformated_section, deformated_key, deformated_value;
6110 LPWSTR folder, fullname = NULL;
6112 INT component_index,action;
6114 rc = MSI_ViewFetch(view,&row);
6115 if (rc != ERROR_SUCCESS)
6121 component = load_dynamic_stringW(row, 8);
6122 component_index = get_loaded_component(package,component);
6123 HeapFree(GetProcessHeap(),0,component);
6125 if (!ACTION_VerifyComponentForAction(package, component_index,
6126 INSTALLSTATE_LOCAL))
6128 TRACE("Skipping ini file due to disabled component\n");
6129 msiobj_release(&row->hdr);
6131 package->components[component_index].Action =
6132 package->components[component_index].Installed;
6137 package->components[component_index].Action = INSTALLSTATE_LOCAL;
6139 identifier = load_dynamic_stringW(row,1);
6140 filename = load_dynamic_stringW(row,2);
6141 dirproperty = load_dynamic_stringW(row,3);
6142 section = load_dynamic_stringW(row,4);
6143 key = load_dynamic_stringW(row,5);
6144 value = load_dynamic_stringW(row,6);
6145 action = MSI_RecordGetInteger(row,7);
6147 deformat_string(package,section,&deformated_section);
6148 deformat_string(package,key,&deformated_key);
6149 deformat_string(package,value,&deformated_value);
6153 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
6155 folder = load_dynamic_property(package,dirproperty,NULL);
6158 folder = load_dynamic_property(package, szWindowsFolder, NULL);
6162 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
6166 fullname = build_directory_name(3, folder, filename, NULL);
6170 TRACE("Adding value %s to section %s in %s\n",
6171 debugstr_w(deformated_key), debugstr_w(deformated_section),
6172 debugstr_w(fullname));
6173 WritePrivateProfileStringW(deformated_section, deformated_key,
6174 deformated_value, fullname);
6176 else if (action == 1)
6179 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
6180 returned, 10, fullname);
6181 if (returned[0] == 0)
6183 TRACE("Adding value %s to section %s in %s\n",
6184 debugstr_w(deformated_key), debugstr_w(deformated_section),
6185 debugstr_w(fullname));
6187 WritePrivateProfileStringW(deformated_section, deformated_key,
6188 deformated_value, fullname);
6191 else if (action == 3)
6193 FIXME("Append to existing section not yet implemented\n");
6196 uirow = MSI_CreateRecord(4);
6197 MSI_RecordSetStringW(uirow,1,identifier);
6198 MSI_RecordSetStringW(uirow,2,deformated_section);
6199 MSI_RecordSetStringW(uirow,3,deformated_key);
6200 MSI_RecordSetStringW(uirow,4,deformated_value);
6201 ui_actiondata(package,szWriteIniValues,uirow);
6202 msiobj_release( &uirow->hdr );
6204 HeapFree(GetProcessHeap(),0,identifier);
6205 HeapFree(GetProcessHeap(),0,fullname);
6206 HeapFree(GetProcessHeap(),0,filename);
6207 HeapFree(GetProcessHeap(),0,key);
6208 HeapFree(GetProcessHeap(),0,value);
6209 HeapFree(GetProcessHeap(),0,section);
6210 HeapFree(GetProcessHeap(),0,dirproperty);
6211 HeapFree(GetProcessHeap(),0,folder);
6212 HeapFree(GetProcessHeap(),0,deformated_key);
6213 HeapFree(GetProcessHeap(),0,deformated_value);
6214 HeapFree(GetProcessHeap(),0,deformated_section);
6215 msiobj_release(&row->hdr);
6217 MSI_ViewClose(view);
6218 msiobj_release(&view->hdr);
6222 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
6226 MSIRECORD * row = 0;
6227 static const WCHAR ExecSeqQuery[] =
6228 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6229 '`','S','e','l','f','R','e','g','`',0};
6231 static const WCHAR ExeStr[] =
6232 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
6233 static const WCHAR close[] = {'\"',0};
6235 PROCESS_INFORMATION info;
6238 memset(&si,0,sizeof(STARTUPINFOW));
6240 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6241 if (rc != ERROR_SUCCESS)
6243 TRACE("no SelfReg table\n");
6244 return ERROR_SUCCESS;
6247 rc = MSI_ViewExecute(view, 0);
6248 if (rc != ERROR_SUCCESS)
6250 MSI_ViewClose(view);
6251 msiobj_release(&view->hdr);
6261 rc = MSI_ViewFetch(view,&row);
6262 if (rc != ERROR_SUCCESS)
6268 filename = load_dynamic_stringW(row,1);
6269 index = get_loaded_file(package,filename);
6273 ERR("Unable to find file id %s\n",debugstr_w(filename));
6274 HeapFree(GetProcessHeap(),0,filename);
6275 msiobj_release(&row->hdr);
6278 HeapFree(GetProcessHeap(),0,filename);
6280 len = strlenW(ExeStr);
6281 len += strlenW(package->files[index].TargetPath);
6284 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
6285 strcpyW(filename,ExeStr);
6286 strcatW(filename,package->files[index].TargetPath);
6287 strcatW(filename,close);
6289 TRACE("Registering %s\n",debugstr_w(filename));
6290 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
6291 c_colon, &si, &info);
6294 msi_dialog_check_messages(info.hProcess);
6296 HeapFree(GetProcessHeap(),0,filename);
6297 msiobj_release(&row->hdr);
6299 MSI_ViewClose(view);
6300 msiobj_release(&view->hdr);
6304 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
6313 return ERROR_INVALID_HANDLE;
6315 productcode = load_dynamic_property(package,szProductCode,&rc);
6319 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
6320 if (rc != ERROR_SUCCESS)
6323 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
6324 if (rc != ERROR_SUCCESS)
6327 /* here the guids are base 85 encoded */
6328 for (i = 0; i < package->loaded_features; i++)
6334 BOOL absent = FALSE;
6336 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL) &&
6337 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_SOURCE) &&
6338 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_ADVERTISED))
6341 size = package->features[i].ComponentCount*21;
6343 if (package->features[i].Feature_Parent[0])
6344 size += strlenW(package->features[i].Feature_Parent)+2;
6346 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
6349 for (j = 0; j < package->features[i].ComponentCount; j++)
6352 memset(buf,0,sizeof(buf));
6353 if (package->components
6354 [package->features[i].Components[j]].ComponentId[0]!=0)
6356 TRACE("From %s\n",debugstr_w(package->components
6357 [package->features[i].Components[j]].ComponentId));
6358 CLSIDFromString(package->components
6359 [package->features[i].Components[j]].ComponentId,
6361 encode_base85_guid(&clsid,buf);
6362 TRACE("to %s\n",debugstr_w(buf));
6366 if (package->features[i].Feature_Parent[0])
6368 static const WCHAR sep[] = {'\2',0};
6370 strcatW(data,package->features[i].Feature_Parent);
6373 size = (strlenW(data)+1)*sizeof(WCHAR);
6374 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
6376 HeapFree(GetProcessHeap(),0,data);
6380 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
6381 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6382 (LPSTR)package->features[i].Feature_Parent,size);
6386 size = (strlenW(package->features[i].Feature_Parent)+2)*
6388 data = HeapAlloc(GetProcessHeap(),0,size);
6390 strcpyW(&data[1],package->features[i].Feature_Parent);
6391 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6393 HeapFree(GetProcessHeap(),0,data);
6400 HeapFree(GetProcessHeap(), 0, productcode);
6404 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
6411 static WCHAR szNONE[] = {0};
6412 static const WCHAR szWindowsInstaler[] =
6413 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
6414 static const WCHAR szPropKeys[][80] =
6416 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
6417 {'A','R','P','C','O','N','T','A','C','T',0},
6418 {'A','R','P','C','O','M','M','E','N','T','S',0},
6419 {'P','r','o','d','u','c','t','N','a','m','e',0},
6420 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
6421 {'A','R','P','H','E','L','P','L','I','N','K',0},
6422 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
6423 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
6424 {'S','o','u','r','c','e','D','i','r',0},
6425 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
6426 {'A','R','P','R','E','A','D','M','E',0},
6427 {'A','R','P','S','I','Z','E',0},
6428 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
6429 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
6433 static const WCHAR szRegKeys[][80] =
6435 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
6436 {'C','o','n','t','a','c','t',0},
6437 {'C','o','m','m','e','n','t','s',0},
6438 {'D','i','s','p','l','a','y','N','a','m','e',0},
6439 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
6440 {'H','e','l','p','L','i','n','k',0},
6441 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
6442 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
6443 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
6444 {'P','u','b','l','i','s','h','e','r',0},
6445 {'R','e','a','d','m','e',0},
6446 {'S','i','z','e',0},
6447 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
6448 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
6452 static const WCHAR installerPathFmt[] = {
6454 'I','n','s','t','a','l','l','e','r','\\',0};
6455 static const WCHAR fmt[] = {
6457 'I','n','s','t','a','l','l','e','r','\\',
6458 '%','x','.','m','s','i',0};
6459 static const WCHAR szLocalPackage[]=
6460 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
6461 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
6465 return ERROR_INVALID_HANDLE;
6467 productcode = load_dynamic_property(package,szProductCode,&rc);
6471 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
6472 if (rc != ERROR_SUCCESS)
6475 /* dump all the info i can grab */
6476 FIXME("Flesh out more information \n");
6479 while (szPropKeys[i][0]!=0)
6481 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
6482 if (rc != ERROR_SUCCESS)
6484 size = strlenW(buffer)*sizeof(WCHAR);
6485 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
6491 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
6493 /* copy the package locally */
6494 num = GetTickCount() & 0xffff;
6498 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
6499 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
6503 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
6504 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
6505 if (handle != INVALID_HANDLE_VALUE)
6507 CloseHandle(handle);
6510 if (GetLastError() != ERROR_FILE_EXISTS &&
6511 GetLastError() != ERROR_SHARING_VIOLATION)
6513 if (!(++num & 0xffff)) num = 1;
6514 sprintfW(packagefile,fmt,num);
6515 } while (num != start);
6517 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
6518 create_full_pathW(path);
6519 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
6520 if (!CopyFileW(package->PackagePath,packagefile,FALSE))
6521 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
6522 debugstr_w(package->PackagePath), debugstr_w(packagefile),
6524 size = strlenW(packagefile)*sizeof(WCHAR);
6525 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
6528 HeapFree(GetProcessHeap(),0,productcode);
6531 return ERROR_SUCCESS;
6534 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
6539 return ERROR_INVALID_HANDLE;
6541 rc = execute_script(package,INSTALL_SCRIPT);
6546 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
6551 return ERROR_INVALID_HANDLE;
6553 /* turn off scheduleing */
6554 package->script->CurrentlyScripting= FALSE;
6556 /* first do the same as an InstallExecute */
6557 rc = ACTION_InstallExecute(package);
6558 if (rc != ERROR_SUCCESS)
6561 /* then handle Commit Actions */
6562 rc = execute_script(package,COMMIT_SCRIPT);
6567 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
6569 static const WCHAR RunOnce[] = {
6570 'S','o','f','t','w','a','r','e','\\',
6571 'M','i','c','r','o','s','o','f','t','\\',
6572 'W','i','n','d','o','w','s','\\',
6573 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6574 'R','u','n','O','n','c','e',0};
6575 static const WCHAR InstallRunOnce[] = {
6576 'S','o','f','t','w','a','r','e','\\',
6577 'M','i','c','r','o','s','o','f','t','\\',
6578 'W','i','n','d','o','w','s','\\',
6579 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6580 'I','n','s','t','a','l','l','e','r','\\',
6581 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
6583 static const WCHAR msiexec_fmt[] = {
6585 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
6586 '\"','%','s','\"',0};
6587 static const WCHAR install_fmt[] = {
6588 '/','I',' ','\"','%','s','\"',' ',
6589 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
6590 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
6591 WCHAR buffer[256], sysdir[MAX_PATH];
6594 WCHAR squished_pc[100];
6597 static const WCHAR szLUS[] = {
6598 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
6599 static const WCHAR szSourceList[] = {
6600 'S','o','u','r','c','e','L','i','s','t',0};
6601 static const WCHAR szPackageName[] = {
6602 'P','a','c','k','a','g','e','N','a','m','e',0};
6605 return ERROR_INVALID_HANDLE;
6607 productcode = load_dynamic_property(package,szProductCode,&rc);
6611 squash_guid(productcode,squished_pc);
6613 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
6614 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
6615 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
6618 size = strlenW(buffer)*sizeof(WCHAR);
6619 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6622 TRACE("Reboot command %s\n",debugstr_w(buffer));
6624 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
6625 sprintfW(buffer,install_fmt,productcode,squished_pc);
6627 size = strlenW(buffer)*sizeof(WCHAR);
6628 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6631 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6632 if (rc == ERROR_SUCCESS)
6636 RegCreateKeyW(hukey, szSourceList, &hukey2);
6637 buf = load_dynamic_property(package,cszSourceDir,NULL);
6638 size = strlenW(buf)*sizeof(WCHAR);
6639 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
6640 HeapFree(GetProcessHeap(),0,buf);
6642 buf = strrchrW(package->PackagePath,'\\');
6646 size = strlenW(buf)*sizeof(WCHAR);
6647 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
6650 RegCloseKey(hukey2);
6652 HeapFree(GetProcessHeap(),0,productcode);
6654 return ERROR_INSTALL_SUSPEND;
6657 UINT ACTION_ResolveSource(MSIPACKAGE* package)
6660 * we are currently doing what should be done here in the top level Install
6661 * however for Adminastrative and uninstalls this step will be needed
6663 return ERROR_SUCCESS;
6666 static LPWSTR create_component_advertise_string(MSIPACKAGE* package,
6667 MSICOMPONENT* component, LPCWSTR feature)
6669 LPWSTR productid=NULL;
6671 WCHAR productid_85[21];
6672 WCHAR component_85[21];
6674 * I have a fair bit of confusion as to when a < is used and when a > is
6675 * used. I do not think i have it right...
6677 * Ok it appears that the > is used if there is a guid for the compoenent
6678 * and the < is used if not.
6680 static WCHAR fmt1[] = {'%','s','%','s','<',0,0};
6681 static WCHAR fmt2[] = {'%','s','%','s','>','%','s',0,0};
6682 LPWSTR output = NULL;
6685 memset(productid_85,0,sizeof(productid_85));
6686 memset(component_85,0,sizeof(component_85));
6688 productid = load_dynamic_property(package,szProductCode,NULL);
6689 CLSIDFromString(productid, &clsid);
6691 encode_base85_guid(&clsid,productid_85);
6693 CLSIDFromString(component->ComponentId, &clsid);
6694 encode_base85_guid(&clsid,component_85);
6696 TRACE("Doing something with this... %s %s %s\n",
6697 debugstr_w(productid_85), debugstr_w(feature),
6698 debugstr_w(component_85));
6700 sz = lstrlenW(productid_85) + lstrlenW(feature);
6702 sz += lstrlenW(component_85);
6705 sz *= sizeof(WCHAR);
6707 output = HeapAlloc(GetProcessHeap(),0,sz);
6708 memset(output,0,sz);
6711 sprintfW(output,fmt2,productid_85,feature,component_85);
6713 sprintfW(output,fmt1,productid_85,feature);
6715 HeapFree(GetProcessHeap(),0,productid);
6720 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
6721 MSICOMPONENT* component, MSIEXTENSION* extension,
6722 MSIVERB* verb, INT* Sequence )
6726 static const WCHAR szShell[] = {'s','h','e','l','l',0};
6727 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
6728 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
6729 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
6734 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
6736 TRACE("Making Key %s\n",debugstr_w(keyname));
6737 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6738 size = strlenW(component->FullKeypath);
6740 size += strlenW(verb->Argument);
6743 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6745 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
6747 sprintfW(command, fmt2, component->FullKeypath);
6749 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)command, (strlenW(command)+1)*
6751 HeapFree(GetProcessHeap(),0,command);
6753 advertise = create_component_advertise_string(package, component,
6754 package->features[extension->FeatureIndex].Feature);
6756 size = strlenW(advertise);
6759 size += strlenW(verb->Argument);
6762 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6763 memset(command,0,size*sizeof(WCHAR));
6765 strcpyW(command,advertise);
6768 static const WCHAR szSpace[] = {' ',0};
6769 strcatW(command,szSpace);
6770 strcatW(command,verb->Argument);
6773 RegSetValueExW(key, szCommand, 0, REG_MULTI_SZ, (LPBYTE)command,
6774 (strlenW(command)+2)*sizeof(WCHAR));
6777 HeapFree(GetProcessHeap(),0,keyname);
6778 HeapFree(GetProcessHeap(),0,advertise);
6779 HeapFree(GetProcessHeap(),0,command);
6783 keyname = build_directory_name(3, progid, szShell, verb->Verb);
6784 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6785 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Command,
6786 (strlenW(verb->Command)+1) *sizeof(WCHAR));
6788 HeapFree(GetProcessHeap(),0,keyname);
6791 if (verb->Sequence != MSI_NULL_INTEGER)
6793 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
6795 *Sequence = verb->Sequence;
6796 keyname = build_directory_name(2, progid, szShell);
6797 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6798 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Verb,
6799 (strlenW(verb->Verb)+1) *sizeof(WCHAR));
6801 HeapFree(GetProcessHeap(),0,keyname);
6804 return ERROR_SUCCESS;
6807 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
6809 static const WCHAR szContentType[] =
6810 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
6814 BOOL install_on_demand = TRUE;
6817 return ERROR_INVALID_HANDLE;
6819 load_classes_and_such(package);
6821 /* We need to set install_on_demand based on if the shell handles advertised
6822 * shortcuts and the like. Because Mike McCormack is working on this i am
6823 * going to default to TRUE
6826 for (i = 0; i < package->loaded_extensions; i++)
6828 WCHAR extension[257];
6831 index = package->extensions[i].ComponentIndex;
6832 f_index = package->extensions[i].FeatureIndex;
6838 * yes. MSDN says that these are based on _Feature_ not on
6839 * Component. So verify the feature is to be installed
6841 if ((!ACTION_VerifyFeatureForAction(package, f_index,
6842 INSTALLSTATE_LOCAL)) &&
6843 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
6844 f_index, INSTALLSTATE_ADVERTISED)))
6846 TRACE("Skipping extension %s reg due to disabled feature %s\n",
6847 debugstr_w(package->extensions[i].Extension),
6848 debugstr_w(package->features[f_index].Feature));
6853 TRACE("Registering extension %s index %i\n",
6854 debugstr_w(package->extensions[i].Extension), i);
6856 package->extensions[i].Installed = TRUE;
6858 /* this is only registered if the extension has at least 1 verb
6861 if (package->extensions[i].ProgIDIndex >= 0 &&
6862 package->extensions[i].VerbCount > 0)
6863 mark_progid_for_install(package, package->extensions[i].ProgIDIndex);
6865 if (package->extensions[i].MIMEIndex >= 0)
6866 mark_mime_for_install(package, package->extensions[i].MIMEIndex);
6870 strcatW(extension,package->extensions[i].Extension);
6872 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
6874 if (package->extensions[i].MIMEIndex >= 0)
6876 RegSetValueExW(hkey,szContentType,0,REG_SZ,
6877 (LPVOID)package->mimes[package->extensions[i].
6878 MIMEIndex].ContentType,
6879 (strlenW(package->mimes[package->extensions[i].
6880 MIMEIndex].ContentType)+1)*sizeof(WCHAR));
6883 if (package->extensions[i].ProgIDIndex >= 0 ||
6884 package->extensions[i].ProgIDText)
6886 static const WCHAR szSN[] =
6887 {'\\','S','h','e','l','l','N','e','w',0};
6892 INT Sequence = MSI_NULL_INTEGER;
6894 if (package->extensions[i].ProgIDIndex >= 0)
6895 progid = package->progids[package->extensions[i].
6896 ProgIDIndex].ProgID;
6898 progid = package->extensions[i].ProgIDText;
6900 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
6901 (strlenW(progid)+1)*sizeof(WCHAR));
6903 newkey = HeapAlloc(GetProcessHeap(),0,
6904 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
6906 strcpyW(newkey,progid);
6907 strcatW(newkey,szSN);
6908 RegCreateKeyW(hkey,newkey,&hkey2);
6911 HeapFree(GetProcessHeap(),0,newkey);
6913 /* do all the verbs */
6914 for (v = 0; v < package->extensions[i].VerbCount; v++)
6915 register_verb(package, progid,
6916 &package->components[index],
6917 &package->extensions[i],
6918 &package->verbs[package->extensions[i].Verbs[v]],
6924 uirow = MSI_CreateRecord(1);
6925 MSI_RecordSetStringW(uirow,1,package->extensions[i].Extension);
6926 ui_actiondata(package,szRegisterExtensionInfo,uirow);
6927 msiobj_release(&uirow->hdr);
6930 return ERROR_SUCCESS;
6933 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
6935 static const WCHAR szExten[] =
6936 {'E','x','t','e','n','s','i','o','n',0 };
6942 return ERROR_INVALID_HANDLE;
6944 load_classes_and_such(package);
6946 for (i = 0; i < package->loaded_mimes; i++)
6948 WCHAR extension[257];
6951 static const WCHAR fmt[] =
6952 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
6953 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
6957 * check if the MIME is to be installed. Either as requesed by an
6958 * extension or Class
6960 package->mimes[i].InstallMe = ((package->mimes[i].InstallMe) ||
6961 (package->mimes[i].ClassIndex >= 0 &&
6962 package->classes[package->mimes[i].ClassIndex].Installed) ||
6963 (package->mimes[i].ExtensionIndex >=0 &&
6964 package->extensions[package->mimes[i].ExtensionIndex].Installed));
6966 if (!package->mimes[i].InstallMe)
6968 TRACE("MIME %s not scheduled to be installed\n",
6969 debugstr_w(package->mimes[i].ContentType));
6973 mime = package->mimes[i].ContentType;
6974 exten = package->extensions[package->mimes[i].ExtensionIndex].Extension;
6977 strcatW(extension,exten);
6979 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
6981 sprintfW(key,fmt,mime);
6982 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
6983 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
6984 (strlenW(extension)+1)*sizeof(WCHAR));
6986 HeapFree(GetProcessHeap(),0,key);
6988 if (package->mimes[i].CLSID[0])
6990 FIXME("Handle non null for field 3\n");
6995 uirow = MSI_CreateRecord(2);
6996 MSI_RecordSetStringW(uirow,1,package->mimes[i].ContentType);
6997 MSI_RecordSetStringW(uirow,2,exten);
6998 ui_actiondata(package,szRegisterMIMEInfo,uirow);
6999 msiobj_release(&uirow->hdr);
7002 return ERROR_SUCCESS;
7005 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
7007 static const WCHAR szProductID[]=
7008 {'P','r','o','d','u','c','t','I','D',0};
7016 static const WCHAR szPropKeys[][80] =
7018 {'P','r','o','d','u','c','t','I','D',0},
7019 {'U','S','E','R','N','A','M','E',0},
7020 {'C','O','M','P','A','N','Y','N','A','M','E',0},
7024 static const WCHAR szRegKeys[][80] =
7026 {'P','r','o','d','u','c','t','I','D',0},
7027 {'R','e','g','O','w','n','e','r',0},
7028 {'R','e','g','C','o','m','p','a','n','y',0},
7033 return ERROR_INVALID_HANDLE;
7035 productid = load_dynamic_property(package,szProductID,&rc);
7037 return ERROR_SUCCESS;
7039 productcode = load_dynamic_property(package,szProductCode,&rc);
7043 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
7044 if (rc != ERROR_SUCCESS)
7048 while (szPropKeys[i][0]!=0)
7050 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
7051 if (rc == ERROR_SUCCESS)
7053 size = strlenW(buffer)*sizeof(WCHAR);
7054 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
7057 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
7062 HeapFree(GetProcessHeap(),0,productcode);
7063 HeapFree(GetProcessHeap(),0,productid);
7066 return ERROR_SUCCESS;
7070 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
7073 rc = ACTION_ProcessExecSequence(package,FALSE);
7079 * Code based off of code located here
7080 * http://www.codeproject.com/gdi/fontnamefromfile.asp
7082 * Using string index 4 (full font name) instead of 1 (family name)
7084 static LPWSTR load_ttfname_from(LPCWSTR filename)
7090 typedef struct _tagTT_OFFSET_TABLE{
7091 USHORT uMajorVersion;
7092 USHORT uMinorVersion;
7093 USHORT uNumOfTables;
7094 USHORT uSearchRange;
7095 USHORT uEntrySelector;
7099 typedef struct _tagTT_TABLE_DIRECTORY{
7100 char szTag[4]; /* table name */
7101 ULONG uCheckSum; /* Check sum */
7102 ULONG uOffset; /* Offset from beginning of file */
7103 ULONG uLength; /* length of the table in bytes */
7104 }TT_TABLE_DIRECTORY;
7106 typedef struct _tagTT_NAME_TABLE_HEADER{
7107 USHORT uFSelector; /* format selector. Always 0 */
7108 USHORT uNRCount; /* Name Records count */
7109 USHORT uStorageOffset; /* Offset for strings storage,
7110 * from start of the table */
7111 }TT_NAME_TABLE_HEADER;
7113 typedef struct _tagTT_NAME_RECORD{
7118 USHORT uStringLength;
7119 USHORT uStringOffset; /* from start of storage area */
7122 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
7123 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
7125 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
7126 FILE_ATTRIBUTE_NORMAL, 0 );
7127 if (handle != INVALID_HANDLE_VALUE)
7129 TT_TABLE_DIRECTORY tblDir;
7130 BOOL bFound = FALSE;
7131 TT_OFFSET_TABLE ttOffsetTable;
7133 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
7134 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
7135 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
7136 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
7138 if (ttOffsetTable.uMajorVersion != 1 ||
7139 ttOffsetTable.uMinorVersion != 0)
7142 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
7144 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
7145 if (strncmp(tblDir.szTag,"name",4)==0)
7148 tblDir.uLength = SWAPLONG(tblDir.uLength);
7149 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
7156 TT_NAME_TABLE_HEADER ttNTHeader;
7157 TT_NAME_RECORD ttRecord;
7159 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
7160 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
7163 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
7164 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
7166 for(i=0; i<ttNTHeader.uNRCount; i++)
7168 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
7169 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
7170 /* 4 is the Full Font Name */
7171 if(ttRecord.uNameID == 4)
7175 static LPCSTR tt = " (TrueType)";
7177 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
7178 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
7179 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
7180 SetFilePointer(handle, tblDir.uOffset +
7181 ttRecord.uStringOffset +
7182 ttNTHeader.uStorageOffset,
7184 buf = HeapAlloc(GetProcessHeap(), 0,
7185 ttRecord.uStringLength + 1 + strlen(tt));
7186 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
7187 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
7188 if (strlen(buf) > 0)
7191 ret = strdupAtoW(buf);
7192 HeapFree(GetProcessHeap(),0,buf);
7196 HeapFree(GetProcessHeap(),0,buf);
7197 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
7201 CloseHandle(handle);
7204 ERR("Unable to open font file %s\n", debugstr_w(filename));
7206 TRACE("Returning fontname %s\n",debugstr_w(ret));
7210 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
7214 MSIRECORD * row = 0;
7215 static const WCHAR ExecSeqQuery[] =
7216 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7217 '`','F','o','n','t','`',0};
7218 static const WCHAR regfont1[] =
7219 {'S','o','f','t','w','a','r','e','\\',
7220 'M','i','c','r','o','s','o','f','t','\\',
7221 'W','i','n','d','o','w','s',' ','N','T','\\',
7222 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7223 'F','o','n','t','s',0};
7224 static const WCHAR regfont2[] =
7225 {'S','o','f','t','w','a','r','e','\\',
7226 'M','i','c','r','o','s','o','f','t','\\',
7227 'W','i','n','d','o','w','s','\\',
7228 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7229 'F','o','n','t','s',0};
7233 TRACE("%p\n", package);
7235 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7236 if (rc != ERROR_SUCCESS)
7238 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
7239 return ERROR_SUCCESS;
7242 rc = MSI_ViewExecute(view, 0);
7243 if (rc != ERROR_SUCCESS)
7245 MSI_ViewClose(view);
7246 msiobj_release(&view->hdr);
7247 TRACE("MSI_ViewExecute returned %d\n", rc);
7248 return ERROR_SUCCESS;
7251 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
7252 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
7261 rc = MSI_ViewFetch(view,&row);
7262 if (rc != ERROR_SUCCESS)
7268 file = load_dynamic_stringW(row,1);
7269 index = get_loaded_file(package,file);
7272 ERR("Unable to load file\n");
7273 HeapFree(GetProcessHeap(),0,file);
7277 /* check to make sure that component is installed */
7278 if (!ACTION_VerifyComponentForAction(package,
7279 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
7281 TRACE("Skipping: Component not scheduled for install\n");
7282 HeapFree(GetProcessHeap(),0,file);
7284 msiobj_release(&row->hdr);
7289 if (MSI_RecordIsNull(row,2))
7290 name = load_ttfname_from(package->files[index].TargetPath);
7292 name = load_dynamic_stringW(row,2);
7296 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
7297 RegSetValueExW(hkey1,name,0,REG_SZ,
7298 (LPBYTE)package->files[index].FileName,size);
7299 RegSetValueExW(hkey2,name,0,REG_SZ,
7300 (LPBYTE)package->files[index].FileName,size);
7303 HeapFree(GetProcessHeap(),0,file);
7304 HeapFree(GetProcessHeap(),0,name);
7305 msiobj_release(&row->hdr);
7307 MSI_ViewClose(view);
7308 msiobj_release(&view->hdr);
7313 TRACE("returning %d\n", rc);
7317 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
7319 MSIPACKAGE *package = (MSIPACKAGE*)param;
7320 LPWSTR compgroupid=NULL;
7321 LPWSTR feature=NULL;
7323 LPWSTR qualifier = NULL;
7324 LPWSTR component = NULL;
7325 LPWSTR advertise = NULL;
7326 LPWSTR output = NULL;
7328 UINT rc = ERROR_SUCCESS;
7332 component = load_dynamic_stringW(rec,3);
7333 index = get_loaded_component(package,component);
7335 if (!ACTION_VerifyComponentForAction(package, index,
7336 INSTALLSTATE_LOCAL) &&
7337 !ACTION_VerifyComponentForAction(package, index,
7338 INSTALLSTATE_SOURCE) &&
7339 !ACTION_VerifyComponentForAction(package, index,
7340 INSTALLSTATE_ADVERTISED))
7342 TRACE("Skipping: Component %s not scheduled for install\n",
7343 debugstr_w(component));
7345 HeapFree(GetProcessHeap(),0,component);
7346 return ERROR_SUCCESS;
7349 compgroupid = load_dynamic_stringW(rec,1);
7351 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
7352 if (rc != ERROR_SUCCESS)
7355 text = load_dynamic_stringW(rec,4);
7356 qualifier = load_dynamic_stringW(rec,2);
7357 feature = load_dynamic_stringW(rec,5);
7359 advertise = create_component_advertise_string(package,
7360 &package->components[index], feature);
7362 sz = strlenW(advertise);
7365 sz += lstrlenW(text);
7368 sz *= sizeof(WCHAR);
7370 output = HeapAlloc(GetProcessHeap(),0,sz);
7371 memset(output,0,sz);
7372 strcpyW(output,advertise);
7375 strcatW(output,text);
7377 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
7378 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
7382 HeapFree(GetProcessHeap(),0,output);
7383 HeapFree(GetProcessHeap(),0,compgroupid);
7384 HeapFree(GetProcessHeap(),0,component);
7385 HeapFree(GetProcessHeap(),0,feature);
7386 HeapFree(GetProcessHeap(),0,text);
7387 HeapFree(GetProcessHeap(),0,qualifier);
7393 * At present I am ignorning the advertised components part of this and only
7394 * focusing on the qualified component sets
7396 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
7400 static const WCHAR ExecSeqQuery[] =
7401 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7402 '`','P','u','b','l','i','s','h',
7403 'C','o','m','p','o','n','e','n','t','`',0};
7405 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7406 if (rc != ERROR_SUCCESS)
7407 return ERROR_SUCCESS;
7409 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
7410 msiobj_release(&view->hdr);
7415 /* Msi functions that seem appropriate here */
7417 /***********************************************************************
7418 * MsiDoActionA (MSI.@)
7420 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
7425 TRACE(" exteral attempt at action %s\n",szAction);
7428 return ERROR_FUNCTION_FAILED;
7430 return ERROR_FUNCTION_FAILED;
7432 szwAction = strdupAtoW(szAction);
7435 return ERROR_FUNCTION_FAILED;
7438 rc = MsiDoActionW(hInstall, szwAction);
7439 HeapFree(GetProcessHeap(),0,szwAction);
7443 /***********************************************************************
7444 * MsiDoActionW (MSI.@)
7446 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
7448 MSIPACKAGE *package;
7449 UINT ret = ERROR_INVALID_HANDLE;
7451 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
7453 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7456 ret = ACTION_PerformUIAction(package,szAction);
7457 msiobj_release( &package->hdr );
7462 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
7463 LPSTR szPathBuf, DWORD* pcchPathBuf)
7469 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7472 return ERROR_FUNCTION_FAILED;
7474 return ERROR_FUNCTION_FAILED;
7476 szwFolder = strdupAtoW(szFolder);
7479 return ERROR_FUNCTION_FAILED;
7481 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7483 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7485 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7486 *pcchPathBuf, NULL, NULL );
7488 HeapFree(GetProcessHeap(),0,szwFolder);
7489 HeapFree(GetProcessHeap(),0,szwPathBuf);
7494 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7495 szPathBuf, DWORD* pcchPathBuf)
7498 UINT rc = ERROR_FUNCTION_FAILED;
7499 MSIPACKAGE *package;
7501 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7503 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7505 return ERROR_INVALID_HANDLE;
7506 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
7507 msiobj_release( &package->hdr );
7509 if (path && (strlenW(path) > *pcchPathBuf))
7511 *pcchPathBuf = strlenW(path)+1;
7512 rc = ERROR_MORE_DATA;
7516 *pcchPathBuf = strlenW(path)+1;
7517 strcpyW(szPathBuf,path);
7518 TRACE("Returning Path %s\n",debugstr_w(path));
7521 HeapFree(GetProcessHeap(),0,path);
7527 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
7528 LPSTR szPathBuf, DWORD* pcchPathBuf)
7534 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7537 return ERROR_FUNCTION_FAILED;
7539 return ERROR_FUNCTION_FAILED;
7541 szwFolder = strdupAtoW(szFolder);
7543 return ERROR_FUNCTION_FAILED;
7545 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7547 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7549 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7550 *pcchPathBuf, NULL, NULL );
7552 HeapFree(GetProcessHeap(),0,szwFolder);
7553 HeapFree(GetProcessHeap(),0,szwPathBuf);
7558 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7559 szPathBuf, DWORD* pcchPathBuf)
7562 UINT rc = ERROR_FUNCTION_FAILED;
7563 MSIPACKAGE *package;
7565 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7567 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7569 return ERROR_INVALID_HANDLE;
7570 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
7571 msiobj_release( &package->hdr );
7573 if (path && strlenW(path) > *pcchPathBuf)
7575 *pcchPathBuf = strlenW(path)+1;
7576 rc = ERROR_MORE_DATA;
7580 *pcchPathBuf = strlenW(path)+1;
7581 strcpyW(szPathBuf,path);
7582 TRACE("Returning Path %s\n",debugstr_w(path));
7585 HeapFree(GetProcessHeap(),0,path);
7591 /***********************************************************************
7592 * MsiSetTargetPathA (MSI.@)
7594 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
7595 LPCSTR szFolderPath)
7598 LPWSTR szwFolderPath;
7602 return ERROR_FUNCTION_FAILED;
7604 return ERROR_FUNCTION_FAILED;
7606 szwFolder = strdupAtoW(szFolder);
7608 return ERROR_FUNCTION_FAILED;
7610 szwFolderPath = strdupAtoW(szFolderPath);
7613 HeapFree(GetProcessHeap(),0,szwFolder);
7614 return ERROR_FUNCTION_FAILED;
7617 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
7619 HeapFree(GetProcessHeap(),0,szwFolder);
7620 HeapFree(GetProcessHeap(),0,szwFolderPath);
7625 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
7626 LPCWSTR szFolderPath)
7630 LPWSTR path2 = NULL;
7633 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
7636 return ERROR_INVALID_HANDLE;
7638 if (szFolderPath[0]==0)
7639 return ERROR_FUNCTION_FAILED;
7641 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
7642 return ERROR_FUNCTION_FAILED;
7644 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
7647 return ERROR_INVALID_PARAMETER;
7649 HeapFree(GetProcessHeap(),0,folder->Property);
7650 folder->Property = build_directory_name(2, szFolderPath, NULL);
7652 if (lstrcmpiW(path, folder->Property) == 0)
7655 * Resolved Target has not really changed, so just
7656 * set this folder and do not recalculate everything.
7658 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
7659 folder->ResolvedTarget = NULL;
7660 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
7661 HeapFree(GetProcessHeap(),0,path2);
7665 for (i = 0; i < package->loaded_folders; i++)
7667 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
7668 package->folders[i].ResolvedTarget=NULL;
7671 for (i = 0; i < package->loaded_folders; i++)
7673 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
7675 HeapFree(GetProcessHeap(),0,path2);
7678 HeapFree(GetProcessHeap(),0,path);
7680 return ERROR_SUCCESS;
7683 /***********************************************************************
7684 * MsiSetTargetPathW (MSI.@)
7686 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
7687 LPCWSTR szFolderPath)
7689 MSIPACKAGE *package;
7692 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
7694 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7695 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
7696 msiobj_release( &package->hdr );
7700 /***********************************************************************
7701 * MsiGetMode (MSI.@)
7703 * Returns an internal installer state (if it is running in a mode iRunMode)
7706 * hInstall [I] Handle to the installation
7707 * hRunMode [I] Checking run mode
7708 * MSIRUNMODE_ADMIN Administrative mode
7709 * MSIRUNMODE_ADVERTISE Advertisement mode
7710 * MSIRUNMODE_MAINTENANCE Maintenance mode
7711 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
7712 * MSIRUNMODE_LOGENABLED Log file is writing
7713 * MSIRUNMODE_OPERATIONS Operations in progress??
7714 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
7715 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
7716 * MSIRUNMODE_CABINET Files from cabinet are installed
7717 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
7718 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
7719 * MSIRUNMODE_RESERVED11 Reserved
7720 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
7721 * MSIRUNMODE_ZAWENABLED Demand installation is supported
7722 * MSIRUNMODE_RESERVED14 Reserved
7723 * MSIRUNMODE_RESERVED15 Reserved
7724 * MSIRUNMODE_SCHEDULED called from install script
7725 * MSIRUNMODE_ROLLBACK called from rollback script
7726 * MSIRUNMODE_COMMIT called from commit script
7729 * In the state: TRUE
7730 * Not in the state: FALSE
7734 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
7736 FIXME("STUB (iRunMode=%i)\n",iRunMode);
7740 /***********************************************************************
7741 * MsiSetFeatureStateA (MSI.@)
7743 * According to the docs, when this is called it immediately recalculates
7744 * all the component states as well
7746 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
7747 INSTALLSTATE iState)
7749 LPWSTR szwFeature = NULL;
7752 szwFeature = strdupAtoW(szFeature);
7755 return ERROR_FUNCTION_FAILED;
7757 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
7759 HeapFree(GetProcessHeap(),0,szwFeature);
7766 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
7767 INSTALLSTATE iState)
7770 UINT rc = ERROR_SUCCESS;
7772 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7774 index = get_loaded_feature(package,szFeature);
7776 return ERROR_UNKNOWN_FEATURE;
7778 if (iState == INSTALLSTATE_ADVERTISED &&
7779 package->features[index].Attributes &
7780 msidbFeatureAttributesDisallowAdvertise)
7781 return ERROR_FUNCTION_FAILED;
7783 package->features[index].ActionRequest= iState;
7784 package->features[index].Action= iState;
7786 ACTION_UpdateComponentStates(package,szFeature);
7788 /* update all the features that are children of this feature */
7789 for (i = 0; i < package->loaded_features; i++)
7791 if (strcmpW(szFeature, package->features[i].Feature_Parent) == 0)
7792 MSI_SetFeatureStateW(package, package->features[i].Feature, iState);
7798 /***********************************************************************
7799 * MsiSetFeatureStateW (MSI.@)
7801 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
7802 INSTALLSTATE iState)
7804 MSIPACKAGE* package;
7805 UINT rc = ERROR_SUCCESS;
7807 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7809 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7811 return ERROR_INVALID_HANDLE;
7813 rc = MSI_SetFeatureStateW(package,szFeature,iState);
7815 msiobj_release( &package->hdr );
7819 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
7820 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7822 LPWSTR szwFeature = NULL;
7825 szwFeature = strdupAtoW(szFeature);
7827 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
7829 HeapFree( GetProcessHeap(), 0 , szwFeature);
7834 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
7835 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7839 index = get_loaded_feature(package,szFeature);
7841 return ERROR_UNKNOWN_FEATURE;
7844 *piInstalled = package->features[index].Installed;
7847 *piAction = package->features[index].Action;
7849 TRACE("returning %i %i\n",*piInstalled,*piAction);
7851 return ERROR_SUCCESS;
7854 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
7855 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7857 MSIPACKAGE* package;
7860 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
7863 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7865 return ERROR_INVALID_HANDLE;
7866 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
7867 msiobj_release( &package->hdr );
7871 /***********************************************************************
7872 * MsiGetComponentStateA (MSI.@)
7874 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
7875 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7877 LPWSTR szwComponent= NULL;
7880 szwComponent= strdupAtoW(szComponent);
7882 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
7884 HeapFree( GetProcessHeap(), 0 , szwComponent);
7889 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
7890 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7894 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
7897 index = get_loaded_component(package,szComponent);
7899 return ERROR_UNKNOWN_COMPONENT;
7902 *piInstalled = package->components[index].Installed;
7905 *piAction = package->components[index].Action;
7907 TRACE("states (%i, %i)\n",
7908 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
7910 return ERROR_SUCCESS;
7913 /***********************************************************************
7914 * MsiGetComponentStateW (MSI.@)
7916 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
7917 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7919 MSIPACKAGE* package;
7922 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
7923 piInstalled, piAction);
7925 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7927 return ERROR_INVALID_HANDLE;
7928 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
7929 msiobj_release( &package->hdr );