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);
1539 MSIRECORD *row = NULL, *uirow;
1541 rc = MSI_ViewFetch(view,&row);
1542 if (rc != ERROR_SUCCESS)
1548 dir = MSI_RecordGetString(row,1);
1551 ERR("Unable to get folder id \n");
1552 msiobj_release(&row->hdr);
1556 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1559 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1560 msiobj_release(&row->hdr);
1564 TRACE("Folder is %s\n",debugstr_w(full_path));
1567 uirow = MSI_CreateRecord(1);
1568 MSI_RecordSetStringW(uirow,1,full_path);
1569 ui_actiondata(package,szCreateFolders,uirow);
1570 msiobj_release( &uirow->hdr );
1572 if (folder->State == 0)
1573 create_full_pathW(full_path);
1577 msiobj_release(&row->hdr);
1578 HeapFree(GetProcessHeap(),0,full_path);
1580 MSI_ViewClose(view);
1581 msiobj_release(&view->hdr);
1586 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1588 int index = package->loaded_components;
1591 /* fill in the data */
1593 package->loaded_components++;
1594 if (package->loaded_components == 1)
1595 package->components = HeapAlloc(GetProcessHeap(),0,
1596 sizeof(MSICOMPONENT));
1598 package->components = HeapReAlloc(GetProcessHeap(),0,
1599 package->components, package->loaded_components *
1600 sizeof(MSICOMPONENT));
1602 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1604 sz = IDENTIFIER_SIZE;
1605 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1607 TRACE("Loading Component %s\n",
1608 debugstr_w(package->components[index].Component));
1611 if (!MSI_RecordIsNull(row,2))
1612 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1614 sz = IDENTIFIER_SIZE;
1615 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1617 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1620 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1622 sz = IDENTIFIER_SIZE;
1623 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1625 package->components[index].Installed = INSTALLSTATE_ABSENT;
1626 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1627 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1629 package->components[index].Enabled = TRUE;
1634 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1636 int index = package->loaded_features;
1638 static const WCHAR Query1[] =
1639 {'S','E','L','E','C','T',' ',
1640 '`','C','o','m','p','o','n','e','n','t','_','`',
1641 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1642 'C','o','m','p','o','n','e','n','t','s','`',' ',
1643 'W','H','E','R','E',' ',
1644 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1645 static const WCHAR Query2[] =
1646 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1647 '`','C','o','m','p','o','n','e','n','t','`',' ',
1648 'W','H','E','R','E',' ',
1649 '`','C','o','m','p','o','n','e','n','t','`',' ',
1650 '=','\'','%','s','\'',0};
1657 /* fill in the data */
1659 package->loaded_features ++;
1660 if (package->loaded_features == 1)
1661 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1663 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1664 package->loaded_features * sizeof(MSIFEATURE));
1666 memset(&package->features[index],0,sizeof(MSIFEATURE));
1668 sz = IDENTIFIER_SIZE;
1669 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1671 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1673 sz = IDENTIFIER_SIZE;
1674 if (!MSI_RecordIsNull(row,2))
1675 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1678 if (!MSI_RecordIsNull(row,3))
1679 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1682 if (!MSI_RecordIsNull(row,4))
1683 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1685 if (!MSI_RecordIsNull(row,5))
1686 package->features[index].Display = MSI_RecordGetInteger(row,5);
1688 package->features[index].Level= MSI_RecordGetInteger(row,6);
1690 sz = IDENTIFIER_SIZE;
1691 if (!MSI_RecordIsNull(row,7))
1692 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1694 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1696 package->features[index].Installed = INSTALLSTATE_ABSENT;
1697 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1698 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1700 /* load feature components */
1702 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1703 if (rc != ERROR_SUCCESS)
1705 rc = MSI_ViewExecute(view,0);
1706 if (rc != ERROR_SUCCESS)
1708 MSI_ViewClose(view);
1709 msiobj_release(&view->hdr);
1717 INT cnt = package->features[index].ComponentCount;
1719 rc = MSI_ViewFetch(view,&row2);
1720 if (rc != ERROR_SUCCESS)
1723 component = MSI_RecordGetString(row2,1);
1725 /* check to see if the component is already loaded */
1726 c_indx = get_loaded_component(package,component);
1729 TRACE("Component %s already loaded at %i\n", debugstr_w(component),
1731 package->features[index].Components[cnt] = c_indx;
1732 package->features[index].ComponentCount ++;
1733 msiobj_release( &row2->hdr );
1737 rc = MSI_OpenQuery(package->db, &view2, Query2, component);
1738 if (rc != ERROR_SUCCESS)
1740 msiobj_release( &row2->hdr );
1743 rc = MSI_ViewExecute(view2,0);
1744 if (rc != ERROR_SUCCESS)
1746 msiobj_release( &row2->hdr );
1747 MSI_ViewClose(view2);
1748 msiobj_release( &view2->hdr );
1755 rc = MSI_ViewFetch(view2,&row3);
1756 if (rc != ERROR_SUCCESS)
1758 c_indx = load_component(package,row3);
1759 msiobj_release( &row3->hdr );
1761 package->features[index].Components[cnt] = c_indx;
1762 package->features[index].ComponentCount ++;
1763 TRACE("Loaded new component to index %i\n",c_indx);
1765 MSI_ViewClose(view2);
1766 msiobj_release( &view2->hdr );
1767 msiobj_release( &row2->hdr );
1769 MSI_ViewClose(view);
1770 msiobj_release(&view->hdr);
1773 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1775 DWORD index = package->loaded_files;
1779 /* fill in the data */
1781 package->loaded_files++;
1782 if (package->loaded_files== 1)
1783 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1785 package->files = HeapReAlloc(GetProcessHeap(),0,
1786 package->files , package->loaded_files * sizeof(MSIFILE));
1788 memset(&package->files[index],0,sizeof(MSIFILE));
1790 package->files[index].File = load_dynamic_stringW(row, 1);
1791 buffer = load_dynamic_stringW(row, 2);
1793 package->files[index].ComponentIndex = -1;
1794 for (i = 0; i < package->loaded_components; i++)
1795 if (strcmpW(package->components[i].Component,buffer)==0)
1797 package->files[index].ComponentIndex = i;
1800 if (package->files[index].ComponentIndex == -1)
1801 ERR("Unfound Component %s\n",debugstr_w(buffer));
1802 HeapFree(GetProcessHeap(), 0, buffer);
1804 package->files[index].FileName = load_dynamic_stringW(row,3);
1805 reduce_to_longfilename(package->files[index].FileName);
1807 package->files[index].ShortName = load_dynamic_stringW(row,3);
1808 reduce_to_shortfilename(package->files[index].ShortName);
1810 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1811 package->files[index].Version = load_dynamic_stringW(row, 5);
1812 package->files[index].Language = load_dynamic_stringW(row, 6);
1813 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1814 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1816 package->files[index].Temporary = FALSE;
1817 package->files[index].State = 0;
1819 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1821 return ERROR_SUCCESS;
1824 static UINT load_all_files(MSIPACKAGE *package)
1829 static const WCHAR Query[] =
1830 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1831 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1832 '`','S','e','q','u','e','n','c','e','`', 0};
1835 return ERROR_INVALID_HANDLE;
1837 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1838 if (rc != ERROR_SUCCESS)
1839 return ERROR_SUCCESS;
1841 rc = MSI_ViewExecute(view, 0);
1842 if (rc != ERROR_SUCCESS)
1844 MSI_ViewClose(view);
1845 msiobj_release(&view->hdr);
1846 return ERROR_SUCCESS;
1851 rc = MSI_ViewFetch(view,&row);
1852 if (rc != ERROR_SUCCESS)
1857 load_file(package,row);
1858 msiobj_release(&row->hdr);
1860 MSI_ViewClose(view);
1861 msiobj_release(&view->hdr);
1863 return ERROR_SUCCESS;
1868 * I am not doing any of the costing functionality yet.
1869 * Mostly looking at doing the Component and Feature loading
1871 * The native MSI does A LOT of modification to tables here. Mostly adding
1872 * a lot of temporary columns to the Feature and Component tables.
1874 * note: Native msi also tracks the short filename. But I am only going to
1875 * track the long ones. Also looking at this directory table
1876 * it appears that the directory table does not get the parents
1877 * resolved base on property only based on their entries in the
1880 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1885 static const WCHAR Query_all[] =
1886 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1887 '`','F','e','a','t','u','r','e','`',0};
1888 static const WCHAR szCosting[] =
1889 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1890 static const WCHAR szZero[] = { '0', 0 };
1894 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1896 return ERROR_SUCCESS;
1898 MSI_SetPropertyW(package, szCosting, szZero);
1899 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1901 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1902 if (rc != ERROR_SUCCESS)
1904 rc = MSI_ViewExecute(view,0);
1905 if (rc != ERROR_SUCCESS)
1907 MSI_ViewClose(view);
1908 msiobj_release(&view->hdr);
1915 rc = MSI_ViewFetch(view,&row);
1916 if (rc != ERROR_SUCCESS)
1919 load_feature(package,row);
1920 msiobj_release(&row->hdr);
1922 MSI_ViewClose(view);
1923 msiobj_release(&view->hdr);
1925 load_all_files(package);
1927 return ERROR_SUCCESS;
1930 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
1933 LPWSTR *newbuf = NULL;
1934 if (script >= TOTAL_SCRIPTS)
1936 FIXME("Unknown script requested %i\n",script);
1937 return ERROR_FUNCTION_FAILED;
1939 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
1941 count = package->script->ActionCount[script];
1942 package->script->ActionCount[script]++;
1944 newbuf = HeapReAlloc(GetProcessHeap(),0,
1945 package->script->Actions[script],
1946 package->script->ActionCount[script]* sizeof(LPWSTR));
1948 newbuf = HeapAlloc(GetProcessHeap(),0, sizeof(LPWSTR));
1950 newbuf[count] = strdupW(action);
1951 package->script->Actions[script] = newbuf;
1953 return ERROR_SUCCESS;
1956 static UINT execute_script(MSIPACKAGE *package, UINT script )
1959 UINT rc = ERROR_SUCCESS;
1961 TRACE("Executing Script %i\n",script);
1963 for (i = 0; i < package->script->ActionCount[script]; i++)
1966 action = package->script->Actions[script][i];
1967 ui_actionstart(package, action);
1968 TRACE("Executing Action (%s)\n",debugstr_w(action));
1969 rc = ACTION_PerformAction(package, action, TRUE);
1970 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
1971 if (rc != ERROR_SUCCESS)
1974 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
1976 package->script->ActionCount[script] = 0;
1977 package->script->Actions[script] = NULL;
1981 static UINT ACTION_FileCost(MSIPACKAGE *package)
1983 return ERROR_SUCCESS;
1987 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1989 static const WCHAR Query[] =
1990 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1991 '`','D','i','r','e','c', 't','o','r','y','`',' ',
1992 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
1993 ' ','=',' ','\'','%','s','\'',
1995 LPWSTR ptargetdir, targetdir, parent, srcdir;
1996 LPWSTR shortname = NULL;
1997 MSIRECORD * row = 0;
2001 TRACE("Looking for dir %s\n",debugstr_w(dir));
2003 for (i = 0; i < package->loaded_folders; i++)
2005 if (strcmpW(package->folders[i].Directory,dir)==0)
2007 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
2012 TRACE("Working to load %s\n",debugstr_w(dir));
2014 index = package->loaded_folders++;
2015 if (package->loaded_folders==1)
2016 package->folders = HeapAlloc(GetProcessHeap(),0,
2019 package->folders= HeapReAlloc(GetProcessHeap(),0,
2020 package->folders, package->loaded_folders*
2023 memset(&package->folders[index],0,sizeof(MSIFOLDER));
2025 package->folders[index].Directory = strdupW(dir);
2027 row = MSI_QueryGetRecord(package->db, Query, dir);
2031 ptargetdir = targetdir = load_dynamic_stringW(row,3);
2033 /* split src and target dir */
2034 if (strchrW(targetdir,':'))
2036 srcdir=strchrW(targetdir,':');
2043 /* for now only pick long filename versions */
2044 if (strchrW(targetdir,'|'))
2046 shortname = targetdir;
2047 targetdir = strchrW(targetdir,'|');
2051 /* for the sourcedir pick the short filename */
2052 if (srcdir && strchrW(srcdir,'|'))
2054 LPWSTR p = strchrW(srcdir,'|');
2058 /* now check for root dirs */
2059 if (targetdir[0] == '.' && targetdir[1] == 0)
2062 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
2067 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2068 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2069 package->folders[index].TargetDefault = strdupW(targetdir);
2073 package->folders[index].SourceDefault = strdupW(srcdir);
2075 package->folders[index].SourceDefault = strdupW(shortname);
2077 package->folders[index].SourceDefault = strdupW(targetdir);
2078 HeapFree(GetProcessHeap(), 0, ptargetdir);
2079 TRACE(" SourceDefault = %s\n",debugstr_w(package->folders[index].SourceDefault));
2081 parent = load_dynamic_stringW(row,2);
2084 i = load_folder(package,parent);
2085 package->folders[index].ParentIndex = i;
2086 TRACE("Parent is index %i... %s %s\n",
2087 package->folders[index].ParentIndex,
2088 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2089 debugstr_w(parent));
2092 package->folders[index].ParentIndex = -2;
2093 HeapFree(GetProcessHeap(), 0, parent);
2095 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2097 msiobj_release(&row->hdr);
2098 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2103 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
2104 BOOL set_prop, MSIFOLDER **folder)
2107 LPWSTR p, path = NULL;
2109 TRACE("Working to resolve %s\n",debugstr_w(name));
2111 /* special resolving for Target and Source root dir */
2112 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2116 path = load_dynamic_property(package,cszTargetDir,NULL);
2119 path = load_dynamic_property(package,cszRootDrive,NULL);
2121 MSI_SetPropertyW(package,cszTargetDir,path);
2125 for (i = 0; i < package->loaded_folders; i++)
2127 if (strcmpW(package->folders[i].Directory,name)==0)
2130 *folder = &(package->folders[i]);
2136 path = load_dynamic_property(package,cszSourceDir,NULL);
2139 path = load_dynamic_property(package,cszDatabase,NULL);
2142 p = strrchrW(path,'\\');
2149 for (i = 0; i < package->loaded_folders; i++)
2151 if (strcmpW(package->folders[i].Directory,name)==0)
2154 *folder = &(package->folders[i]);
2160 for (i = 0; i < package->loaded_folders; i++)
2162 if (strcmpW(package->folders[i].Directory,name)==0)
2166 if (i >= package->loaded_folders)
2170 *folder = &(package->folders[i]);
2172 if (!source && package->folders[i].ResolvedTarget)
2174 path = strdupW(package->folders[i].ResolvedTarget);
2175 TRACE(" already resolved to %s\n",debugstr_w(path));
2178 else if (source && package->folders[i].ResolvedSource)
2180 path = strdupW(package->folders[i].ResolvedSource);
2181 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
2184 else if (!source && package->folders[i].Property)
2186 path = build_directory_name(2, package->folders[i].Property, NULL);
2188 TRACE(" internally set to %s\n",debugstr_w(path));
2190 MSI_SetPropertyW(package,name,path);
2194 if (package->folders[i].ParentIndex >= 0)
2196 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2198 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2200 p = resolve_folder(package, parent, source, set_prop, NULL);
2203 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2204 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2205 package->folders[i].ResolvedTarget = strdupW(path);
2206 TRACE(" resolved into %s\n",debugstr_w(path));
2208 MSI_SetPropertyW(package,name,path);
2212 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2213 TRACE(" (source)resolved into %s\n",debugstr_w(path));
2214 package->folders[i].ResolvedSource = strdupW(path);
2216 HeapFree(GetProcessHeap(),0,p);
2221 /* scan for and update current install states */
2222 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
2227 productcode = load_dynamic_property(package,szProductCode,NULL);
2229 for (i = 0; i < package->loaded_components; i++)
2232 res = MsiGetComponentPathW(productcode,
2233 package->components[i].ComponentId , NULL, NULL);
2235 res = INSTALLSTATE_ABSENT;
2236 package->components[i].Installed = res;
2239 for (i = 0; i < package->loaded_features; i++)
2241 INSTALLSTATE res = -10;
2243 for (j = 0; j < package->features[i].ComponentCount; j++)
2245 MSICOMPONENT* component = &package->components[package->features[i].
2248 res = component->Installed;
2251 if (res == component->Installed)
2254 if (res != component->Installed)
2255 res = INSTALLSTATE_INCOMPLETE;
2261 /* update compoennt state based on a feature change */
2262 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2265 INSTALLSTATE newstate;
2266 MSIFEATURE *feature;
2268 i = get_loaded_feature(package,szFeature);
2272 feature = &package->features[i];
2273 newstate = feature->ActionRequest;
2275 for( i = 0; i < feature->ComponentCount; i++)
2277 MSICOMPONENT* component = &package->components[feature->Components[i]];
2279 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
2280 newstate, debugstr_w(component->Component), component->Installed,
2281 component->Action, component->ActionRequest);
2283 if (!component->Enabled)
2287 if (newstate == INSTALLSTATE_LOCAL)
2289 component->ActionRequest = INSTALLSTATE_LOCAL;
2290 component->Action = INSTALLSTATE_LOCAL;
2296 component->ActionRequest = newstate;
2297 component->Action = newstate;
2299 /*if any other feature wants is local we need to set it local*/
2301 j < package->loaded_features &&
2302 component->ActionRequest != INSTALLSTATE_LOCAL;
2305 for (k = 0; k < package->features[j].ComponentCount; k++)
2306 if ( package->features[j].Components[k] ==
2307 feature->Components[i] )
2309 if (package->features[j].ActionRequest ==
2312 TRACE("Saved by %s\n", debugstr_w(package->features[j].Feature));
2313 component->ActionRequest = INSTALLSTATE_LOCAL;
2314 component->Action = INSTALLSTATE_LOCAL;
2321 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
2322 newstate, debugstr_w(component->Component), component->Installed,
2323 component->Action, component->ActionRequest);
2327 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
2330 static const WCHAR all[]={'A','L','L',0};
2331 LPWSTR override = NULL;
2335 override = load_dynamic_property(package, property, NULL);
2339 for(i = 0; i < package->loaded_features; i++)
2341 if (strcmpiW(override,all)==0)
2343 package->features[i].ActionRequest= state;
2344 package->features[i].Action = state;
2348 LPWSTR ptr = override;
2349 LPWSTR ptr2 = strchrW(override,',');
2354 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2356 strcmpW(ptr,package->features[i].Feature)==0))
2358 package->features[i].ActionRequest= state;
2359 package->features[i].Action = state;
2365 ptr2 = strchrW(ptr,',');
2372 HeapFree(GetProcessHeap(),0,override);
2378 static UINT SetFeatureStates(MSIPACKAGE *package)
2384 static const WCHAR szlevel[] =
2385 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2386 static const WCHAR szAddLocal[] =
2387 {'A','D','D','L','O','C','A','L',0};
2388 static const WCHAR szRemove[] =
2389 {'R','E','M','O','V','E',0};
2390 BOOL override = FALSE;
2392 /* I do not know if this is where it should happen.. but */
2394 TRACE("Checking Install Level\n");
2396 level = load_dynamic_property(package,szlevel,NULL);
2399 install_level = atoiW(level);
2400 HeapFree(GetProcessHeap(), 0, level);
2405 /* ok hereis the _real_ rub
2406 * all these activation/deactivation things happen in order and things
2407 * later on the list override things earlier on the list.
2408 * 1) INSTALLLEVEL processing
2418 * 11) FILEADDDEFAULT
2419 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2420 * ignored for all the features. seems strange, especially since it is not
2421 * documented anywhere, but it is how it works.
2423 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2424 * REMOVE are the big ones, since we don't handle administrative installs
2427 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
2428 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
2432 for(i = 0; i < package->loaded_features; i++)
2434 BOOL feature_state = ((package->features[i].Level > 0) &&
2435 (package->features[i].Level <= install_level));
2437 if ((feature_state) &&
2438 (package->features[i].Action == INSTALLSTATE_UNKNOWN))
2440 if (package->features[i].Attributes &
2441 msidbFeatureAttributesFavorSource)
2443 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
2444 package->features[i].Action = INSTALLSTATE_SOURCE;
2446 else if (package->features[i].Attributes &
2447 msidbFeatureAttributesFavorAdvertise)
2449 package->features[i].ActionRequest =INSTALLSTATE_ADVERTISED;
2450 package->features[i].Action =INSTALLSTATE_ADVERTISED;
2454 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
2455 package->features[i].Action = INSTALLSTATE_LOCAL;
2462 /* set the Preselected Property */
2463 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
2464 static const WCHAR szOne[] = { '1', 0 };
2466 MSI_SetPropertyW(package,szPreselected,szOne);
2470 * now we want to enable or disable components base on feature
2473 for(i = 0; i < package->loaded_features; i++)
2475 MSIFEATURE* feature = &package->features[i];
2476 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2477 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2478 feature->ActionRequest);
2480 for( j = 0; j < feature->ComponentCount; j++)
2482 MSICOMPONENT* component = &package->components[
2483 feature->Components[j]];
2485 if (!component->Enabled)
2487 component->Action = INSTALLSTATE_UNKNOWN;
2488 component->ActionRequest = INSTALLSTATE_UNKNOWN;
2492 if (feature->Action == INSTALLSTATE_LOCAL)
2494 component->Action = INSTALLSTATE_LOCAL;
2495 component->ActionRequest = INSTALLSTATE_LOCAL;
2497 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
2499 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2500 (component->Action == INSTALLSTATE_ABSENT) ||
2501 (component->Action == INSTALLSTATE_ADVERTISED))
2504 component->Action = INSTALLSTATE_SOURCE;
2505 component->ActionRequest = INSTALLSTATE_SOURCE;
2508 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
2510 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2511 (component->Action == INSTALLSTATE_ABSENT))
2514 component->Action = INSTALLSTATE_ADVERTISED;
2515 component->ActionRequest = INSTALLSTATE_ADVERTISED;
2518 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
2520 if (component->Action == INSTALLSTATE_UNKNOWN)
2522 component->Action = INSTALLSTATE_ABSENT;
2523 component->ActionRequest = INSTALLSTATE_ABSENT;
2530 for(i = 0; i < package->loaded_components; i++)
2532 MSICOMPONENT* component= &package->components[i];
2534 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2535 debugstr_w(component->Component), component->Installed,
2536 component->Action, component->ActionRequest);
2540 return ERROR_SUCCESS;
2544 * A lot is done in this function aside from just the costing.
2545 * The costing needs to be implemented at some point but for now I am going
2546 * to focus on the directory building
2549 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2551 static const WCHAR ExecSeqQuery[] =
2552 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2553 '`','D','i','r','e','c','t','o','r','y','`',0};
2554 static const WCHAR ConditionQuery[] =
2555 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2556 '`','C','o','n','d','i','t','i','o','n','`',0};
2557 static const WCHAR szCosting[] =
2558 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2559 static const WCHAR szlevel[] =
2560 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2561 static const WCHAR szOne[] = { '1', 0 };
2569 MSI_GetPropertyW(package, szCosting, buffer, &sz);
2571 return ERROR_SUCCESS;
2573 TRACE("Building Directory properties\n");
2575 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2576 if (rc == ERROR_SUCCESS)
2578 rc = MSI_ViewExecute(view, 0);
2579 if (rc != ERROR_SUCCESS)
2581 MSI_ViewClose(view);
2582 msiobj_release(&view->hdr);
2590 MSIRECORD * row = 0;
2592 rc = MSI_ViewFetch(view,&row);
2593 if (rc != ERROR_SUCCESS)
2599 name = MSI_RecordGetString(row,1);
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);
2714 MSIRECORD * row = 0;
2717 rc = MSI_ViewFetch(view,&row);
2719 if (rc != ERROR_SUCCESS)
2725 Feature = MSI_RecordGetString(row,1);
2727 feature_index = get_loaded_feature(package,Feature);
2728 if (feature_index < 0)
2729 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2733 Condition = MSI_RecordGetString(row,3);
2735 if (MSI_EvaluateConditionW(package,Condition) ==
2738 int level = MSI_RecordGetInteger(row,2);
2739 TRACE("Reseting feature %s to level %i\n",
2740 debugstr_w(Feature), level);
2741 package->features[feature_index].Level = level;
2745 msiobj_release(&row->hdr);
2747 MSI_ViewClose(view);
2748 msiobj_release(&view->hdr);
2751 TRACE("Enabling or Disabling Components\n");
2752 for (i = 0; i < package->loaded_components; i++)
2754 if (package->components[i].Condition[0])
2756 if (MSI_EvaluateConditionW(package,
2757 package->components[i].Condition) == MSICONDITION_FALSE)
2759 TRACE("Disabling component %s\n",
2760 debugstr_w(package->components[i].Component));
2761 package->components[i].Enabled = FALSE;
2766 MSI_SetPropertyW(package,szCosting,szOne);
2767 /* set default run level if not set */
2768 level = load_dynamic_property(package,szlevel,NULL);
2770 MSI_SetPropertyW(package,szlevel, szOne);
2772 HeapFree(GetProcessHeap(),0,level);
2774 ACTION_UpdateInstallStates(package);
2776 return SetFeatureStates(package);
2780 * This is a helper function for handling embedded cabinet media
2782 static UINT writeout_cabinet_stream(MSIPACKAGE *package, LPCWSTR stream_name,
2790 WCHAR tmp[MAX_PATH];
2792 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2793 if (rc != ERROR_SUCCESS)
2797 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2798 GetTempPathW(MAX_PATH,tmp);
2800 GetTempFileNameW(tmp,stream_name,0,source);
2802 track_tempfile(package,strrchrW(source,'\\'), source);
2803 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2804 FILE_ATTRIBUTE_NORMAL, NULL);
2806 if (the_file == INVALID_HANDLE_VALUE)
2808 ERR("Unable to create file %s\n",debugstr_w(source));
2809 rc = ERROR_FUNCTION_FAILED;
2813 WriteFile(the_file,data,size,&write,NULL);
2814 CloseHandle(the_file);
2815 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2817 HeapFree(GetProcessHeap(),0,data);
2822 /* Support functions for FDI functions */
2825 MSIPACKAGE* package;
2830 static void * cabinet_alloc(ULONG cb)
2832 return HeapAlloc(GetProcessHeap(), 0, cb);
2835 static void cabinet_free(void *pv)
2837 HeapFree(GetProcessHeap(), 0, pv);
2840 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2843 DWORD dwShareMode = 0;
2844 DWORD dwCreateDisposition = OPEN_EXISTING;
2845 switch (oflag & _O_ACCMODE)
2848 dwAccess = GENERIC_READ;
2849 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2852 dwAccess = GENERIC_WRITE;
2853 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2856 dwAccess = GENERIC_READ | GENERIC_WRITE;
2857 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2860 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2861 dwCreateDisposition = CREATE_NEW;
2862 else if (oflag & _O_CREAT)
2863 dwCreateDisposition = CREATE_ALWAYS;
2864 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
2865 dwCreateDisposition, 0, NULL);
2868 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2871 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2876 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2879 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2884 static int cabinet_close(INT_PTR hf)
2886 return CloseHandle((HANDLE)hf) ? 0 : -1;
2889 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2891 /* flags are compatible and so are passed straight through */
2892 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2895 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2897 /* FIXME: try to do more processing in this function */
2900 case fdintCOPY_FILE:
2902 CabData *data = (CabData*) pfdin->pv;
2903 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2908 LPWSTR tracknametmp;
2909 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2911 if (data->file_name && lstrcmpiA(data->file_name,pfdin->psz1))
2914 file = cabinet_alloc((len+1)*sizeof(char));
2915 strcpy(file, data->cab_path);
2916 strcat(file, pfdin->psz1);
2918 TRACE("file: %s\n", debugstr_a(file));
2920 /* track this file so it can be deleted if not installed */
2921 trackpath=strdupAtoW(file);
2922 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2923 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2924 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2926 strcpyW(trackname,tmpprefix);
2927 strcatW(trackname,tracknametmp);
2929 track_tempfile(data->package, trackname, trackpath);
2931 HeapFree(GetProcessHeap(),0,trackpath);
2932 HeapFree(GetProcessHeap(),0,trackname);
2933 HeapFree(GetProcessHeap(),0,tracknametmp);
2935 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2937 case fdintCLOSE_FILE_INFO:
2941 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2943 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2945 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2948 cabinet_close(pfdin->hf);
2956 /***********************************************************************
2957 * extract_cabinet_file
2959 * Extract files from a cab file.
2961 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2962 const WCHAR* path, const WCHAR* file)
2972 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2973 debugstr_w(file), debugstr_w(path));
2975 hfdi = FDICreate(cabinet_alloc,
2986 ERR("FDICreate failed\n");
2990 if (!(cabinet = strdupWtoA( source )))
2995 if (!(cab_path = strdupWtoA( path )))
2998 HeapFree(GetProcessHeap(), 0, cabinet);
3002 data.package = package;
3003 data.cab_path = cab_path;
3005 file_name = strdupWtoA(file);
3008 data.file_name = file_name;
3010 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
3013 ERR("FDICopy failed\n");
3017 HeapFree(GetProcessHeap(), 0, cabinet);
3018 HeapFree(GetProcessHeap(), 0, cab_path);
3019 HeapFree(GetProcessHeap(), 0, file_name);
3024 static UINT ready_media_for_file(MSIPACKAGE *package, WCHAR* path,
3027 UINT rc = ERROR_SUCCESS;
3028 MSIRECORD * row = 0;
3029 static WCHAR source[MAX_PATH];
3030 static const WCHAR ExecSeqQuery[] =
3031 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3032 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3033 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
3034 ' ','%', 'i',' ','O','R','D','E','R',' ','B','Y',' ',
3035 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',0};
3039 static UINT last_sequence = 0;
3041 if (file->Attributes & msidbFileAttributesNoncompressed)
3043 TRACE("Uncompressed File, no media to ready.\n");
3044 return ERROR_SUCCESS;
3047 if (file->Sequence <= last_sequence)
3049 TRACE("Media already ready (%u, %u)\n",file->Sequence,last_sequence);
3050 /*extract_a_cabinet_file(package, source,path,file->File); */
3051 return ERROR_SUCCESS;
3054 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, file->Sequence);
3056 return ERROR_FUNCTION_FAILED;
3058 seq = MSI_RecordGetInteger(row,2);
3059 last_sequence = seq;
3061 cab = MSI_RecordGetString(row,4);
3064 TRACE("Source is CAB %s\n",debugstr_w(cab));
3065 /* the stream does not contain the # character */
3068 writeout_cabinet_stream(package,&cab[1],source);
3069 strcpyW(path,source);
3070 *(strrchrW(path,'\\')+1)=0;
3075 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
3077 ERR("No Source dir defined \n");
3078 rc = ERROR_FUNCTION_FAILED;
3082 strcpyW(path,source);
3083 strcatW(source,cab);
3084 /* extract the cab file into a folder in the temp folder */
3086 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
3088 GetTempPathW(MAX_PATH,path);
3091 rc = !extract_a_cabinet_file(package, source,path,NULL);
3096 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
3097 strcpyW(path,source);
3099 msiobj_release(&row->hdr);
3103 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
3105 UINT rc = ERROR_SUCCESS;
3107 LPWSTR install_path;
3109 install_path = resolve_folder(package, package->components[component].Directory,
3110 FALSE, FALSE, &folder);
3112 return ERROR_FUNCTION_FAILED;
3114 /* create the path */
3115 if (folder->State == 0)
3117 create_full_pathW(install_path);
3120 HeapFree(GetProcessHeap(), 0, install_path);
3125 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3127 UINT rc = ERROR_SUCCESS;
3130 WCHAR uipath[MAX_PATH];
3133 return ERROR_INVALID_HANDLE;
3135 /* increment progress bar each time action data is sent */
3136 ui_progress(package,1,1,0,0);
3138 for (index = 0; index < package->loaded_files; index++)
3140 WCHAR path_to_source[MAX_PATH];
3143 file = &package->files[index];
3145 if (file->Temporary)
3149 if (!ACTION_VerifyComponentForAction(package, file->ComponentIndex,
3150 INSTALLSTATE_LOCAL))
3152 ui_progress(package,2,file->FileSize,0,0);
3153 TRACE("File %s is not scheduled for install\n",
3154 debugstr_w(file->File));
3159 if ((file->State == 1) || (file->State == 2))
3162 MSICOMPONENT* comp = NULL;
3164 TRACE("Installing %s\n",debugstr_w(file->File));
3165 rc = ready_media_for_file(package, path_to_source, file);
3168 * our file table could change here because a new temp file
3169 * may have been created
3171 file = &package->files[index];
3172 if (rc != ERROR_SUCCESS)
3174 ERR("Unable to ready media\n");
3175 rc = ERROR_FUNCTION_FAILED;
3179 create_component_directory( package, file->ComponentIndex);
3181 /* recalculate file paths because things may have changed */
3183 if (file->ComponentIndex >= 0)
3184 comp = &package->components[file->ComponentIndex];
3186 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3187 HeapFree(GetProcessHeap(),0,file->TargetPath);
3189 file->TargetPath = build_directory_name(2, p, file->FileName);
3190 HeapFree(GetProcessHeap(),0,p);
3192 if (file->Attributes & msidbFileAttributesNoncompressed)
3194 p = resolve_folder(package, comp->Directory, TRUE, FALSE, NULL);
3195 file->SourcePath = build_directory_name(2, p, file->ShortName);
3196 HeapFree(GetProcessHeap(),0,p);
3199 file->SourcePath = build_directory_name(2, path_to_source,
3203 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3204 debugstr_w(file->TargetPath));
3207 uirow=MSI_CreateRecord(9);
3208 MSI_RecordSetStringW(uirow,1,file->File);
3209 strcpyW(uipath,file->TargetPath);
3210 *(strrchrW(uipath,'\\')+1)=0;
3211 MSI_RecordSetStringW(uirow,9,uipath);
3212 MSI_RecordSetInteger(uirow,6,file->FileSize);
3213 ui_actiondata(package,szInstallFiles,uirow);
3214 msiobj_release( &uirow->hdr );
3215 ui_progress(package,2,file->FileSize,0,0);
3218 if (file->Attributes & msidbFileAttributesNoncompressed)
3219 rc = CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3221 rc = MoveFileW(file->SourcePath, file->TargetPath);
3225 rc = GetLastError();
3226 ERR("Unable to move/copy file (%s -> %s) (error %d)\n",
3227 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3229 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3231 if (!CopyFileW(file->SourcePath,file->TargetPath,FALSE))
3232 ERR("Unable to copy file (%s -> %s) (error %ld)\n",
3233 debugstr_w(file->SourcePath),
3234 debugstr_w(file->TargetPath), GetLastError());
3235 if (!(file->Attributes & msidbFileAttributesNoncompressed))
3236 DeleteFileW(file->SourcePath);
3239 else if (rc == ERROR_FILE_NOT_FOUND)
3241 ERR("Source File Not Found! Continuing\n");
3244 else if (file->Attributes & msidbFileAttributesVital)
3246 ERR("Ignoring Error and continuing (nonvital file)...\n");
3261 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3262 LPWSTR* file_source)
3267 return ERROR_INVALID_HANDLE;
3269 for (index = 0; index < package->loaded_files; index ++)
3271 if (strcmpW(file_key,package->files[index].File)==0)
3273 if (package->files[index].State >= 2)
3275 *file_source = strdupW(package->files[index].TargetPath);
3276 return ERROR_SUCCESS;
3279 return ERROR_FILE_NOT_FOUND;
3283 return ERROR_FUNCTION_FAILED;
3286 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3290 MSIRECORD * row = 0;
3291 static const WCHAR ExecSeqQuery[] =
3292 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3293 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
3296 return ERROR_INVALID_HANDLE;
3298 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3299 if (rc != ERROR_SUCCESS)
3300 return ERROR_SUCCESS;
3302 rc = MSI_ViewExecute(view, 0);
3303 if (rc != ERROR_SUCCESS)
3305 MSI_ViewClose(view);
3306 msiobj_release(&view->hdr);
3312 WCHAR *file_source = NULL;
3313 WCHAR dest_name[0x100];
3314 LPWSTR dest_path, dest;
3315 LPCWSTR file_key, component;
3316 INT component_index;
3320 rc = MSI_ViewFetch(view,&row);
3321 if (rc != ERROR_SUCCESS)
3327 component = MSI_RecordGetString(row,2);
3330 ERR("Unable to get component\n");
3331 msiobj_release(&row->hdr);
3335 component_index = get_loaded_component(package,component);
3337 if (!ACTION_VerifyComponentForAction(package, component_index,
3338 INSTALLSTATE_LOCAL))
3340 TRACE("Skipping copy due to disabled component\n");
3342 /* the action taken was the same as the current install state */
3343 package->components[component_index].Action =
3344 package->components[component_index].Installed;
3346 msiobj_release(&row->hdr);
3350 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3352 file_key = MSI_RecordGetString(row,3);
3355 ERR("Unable to get file key\n");
3356 msiobj_release(&row->hdr);
3360 rc = get_file_target(package,file_key,&file_source);
3362 if (rc != ERROR_SUCCESS)
3364 ERR("Original file unknown %s\n",debugstr_w(file_key));
3365 msiobj_release(&row->hdr);
3366 HeapFree(GetProcessHeap(),0,file_source);
3370 if (MSI_RecordIsNull(row,4))
3372 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3377 MSI_RecordGetStringW(row,4,dest_name,&sz);
3378 reduce_to_longfilename(dest_name);
3381 if (MSI_RecordIsNull(row,5))
3384 dest_path = strdupW(file_source);
3385 p = strrchrW(dest_path,'\\');
3392 destkey = MSI_RecordGetString(row,5);
3393 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3396 ERR("Unable to get destination folder\n");
3397 msiobj_release(&row->hdr);
3398 HeapFree(GetProcessHeap(),0,file_source);
3403 dest = build_directory_name(2, dest_path, dest_name);
3405 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3408 if (strcmpW(file_source,dest))
3409 rc = !CopyFileW(file_source,dest,TRUE);
3413 if (rc != ERROR_SUCCESS)
3414 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
3416 FIXME("We should track these duplicate files as well\n");
3418 msiobj_release(&row->hdr);
3419 HeapFree(GetProcessHeap(),0,dest_path);
3420 HeapFree(GetProcessHeap(),0,dest);
3421 HeapFree(GetProcessHeap(),0,file_source);
3423 MSI_ViewClose(view);
3424 msiobj_release(&view->hdr);
3429 /* OK this value is "interpreted" and then formatted based on the
3430 first few characters */
3431 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3435 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3441 LPWSTR deformated = NULL;
3444 deformat_string(package, &value[2], &deformated);
3446 /* binary value type */
3450 *size = (strlenW(ptr)/2)+1;
3452 *size = strlenW(ptr)/2;
3454 data = HeapAlloc(GetProcessHeap(),0,*size);
3460 /* if uneven pad with a zero in front */
3466 data[count] = (BYTE)strtol(byte,NULL,0);
3468 TRACE("Uneven byte count\n");
3476 data[count] = (BYTE)strtol(byte,NULL,0);
3479 HeapFree(GetProcessHeap(),0,deformated);
3481 TRACE("Data %li bytes(%i)\n",*size,count);
3488 deformat_string(package, &value[1], &deformated);
3491 *size = sizeof(DWORD);
3492 data = HeapAlloc(GetProcessHeap(),0,*size);
3498 if ( (*p < '0') || (*p > '9') )
3504 if (deformated[0] == '-')
3507 TRACE("DWORD %li\n",*(LPDWORD)data);
3509 HeapFree(GetProcessHeap(),0,deformated);
3514 static const WCHAR szMulti[] = {'[','~',']',0};
3523 *type=REG_EXPAND_SZ;
3531 if (strstrW(value,szMulti))
3532 *type = REG_MULTI_SZ;
3534 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3539 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3543 MSIRECORD * row = 0;
3544 static const WCHAR ExecSeqQuery[] =
3545 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3546 '`','R','e','g','i','s','t','r','y','`',0 };
3549 return ERROR_INVALID_HANDLE;
3551 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3552 if (rc != ERROR_SUCCESS)
3553 return ERROR_SUCCESS;
3555 rc = MSI_ViewExecute(view, 0);
3556 if (rc != ERROR_SUCCESS)
3558 MSI_ViewClose(view);
3559 msiobj_release(&view->hdr);
3563 /* increment progress bar each time action data is sent */
3564 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3568 static const WCHAR szHCR[] =
3569 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3570 'R','O','O','T','\\',0};
3571 static const WCHAR szHCU[] =
3572 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3573 'U','S','E','R','\\',0};
3574 static const WCHAR szHLM[] =
3575 {'H','K','E','Y','_','L','O','C','A','L','_',
3576 'M','A','C','H','I','N','E','\\',0};
3577 static const WCHAR szHU[] =
3578 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3580 LPSTR value_data = NULL;
3581 HKEY root_key, hkey;
3583 LPWSTR value, key, name, component, deformated;
3585 INT component_index;
3589 BOOL check_first = FALSE;
3591 rc = MSI_ViewFetch(view,&row);
3592 if (rc != ERROR_SUCCESS)
3597 ui_progress(package,2,0,0,0);
3604 component = load_dynamic_stringW(row, 6);
3605 component_index = get_loaded_component(package,component);
3607 if (!ACTION_VerifyComponentForAction(package, component_index,
3608 INSTALLSTATE_LOCAL))
3610 TRACE("Skipping write due to disabled component\n");
3611 msiobj_release(&row->hdr);
3613 package->components[component_index].Action =
3614 package->components[component_index].Installed;
3619 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3621 name = load_dynamic_stringW(row, 4);
3622 if( MSI_RecordIsNull(row,5) && name )
3624 /* null values can have special meanings */
3625 if (name[0]=='-' && name[1] == 0)
3627 msiobj_release(&row->hdr);
3630 else if ((name[0]=='+' && name[1] == 0) ||
3631 (name[0] == '*' && name[1] == 0))
3633 HeapFree(GetProcessHeap(),0,name);
3639 root = MSI_RecordGetInteger(row,2);
3640 key = load_dynamic_stringW(row, 3);
3643 /* get the root key */
3646 case 0: root_key = HKEY_CLASSES_ROOT;
3649 case 1: root_key = HKEY_CURRENT_USER;
3652 case 2: root_key = HKEY_LOCAL_MACHINE;
3655 case 3: root_key = HKEY_USERS;
3659 ERR("Unknown root %i\n",root);
3666 msiobj_release(&row->hdr);
3670 deformat_string(package, key , &deformated);
3671 size = strlenW(deformated) + strlenW(szRoot) + 1;
3672 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3673 strcpyW(uikey,szRoot);
3674 strcatW(uikey,deformated);
3676 if (RegCreateKeyW( root_key, deformated, &hkey))
3678 ERR("Could not create key %s\n",debugstr_w(deformated));
3679 msiobj_release(&row->hdr);
3680 HeapFree(GetProcessHeap(),0,deformated);
3683 HeapFree(GetProcessHeap(),0,deformated);
3685 value = load_dynamic_stringW(row,5);
3687 value_data = parse_value(package, value, &type, &size);
3690 static const WCHAR szEmpty[] = {0};
3691 value_data = (LPSTR)strdupW(szEmpty);
3696 deformat_string(package, name, &deformated);
3698 /* get the double nulls to terminate SZ_MULTI */
3699 if (type == REG_MULTI_SZ)
3700 size +=sizeof(WCHAR);
3704 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
3706 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3711 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
3712 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3714 TRACE("value %s of %s checked already exists\n",
3715 debugstr_w(deformated), debugstr_w(uikey));
3719 TRACE("Checked and setting value %s of %s\n",
3720 debugstr_w(deformated), debugstr_w(uikey));
3721 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3725 uirow = MSI_CreateRecord(3);
3726 MSI_RecordSetStringW(uirow,2,deformated);
3727 MSI_RecordSetStringW(uirow,1,uikey);
3730 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3732 MSI_RecordSetStringW(uirow,3,value);
3734 ui_actiondata(package,szWriteRegistryValues,uirow);
3735 msiobj_release( &uirow->hdr );
3737 HeapFree(GetProcessHeap(),0,value_data);
3738 HeapFree(GetProcessHeap(),0,value);
3739 HeapFree(GetProcessHeap(),0,deformated);
3741 msiobj_release(&row->hdr);
3744 HeapFree(GetProcessHeap(),0,uikey);
3745 HeapFree(GetProcessHeap(),0,key);
3746 HeapFree(GetProcessHeap(),0,name);
3747 HeapFree(GetProcessHeap(),0,component);
3749 MSI_ViewClose(view);
3750 msiobj_release(&view->hdr);
3754 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3756 package->script->CurrentlyScripting = TRUE;
3758 return ERROR_SUCCESS;
3762 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3766 static const WCHAR q1[]=
3767 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3768 '`','R','e','g','i','s','t','r','y','`',0};
3771 MSIRECORD * row = 0;
3774 TRACE(" InstallValidate \n");
3776 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3777 if (rc != ERROR_SUCCESS)
3778 return ERROR_SUCCESS;
3780 rc = MSI_ViewExecute(view, 0);
3781 if (rc != ERROR_SUCCESS)
3783 MSI_ViewClose(view);
3784 msiobj_release(&view->hdr);
3789 rc = MSI_ViewFetch(view,&row);
3790 if (rc != ERROR_SUCCESS)
3797 msiobj_release(&row->hdr);
3799 MSI_ViewClose(view);
3800 msiobj_release(&view->hdr);
3802 total = total + progress * REG_PROGRESS_VALUE;
3803 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3804 for (i=0; i < package->loaded_files; i++)
3805 total += package->files[i].FileSize;
3806 ui_progress(package,0,total,0,0);
3808 for(i = 0; i < package->loaded_features; i++)
3810 MSIFEATURE* feature = &package->features[i];
3811 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
3812 debugstr_w(feature->Feature), feature->Installed, feature->Action,
3813 feature->ActionRequest);
3816 return ERROR_SUCCESS;
3819 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3822 MSIQUERY * view = NULL;
3823 MSIRECORD * row = 0;
3824 static const WCHAR ExecSeqQuery[] =
3825 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3826 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
3827 static const WCHAR title[]=
3828 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3830 TRACE("Checking launch conditions\n");
3832 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3833 if (rc != ERROR_SUCCESS)
3834 return ERROR_SUCCESS;
3836 rc = MSI_ViewExecute(view, 0);
3837 if (rc != ERROR_SUCCESS)
3839 MSI_ViewClose(view);
3840 msiobj_release(&view->hdr);
3845 while (rc == ERROR_SUCCESS)
3848 LPWSTR message = NULL;
3850 rc = MSI_ViewFetch(view,&row);
3851 if (rc != ERROR_SUCCESS)
3857 cond = load_dynamic_stringW(row,1);
3859 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3862 message = load_dynamic_stringW(row,2);
3863 deformat_string(package,message,&deformated);
3864 MessageBoxW(NULL,deformated,title,MB_OK);
3865 HeapFree(GetProcessHeap(),0,message);
3866 HeapFree(GetProcessHeap(),0,deformated);
3867 rc = ERROR_FUNCTION_FAILED;
3869 HeapFree(GetProcessHeap(),0,cond);
3870 msiobj_release(&row->hdr);
3872 MSI_ViewClose(view);
3873 msiobj_release(&view->hdr);
3877 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3880 MSICOMPONENT* cmp = &package->components[component_index];
3882 if (cmp->KeyPath[0]==0)
3884 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3887 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
3889 MSIRECORD * row = 0;
3891 LPWSTR key,deformated,buffer,name,deformated_name;
3892 static const WCHAR ExecSeqQuery[] =
3893 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3894 '`','R','e','g','i','s','t','r','y','`',' ',
3895 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
3896 ' ','=',' ' ,'\'','%','s','\'',0 };
3897 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
3898 static const WCHAR fmt2[]=
3899 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3901 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
3905 root = MSI_RecordGetInteger(row,2);
3906 key = load_dynamic_stringW(row, 3);
3907 name = load_dynamic_stringW(row, 4);
3908 deformat_string(package, key , &deformated);
3909 deformat_string(package, name, &deformated_name);
3911 len = strlenW(deformated) + 6;
3912 if (deformated_name)
3913 len+=strlenW(deformated_name);
3915 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3917 if (deformated_name)
3918 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3920 sprintfW(buffer,fmt,root,deformated);
3922 HeapFree(GetProcessHeap(),0,key);
3923 HeapFree(GetProcessHeap(),0,deformated);
3924 HeapFree(GetProcessHeap(),0,name);
3925 HeapFree(GetProcessHeap(),0,deformated_name);
3926 msiobj_release(&row->hdr);
3930 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
3932 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3938 j = get_loaded_file(package,cmp->KeyPath);
3942 LPWSTR p = strdupW(package->files[j].TargetPath);
3949 static HKEY openSharedDLLsKey()
3952 static const WCHAR path[] =
3953 {'S','o','f','t','w','a','r','e','\\',
3954 'M','i','c','r','o','s','o','f','t','\\',
3955 'W','i','n','d','o','w','s','\\',
3956 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3957 'S','h','a','r','e','d','D','L','L','s',0};
3959 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
3963 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
3968 DWORD sz = sizeof(count);
3971 hkey = openSharedDLLsKey();
3972 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
3973 if (rc != ERROR_SUCCESS)
3979 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
3983 hkey = openSharedDLLsKey();
3985 RegSetValueExW(hkey,path,0,REG_DWORD,
3986 (LPBYTE)&count,sizeof(count));
3988 RegDeleteValueW(hkey,path);
3994 * Return TRUE if the count should be written out and FALSE if not
3996 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
4002 /* only refcount DLLs */
4003 if (package->components[index].KeyPath[0]==0 ||
4004 package->components[index].Attributes &
4005 msidbComponentAttributesRegistryKeyPath ||
4006 package->components[index].Attributes &
4007 msidbComponentAttributesODBCDataSource)
4011 count = ACTION_GetSharedDLLsCount(package->components[index].
4013 write = (count > 0);
4015 if (package->components[index].Attributes &
4016 msidbComponentAttributesSharedDllRefCount)
4020 /* increment counts */
4021 for (j = 0; j < package->loaded_features; j++)
4025 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
4028 for (i = 0; i < package->features[j].ComponentCount; i++)
4030 if (package->features[j].Components[i] == index)
4034 /* decrement counts */
4035 for (j = 0; j < package->loaded_features; j++)
4038 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
4041 for (i = 0; i < package->features[j].ComponentCount; i++)
4043 if (package->features[j].Components[i] == index)
4048 /* ref count all the files in the component */
4050 for (j = 0; j < package->loaded_files; j++)
4052 if (package->files[j].Temporary)
4054 if (package->files[j].ComponentIndex == index)
4055 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
4058 /* add a count for permenent */
4059 if (package->components[index].Attributes &
4060 msidbComponentAttributesPermanent)
4063 package->components[index].RefCount = count;
4066 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
4067 package->components[index].RefCount);
4071 * Ok further analysis makes me think that this work is
4072 * actually done in the PublishComponents and PublishFeatures
4073 * step, and not here. It appears like the keypath and all that is
4074 * resolved in this step, however actually written in the Publish steps.
4075 * But we will leave it here for now because it is unclear
4077 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
4080 WCHAR squished_pc[GUID_SIZE];
4081 WCHAR squished_cc[GUID_SIZE];
4084 HKEY hkey=0,hkey2=0;
4087 return ERROR_INVALID_HANDLE;
4089 /* writes the Component and Features values to the registry */
4090 productcode = load_dynamic_property(package,szProductCode,&rc);
4094 rc = MSIREG_OpenComponents(&hkey);
4095 if (rc != ERROR_SUCCESS)
4098 squash_guid(productcode,squished_pc);
4099 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
4100 for (i = 0; i < package->loaded_components; i++)
4102 ui_progress(package,2,0,0,0);
4103 if (package->components[i].ComponentId[0]!=0)
4105 WCHAR *keypath = NULL;
4108 squash_guid(package->components[i].ComponentId,squished_cc);
4110 keypath = resolve_keypath(package,i);
4111 package->components[i].FullKeypath = keypath;
4113 /* do the refcounting */
4114 ACTION_RefCountComponent( package, i);
4116 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
4117 debugstr_w(package->components[i].Component),
4118 debugstr_w(squished_cc),
4119 debugstr_w(package->components[i].FullKeypath),
4120 package->components[i].RefCount);
4122 * Write the keypath out if the component is to be registered
4123 * and delete the key if the component is to be deregistered
4125 if (ACTION_VerifyComponentForAction(package, i,
4126 INSTALLSTATE_LOCAL))
4128 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
4129 if (rc != ERROR_SUCCESS)
4134 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
4135 (strlenW(keypath)+1)*sizeof(WCHAR));
4137 if (package->components[i].Attributes &
4138 msidbComponentAttributesPermanent)
4140 static const WCHAR szPermKey[] =
4141 { '0','0','0','0','0','0','0','0','0','0','0','0',
4142 '0','0','0','0','0','0','0', '0','0','0','0','0',
4143 '0','0','0','0','0','0','0','0',0};
4145 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
4147 (strlenW(keypath)+1)*sizeof(WCHAR));
4153 uirow = MSI_CreateRecord(3);
4154 MSI_RecordSetStringW(uirow,1,productcode);
4155 MSI_RecordSetStringW(uirow,2,package->components[i].
4157 MSI_RecordSetStringW(uirow,3,keypath);
4158 ui_actiondata(package,szProcessComponents,uirow);
4159 msiobj_release( &uirow->hdr );
4162 else if (ACTION_VerifyComponentForAction(package, i,
4163 INSTALLSTATE_ABSENT))
4167 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
4168 if (rc != ERROR_SUCCESS)
4171 RegDeleteValueW(hkey2,squished_pc);
4173 /* if the key is empty delete it */
4174 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
4176 if (res == ERROR_NO_MORE_ITEMS)
4177 RegDeleteKeyW(hkey,squished_cc);
4180 uirow = MSI_CreateRecord(2);
4181 MSI_RecordSetStringW(uirow,1,productcode);
4182 MSI_RecordSetStringW(uirow,2,package->components[i].
4184 ui_actiondata(package,szProcessComponents,uirow);
4185 msiobj_release( &uirow->hdr );
4190 HeapFree(GetProcessHeap(), 0, productcode);
4203 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
4204 LPWSTR lpszName, LONG_PTR lParam)
4207 typelib_struct *tl_struct = (typelib_struct*) lParam;
4208 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
4212 if (!IS_INTRESOURCE(lpszName))
4214 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
4218 sz = strlenW(tl_struct->source)+4;
4219 sz *= sizeof(WCHAR);
4221 if ((INT)lpszName == 1)
4222 tl_struct->path = strdupW(tl_struct->source);
4225 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
4226 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
4229 TRACE("trying %s\n", debugstr_w(tl_struct->path));
4230 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
4231 if (!SUCCEEDED(res))
4233 HeapFree(GetProcessHeap(),0,tl_struct->path);
4234 tl_struct->path = NULL;
4239 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
4240 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
4242 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4246 HeapFree(GetProcessHeap(),0,tl_struct->path);
4247 tl_struct->path = NULL;
4249 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4250 ITypeLib_Release(tl_struct->ptLib);
4255 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4258 * OK this is a bit confusing.. I am given a _Component key and I believe
4259 * that the file that is being registered as a type library is the "key file
4260 * of that component" which I interpret to mean "The file in the KeyPath of
4265 MSIRECORD * row = 0;
4266 static const WCHAR Query[] =
4267 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4268 '`','T','y','p','e','L','i','b','`',0};
4271 return ERROR_INVALID_HANDLE;
4273 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4274 if (rc != ERROR_SUCCESS)
4275 return ERROR_SUCCESS;
4277 rc = MSI_ViewExecute(view, 0);
4278 if (rc != ERROR_SUCCESS)
4280 MSI_ViewClose(view);
4281 msiobj_release(&view->hdr);
4287 WCHAR component[0x100];
4291 typelib_struct tl_struct;
4293 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
4295 rc = MSI_ViewFetch(view,&row);
4296 if (rc != ERROR_SUCCESS)
4303 MSI_RecordGetStringW(row,3,component,&sz);
4305 index = get_loaded_component(package,component);
4308 msiobj_release(&row->hdr);
4312 if (!ACTION_VerifyComponentForAction(package, index,
4313 INSTALLSTATE_LOCAL))
4315 TRACE("Skipping typelib reg due to disabled component\n");
4316 msiobj_release(&row->hdr);
4318 package->components[index].Action =
4319 package->components[index].Installed;
4324 package->components[index].Action = INSTALLSTATE_LOCAL;
4326 index = get_loaded_file(package,package->components[index].KeyPath);
4330 msiobj_release(&row->hdr);
4334 guid = load_dynamic_stringW(row,1);
4335 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
4336 LOAD_LIBRARY_AS_DATAFILE);
4339 CLSIDFromString(guid, &tl_struct.clsid);
4340 tl_struct.source = strdupW(package->files[index].TargetPath);
4341 tl_struct.path = NULL;
4343 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
4344 (LONG_PTR)&tl_struct);
4346 if (tl_struct.path != NULL)
4349 WCHAR helpid[0x100];
4353 MSI_RecordGetStringW(row,6,helpid,&sz);
4355 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4356 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
4357 HeapFree(GetProcessHeap(),0,help);
4359 if (!SUCCEEDED(res))
4360 ERR("Failed to register type library %s\n",
4361 debugstr_w(tl_struct.path));
4364 ui_actiondata(package,szRegisterTypeLibraries,row);
4366 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
4369 ITypeLib_Release(tl_struct.ptLib);
4370 HeapFree(GetProcessHeap(),0,tl_struct.path);
4373 ERR("Failed to load type library %s\n",
4374 debugstr_w(tl_struct.source));
4376 FreeLibrary(module);
4377 HeapFree(GetProcessHeap(),0,tl_struct.source);
4380 ERR("Could not load file! %s\n",
4381 debugstr_w(package->files[index].TargetPath));
4382 msiobj_release(&row->hdr);
4384 MSI_ViewClose(view);
4385 msiobj_release(&view->hdr);
4389 static INT load_appid(MSIPACKAGE* package, MSIRECORD *row)
4391 DWORD index = package->loaded_appids;
4395 /* fill in the data */
4397 package->loaded_appids++;
4398 if (package->loaded_appids == 1)
4399 package->appids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIAPPID));
4401 package->appids = HeapReAlloc(GetProcessHeap(),0,
4402 package->appids, package->loaded_appids * sizeof(MSIAPPID));
4404 memset(&package->appids[index],0,sizeof(MSIAPPID));
4406 sz = IDENTIFIER_SIZE;
4407 MSI_RecordGetStringW(row, 1, package->appids[index].AppID, &sz);
4408 TRACE("loading appid %s\n",debugstr_w(package->appids[index].AppID));
4410 buffer = load_dynamic_stringW(row,2);
4411 deformat_string(package,buffer,&package->appids[index].RemoteServerName);
4412 HeapFree(GetProcessHeap(),0,buffer);
4414 package->appids[index].LocalServer = load_dynamic_stringW(row,3);
4415 package->appids[index].ServiceParameters = load_dynamic_stringW(row,4);
4416 package->appids[index].DllSurrogate = load_dynamic_stringW(row,5);
4418 package->appids[index].ActivateAtStorage = !MSI_RecordIsNull(row,6);
4419 package->appids[index].RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
4424 static INT load_given_appid(MSIPACKAGE *package, LPCWSTR appid)
4429 static const WCHAR ExecSeqQuery[] =
4430 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4431 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
4432 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
4437 /* check for appids already loaded */
4438 for (i = 0; i < package->loaded_appids; i++)
4439 if (strcmpiW(package->appids[i].AppID,appid)==0)
4441 TRACE("found appid %s at index %i\n",debugstr_w(appid),i);
4445 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, appid);
4449 rc = load_appid(package, row);
4450 msiobj_release(&row->hdr);
4455 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
4456 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid);
4458 static INT load_progid(MSIPACKAGE* package, MSIRECORD *row)
4460 DWORD index = package->loaded_progids;
4463 /* fill in the data */
4465 package->loaded_progids++;
4466 if (package->loaded_progids == 1)
4467 package->progids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIPROGID));
4469 package->progids = HeapReAlloc(GetProcessHeap(),0,
4470 package->progids , package->loaded_progids * sizeof(MSIPROGID));
4472 memset(&package->progids[index],0,sizeof(MSIPROGID));
4474 package->progids[index].ProgID = load_dynamic_stringW(row,1);
4475 TRACE("loading progid %s\n",debugstr_w(package->progids[index].ProgID));
4477 buffer = load_dynamic_stringW(row,2);
4478 package->progids[index].ParentIndex = load_given_progid(package,buffer);
4479 if (package->progids[index].ParentIndex < 0 && buffer)
4480 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
4481 HeapFree(GetProcessHeap(),0,buffer);
4483 buffer = load_dynamic_stringW(row,3);
4484 package->progids[index].ClassIndex = load_given_class(package,buffer);
4485 if (package->progids[index].ClassIndex< 0 && buffer)
4486 FIXME("Unknown class %s\n",debugstr_w(buffer));
4487 HeapFree(GetProcessHeap(),0,buffer);
4489 package->progids[index].Description = load_dynamic_stringW(row,4);
4491 if (!MSI_RecordIsNull(row,6))
4493 INT icon_index = MSI_RecordGetInteger(row,6);
4494 LPWSTR FileName = load_dynamic_stringW(row,5);
4496 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4498 build_icon_path(package,FileName,&FilePath);
4500 package->progids[index].IconPath =
4501 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+10)*
4504 sprintfW(package->progids[index].IconPath,fmt,FilePath,icon_index);
4506 HeapFree(GetProcessHeap(),0,FilePath);
4507 HeapFree(GetProcessHeap(),0,FileName);
4511 buffer = load_dynamic_stringW(row,5);
4513 build_icon_path(package,buffer,&(package->progids[index].IconPath));
4514 HeapFree(GetProcessHeap(),0,buffer);
4517 package->progids[index].CurVerIndex = -1;
4518 package->progids[index].VersionIndIndex = -1;
4520 /* if we have a parent then we may be that parents CurVer */
4521 if (package->progids[index].ParentIndex >= 0 &&
4522 package->progids[index].ParentIndex != index)
4524 int pindex = package->progids[index].ParentIndex;
4525 while (package->progids[pindex].ParentIndex>= 0 &&
4526 package->progids[pindex].ParentIndex != pindex)
4527 pindex = package->progids[pindex].ParentIndex;
4529 FIXME("BAD BAD need to determing if we are really the CurVer\n");
4531 package->progids[index].CurVerIndex = pindex;
4532 package->progids[pindex].VersionIndIndex = index;
4538 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid)
4543 static const WCHAR ExecSeqQuery[] =
4544 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4545 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
4546 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
4551 /* check for progids already loaded */
4552 for (i = 0; i < package->loaded_progids; i++)
4553 if (strcmpiW(package->progids[i].ProgID,progid)==0)
4555 TRACE("found progid %s at index %i\n",debugstr_w(progid), i);
4559 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, progid);
4563 rc = load_progid(package, row);
4564 msiobj_release(&row->hdr);
4569 static INT load_class(MSIPACKAGE* package, MSIRECORD *row)
4571 DWORD index = package->loaded_classes;
4575 /* fill in the data */
4577 package->loaded_classes++;
4578 if (package->loaded_classes== 1)
4579 package->classes = HeapAlloc(GetProcessHeap(),0,sizeof(MSICLASS));
4581 package->classes = HeapReAlloc(GetProcessHeap(),0,
4582 package->classes, package->loaded_classes * sizeof(MSICLASS));
4584 memset(&package->classes[index],0,sizeof(MSICLASS));
4586 sz = IDENTIFIER_SIZE;
4587 MSI_RecordGetStringW(row, 1, package->classes[index].CLSID, &sz);
4588 TRACE("loading class %s\n",debugstr_w(package->classes[index].CLSID));
4589 sz = IDENTIFIER_SIZE;
4590 MSI_RecordGetStringW(row, 2, package->classes[index].Context, &sz);
4591 buffer = load_dynamic_stringW(row,3);
4592 package->classes[index].ComponentIndex = get_loaded_component(package,
4594 HeapFree(GetProcessHeap(),0,buffer);
4596 package->classes[index].ProgIDText = load_dynamic_stringW(row,4);
4597 package->classes[index].ProgIDIndex =
4598 load_given_progid(package, package->classes[index].ProgIDText);
4600 package->classes[index].Description = load_dynamic_stringW(row,5);
4602 buffer = load_dynamic_stringW(row,6);
4604 package->classes[index].AppIDIndex =
4605 load_given_appid(package, buffer);
4607 package->classes[index].AppIDIndex = -1;
4608 HeapFree(GetProcessHeap(),0,buffer);
4610 package->classes[index].FileTypeMask = load_dynamic_stringW(row,7);
4612 if (!MSI_RecordIsNull(row,9))
4615 INT icon_index = MSI_RecordGetInteger(row,9);
4616 LPWSTR FileName = load_dynamic_stringW(row,8);
4618 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4620 build_icon_path(package,FileName,&FilePath);
4622 package->classes[index].IconPath =
4623 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4626 sprintfW(package->classes[index].IconPath,fmt,FilePath,icon_index);
4628 HeapFree(GetProcessHeap(),0,FilePath);
4629 HeapFree(GetProcessHeap(),0,FileName);
4633 buffer = load_dynamic_stringW(row,8);
4635 build_icon_path(package,buffer,&(package->classes[index].IconPath));
4636 HeapFree(GetProcessHeap(),0,buffer);
4639 if (!MSI_RecordIsNull(row,10))
4641 i = MSI_RecordGetInteger(row,10);
4642 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4644 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4645 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
4650 package->classes[index].DefInprocHandler = strdupW(ole2);
4653 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4656 package->classes[index].DefInprocHandler = strdupW(ole2);
4657 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4663 package->classes[index].DefInprocHandler32 = load_dynamic_stringW(
4665 reduce_to_longfilename(package->classes[index].DefInprocHandler32);
4668 buffer = load_dynamic_stringW(row,11);
4669 deformat_string(package,buffer,&package->classes[index].Argument);
4670 HeapFree(GetProcessHeap(),0,buffer);
4672 buffer = load_dynamic_stringW(row,12);
4673 package->classes[index].FeatureIndex = get_loaded_feature(package,buffer);
4674 HeapFree(GetProcessHeap(),0,buffer);
4676 package->classes[index].Attributes = MSI_RecordGetInteger(row,13);
4682 * the Class table has 3 primary keys. Generally it is only
4683 * referenced through the first CLSID key. However when loading
4684 * all of the classes we need to make sure we do not ignore rows
4685 * with other Context and ComponentIndexs
4687 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid)
4692 static const WCHAR ExecSeqQuery[] =
4693 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4694 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
4695 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
4701 /* check for classes already loaded */
4702 for (i = 0; i < package->loaded_classes; i++)
4703 if (strcmpiW(package->classes[i].CLSID,classid)==0)
4705 TRACE("found class %s at index %i\n",debugstr_w(classid), i);
4709 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
4713 rc = load_class(package, row);
4714 msiobj_release(&row->hdr);
4719 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension);
4721 static INT load_mime(MSIPACKAGE* package, MSIRECORD *row)
4723 DWORD index = package->loaded_mimes;
4727 /* fill in the data */
4729 package->loaded_mimes++;
4730 if (package->loaded_mimes== 1)
4731 package->mimes= HeapAlloc(GetProcessHeap(),0,sizeof(MSIMIME));
4733 package->mimes= HeapReAlloc(GetProcessHeap(),0,
4734 package->mimes, package->loaded_mimes*
4737 memset(&package->mimes[index],0,sizeof(MSIMIME));
4739 package->mimes[index].ContentType = load_dynamic_stringW(row,1);
4740 TRACE("loading mime %s\n",debugstr_w(package->mimes[index].ContentType));
4742 buffer = load_dynamic_stringW(row,2);
4743 package->mimes[index].ExtensionIndex = load_given_extension(package,
4745 HeapFree(GetProcessHeap(),0,buffer);
4747 sz = IDENTIFIER_SIZE;
4748 MSI_RecordGetStringW(row,3,package->mimes[index].CLSID,&sz);
4749 package->mimes[index].ClassIndex= load_given_class(package,
4750 package->mimes[index].CLSID);
4755 static INT load_given_mime(MSIPACKAGE *package, LPCWSTR mime)
4760 static const WCHAR ExecSeqQuery[] =
4761 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4762 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
4763 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
4764 '\'','%','s','\'',0};
4769 /* check for mime already loaded */
4770 for (i = 0; i < package->loaded_mimes; i++)
4771 if (strcmpiW(package->mimes[i].ContentType,mime)==0)
4773 TRACE("found mime %s at index %i\n",debugstr_w(mime), i);
4777 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
4781 rc = load_mime(package, row);
4782 msiobj_release(&row->hdr);
4787 static INT load_extension(MSIPACKAGE* package, MSIRECORD *row)
4789 DWORD index = package->loaded_extensions;
4793 /* fill in the data */
4795 package->loaded_extensions++;
4796 if (package->loaded_extensions == 1)
4797 package->extensions = HeapAlloc(GetProcessHeap(),0,sizeof(MSIEXTENSION));
4799 package->extensions = HeapReAlloc(GetProcessHeap(),0,
4800 package->extensions, package->loaded_extensions*
4801 sizeof(MSIEXTENSION));
4803 memset(&package->extensions[index],0,sizeof(MSIEXTENSION));
4806 MSI_RecordGetStringW(row,1,package->extensions[index].Extension,&sz);
4807 TRACE("loading extension %s\n",
4808 debugstr_w(package->extensions[index].Extension));
4810 buffer = load_dynamic_stringW(row,2);
4811 package->extensions[index].ComponentIndex =
4812 get_loaded_component(package,buffer);
4813 HeapFree(GetProcessHeap(),0,buffer);
4815 package->extensions[index].ProgIDText = load_dynamic_stringW(row,3);
4816 package->extensions[index].ProgIDIndex = load_given_progid(package,
4817 package->extensions[index].ProgIDText);
4819 buffer = load_dynamic_stringW(row,4);
4820 package->extensions[index].MIMEIndex = load_given_mime(package,buffer);
4821 HeapFree(GetProcessHeap(),0,buffer);
4823 buffer = load_dynamic_stringW(row,5);
4824 package->extensions[index].FeatureIndex =
4825 get_loaded_feature(package,buffer);
4826 HeapFree(GetProcessHeap(),0,buffer);
4832 * While the extension table has 2 primary keys, this function is only looking
4833 * at the Extension key which is what is referenced as a forign key
4835 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension)
4840 static const WCHAR ExecSeqQuery[] =
4841 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4842 '`','E','x','t','e','n','s','i','o','n','`',' ',
4843 'W','H','E','R','E',' ',
4844 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
4845 '\'','%','s','\'',0};
4850 /* check for extensions already loaded */
4851 for (i = 0; i < package->loaded_extensions; i++)
4852 if (strcmpiW(package->extensions[i].Extension,extension)==0)
4854 TRACE("extension %s already loaded at %i\n",debugstr_w(extension),
4859 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, extension);
4863 rc = load_extension(package, row);
4864 msiobj_release(&row->hdr);
4869 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
4871 MSIPACKAGE* package = (MSIPACKAGE*)param;
4872 DWORD index = package->loaded_verbs;
4875 /* fill in the data */
4877 package->loaded_verbs++;
4878 if (package->loaded_verbs == 1)
4879 package->verbs = HeapAlloc(GetProcessHeap(),0,sizeof(MSIVERB));
4881 package->verbs = HeapReAlloc(GetProcessHeap(),0,
4882 package->verbs , package->loaded_verbs * sizeof(MSIVERB));
4884 memset(&package->verbs[index],0,sizeof(MSIVERB));
4886 buffer = load_dynamic_stringW(row,1);
4887 package->verbs[index].ExtensionIndex = load_given_extension(package,buffer);
4888 if (package->verbs[index].ExtensionIndex < 0 && buffer)
4889 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
4890 HeapFree(GetProcessHeap(),0,buffer);
4892 package->verbs[index].Verb = load_dynamic_stringW(row,2);
4893 TRACE("loading verb %s\n",debugstr_w(package->verbs[index].Verb));
4894 package->verbs[index].Sequence = MSI_RecordGetInteger(row,3);
4896 buffer = load_dynamic_stringW(row,4);
4897 deformat_string(package,buffer,&package->verbs[index].Command);
4898 HeapFree(GetProcessHeap(),0,buffer);
4900 buffer = load_dynamic_stringW(row,5);
4901 deformat_string(package,buffer,&package->verbs[index].Argument);
4902 HeapFree(GetProcessHeap(),0,buffer);
4904 /* assosiate the verb with the correct extension */
4905 if (package->verbs[index].ExtensionIndex >= 0)
4907 MSIEXTENSION* extension = &package->extensions[package->verbs[index].
4909 int count = extension->VerbCount;
4912 FIXME("Exceeding max verb count! Increase that limit!!!\n");
4915 extension->VerbCount++;
4916 extension->Verbs[count] = index;
4920 return ERROR_SUCCESS;
4923 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
4928 INT component_index;
4929 MSIPACKAGE* package =(MSIPACKAGE*)param;
4933 clsid = load_dynamic_stringW(rec,1);
4934 context = load_dynamic_stringW(rec,2);
4935 buffer = load_dynamic_stringW(rec,3);
4936 component_index = get_loaded_component(package,buffer);
4938 for (i = 0; i < package->loaded_classes; i++)
4940 if (strcmpiW(clsid,package->classes[i].CLSID))
4942 if (strcmpW(context,package->classes[i].Context))
4944 if (component_index == package->classes[i].ComponentIndex)
4951 HeapFree(GetProcessHeap(),0,buffer);
4952 HeapFree(GetProcessHeap(),0,clsid);
4953 HeapFree(GetProcessHeap(),0,context);
4956 load_class(package, rec);
4958 return ERROR_SUCCESS;
4961 static VOID load_all_classes(MSIPACKAGE *package)
4963 UINT rc = ERROR_SUCCESS;
4966 static const WCHAR ExecSeqQuery[] =
4967 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
4968 '`','C','l','a','s','s','`',0};
4970 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4971 if (rc != ERROR_SUCCESS)
4974 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
4975 msiobj_release(&view->hdr);
4978 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
4982 INT component_index;
4983 MSIPACKAGE* package =(MSIPACKAGE*)param;
4987 extension = load_dynamic_stringW(rec,1);
4988 buffer = load_dynamic_stringW(rec,2);
4989 component_index = get_loaded_component(package,buffer);
4991 for (i = 0; i < package->loaded_extensions; i++)
4993 if (strcmpiW(extension,package->extensions[i].Extension))
4995 if (component_index == package->extensions[i].ComponentIndex)
5002 HeapFree(GetProcessHeap(),0,buffer);
5003 HeapFree(GetProcessHeap(),0,extension);
5006 load_extension(package, rec);
5008 return ERROR_SUCCESS;
5011 static VOID load_all_extensions(MSIPACKAGE *package)
5013 UINT rc = ERROR_SUCCESS;
5016 static const WCHAR ExecSeqQuery[] =
5017 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5018 '`','E','x','t','e','n','s','i','o','n','`',0};
5020 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5021 if (rc != ERROR_SUCCESS)
5024 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
5025 msiobj_release(&view->hdr);
5028 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
5031 MSIPACKAGE* package =(MSIPACKAGE*)param;
5033 buffer = load_dynamic_stringW(rec,1);
5034 load_given_progid(package,buffer);
5035 HeapFree(GetProcessHeap(),0,buffer);
5036 return ERROR_SUCCESS;
5039 static VOID load_all_progids(MSIPACKAGE *package)
5041 UINT rc = ERROR_SUCCESS;
5044 static const WCHAR ExecSeqQuery[] =
5045 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
5046 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
5048 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5049 if (rc != ERROR_SUCCESS)
5052 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
5053 msiobj_release(&view->hdr);
5056 static VOID load_all_verbs(MSIPACKAGE *package)
5058 UINT rc = ERROR_SUCCESS;
5061 static const WCHAR ExecSeqQuery[] =
5062 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5063 '`','V','e','r','b','`',0};
5065 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5066 if (rc != ERROR_SUCCESS)
5069 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
5070 msiobj_release(&view->hdr);
5073 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
5076 MSIPACKAGE* package =(MSIPACKAGE*)param;
5078 buffer = load_dynamic_stringW(rec,1);
5079 load_given_mime(package,buffer);
5080 HeapFree(GetProcessHeap(),0,buffer);
5081 return ERROR_SUCCESS;
5084 static VOID load_all_mimes(MSIPACKAGE *package)
5086 UINT rc = ERROR_SUCCESS;
5089 static const WCHAR ExecSeqQuery[] =
5090 {'S','E','L','E','C','T',' ',
5091 '`','C','o','n','t','e','n','t','T','y','p','e','`',
5092 ' ','F','R','O','M',' ',
5093 '`','M','I','M','E','`',0};
5095 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5096 if (rc != ERROR_SUCCESS)
5099 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
5100 msiobj_release(&view->hdr);
5103 static void load_classes_and_such(MSIPACKAGE *package)
5105 TRACE("Loading all the class info and related tables\n");
5107 /* check if already loaded */
5108 if (package->classes || package->extensions || package->progids ||
5109 package->verbs || package->mimes)
5112 load_all_classes(package);
5113 load_all_extensions(package);
5114 load_all_progids(package);
5115 /* these loads must come after the other loads */
5116 load_all_verbs(package);
5117 load_all_mimes(package);
5120 static void mark_progid_for_install(MSIPACKAGE* package, INT index)
5125 if (index < 0 || index >= package->loaded_progids)
5128 progid = &package->progids[index];
5130 if (progid->InstallMe == TRUE)
5133 progid->InstallMe = TRUE;
5135 /* all children if this is a parent also install */
5136 for (i = 0; i < package->loaded_progids; i++)
5137 if (package->progids[i].ParentIndex == index)
5138 mark_progid_for_install(package,i);
5141 static void mark_mime_for_install(MSIPACKAGE* package, INT index)
5145 if (index < 0 || index >= package->loaded_mimes)
5148 mime = &package->mimes[index];
5150 if (mime->InstallMe == TRUE)
5153 mime->InstallMe = TRUE;
5156 static UINT register_appid(MSIPACKAGE *package, int appidIndex, LPCWSTR app )
5158 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5162 return ERROR_INVALID_HANDLE;
5164 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
5165 RegCreateKeyW(hkey2,package->appids[appidIndex].AppID,&hkey3);
5166 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
5167 (strlenW(app)+1)*sizeof(WCHAR));
5169 if (package->appids[appidIndex].RemoteServerName)
5172 static const WCHAR szRemoteServerName[] =
5173 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
5176 size = (strlenW(package->appids[appidIndex].RemoteServerName)+1) *
5179 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,
5180 (LPVOID)package->appids[appidIndex].RemoteServerName,
5184 if (package->appids[appidIndex].LocalServer)
5186 static const WCHAR szLocalService[] =
5187 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
5189 size = (strlenW(package->appids[appidIndex].LocalServer)+1) *
5192 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,
5193 (LPVOID)package->appids[appidIndex].LocalServer,size);
5196 if (package->appids[appidIndex].ServiceParameters)
5198 static const WCHAR szService[] =
5199 {'S','e','r','v','i','c','e',
5200 'P','a','r','a','m','e','t','e','r','s',0};
5202 size = (strlenW(package->appids[appidIndex].ServiceParameters)+1) *
5204 RegSetValueExW(hkey3,szService,0,REG_SZ,
5205 (LPVOID)package->appids[appidIndex].ServiceParameters,
5209 if (package->appids[appidIndex].DllSurrogate)
5211 static const WCHAR szDLL[] =
5212 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
5214 size = (strlenW(package->appids[appidIndex].DllSurrogate)+1) *
5216 RegSetValueExW(hkey3,szDLL,0,REG_SZ,
5217 (LPVOID)package->appids[appidIndex].DllSurrogate,size);
5220 if (package->appids[appidIndex].ActivateAtStorage)
5222 static const WCHAR szActivate[] =
5223 {'A','c','t','i','v','a','t','e','A','s',
5224 'S','t','o','r','a','g','e',0};
5225 static const WCHAR szY[] = {'Y',0};
5227 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
5230 if (package->appids[appidIndex].RunAsInteractiveUser)
5232 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
5233 static const WCHAR szUser[] =
5234 {'I','n','t','e','r','a','c','t','i','v','e',' ',
5237 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,sizeof(szUser));
5242 return ERROR_SUCCESS;
5245 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
5248 * Again I am assuming the words, "Whose key file represents" when referring
5249 * to a Component as to meaning that Components KeyPath file
5254 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5255 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
5256 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 };
5257 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5258 static const WCHAR szSpace[] = {' ',0};
5259 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
5260 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
5261 HKEY hkey,hkey2,hkey3;
5262 BOOL install_on_demand = FALSE;
5266 return ERROR_INVALID_HANDLE;
5268 load_classes_and_such(package);
5269 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
5270 if (rc != ERROR_SUCCESS)
5271 return ERROR_FUNCTION_FAILED;
5273 /* install_on_demand should be set if OLE supports install on demand OLE
5274 * servers. For now i am defaulting to FALSE because i do not know how to
5275 * check, and i am told our builtin OLE does not support it
5278 for (i = 0; i < package->loaded_classes; i++)
5284 if (package->classes[i].ComponentIndex < 0)
5289 index = package->classes[i].ComponentIndex;
5290 f_index = package->classes[i].FeatureIndex;
5293 * yes. MSDN says that these are based on _Feature_ not on
5294 * Component. So verify the feature is to be installed
5296 if ((!ACTION_VerifyFeatureForAction(package, f_index,
5297 INSTALLSTATE_LOCAL)) &&
5298 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
5299 f_index, INSTALLSTATE_ADVERTISED)))
5301 TRACE("Skipping class %s reg due to disabled feature %s\n",
5302 debugstr_w(package->classes[i].CLSID),
5303 debugstr_w(package->features[f_index].Feature));
5308 TRACE("Registering index %i class %s\n",i,
5309 debugstr_w(package->classes[i].CLSID));
5311 package->classes[i].Installed = TRUE;
5312 if (package->classes[i].ProgIDIndex >= 0)
5313 mark_progid_for_install(package, package->classes[i].ProgIDIndex);
5315 RegCreateKeyW(hkey,package->classes[i].CLSID,&hkey2);
5317 if (package->classes[i].Description)
5318 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)package->classes[i].
5319 Description, (strlenW(package->classes[i].
5320 Description)+1)*sizeof(WCHAR));
5322 RegCreateKeyW(hkey2,package->classes[i].Context,&hkey3);
5323 index = get_loaded_file(package,package->components[index].KeyPath);
5326 /* the context server is a short path name
5327 * except for if it is InprocServer32...
5329 if (strcmpiW(package->classes[i].Context,szInprocServer32)!=0)
5332 sz = GetShortPathNameW(package->files[index].TargetPath, NULL, 0);
5335 ERR("Unable to find short path for CLSID COM Server\n");
5340 size = sz * sizeof(WCHAR);
5342 if (package->classes[i].Argument)
5344 size += strlenW(package->classes[i].Argument) *
5346 size += sizeof(WCHAR);
5349 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5350 GetShortPathNameW(package->files[index].TargetPath, argument,
5353 if (package->classes[i].Argument)
5355 strcatW(argument,szSpace);
5356 strcatW(argument,package->classes[i].Argument);
5362 size = lstrlenW(package->files[index].TargetPath) * sizeof(WCHAR);
5364 if (package->classes[i].Argument)
5366 size += strlenW(package->classes[i].Argument) * sizeof(WCHAR);
5367 size += sizeof(WCHAR);
5370 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5371 strcpyW(argument, package->files[index].TargetPath);
5373 if (package->classes[i].Argument)
5375 strcatW(argument,szSpace);
5376 strcatW(argument,package->classes[i].Argument);
5382 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
5383 HeapFree(GetProcessHeap(),0,argument);
5388 if (package->classes[i].ProgIDIndex >= 0 ||
5389 package->classes[i].ProgIDText)
5393 if (package->classes[i].ProgIDIndex >= 0)
5394 progid = package->progids[
5395 package->classes[i].ProgIDIndex].ProgID;
5397 progid = package->classes[i].ProgIDText;
5399 RegCreateKeyW(hkey2,szProgID,&hkey3);
5400 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)progid,
5401 (strlenW(progid)+1) *sizeof(WCHAR));
5404 if (package->classes[i].ProgIDIndex >= 0 &&
5405 package->progids[package->classes[i].ProgIDIndex].
5406 VersionIndIndex >= 0)
5408 LPWSTR viprogid = strdupW(package->progids[package->progids[
5409 package->classes[i].ProgIDIndex].VersionIndIndex].
5411 RegCreateKeyW(hkey2,szVIProgID,&hkey3);
5412 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)viprogid,
5413 (strlenW(viprogid)+1) *sizeof(WCHAR));
5415 HeapFree(GetProcessHeap(), 0, viprogid);
5419 if (package->classes[i].AppIDIndex >= 0)
5421 RegSetValueExW(hkey2,szAppID,0,REG_SZ,
5422 (LPVOID)package->appids[package->classes[i].AppIDIndex].AppID,
5423 (strlenW(package->appids[package->classes[i].AppIDIndex].AppID)+1)
5426 register_appid(package,package->classes[i].AppIDIndex,
5427 package->classes[i].Description);
5430 if (package->classes[i].IconPath)
5432 static const WCHAR szDefaultIcon[] =
5433 {'D','e','f','a','u','l','t','I','c','o','n',0};
5435 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
5437 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5438 (LPVOID)package->classes[i].IconPath,
5439 (strlenW(package->classes[i].IconPath)+1) *
5445 if (package->classes[i].DefInprocHandler)
5447 static const WCHAR szInproc[] =
5448 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
5450 size = (strlenW(package->classes[i].DefInprocHandler) + 1) *
5452 RegCreateKeyW(hkey2,szInproc,&hkey3);
5453 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5454 (LPVOID)package->classes[i].DefInprocHandler, size);
5458 if (package->classes[i].DefInprocHandler32)
5460 static const WCHAR szInproc32[] =
5461 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
5463 size = (strlenW(package->classes[i].DefInprocHandler32) + 1) *
5466 RegCreateKeyW(hkey2,szInproc32,&hkey3);
5467 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5468 (LPVOID)package->classes[i].DefInprocHandler32,size);
5474 /* if there is a FileTypeMask, register the FileType */
5475 if (package->classes[i].FileTypeMask)
5480 ptr = package->classes[i].FileTypeMask;
5483 ptr2 = strchrW(ptr,';');
5486 keyname = HeapAlloc(GetProcessHeap(),0,(strlenW(szFileType_fmt)+
5487 strlenW(package->classes[i].CLSID) + 4)
5489 sprintfW(keyname,szFileType_fmt, package->classes[i].CLSID,
5492 RegCreateKeyW(HKEY_CLASSES_ROOT,keyname,&hkey2);
5493 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPVOID)ptr,
5494 strlenW(ptr)*sizeof(WCHAR));
5496 HeapFree(GetProcessHeap(), 0, keyname);
5507 uirow = MSI_CreateRecord(1);
5509 MSI_RecordSetStringW(uirow,1,package->classes[i].CLSID);
5510 ui_actiondata(package,szRegisterClassInfo,uirow);
5511 msiobj_release(&uirow->hdr);
5518 static UINT register_progid_base(MSIPACKAGE* package, MSIPROGID* progid,
5521 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5522 static const WCHAR szDefaultIcon[] =
5523 {'D','e','f','a','u','l','t','I','c','o','n',0};
5526 RegCreateKeyW(HKEY_CLASSES_ROOT,progid->ProgID,&hkey);
5528 if (progid->Description)
5530 RegSetValueExW(hkey,NULL,0,REG_SZ,
5531 (LPVOID)progid->Description,
5532 (strlenW(progid->Description)+1) *
5536 if (progid->ClassIndex >= 0)
5538 RegCreateKeyW(hkey,szCLSID,&hkey2);
5539 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5540 (LPVOID)package->classes[progid->ClassIndex].CLSID,
5541 (strlenW(package->classes[progid->ClassIndex].CLSID)+1)
5545 strcpyW(clsid,package->classes[progid->ClassIndex].CLSID);
5551 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
5554 if (progid->IconPath)
5556 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5558 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5559 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5562 return ERROR_SUCCESS;
5565 static UINT register_progid(MSIPACKAGE *package, MSIPROGID* progid,
5568 UINT rc = ERROR_SUCCESS;
5570 if (progid->ParentIndex < 0)
5571 rc = register_progid_base(package, progid, clsid);
5576 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5577 static const WCHAR szDefaultIcon[] =
5578 {'D','e','f','a','u','l','t','I','c','o','n',0};
5579 static const WCHAR szCurVer[] =
5580 {'C','u','r','V','e','r',0};
5582 /* check if already registered */
5583 RegCreateKeyExW(HKEY_CLASSES_ROOT, progid->ProgID, 0, NULL, 0,
5584 KEY_ALL_ACCESS, NULL, &hkey, &disp );
5585 if (disp == REG_OPENED_EXISTING_KEY)
5587 TRACE("Key already registered\n");
5592 TRACE("Registering Parent %s index %i\n",
5593 debugstr_w(package->progids[progid->ParentIndex].ProgID),
5594 progid->ParentIndex);
5595 rc = register_progid(package,&package->progids[progid->ParentIndex],
5598 /* clsid is same as parent */
5599 RegCreateKeyW(hkey,szCLSID,&hkey2);
5600 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
5606 if (progid->Description)
5608 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid->Description,
5609 (strlenW(progid->Description)+1) * sizeof(WCHAR));
5612 if (progid->IconPath)
5614 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5615 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5616 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5620 /* write out the current version */
5621 if (progid->CurVerIndex >= 0)
5623 RegCreateKeyW(hkey,szCurVer,&hkey2);
5624 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5625 (LPVOID)package->progids[progid->CurVerIndex].ProgID,
5626 (strlenW(package->progids[progid->CurVerIndex].ProgID)+1) *
5636 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
5642 return ERROR_INVALID_HANDLE;
5644 load_classes_and_such(package);
5646 for (i = 0; i < package->loaded_progids; i++)
5648 WCHAR clsid[0x1000];
5650 /* check if this progid is to be installed */
5651 package->progids[i].InstallMe = ((package->progids[i].InstallMe) ||
5652 (package->progids[i].ClassIndex >= 0 &&
5653 package->classes[package->progids[i].ClassIndex].Installed));
5655 if (!package->progids[i].InstallMe)
5657 TRACE("progid %s not scheduled to be installed\n",
5658 debugstr_w(package->progids[i].ProgID));
5662 TRACE("Registering progid %s index %i\n",
5663 debugstr_w(package->progids[i].ProgID), i);
5665 register_progid(package,&package->progids[i],clsid);
5667 uirow = MSI_CreateRecord(1);
5668 MSI_RecordSetStringW(uirow,1,package->progids[i].ProgID);
5669 ui_actiondata(package,szRegisterProgIdInfo,uirow);
5670 msiobj_release(&uirow->hdr);
5673 return ERROR_SUCCESS;
5676 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
5680 LPWSTR SystemFolder;
5684 static const WCHAR szInstaller[] =
5685 {'M','i','c','r','o','s','o','f','t','\\',
5686 'I','n','s','t','a','l','l','e','r','\\',0};
5687 static const WCHAR szFolder[] =
5688 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
5690 ProductCode = load_dynamic_property(package,szProductCode,&rc);
5694 SystemFolder = load_dynamic_property(package,szFolder,NULL);
5696 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
5698 create_full_pathW(dest);
5700 *FilePath = build_directory_name(2, dest, icon_name);
5702 HeapFree(GetProcessHeap(),0,SystemFolder);
5703 HeapFree(GetProcessHeap(),0,ProductCode);
5704 HeapFree(GetProcessHeap(),0,dest);
5705 return ERROR_SUCCESS;
5708 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
5712 MSIRECORD * row = 0;
5713 static const WCHAR Query[] =
5714 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5715 '`','S','h','o','r','t','c','u','t','`',0};
5721 return ERROR_INVALID_HANDLE;
5723 res = CoInitialize( NULL );
5726 ERR("CoInitialize failed\n");
5727 return ERROR_FUNCTION_FAILED;
5730 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5731 if (rc != ERROR_SUCCESS)
5732 return ERROR_SUCCESS;
5734 rc = MSI_ViewExecute(view, 0);
5735 if (rc != ERROR_SUCCESS)
5737 MSI_ViewClose(view);
5738 msiobj_release(&view->hdr);
5744 LPWSTR target_file, target_folder;
5745 WCHAR buffer[0x100];
5748 static const WCHAR szlnk[]={'.','l','n','k',0};
5750 rc = MSI_ViewFetch(view,&row);
5751 if (rc != ERROR_SUCCESS)
5758 MSI_RecordGetStringW(row,4,buffer,&sz);
5760 index = get_loaded_component(package,buffer);
5764 msiobj_release(&row->hdr);
5768 if (!ACTION_VerifyComponentForAction(package, index,
5769 INSTALLSTATE_LOCAL))
5771 TRACE("Skipping shortcut creation due to disabled component\n");
5772 msiobj_release(&row->hdr);
5774 package->components[index].Action =
5775 package->components[index].Installed;
5780 package->components[index].Action = INSTALLSTATE_LOCAL;
5782 ui_actiondata(package,szCreateShortcuts,row);
5784 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
5785 &IID_IShellLinkW, (LPVOID *) &sl );
5789 ERR("Is IID_IShellLink\n");
5790 msiobj_release(&row->hdr);
5794 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
5797 ERR("Is IID_IPersistFile\n");
5798 msiobj_release(&row->hdr);
5803 MSI_RecordGetStringW(row,2,buffer,&sz);
5804 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
5806 /* may be needed because of a bug somehwere else */
5807 create_full_pathW(target_folder);
5810 MSI_RecordGetStringW(row,3,buffer,&sz);
5811 reduce_to_longfilename(buffer);
5812 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
5813 strcatW(buffer,szlnk);
5814 target_file = build_directory_name(2, target_folder, buffer);
5815 HeapFree(GetProcessHeap(),0,target_folder);
5818 MSI_RecordGetStringW(row,5,buffer,&sz);
5819 if (strchrW(buffer,'['))
5822 deformat_string(package,buffer,&deformated);
5823 IShellLinkW_SetPath(sl,deformated);
5824 HeapFree(GetProcessHeap(),0,deformated);
5829 FIXME("poorly handled shortcut format, advertised shortcut\n");
5830 keypath = strdupW(package->components[index].FullKeypath);
5831 IShellLinkW_SetPath(sl,keypath);
5832 HeapFree(GetProcessHeap(),0,keypath);
5835 if (!MSI_RecordIsNull(row,6))
5839 MSI_RecordGetStringW(row,6,buffer,&sz);
5840 deformat_string(package,buffer,&deformated);
5841 IShellLinkW_SetArguments(sl,deformated);
5842 HeapFree(GetProcessHeap(),0,deformated);
5845 if (!MSI_RecordIsNull(row,7))
5848 deformated = load_dynamic_stringW(row,7);
5849 IShellLinkW_SetDescription(sl,deformated);
5850 HeapFree(GetProcessHeap(),0,deformated);
5853 if (!MSI_RecordIsNull(row,8))
5854 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
5856 if (!MSI_RecordIsNull(row,9))
5862 MSI_RecordGetStringW(row,9,buffer,&sz);
5864 build_icon_path(package,buffer,&Path);
5865 index = MSI_RecordGetInteger(row,10);
5867 IShellLinkW_SetIconLocation(sl,Path,index);
5868 HeapFree(GetProcessHeap(),0,Path);
5871 if (!MSI_RecordIsNull(row,11))
5872 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
5874 if (!MSI_RecordIsNull(row,12))
5878 MSI_RecordGetStringW(row,12,buffer,&sz);
5879 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
5880 IShellLinkW_SetWorkingDirectory(sl,Path);
5881 HeapFree(GetProcessHeap(), 0, Path);
5884 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
5885 IPersistFile_Save(pf,target_file,FALSE);
5887 HeapFree(GetProcessHeap(),0,target_file);
5889 IPersistFile_Release( pf );
5890 IShellLinkW_Release( sl );
5892 msiobj_release(&row->hdr);
5894 MSI_ViewClose(view);
5895 msiobj_release(&view->hdr);
5905 * 99% of the work done here is only done for
5906 * advertised installs. However this is where the
5907 * Icon table is processed and written out
5908 * so that is what I am going to do here.
5910 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
5914 MSIRECORD * row = 0;
5915 static const WCHAR Query[]=
5916 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5917 '`','I','c','o','n','`',0};
5919 /* for registry stuff */
5923 static const WCHAR szProductName[] =
5924 {'P','r','o','d','u','c','t','N','a','m','e',0};
5925 static const WCHAR szPackageCode[] =
5926 {'P','a','c','k','a','g','e','C','o','d','e',0};
5927 static const WCHAR szLanguage[] =
5928 {'L','a','n','g','u','a','g','e',0};
5929 static const WCHAR szProductLanguage[] =
5930 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
5931 static const WCHAR szProductIcon[] =
5932 {'P','r','o','d','u','c','t','I','c','o','n',0};
5933 static const WCHAR szARPProductIcon[] =
5934 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',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);
6037 buffer = load_dynamic_property(package,szProductLanguage,NULL);
6038 size = sizeof(DWORD);
6039 langid = atoiW(buffer);
6040 RegSetValueExW(hukey,szLanguage,0,REG_DWORD, (BYTE *)&langid,size);
6042 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
6046 build_icon_path(package,buffer,&path);
6047 size = strlenW(path) * sizeof(WCHAR);
6048 RegSetValueExW(hukey,szProductIcon,0,REG_SZ, (BYTE *)path,size);
6051 FIXME("Need to write more keys to the user registry\n");
6053 hDb= alloc_msihandle( &package->db->hdr );
6054 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
6055 MsiCloseHandle(hDb);
6056 if (rc == ERROR_SUCCESS)
6058 WCHAR guidbuffer[0x200];
6060 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
6062 if (rc == ERROR_SUCCESS)
6064 WCHAR squashed[GUID_SIZE];
6065 /* for now we only care about the first guid */
6066 LPWSTR ptr = strchrW(guidbuffer,';');
6068 squash_guid(guidbuffer,squashed);
6069 size = strlenW(squashed)*sizeof(WCHAR);
6070 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
6075 ERR("Unable to query Revision_Number... \n");
6078 MsiCloseHandle(hSumInfo);
6082 ERR("Unable to open Summary Information\n");
6088 HeapFree(GetProcessHeap(),0,productcode);
6095 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
6099 MSIRECORD * row = 0;
6100 static const WCHAR ExecSeqQuery[] =
6101 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6102 '`','I','n','i','F','i','l','e','`',0};
6103 static const WCHAR szWindowsFolder[] =
6104 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
6106 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6107 if (rc != ERROR_SUCCESS)
6109 TRACE("no IniFile table\n");
6110 return ERROR_SUCCESS;
6113 rc = MSI_ViewExecute(view, 0);
6114 if (rc != ERROR_SUCCESS)
6116 MSI_ViewClose(view);
6117 msiobj_release(&view->hdr);
6123 LPWSTR component,filename,dirproperty,section,key,value,identifier;
6124 LPWSTR deformated_section, deformated_key, deformated_value;
6125 LPWSTR folder, fullname = NULL;
6127 INT component_index,action;
6129 rc = MSI_ViewFetch(view,&row);
6130 if (rc != ERROR_SUCCESS)
6136 component = load_dynamic_stringW(row, 8);
6137 component_index = get_loaded_component(package,component);
6138 HeapFree(GetProcessHeap(),0,component);
6140 if (!ACTION_VerifyComponentForAction(package, component_index,
6141 INSTALLSTATE_LOCAL))
6143 TRACE("Skipping ini file due to disabled component\n");
6144 msiobj_release(&row->hdr);
6146 package->components[component_index].Action =
6147 package->components[component_index].Installed;
6152 package->components[component_index].Action = INSTALLSTATE_LOCAL;
6154 identifier = load_dynamic_stringW(row,1);
6155 filename = load_dynamic_stringW(row,2);
6156 dirproperty = load_dynamic_stringW(row,3);
6157 section = load_dynamic_stringW(row,4);
6158 key = load_dynamic_stringW(row,5);
6159 value = load_dynamic_stringW(row,6);
6160 action = MSI_RecordGetInteger(row,7);
6162 deformat_string(package,section,&deformated_section);
6163 deformat_string(package,key,&deformated_key);
6164 deformat_string(package,value,&deformated_value);
6168 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
6170 folder = load_dynamic_property(package,dirproperty,NULL);
6173 folder = load_dynamic_property(package, szWindowsFolder, NULL);
6177 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
6181 fullname = build_directory_name(3, folder, filename, NULL);
6185 TRACE("Adding value %s to section %s in %s\n",
6186 debugstr_w(deformated_key), debugstr_w(deformated_section),
6187 debugstr_w(fullname));
6188 WritePrivateProfileStringW(deformated_section, deformated_key,
6189 deformated_value, fullname);
6191 else if (action == 1)
6194 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
6195 returned, 10, fullname);
6196 if (returned[0] == 0)
6198 TRACE("Adding value %s to section %s in %s\n",
6199 debugstr_w(deformated_key), debugstr_w(deformated_section),
6200 debugstr_w(fullname));
6202 WritePrivateProfileStringW(deformated_section, deformated_key,
6203 deformated_value, fullname);
6206 else if (action == 3)
6208 FIXME("Append to existing section not yet implemented\n");
6211 uirow = MSI_CreateRecord(4);
6212 MSI_RecordSetStringW(uirow,1,identifier);
6213 MSI_RecordSetStringW(uirow,2,deformated_section);
6214 MSI_RecordSetStringW(uirow,3,deformated_key);
6215 MSI_RecordSetStringW(uirow,4,deformated_value);
6216 ui_actiondata(package,szWriteIniValues,uirow);
6217 msiobj_release( &uirow->hdr );
6219 HeapFree(GetProcessHeap(),0,identifier);
6220 HeapFree(GetProcessHeap(),0,fullname);
6221 HeapFree(GetProcessHeap(),0,filename);
6222 HeapFree(GetProcessHeap(),0,key);
6223 HeapFree(GetProcessHeap(),0,value);
6224 HeapFree(GetProcessHeap(),0,section);
6225 HeapFree(GetProcessHeap(),0,dirproperty);
6226 HeapFree(GetProcessHeap(),0,folder);
6227 HeapFree(GetProcessHeap(),0,deformated_key);
6228 HeapFree(GetProcessHeap(),0,deformated_value);
6229 HeapFree(GetProcessHeap(),0,deformated_section);
6230 msiobj_release(&row->hdr);
6232 MSI_ViewClose(view);
6233 msiobj_release(&view->hdr);
6237 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
6241 MSIRECORD * row = 0;
6242 static const WCHAR ExecSeqQuery[] =
6243 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6244 '`','S','e','l','f','R','e','g','`',0};
6246 static const WCHAR ExeStr[] =
6247 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
6248 static const WCHAR close[] = {'\"',0};
6250 PROCESS_INFORMATION info;
6253 memset(&si,0,sizeof(STARTUPINFOW));
6255 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6256 if (rc != ERROR_SUCCESS)
6258 TRACE("no SelfReg table\n");
6259 return ERROR_SUCCESS;
6262 rc = MSI_ViewExecute(view, 0);
6263 if (rc != ERROR_SUCCESS)
6265 MSI_ViewClose(view);
6266 msiobj_release(&view->hdr);
6276 rc = MSI_ViewFetch(view,&row);
6277 if (rc != ERROR_SUCCESS)
6283 filename = load_dynamic_stringW(row,1);
6284 index = get_loaded_file(package,filename);
6288 ERR("Unable to find file id %s\n",debugstr_w(filename));
6289 HeapFree(GetProcessHeap(),0,filename);
6290 msiobj_release(&row->hdr);
6293 HeapFree(GetProcessHeap(),0,filename);
6295 len = strlenW(ExeStr);
6296 len += strlenW(package->files[index].TargetPath);
6299 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
6300 strcpyW(filename,ExeStr);
6301 strcatW(filename,package->files[index].TargetPath);
6302 strcatW(filename,close);
6304 TRACE("Registering %s\n",debugstr_w(filename));
6305 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
6306 c_colon, &si, &info);
6309 msi_dialog_check_messages(info.hProcess);
6311 HeapFree(GetProcessHeap(),0,filename);
6312 msiobj_release(&row->hdr);
6314 MSI_ViewClose(view);
6315 msiobj_release(&view->hdr);
6319 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
6328 return ERROR_INVALID_HANDLE;
6330 productcode = load_dynamic_property(package,szProductCode,&rc);
6334 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
6335 if (rc != ERROR_SUCCESS)
6338 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
6339 if (rc != ERROR_SUCCESS)
6342 /* here the guids are base 85 encoded */
6343 for (i = 0; i < package->loaded_features; i++)
6349 BOOL absent = FALSE;
6351 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL) &&
6352 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_SOURCE) &&
6353 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_ADVERTISED))
6356 size = package->features[i].ComponentCount*21;
6358 if (package->features[i].Feature_Parent[0])
6359 size += strlenW(package->features[i].Feature_Parent)+2;
6361 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
6364 for (j = 0; j < package->features[i].ComponentCount; j++)
6367 memset(buf,0,sizeof(buf));
6368 if (package->components
6369 [package->features[i].Components[j]].ComponentId[0]!=0)
6371 TRACE("From %s\n",debugstr_w(package->components
6372 [package->features[i].Components[j]].ComponentId));
6373 CLSIDFromString(package->components
6374 [package->features[i].Components[j]].ComponentId,
6376 encode_base85_guid(&clsid,buf);
6377 TRACE("to %s\n",debugstr_w(buf));
6381 if (package->features[i].Feature_Parent[0])
6383 static const WCHAR sep[] = {'\2',0};
6385 strcatW(data,package->features[i].Feature_Parent);
6388 size = (strlenW(data)+1)*sizeof(WCHAR);
6389 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
6391 HeapFree(GetProcessHeap(),0,data);
6395 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
6396 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6397 (LPSTR)package->features[i].Feature_Parent,size);
6401 size = (strlenW(package->features[i].Feature_Parent)+2)*
6403 data = HeapAlloc(GetProcessHeap(),0,size);
6405 strcpyW(&data[1],package->features[i].Feature_Parent);
6406 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6408 HeapFree(GetProcessHeap(),0,data);
6415 HeapFree(GetProcessHeap(), 0, productcode);
6419 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
6426 static WCHAR szNONE[] = {0};
6427 static const WCHAR szWindowsInstaler[] =
6428 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
6429 static const WCHAR szPropKeys[][80] =
6431 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
6432 {'A','R','P','C','O','N','T','A','C','T',0},
6433 {'A','R','P','C','O','M','M','E','N','T','S',0},
6434 {'P','r','o','d','u','c','t','N','a','m','e',0},
6435 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
6436 {'A','R','P','H','E','L','P','L','I','N','K',0},
6437 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
6438 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
6439 {'S','o','u','r','c','e','D','i','r',0},
6440 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
6441 {'A','R','P','R','E','A','D','M','E',0},
6442 {'A','R','P','S','I','Z','E',0},
6443 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
6444 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
6448 static const WCHAR szRegKeys[][80] =
6450 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
6451 {'C','o','n','t','a','c','t',0},
6452 {'C','o','m','m','e','n','t','s',0},
6453 {'D','i','s','p','l','a','y','N','a','m','e',0},
6454 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
6455 {'H','e','l','p','L','i','n','k',0},
6456 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
6457 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
6458 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
6459 {'P','u','b','l','i','s','h','e','r',0},
6460 {'R','e','a','d','m','e',0},
6461 {'S','i','z','e',0},
6462 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
6463 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
6467 static const WCHAR installerPathFmt[] = {
6469 'I','n','s','t','a','l','l','e','r','\\',0};
6470 static const WCHAR fmt[] = {
6472 'I','n','s','t','a','l','l','e','r','\\',
6473 '%','x','.','m','s','i',0};
6474 static const WCHAR szLocalPackage[]=
6475 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
6476 static const WCHAR szUpgradeCode[] =
6477 {'U','p','g','r','a','d','e','C','o','d','e',0};
6478 LPWSTR upgrade_code;
6479 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
6483 return ERROR_INVALID_HANDLE;
6485 productcode = load_dynamic_property(package,szProductCode,&rc);
6489 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
6490 if (rc != ERROR_SUCCESS)
6493 /* dump all the info i can grab */
6494 FIXME("Flesh out more information \n");
6497 while (szPropKeys[i][0]!=0)
6499 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
6500 if (rc != ERROR_SUCCESS)
6502 size = strlenW(buffer)*sizeof(WCHAR);
6503 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
6509 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
6511 /* copy the package locally */
6512 num = GetTickCount() & 0xffff;
6516 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
6517 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
6521 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
6522 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
6523 if (handle != INVALID_HANDLE_VALUE)
6525 CloseHandle(handle);
6528 if (GetLastError() != ERROR_FILE_EXISTS &&
6529 GetLastError() != ERROR_SHARING_VIOLATION)
6531 if (!(++num & 0xffff)) num = 1;
6532 sprintfW(packagefile,fmt,num);
6533 } while (num != start);
6535 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
6536 create_full_pathW(path);
6537 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
6538 if (!CopyFileW(package->PackagePath,packagefile,FALSE))
6539 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
6540 debugstr_w(package->PackagePath), debugstr_w(packagefile),
6542 size = strlenW(packagefile)*sizeof(WCHAR);
6543 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
6545 /* Handle Upgrade Codes */
6546 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
6551 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
6552 squash_guid(productcode,squashed);
6553 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
6555 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
6556 squash_guid(productcode,squashed);
6557 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
6560 HeapFree(GetProcessHeap(),0,upgrade_code);
6564 HeapFree(GetProcessHeap(),0,productcode);
6567 return ERROR_SUCCESS;
6570 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
6575 return ERROR_INVALID_HANDLE;
6577 rc = execute_script(package,INSTALL_SCRIPT);
6582 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
6587 return ERROR_INVALID_HANDLE;
6589 /* turn off scheduleing */
6590 package->script->CurrentlyScripting= FALSE;
6592 /* first do the same as an InstallExecute */
6593 rc = ACTION_InstallExecute(package);
6594 if (rc != ERROR_SUCCESS)
6597 /* then handle Commit Actions */
6598 rc = execute_script(package,COMMIT_SCRIPT);
6603 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
6605 static const WCHAR RunOnce[] = {
6606 'S','o','f','t','w','a','r','e','\\',
6607 'M','i','c','r','o','s','o','f','t','\\',
6608 'W','i','n','d','o','w','s','\\',
6609 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6610 'R','u','n','O','n','c','e',0};
6611 static const WCHAR InstallRunOnce[] = {
6612 'S','o','f','t','w','a','r','e','\\',
6613 'M','i','c','r','o','s','o','f','t','\\',
6614 'W','i','n','d','o','w','s','\\',
6615 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6616 'I','n','s','t','a','l','l','e','r','\\',
6617 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
6619 static const WCHAR msiexec_fmt[] = {
6621 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
6622 '\"','%','s','\"',0};
6623 static const WCHAR install_fmt[] = {
6624 '/','I',' ','\"','%','s','\"',' ',
6625 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
6626 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
6627 WCHAR buffer[256], sysdir[MAX_PATH];
6630 WCHAR squished_pc[100];
6633 static const WCHAR szLUS[] = {
6634 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
6635 static const WCHAR szSourceList[] = {
6636 'S','o','u','r','c','e','L','i','s','t',0};
6637 static const WCHAR szPackageName[] = {
6638 'P','a','c','k','a','g','e','N','a','m','e',0};
6641 return ERROR_INVALID_HANDLE;
6643 productcode = load_dynamic_property(package,szProductCode,&rc);
6647 squash_guid(productcode,squished_pc);
6649 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
6650 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
6651 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
6654 size = strlenW(buffer)*sizeof(WCHAR);
6655 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6658 TRACE("Reboot command %s\n",debugstr_w(buffer));
6660 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
6661 sprintfW(buffer,install_fmt,productcode,squished_pc);
6663 size = strlenW(buffer)*sizeof(WCHAR);
6664 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6667 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6668 if (rc == ERROR_SUCCESS)
6672 RegCreateKeyW(hukey, szSourceList, &hukey2);
6673 buf = load_dynamic_property(package,cszSourceDir,NULL);
6674 size = strlenW(buf)*sizeof(WCHAR);
6675 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
6676 HeapFree(GetProcessHeap(),0,buf);
6678 buf = strrchrW(package->PackagePath,'\\');
6682 size = strlenW(buf)*sizeof(WCHAR);
6683 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
6686 RegCloseKey(hukey2);
6688 HeapFree(GetProcessHeap(),0,productcode);
6690 return ERROR_INSTALL_SUSPEND;
6693 UINT ACTION_ResolveSource(MSIPACKAGE* package)
6696 * we are currently doing what should be done here in the top level Install
6697 * however for Adminastrative and uninstalls this step will be needed
6699 return ERROR_SUCCESS;
6702 static LPWSTR create_component_advertise_string(MSIPACKAGE* package,
6703 MSICOMPONENT* component, LPCWSTR feature)
6705 LPWSTR productid=NULL;
6707 WCHAR productid_85[21];
6708 WCHAR component_85[21];
6710 * I have a fair bit of confusion as to when a < is used and when a > is
6711 * used. I do not think i have it right...
6713 * Ok it appears that the > is used if there is a guid for the compoenent
6714 * and the < is used if not.
6716 static WCHAR fmt1[] = {'%','s','%','s','<',0,0};
6717 static WCHAR fmt2[] = {'%','s','%','s','>','%','s',0,0};
6718 LPWSTR output = NULL;
6721 memset(productid_85,0,sizeof(productid_85));
6722 memset(component_85,0,sizeof(component_85));
6724 productid = load_dynamic_property(package,szProductCode,NULL);
6725 CLSIDFromString(productid, &clsid);
6727 encode_base85_guid(&clsid,productid_85);
6729 CLSIDFromString(component->ComponentId, &clsid);
6730 encode_base85_guid(&clsid,component_85);
6732 TRACE("Doing something with this... %s %s %s\n",
6733 debugstr_w(productid_85), debugstr_w(feature),
6734 debugstr_w(component_85));
6736 sz = lstrlenW(productid_85) + lstrlenW(feature);
6738 sz += lstrlenW(component_85);
6741 sz *= sizeof(WCHAR);
6743 output = HeapAlloc(GetProcessHeap(),0,sz);
6744 memset(output,0,sz);
6747 sprintfW(output,fmt2,productid_85,feature,component_85);
6749 sprintfW(output,fmt1,productid_85,feature);
6751 HeapFree(GetProcessHeap(),0,productid);
6756 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
6757 MSICOMPONENT* component, MSIEXTENSION* extension,
6758 MSIVERB* verb, INT* Sequence )
6762 static const WCHAR szShell[] = {'s','h','e','l','l',0};
6763 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
6764 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
6765 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
6770 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
6772 TRACE("Making Key %s\n",debugstr_w(keyname));
6773 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6774 size = strlenW(component->FullKeypath);
6776 size += strlenW(verb->Argument);
6779 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6781 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
6783 sprintfW(command, fmt2, component->FullKeypath);
6785 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)command, (strlenW(command)+1)*
6787 HeapFree(GetProcessHeap(),0,command);
6789 advertise = create_component_advertise_string(package, component,
6790 package->features[extension->FeatureIndex].Feature);
6792 size = strlenW(advertise);
6795 size += strlenW(verb->Argument);
6798 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6799 memset(command,0,size*sizeof(WCHAR));
6801 strcpyW(command,advertise);
6804 static const WCHAR szSpace[] = {' ',0};
6805 strcatW(command,szSpace);
6806 strcatW(command,verb->Argument);
6809 RegSetValueExW(key, szCommand, 0, REG_MULTI_SZ, (LPBYTE)command,
6810 (strlenW(command)+2)*sizeof(WCHAR));
6813 HeapFree(GetProcessHeap(),0,keyname);
6814 HeapFree(GetProcessHeap(),0,advertise);
6815 HeapFree(GetProcessHeap(),0,command);
6819 keyname = build_directory_name(3, progid, szShell, verb->Verb);
6820 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6821 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Command,
6822 (strlenW(verb->Command)+1) *sizeof(WCHAR));
6824 HeapFree(GetProcessHeap(),0,keyname);
6827 if (verb->Sequence != MSI_NULL_INTEGER)
6829 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
6831 *Sequence = verb->Sequence;
6832 keyname = build_directory_name(2, progid, szShell);
6833 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6834 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Verb,
6835 (strlenW(verb->Verb)+1) *sizeof(WCHAR));
6837 HeapFree(GetProcessHeap(),0,keyname);
6840 return ERROR_SUCCESS;
6843 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
6845 static const WCHAR szContentType[] =
6846 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
6850 BOOL install_on_demand = TRUE;
6853 return ERROR_INVALID_HANDLE;
6855 load_classes_and_such(package);
6857 /* We need to set install_on_demand based on if the shell handles advertised
6858 * shortcuts and the like. Because Mike McCormack is working on this i am
6859 * going to default to TRUE
6862 for (i = 0; i < package->loaded_extensions; i++)
6864 WCHAR extension[257];
6867 index = package->extensions[i].ComponentIndex;
6868 f_index = package->extensions[i].FeatureIndex;
6874 * yes. MSDN says that these are based on _Feature_ not on
6875 * Component. So verify the feature is to be installed
6877 if ((!ACTION_VerifyFeatureForAction(package, f_index,
6878 INSTALLSTATE_LOCAL)) &&
6879 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
6880 f_index, INSTALLSTATE_ADVERTISED)))
6882 TRACE("Skipping extension %s reg due to disabled feature %s\n",
6883 debugstr_w(package->extensions[i].Extension),
6884 debugstr_w(package->features[f_index].Feature));
6889 TRACE("Registering extension %s index %i\n",
6890 debugstr_w(package->extensions[i].Extension), i);
6892 package->extensions[i].Installed = TRUE;
6894 /* this is only registered if the extension has at least 1 verb
6897 if (package->extensions[i].ProgIDIndex >= 0 &&
6898 package->extensions[i].VerbCount > 0)
6899 mark_progid_for_install(package, package->extensions[i].ProgIDIndex);
6901 if (package->extensions[i].MIMEIndex >= 0)
6902 mark_mime_for_install(package, package->extensions[i].MIMEIndex);
6906 strcatW(extension,package->extensions[i].Extension);
6908 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
6910 if (package->extensions[i].MIMEIndex >= 0)
6912 RegSetValueExW(hkey,szContentType,0,REG_SZ,
6913 (LPVOID)package->mimes[package->extensions[i].
6914 MIMEIndex].ContentType,
6915 (strlenW(package->mimes[package->extensions[i].
6916 MIMEIndex].ContentType)+1)*sizeof(WCHAR));
6919 if (package->extensions[i].ProgIDIndex >= 0 ||
6920 package->extensions[i].ProgIDText)
6922 static const WCHAR szSN[] =
6923 {'\\','S','h','e','l','l','N','e','w',0};
6928 INT Sequence = MSI_NULL_INTEGER;
6930 if (package->extensions[i].ProgIDIndex >= 0)
6931 progid = package->progids[package->extensions[i].
6932 ProgIDIndex].ProgID;
6934 progid = package->extensions[i].ProgIDText;
6936 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
6937 (strlenW(progid)+1)*sizeof(WCHAR));
6939 newkey = HeapAlloc(GetProcessHeap(),0,
6940 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
6942 strcpyW(newkey,progid);
6943 strcatW(newkey,szSN);
6944 RegCreateKeyW(hkey,newkey,&hkey2);
6947 HeapFree(GetProcessHeap(),0,newkey);
6949 /* do all the verbs */
6950 for (v = 0; v < package->extensions[i].VerbCount; v++)
6951 register_verb(package, progid,
6952 &package->components[index],
6953 &package->extensions[i],
6954 &package->verbs[package->extensions[i].Verbs[v]],
6960 uirow = MSI_CreateRecord(1);
6961 MSI_RecordSetStringW(uirow,1,package->extensions[i].Extension);
6962 ui_actiondata(package,szRegisterExtensionInfo,uirow);
6963 msiobj_release(&uirow->hdr);
6966 return ERROR_SUCCESS;
6969 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
6971 static const WCHAR szExten[] =
6972 {'E','x','t','e','n','s','i','o','n',0 };
6978 return ERROR_INVALID_HANDLE;
6980 load_classes_and_such(package);
6982 for (i = 0; i < package->loaded_mimes; i++)
6984 WCHAR extension[257];
6987 static const WCHAR fmt[] =
6988 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
6989 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
6993 * check if the MIME is to be installed. Either as requesed by an
6994 * extension or Class
6996 package->mimes[i].InstallMe = ((package->mimes[i].InstallMe) ||
6997 (package->mimes[i].ClassIndex >= 0 &&
6998 package->classes[package->mimes[i].ClassIndex].Installed) ||
6999 (package->mimes[i].ExtensionIndex >=0 &&
7000 package->extensions[package->mimes[i].ExtensionIndex].Installed));
7002 if (!package->mimes[i].InstallMe)
7004 TRACE("MIME %s not scheduled to be installed\n",
7005 debugstr_w(package->mimes[i].ContentType));
7009 mime = package->mimes[i].ContentType;
7010 exten = package->extensions[package->mimes[i].ExtensionIndex].Extension;
7013 strcatW(extension,exten);
7015 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
7017 sprintfW(key,fmt,mime);
7018 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
7019 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
7020 (strlenW(extension)+1)*sizeof(WCHAR));
7022 HeapFree(GetProcessHeap(),0,key);
7024 if (package->mimes[i].CLSID[0])
7026 FIXME("Handle non null for field 3\n");
7031 uirow = MSI_CreateRecord(2);
7032 MSI_RecordSetStringW(uirow,1,package->mimes[i].ContentType);
7033 MSI_RecordSetStringW(uirow,2,exten);
7034 ui_actiondata(package,szRegisterMIMEInfo,uirow);
7035 msiobj_release(&uirow->hdr);
7038 return ERROR_SUCCESS;
7041 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
7043 static const WCHAR szProductID[]=
7044 {'P','r','o','d','u','c','t','I','D',0};
7052 static const WCHAR szPropKeys[][80] =
7054 {'P','r','o','d','u','c','t','I','D',0},
7055 {'U','S','E','R','N','A','M','E',0},
7056 {'C','O','M','P','A','N','Y','N','A','M','E',0},
7060 static const WCHAR szRegKeys[][80] =
7062 {'P','r','o','d','u','c','t','I','D',0},
7063 {'R','e','g','O','w','n','e','r',0},
7064 {'R','e','g','C','o','m','p','a','n','y',0},
7069 return ERROR_INVALID_HANDLE;
7071 productid = load_dynamic_property(package,szProductID,&rc);
7073 return ERROR_SUCCESS;
7075 productcode = load_dynamic_property(package,szProductCode,&rc);
7079 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
7080 if (rc != ERROR_SUCCESS)
7084 while (szPropKeys[i][0]!=0)
7086 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
7087 if (rc == ERROR_SUCCESS)
7089 size = strlenW(buffer)*sizeof(WCHAR);
7090 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
7093 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
7098 HeapFree(GetProcessHeap(),0,productcode);
7099 HeapFree(GetProcessHeap(),0,productid);
7102 return ERROR_SUCCESS;
7106 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
7109 rc = ACTION_ProcessExecSequence(package,FALSE);
7115 * Code based off of code located here
7116 * http://www.codeproject.com/gdi/fontnamefromfile.asp
7118 * Using string index 4 (full font name) instead of 1 (family name)
7120 static LPWSTR load_ttfname_from(LPCWSTR filename)
7126 typedef struct _tagTT_OFFSET_TABLE{
7127 USHORT uMajorVersion;
7128 USHORT uMinorVersion;
7129 USHORT uNumOfTables;
7130 USHORT uSearchRange;
7131 USHORT uEntrySelector;
7135 typedef struct _tagTT_TABLE_DIRECTORY{
7136 char szTag[4]; /* table name */
7137 ULONG uCheckSum; /* Check sum */
7138 ULONG uOffset; /* Offset from beginning of file */
7139 ULONG uLength; /* length of the table in bytes */
7140 }TT_TABLE_DIRECTORY;
7142 typedef struct _tagTT_NAME_TABLE_HEADER{
7143 USHORT uFSelector; /* format selector. Always 0 */
7144 USHORT uNRCount; /* Name Records count */
7145 USHORT uStorageOffset; /* Offset for strings storage,
7146 * from start of the table */
7147 }TT_NAME_TABLE_HEADER;
7149 typedef struct _tagTT_NAME_RECORD{
7154 USHORT uStringLength;
7155 USHORT uStringOffset; /* from start of storage area */
7158 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
7159 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
7161 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
7162 FILE_ATTRIBUTE_NORMAL, 0 );
7163 if (handle != INVALID_HANDLE_VALUE)
7165 TT_TABLE_DIRECTORY tblDir;
7166 BOOL bFound = FALSE;
7167 TT_OFFSET_TABLE ttOffsetTable;
7169 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
7170 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
7171 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
7172 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
7174 if (ttOffsetTable.uMajorVersion != 1 ||
7175 ttOffsetTable.uMinorVersion != 0)
7178 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
7180 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
7181 if (strncmp(tblDir.szTag,"name",4)==0)
7184 tblDir.uLength = SWAPLONG(tblDir.uLength);
7185 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
7192 TT_NAME_TABLE_HEADER ttNTHeader;
7193 TT_NAME_RECORD ttRecord;
7195 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
7196 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
7199 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
7200 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
7202 for(i=0; i<ttNTHeader.uNRCount; i++)
7204 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
7205 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
7206 /* 4 is the Full Font Name */
7207 if(ttRecord.uNameID == 4)
7211 static LPCSTR tt = " (TrueType)";
7213 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
7214 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
7215 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
7216 SetFilePointer(handle, tblDir.uOffset +
7217 ttRecord.uStringOffset +
7218 ttNTHeader.uStorageOffset,
7220 buf = HeapAlloc(GetProcessHeap(), 0,
7221 ttRecord.uStringLength + 1 + strlen(tt));
7222 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
7223 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
7224 if (strlen(buf) > 0)
7227 ret = strdupAtoW(buf);
7228 HeapFree(GetProcessHeap(),0,buf);
7232 HeapFree(GetProcessHeap(),0,buf);
7233 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
7237 CloseHandle(handle);
7240 ERR("Unable to open font file %s\n", debugstr_w(filename));
7242 TRACE("Returning fontname %s\n",debugstr_w(ret));
7246 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
7250 MSIRECORD * row = 0;
7251 static const WCHAR ExecSeqQuery[] =
7252 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7253 '`','F','o','n','t','`',0};
7254 static const WCHAR regfont1[] =
7255 {'S','o','f','t','w','a','r','e','\\',
7256 'M','i','c','r','o','s','o','f','t','\\',
7257 'W','i','n','d','o','w','s',' ','N','T','\\',
7258 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7259 'F','o','n','t','s',0};
7260 static const WCHAR regfont2[] =
7261 {'S','o','f','t','w','a','r','e','\\',
7262 'M','i','c','r','o','s','o','f','t','\\',
7263 'W','i','n','d','o','w','s','\\',
7264 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7265 'F','o','n','t','s',0};
7269 TRACE("%p\n", package);
7271 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7272 if (rc != ERROR_SUCCESS)
7274 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
7275 return ERROR_SUCCESS;
7278 rc = MSI_ViewExecute(view, 0);
7279 if (rc != ERROR_SUCCESS)
7281 MSI_ViewClose(view);
7282 msiobj_release(&view->hdr);
7283 TRACE("MSI_ViewExecute returned %d\n", rc);
7284 return ERROR_SUCCESS;
7287 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
7288 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
7297 rc = MSI_ViewFetch(view,&row);
7298 if (rc != ERROR_SUCCESS)
7304 file = load_dynamic_stringW(row,1);
7305 index = get_loaded_file(package,file);
7308 ERR("Unable to load file\n");
7309 HeapFree(GetProcessHeap(),0,file);
7313 /* check to make sure that component is installed */
7314 if (!ACTION_VerifyComponentForAction(package,
7315 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
7317 TRACE("Skipping: Component not scheduled for install\n");
7318 HeapFree(GetProcessHeap(),0,file);
7320 msiobj_release(&row->hdr);
7325 if (MSI_RecordIsNull(row,2))
7326 name = load_ttfname_from(package->files[index].TargetPath);
7328 name = load_dynamic_stringW(row,2);
7332 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
7333 RegSetValueExW(hkey1,name,0,REG_SZ,
7334 (LPBYTE)package->files[index].FileName,size);
7335 RegSetValueExW(hkey2,name,0,REG_SZ,
7336 (LPBYTE)package->files[index].FileName,size);
7339 HeapFree(GetProcessHeap(),0,file);
7340 HeapFree(GetProcessHeap(),0,name);
7341 msiobj_release(&row->hdr);
7343 MSI_ViewClose(view);
7344 msiobj_release(&view->hdr);
7349 TRACE("returning %d\n", rc);
7353 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
7355 MSIPACKAGE *package = (MSIPACKAGE*)param;
7356 LPWSTR compgroupid=NULL;
7357 LPWSTR feature=NULL;
7359 LPWSTR qualifier = NULL;
7360 LPWSTR component = NULL;
7361 LPWSTR advertise = NULL;
7362 LPWSTR output = NULL;
7364 UINT rc = ERROR_SUCCESS;
7368 component = load_dynamic_stringW(rec,3);
7369 index = get_loaded_component(package,component);
7371 if (!ACTION_VerifyComponentForAction(package, index,
7372 INSTALLSTATE_LOCAL) &&
7373 !ACTION_VerifyComponentForAction(package, index,
7374 INSTALLSTATE_SOURCE) &&
7375 !ACTION_VerifyComponentForAction(package, index,
7376 INSTALLSTATE_ADVERTISED))
7378 TRACE("Skipping: Component %s not scheduled for install\n",
7379 debugstr_w(component));
7381 HeapFree(GetProcessHeap(),0,component);
7382 return ERROR_SUCCESS;
7385 compgroupid = load_dynamic_stringW(rec,1);
7387 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
7388 if (rc != ERROR_SUCCESS)
7391 text = load_dynamic_stringW(rec,4);
7392 qualifier = load_dynamic_stringW(rec,2);
7393 feature = load_dynamic_stringW(rec,5);
7395 advertise = create_component_advertise_string(package,
7396 &package->components[index], feature);
7398 sz = strlenW(advertise);
7401 sz += lstrlenW(text);
7404 sz *= sizeof(WCHAR);
7406 output = HeapAlloc(GetProcessHeap(),0,sz);
7407 memset(output,0,sz);
7408 strcpyW(output,advertise);
7411 strcatW(output,text);
7413 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
7414 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
7418 HeapFree(GetProcessHeap(),0,output);
7419 HeapFree(GetProcessHeap(),0,compgroupid);
7420 HeapFree(GetProcessHeap(),0,component);
7421 HeapFree(GetProcessHeap(),0,feature);
7422 HeapFree(GetProcessHeap(),0,text);
7423 HeapFree(GetProcessHeap(),0,qualifier);
7429 * At present I am ignorning the advertised components part of this and only
7430 * focusing on the qualified component sets
7432 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
7436 static const WCHAR ExecSeqQuery[] =
7437 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7438 '`','P','u','b','l','i','s','h',
7439 'C','o','m','p','o','n','e','n','t','`',0};
7441 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7442 if (rc != ERROR_SUCCESS)
7443 return ERROR_SUCCESS;
7445 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
7446 msiobj_release(&view->hdr);
7451 /* Msi functions that seem appropriate here */
7453 /***********************************************************************
7454 * MsiDoActionA (MSI.@)
7456 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
7461 TRACE(" exteral attempt at action %s\n",szAction);
7464 return ERROR_FUNCTION_FAILED;
7466 return ERROR_FUNCTION_FAILED;
7468 szwAction = strdupAtoW(szAction);
7471 return ERROR_FUNCTION_FAILED;
7474 rc = MsiDoActionW(hInstall, szwAction);
7475 HeapFree(GetProcessHeap(),0,szwAction);
7479 /***********************************************************************
7480 * MsiDoActionW (MSI.@)
7482 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
7484 MSIPACKAGE *package;
7485 UINT ret = ERROR_INVALID_HANDLE;
7487 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
7489 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7492 ret = ACTION_PerformUIAction(package,szAction);
7493 msiobj_release( &package->hdr );
7498 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
7499 LPSTR szPathBuf, DWORD* pcchPathBuf)
7505 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7508 return ERROR_FUNCTION_FAILED;
7510 return ERROR_FUNCTION_FAILED;
7512 szwFolder = strdupAtoW(szFolder);
7515 return ERROR_FUNCTION_FAILED;
7517 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7519 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7521 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7522 *pcchPathBuf, NULL, NULL );
7524 HeapFree(GetProcessHeap(),0,szwFolder);
7525 HeapFree(GetProcessHeap(),0,szwPathBuf);
7530 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7531 szPathBuf, DWORD* pcchPathBuf)
7534 UINT rc = ERROR_FUNCTION_FAILED;
7535 MSIPACKAGE *package;
7537 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7539 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7541 return ERROR_INVALID_HANDLE;
7542 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
7543 msiobj_release( &package->hdr );
7545 if (path && (strlenW(path) > *pcchPathBuf))
7547 *pcchPathBuf = strlenW(path)+1;
7548 rc = ERROR_MORE_DATA;
7552 *pcchPathBuf = strlenW(path)+1;
7553 strcpyW(szPathBuf,path);
7554 TRACE("Returning Path %s\n",debugstr_w(path));
7557 HeapFree(GetProcessHeap(),0,path);
7563 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
7564 LPSTR szPathBuf, DWORD* pcchPathBuf)
7570 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7573 return ERROR_FUNCTION_FAILED;
7575 return ERROR_FUNCTION_FAILED;
7577 szwFolder = strdupAtoW(szFolder);
7579 return ERROR_FUNCTION_FAILED;
7581 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7583 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7585 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7586 *pcchPathBuf, NULL, NULL );
7588 HeapFree(GetProcessHeap(),0,szwFolder);
7589 HeapFree(GetProcessHeap(),0,szwPathBuf);
7594 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7595 szPathBuf, DWORD* pcchPathBuf)
7598 UINT rc = ERROR_FUNCTION_FAILED;
7599 MSIPACKAGE *package;
7601 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7603 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7605 return ERROR_INVALID_HANDLE;
7606 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
7607 msiobj_release( &package->hdr );
7609 if (path && strlenW(path) > *pcchPathBuf)
7611 *pcchPathBuf = strlenW(path)+1;
7612 rc = ERROR_MORE_DATA;
7616 *pcchPathBuf = strlenW(path)+1;
7617 strcpyW(szPathBuf,path);
7618 TRACE("Returning Path %s\n",debugstr_w(path));
7621 HeapFree(GetProcessHeap(),0,path);
7627 /***********************************************************************
7628 * MsiSetTargetPathA (MSI.@)
7630 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
7631 LPCSTR szFolderPath)
7634 LPWSTR szwFolderPath;
7638 return ERROR_FUNCTION_FAILED;
7640 return ERROR_FUNCTION_FAILED;
7642 szwFolder = strdupAtoW(szFolder);
7644 return ERROR_FUNCTION_FAILED;
7646 szwFolderPath = strdupAtoW(szFolderPath);
7649 HeapFree(GetProcessHeap(),0,szwFolder);
7650 return ERROR_FUNCTION_FAILED;
7653 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
7655 HeapFree(GetProcessHeap(),0,szwFolder);
7656 HeapFree(GetProcessHeap(),0,szwFolderPath);
7661 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
7662 LPCWSTR szFolderPath)
7666 LPWSTR path2 = NULL;
7669 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
7672 return ERROR_INVALID_HANDLE;
7674 if (szFolderPath[0]==0)
7675 return ERROR_FUNCTION_FAILED;
7677 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
7678 return ERROR_FUNCTION_FAILED;
7680 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
7683 return ERROR_INVALID_PARAMETER;
7685 HeapFree(GetProcessHeap(),0,folder->Property);
7686 folder->Property = build_directory_name(2, szFolderPath, NULL);
7688 if (lstrcmpiW(path, folder->Property) == 0)
7691 * Resolved Target has not really changed, so just
7692 * set this folder and do not recalculate everything.
7694 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
7695 folder->ResolvedTarget = NULL;
7696 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
7697 HeapFree(GetProcessHeap(),0,path2);
7701 for (i = 0; i < package->loaded_folders; i++)
7703 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
7704 package->folders[i].ResolvedTarget=NULL;
7707 for (i = 0; i < package->loaded_folders; i++)
7709 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
7711 HeapFree(GetProcessHeap(),0,path2);
7714 HeapFree(GetProcessHeap(),0,path);
7716 return ERROR_SUCCESS;
7719 /***********************************************************************
7720 * MsiSetTargetPathW (MSI.@)
7722 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
7723 LPCWSTR szFolderPath)
7725 MSIPACKAGE *package;
7728 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
7730 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7731 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
7732 msiobj_release( &package->hdr );
7736 /***********************************************************************
7737 * MsiGetMode (MSI.@)
7739 * Returns an internal installer state (if it is running in a mode iRunMode)
7742 * hInstall [I] Handle to the installation
7743 * hRunMode [I] Checking run mode
7744 * MSIRUNMODE_ADMIN Administrative mode
7745 * MSIRUNMODE_ADVERTISE Advertisement mode
7746 * MSIRUNMODE_MAINTENANCE Maintenance mode
7747 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
7748 * MSIRUNMODE_LOGENABLED Log file is writing
7749 * MSIRUNMODE_OPERATIONS Operations in progress??
7750 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
7751 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
7752 * MSIRUNMODE_CABINET Files from cabinet are installed
7753 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
7754 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
7755 * MSIRUNMODE_RESERVED11 Reserved
7756 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
7757 * MSIRUNMODE_ZAWENABLED Demand installation is supported
7758 * MSIRUNMODE_RESERVED14 Reserved
7759 * MSIRUNMODE_RESERVED15 Reserved
7760 * MSIRUNMODE_SCHEDULED called from install script
7761 * MSIRUNMODE_ROLLBACK called from rollback script
7762 * MSIRUNMODE_COMMIT called from commit script
7765 * In the state: TRUE
7766 * Not in the state: FALSE
7770 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
7772 FIXME("STUB (iRunMode=%i)\n",iRunMode);
7776 /***********************************************************************
7777 * MsiSetFeatureStateA (MSI.@)
7779 * According to the docs, when this is called it immediately recalculates
7780 * all the component states as well
7782 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
7783 INSTALLSTATE iState)
7785 LPWSTR szwFeature = NULL;
7788 szwFeature = strdupAtoW(szFeature);
7791 return ERROR_FUNCTION_FAILED;
7793 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
7795 HeapFree(GetProcessHeap(),0,szwFeature);
7802 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
7803 INSTALLSTATE iState)
7806 UINT rc = ERROR_SUCCESS;
7808 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7810 index = get_loaded_feature(package,szFeature);
7812 return ERROR_UNKNOWN_FEATURE;
7814 if (iState == INSTALLSTATE_ADVERTISED &&
7815 package->features[index].Attributes &
7816 msidbFeatureAttributesDisallowAdvertise)
7817 return ERROR_FUNCTION_FAILED;
7819 package->features[index].ActionRequest= iState;
7820 package->features[index].Action= iState;
7822 ACTION_UpdateComponentStates(package,szFeature);
7824 /* update all the features that are children of this feature */
7825 for (i = 0; i < package->loaded_features; i++)
7827 if (strcmpW(szFeature, package->features[i].Feature_Parent) == 0)
7828 MSI_SetFeatureStateW(package, package->features[i].Feature, iState);
7834 /***********************************************************************
7835 * MsiSetFeatureStateW (MSI.@)
7837 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
7838 INSTALLSTATE iState)
7840 MSIPACKAGE* package;
7841 UINT rc = ERROR_SUCCESS;
7843 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7845 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7847 return ERROR_INVALID_HANDLE;
7849 rc = MSI_SetFeatureStateW(package,szFeature,iState);
7851 msiobj_release( &package->hdr );
7855 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
7856 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7858 LPWSTR szwFeature = NULL;
7861 szwFeature = strdupAtoW(szFeature);
7863 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
7865 HeapFree( GetProcessHeap(), 0 , szwFeature);
7870 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
7871 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7875 index = get_loaded_feature(package,szFeature);
7877 return ERROR_UNKNOWN_FEATURE;
7880 *piInstalled = package->features[index].Installed;
7883 *piAction = package->features[index].Action;
7885 TRACE("returning %i %i\n",*piInstalled,*piAction);
7887 return ERROR_SUCCESS;
7890 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
7891 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7893 MSIPACKAGE* package;
7896 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
7899 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7901 return ERROR_INVALID_HANDLE;
7902 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
7903 msiobj_release( &package->hdr );
7907 /***********************************************************************
7908 * MsiGetComponentStateA (MSI.@)
7910 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
7911 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7913 LPWSTR szwComponent= NULL;
7916 szwComponent= strdupAtoW(szComponent);
7918 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
7920 HeapFree( GetProcessHeap(), 0 , szwComponent);
7925 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
7926 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7930 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
7933 index = get_loaded_component(package,szComponent);
7935 return ERROR_UNKNOWN_COMPONENT;
7938 *piInstalled = package->components[index].Installed;
7941 *piAction = package->components[index].Action;
7943 TRACE("states (%i, %i)\n",
7944 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
7946 return ERROR_SUCCESS;
7949 /***********************************************************************
7950 * MsiGetComponentStateW (MSI.@)
7952 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
7953 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7955 MSIPACKAGE* package;
7958 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
7959 piInstalled, piAction);
7961 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7963 return ERROR_INVALID_HANDLE;
7964 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
7965 msiobj_release( &package->hdr );