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, ACTION_FindRelatedProducts },
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 DWORD build_version_dword(LPCWSTR version_string)
578 DWORD rc = 0x00000000;
581 ptr1 = version_string;
590 ptr1 = strchrW(ptr1,'.');
600 ptr1 = strchrW(ptr1,'.');
610 rc = MAKELONG(build,MAKEWORD(minor,major));
611 TRACE("%s -> 0x%lx\n",debugstr_w(version_string),rc);
615 /* Called when the package is being closed */
616 void ACTION_free_package_structures( MSIPACKAGE* package)
620 TRACE("Freeing package action data\n");
622 remove_tracked_tempfiles(package);
624 /* No dynamic buffers in features */
625 if (package->features && package->loaded_features > 0)
626 HeapFree(GetProcessHeap(),0,package->features);
628 for (i = 0; i < package->loaded_folders; i++)
630 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
631 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
632 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
633 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
634 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
635 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
637 if (package->folders && package->loaded_folders > 0)
638 HeapFree(GetProcessHeap(),0,package->folders);
640 for (i = 0; i < package->loaded_components; i++)
641 HeapFree(GetProcessHeap(),0,package->components[i].FullKeypath);
643 if (package->components && package->loaded_components > 0)
644 HeapFree(GetProcessHeap(),0,package->components);
646 for (i = 0; i < package->loaded_files; i++)
648 HeapFree(GetProcessHeap(),0,package->files[i].File);
649 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
650 HeapFree(GetProcessHeap(),0,package->files[i].ShortName);
651 HeapFree(GetProcessHeap(),0,package->files[i].Version);
652 HeapFree(GetProcessHeap(),0,package->files[i].Language);
653 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
654 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
657 if (package->files && package->loaded_files > 0)
658 HeapFree(GetProcessHeap(),0,package->files);
660 /* clean up extension, progid, class and verb structures */
661 for (i = 0; i < package->loaded_classes; i++)
663 HeapFree(GetProcessHeap(),0,package->classes[i].Description);
664 HeapFree(GetProcessHeap(),0,package->classes[i].FileTypeMask);
665 HeapFree(GetProcessHeap(),0,package->classes[i].IconPath);
666 HeapFree(GetProcessHeap(),0,package->classes[i].DefInprocHandler);
667 HeapFree(GetProcessHeap(),0,package->classes[i].DefInprocHandler32);
668 HeapFree(GetProcessHeap(),0,package->classes[i].Argument);
669 HeapFree(GetProcessHeap(),0,package->classes[i].ProgIDText);
672 if (package->classes && package->loaded_classes > 0)
673 HeapFree(GetProcessHeap(),0,package->classes);
675 for (i = 0; i < package->loaded_extensions; i++)
677 HeapFree(GetProcessHeap(),0,package->extensions[i].ProgIDText);
680 if (package->extensions && package->loaded_extensions > 0)
681 HeapFree(GetProcessHeap(),0,package->extensions);
683 for (i = 0; i < package->loaded_progids; i++)
685 HeapFree(GetProcessHeap(),0,package->progids[i].ProgID);
686 HeapFree(GetProcessHeap(),0,package->progids[i].Description);
687 HeapFree(GetProcessHeap(),0,package->progids[i].IconPath);
690 if (package->progids && package->loaded_progids > 0)
691 HeapFree(GetProcessHeap(),0,package->progids);
693 for (i = 0; i < package->loaded_verbs; i++)
695 HeapFree(GetProcessHeap(),0,package->verbs[i].Verb);
696 HeapFree(GetProcessHeap(),0,package->verbs[i].Command);
697 HeapFree(GetProcessHeap(),0,package->verbs[i].Argument);
700 if (package->verbs && package->loaded_verbs > 0)
701 HeapFree(GetProcessHeap(),0,package->verbs);
703 for (i = 0; i < package->loaded_mimes; i++)
704 HeapFree(GetProcessHeap(),0,package->mimes[i].ContentType);
706 if (package->mimes && package->loaded_mimes > 0)
707 HeapFree(GetProcessHeap(),0,package->mimes);
709 for (i = 0; i < package->loaded_appids; i++)
711 HeapFree(GetProcessHeap(),0,package->appids[i].RemoteServerName);
712 HeapFree(GetProcessHeap(),0,package->appids[i].LocalServer);
713 HeapFree(GetProcessHeap(),0,package->appids[i].ServiceParameters);
714 HeapFree(GetProcessHeap(),0,package->appids[i].DllSurrogate);
717 if (package->appids && package->loaded_appids > 0)
718 HeapFree(GetProcessHeap(),0,package->appids);
722 for (i = 0; i < TOTAL_SCRIPTS; i++)
725 for (j = 0; j < package->script->ActionCount[i]; j++)
726 HeapFree(GetProcessHeap(),0,package->script->Actions[i][j]);
728 HeapFree(GetProcessHeap(),0,package->script->Actions[i]);
730 HeapFree(GetProcessHeap(),0,package->script);
733 HeapFree(GetProcessHeap(),0,package->PackagePath);
735 /* cleanup control event subscriptions */
736 ControlEvent_CleanupSubscriptions(package);
739 static void ce_actiontext(MSIPACKAGE* package, LPCWSTR action)
741 static const WCHAR szActionText[] =
742 {'A','c','t','i','o','n','T','e','x','t',0};
745 row = MSI_CreateRecord(1);
746 MSI_RecordSetStringW(row,1,action);
747 ControlEvent_FireSubscribedEvent(package,szActionText, row);
748 msiobj_release(&row->hdr);
751 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
755 row = MSI_CreateRecord(4);
756 MSI_RecordSetInteger(row,1,a);
757 MSI_RecordSetInteger(row,2,b);
758 MSI_RecordSetInteger(row,3,c);
759 MSI_RecordSetInteger(row,4,d);
760 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
761 msiobj_release(&row->hdr);
763 msi_dialog_check_messages(NULL);
766 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
768 static const WCHAR Query_t[] =
769 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
770 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
771 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
772 ' ','\'','%','s','\'',0};
776 static const WCHAR szActionData[] =
777 {'A','c','t','i','o','n','D','a','t','a',0};
779 if (!package->LastAction || strcmpW(package->LastAction,action))
781 row = MSI_QueryGetRecord(package->db, Query_t, action);
785 if (MSI_RecordIsNull(row,3))
787 msiobj_release(&row->hdr);
791 /* update the cached actionformat */
792 HeapFree(GetProcessHeap(),0,package->ActionFormat);
793 package->ActionFormat = load_dynamic_stringW(row,3);
795 HeapFree(GetProcessHeap(),0,package->LastAction);
796 package->LastAction = strdupW(action);
798 msiobj_release(&row->hdr);
801 MSI_RecordSetStringW(record,0,package->ActionFormat);
803 MSI_FormatRecordW(package,record,message,&size);
805 row = MSI_CreateRecord(1);
806 MSI_RecordSetStringW(row,1,message);
808 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
810 ControlEvent_FireSubscribedEvent(package,szActionData, row);
812 msiobj_release(&row->hdr);
816 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
818 static const WCHAR template_s[]=
819 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
821 static const WCHAR format[] =
822 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
823 static const WCHAR Query_t[] =
824 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
825 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
826 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
827 ' ','\'','%','s','\'',0};
833 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
835 row = MSI_QueryGetRecord( package->db, Query_t, action );
839 ActionText = MSI_RecordGetString(row,2);
841 sprintfW(message,template_s,timet,action,ActionText);
842 msiobj_release(&row->hdr);
844 row = MSI_CreateRecord(1);
845 MSI_RecordSetStringW(row,1,message);
847 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
848 msiobj_release(&row->hdr);
851 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
855 static const WCHAR template_s[]=
856 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
858 static const WCHAR template_e[]=
859 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
860 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
862 static const WCHAR format[] =
863 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
867 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
869 sprintfW(message,template_s,timet,action);
871 sprintfW(message,template_e,timet,action,rc);
873 row = MSI_CreateRecord(1);
874 MSI_RecordSetStringW(row,1,message);
876 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
877 msiobj_release(&row->hdr);
881 * build_directory_name()
883 * This function is to save messing round with directory names
884 * It handles adding backslashes between path segments,
885 * and can add \ at the end of the directory name if told to.
887 * It takes a variable number of arguments.
888 * It always allocates a new string for the result, so make sure
889 * to free the return value when finished with it.
891 * The first arg is the number of path segments that follow.
892 * The arguments following count are a list of path segments.
893 * A path segment may be NULL.
895 * Path segments will be added with a \ separating them.
896 * A \ will not be added after the last segment, however if the
897 * last segment is NULL, then the last character will be a \
900 static LPWSTR build_directory_name(DWORD count, ...)
907 for(i=0; i<count; i++)
909 LPCWSTR str = va_arg(va,LPCWSTR);
911 sz += strlenW(str) + 1;
915 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
919 for(i=0; i<count; i++)
921 LPCWSTR str = va_arg(va,LPCWSTR);
925 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
931 static BOOL ACTION_VerifyComponentForAction(MSIPACKAGE* package, INT index,
934 if (package->components[index].Installed == check)
937 if (package->components[index].ActionRequest == check)
943 static BOOL ACTION_VerifyFeatureForAction(MSIPACKAGE* package, INT index,
946 if (package->features[index].Installed == check)
949 if (package->features[index].ActionRequest == check)
956 /****************************************************
957 * TOP level entry points
958 *****************************************************/
960 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
961 LPCWSTR szCommandLine)
967 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
968 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
969 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
971 MSI_SetPropertyW(package, szAction, szInstall);
973 package->script = HeapAlloc(GetProcessHeap(),0,sizeof(MSISCRIPT));
974 memset(package->script,0,sizeof(MSISCRIPT));
978 LPWSTR p, check, path;
980 package->PackagePath = strdupW(szPackagePath);
981 path = strdupW(szPackagePath);
982 p = strrchrW(path,'\\');
990 HeapFree(GetProcessHeap(),0,path);
991 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
992 GetCurrentDirectoryW(MAX_PATH,path);
996 check = load_dynamic_property(package, cszSourceDir,NULL);
998 MSI_SetPropertyW(package, cszSourceDir, path);
1000 HeapFree(GetProcessHeap(), 0, check);
1002 HeapFree(GetProcessHeap(), 0, path);
1008 ptr = (LPWSTR)szCommandLine;
1015 TRACE("Looking at %s\n",debugstr_w(ptr));
1017 ptr2 = strchrW(ptr,'=');
1023 while (*ptr == ' ') ptr++;
1025 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
1026 memcpy(prop,ptr,len*sizeof(WCHAR));
1032 while (*ptr && (quote || (!quote && *ptr!=' ')))
1045 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
1046 memcpy(val,ptr2,len*sizeof(WCHAR));
1049 if (strlenW(prop) > 0)
1051 TRACE("Found commandline property (%s) = (%s)\n",
1052 debugstr_w(prop), debugstr_w(val));
1053 MSI_SetPropertyW(package,prop,val);
1055 HeapFree(GetProcessHeap(),0,val);
1056 HeapFree(GetProcessHeap(),0,prop);
1063 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
1065 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
1067 rc = ACTION_ProcessUISequence(package);
1069 if (rc == ERROR_SUCCESS)
1070 rc = ACTION_ProcessExecSequence(package,TRUE);
1073 rc = ACTION_ProcessExecSequence(package,FALSE);
1076 rc = ACTION_ProcessExecSequence(package,FALSE);
1080 /* install was halted but should be considered a success */
1084 package->script->CurrentlyScripting= FALSE;
1086 /* process the ending type action */
1087 if (rc == ERROR_SUCCESS)
1088 ACTION_PerformActionSequence(package,-1,ui);
1089 else if (rc == ERROR_INSTALL_USEREXIT)
1090 ACTION_PerformActionSequence(package,-2,ui);
1091 else if (rc == ERROR_INSTALL_SUSPEND)
1092 ACTION_PerformActionSequence(package,-4,ui);
1094 ACTION_PerformActionSequence(package,-3,ui);
1096 /* finish up running custom actions */
1097 ACTION_FinishCustomActions(package);
1102 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
1104 UINT rc = ERROR_SUCCESS;
1105 MSIRECORD * row = 0;
1106 static const WCHAR ExecSeqQuery[] =
1107 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1108 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1109 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1110 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
1112 static const WCHAR UISeqQuery[] =
1113 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1114 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1115 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
1116 ' ', '=',' ','%','i',0};
1119 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
1121 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
1125 LPCWSTR action, cond;
1127 TRACE("Running the actions\n");
1129 /* check conditions */
1130 cond = MSI_RecordGetString(row,2);
1133 /* this is a hack to skip errors in the condition code */
1134 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1138 action = MSI_RecordGetString(row,1);
1141 ERR("failed to fetch action\n");
1142 rc = ERROR_FUNCTION_FAILED;
1147 rc = ACTION_PerformUIAction(package,action);
1149 rc = ACTION_PerformAction(package,action,FALSE);
1151 msiobj_release(&row->hdr);
1159 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1163 static const WCHAR ExecSeqQuery[] =
1164 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1165 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1166 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
1167 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
1168 'O','R','D','E','R',' ', 'B','Y',' ',
1169 '`','S','e','q','u','e','n','c','e','`',0 };
1170 MSIRECORD * row = 0;
1171 static const WCHAR IVQuery[] =
1172 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
1173 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
1174 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
1175 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
1176 ' ','\'', 'I','n','s','t','a','l','l',
1177 'V','a','l','i','d','a','t','e','\'', 0};
1181 if (package->script->ExecuteSequenceRun)
1183 TRACE("Execute Sequence already Run\n");
1184 return ERROR_SUCCESS;
1187 package->script->ExecuteSequenceRun = TRUE;
1189 /* get the sequence number */
1192 row = MSI_QueryGetRecord(package->db, IVQuery);
1194 return ERROR_FUNCTION_FAILED;
1195 seq = MSI_RecordGetInteger(row,1);
1196 msiobj_release(&row->hdr);
1199 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1200 if (rc == ERROR_SUCCESS)
1202 rc = MSI_ViewExecute(view, 0);
1204 if (rc != ERROR_SUCCESS)
1206 MSI_ViewClose(view);
1207 msiobj_release(&view->hdr);
1211 TRACE("Running the actions\n");
1215 LPCWSTR cond, action;
1217 rc = MSI_ViewFetch(view,&row);
1218 if (rc != ERROR_SUCCESS)
1224 action = MSI_RecordGetString(row,1);
1227 ERR("Error in retrieving action name\n");
1228 rc = ERROR_FUNCTION_FAILED;
1229 msiobj_release(&row->hdr);
1233 /* check conditions */
1234 cond = MSI_RecordGetString(row,2);
1237 /* this is a hack to skip errors in the condition code */
1238 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1240 TRACE("Skipping action: %s (condition is false)\n",
1241 debugstr_w(action));
1242 msiobj_release(&row->hdr);
1247 rc = ACTION_PerformAction(package,action,FALSE);
1249 if (rc == ERROR_FUNCTION_NOT_CALLED)
1252 if (rc != ERROR_SUCCESS)
1254 ERR("Execution halted due to error (%i)\n",rc);
1255 msiobj_release(&row->hdr);
1259 msiobj_release(&row->hdr);
1262 MSI_ViewClose(view);
1263 msiobj_release(&view->hdr);
1271 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1275 static const WCHAR ExecSeqQuery [] =
1276 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1277 '`','I','n','s','t','a','l','l',
1278 'U','I','S','e','q','u','e','n','c','e','`',
1279 ' ','W','H','E','R','E',' ',
1280 '`','S','e','q','u','e','n','c','e','`',' ',
1281 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1282 '`','S','e','q','u','e','n','c','e','`',0};
1284 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1286 if (rc == ERROR_SUCCESS)
1288 rc = MSI_ViewExecute(view, 0);
1290 if (rc != ERROR_SUCCESS)
1292 MSI_ViewClose(view);
1293 msiobj_release(&view->hdr);
1297 TRACE("Running the actions \n");
1301 LPCWSTR action, cond;
1302 MSIRECORD * row = 0;
1304 rc = MSI_ViewFetch(view,&row);
1305 if (rc != ERROR_SUCCESS)
1311 action = MSI_RecordGetString(row,1);
1314 ERR("failed to fetch action\n");
1315 rc = ERROR_FUNCTION_FAILED;
1316 msiobj_release(&row->hdr);
1320 /* check conditions */
1321 cond = MSI_RecordGetString(row,2);
1324 /* this is a hack to skip errors in the condition code */
1325 if (MSI_EvaluateConditionW(package,cond) == MSICONDITION_FALSE)
1327 TRACE("Skipping action: %s (condition is false)\n",
1328 debugstr_w(action));
1329 msiobj_release(&row->hdr);
1334 rc = ACTION_PerformUIAction(package,action);
1336 if (rc == ERROR_FUNCTION_NOT_CALLED)
1339 if (rc != ERROR_SUCCESS)
1341 ERR("Execution halted due to error (%i)\n",rc);
1342 msiobj_release(&row->hdr);
1346 msiobj_release(&row->hdr);
1349 MSI_ViewClose(view);
1350 msiobj_release(&view->hdr);
1357 /********************************************************
1358 * ACTION helper functions and functions that perform the actions
1359 *******************************************************/
1360 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
1361 UINT* rc, BOOL force )
1367 if (!run && !package->script->CurrentlyScripting)
1372 if (strcmpW(action,szInstallFinalize) == 0 ||
1373 strcmpW(action,szInstallExecute) == 0 ||
1374 strcmpW(action,szInstallExecuteAgain) == 0)
1379 while (StandardActions[i].action != NULL)
1381 if (strcmpW(StandardActions[i].action, action)==0)
1383 ce_actiontext(package, action);
1386 ui_actioninfo(package, action, TRUE, 0);
1387 *rc = schedule_action(package,INSTALL_SCRIPT,action);
1388 ui_actioninfo(package, action, FALSE, *rc);
1392 ui_actionstart(package, action);
1393 if (StandardActions[i].handler)
1395 *rc = StandardActions[i].handler(package);
1399 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1400 *rc = ERROR_SUCCESS;
1411 static BOOL ACTION_HandleDialogBox( MSIPACKAGE *package, LPCWSTR dialog, UINT* rc )
1415 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1417 *rc = package->CurrentInstallState;
1423 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
1424 UINT* rc, BOOL force )
1429 arc = ACTION_CustomAction(package,action, force);
1431 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1440 * A lot of actions are really important even if they don't do anything
1441 * explicit... Lots of properties are set at the beginning of the installation
1442 * CostFinalize does a bunch of work to translate the directories and such
1444 * But until I get write access to the database that is hard, so I am going to
1445 * hack it to see if I can get something to run.
1447 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, BOOL force)
1449 UINT rc = ERROR_SUCCESS;
1452 TRACE("Performing action (%s)\n",debugstr_w(action));
1454 handled = ACTION_HandleStandardAction(package, action, &rc, force);
1457 handled = ACTION_HandleCustomAction(package, action, &rc, force);
1461 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1462 rc = ERROR_FUNCTION_NOT_CALLED;
1465 package->CurrentInstallState = rc;
1469 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1471 UINT rc = ERROR_SUCCESS;
1472 BOOL handled = FALSE;
1474 TRACE("Performing action (%s)\n",debugstr_w(action));
1476 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
1479 handled = ACTION_HandleCustomAction(package, action, &rc, FALSE);
1482 handled = ACTION_HandleDialogBox(package, action, &rc);
1484 msi_dialog_check_messages( NULL );
1488 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1489 rc = ERROR_FUNCTION_NOT_CALLED;
1492 package->CurrentInstallState = rc;
1496 /***********************************************************************
1499 * Recursively create all directories in the path.
1501 * shamelessly stolen from setupapi/queue.c
1503 static BOOL create_full_pathW(const WCHAR *path)
1509 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1512 strcpyW(new_path, path);
1514 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1515 new_path[len - 1] = 0;
1517 while(!CreateDirectoryW(new_path, NULL))
1520 DWORD last_error = GetLastError();
1521 if(last_error == ERROR_ALREADY_EXISTS)
1524 if(last_error != ERROR_PATH_NOT_FOUND)
1530 if(!(slash = strrchrW(new_path, '\\')))
1536 len = slash - new_path;
1538 if(!create_full_pathW(new_path))
1543 new_path[len] = '\\';
1546 HeapFree(GetProcessHeap(), 0, new_path);
1551 * Also we cannot enable/disable components either, so for now I am just going
1552 * to do all the directories for all the components.
1554 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1556 static const WCHAR ExecSeqQuery[] =
1557 {'S','E','L','E','C','T',' ',
1558 '`','D','i','r','e','c','t','o','r','y','_','`',
1559 ' ','F','R','O','M',' ',
1560 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
1565 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1566 if (rc != ERROR_SUCCESS)
1567 return ERROR_SUCCESS;
1569 rc = MSI_ViewExecute(view, 0);
1570 if (rc != ERROR_SUCCESS)
1572 MSI_ViewClose(view);
1573 msiobj_release(&view->hdr);
1581 MSIRECORD *row = NULL, *uirow;
1583 rc = MSI_ViewFetch(view,&row);
1584 if (rc != ERROR_SUCCESS)
1590 dir = MSI_RecordGetString(row,1);
1593 ERR("Unable to get folder id \n");
1594 msiobj_release(&row->hdr);
1598 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1601 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1602 msiobj_release(&row->hdr);
1606 TRACE("Folder is %s\n",debugstr_w(full_path));
1609 uirow = MSI_CreateRecord(1);
1610 MSI_RecordSetStringW(uirow,1,full_path);
1611 ui_actiondata(package,szCreateFolders,uirow);
1612 msiobj_release( &uirow->hdr );
1614 if (folder->State == 0)
1615 create_full_pathW(full_path);
1619 msiobj_release(&row->hdr);
1620 HeapFree(GetProcessHeap(),0,full_path);
1622 MSI_ViewClose(view);
1623 msiobj_release(&view->hdr);
1628 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1630 int index = package->loaded_components;
1633 /* fill in the data */
1635 package->loaded_components++;
1636 if (package->loaded_components == 1)
1637 package->components = HeapAlloc(GetProcessHeap(),0,
1638 sizeof(MSICOMPONENT));
1640 package->components = HeapReAlloc(GetProcessHeap(),0,
1641 package->components, package->loaded_components *
1642 sizeof(MSICOMPONENT));
1644 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1646 sz = IDENTIFIER_SIZE;
1647 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1649 TRACE("Loading Component %s\n",
1650 debugstr_w(package->components[index].Component));
1653 if (!MSI_RecordIsNull(row,2))
1654 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1656 sz = IDENTIFIER_SIZE;
1657 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1659 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1662 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1664 sz = IDENTIFIER_SIZE;
1665 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1667 package->components[index].Installed = INSTALLSTATE_ABSENT;
1668 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1669 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1671 package->components[index].Enabled = TRUE;
1676 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1678 int index = package->loaded_features;
1680 static const WCHAR Query1[] =
1681 {'S','E','L','E','C','T',' ',
1682 '`','C','o','m','p','o','n','e','n','t','_','`',
1683 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1684 'C','o','m','p','o','n','e','n','t','s','`',' ',
1685 'W','H','E','R','E',' ',
1686 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1687 static const WCHAR Query2[] =
1688 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1689 '`','C','o','m','p','o','n','e','n','t','`',' ',
1690 'W','H','E','R','E',' ',
1691 '`','C','o','m','p','o','n','e','n','t','`',' ',
1692 '=','\'','%','s','\'',0};
1699 /* fill in the data */
1701 package->loaded_features ++;
1702 if (package->loaded_features == 1)
1703 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1705 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1706 package->loaded_features * sizeof(MSIFEATURE));
1708 memset(&package->features[index],0,sizeof(MSIFEATURE));
1710 sz = IDENTIFIER_SIZE;
1711 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1713 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1715 sz = IDENTIFIER_SIZE;
1716 if (!MSI_RecordIsNull(row,2))
1717 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1720 if (!MSI_RecordIsNull(row,3))
1721 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1724 if (!MSI_RecordIsNull(row,4))
1725 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1727 if (!MSI_RecordIsNull(row,5))
1728 package->features[index].Display = MSI_RecordGetInteger(row,5);
1730 package->features[index].Level= MSI_RecordGetInteger(row,6);
1732 sz = IDENTIFIER_SIZE;
1733 if (!MSI_RecordIsNull(row,7))
1734 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1736 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1738 package->features[index].Installed = INSTALLSTATE_ABSENT;
1739 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1740 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1742 /* load feature components */
1744 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1745 if (rc != ERROR_SUCCESS)
1747 rc = MSI_ViewExecute(view,0);
1748 if (rc != ERROR_SUCCESS)
1750 MSI_ViewClose(view);
1751 msiobj_release(&view->hdr);
1759 INT cnt = package->features[index].ComponentCount;
1761 rc = MSI_ViewFetch(view,&row2);
1762 if (rc != ERROR_SUCCESS)
1765 component = MSI_RecordGetString(row2,1);
1767 /* check to see if the component is already loaded */
1768 c_indx = get_loaded_component(package,component);
1771 TRACE("Component %s already loaded at %i\n", debugstr_w(component),
1773 package->features[index].Components[cnt] = c_indx;
1774 package->features[index].ComponentCount ++;
1775 msiobj_release( &row2->hdr );
1779 rc = MSI_OpenQuery(package->db, &view2, Query2, component);
1780 if (rc != ERROR_SUCCESS)
1782 msiobj_release( &row2->hdr );
1785 rc = MSI_ViewExecute(view2,0);
1786 if (rc != ERROR_SUCCESS)
1788 msiobj_release( &row2->hdr );
1789 MSI_ViewClose(view2);
1790 msiobj_release( &view2->hdr );
1797 rc = MSI_ViewFetch(view2,&row3);
1798 if (rc != ERROR_SUCCESS)
1800 c_indx = load_component(package,row3);
1801 msiobj_release( &row3->hdr );
1803 package->features[index].Components[cnt] = c_indx;
1804 package->features[index].ComponentCount ++;
1805 TRACE("Loaded new component to index %i\n",c_indx);
1807 MSI_ViewClose(view2);
1808 msiobj_release( &view2->hdr );
1809 msiobj_release( &row2->hdr );
1811 MSI_ViewClose(view);
1812 msiobj_release(&view->hdr);
1815 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1817 DWORD index = package->loaded_files;
1820 /* fill in the data */
1822 package->loaded_files++;
1823 if (package->loaded_files== 1)
1824 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1826 package->files = HeapReAlloc(GetProcessHeap(),0,
1827 package->files , package->loaded_files * sizeof(MSIFILE));
1829 memset(&package->files[index],0,sizeof(MSIFILE));
1831 package->files[index].File = load_dynamic_stringW(row, 1);
1833 component = MSI_RecordGetString(row, 2);
1834 package->files[index].ComponentIndex = get_loaded_component(package,
1837 if (package->files[index].ComponentIndex == -1)
1838 ERR("Unfound Component %s\n",debugstr_w(component));
1840 package->files[index].FileName = load_dynamic_stringW(row,3);
1841 reduce_to_longfilename(package->files[index].FileName);
1843 package->files[index].ShortName = load_dynamic_stringW(row,3);
1844 reduce_to_shortfilename(package->files[index].ShortName);
1846 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1847 package->files[index].Version = load_dynamic_stringW(row, 5);
1848 package->files[index].Language = load_dynamic_stringW(row, 6);
1849 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1850 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1852 package->files[index].Temporary = FALSE;
1853 package->files[index].State = 0;
1855 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1857 return ERROR_SUCCESS;
1860 static UINT load_all_files(MSIPACKAGE *package)
1865 static const WCHAR Query[] =
1866 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1867 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1868 '`','S','e','q','u','e','n','c','e','`', 0};
1871 return ERROR_INVALID_HANDLE;
1873 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1874 if (rc != ERROR_SUCCESS)
1875 return ERROR_SUCCESS;
1877 rc = MSI_ViewExecute(view, 0);
1878 if (rc != ERROR_SUCCESS)
1880 MSI_ViewClose(view);
1881 msiobj_release(&view->hdr);
1882 return ERROR_SUCCESS;
1887 rc = MSI_ViewFetch(view,&row);
1888 if (rc != ERROR_SUCCESS)
1893 load_file(package,row);
1894 msiobj_release(&row->hdr);
1896 MSI_ViewClose(view);
1897 msiobj_release(&view->hdr);
1899 return ERROR_SUCCESS;
1904 * I am not doing any of the costing functionality yet.
1905 * Mostly looking at doing the Component and Feature loading
1907 * The native MSI does A LOT of modification to tables here. Mostly adding
1908 * a lot of temporary columns to the Feature and Component tables.
1910 * note: Native msi also tracks the short filename. But I am only going to
1911 * track the long ones. Also looking at this directory table
1912 * it appears that the directory table does not get the parents
1913 * resolved base on property only based on their entries in the
1916 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1921 static const WCHAR Query_all[] =
1922 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1923 '`','F','e','a','t','u','r','e','`',0};
1924 static const WCHAR szCosting[] =
1925 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1926 static const WCHAR szZero[] = { '0', 0 };
1930 MSI_GetPropertyW(package, szCosting, buffer, &sz);
1932 return ERROR_SUCCESS;
1934 MSI_SetPropertyW(package, szCosting, szZero);
1935 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1937 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1938 if (rc != ERROR_SUCCESS)
1940 rc = MSI_ViewExecute(view,0);
1941 if (rc != ERROR_SUCCESS)
1943 MSI_ViewClose(view);
1944 msiobj_release(&view->hdr);
1951 rc = MSI_ViewFetch(view,&row);
1952 if (rc != ERROR_SUCCESS)
1955 load_feature(package,row);
1956 msiobj_release(&row->hdr);
1958 MSI_ViewClose(view);
1959 msiobj_release(&view->hdr);
1961 load_all_files(package);
1963 return ERROR_SUCCESS;
1966 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
1969 LPWSTR *newbuf = NULL;
1970 if (script >= TOTAL_SCRIPTS)
1972 FIXME("Unknown script requested %i\n",script);
1973 return ERROR_FUNCTION_FAILED;
1975 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
1977 count = package->script->ActionCount[script];
1978 package->script->ActionCount[script]++;
1980 newbuf = HeapReAlloc(GetProcessHeap(),0,
1981 package->script->Actions[script],
1982 package->script->ActionCount[script]* sizeof(LPWSTR));
1984 newbuf = HeapAlloc(GetProcessHeap(),0, sizeof(LPWSTR));
1986 newbuf[count] = strdupW(action);
1987 package->script->Actions[script] = newbuf;
1989 return ERROR_SUCCESS;
1992 static UINT execute_script(MSIPACKAGE *package, UINT script )
1995 UINT rc = ERROR_SUCCESS;
1997 TRACE("Executing Script %i\n",script);
1999 for (i = 0; i < package->script->ActionCount[script]; i++)
2002 action = package->script->Actions[script][i];
2003 ui_actionstart(package, action);
2004 TRACE("Executing Action (%s)\n",debugstr_w(action));
2005 rc = ACTION_PerformAction(package, action, TRUE);
2006 HeapFree(GetProcessHeap(),0,package->script->Actions[script][i]);
2007 if (rc != ERROR_SUCCESS)
2010 HeapFree(GetProcessHeap(),0,package->script->Actions[script]);
2012 package->script->ActionCount[script] = 0;
2013 package->script->Actions[script] = NULL;
2017 static UINT ACTION_FileCost(MSIPACKAGE *package)
2019 return ERROR_SUCCESS;
2023 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
2025 static const WCHAR Query[] =
2026 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2027 '`','D','i','r','e','c', 't','o','r','y','`',' ',
2028 'W','H','E','R','E',' ', '`', 'D','i','r','e','c','t', 'o','r','y','`',
2029 ' ','=',' ','\'','%','s','\'',
2031 LPWSTR ptargetdir, targetdir, srcdir;
2033 LPWSTR shortname = NULL;
2034 MSIRECORD * row = 0;
2038 TRACE("Looking for dir %s\n",debugstr_w(dir));
2040 for (i = 0; i < package->loaded_folders; i++)
2042 if (strcmpW(package->folders[i].Directory,dir)==0)
2044 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
2049 TRACE("Working to load %s\n",debugstr_w(dir));
2051 index = package->loaded_folders++;
2052 if (package->loaded_folders==1)
2053 package->folders = HeapAlloc(GetProcessHeap(),0,
2056 package->folders= HeapReAlloc(GetProcessHeap(),0,
2057 package->folders, package->loaded_folders*
2060 memset(&package->folders[index],0,sizeof(MSIFOLDER));
2062 package->folders[index].Directory = strdupW(dir);
2064 row = MSI_QueryGetRecord(package->db, Query, dir);
2068 ptargetdir = targetdir = load_dynamic_stringW(row,3);
2070 /* split src and target dir */
2071 if (strchrW(targetdir,':'))
2073 srcdir=strchrW(targetdir,':');
2080 /* for now only pick long filename versions */
2081 if (strchrW(targetdir,'|'))
2083 shortname = targetdir;
2084 targetdir = strchrW(targetdir,'|');
2088 /* for the sourcedir pick the short filename */
2089 if (srcdir && strchrW(srcdir,'|'))
2091 LPWSTR p = strchrW(srcdir,'|');
2095 /* now check for root dirs */
2096 if (targetdir[0] == '.' && targetdir[1] == 0)
2099 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
2104 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2105 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2106 package->folders[index].TargetDefault = strdupW(targetdir);
2110 package->folders[index].SourceDefault = strdupW(srcdir);
2112 package->folders[index].SourceDefault = strdupW(shortname);
2114 package->folders[index].SourceDefault = strdupW(targetdir);
2115 HeapFree(GetProcessHeap(), 0, ptargetdir);
2116 TRACE(" SourceDefault = %s\n",debugstr_w(package->folders[index].SourceDefault));
2118 parent = MSI_RecordGetString(row,2);
2121 i = load_folder(package,parent);
2122 package->folders[index].ParentIndex = i;
2123 TRACE("Parent is index %i... %s %s\n",
2124 package->folders[index].ParentIndex,
2125 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2126 debugstr_w(parent));
2129 package->folders[index].ParentIndex = -2;
2131 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2133 msiobj_release(&row->hdr);
2134 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2139 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
2140 BOOL set_prop, MSIFOLDER **folder)
2143 LPWSTR p, path = NULL;
2145 TRACE("Working to resolve %s\n",debugstr_w(name));
2150 /* special resolving for Target and Source root dir */
2151 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2155 path = load_dynamic_property(package,cszTargetDir,NULL);
2158 path = load_dynamic_property(package,cszRootDrive,NULL);
2160 MSI_SetPropertyW(package,cszTargetDir,path);
2164 for (i = 0; i < package->loaded_folders; i++)
2166 if (strcmpW(package->folders[i].Directory,name)==0)
2169 *folder = &(package->folders[i]);
2175 path = load_dynamic_property(package,cszSourceDir,NULL);
2178 path = load_dynamic_property(package,cszDatabase,NULL);
2181 p = strrchrW(path,'\\');
2188 for (i = 0; i < package->loaded_folders; i++)
2190 if (strcmpW(package->folders[i].Directory,name)==0)
2193 *folder = &(package->folders[i]);
2199 for (i = 0; i < package->loaded_folders; i++)
2201 if (strcmpW(package->folders[i].Directory,name)==0)
2205 if (i >= package->loaded_folders)
2209 *folder = &(package->folders[i]);
2211 if (!source && package->folders[i].ResolvedTarget)
2213 path = strdupW(package->folders[i].ResolvedTarget);
2214 TRACE(" already resolved to %s\n",debugstr_w(path));
2217 else if (source && package->folders[i].ResolvedSource)
2219 path = strdupW(package->folders[i].ResolvedSource);
2220 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
2223 else if (!source && package->folders[i].Property)
2225 path = build_directory_name(2, package->folders[i].Property, NULL);
2227 TRACE(" internally set to %s\n",debugstr_w(path));
2229 MSI_SetPropertyW(package,name,path);
2233 if (package->folders[i].ParentIndex >= 0)
2235 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2237 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2239 p = resolve_folder(package, parent, source, set_prop, NULL);
2242 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2243 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2244 package->folders[i].ResolvedTarget = strdupW(path);
2245 TRACE(" resolved into %s\n",debugstr_w(path));
2247 MSI_SetPropertyW(package,name,path);
2251 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2252 TRACE(" (source)resolved into %s\n",debugstr_w(path));
2253 package->folders[i].ResolvedSource = strdupW(path);
2255 HeapFree(GetProcessHeap(),0,p);
2260 /* scan for and update current install states */
2261 static void ACTION_UpdateInstallStates(MSIPACKAGE *package)
2266 productcode = load_dynamic_property(package,szProductCode,NULL);
2268 for (i = 0; i < package->loaded_components; i++)
2271 res = MsiGetComponentPathW(productcode,
2272 package->components[i].ComponentId , NULL, NULL);
2274 res = INSTALLSTATE_ABSENT;
2275 package->components[i].Installed = res;
2278 for (i = 0; i < package->loaded_features; i++)
2280 INSTALLSTATE res = -10;
2282 for (j = 0; j < package->features[i].ComponentCount; j++)
2284 MSICOMPONENT* component = &package->components[package->features[i].
2287 res = component->Installed;
2290 if (res == component->Installed)
2293 if (res != component->Installed)
2294 res = INSTALLSTATE_INCOMPLETE;
2300 /* update compoennt state based on a feature change */
2301 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2304 INSTALLSTATE newstate;
2305 MSIFEATURE *feature;
2307 i = get_loaded_feature(package,szFeature);
2311 feature = &package->features[i];
2312 newstate = feature->ActionRequest;
2314 for( i = 0; i < feature->ComponentCount; i++)
2316 MSICOMPONENT* component = &package->components[feature->Components[i]];
2318 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
2319 newstate, debugstr_w(component->Component), component->Installed,
2320 component->Action, component->ActionRequest);
2322 if (!component->Enabled)
2326 if (newstate == INSTALLSTATE_LOCAL)
2328 component->ActionRequest = INSTALLSTATE_LOCAL;
2329 component->Action = INSTALLSTATE_LOCAL;
2335 component->ActionRequest = newstate;
2336 component->Action = newstate;
2338 /*if any other feature wants is local we need to set it local*/
2340 j < package->loaded_features &&
2341 component->ActionRequest != INSTALLSTATE_LOCAL;
2344 for (k = 0; k < package->features[j].ComponentCount; k++)
2345 if ( package->features[j].Components[k] ==
2346 feature->Components[i] )
2348 if (package->features[j].ActionRequest ==
2351 TRACE("Saved by %s\n", debugstr_w(package->features[j].Feature));
2352 component->ActionRequest = INSTALLSTATE_LOCAL;
2353 component->Action = INSTALLSTATE_LOCAL;
2360 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
2361 newstate, debugstr_w(component->Component), component->Installed,
2362 component->Action, component->ActionRequest);
2366 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
2369 static const WCHAR all[]={'A','L','L',0};
2370 LPWSTR override = NULL;
2374 override = load_dynamic_property(package, property, NULL);
2378 for(i = 0; i < package->loaded_features; i++)
2380 if (strcmpiW(override,all)==0)
2382 package->features[i].ActionRequest= state;
2383 package->features[i].Action = state;
2387 LPWSTR ptr = override;
2388 LPWSTR ptr2 = strchrW(override,',');
2393 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2395 strcmpW(ptr,package->features[i].Feature)==0))
2397 package->features[i].ActionRequest= state;
2398 package->features[i].Action = state;
2404 ptr2 = strchrW(ptr,',');
2411 HeapFree(GetProcessHeap(),0,override);
2417 static UINT SetFeatureStates(MSIPACKAGE *package)
2423 static const WCHAR szlevel[] =
2424 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2425 static const WCHAR szAddLocal[] =
2426 {'A','D','D','L','O','C','A','L',0};
2427 static const WCHAR szRemove[] =
2428 {'R','E','M','O','V','E',0};
2429 BOOL override = FALSE;
2431 /* I do not know if this is where it should happen.. but */
2433 TRACE("Checking Install Level\n");
2435 level = load_dynamic_property(package,szlevel,NULL);
2438 install_level = atoiW(level);
2439 HeapFree(GetProcessHeap(), 0, level);
2444 /* ok hereis the _real_ rub
2445 * all these activation/deactivation things happen in order and things
2446 * later on the list override things earlier on the list.
2447 * 1) INSTALLLEVEL processing
2457 * 11) FILEADDDEFAULT
2458 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2459 * ignored for all the features. seems strange, especially since it is not
2460 * documented anywhere, but it is how it works.
2462 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2463 * REMOVE are the big ones, since we don't handle administrative installs
2466 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
2467 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
2471 for(i = 0; i < package->loaded_features; i++)
2473 BOOL feature_state = ((package->features[i].Level > 0) &&
2474 (package->features[i].Level <= install_level));
2476 if ((feature_state) &&
2477 (package->features[i].Action == INSTALLSTATE_UNKNOWN))
2479 if (package->features[i].Attributes &
2480 msidbFeatureAttributesFavorSource)
2482 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
2483 package->features[i].Action = INSTALLSTATE_SOURCE;
2485 else if (package->features[i].Attributes &
2486 msidbFeatureAttributesFavorAdvertise)
2488 package->features[i].ActionRequest =INSTALLSTATE_ADVERTISED;
2489 package->features[i].Action =INSTALLSTATE_ADVERTISED;
2493 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
2494 package->features[i].Action = INSTALLSTATE_LOCAL;
2501 /* set the Preselected Property */
2502 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
2503 static const WCHAR szOne[] = { '1', 0 };
2505 MSI_SetPropertyW(package,szPreselected,szOne);
2509 * now we want to enable or disable components base on feature
2512 for(i = 0; i < package->loaded_features; i++)
2514 MSIFEATURE* feature = &package->features[i];
2515 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2516 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2517 feature->ActionRequest);
2519 for( j = 0; j < feature->ComponentCount; j++)
2521 MSICOMPONENT* component = &package->components[
2522 feature->Components[j]];
2524 if (!component->Enabled)
2526 component->Action = INSTALLSTATE_UNKNOWN;
2527 component->ActionRequest = INSTALLSTATE_UNKNOWN;
2531 if (feature->Action == INSTALLSTATE_LOCAL)
2533 component->Action = INSTALLSTATE_LOCAL;
2534 component->ActionRequest = INSTALLSTATE_LOCAL;
2536 else if (feature->ActionRequest == INSTALLSTATE_SOURCE)
2538 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2539 (component->Action == INSTALLSTATE_ABSENT) ||
2540 (component->Action == INSTALLSTATE_ADVERTISED))
2543 component->Action = INSTALLSTATE_SOURCE;
2544 component->ActionRequest = INSTALLSTATE_SOURCE;
2547 else if (feature->ActionRequest == INSTALLSTATE_ADVERTISED)
2549 if ((component->Action == INSTALLSTATE_UNKNOWN) ||
2550 (component->Action == INSTALLSTATE_ABSENT))
2553 component->Action = INSTALLSTATE_ADVERTISED;
2554 component->ActionRequest = INSTALLSTATE_ADVERTISED;
2557 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
2559 if (component->Action == INSTALLSTATE_UNKNOWN)
2561 component->Action = INSTALLSTATE_ABSENT;
2562 component->ActionRequest = INSTALLSTATE_ABSENT;
2569 for(i = 0; i < package->loaded_components; i++)
2571 MSICOMPONENT* component= &package->components[i];
2573 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2574 debugstr_w(component->Component), component->Installed,
2575 component->Action, component->ActionRequest);
2579 return ERROR_SUCCESS;
2583 * A lot is done in this function aside from just the costing.
2584 * The costing needs to be implemented at some point but for now I am going
2585 * to focus on the directory building
2588 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2590 static const WCHAR ExecSeqQuery[] =
2591 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2592 '`','D','i','r','e','c','t','o','r','y','`',0};
2593 static const WCHAR ConditionQuery[] =
2594 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2595 '`','C','o','n','d','i','t','i','o','n','`',0};
2596 static const WCHAR szCosting[] =
2597 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2598 static const WCHAR szlevel[] =
2599 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2600 static const WCHAR szOne[] = { '1', 0 };
2608 MSI_GetPropertyW(package, szCosting, buffer, &sz);
2610 return ERROR_SUCCESS;
2612 TRACE("Building Directory properties\n");
2614 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2615 if (rc == ERROR_SUCCESS)
2617 rc = MSI_ViewExecute(view, 0);
2618 if (rc != ERROR_SUCCESS)
2620 MSI_ViewClose(view);
2621 msiobj_release(&view->hdr);
2629 MSIRECORD * row = 0;
2631 rc = MSI_ViewFetch(view,&row);
2632 if (rc != ERROR_SUCCESS)
2638 name = MSI_RecordGetString(row,1);
2640 /* This helper function now does ALL the work */
2641 TRACE("Dir %s ...\n",debugstr_w(name));
2642 load_folder(package,name);
2643 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2644 TRACE("resolves to %s\n",debugstr_w(path));
2645 HeapFree( GetProcessHeap(), 0, path);
2647 msiobj_release(&row->hdr);
2649 MSI_ViewClose(view);
2650 msiobj_release(&view->hdr);
2653 TRACE("File calculations %i files\n",package->loaded_files);
2655 for (i = 0; i < package->loaded_files; i++)
2657 MSICOMPONENT* comp = NULL;
2658 MSIFILE* file= NULL;
2660 file = &package->files[i];
2661 if (file->ComponentIndex >= 0)
2662 comp = &package->components[file->ComponentIndex];
2664 if (file->Temporary == TRUE)
2671 /* calculate target */
2672 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2674 HeapFree(GetProcessHeap(),0,file->TargetPath);
2676 TRACE("file %s is named %s\n",
2677 debugstr_w(file->File),debugstr_w(file->FileName));
2679 file->TargetPath = build_directory_name(2, p, file->FileName);
2681 HeapFree(GetProcessHeap(),0,p);
2683 TRACE("file %s resolves to %s\n",
2684 debugstr_w(file->File),debugstr_w(file->TargetPath));
2686 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2689 comp->Cost += file->FileSize;
2699 static const WCHAR name[] =
2701 static const WCHAR name_fmt[] =
2702 {'%','u','.','%','u','.','%','u','.','%','u',0};
2703 WCHAR filever[0x100];
2704 VS_FIXEDFILEINFO *lpVer;
2706 TRACE("Version comparison.. \n");
2707 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2708 version = HeapAlloc(GetProcessHeap(),0,versize);
2709 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2711 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2713 sprintfW(filever,name_fmt,
2714 HIWORD(lpVer->dwFileVersionMS),
2715 LOWORD(lpVer->dwFileVersionMS),
2716 HIWORD(lpVer->dwFileVersionLS),
2717 LOWORD(lpVer->dwFileVersionLS));
2719 TRACE("new %s old %s\n", debugstr_w(file->Version),
2720 debugstr_w(filever));
2721 if (strcmpiW(filever,file->Version)<0)
2724 FIXME("cost should be diff in size\n");
2725 comp->Cost += file->FileSize;
2729 HeapFree(GetProcessHeap(),0,version);
2737 TRACE("Evaluating Condition Table\n");
2739 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2740 if (rc == ERROR_SUCCESS)
2742 rc = MSI_ViewExecute(view, 0);
2743 if (rc != ERROR_SUCCESS)
2745 MSI_ViewClose(view);
2746 msiobj_release(&view->hdr);
2753 MSIRECORD * row = 0;
2756 rc = MSI_ViewFetch(view,&row);
2758 if (rc != ERROR_SUCCESS)
2764 Feature = MSI_RecordGetString(row,1);
2766 feature_index = get_loaded_feature(package,Feature);
2767 if (feature_index < 0)
2768 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2772 Condition = MSI_RecordGetString(row,3);
2774 if (MSI_EvaluateConditionW(package,Condition) ==
2777 int level = MSI_RecordGetInteger(row,2);
2778 TRACE("Reseting feature %s to level %i\n",
2779 debugstr_w(Feature), level);
2780 package->features[feature_index].Level = level;
2784 msiobj_release(&row->hdr);
2786 MSI_ViewClose(view);
2787 msiobj_release(&view->hdr);
2790 TRACE("Enabling or Disabling Components\n");
2791 for (i = 0; i < package->loaded_components; i++)
2793 if (package->components[i].Condition[0])
2795 if (MSI_EvaluateConditionW(package,
2796 package->components[i].Condition) == MSICONDITION_FALSE)
2798 TRACE("Disabling component %s\n",
2799 debugstr_w(package->components[i].Component));
2800 package->components[i].Enabled = FALSE;
2805 MSI_SetPropertyW(package,szCosting,szOne);
2806 /* set default run level if not set */
2807 level = load_dynamic_property(package,szlevel,NULL);
2809 MSI_SetPropertyW(package,szlevel, szOne);
2811 HeapFree(GetProcessHeap(),0,level);
2813 ACTION_UpdateInstallStates(package);
2815 return SetFeatureStates(package);
2819 * This is a helper function for handling embedded cabinet media
2821 static UINT writeout_cabinet_stream(MSIPACKAGE *package, LPCWSTR stream_name,
2829 WCHAR tmp[MAX_PATH];
2831 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2832 if (rc != ERROR_SUCCESS)
2836 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2837 GetTempPathW(MAX_PATH,tmp);
2839 GetTempFileNameW(tmp,stream_name,0,source);
2841 track_tempfile(package,strrchrW(source,'\\'), source);
2842 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2843 FILE_ATTRIBUTE_NORMAL, NULL);
2845 if (the_file == INVALID_HANDLE_VALUE)
2847 ERR("Unable to create file %s\n",debugstr_w(source));
2848 rc = ERROR_FUNCTION_FAILED;
2852 WriteFile(the_file,data,size,&write,NULL);
2853 CloseHandle(the_file);
2854 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2856 HeapFree(GetProcessHeap(),0,data);
2861 /* Support functions for FDI functions */
2864 MSIPACKAGE* package;
2869 static void * cabinet_alloc(ULONG cb)
2871 return HeapAlloc(GetProcessHeap(), 0, cb);
2874 static void cabinet_free(void *pv)
2876 HeapFree(GetProcessHeap(), 0, pv);
2879 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2882 DWORD dwShareMode = 0;
2883 DWORD dwCreateDisposition = OPEN_EXISTING;
2884 switch (oflag & _O_ACCMODE)
2887 dwAccess = GENERIC_READ;
2888 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2891 dwAccess = GENERIC_WRITE;
2892 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2895 dwAccess = GENERIC_READ | GENERIC_WRITE;
2896 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2899 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2900 dwCreateDisposition = CREATE_NEW;
2901 else if (oflag & _O_CREAT)
2902 dwCreateDisposition = CREATE_ALWAYS;
2903 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
2904 dwCreateDisposition, 0, NULL);
2907 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2910 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2915 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2918 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2923 static int cabinet_close(INT_PTR hf)
2925 return CloseHandle((HANDLE)hf) ? 0 : -1;
2928 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2930 /* flags are compatible and so are passed straight through */
2931 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2934 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2936 /* FIXME: try to do more processing in this function */
2939 case fdintCOPY_FILE:
2941 CabData *data = (CabData*) pfdin->pv;
2942 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2947 LPWSTR tracknametmp;
2948 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2950 if (data->file_name && lstrcmpiA(data->file_name,pfdin->psz1))
2953 file = cabinet_alloc((len+1)*sizeof(char));
2954 strcpy(file, data->cab_path);
2955 strcat(file, pfdin->psz1);
2957 TRACE("file: %s\n", debugstr_a(file));
2959 /* track this file so it can be deleted if not installed */
2960 trackpath=strdupAtoW(file);
2961 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2962 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2963 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2965 strcpyW(trackname,tmpprefix);
2966 strcatW(trackname,tracknametmp);
2968 track_tempfile(data->package, trackname, trackpath);
2970 HeapFree(GetProcessHeap(),0,trackpath);
2971 HeapFree(GetProcessHeap(),0,trackname);
2972 HeapFree(GetProcessHeap(),0,tracknametmp);
2974 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2976 case fdintCLOSE_FILE_INFO:
2980 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2982 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2984 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2987 cabinet_close(pfdin->hf);
2995 /***********************************************************************
2996 * extract_cabinet_file
2998 * Extract files from a cab file.
3000 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
3001 const WCHAR* path, const WCHAR* file)
3011 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
3012 debugstr_w(file), debugstr_w(path));
3014 hfdi = FDICreate(cabinet_alloc,
3025 ERR("FDICreate failed\n");
3029 if (!(cabinet = strdupWtoA( source )))
3034 if (!(cab_path = strdupWtoA( path )))
3037 HeapFree(GetProcessHeap(), 0, cabinet);
3041 data.package = package;
3042 data.cab_path = cab_path;
3044 file_name = strdupWtoA(file);
3047 data.file_name = file_name;
3049 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
3052 ERR("FDICopy failed\n");
3056 HeapFree(GetProcessHeap(), 0, cabinet);
3057 HeapFree(GetProcessHeap(), 0, cab_path);
3058 HeapFree(GetProcessHeap(), 0, file_name);
3063 static UINT ready_media_for_file(MSIPACKAGE *package, WCHAR* path,
3066 UINT rc = ERROR_SUCCESS;
3067 MSIRECORD * row = 0;
3068 static WCHAR source[MAX_PATH];
3069 static const WCHAR ExecSeqQuery[] =
3070 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3071 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3072 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
3073 ' ','%', 'i',' ','O','R','D','E','R',' ','B','Y',' ',
3074 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',0};
3078 static UINT last_sequence = 0;
3080 if (file->Attributes & msidbFileAttributesNoncompressed)
3082 TRACE("Uncompressed File, no media to ready.\n");
3083 return ERROR_SUCCESS;
3086 if (file->Sequence <= last_sequence)
3088 TRACE("Media already ready (%u, %u)\n",file->Sequence,last_sequence);
3089 /*extract_a_cabinet_file(package, source,path,file->File); */
3090 return ERROR_SUCCESS;
3093 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, file->Sequence);
3095 return ERROR_FUNCTION_FAILED;
3097 seq = MSI_RecordGetInteger(row,2);
3098 last_sequence = seq;
3100 cab = MSI_RecordGetString(row,4);
3103 TRACE("Source is CAB %s\n",debugstr_w(cab));
3104 /* the stream does not contain the # character */
3107 writeout_cabinet_stream(package,&cab[1],source);
3108 strcpyW(path,source);
3109 *(strrchrW(path,'\\')+1)=0;
3114 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
3116 ERR("No Source dir defined \n");
3117 rc = ERROR_FUNCTION_FAILED;
3121 strcpyW(path,source);
3122 strcatW(source,cab);
3123 /* extract the cab file into a folder in the temp folder */
3125 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
3127 GetTempPathW(MAX_PATH,path);
3130 rc = !extract_a_cabinet_file(package, source,path,NULL);
3135 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
3136 strcpyW(path,source);
3138 msiobj_release(&row->hdr);
3142 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
3144 UINT rc = ERROR_SUCCESS;
3146 LPWSTR install_path;
3148 install_path = resolve_folder(package, package->components[component].Directory,
3149 FALSE, FALSE, &folder);
3151 return ERROR_FUNCTION_FAILED;
3153 /* create the path */
3154 if (folder->State == 0)
3156 create_full_pathW(install_path);
3159 HeapFree(GetProcessHeap(), 0, install_path);
3164 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3166 UINT rc = ERROR_SUCCESS;
3169 WCHAR uipath[MAX_PATH];
3172 return ERROR_INVALID_HANDLE;
3174 /* increment progress bar each time action data is sent */
3175 ui_progress(package,1,1,0,0);
3177 for (index = 0; index < package->loaded_files; index++)
3179 WCHAR path_to_source[MAX_PATH];
3182 file = &package->files[index];
3184 if (file->Temporary)
3188 if (!ACTION_VerifyComponentForAction(package, file->ComponentIndex,
3189 INSTALLSTATE_LOCAL))
3191 ui_progress(package,2,file->FileSize,0,0);
3192 TRACE("File %s is not scheduled for install\n",
3193 debugstr_w(file->File));
3198 if ((file->State == 1) || (file->State == 2))
3201 MSICOMPONENT* comp = NULL;
3203 TRACE("Installing %s\n",debugstr_w(file->File));
3204 rc = ready_media_for_file(package, path_to_source, file);
3207 * our file table could change here because a new temp file
3208 * may have been created
3210 file = &package->files[index];
3211 if (rc != ERROR_SUCCESS)
3213 ERR("Unable to ready media\n");
3214 rc = ERROR_FUNCTION_FAILED;
3218 create_component_directory( package, file->ComponentIndex);
3220 /* recalculate file paths because things may have changed */
3222 if (file->ComponentIndex >= 0)
3223 comp = &package->components[file->ComponentIndex];
3225 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3226 HeapFree(GetProcessHeap(),0,file->TargetPath);
3228 file->TargetPath = build_directory_name(2, p, file->FileName);
3229 HeapFree(GetProcessHeap(),0,p);
3231 if (file->Attributes & msidbFileAttributesNoncompressed)
3233 p = resolve_folder(package, comp->Directory, TRUE, FALSE, NULL);
3234 file->SourcePath = build_directory_name(2, p, file->ShortName);
3235 HeapFree(GetProcessHeap(),0,p);
3238 file->SourcePath = build_directory_name(2, path_to_source,
3242 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3243 debugstr_w(file->TargetPath));
3246 uirow=MSI_CreateRecord(9);
3247 MSI_RecordSetStringW(uirow,1,file->File);
3248 strcpyW(uipath,file->TargetPath);
3249 *(strrchrW(uipath,'\\')+1)=0;
3250 MSI_RecordSetStringW(uirow,9,uipath);
3251 MSI_RecordSetInteger(uirow,6,file->FileSize);
3252 ui_actiondata(package,szInstallFiles,uirow);
3253 msiobj_release( &uirow->hdr );
3254 ui_progress(package,2,file->FileSize,0,0);
3257 if (file->Attributes & msidbFileAttributesNoncompressed)
3258 rc = CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3260 rc = MoveFileW(file->SourcePath, file->TargetPath);
3264 rc = GetLastError();
3265 ERR("Unable to move/copy file (%s -> %s) (error %d)\n",
3266 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3268 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3270 if (!CopyFileW(file->SourcePath,file->TargetPath,FALSE))
3271 ERR("Unable to copy file (%s -> %s) (error %ld)\n",
3272 debugstr_w(file->SourcePath),
3273 debugstr_w(file->TargetPath), GetLastError());
3274 if (!(file->Attributes & msidbFileAttributesNoncompressed))
3275 DeleteFileW(file->SourcePath);
3278 else if (rc == ERROR_FILE_NOT_FOUND)
3280 ERR("Source File Not Found! Continuing\n");
3283 else if (file->Attributes & msidbFileAttributesVital)
3285 ERR("Ignoring Error and continuing (nonvital file)...\n");
3300 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3301 LPWSTR* file_source)
3306 return ERROR_INVALID_HANDLE;
3308 for (index = 0; index < package->loaded_files; index ++)
3310 if (strcmpW(file_key,package->files[index].File)==0)
3312 if (package->files[index].State >= 2)
3314 *file_source = strdupW(package->files[index].TargetPath);
3315 return ERROR_SUCCESS;
3318 return ERROR_FILE_NOT_FOUND;
3322 return ERROR_FUNCTION_FAILED;
3325 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3329 MSIRECORD * row = 0;
3330 static const WCHAR ExecSeqQuery[] =
3331 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3332 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
3335 return ERROR_INVALID_HANDLE;
3337 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3338 if (rc != ERROR_SUCCESS)
3339 return ERROR_SUCCESS;
3341 rc = MSI_ViewExecute(view, 0);
3342 if (rc != ERROR_SUCCESS)
3344 MSI_ViewClose(view);
3345 msiobj_release(&view->hdr);
3351 WCHAR *file_source = NULL;
3352 WCHAR dest_name[0x100];
3353 LPWSTR dest_path, dest;
3354 LPCWSTR file_key, component;
3355 INT component_index;
3359 rc = MSI_ViewFetch(view,&row);
3360 if (rc != ERROR_SUCCESS)
3366 component = MSI_RecordGetString(row,2);
3367 component_index = get_loaded_component(package,component);
3369 if (!ACTION_VerifyComponentForAction(package, component_index,
3370 INSTALLSTATE_LOCAL))
3372 TRACE("Skipping copy due to disabled component %s\n",
3373 debugstr_w(component));
3375 /* the action taken was the same as the current install state */
3376 package->components[component_index].Action =
3377 package->components[component_index].Installed;
3379 msiobj_release(&row->hdr);
3383 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3385 file_key = MSI_RecordGetString(row,3);
3388 ERR("Unable to get file key\n");
3389 msiobj_release(&row->hdr);
3393 rc = get_file_target(package,file_key,&file_source);
3395 if (rc != ERROR_SUCCESS)
3397 ERR("Original file unknown %s\n",debugstr_w(file_key));
3398 msiobj_release(&row->hdr);
3399 HeapFree(GetProcessHeap(),0,file_source);
3403 if (MSI_RecordIsNull(row,4))
3405 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3410 MSI_RecordGetStringW(row,4,dest_name,&sz);
3411 reduce_to_longfilename(dest_name);
3414 if (MSI_RecordIsNull(row,5))
3417 dest_path = strdupW(file_source);
3418 p = strrchrW(dest_path,'\\');
3425 destkey = MSI_RecordGetString(row,5);
3426 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3429 ERR("Unable to get destination folder\n");
3430 msiobj_release(&row->hdr);
3431 HeapFree(GetProcessHeap(),0,file_source);
3436 dest = build_directory_name(2, dest_path, dest_name);
3438 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3441 if (strcmpW(file_source,dest))
3442 rc = !CopyFileW(file_source,dest,TRUE);
3446 if (rc != ERROR_SUCCESS)
3447 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
3449 FIXME("We should track these duplicate files as well\n");
3451 msiobj_release(&row->hdr);
3452 HeapFree(GetProcessHeap(),0,dest_path);
3453 HeapFree(GetProcessHeap(),0,dest);
3454 HeapFree(GetProcessHeap(),0,file_source);
3456 MSI_ViewClose(view);
3457 msiobj_release(&view->hdr);
3462 /* OK this value is "interpreted" and then formatted based on the
3463 first few characters */
3464 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
3468 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3474 LPWSTR deformated = NULL;
3477 deformat_string(package, &value[2], &deformated);
3479 /* binary value type */
3483 *size = (strlenW(ptr)/2)+1;
3485 *size = strlenW(ptr)/2;
3487 data = HeapAlloc(GetProcessHeap(),0,*size);
3493 /* if uneven pad with a zero in front */
3499 data[count] = (BYTE)strtol(byte,NULL,0);
3501 TRACE("Uneven byte count\n");
3509 data[count] = (BYTE)strtol(byte,NULL,0);
3512 HeapFree(GetProcessHeap(),0,deformated);
3514 TRACE("Data %li bytes(%i)\n",*size,count);
3521 deformat_string(package, &value[1], &deformated);
3524 *size = sizeof(DWORD);
3525 data = HeapAlloc(GetProcessHeap(),0,*size);
3531 if ( (*p < '0') || (*p > '9') )
3537 if (deformated[0] == '-')
3540 TRACE("DWORD %li\n",*(LPDWORD)data);
3542 HeapFree(GetProcessHeap(),0,deformated);
3547 static const WCHAR szMulti[] = {'[','~',']',0};
3556 *type=REG_EXPAND_SZ;
3564 if (strstrW(value,szMulti))
3565 *type = REG_MULTI_SZ;
3567 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3572 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3576 MSIRECORD * row = 0;
3577 static const WCHAR ExecSeqQuery[] =
3578 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3579 '`','R','e','g','i','s','t','r','y','`',0 };
3582 return ERROR_INVALID_HANDLE;
3584 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3585 if (rc != ERROR_SUCCESS)
3586 return ERROR_SUCCESS;
3588 rc = MSI_ViewExecute(view, 0);
3589 if (rc != ERROR_SUCCESS)
3591 MSI_ViewClose(view);
3592 msiobj_release(&view->hdr);
3596 /* increment progress bar each time action data is sent */
3597 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3601 static const WCHAR szHCR[] =
3602 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3603 'R','O','O','T','\\',0};
3604 static const WCHAR szHCU[] =
3605 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3606 'U','S','E','R','\\',0};
3607 static const WCHAR szHLM[] =
3608 {'H','K','E','Y','_','L','O','C','A','L','_',
3609 'M','A','C','H','I','N','E','\\',0};
3610 static const WCHAR szHU[] =
3611 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3613 LPSTR value_data = NULL;
3614 HKEY root_key, hkey;
3617 LPCWSTR szRoot, component, name, key, value;
3618 INT component_index;
3622 BOOL check_first = FALSE;
3624 rc = MSI_ViewFetch(view,&row);
3625 if (rc != ERROR_SUCCESS)
3630 ui_progress(package,2,0,0,0);
3637 component = MSI_RecordGetString(row, 6);
3638 component_index = get_loaded_component(package,component);
3640 if (!ACTION_VerifyComponentForAction(package, component_index,
3641 INSTALLSTATE_LOCAL))
3643 TRACE("Skipping write due to disabled component %s\n",
3644 debugstr_w(component));
3645 msiobj_release(&row->hdr);
3647 package->components[component_index].Action =
3648 package->components[component_index].Installed;
3653 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3655 name = MSI_RecordGetString(row, 4);
3656 if( MSI_RecordIsNull(row,5) && name )
3658 /* null values can have special meanings */
3659 if (name[0]=='-' && name[1] == 0)
3661 msiobj_release(&row->hdr);
3664 else if ((name[0]=='+' && name[1] == 0) ||
3665 (name[0] == '*' && name[1] == 0))
3670 root = MSI_RecordGetInteger(row,2);
3671 key = MSI_RecordGetString(row, 3);
3673 /* get the root key */
3676 case 0: root_key = HKEY_CLASSES_ROOT;
3679 case 1: root_key = HKEY_CURRENT_USER;
3682 case 2: root_key = HKEY_LOCAL_MACHINE;
3685 case 3: root_key = HKEY_USERS;
3689 ERR("Unknown root %i\n",root);
3696 msiobj_release(&row->hdr);
3700 deformat_string(package, key , &deformated);
3701 size = strlenW(deformated) + strlenW(szRoot) + 1;
3702 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3703 strcpyW(uikey,szRoot);
3704 strcatW(uikey,deformated);
3706 if (RegCreateKeyW( root_key, deformated, &hkey))
3708 ERR("Could not create key %s\n",debugstr_w(deformated));
3709 msiobj_release(&row->hdr);
3710 HeapFree(GetProcessHeap(),0,deformated);
3713 HeapFree(GetProcessHeap(),0,deformated);
3715 value = MSI_RecordGetString(row,5);
3717 value_data = parse_value(package, value, &type, &size);
3720 static const WCHAR szEmpty[] = {0};
3721 value_data = (LPSTR)strdupW(szEmpty);
3726 deformat_string(package, name, &deformated);
3728 /* get the double nulls to terminate SZ_MULTI */
3729 if (type == REG_MULTI_SZ)
3730 size +=sizeof(WCHAR);
3734 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
3736 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3741 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
3742 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3744 TRACE("value %s of %s checked already exists\n",
3745 debugstr_w(deformated), debugstr_w(uikey));
3749 TRACE("Checked and setting value %s of %s\n",
3750 debugstr_w(deformated), debugstr_w(uikey));
3751 if (deformated || size)
3752 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3756 uirow = MSI_CreateRecord(3);
3757 MSI_RecordSetStringW(uirow,2,deformated);
3758 MSI_RecordSetStringW(uirow,1,uikey);
3761 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3763 MSI_RecordSetStringW(uirow,3,value);
3765 ui_actiondata(package,szWriteRegistryValues,uirow);
3766 msiobj_release( &uirow->hdr );
3768 HeapFree(GetProcessHeap(),0,value_data);
3769 HeapFree(GetProcessHeap(),0,deformated);
3771 msiobj_release(&row->hdr);
3774 HeapFree(GetProcessHeap(),0,uikey);
3776 MSI_ViewClose(view);
3777 msiobj_release(&view->hdr);
3781 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3783 package->script->CurrentlyScripting = TRUE;
3785 return ERROR_SUCCESS;
3789 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3793 static const WCHAR q1[]=
3794 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3795 '`','R','e','g','i','s','t','r','y','`',0};
3798 MSIRECORD * row = 0;
3801 TRACE(" InstallValidate \n");
3803 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3804 if (rc != ERROR_SUCCESS)
3805 return ERROR_SUCCESS;
3807 rc = MSI_ViewExecute(view, 0);
3808 if (rc != ERROR_SUCCESS)
3810 MSI_ViewClose(view);
3811 msiobj_release(&view->hdr);
3816 rc = MSI_ViewFetch(view,&row);
3817 if (rc != ERROR_SUCCESS)
3824 msiobj_release(&row->hdr);
3826 MSI_ViewClose(view);
3827 msiobj_release(&view->hdr);
3829 total = total + progress * REG_PROGRESS_VALUE;
3830 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3831 for (i=0; i < package->loaded_files; i++)
3832 total += package->files[i].FileSize;
3833 ui_progress(package,0,total,0,0);
3835 for(i = 0; i < package->loaded_features; i++)
3837 MSIFEATURE* feature = &package->features[i];
3838 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
3839 debugstr_w(feature->Feature), feature->Installed, feature->Action,
3840 feature->ActionRequest);
3843 return ERROR_SUCCESS;
3846 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3849 MSIQUERY * view = NULL;
3850 MSIRECORD * row = 0;
3851 static const WCHAR ExecSeqQuery[] =
3852 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3853 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
3854 static const WCHAR title[]=
3855 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3857 TRACE("Checking launch conditions\n");
3859 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3860 if (rc != ERROR_SUCCESS)
3861 return ERROR_SUCCESS;
3863 rc = MSI_ViewExecute(view, 0);
3864 if (rc != ERROR_SUCCESS)
3866 MSI_ViewClose(view);
3867 msiobj_release(&view->hdr);
3872 while (rc == ERROR_SUCCESS)
3874 LPCWSTR cond = NULL;
3875 LPCWSTR message = NULL;
3877 rc = MSI_ViewFetch(view,&row);
3878 if (rc != ERROR_SUCCESS)
3884 cond = MSI_RecordGetString(row,1);
3886 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3889 message = MSI_RecordGetString(row,2);
3890 deformat_string(package,message,&deformated);
3891 MessageBoxW(NULL,deformated,title,MB_OK);
3892 HeapFree(GetProcessHeap(),0,deformated);
3893 rc = ERROR_FUNCTION_FAILED;
3895 msiobj_release(&row->hdr);
3897 MSI_ViewClose(view);
3898 msiobj_release(&view->hdr);
3902 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3905 MSICOMPONENT* cmp = &package->components[component_index];
3907 if (cmp->KeyPath[0]==0)
3909 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3912 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
3914 MSIRECORD * row = 0;
3916 LPWSTR deformated,buffer,deformated_name;
3918 static const WCHAR ExecSeqQuery[] =
3919 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3920 '`','R','e','g','i','s','t','r','y','`',' ',
3921 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
3922 ' ','=',' ' ,'\'','%','s','\'',0 };
3923 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
3924 static const WCHAR fmt2[]=
3925 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3927 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
3931 root = MSI_RecordGetInteger(row,2);
3932 key = MSI_RecordGetString(row, 3);
3933 name = MSI_RecordGetString(row, 4);
3934 deformat_string(package, key , &deformated);
3935 deformat_string(package, name, &deformated_name);
3937 len = strlenW(deformated) + 6;
3938 if (deformated_name)
3939 len+=strlenW(deformated_name);
3941 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3943 if (deformated_name)
3944 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3946 sprintfW(buffer,fmt,root,deformated);
3948 HeapFree(GetProcessHeap(),0,deformated);
3949 HeapFree(GetProcessHeap(),0,deformated_name);
3950 msiobj_release(&row->hdr);
3954 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
3956 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3962 j = get_loaded_file(package,cmp->KeyPath);
3966 LPWSTR p = strdupW(package->files[j].TargetPath);
3973 static HKEY openSharedDLLsKey()
3976 static const WCHAR path[] =
3977 {'S','o','f','t','w','a','r','e','\\',
3978 'M','i','c','r','o','s','o','f','t','\\',
3979 'W','i','n','d','o','w','s','\\',
3980 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3981 'S','h','a','r','e','d','D','L','L','s',0};
3983 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
3987 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
3992 DWORD sz = sizeof(count);
3995 hkey = openSharedDLLsKey();
3996 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
3997 if (rc != ERROR_SUCCESS)
4003 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
4007 hkey = openSharedDLLsKey();
4009 RegSetValueExW(hkey,path,0,REG_DWORD,
4010 (LPBYTE)&count,sizeof(count));
4012 RegDeleteValueW(hkey,path);
4018 * Return TRUE if the count should be written out and FALSE if not
4020 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
4026 /* only refcount DLLs */
4027 if (package->components[index].KeyPath[0]==0 ||
4028 package->components[index].Attributes &
4029 msidbComponentAttributesRegistryKeyPath ||
4030 package->components[index].Attributes &
4031 msidbComponentAttributesODBCDataSource)
4035 count = ACTION_GetSharedDLLsCount(package->components[index].
4037 write = (count > 0);
4039 if (package->components[index].Attributes &
4040 msidbComponentAttributesSharedDllRefCount)
4044 /* increment counts */
4045 for (j = 0; j < package->loaded_features; j++)
4049 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
4052 for (i = 0; i < package->features[j].ComponentCount; i++)
4054 if (package->features[j].Components[i] == index)
4058 /* decrement counts */
4059 for (j = 0; j < package->loaded_features; j++)
4062 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
4065 for (i = 0; i < package->features[j].ComponentCount; i++)
4067 if (package->features[j].Components[i] == index)
4072 /* ref count all the files in the component */
4074 for (j = 0; j < package->loaded_files; j++)
4076 if (package->files[j].Temporary)
4078 if (package->files[j].ComponentIndex == index)
4079 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
4082 /* add a count for permenent */
4083 if (package->components[index].Attributes &
4084 msidbComponentAttributesPermanent)
4087 package->components[index].RefCount = count;
4090 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
4091 package->components[index].RefCount);
4095 * Ok further analysis makes me think that this work is
4096 * actually done in the PublishComponents and PublishFeatures
4097 * step, and not here. It appears like the keypath and all that is
4098 * resolved in this step, however actually written in the Publish steps.
4099 * But we will leave it here for now because it is unclear
4101 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
4104 WCHAR squished_pc[GUID_SIZE];
4105 WCHAR squished_cc[GUID_SIZE];
4108 HKEY hkey=0,hkey2=0;
4111 return ERROR_INVALID_HANDLE;
4113 /* writes the Component and Features values to the registry */
4114 productcode = load_dynamic_property(package,szProductCode,&rc);
4118 rc = MSIREG_OpenComponents(&hkey);
4119 if (rc != ERROR_SUCCESS)
4122 squash_guid(productcode,squished_pc);
4123 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
4124 for (i = 0; i < package->loaded_components; i++)
4126 ui_progress(package,2,0,0,0);
4127 if (package->components[i].ComponentId[0]!=0)
4129 WCHAR *keypath = NULL;
4132 squash_guid(package->components[i].ComponentId,squished_cc);
4134 keypath = resolve_keypath(package,i);
4135 package->components[i].FullKeypath = keypath;
4137 /* do the refcounting */
4138 ACTION_RefCountComponent( package, i);
4140 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
4141 debugstr_w(package->components[i].Component),
4142 debugstr_w(squished_cc),
4143 debugstr_w(package->components[i].FullKeypath),
4144 package->components[i].RefCount);
4146 * Write the keypath out if the component is to be registered
4147 * and delete the key if the component is to be deregistered
4149 if (ACTION_VerifyComponentForAction(package, i,
4150 INSTALLSTATE_LOCAL))
4152 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
4153 if (rc != ERROR_SUCCESS)
4158 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
4159 (strlenW(keypath)+1)*sizeof(WCHAR));
4161 if (package->components[i].Attributes &
4162 msidbComponentAttributesPermanent)
4164 static const WCHAR szPermKey[] =
4165 { '0','0','0','0','0','0','0','0','0','0','0','0',
4166 '0','0','0','0','0','0','0', '0','0','0','0','0',
4167 '0','0','0','0','0','0','0','0',0};
4169 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
4171 (strlenW(keypath)+1)*sizeof(WCHAR));
4177 uirow = MSI_CreateRecord(3);
4178 MSI_RecordSetStringW(uirow,1,productcode);
4179 MSI_RecordSetStringW(uirow,2,package->components[i].
4181 MSI_RecordSetStringW(uirow,3,keypath);
4182 ui_actiondata(package,szProcessComponents,uirow);
4183 msiobj_release( &uirow->hdr );
4186 else if (ACTION_VerifyComponentForAction(package, i,
4187 INSTALLSTATE_ABSENT))
4191 rc = RegOpenKeyW(hkey,squished_cc,&hkey2);
4192 if (rc != ERROR_SUCCESS)
4195 RegDeleteValueW(hkey2,squished_pc);
4197 /* if the key is empty delete it */
4198 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
4200 if (res == ERROR_NO_MORE_ITEMS)
4201 RegDeleteKeyW(hkey,squished_cc);
4204 uirow = MSI_CreateRecord(2);
4205 MSI_RecordSetStringW(uirow,1,productcode);
4206 MSI_RecordSetStringW(uirow,2,package->components[i].
4208 ui_actiondata(package,szProcessComponents,uirow);
4209 msiobj_release( &uirow->hdr );
4214 HeapFree(GetProcessHeap(), 0, productcode);
4227 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
4228 LPWSTR lpszName, LONG_PTR lParam)
4231 typelib_struct *tl_struct = (typelib_struct*) lParam;
4232 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
4236 if (!IS_INTRESOURCE(lpszName))
4238 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
4242 sz = strlenW(tl_struct->source)+4;
4243 sz *= sizeof(WCHAR);
4245 if ((INT)lpszName == 1)
4246 tl_struct->path = strdupW(tl_struct->source);
4249 tl_struct->path = HeapAlloc(GetProcessHeap(),0,sz);
4250 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
4253 TRACE("trying %s\n", debugstr_w(tl_struct->path));
4254 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
4255 if (!SUCCEEDED(res))
4257 HeapFree(GetProcessHeap(),0,tl_struct->path);
4258 tl_struct->path = NULL;
4263 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
4264 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
4266 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4270 HeapFree(GetProcessHeap(),0,tl_struct->path);
4271 tl_struct->path = NULL;
4273 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
4274 ITypeLib_Release(tl_struct->ptLib);
4279 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4282 * OK this is a bit confusing.. I am given a _Component key and I believe
4283 * that the file that is being registered as a type library is the "key file
4284 * of that component" which I interpret to mean "The file in the KeyPath of
4289 MSIRECORD * row = 0;
4290 static const WCHAR Query[] =
4291 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4292 '`','T','y','p','e','L','i','b','`',0};
4295 return ERROR_INVALID_HANDLE;
4297 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4298 if (rc != ERROR_SUCCESS)
4299 return ERROR_SUCCESS;
4301 rc = MSI_ViewExecute(view, 0);
4302 if (rc != ERROR_SUCCESS)
4304 MSI_ViewClose(view);
4305 msiobj_release(&view->hdr);
4313 typelib_struct tl_struct;
4315 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
4317 rc = MSI_ViewFetch(view,&row);
4318 if (rc != ERROR_SUCCESS)
4324 component = MSI_RecordGetString(row,3);
4325 index = get_loaded_component(package,component);
4328 msiobj_release(&row->hdr);
4332 if (!ACTION_VerifyComponentForAction(package, index,
4333 INSTALLSTATE_LOCAL))
4335 TRACE("Skipping typelib reg due to disabled component\n");
4336 msiobj_release(&row->hdr);
4338 package->components[index].Action =
4339 package->components[index].Installed;
4344 package->components[index].Action = INSTALLSTATE_LOCAL;
4346 index = get_loaded_file(package,package->components[index].KeyPath);
4350 msiobj_release(&row->hdr);
4354 module = LoadLibraryExW(package->files[index].TargetPath, NULL,
4355 LOAD_LIBRARY_AS_DATAFILE);
4359 guid = load_dynamic_stringW(row,1);
4360 CLSIDFromString(guid, &tl_struct.clsid);
4361 HeapFree(GetProcessHeap(),0,guid);
4362 tl_struct.source = strdupW(package->files[index].TargetPath);
4363 tl_struct.path = NULL;
4365 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
4366 (LONG_PTR)&tl_struct);
4368 if (tl_struct.path != NULL)
4374 helpid = MSI_RecordGetString(row,6);
4377 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4378 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
4379 HeapFree(GetProcessHeap(),0,help);
4381 if (!SUCCEEDED(res))
4382 ERR("Failed to register type library %s\n",
4383 debugstr_w(tl_struct.path));
4386 ui_actiondata(package,szRegisterTypeLibraries,row);
4388 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
4391 ITypeLib_Release(tl_struct.ptLib);
4392 HeapFree(GetProcessHeap(),0,tl_struct.path);
4395 ERR("Failed to load type library %s\n",
4396 debugstr_w(tl_struct.source));
4398 FreeLibrary(module);
4399 HeapFree(GetProcessHeap(),0,tl_struct.source);
4402 ERR("Could not load file! %s\n",
4403 debugstr_w(package->files[index].TargetPath));
4404 msiobj_release(&row->hdr);
4406 MSI_ViewClose(view);
4407 msiobj_release(&view->hdr);
4411 static INT load_appid(MSIPACKAGE* package, MSIRECORD *row)
4413 DWORD index = package->loaded_appids;
4417 /* fill in the data */
4419 package->loaded_appids++;
4420 if (package->loaded_appids == 1)
4421 package->appids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIAPPID));
4423 package->appids = HeapReAlloc(GetProcessHeap(),0,
4424 package->appids, package->loaded_appids * sizeof(MSIAPPID));
4426 memset(&package->appids[index],0,sizeof(MSIAPPID));
4428 sz = IDENTIFIER_SIZE;
4429 MSI_RecordGetStringW(row, 1, package->appids[index].AppID, &sz);
4430 TRACE("loading appid %s\n",debugstr_w(package->appids[index].AppID));
4432 buffer = MSI_RecordGetString(row,2);
4433 deformat_string(package,buffer,&package->appids[index].RemoteServerName);
4435 package->appids[index].LocalServer = load_dynamic_stringW(row,3);
4436 package->appids[index].ServiceParameters = load_dynamic_stringW(row,4);
4437 package->appids[index].DllSurrogate = load_dynamic_stringW(row,5);
4439 package->appids[index].ActivateAtStorage = !MSI_RecordIsNull(row,6);
4440 package->appids[index].RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
4445 static INT load_given_appid(MSIPACKAGE *package, LPCWSTR appid)
4450 static const WCHAR ExecSeqQuery[] =
4451 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4452 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
4453 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
4458 /* check for appids already loaded */
4459 for (i = 0; i < package->loaded_appids; i++)
4460 if (strcmpiW(package->appids[i].AppID,appid)==0)
4462 TRACE("found appid %s at index %i\n",debugstr_w(appid),i);
4466 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, appid);
4470 rc = load_appid(package, row);
4471 msiobj_release(&row->hdr);
4476 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
4477 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid);
4479 static INT load_progid(MSIPACKAGE* package, MSIRECORD *row)
4481 DWORD index = package->loaded_progids;
4484 /* fill in the data */
4486 package->loaded_progids++;
4487 if (package->loaded_progids == 1)
4488 package->progids = HeapAlloc(GetProcessHeap(),0,sizeof(MSIPROGID));
4490 package->progids = HeapReAlloc(GetProcessHeap(),0,
4491 package->progids , package->loaded_progids * sizeof(MSIPROGID));
4493 memset(&package->progids[index],0,sizeof(MSIPROGID));
4495 package->progids[index].ProgID = load_dynamic_stringW(row,1);
4496 TRACE("loading progid %s\n",debugstr_w(package->progids[index].ProgID));
4498 buffer = MSI_RecordGetString(row,2);
4499 package->progids[index].ParentIndex = load_given_progid(package,buffer);
4500 if (package->progids[index].ParentIndex < 0 && buffer)
4501 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
4503 buffer = MSI_RecordGetString(row,3);
4504 package->progids[index].ClassIndex = load_given_class(package,buffer);
4505 if (package->progids[index].ClassIndex< 0 && buffer)
4506 FIXME("Unknown class %s\n",debugstr_w(buffer));
4508 package->progids[index].Description = load_dynamic_stringW(row,4);
4510 if (!MSI_RecordIsNull(row,6))
4512 INT icon_index = MSI_RecordGetInteger(row,6);
4513 LPWSTR FileName = load_dynamic_stringW(row,5);
4515 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4517 build_icon_path(package,FileName,&FilePath);
4519 package->progids[index].IconPath =
4520 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+10)*
4523 sprintfW(package->progids[index].IconPath,fmt,FilePath,icon_index);
4525 HeapFree(GetProcessHeap(),0,FilePath);
4526 HeapFree(GetProcessHeap(),0,FileName);
4530 buffer = MSI_RecordGetString(row,5);
4532 build_icon_path(package,buffer,&(package->progids[index].IconPath));
4535 package->progids[index].CurVerIndex = -1;
4536 package->progids[index].VersionIndIndex = -1;
4538 /* if we have a parent then we may be that parents CurVer */
4539 if (package->progids[index].ParentIndex >= 0 &&
4540 package->progids[index].ParentIndex != index)
4542 int pindex = package->progids[index].ParentIndex;
4543 while (package->progids[pindex].ParentIndex>= 0)
4544 pindex = package->progids[pindex].ParentIndex;
4546 FIXME("BAD BAD need to determing if we are really the CurVer\n");
4548 package->progids[index].CurVerIndex = pindex;
4549 package->progids[pindex].VersionIndIndex = index;
4555 static INT load_given_progid(MSIPACKAGE *package, LPCWSTR progid)
4560 static const WCHAR ExecSeqQuery[] =
4561 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4562 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
4563 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
4568 /* check for progids already loaded */
4569 for (i = 0; i < package->loaded_progids; i++)
4570 if (strcmpiW(package->progids[i].ProgID,progid)==0)
4572 TRACE("found progid %s at index %i\n",debugstr_w(progid), i);
4576 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, progid);
4580 rc = load_progid(package, row);
4581 msiobj_release(&row->hdr);
4586 static INT load_class(MSIPACKAGE* package, MSIRECORD *row)
4588 DWORD index = package->loaded_classes;
4592 /* fill in the data */
4594 package->loaded_classes++;
4595 if (package->loaded_classes== 1)
4596 package->classes = HeapAlloc(GetProcessHeap(),0,sizeof(MSICLASS));
4598 package->classes = HeapReAlloc(GetProcessHeap(),0,
4599 package->classes, package->loaded_classes * sizeof(MSICLASS));
4601 memset(&package->classes[index],0,sizeof(MSICLASS));
4603 sz = IDENTIFIER_SIZE;
4604 MSI_RecordGetStringW(row, 1, package->classes[index].CLSID, &sz);
4605 TRACE("loading class %s\n",debugstr_w(package->classes[index].CLSID));
4606 sz = IDENTIFIER_SIZE;
4607 MSI_RecordGetStringW(row, 2, package->classes[index].Context, &sz);
4608 buffer = MSI_RecordGetString(row,3);
4609 package->classes[index].ComponentIndex = get_loaded_component(package,
4612 package->classes[index].ProgIDText = load_dynamic_stringW(row,4);
4613 package->classes[index].ProgIDIndex =
4614 load_given_progid(package, package->classes[index].ProgIDText);
4616 package->classes[index].Description = load_dynamic_stringW(row,5);
4618 buffer = MSI_RecordGetString(row,6);
4620 package->classes[index].AppIDIndex =
4621 load_given_appid(package, buffer);
4623 package->classes[index].AppIDIndex = -1;
4625 package->classes[index].FileTypeMask = load_dynamic_stringW(row,7);
4627 if (!MSI_RecordIsNull(row,9))
4630 INT icon_index = MSI_RecordGetInteger(row,9);
4631 LPWSTR FileName = load_dynamic_stringW(row,8);
4633 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4635 build_icon_path(package,FileName,&FilePath);
4637 package->classes[index].IconPath =
4638 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4641 sprintfW(package->classes[index].IconPath,fmt,FilePath,icon_index);
4643 HeapFree(GetProcessHeap(),0,FilePath);
4644 HeapFree(GetProcessHeap(),0,FileName);
4648 buffer = MSI_RecordGetString(row,8);
4650 build_icon_path(package,buffer,&(package->classes[index].IconPath));
4653 if (!MSI_RecordIsNull(row,10))
4655 i = MSI_RecordGetInteger(row,10);
4656 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4658 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4659 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
4664 package->classes[index].DefInprocHandler = strdupW(ole2);
4667 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4670 package->classes[index].DefInprocHandler = strdupW(ole2);
4671 package->classes[index].DefInprocHandler32 = strdupW(ole32);
4677 package->classes[index].DefInprocHandler32 = load_dynamic_stringW(
4679 reduce_to_longfilename(package->classes[index].DefInprocHandler32);
4682 buffer = MSI_RecordGetString(row,11);
4683 deformat_string(package,buffer,&package->classes[index].Argument);
4685 buffer = MSI_RecordGetString(row,12);
4686 package->classes[index].FeatureIndex = get_loaded_feature(package,buffer);
4688 package->classes[index].Attributes = MSI_RecordGetInteger(row,13);
4694 * the Class table has 3 primary keys. Generally it is only
4695 * referenced through the first CLSID key. However when loading
4696 * all of the classes we need to make sure we do not ignore rows
4697 * with other Context and ComponentIndexs
4699 static INT load_given_class(MSIPACKAGE *package, LPCWSTR classid)
4704 static const WCHAR ExecSeqQuery[] =
4705 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4706 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
4707 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
4713 /* check for classes already loaded */
4714 for (i = 0; i < package->loaded_classes; i++)
4715 if (strcmpiW(package->classes[i].CLSID,classid)==0)
4717 TRACE("found class %s at index %i\n",debugstr_w(classid), i);
4721 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
4725 rc = load_class(package, row);
4726 msiobj_release(&row->hdr);
4731 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension);
4733 static INT load_mime(MSIPACKAGE* package, MSIRECORD *row)
4735 DWORD index = package->loaded_mimes;
4739 /* fill in the data */
4741 package->loaded_mimes++;
4742 if (package->loaded_mimes== 1)
4743 package->mimes= HeapAlloc(GetProcessHeap(),0,sizeof(MSIMIME));
4745 package->mimes= HeapReAlloc(GetProcessHeap(),0,
4746 package->mimes, package->loaded_mimes*
4749 memset(&package->mimes[index],0,sizeof(MSIMIME));
4751 package->mimes[index].ContentType = load_dynamic_stringW(row,1);
4752 TRACE("loading mime %s\n",debugstr_w(package->mimes[index].ContentType));
4754 buffer = MSI_RecordGetString(row,2);
4755 package->mimes[index].ExtensionIndex = load_given_extension(package,
4758 sz = IDENTIFIER_SIZE;
4759 MSI_RecordGetStringW(row,3,package->mimes[index].CLSID,&sz);
4760 package->mimes[index].ClassIndex= load_given_class(package,
4761 package->mimes[index].CLSID);
4766 static INT load_given_mime(MSIPACKAGE *package, LPCWSTR mime)
4771 static const WCHAR ExecSeqQuery[] =
4772 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4773 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
4774 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
4775 '\'','%','s','\'',0};
4780 /* check for mime already loaded */
4781 for (i = 0; i < package->loaded_mimes; i++)
4782 if (strcmpiW(package->mimes[i].ContentType,mime)==0)
4784 TRACE("found mime %s at index %i\n",debugstr_w(mime), i);
4788 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
4792 rc = load_mime(package, row);
4793 msiobj_release(&row->hdr);
4798 static INT load_extension(MSIPACKAGE* package, MSIRECORD *row)
4800 DWORD index = package->loaded_extensions;
4804 /* fill in the data */
4806 package->loaded_extensions++;
4807 if (package->loaded_extensions == 1)
4808 package->extensions = HeapAlloc(GetProcessHeap(),0,sizeof(MSIEXTENSION));
4810 package->extensions = HeapReAlloc(GetProcessHeap(),0,
4811 package->extensions, package->loaded_extensions*
4812 sizeof(MSIEXTENSION));
4814 memset(&package->extensions[index],0,sizeof(MSIEXTENSION));
4817 MSI_RecordGetStringW(row,1,package->extensions[index].Extension,&sz);
4818 TRACE("loading extension %s\n",
4819 debugstr_w(package->extensions[index].Extension));
4821 buffer = MSI_RecordGetString(row,2);
4822 package->extensions[index].ComponentIndex =
4823 get_loaded_component(package,buffer);
4825 package->extensions[index].ProgIDText = load_dynamic_stringW(row,3);
4826 package->extensions[index].ProgIDIndex = load_given_progid(package,
4827 package->extensions[index].ProgIDText);
4829 buffer = MSI_RecordGetString(row,4);
4830 package->extensions[index].MIMEIndex = load_given_mime(package,buffer);
4832 buffer = MSI_RecordGetString(row,5);
4833 package->extensions[index].FeatureIndex =
4834 get_loaded_feature(package,buffer);
4840 * While the extension table has 2 primary keys, this function is only looking
4841 * at the Extension key which is what is referenced as a forign key
4843 static INT load_given_extension(MSIPACKAGE *package, LPCWSTR extension)
4848 static const WCHAR ExecSeqQuery[] =
4849 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4850 '`','E','x','t','e','n','s','i','o','n','`',' ',
4851 'W','H','E','R','E',' ',
4852 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
4853 '\'','%','s','\'',0};
4858 /* check for extensions already loaded */
4859 for (i = 0; i < package->loaded_extensions; i++)
4860 if (strcmpiW(package->extensions[i].Extension,extension)==0)
4862 TRACE("extension %s already loaded at %i\n",debugstr_w(extension),
4867 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, extension);
4871 rc = load_extension(package, row);
4872 msiobj_release(&row->hdr);
4877 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
4879 MSIPACKAGE* package = (MSIPACKAGE*)param;
4880 DWORD index = package->loaded_verbs;
4883 /* fill in the data */
4885 package->loaded_verbs++;
4886 if (package->loaded_verbs == 1)
4887 package->verbs = HeapAlloc(GetProcessHeap(),0,sizeof(MSIVERB));
4889 package->verbs = HeapReAlloc(GetProcessHeap(),0,
4890 package->verbs , package->loaded_verbs * sizeof(MSIVERB));
4892 memset(&package->verbs[index],0,sizeof(MSIVERB));
4894 buffer = MSI_RecordGetString(row,1);
4895 package->verbs[index].ExtensionIndex = load_given_extension(package,buffer);
4896 if (package->verbs[index].ExtensionIndex < 0 && buffer)
4897 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
4899 package->verbs[index].Verb = load_dynamic_stringW(row,2);
4900 TRACE("loading verb %s\n",debugstr_w(package->verbs[index].Verb));
4901 package->verbs[index].Sequence = MSI_RecordGetInteger(row,3);
4903 buffer = MSI_RecordGetString(row,4);
4904 deformat_string(package,buffer,&package->verbs[index].Command);
4906 buffer = MSI_RecordGetString(row,5);
4907 deformat_string(package,buffer,&package->verbs[index].Argument);
4909 /* assosiate the verb with the correct extension */
4910 if (package->verbs[index].ExtensionIndex >= 0)
4912 MSIEXTENSION* extension = &package->extensions[package->verbs[index].
4914 int count = extension->VerbCount;
4917 FIXME("Exceeding max verb count! Increase that limit!!!\n");
4920 extension->VerbCount++;
4921 extension->Verbs[count] = index;
4925 return ERROR_SUCCESS;
4928 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
4933 INT component_index;
4934 MSIPACKAGE* package =(MSIPACKAGE*)param;
4938 clsid = MSI_RecordGetString(rec,1);
4939 context = MSI_RecordGetString(rec,2);
4940 buffer = MSI_RecordGetString(rec,3);
4941 component_index = get_loaded_component(package,buffer);
4943 for (i = 0; i < package->loaded_classes; i++)
4945 if (strcmpiW(clsid,package->classes[i].CLSID))
4947 if (strcmpW(context,package->classes[i].Context))
4949 if (component_index == package->classes[i].ComponentIndex)
4957 load_class(package, rec);
4959 return ERROR_SUCCESS;
4962 static VOID load_all_classes(MSIPACKAGE *package)
4964 UINT rc = ERROR_SUCCESS;
4967 static const WCHAR ExecSeqQuery[] =
4968 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
4969 '`','C','l','a','s','s','`',0};
4971 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4972 if (rc != ERROR_SUCCESS)
4975 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
4976 msiobj_release(&view->hdr);
4979 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
4983 INT component_index;
4984 MSIPACKAGE* package =(MSIPACKAGE*)param;
4988 extension = MSI_RecordGetString(rec,1);
4989 buffer = MSI_RecordGetString(rec,2);
4990 component_index = get_loaded_component(package,buffer);
4992 for (i = 0; i < package->loaded_extensions; i++)
4994 if (strcmpiW(extension,package->extensions[i].Extension))
4996 if (component_index == package->extensions[i].ComponentIndex)
5004 load_extension(package, rec);
5006 return ERROR_SUCCESS;
5009 static VOID load_all_extensions(MSIPACKAGE *package)
5011 UINT rc = ERROR_SUCCESS;
5014 static const WCHAR ExecSeqQuery[] =
5015 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5016 '`','E','x','t','e','n','s','i','o','n','`',0};
5018 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5019 if (rc != ERROR_SUCCESS)
5022 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
5023 msiobj_release(&view->hdr);
5026 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
5029 MSIPACKAGE* package =(MSIPACKAGE*)param;
5031 buffer = MSI_RecordGetString(rec,1);
5032 load_given_progid(package,buffer);
5033 return ERROR_SUCCESS;
5036 static VOID load_all_progids(MSIPACKAGE *package)
5038 UINT rc = ERROR_SUCCESS;
5041 static const WCHAR ExecSeqQuery[] =
5042 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
5043 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
5045 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5046 if (rc != ERROR_SUCCESS)
5049 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
5050 msiobj_release(&view->hdr);
5053 static VOID load_all_verbs(MSIPACKAGE *package)
5055 UINT rc = ERROR_SUCCESS;
5058 static const WCHAR ExecSeqQuery[] =
5059 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5060 '`','V','e','r','b','`',0};
5062 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5063 if (rc != ERROR_SUCCESS)
5066 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
5067 msiobj_release(&view->hdr);
5070 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
5073 MSIPACKAGE* package =(MSIPACKAGE*)param;
5075 buffer = MSI_RecordGetString(rec,1);
5076 load_given_mime(package,buffer);
5077 return ERROR_SUCCESS;
5080 static VOID load_all_mimes(MSIPACKAGE *package)
5082 UINT rc = ERROR_SUCCESS;
5085 static const WCHAR ExecSeqQuery[] =
5086 {'S','E','L','E','C','T',' ',
5087 '`','C','o','n','t','e','n','t','T','y','p','e','`',
5088 ' ','F','R','O','M',' ',
5089 '`','M','I','M','E','`',0};
5091 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5092 if (rc != ERROR_SUCCESS)
5095 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
5096 msiobj_release(&view->hdr);
5099 static void load_classes_and_such(MSIPACKAGE *package)
5101 TRACE("Loading all the class info and related tables\n");
5103 /* check if already loaded */
5104 if (package->classes || package->extensions || package->progids ||
5105 package->verbs || package->mimes)
5108 load_all_classes(package);
5109 load_all_extensions(package);
5110 load_all_progids(package);
5111 /* these loads must come after the other loads */
5112 load_all_verbs(package);
5113 load_all_mimes(package);
5116 static void mark_progid_for_install(MSIPACKAGE* package, INT index)
5121 if (index < 0 || index >= package->loaded_progids)
5124 progid = &package->progids[index];
5126 if (progid->InstallMe == TRUE)
5129 progid->InstallMe = TRUE;
5131 /* all children if this is a parent also install */
5132 for (i = 0; i < package->loaded_progids; i++)
5133 if (package->progids[i].ParentIndex == index)
5134 mark_progid_for_install(package,i);
5137 static void mark_mime_for_install(MSIPACKAGE* package, INT index)
5141 if (index < 0 || index >= package->loaded_mimes)
5144 mime = &package->mimes[index];
5146 if (mime->InstallMe == TRUE)
5149 mime->InstallMe = TRUE;
5152 static UINT register_appid(MSIPACKAGE *package, int appidIndex, LPCWSTR app )
5154 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5158 return ERROR_INVALID_HANDLE;
5160 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
5161 RegCreateKeyW(hkey2,package->appids[appidIndex].AppID,&hkey3);
5162 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
5163 (strlenW(app)+1)*sizeof(WCHAR));
5165 if (package->appids[appidIndex].RemoteServerName)
5168 static const WCHAR szRemoteServerName[] =
5169 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
5172 size = (strlenW(package->appids[appidIndex].RemoteServerName)+1) *
5175 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,
5176 (LPVOID)package->appids[appidIndex].RemoteServerName,
5180 if (package->appids[appidIndex].LocalServer)
5182 static const WCHAR szLocalService[] =
5183 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
5185 size = (strlenW(package->appids[appidIndex].LocalServer)+1) *
5188 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,
5189 (LPVOID)package->appids[appidIndex].LocalServer,size);
5192 if (package->appids[appidIndex].ServiceParameters)
5194 static const WCHAR szService[] =
5195 {'S','e','r','v','i','c','e',
5196 'P','a','r','a','m','e','t','e','r','s',0};
5198 size = (strlenW(package->appids[appidIndex].ServiceParameters)+1) *
5200 RegSetValueExW(hkey3,szService,0,REG_SZ,
5201 (LPVOID)package->appids[appidIndex].ServiceParameters,
5205 if (package->appids[appidIndex].DllSurrogate)
5207 static const WCHAR szDLL[] =
5208 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
5210 size = (strlenW(package->appids[appidIndex].DllSurrogate)+1) *
5212 RegSetValueExW(hkey3,szDLL,0,REG_SZ,
5213 (LPVOID)package->appids[appidIndex].DllSurrogate,size);
5216 if (package->appids[appidIndex].ActivateAtStorage)
5218 static const WCHAR szActivate[] =
5219 {'A','c','t','i','v','a','t','e','A','s',
5220 'S','t','o','r','a','g','e',0};
5221 static const WCHAR szY[] = {'Y',0};
5223 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
5226 if (package->appids[appidIndex].RunAsInteractiveUser)
5228 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
5229 static const WCHAR szUser[] =
5230 {'I','n','t','e','r','a','c','t','i','v','e',' ',
5233 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,sizeof(szUser));
5238 return ERROR_SUCCESS;
5241 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
5244 * Again I am assuming the words, "Whose key file represents" when referring
5245 * to a Component as to meaning that Components KeyPath file
5250 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5251 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
5252 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 };
5253 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
5254 static const WCHAR szSpace[] = {' ',0};
5255 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
5256 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
5257 HKEY hkey,hkey2,hkey3;
5258 BOOL install_on_demand = FALSE;
5262 return ERROR_INVALID_HANDLE;
5264 load_classes_and_such(package);
5265 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
5266 if (rc != ERROR_SUCCESS)
5267 return ERROR_FUNCTION_FAILED;
5269 /* install_on_demand should be set if OLE supports install on demand OLE
5270 * servers. For now i am defaulting to FALSE because i do not know how to
5271 * check, and i am told our builtin OLE does not support it
5274 for (i = 0; i < package->loaded_classes; i++)
5280 if (package->classes[i].ComponentIndex < 0)
5285 index = package->classes[i].ComponentIndex;
5286 f_index = package->classes[i].FeatureIndex;
5289 * yes. MSDN says that these are based on _Feature_ not on
5290 * Component. So verify the feature is to be installed
5292 if ((!ACTION_VerifyFeatureForAction(package, f_index,
5293 INSTALLSTATE_LOCAL)) &&
5294 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
5295 f_index, INSTALLSTATE_ADVERTISED)))
5297 TRACE("Skipping class %s reg due to disabled feature %s\n",
5298 debugstr_w(package->classes[i].CLSID),
5299 debugstr_w(package->features[f_index].Feature));
5304 TRACE("Registering index %i class %s\n",i,
5305 debugstr_w(package->classes[i].CLSID));
5307 package->classes[i].Installed = TRUE;
5308 if (package->classes[i].ProgIDIndex >= 0)
5309 mark_progid_for_install(package, package->classes[i].ProgIDIndex);
5311 RegCreateKeyW(hkey,package->classes[i].CLSID,&hkey2);
5313 if (package->classes[i].Description)
5314 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)package->classes[i].
5315 Description, (strlenW(package->classes[i].
5316 Description)+1)*sizeof(WCHAR));
5318 RegCreateKeyW(hkey2,package->classes[i].Context,&hkey3);
5319 index = get_loaded_file(package,package->components[index].KeyPath);
5322 /* the context server is a short path name
5323 * except for if it is InprocServer32...
5325 if (strcmpiW(package->classes[i].Context,szInprocServer32)!=0)
5328 sz = GetShortPathNameW(package->files[index].TargetPath, NULL, 0);
5331 ERR("Unable to find short path for CLSID COM Server\n");
5336 size = sz * sizeof(WCHAR);
5338 if (package->classes[i].Argument)
5340 size += strlenW(package->classes[i].Argument) *
5342 size += sizeof(WCHAR);
5345 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5346 GetShortPathNameW(package->files[index].TargetPath, argument,
5349 if (package->classes[i].Argument)
5351 strcatW(argument,szSpace);
5352 strcatW(argument,package->classes[i].Argument);
5358 size = lstrlenW(package->files[index].TargetPath) * sizeof(WCHAR);
5360 if (package->classes[i].Argument)
5362 size += strlenW(package->classes[i].Argument) * sizeof(WCHAR);
5363 size += sizeof(WCHAR);
5366 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
5367 strcpyW(argument, package->files[index].TargetPath);
5369 if (package->classes[i].Argument)
5371 strcatW(argument,szSpace);
5372 strcatW(argument,package->classes[i].Argument);
5378 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
5379 HeapFree(GetProcessHeap(),0,argument);
5384 if (package->classes[i].ProgIDIndex >= 0 ||
5385 package->classes[i].ProgIDText)
5389 if (package->classes[i].ProgIDIndex >= 0)
5390 progid = package->progids[
5391 package->classes[i].ProgIDIndex].ProgID;
5393 progid = package->classes[i].ProgIDText;
5395 RegCreateKeyW(hkey2,szProgID,&hkey3);
5396 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)progid,
5397 (strlenW(progid)+1) *sizeof(WCHAR));
5400 if (package->classes[i].ProgIDIndex >= 0 &&
5401 package->progids[package->classes[i].ProgIDIndex].
5402 VersionIndIndex >= 0)
5404 LPWSTR viprogid = strdupW(package->progids[package->progids[
5405 package->classes[i].ProgIDIndex].VersionIndIndex].
5407 RegCreateKeyW(hkey2,szVIProgID,&hkey3);
5408 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)viprogid,
5409 (strlenW(viprogid)+1) *sizeof(WCHAR));
5411 HeapFree(GetProcessHeap(), 0, viprogid);
5415 if (package->classes[i].AppIDIndex >= 0)
5417 RegSetValueExW(hkey2,szAppID,0,REG_SZ,
5418 (LPVOID)package->appids[package->classes[i].AppIDIndex].AppID,
5419 (strlenW(package->appids[package->classes[i].AppIDIndex].AppID)+1)
5422 register_appid(package,package->classes[i].AppIDIndex,
5423 package->classes[i].Description);
5426 if (package->classes[i].IconPath)
5428 static const WCHAR szDefaultIcon[] =
5429 {'D','e','f','a','u','l','t','I','c','o','n',0};
5431 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
5433 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5434 (LPVOID)package->classes[i].IconPath,
5435 (strlenW(package->classes[i].IconPath)+1) *
5441 if (package->classes[i].DefInprocHandler)
5443 static const WCHAR szInproc[] =
5444 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
5446 size = (strlenW(package->classes[i].DefInprocHandler) + 1) *
5448 RegCreateKeyW(hkey2,szInproc,&hkey3);
5449 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5450 (LPVOID)package->classes[i].DefInprocHandler, size);
5454 if (package->classes[i].DefInprocHandler32)
5456 static const WCHAR szInproc32[] =
5457 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
5459 size = (strlenW(package->classes[i].DefInprocHandler32) + 1) *
5462 RegCreateKeyW(hkey2,szInproc32,&hkey3);
5463 RegSetValueExW(hkey3,NULL,0,REG_SZ,
5464 (LPVOID)package->classes[i].DefInprocHandler32,size);
5470 /* if there is a FileTypeMask, register the FileType */
5471 if (package->classes[i].FileTypeMask)
5476 ptr = package->classes[i].FileTypeMask;
5479 ptr2 = strchrW(ptr,';');
5482 keyname = HeapAlloc(GetProcessHeap(),0,(strlenW(szFileType_fmt)+
5483 strlenW(package->classes[i].CLSID) + 4)
5485 sprintfW(keyname,szFileType_fmt, package->classes[i].CLSID,
5488 RegCreateKeyW(HKEY_CLASSES_ROOT,keyname,&hkey2);
5489 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPVOID)ptr,
5490 strlenW(ptr)*sizeof(WCHAR));
5492 HeapFree(GetProcessHeap(), 0, keyname);
5503 uirow = MSI_CreateRecord(1);
5505 MSI_RecordSetStringW(uirow,1,package->classes[i].CLSID);
5506 ui_actiondata(package,szRegisterClassInfo,uirow);
5507 msiobj_release(&uirow->hdr);
5514 static UINT register_progid_base(MSIPACKAGE* package, MSIPROGID* progid,
5517 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5518 static const WCHAR szDefaultIcon[] =
5519 {'D','e','f','a','u','l','t','I','c','o','n',0};
5522 RegCreateKeyW(HKEY_CLASSES_ROOT,progid->ProgID,&hkey);
5524 if (progid->Description)
5526 RegSetValueExW(hkey,NULL,0,REG_SZ,
5527 (LPVOID)progid->Description,
5528 (strlenW(progid->Description)+1) *
5532 if (progid->ClassIndex >= 0)
5534 RegCreateKeyW(hkey,szCLSID,&hkey2);
5535 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5536 (LPVOID)package->classes[progid->ClassIndex].CLSID,
5537 (strlenW(package->classes[progid->ClassIndex].CLSID)+1)
5541 strcpyW(clsid,package->classes[progid->ClassIndex].CLSID);
5547 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
5550 if (progid->IconPath)
5552 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5554 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5555 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5558 return ERROR_SUCCESS;
5561 static UINT register_progid(MSIPACKAGE *package, MSIPROGID* progid,
5564 UINT rc = ERROR_SUCCESS;
5566 if (progid->ParentIndex < 0)
5567 rc = register_progid_base(package, progid, clsid);
5572 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
5573 static const WCHAR szDefaultIcon[] =
5574 {'D','e','f','a','u','l','t','I','c','o','n',0};
5575 static const WCHAR szCurVer[] =
5576 {'C','u','r','V','e','r',0};
5578 /* check if already registered */
5579 RegCreateKeyExW(HKEY_CLASSES_ROOT, progid->ProgID, 0, NULL, 0,
5580 KEY_ALL_ACCESS, NULL, &hkey, &disp );
5581 if (disp == REG_OPENED_EXISTING_KEY)
5583 TRACE("Key already registered\n");
5588 TRACE("Registering Parent %s index %i\n",
5589 debugstr_w(package->progids[progid->ParentIndex].ProgID),
5590 progid->ParentIndex);
5591 rc = register_progid(package,&package->progids[progid->ParentIndex],
5594 /* clsid is same as parent */
5595 RegCreateKeyW(hkey,szCLSID,&hkey2);
5596 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
5602 if (progid->Description)
5604 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid->Description,
5605 (strlenW(progid->Description)+1) * sizeof(WCHAR));
5608 if (progid->IconPath)
5610 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
5611 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
5612 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
5616 /* write out the current version */
5617 if (progid->CurVerIndex >= 0)
5619 RegCreateKeyW(hkey,szCurVer,&hkey2);
5620 RegSetValueExW(hkey2,NULL,0,REG_SZ,
5621 (LPVOID)package->progids[progid->CurVerIndex].ProgID,
5622 (strlenW(package->progids[progid->CurVerIndex].ProgID)+1) *
5632 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
5638 return ERROR_INVALID_HANDLE;
5640 load_classes_and_such(package);
5642 for (i = 0; i < package->loaded_progids; i++)
5644 WCHAR clsid[0x1000];
5646 /* check if this progid is to be installed */
5647 package->progids[i].InstallMe = ((package->progids[i].InstallMe) ||
5648 (package->progids[i].ClassIndex >= 0 &&
5649 package->classes[package->progids[i].ClassIndex].Installed));
5651 if (!package->progids[i].InstallMe)
5653 TRACE("progid %s not scheduled to be installed\n",
5654 debugstr_w(package->progids[i].ProgID));
5658 TRACE("Registering progid %s index %i\n",
5659 debugstr_w(package->progids[i].ProgID), i);
5661 register_progid(package,&package->progids[i],clsid);
5663 uirow = MSI_CreateRecord(1);
5664 MSI_RecordSetStringW(uirow,1,package->progids[i].ProgID);
5665 ui_actiondata(package,szRegisterProgIdInfo,uirow);
5666 msiobj_release(&uirow->hdr);
5669 return ERROR_SUCCESS;
5672 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
5676 LPWSTR SystemFolder;
5680 static const WCHAR szInstaller[] =
5681 {'M','i','c','r','o','s','o','f','t','\\',
5682 'I','n','s','t','a','l','l','e','r','\\',0};
5683 static const WCHAR szFolder[] =
5684 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
5686 ProductCode = load_dynamic_property(package,szProductCode,&rc);
5690 SystemFolder = load_dynamic_property(package,szFolder,NULL);
5692 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
5694 create_full_pathW(dest);
5696 *FilePath = build_directory_name(2, dest, icon_name);
5698 HeapFree(GetProcessHeap(),0,SystemFolder);
5699 HeapFree(GetProcessHeap(),0,ProductCode);
5700 HeapFree(GetProcessHeap(),0,dest);
5701 return ERROR_SUCCESS;
5704 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
5708 MSIRECORD * row = 0;
5709 static const WCHAR Query[] =
5710 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5711 '`','S','h','o','r','t','c','u','t','`',0};
5717 return ERROR_INVALID_HANDLE;
5719 res = CoInitialize( NULL );
5722 ERR("CoInitialize failed\n");
5723 return ERROR_FUNCTION_FAILED;
5726 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5727 if (rc != ERROR_SUCCESS)
5728 return ERROR_SUCCESS;
5730 rc = MSI_ViewExecute(view, 0);
5731 if (rc != ERROR_SUCCESS)
5733 MSI_ViewClose(view);
5734 msiobj_release(&view->hdr);
5740 LPWSTR target_file, target_folder;
5742 WCHAR filename[0x100];
5745 static const WCHAR szlnk[]={'.','l','n','k',0};
5747 rc = MSI_ViewFetch(view,&row);
5748 if (rc != ERROR_SUCCESS)
5754 buffer = MSI_RecordGetString(row,4);
5755 index = get_loaded_component(package,buffer);
5759 msiobj_release(&row->hdr);
5763 if (!ACTION_VerifyComponentForAction(package, index,
5764 INSTALLSTATE_LOCAL))
5766 TRACE("Skipping shortcut creation due to disabled component\n");
5767 msiobj_release(&row->hdr);
5769 package->components[index].Action =
5770 package->components[index].Installed;
5775 package->components[index].Action = INSTALLSTATE_LOCAL;
5777 ui_actiondata(package,szCreateShortcuts,row);
5779 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
5780 &IID_IShellLinkW, (LPVOID *) &sl );
5784 ERR("Is IID_IShellLink\n");
5785 msiobj_release(&row->hdr);
5789 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
5792 ERR("Is IID_IPersistFile\n");
5793 msiobj_release(&row->hdr);
5797 buffer = MSI_RecordGetString(row,2);
5798 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
5800 /* may be needed because of a bug somehwere else */
5801 create_full_pathW(target_folder);
5804 MSI_RecordGetStringW(row,3,filename,&sz);
5805 reduce_to_longfilename(filename);
5806 if (!strchrW(filename,'.') || strcmpiW(strchrW(filename,'.'),szlnk))
5807 strcatW(filename,szlnk);
5808 target_file = build_directory_name(2, target_folder, filename);
5809 HeapFree(GetProcessHeap(),0,target_folder);
5811 buffer = MSI_RecordGetString(row,5);
5812 if (strchrW(buffer,'['))
5815 deformat_string(package,buffer,&deformated);
5816 IShellLinkW_SetPath(sl,deformated);
5817 HeapFree(GetProcessHeap(),0,deformated);
5822 FIXME("poorly handled shortcut format, advertised shortcut\n");
5823 keypath = strdupW(package->components[index].FullKeypath);
5824 IShellLinkW_SetPath(sl,keypath);
5825 HeapFree(GetProcessHeap(),0,keypath);
5828 if (!MSI_RecordIsNull(row,6))
5831 buffer = MSI_RecordGetString(row,6);
5832 deformat_string(package,buffer,&deformated);
5833 IShellLinkW_SetArguments(sl,deformated);
5834 HeapFree(GetProcessHeap(),0,deformated);
5837 if (!MSI_RecordIsNull(row,7))
5839 buffer = MSI_RecordGetString(row,7);
5840 IShellLinkW_SetDescription(sl,buffer);
5843 if (!MSI_RecordIsNull(row,8))
5844 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
5846 if (!MSI_RecordIsNull(row,9))
5851 buffer = MSI_RecordGetString(row,9);
5853 build_icon_path(package,buffer,&Path);
5854 index = MSI_RecordGetInteger(row,10);
5856 IShellLinkW_SetIconLocation(sl,Path,index);
5857 HeapFree(GetProcessHeap(),0,Path);
5860 if (!MSI_RecordIsNull(row,11))
5861 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
5863 if (!MSI_RecordIsNull(row,12))
5866 buffer = MSI_RecordGetString(row,12);
5867 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
5868 IShellLinkW_SetWorkingDirectory(sl,Path);
5869 HeapFree(GetProcessHeap(), 0, Path);
5872 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
5873 IPersistFile_Save(pf,target_file,FALSE);
5875 HeapFree(GetProcessHeap(),0,target_file);
5877 IPersistFile_Release( pf );
5878 IShellLinkW_Release( sl );
5880 msiobj_release(&row->hdr);
5882 MSI_ViewClose(view);
5883 msiobj_release(&view->hdr);
5893 * 99% of the work done here is only done for
5894 * advertised installs. However this is where the
5895 * Icon table is processed and written out
5896 * so that is what I am going to do here.
5898 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
5902 MSIRECORD * row = 0;
5903 static const WCHAR Query[]=
5904 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5905 '`','I','c','o','n','`',0};
5907 /* for registry stuff */
5911 static const WCHAR szProductName[] =
5912 {'P','r','o','d','u','c','t','N','a','m','e',0};
5913 static const WCHAR szPackageCode[] =
5914 {'P','a','c','k','a','g','e','C','o','d','e',0};
5915 static const WCHAR szLanguage[] =
5916 {'L','a','n','g','u','a','g','e',0};
5917 static const WCHAR szProductLanguage[] =
5918 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
5919 static const WCHAR szProductIcon[] =
5920 {'P','r','o','d','u','c','t','I','c','o','n',0};
5921 static const WCHAR szARPProductIcon[] =
5922 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
5923 static const WCHAR szProductVersion[] =
5924 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
5925 static const WCHAR szVersion[] =
5926 {'V','e','r','s','i','o','n',0};
5930 MSIHANDLE hDb, hSumInfo;
5933 return ERROR_INVALID_HANDLE;
5935 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
5936 if (rc != ERROR_SUCCESS)
5939 rc = MSI_ViewExecute(view, 0);
5940 if (rc != ERROR_SUCCESS)
5942 MSI_ViewClose(view);
5943 msiobj_release(&view->hdr);
5950 LPWSTR FilePath=NULL;
5951 LPCWSTR FileName=NULL;
5954 rc = MSI_ViewFetch(view,&row);
5955 if (rc != ERROR_SUCCESS)
5961 FileName = MSI_RecordGetString(row,1);
5964 ERR("Unable to get FileName\n");
5965 msiobj_release(&row->hdr);
5969 build_icon_path(package,FileName,&FilePath);
5971 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
5973 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
5974 FILE_ATTRIBUTE_NORMAL, NULL);
5976 if (the_file == INVALID_HANDLE_VALUE)
5978 ERR("Unable to create file %s\n",debugstr_w(FilePath));
5979 msiobj_release(&row->hdr);
5980 HeapFree(GetProcessHeap(),0,FilePath);
5988 rc = MSI_RecordReadStream(row,2,buffer,&sz);
5989 if (rc != ERROR_SUCCESS)
5991 ERR("Failed to get stream\n");
5992 CloseHandle(the_file);
5993 DeleteFileW(FilePath);
5996 WriteFile(the_file,buffer,sz,&write,NULL);
5997 } while (sz == 1024);
5999 HeapFree(GetProcessHeap(),0,FilePath);
6001 CloseHandle(the_file);
6002 msiobj_release(&row->hdr);
6004 MSI_ViewClose(view);
6005 msiobj_release(&view->hdr);
6008 /* ok there is a lot more done here but i need to figure out what */
6009 productcode = load_dynamic_property(package,szProductCode,&rc);
6013 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
6014 if (rc != ERROR_SUCCESS)
6017 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6018 if (rc != ERROR_SUCCESS)
6022 buffer = load_dynamic_property(package,szProductName,NULL);
6023 size = strlenW(buffer)*sizeof(WCHAR);
6024 RegSetValueExW(hukey,szProductName,0,REG_SZ, (BYTE *)buffer,size);
6025 HeapFree(GetProcessHeap(),0,buffer);
6027 buffer = load_dynamic_property(package,szProductLanguage,NULL);
6028 size = sizeof(DWORD);
6029 langid = atoiW(buffer);
6030 RegSetValueExW(hukey,szLanguage,0,REG_DWORD, (BYTE *)&langid,size);
6031 HeapFree(GetProcessHeap(),0,buffer);
6033 buffer = load_dynamic_property(package,szARPProductIcon,NULL);
6037 build_icon_path(package,buffer,&path);
6038 size = strlenW(path) * sizeof(WCHAR);
6039 RegSetValueExW(hukey,szProductIcon,0,REG_SZ, (BYTE *)path,size);
6041 HeapFree(GetProcessHeap(),0,buffer);
6043 buffer = load_dynamic_property(package,szProductVersion,NULL);
6046 DWORD verdword = build_version_dword(buffer);
6047 size = sizeof(DWORD);
6048 RegSetValueExW(hukey,szVersion,0,REG_DWORD, (BYTE *)&verdword,size);
6050 HeapFree(GetProcessHeap(),0,buffer);
6052 FIXME("Need to write more keys to the user registry\n");
6054 hDb= alloc_msihandle( &package->db->hdr );
6055 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
6056 MsiCloseHandle(hDb);
6057 if (rc == ERROR_SUCCESS)
6059 WCHAR guidbuffer[0x200];
6061 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
6063 if (rc == ERROR_SUCCESS)
6065 WCHAR squashed[GUID_SIZE];
6066 /* for now we only care about the first guid */
6067 LPWSTR ptr = strchrW(guidbuffer,';');
6069 squash_guid(guidbuffer,squashed);
6070 size = strlenW(squashed)*sizeof(WCHAR);
6071 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
6076 ERR("Unable to query Revision_Number... \n");
6079 MsiCloseHandle(hSumInfo);
6083 ERR("Unable to open Summary Information\n");
6089 HeapFree(GetProcessHeap(),0,productcode);
6096 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
6100 MSIRECORD * row = 0;
6101 static const WCHAR ExecSeqQuery[] =
6102 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6103 '`','I','n','i','F','i','l','e','`',0};
6104 static const WCHAR szWindowsFolder[] =
6105 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
6107 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6108 if (rc != ERROR_SUCCESS)
6110 TRACE("no IniFile table\n");
6111 return ERROR_SUCCESS;
6114 rc = MSI_ViewExecute(view, 0);
6115 if (rc != ERROR_SUCCESS)
6117 MSI_ViewClose(view);
6118 msiobj_release(&view->hdr);
6124 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
6125 LPWSTR deformated_section, deformated_key, deformated_value;
6126 LPWSTR folder, fullname = NULL;
6128 INT component_index,action;
6130 rc = MSI_ViewFetch(view,&row);
6131 if (rc != ERROR_SUCCESS)
6137 component = MSI_RecordGetString(row, 8);
6138 component_index = get_loaded_component(package,component);
6140 if (!ACTION_VerifyComponentForAction(package, component_index,
6141 INSTALLSTATE_LOCAL))
6143 TRACE("Skipping ini file due to disabled component %s\n",
6144 debugstr_w(component));
6145 msiobj_release(&row->hdr);
6147 package->components[component_index].Action =
6148 package->components[component_index].Installed;
6153 package->components[component_index].Action = INSTALLSTATE_LOCAL;
6155 identifier = MSI_RecordGetString(row,1);
6156 filename = MSI_RecordGetString(row,2);
6157 dirproperty = MSI_RecordGetString(row,3);
6158 section = MSI_RecordGetString(row,4);
6159 key = MSI_RecordGetString(row,5);
6160 value = MSI_RecordGetString(row,6);
6161 action = MSI_RecordGetInteger(row,7);
6163 deformat_string(package,section,&deformated_section);
6164 deformat_string(package,key,&deformated_key);
6165 deformat_string(package,value,&deformated_value);
6169 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
6171 folder = load_dynamic_property(package,dirproperty,NULL);
6174 folder = load_dynamic_property(package, szWindowsFolder, NULL);
6178 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
6182 fullname = build_directory_name(3, folder, filename, NULL);
6186 TRACE("Adding value %s to section %s in %s\n",
6187 debugstr_w(deformated_key), debugstr_w(deformated_section),
6188 debugstr_w(fullname));
6189 WritePrivateProfileStringW(deformated_section, deformated_key,
6190 deformated_value, fullname);
6192 else if (action == 1)
6195 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
6196 returned, 10, fullname);
6197 if (returned[0] == 0)
6199 TRACE("Adding value %s to section %s in %s\n",
6200 debugstr_w(deformated_key), debugstr_w(deformated_section),
6201 debugstr_w(fullname));
6203 WritePrivateProfileStringW(deformated_section, deformated_key,
6204 deformated_value, fullname);
6207 else if (action == 3)
6209 FIXME("Append to existing section not yet implemented\n");
6212 uirow = MSI_CreateRecord(4);
6213 MSI_RecordSetStringW(uirow,1,identifier);
6214 MSI_RecordSetStringW(uirow,2,deformated_section);
6215 MSI_RecordSetStringW(uirow,3,deformated_key);
6216 MSI_RecordSetStringW(uirow,4,deformated_value);
6217 ui_actiondata(package,szWriteIniValues,uirow);
6218 msiobj_release( &uirow->hdr );
6220 HeapFree(GetProcessHeap(),0,fullname);
6221 HeapFree(GetProcessHeap(),0,folder);
6222 HeapFree(GetProcessHeap(),0,deformated_key);
6223 HeapFree(GetProcessHeap(),0,deformated_value);
6224 HeapFree(GetProcessHeap(),0,deformated_section);
6225 msiobj_release(&row->hdr);
6227 MSI_ViewClose(view);
6228 msiobj_release(&view->hdr);
6232 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
6236 MSIRECORD * row = 0;
6237 static const WCHAR ExecSeqQuery[] =
6238 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6239 '`','S','e','l','f','R','e','g','`',0};
6241 static const WCHAR ExeStr[] =
6242 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
6243 static const WCHAR close[] = {'\"',0};
6245 PROCESS_INFORMATION info;
6248 memset(&si,0,sizeof(STARTUPINFOW));
6250 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6251 if (rc != ERROR_SUCCESS)
6253 TRACE("no SelfReg table\n");
6254 return ERROR_SUCCESS;
6257 rc = MSI_ViewExecute(view, 0);
6258 if (rc != ERROR_SUCCESS)
6260 MSI_ViewClose(view);
6261 msiobj_release(&view->hdr);
6272 rc = MSI_ViewFetch(view,&row);
6273 if (rc != ERROR_SUCCESS)
6279 filename = MSI_RecordGetString(row,1);
6280 index = get_loaded_file(package,filename);
6284 ERR("Unable to find file id %s\n",debugstr_w(filename));
6285 msiobj_release(&row->hdr);
6289 len = strlenW(ExeStr);
6290 len += strlenW(package->files[index].TargetPath);
6293 FullName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
6294 strcpyW(FullName,ExeStr);
6295 strcatW(FullName,package->files[index].TargetPath);
6296 strcatW(FullName,close);
6298 TRACE("Registering %s\n",debugstr_w(FullName));
6299 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL,
6300 c_colon, &si, &info);
6303 msi_dialog_check_messages(info.hProcess);
6305 HeapFree(GetProcessHeap(),0,FullName);
6306 msiobj_release(&row->hdr);
6308 MSI_ViewClose(view);
6309 msiobj_release(&view->hdr);
6313 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
6322 return ERROR_INVALID_HANDLE;
6324 productcode = load_dynamic_property(package,szProductCode,&rc);
6328 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
6329 if (rc != ERROR_SUCCESS)
6332 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
6333 if (rc != ERROR_SUCCESS)
6336 /* here the guids are base 85 encoded */
6337 for (i = 0; i < package->loaded_features; i++)
6343 BOOL absent = FALSE;
6345 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL) &&
6346 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_SOURCE) &&
6347 !ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_ADVERTISED))
6350 size = package->features[i].ComponentCount*21;
6352 if (package->features[i].Feature_Parent[0])
6353 size += strlenW(package->features[i].Feature_Parent)+2;
6355 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
6358 for (j = 0; j < package->features[i].ComponentCount; j++)
6361 memset(buf,0,sizeof(buf));
6362 if (package->components
6363 [package->features[i].Components[j]].ComponentId[0]!=0)
6365 TRACE("From %s\n",debugstr_w(package->components
6366 [package->features[i].Components[j]].ComponentId));
6367 CLSIDFromString(package->components
6368 [package->features[i].Components[j]].ComponentId,
6370 encode_base85_guid(&clsid,buf);
6371 TRACE("to %s\n",debugstr_w(buf));
6375 if (package->features[i].Feature_Parent[0])
6377 static const WCHAR sep[] = {'\2',0};
6379 strcatW(data,package->features[i].Feature_Parent);
6382 size = (strlenW(data)+1)*sizeof(WCHAR);
6383 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
6385 HeapFree(GetProcessHeap(),0,data);
6389 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
6390 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6391 (LPSTR)package->features[i].Feature_Parent,size);
6395 size = (strlenW(package->features[i].Feature_Parent)+2)*
6397 data = HeapAlloc(GetProcessHeap(),0,size);
6399 strcpyW(&data[1],package->features[i].Feature_Parent);
6400 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
6402 HeapFree(GetProcessHeap(),0,data);
6409 HeapFree(GetProcessHeap(), 0, productcode);
6413 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
6420 static WCHAR szNONE[] = {0};
6421 static const WCHAR szWindowsInstaler[] =
6422 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
6423 static const WCHAR szPropKeys[][80] =
6425 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
6426 {'A','R','P','C','O','N','T','A','C','T',0},
6427 {'A','R','P','C','O','M','M','E','N','T','S',0},
6428 {'P','r','o','d','u','c','t','N','a','m','e',0},
6429 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
6430 {'A','R','P','H','E','L','P','L','I','N','K',0},
6431 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
6432 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
6433 {'S','o','u','r','c','e','D','i','r',0},
6434 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
6435 {'A','R','P','R','E','A','D','M','E',0},
6436 {'A','R','P','S','I','Z','E',0},
6437 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
6438 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
6442 static const WCHAR szRegKeys[][80] =
6444 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
6445 {'C','o','n','t','a','c','t',0},
6446 {'C','o','m','m','e','n','t','s',0},
6447 {'D','i','s','p','l','a','y','N','a','m','e',0},
6448 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
6449 {'H','e','l','p','L','i','n','k',0},
6450 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
6451 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
6452 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
6453 {'P','u','b','l','i','s','h','e','r',0},
6454 {'R','e','a','d','m','e',0},
6455 {'S','i','z','e',0},
6456 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
6457 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
6461 static const WCHAR installerPathFmt[] = {
6463 'I','n','s','t','a','l','l','e','r','\\',0};
6464 static const WCHAR fmt[] = {
6466 'I','n','s','t','a','l','l','e','r','\\',
6467 '%','x','.','m','s','i',0};
6468 static const WCHAR szLocalPackage[]=
6469 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
6470 static const WCHAR szUpgradeCode[] =
6471 {'U','p','g','r','a','d','e','C','o','d','e',0};
6472 LPWSTR upgrade_code;
6473 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
6477 return ERROR_INVALID_HANDLE;
6479 productcode = load_dynamic_property(package,szProductCode,&rc);
6483 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
6484 if (rc != ERROR_SUCCESS)
6487 /* dump all the info i can grab */
6488 FIXME("Flesh out more information \n");
6491 while (szPropKeys[i][0]!=0)
6493 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
6494 if (rc != ERROR_SUCCESS)
6496 size = strlenW(buffer)*sizeof(WCHAR);
6497 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
6503 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
6505 /* copy the package locally */
6506 num = GetTickCount() & 0xffff;
6510 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
6511 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
6515 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
6516 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
6517 if (handle != INVALID_HANDLE_VALUE)
6519 CloseHandle(handle);
6522 if (GetLastError() != ERROR_FILE_EXISTS &&
6523 GetLastError() != ERROR_SHARING_VIOLATION)
6525 if (!(++num & 0xffff)) num = 1;
6526 sprintfW(packagefile,fmt,num);
6527 } while (num != start);
6529 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
6530 create_full_pathW(path);
6531 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
6532 if (!CopyFileW(package->PackagePath,packagefile,FALSE))
6533 ERR("Unable to copy package (%s -> %s) (error %ld)\n",
6534 debugstr_w(package->PackagePath), debugstr_w(packagefile),
6536 size = strlenW(packagefile)*sizeof(WCHAR);
6537 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
6539 /* Handle Upgrade Codes */
6540 upgrade_code = load_dynamic_property(package,szUpgradeCode, NULL);
6545 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
6546 squash_guid(productcode,squashed);
6547 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
6549 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
6550 squash_guid(productcode,squashed);
6551 RegSetValueExW(hkey2, squashed, 0,REG_SZ,NULL,0);
6554 HeapFree(GetProcessHeap(),0,upgrade_code);
6558 HeapFree(GetProcessHeap(),0,productcode);
6561 return ERROR_SUCCESS;
6564 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
6569 return ERROR_INVALID_HANDLE;
6571 rc = execute_script(package,INSTALL_SCRIPT);
6576 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
6581 return ERROR_INVALID_HANDLE;
6583 /* turn off scheduleing */
6584 package->script->CurrentlyScripting= FALSE;
6586 /* first do the same as an InstallExecute */
6587 rc = ACTION_InstallExecute(package);
6588 if (rc != ERROR_SUCCESS)
6591 /* then handle Commit Actions */
6592 rc = execute_script(package,COMMIT_SCRIPT);
6597 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
6599 static const WCHAR RunOnce[] = {
6600 'S','o','f','t','w','a','r','e','\\',
6601 'M','i','c','r','o','s','o','f','t','\\',
6602 'W','i','n','d','o','w','s','\\',
6603 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6604 'R','u','n','O','n','c','e',0};
6605 static const WCHAR InstallRunOnce[] = {
6606 'S','o','f','t','w','a','r','e','\\',
6607 'M','i','c','r','o','s','o','f','t','\\',
6608 'W','i','n','d','o','w','s','\\',
6609 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6610 'I','n','s','t','a','l','l','e','r','\\',
6611 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
6613 static const WCHAR msiexec_fmt[] = {
6615 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
6616 '\"','%','s','\"',0};
6617 static const WCHAR install_fmt[] = {
6618 '/','I',' ','\"','%','s','\"',' ',
6619 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
6620 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
6621 WCHAR buffer[256], sysdir[MAX_PATH];
6624 WCHAR squished_pc[100];
6627 static const WCHAR szLUS[] = {
6628 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
6629 static const WCHAR szSourceList[] = {
6630 'S','o','u','r','c','e','L','i','s','t',0};
6631 static const WCHAR szPackageName[] = {
6632 'P','a','c','k','a','g','e','N','a','m','e',0};
6635 return ERROR_INVALID_HANDLE;
6637 productcode = load_dynamic_property(package,szProductCode,&rc);
6641 squash_guid(productcode,squished_pc);
6643 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
6644 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
6645 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
6648 size = strlenW(buffer)*sizeof(WCHAR);
6649 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6652 TRACE("Reboot command %s\n",debugstr_w(buffer));
6654 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
6655 sprintfW(buffer,install_fmt,productcode,squished_pc);
6657 size = strlenW(buffer)*sizeof(WCHAR);
6658 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
6661 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
6662 if (rc == ERROR_SUCCESS)
6666 RegCreateKeyW(hukey, szSourceList, &hukey2);
6667 buf = load_dynamic_property(package,cszSourceDir,NULL);
6668 size = strlenW(buf)*sizeof(WCHAR);
6669 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
6670 HeapFree(GetProcessHeap(),0,buf);
6672 buf = strrchrW(package->PackagePath,'\\');
6676 size = strlenW(buf)*sizeof(WCHAR);
6677 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
6680 RegCloseKey(hukey2);
6682 HeapFree(GetProcessHeap(),0,productcode);
6684 return ERROR_INSTALL_SUSPEND;
6687 UINT ACTION_ResolveSource(MSIPACKAGE* package)
6690 * we are currently doing what should be done here in the top level Install
6691 * however for Adminastrative and uninstalls this step will be needed
6693 return ERROR_SUCCESS;
6696 static LPWSTR create_component_advertise_string(MSIPACKAGE* package,
6697 MSICOMPONENT* component, LPCWSTR feature)
6699 LPWSTR productid=NULL;
6701 WCHAR productid_85[21];
6702 WCHAR component_85[21];
6704 * I have a fair bit of confusion as to when a < is used and when a > is
6705 * used. I do not think i have it right...
6707 * Ok it appears that the > is used if there is a guid for the compoenent
6708 * and the < is used if not.
6710 static WCHAR fmt1[] = {'%','s','%','s','<',0,0};
6711 static WCHAR fmt2[] = {'%','s','%','s','>','%','s',0,0};
6712 LPWSTR output = NULL;
6715 memset(productid_85,0,sizeof(productid_85));
6716 memset(component_85,0,sizeof(component_85));
6718 productid = load_dynamic_property(package,szProductCode,NULL);
6719 CLSIDFromString(productid, &clsid);
6721 encode_base85_guid(&clsid,productid_85);
6723 CLSIDFromString(component->ComponentId, &clsid);
6724 encode_base85_guid(&clsid,component_85);
6726 TRACE("Doing something with this... %s %s %s\n",
6727 debugstr_w(productid_85), debugstr_w(feature),
6728 debugstr_w(component_85));
6730 sz = lstrlenW(productid_85) + lstrlenW(feature);
6732 sz += lstrlenW(component_85);
6735 sz *= sizeof(WCHAR);
6737 output = HeapAlloc(GetProcessHeap(),0,sz);
6738 memset(output,0,sz);
6741 sprintfW(output,fmt2,productid_85,feature,component_85);
6743 sprintfW(output,fmt1,productid_85,feature);
6745 HeapFree(GetProcessHeap(),0,productid);
6750 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
6751 MSICOMPONENT* component, MSIEXTENSION* extension,
6752 MSIVERB* verb, INT* Sequence )
6756 static const WCHAR szShell[] = {'s','h','e','l','l',0};
6757 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
6758 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
6759 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
6764 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
6766 TRACE("Making Key %s\n",debugstr_w(keyname));
6767 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6768 size = strlenW(component->FullKeypath);
6770 size += strlenW(verb->Argument);
6773 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6775 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
6777 sprintfW(command, fmt2, component->FullKeypath);
6779 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)command, (strlenW(command)+1)*
6781 HeapFree(GetProcessHeap(),0,command);
6783 advertise = create_component_advertise_string(package, component,
6784 package->features[extension->FeatureIndex].Feature);
6786 size = strlenW(advertise);
6789 size += strlenW(verb->Argument);
6792 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
6793 memset(command,0,size*sizeof(WCHAR));
6795 strcpyW(command,advertise);
6798 static const WCHAR szSpace[] = {' ',0};
6799 strcatW(command,szSpace);
6800 strcatW(command,verb->Argument);
6803 RegSetValueExW(key, szCommand, 0, REG_MULTI_SZ, (LPBYTE)command,
6804 (strlenW(command)+2)*sizeof(WCHAR));
6807 HeapFree(GetProcessHeap(),0,keyname);
6808 HeapFree(GetProcessHeap(),0,advertise);
6809 HeapFree(GetProcessHeap(),0,command);
6813 keyname = build_directory_name(3, progid, szShell, verb->Verb);
6814 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6815 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Command,
6816 (strlenW(verb->Command)+1) *sizeof(WCHAR));
6818 HeapFree(GetProcessHeap(),0,keyname);
6821 if (verb->Sequence != MSI_NULL_INTEGER)
6823 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
6825 *Sequence = verb->Sequence;
6826 keyname = build_directory_name(2, progid, szShell);
6827 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
6828 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Verb,
6829 (strlenW(verb->Verb)+1) *sizeof(WCHAR));
6831 HeapFree(GetProcessHeap(),0,keyname);
6834 return ERROR_SUCCESS;
6837 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
6839 static const WCHAR szContentType[] =
6840 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
6844 BOOL install_on_demand = TRUE;
6847 return ERROR_INVALID_HANDLE;
6849 load_classes_and_such(package);
6851 /* We need to set install_on_demand based on if the shell handles advertised
6852 * shortcuts and the like. Because Mike McCormack is working on this i am
6853 * going to default to TRUE
6856 for (i = 0; i < package->loaded_extensions; i++)
6858 WCHAR extension[257];
6861 index = package->extensions[i].ComponentIndex;
6862 f_index = package->extensions[i].FeatureIndex;
6868 * yes. MSDN says that these are based on _Feature_ not on
6869 * Component. So verify the feature is to be installed
6871 if ((!ACTION_VerifyFeatureForAction(package, f_index,
6872 INSTALLSTATE_LOCAL)) &&
6873 !(install_on_demand && ACTION_VerifyFeatureForAction(package,
6874 f_index, INSTALLSTATE_ADVERTISED)))
6876 TRACE("Skipping extension %s reg due to disabled feature %s\n",
6877 debugstr_w(package->extensions[i].Extension),
6878 debugstr_w(package->features[f_index].Feature));
6883 TRACE("Registering extension %s index %i\n",
6884 debugstr_w(package->extensions[i].Extension), i);
6886 package->extensions[i].Installed = TRUE;
6888 /* this is only registered if the extension has at least 1 verb
6891 if (package->extensions[i].ProgIDIndex >= 0 &&
6892 package->extensions[i].VerbCount > 0)
6893 mark_progid_for_install(package, package->extensions[i].ProgIDIndex);
6895 if (package->extensions[i].MIMEIndex >= 0)
6896 mark_mime_for_install(package, package->extensions[i].MIMEIndex);
6900 strcatW(extension,package->extensions[i].Extension);
6902 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
6904 if (package->extensions[i].MIMEIndex >= 0)
6906 RegSetValueExW(hkey,szContentType,0,REG_SZ,
6907 (LPVOID)package->mimes[package->extensions[i].
6908 MIMEIndex].ContentType,
6909 (strlenW(package->mimes[package->extensions[i].
6910 MIMEIndex].ContentType)+1)*sizeof(WCHAR));
6913 if (package->extensions[i].ProgIDIndex >= 0 ||
6914 package->extensions[i].ProgIDText)
6916 static const WCHAR szSN[] =
6917 {'\\','S','h','e','l','l','N','e','w',0};
6922 INT Sequence = MSI_NULL_INTEGER;
6924 if (package->extensions[i].ProgIDIndex >= 0)
6925 progid = package->progids[package->extensions[i].
6926 ProgIDIndex].ProgID;
6928 progid = package->extensions[i].ProgIDText;
6930 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
6931 (strlenW(progid)+1)*sizeof(WCHAR));
6933 newkey = HeapAlloc(GetProcessHeap(),0,
6934 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
6936 strcpyW(newkey,progid);
6937 strcatW(newkey,szSN);
6938 RegCreateKeyW(hkey,newkey,&hkey2);
6941 HeapFree(GetProcessHeap(),0,newkey);
6943 /* do all the verbs */
6944 for (v = 0; v < package->extensions[i].VerbCount; v++)
6945 register_verb(package, progid,
6946 &package->components[index],
6947 &package->extensions[i],
6948 &package->verbs[package->extensions[i].Verbs[v]],
6954 uirow = MSI_CreateRecord(1);
6955 MSI_RecordSetStringW(uirow,1,package->extensions[i].Extension);
6956 ui_actiondata(package,szRegisterExtensionInfo,uirow);
6957 msiobj_release(&uirow->hdr);
6960 return ERROR_SUCCESS;
6963 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
6965 static const WCHAR szExten[] =
6966 {'E','x','t','e','n','s','i','o','n',0 };
6972 return ERROR_INVALID_HANDLE;
6974 load_classes_and_such(package);
6976 for (i = 0; i < package->loaded_mimes; i++)
6978 WCHAR extension[257];
6981 static const WCHAR fmt[] =
6982 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
6983 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
6987 * check if the MIME is to be installed. Either as requesed by an
6988 * extension or Class
6990 package->mimes[i].InstallMe = ((package->mimes[i].InstallMe) ||
6991 (package->mimes[i].ClassIndex >= 0 &&
6992 package->classes[package->mimes[i].ClassIndex].Installed) ||
6993 (package->mimes[i].ExtensionIndex >=0 &&
6994 package->extensions[package->mimes[i].ExtensionIndex].Installed));
6996 if (!package->mimes[i].InstallMe)
6998 TRACE("MIME %s not scheduled to be installed\n",
6999 debugstr_w(package->mimes[i].ContentType));
7003 mime = package->mimes[i].ContentType;
7004 exten = package->extensions[package->mimes[i].ExtensionIndex].Extension;
7007 strcatW(extension,exten);
7009 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
7011 sprintfW(key,fmt,mime);
7012 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
7013 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
7014 (strlenW(extension)+1)*sizeof(WCHAR));
7016 HeapFree(GetProcessHeap(),0,key);
7018 if (package->mimes[i].CLSID[0])
7020 FIXME("Handle non null for field 3\n");
7025 uirow = MSI_CreateRecord(2);
7026 MSI_RecordSetStringW(uirow,1,package->mimes[i].ContentType);
7027 MSI_RecordSetStringW(uirow,2,exten);
7028 ui_actiondata(package,szRegisterMIMEInfo,uirow);
7029 msiobj_release(&uirow->hdr);
7032 return ERROR_SUCCESS;
7035 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
7037 static const WCHAR szProductID[]=
7038 {'P','r','o','d','u','c','t','I','D',0};
7046 static const WCHAR szPropKeys[][80] =
7048 {'P','r','o','d','u','c','t','I','D',0},
7049 {'U','S','E','R','N','A','M','E',0},
7050 {'C','O','M','P','A','N','Y','N','A','M','E',0},
7054 static const WCHAR szRegKeys[][80] =
7056 {'P','r','o','d','u','c','t','I','D',0},
7057 {'R','e','g','O','w','n','e','r',0},
7058 {'R','e','g','C','o','m','p','a','n','y',0},
7063 return ERROR_INVALID_HANDLE;
7065 productid = load_dynamic_property(package,szProductID,&rc);
7067 return ERROR_SUCCESS;
7069 productcode = load_dynamic_property(package,szProductCode,&rc);
7073 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
7074 if (rc != ERROR_SUCCESS)
7078 while (szPropKeys[i][0]!=0)
7080 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
7081 if (rc == ERROR_SUCCESS)
7083 size = strlenW(buffer)*sizeof(WCHAR);
7084 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
7087 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,NULL,0);
7092 HeapFree(GetProcessHeap(),0,productcode);
7093 HeapFree(GetProcessHeap(),0,productid);
7096 return ERROR_SUCCESS;
7100 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
7103 rc = ACTION_ProcessExecSequence(package,FALSE);
7109 * Code based off of code located here
7110 * http://www.codeproject.com/gdi/fontnamefromfile.asp
7112 * Using string index 4 (full font name) instead of 1 (family name)
7114 static LPWSTR load_ttfname_from(LPCWSTR filename)
7120 typedef struct _tagTT_OFFSET_TABLE{
7121 USHORT uMajorVersion;
7122 USHORT uMinorVersion;
7123 USHORT uNumOfTables;
7124 USHORT uSearchRange;
7125 USHORT uEntrySelector;
7129 typedef struct _tagTT_TABLE_DIRECTORY{
7130 char szTag[4]; /* table name */
7131 ULONG uCheckSum; /* Check sum */
7132 ULONG uOffset; /* Offset from beginning of file */
7133 ULONG uLength; /* length of the table in bytes */
7134 }TT_TABLE_DIRECTORY;
7136 typedef struct _tagTT_NAME_TABLE_HEADER{
7137 USHORT uFSelector; /* format selector. Always 0 */
7138 USHORT uNRCount; /* Name Records count */
7139 USHORT uStorageOffset; /* Offset for strings storage,
7140 * from start of the table */
7141 }TT_NAME_TABLE_HEADER;
7143 typedef struct _tagTT_NAME_RECORD{
7148 USHORT uStringLength;
7149 USHORT uStringOffset; /* from start of storage area */
7152 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
7153 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
7155 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
7156 FILE_ATTRIBUTE_NORMAL, 0 );
7157 if (handle != INVALID_HANDLE_VALUE)
7159 TT_TABLE_DIRECTORY tblDir;
7160 BOOL bFound = FALSE;
7161 TT_OFFSET_TABLE ttOffsetTable;
7163 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
7164 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
7165 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
7166 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
7168 if (ttOffsetTable.uMajorVersion != 1 ||
7169 ttOffsetTable.uMinorVersion != 0)
7172 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
7174 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
7175 if (strncmp(tblDir.szTag,"name",4)==0)
7178 tblDir.uLength = SWAPLONG(tblDir.uLength);
7179 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
7186 TT_NAME_TABLE_HEADER ttNTHeader;
7187 TT_NAME_RECORD ttRecord;
7189 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
7190 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
7193 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
7194 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
7196 for(i=0; i<ttNTHeader.uNRCount; i++)
7198 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
7199 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
7200 /* 4 is the Full Font Name */
7201 if(ttRecord.uNameID == 4)
7205 static LPCSTR tt = " (TrueType)";
7207 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
7208 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
7209 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
7210 SetFilePointer(handle, tblDir.uOffset +
7211 ttRecord.uStringOffset +
7212 ttNTHeader.uStorageOffset,
7214 buf = HeapAlloc(GetProcessHeap(), 0,
7215 ttRecord.uStringLength + 1 + strlen(tt));
7216 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
7217 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
7218 if (strlen(buf) > 0)
7221 ret = strdupAtoW(buf);
7222 HeapFree(GetProcessHeap(),0,buf);
7226 HeapFree(GetProcessHeap(),0,buf);
7227 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
7231 CloseHandle(handle);
7234 ERR("Unable to open font file %s\n", debugstr_w(filename));
7236 TRACE("Returning fontname %s\n",debugstr_w(ret));
7240 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
7244 MSIRECORD * row = 0;
7245 static const WCHAR ExecSeqQuery[] =
7246 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7247 '`','F','o','n','t','`',0};
7248 static const WCHAR regfont1[] =
7249 {'S','o','f','t','w','a','r','e','\\',
7250 'M','i','c','r','o','s','o','f','t','\\',
7251 'W','i','n','d','o','w','s',' ','N','T','\\',
7252 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7253 'F','o','n','t','s',0};
7254 static const WCHAR regfont2[] =
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','\\',
7258 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
7259 'F','o','n','t','s',0};
7263 TRACE("%p\n", package);
7265 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7266 if (rc != ERROR_SUCCESS)
7268 TRACE("MSI_DatabaseOpenViewW failed: %d\n", rc);
7269 return ERROR_SUCCESS;
7272 rc = MSI_ViewExecute(view, 0);
7273 if (rc != ERROR_SUCCESS)
7275 MSI_ViewClose(view);
7276 msiobj_release(&view->hdr);
7277 TRACE("MSI_ViewExecute returned %d\n", rc);
7278 return ERROR_SUCCESS;
7281 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
7282 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
7291 rc = MSI_ViewFetch(view,&row);
7292 if (rc != ERROR_SUCCESS)
7298 file = MSI_RecordGetString(row,1);
7299 index = get_loaded_file(package,file);
7302 ERR("Unable to load file\n");
7306 /* check to make sure that component is installed */
7307 if (!ACTION_VerifyComponentForAction(package,
7308 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
7310 TRACE("Skipping: Component not scheduled for install\n");
7312 msiobj_release(&row->hdr);
7317 if (MSI_RecordIsNull(row,2))
7318 name = load_ttfname_from(package->files[index].TargetPath);
7320 name = load_dynamic_stringW(row,2);
7324 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
7325 RegSetValueExW(hkey1,name,0,REG_SZ,
7326 (LPBYTE)package->files[index].FileName,size);
7327 RegSetValueExW(hkey2,name,0,REG_SZ,
7328 (LPBYTE)package->files[index].FileName,size);
7331 HeapFree(GetProcessHeap(),0,name);
7332 msiobj_release(&row->hdr);
7334 MSI_ViewClose(view);
7335 msiobj_release(&view->hdr);
7340 TRACE("returning %d\n", rc);
7344 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
7346 MSIPACKAGE *package = (MSIPACKAGE*)param;
7347 LPCWSTR compgroupid=NULL;
7348 LPCWSTR feature=NULL;
7349 LPCWSTR text = NULL;
7350 LPCWSTR qualifier = NULL;
7351 LPCWSTR component = NULL;
7352 LPWSTR advertise = NULL;
7353 LPWSTR output = NULL;
7355 UINT rc = ERROR_SUCCESS;
7359 component = MSI_RecordGetString(rec,3);
7360 index = get_loaded_component(package,component);
7362 if (!ACTION_VerifyComponentForAction(package, index,
7363 INSTALLSTATE_LOCAL) &&
7364 !ACTION_VerifyComponentForAction(package, index,
7365 INSTALLSTATE_SOURCE) &&
7366 !ACTION_VerifyComponentForAction(package, index,
7367 INSTALLSTATE_ADVERTISED))
7369 TRACE("Skipping: Component %s not scheduled for install\n",
7370 debugstr_w(component));
7372 return ERROR_SUCCESS;
7375 compgroupid = MSI_RecordGetString(rec,1);
7377 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
7378 if (rc != ERROR_SUCCESS)
7381 text = MSI_RecordGetString(rec,4);
7382 qualifier = MSI_RecordGetString(rec,2);
7383 feature = MSI_RecordGetString(rec,5);
7385 advertise = create_component_advertise_string(package,
7386 &package->components[index], feature);
7388 sz = strlenW(advertise);
7391 sz += lstrlenW(text);
7394 sz *= sizeof(WCHAR);
7396 output = HeapAlloc(GetProcessHeap(),0,sz);
7397 memset(output,0,sz);
7398 strcpyW(output,advertise);
7401 strcatW(output,text);
7403 sz = (lstrlenW(output)+2) * sizeof(WCHAR);
7404 RegSetValueExW(hkey, qualifier,0,REG_MULTI_SZ, (LPBYTE)output, sz);
7408 HeapFree(GetProcessHeap(),0,output);
7414 * At present I am ignorning the advertised components part of this and only
7415 * focusing on the qualified component sets
7417 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
7421 static const WCHAR ExecSeqQuery[] =
7422 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7423 '`','P','u','b','l','i','s','h',
7424 'C','o','m','p','o','n','e','n','t','`',0};
7426 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
7427 if (rc != ERROR_SUCCESS)
7428 return ERROR_SUCCESS;
7430 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
7431 msiobj_release(&view->hdr);
7436 /* Msi functions that seem appropriate here */
7438 /***********************************************************************
7439 * MsiDoActionA (MSI.@)
7441 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
7446 TRACE(" exteral attempt at action %s\n",szAction);
7449 return ERROR_FUNCTION_FAILED;
7451 return ERROR_FUNCTION_FAILED;
7453 szwAction = strdupAtoW(szAction);
7456 return ERROR_FUNCTION_FAILED;
7459 rc = MsiDoActionW(hInstall, szwAction);
7460 HeapFree(GetProcessHeap(),0,szwAction);
7464 /***********************************************************************
7465 * MsiDoActionW (MSI.@)
7467 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
7469 MSIPACKAGE *package;
7470 UINT ret = ERROR_INVALID_HANDLE;
7472 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
7474 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7477 ret = ACTION_PerformUIAction(package,szAction);
7478 msiobj_release( &package->hdr );
7483 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
7484 LPSTR szPathBuf, DWORD* pcchPathBuf)
7490 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7493 return ERROR_FUNCTION_FAILED;
7495 return ERROR_FUNCTION_FAILED;
7497 szwFolder = strdupAtoW(szFolder);
7500 return ERROR_FUNCTION_FAILED;
7502 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7504 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7506 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7507 *pcchPathBuf, NULL, NULL );
7509 HeapFree(GetProcessHeap(),0,szwFolder);
7510 HeapFree(GetProcessHeap(),0,szwPathBuf);
7515 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7516 szPathBuf, DWORD* pcchPathBuf)
7519 UINT rc = ERROR_FUNCTION_FAILED;
7520 MSIPACKAGE *package;
7522 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7524 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7526 return ERROR_INVALID_HANDLE;
7527 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
7528 msiobj_release( &package->hdr );
7530 if (path && (strlenW(path) > *pcchPathBuf))
7532 *pcchPathBuf = strlenW(path)+1;
7533 rc = ERROR_MORE_DATA;
7537 *pcchPathBuf = strlenW(path)+1;
7538 strcpyW(szPathBuf,path);
7539 TRACE("Returning Path %s\n",debugstr_w(path));
7542 HeapFree(GetProcessHeap(),0,path);
7548 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
7549 LPSTR szPathBuf, DWORD* pcchPathBuf)
7555 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
7558 return ERROR_FUNCTION_FAILED;
7560 return ERROR_FUNCTION_FAILED;
7562 szwFolder = strdupAtoW(szFolder);
7564 return ERROR_FUNCTION_FAILED;
7566 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
7568 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
7570 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
7571 *pcchPathBuf, NULL, NULL );
7573 HeapFree(GetProcessHeap(),0,szwFolder);
7574 HeapFree(GetProcessHeap(),0,szwPathBuf);
7579 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
7580 szPathBuf, DWORD* pcchPathBuf)
7583 UINT rc = ERROR_FUNCTION_FAILED;
7584 MSIPACKAGE *package;
7586 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
7588 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7590 return ERROR_INVALID_HANDLE;
7591 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
7592 msiobj_release( &package->hdr );
7594 if (path && strlenW(path) > *pcchPathBuf)
7596 *pcchPathBuf = strlenW(path)+1;
7597 rc = ERROR_MORE_DATA;
7601 *pcchPathBuf = strlenW(path)+1;
7602 strcpyW(szPathBuf,path);
7603 TRACE("Returning Path %s\n",debugstr_w(path));
7606 HeapFree(GetProcessHeap(),0,path);
7612 /***********************************************************************
7613 * MsiSetTargetPathA (MSI.@)
7615 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
7616 LPCSTR szFolderPath)
7619 LPWSTR szwFolderPath;
7623 return ERROR_FUNCTION_FAILED;
7625 return ERROR_FUNCTION_FAILED;
7627 szwFolder = strdupAtoW(szFolder);
7629 return ERROR_FUNCTION_FAILED;
7631 szwFolderPath = strdupAtoW(szFolderPath);
7634 HeapFree(GetProcessHeap(),0,szwFolder);
7635 return ERROR_FUNCTION_FAILED;
7638 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
7640 HeapFree(GetProcessHeap(),0,szwFolder);
7641 HeapFree(GetProcessHeap(),0,szwFolderPath);
7646 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
7647 LPCWSTR szFolderPath)
7651 LPWSTR path2 = NULL;
7654 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
7657 return ERROR_INVALID_HANDLE;
7659 if (szFolderPath[0]==0)
7660 return ERROR_FUNCTION_FAILED;
7662 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
7663 return ERROR_FUNCTION_FAILED;
7665 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
7668 return ERROR_INVALID_PARAMETER;
7670 HeapFree(GetProcessHeap(),0,folder->Property);
7671 folder->Property = build_directory_name(2, szFolderPath, NULL);
7673 if (lstrcmpiW(path, folder->Property) == 0)
7676 * Resolved Target has not really changed, so just
7677 * set this folder and do not recalculate everything.
7679 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
7680 folder->ResolvedTarget = NULL;
7681 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
7682 HeapFree(GetProcessHeap(),0,path2);
7686 for (i = 0; i < package->loaded_folders; i++)
7688 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
7689 package->folders[i].ResolvedTarget=NULL;
7692 for (i = 0; i < package->loaded_folders; i++)
7694 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
7696 HeapFree(GetProcessHeap(),0,path2);
7699 HeapFree(GetProcessHeap(),0,path);
7701 return ERROR_SUCCESS;
7704 /***********************************************************************
7705 * MsiSetTargetPathW (MSI.@)
7707 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
7708 LPCWSTR szFolderPath)
7710 MSIPACKAGE *package;
7713 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
7715 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7716 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
7717 msiobj_release( &package->hdr );
7721 /***********************************************************************
7722 * MsiGetMode (MSI.@)
7724 * Returns an internal installer state (if it is running in a mode iRunMode)
7727 * hInstall [I] Handle to the installation
7728 * hRunMode [I] Checking run mode
7729 * MSIRUNMODE_ADMIN Administrative mode
7730 * MSIRUNMODE_ADVERTISE Advertisement mode
7731 * MSIRUNMODE_MAINTENANCE Maintenance mode
7732 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
7733 * MSIRUNMODE_LOGENABLED Log file is writing
7734 * MSIRUNMODE_OPERATIONS Operations in progress??
7735 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
7736 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
7737 * MSIRUNMODE_CABINET Files from cabinet are installed
7738 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
7739 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
7740 * MSIRUNMODE_RESERVED11 Reserved
7741 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
7742 * MSIRUNMODE_ZAWENABLED Demand installation is supported
7743 * MSIRUNMODE_RESERVED14 Reserved
7744 * MSIRUNMODE_RESERVED15 Reserved
7745 * MSIRUNMODE_SCHEDULED called from install script
7746 * MSIRUNMODE_ROLLBACK called from rollback script
7747 * MSIRUNMODE_COMMIT called from commit script
7750 * In the state: TRUE
7751 * Not in the state: FALSE
7755 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
7757 FIXME("STUB (iRunMode=%i)\n",iRunMode);
7761 /***********************************************************************
7762 * MsiSetFeatureStateA (MSI.@)
7764 * According to the docs, when this is called it immediately recalculates
7765 * all the component states as well
7767 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
7768 INSTALLSTATE iState)
7770 LPWSTR szwFeature = NULL;
7773 szwFeature = strdupAtoW(szFeature);
7776 return ERROR_FUNCTION_FAILED;
7778 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
7780 HeapFree(GetProcessHeap(),0,szwFeature);
7787 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
7788 INSTALLSTATE iState)
7791 UINT rc = ERROR_SUCCESS;
7793 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7795 index = get_loaded_feature(package,szFeature);
7797 return ERROR_UNKNOWN_FEATURE;
7799 if (iState == INSTALLSTATE_ADVERTISED &&
7800 package->features[index].Attributes &
7801 msidbFeatureAttributesDisallowAdvertise)
7802 return ERROR_FUNCTION_FAILED;
7804 package->features[index].ActionRequest= iState;
7805 package->features[index].Action= iState;
7807 ACTION_UpdateComponentStates(package,szFeature);
7809 /* update all the features that are children of this feature */
7810 for (i = 0; i < package->loaded_features; i++)
7812 if (strcmpW(szFeature, package->features[i].Feature_Parent) == 0)
7813 MSI_SetFeatureStateW(package, package->features[i].Feature, iState);
7819 /***********************************************************************
7820 * MsiSetFeatureStateW (MSI.@)
7822 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
7823 INSTALLSTATE iState)
7825 MSIPACKAGE* package;
7826 UINT rc = ERROR_SUCCESS;
7828 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
7830 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7832 return ERROR_INVALID_HANDLE;
7834 rc = MSI_SetFeatureStateW(package,szFeature,iState);
7836 msiobj_release( &package->hdr );
7840 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
7841 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7843 LPWSTR szwFeature = NULL;
7846 szwFeature = strdupAtoW(szFeature);
7848 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
7850 HeapFree( GetProcessHeap(), 0 , szwFeature);
7855 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
7856 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7860 index = get_loaded_feature(package,szFeature);
7862 return ERROR_UNKNOWN_FEATURE;
7865 *piInstalled = package->features[index].Installed;
7868 *piAction = package->features[index].Action;
7870 TRACE("returning %i %i\n",*piInstalled,*piAction);
7872 return ERROR_SUCCESS;
7875 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
7876 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7878 MSIPACKAGE* package;
7881 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
7884 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7886 return ERROR_INVALID_HANDLE;
7887 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
7888 msiobj_release( &package->hdr );
7892 /***********************************************************************
7893 * MsiGetComponentStateA (MSI.@)
7895 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
7896 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7898 LPWSTR szwComponent= NULL;
7901 szwComponent= strdupAtoW(szComponent);
7903 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
7905 HeapFree( GetProcessHeap(), 0 , szwComponent);
7910 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
7911 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7915 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
7918 index = get_loaded_component(package,szComponent);
7920 return ERROR_UNKNOWN_COMPONENT;
7923 *piInstalled = package->components[index].Installed;
7926 *piAction = package->components[index].Action;
7928 TRACE("states (%i, %i)\n",
7929 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
7931 return ERROR_SUCCESS;
7934 /***********************************************************************
7935 * MsiGetComponentStateW (MSI.@)
7937 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
7938 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
7940 MSIPACKAGE* package;
7943 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
7944 piInstalled, piAction);
7946 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
7948 return ERROR_INVALID_HANDLE;
7949 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
7950 msiobj_release( &package->hdr );