Allocate space for terminating null.
[wine/dcerpc.git] / dlls / msi / action.c
blob07c8fcf376d98cacbe4886a02303f70686e43a6d
1 /*
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
22 * Pages I need
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
29 #include <stdarg.h>
30 #include <stdio.h>
32 #define COBJMACROS
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "winreg.h"
38 #include "wine/debug.h"
39 #include "fdi.h"
40 #include "msi.h"
41 #include "msiquery.h"
42 #include "msidefs.h"
43 #include "msvcrt/fcntl.h"
44 #include "objbase.h"
45 #include "objidl.h"
46 #include "msipriv.h"
47 #include "winnls.h"
48 #include "winuser.h"
49 #include "shlobj.h"
50 #include "wine/unicode.h"
51 #include "ver.h"
52 #include "action.h"
54 #define REG_PROGRESS_VALUE 13200
55 #define COMPONENT_PROGRESS_VALUE 24000
57 WINE_DEFAULT_DEBUG_CHANNEL(msi);
60 * Prototypes
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);
65 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
66 LPWSTR *FilePath);
68 /*
69 * action handlers
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);
105 * consts and values used
107 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
108 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
109 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
110 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
111 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
112 static const WCHAR c_colon[] = {'C',':','\\',0};
113 static const WCHAR szProductCode[]=
114 {'P','r','o','d','u','c','t','C','o','d','e',0};
115 static const WCHAR cszbs[]={'\\',0};
116 const static WCHAR szCreateFolders[] =
117 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
118 const static WCHAR szCostFinalize[] =
119 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
120 const static WCHAR szInstallFiles[] =
121 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
122 const static WCHAR szDuplicateFiles[] =
123 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
124 const static WCHAR szWriteRegistryValues[] =
125 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
126 'V','a','l','u','e','s',0};
127 const static WCHAR szCostInitialize[] =
128 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
129 const static WCHAR szFileCost[] =
130 {'F','i','l','e','C','o','s','t',0};
131 const static WCHAR szInstallInitialize[] =
132 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
133 const static WCHAR szInstallValidate[] =
134 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
135 const static WCHAR szLaunchConditions[] =
136 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
137 const static WCHAR szProcessComponents[] =
138 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
139 const static WCHAR szRegisterTypeLibraries[] =
140 {'R','e','g','i','s','t','e','r','T','y','p','e',
141 'L','i','b','r','a','r','i','e','s',0};
142 const static WCHAR szRegisterClassInfo[] =
143 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
144 const static WCHAR szRegisterProgIdInfo[] =
145 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
146 const static WCHAR szCreateShortcuts[] =
147 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
148 const static WCHAR szPublishProduct[] =
149 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
150 const static WCHAR szWriteIniValues[] =
151 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
152 const static WCHAR szSelfRegModules[] =
153 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
154 const static WCHAR szPublishFeatures[] =
155 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
156 const static WCHAR szRegisterProduct[] =
157 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
158 const static WCHAR szInstallExecute[] =
159 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
160 const static WCHAR szInstallExecuteAgain[] =
161 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
162 'A','g','a','i','n',0};
163 const static WCHAR szInstallFinalize[] =
164 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
165 const static WCHAR szForceReboot[] =
166 {'F','o','r','c','e','R','e','b','o','o','t',0};
167 const static WCHAR szResolveSource[] =
168 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
169 const static WCHAR szAppSearch[] =
170 {'A','p','p','S','e','a','r','c','h',0};
171 const static WCHAR szAllocateRegistrySpace[] =
172 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
173 'S','p','a','c','e',0};
174 const static WCHAR szBindImage[] =
175 {'B','i','n','d','I','m','a','g','e',0};
176 const static WCHAR szCCPSearch[] =
177 {'C','C','P','S','e','a','r','c','h',0};
178 const static WCHAR szDeleteServices[] =
179 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
180 const static WCHAR szDisableRollback[] =
181 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
182 const static WCHAR szExecuteAction[] =
183 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
184 const static WCHAR szFindRelatedProducts[] =
185 {'F','i','n','d','R','e','l','a','t','e','d',
186 'P','r','o','d','u','c','t','s',0};
187 const static WCHAR szInstallAdminPackage[] =
188 {'I','n','s','t','a','l','l','A','d','m','i','n',
189 'P','a','c','k','a','g','e',0};
190 const static WCHAR szInstallSFPCatalogFile[] =
191 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
192 'F','i','l','e',0};
193 const static WCHAR szIsolateComponents[] =
194 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
195 const static WCHAR szMigrateFeatureStates[] =
196 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
197 'S','t','a','t','e','s',0};
198 const static WCHAR szMoveFiles[] =
199 {'M','o','v','e','F','i','l','e','s',0};
200 const static WCHAR szMsiPublishAssemblies[] =
201 {'M','s','i','P','u','b','l','i','s','h',
202 'A','s','s','e','m','b','l','i','e','s',0};
203 const static WCHAR szMsiUnpublishAssemblies[] =
204 {'M','s','i','U','n','p','u','b','l','i','s','h',
205 'A','s','s','e','m','b','l','i','e','s',0};
206 const static WCHAR szInstallODBC[] =
207 {'I','n','s','t','a','l','l','O','D','B','C',0};
208 const static WCHAR szInstallServices[] =
209 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
210 const static WCHAR szPatchFiles[] =
211 {'P','a','t','c','h','F','i','l','e','s',0};
212 const static WCHAR szPublishComponents[] =
213 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
214 const static WCHAR szRegisterComPlus[] =
215 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
216 const static WCHAR szRegisterExtensionInfo[] =
217 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
218 'I','n','f','o',0};
219 const static WCHAR szRegisterFonts[] =
220 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
221 const static WCHAR szRegisterMIMEInfo[] =
222 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
223 const static WCHAR szRegisterUser[] =
224 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
225 const static WCHAR szRemoveDuplicateFiles[] =
226 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
227 'F','i','l','e','s',0};
228 const static WCHAR szRemoveEnvironmentStrings[] =
229 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
230 'S','t','r','i','n','g','s',0};
231 const static WCHAR szRemoveExistingProducts[] =
232 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
233 'P','r','o','d','u','c','t','s',0};
234 const static WCHAR szRemoveFiles[] =
235 {'R','e','m','o','v','e','F','i','l','e','s',0};
236 const static WCHAR szRemoveFolders[] =
237 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
238 const static WCHAR szRemoveIniValues[] =
239 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
240 const static WCHAR szRemoveODBC[] =
241 {'R','e','m','o','v','e','O','D','B','C',0};
242 const static WCHAR szRemoveRegistryValues[] =
243 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
244 'V','a','l','u','e','s',0};
245 const static WCHAR szRemoveShortcuts[] =
246 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
247 const static WCHAR szRMCCPSearch[] =
248 {'R','M','C','C','P','S','e','a','r','c','h',0};
249 const static WCHAR szScheduleReboot[] =
250 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
251 const static WCHAR szSelfUnregModules[] =
252 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
253 const static WCHAR szSetODBCFolders[] =
254 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
255 const static WCHAR szStartServices[] =
256 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
257 const static WCHAR szStopServices[] =
258 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
259 const static WCHAR szUnpublishComponents[] =
260 {'U','n','p','u','b','l','i','s','h',
261 'C','o','m','p','o','n','e','n','t','s',0};
262 const static WCHAR szUnpublishFeatures[] =
263 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
264 const static WCHAR szUnregisterClassInfo[] =
265 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
266 'I','n','f','o',0};
267 const static WCHAR szUnregisterComPlus[] =
268 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
269 const static WCHAR szUnregisterExtensionInfo[] =
270 {'U','n','r','e','g','i','s','t','e','r',
271 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
272 const static WCHAR szUnregisterFonts[] =
273 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
274 const static WCHAR szUnregisterMIMEInfo[] =
275 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
276 const static WCHAR szUnregisterProgIdInfo[] =
277 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
278 'I','n','f','o',0};
279 const static WCHAR szUnregisterTypeLibraries[] =
280 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
281 'L','i','b','r','a','r','i','e','s',0};
282 const static WCHAR szValidateProductID[] =
283 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
284 const static WCHAR szWriteEnvironmentStrings[] =
285 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
286 'S','t','r','i','n','g','s',0};
288 struct _actions {
289 LPCWSTR action;
290 STANDARDACTIONHANDLER handler;
293 static struct _actions StandardActions[] = {
294 { szAllocateRegistrySpace, NULL},
295 { szAppSearch, ACTION_AppSearch },
296 { szBindImage, NULL},
297 { szCCPSearch, NULL},
298 { szCostFinalize, ACTION_CostFinalize },
299 { szCostInitialize, ACTION_CostInitialize },
300 { szCreateFolders, ACTION_CreateFolders },
301 { szCreateShortcuts, ACTION_CreateShortcuts },
302 { szDeleteServices, NULL},
303 { szDisableRollback, NULL},
304 { szDuplicateFiles, ACTION_DuplicateFiles },
305 { szExecuteAction, ACTION_ExecuteAction },
306 { szFileCost, ACTION_FileCost },
307 { szFindRelatedProducts, NULL},
308 { szForceReboot, ACTION_ForceReboot },
309 { szInstallAdminPackage, NULL},
310 { szInstallExecute, ACTION_InstallExecute },
311 { szInstallExecuteAgain, ACTION_InstallExecute },
312 { szInstallFiles, ACTION_InstallFiles},
313 { szInstallFinalize, ACTION_InstallFinalize },
314 { szInstallInitialize, ACTION_InstallInitialize },
315 { szInstallSFPCatalogFile, NULL},
316 { szInstallValidate, ACTION_InstallValidate },
317 { szIsolateComponents, NULL},
318 { szLaunchConditions, ACTION_LaunchConditions },
319 { szMigrateFeatureStates, NULL},
320 { szMoveFiles, NULL},
321 { szMsiPublishAssemblies, NULL},
322 { szMsiUnpublishAssemblies, NULL},
323 { szInstallODBC, NULL},
324 { szInstallServices, NULL},
325 { szPatchFiles, NULL},
326 { szProcessComponents, ACTION_ProcessComponents },
327 { szPublishComponents, NULL},
328 { szPublishFeatures, ACTION_PublishFeatures },
329 { szPublishProduct, ACTION_PublishProduct },
330 { szRegisterClassInfo, ACTION_RegisterClassInfo },
331 { szRegisterComPlus, NULL},
332 { szRegisterExtensionInfo, ACTION_RegisterExtensionInfo },
333 { szRegisterFonts, ACTION_RegisterFonts },
334 { szRegisterMIMEInfo, ACTION_RegisterMIMEInfo },
335 { szRegisterProduct, ACTION_RegisterProduct },
336 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
337 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
338 { szRegisterUser, ACTION_RegisterUser},
339 { szRemoveDuplicateFiles, NULL},
340 { szRemoveEnvironmentStrings, NULL},
341 { szRemoveExistingProducts, NULL},
342 { szRemoveFiles, NULL},
343 { szRemoveFolders, NULL},
344 { szRemoveIniValues, NULL},
345 { szRemoveODBC, NULL},
346 { szRemoveRegistryValues, NULL},
347 { szRemoveShortcuts, NULL},
348 { szResolveSource, ACTION_ResolveSource},
349 { szRMCCPSearch, NULL},
350 { szScheduleReboot, NULL},
351 { szSelfRegModules, ACTION_SelfRegModules },
352 { szSelfUnregModules, NULL},
353 { szSetODBCFolders, NULL},
354 { szStartServices, NULL},
355 { szStopServices, NULL},
356 { szUnpublishComponents, NULL},
357 { szUnpublishFeatures, NULL},
358 { szUnregisterClassInfo, NULL},
359 { szUnregisterComPlus, NULL},
360 { szUnregisterExtensionInfo, NULL},
361 { szUnregisterFonts, NULL},
362 { szUnregisterMIMEInfo, NULL},
363 { szUnregisterProgIdInfo, NULL},
364 { szUnregisterTypeLibraries, NULL},
365 { szValidateProductID, NULL},
366 { szWriteEnvironmentStrings, NULL},
367 { szWriteIniValues, ACTION_WriteIniValues },
368 { szWriteRegistryValues, ACTION_WriteRegistryValues},
369 { NULL, NULL},
373 /********************************************************
374 * helper functions to get around current HACKS and such
375 ********************************************************/
376 inline static void reduce_to_longfilename(WCHAR* filename)
378 LPWSTR p = strchrW(filename,'|');
379 if (p)
380 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
383 WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
385 UINT rc;
386 DWORD sz;
387 LPWSTR ret;
389 sz = 0;
390 if (MSI_RecordIsNull(row,index))
391 return NULL;
393 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
395 /* having an empty string is different than NULL */
396 if (sz == 0)
398 ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
399 ret[0] = 0;
400 return ret;
403 sz ++;
404 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
405 rc = MSI_RecordGetStringW(row,index,ret,&sz);
406 if (rc!=ERROR_SUCCESS)
408 ERR("Unable to load dynamic string\n");
409 HeapFree(GetProcessHeap(), 0, ret);
410 ret = NULL;
412 return ret;
415 LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop, UINT* rc)
417 DWORD sz = 0;
418 LPWSTR str;
419 UINT r;
421 r = MSI_GetPropertyW(package, prop, NULL, &sz);
422 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
424 if (rc)
425 *rc = r;
426 return NULL;
428 sz++;
429 str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
430 r = MSI_GetPropertyW(package, prop, str, &sz);
431 if (r != ERROR_SUCCESS)
433 HeapFree(GetProcessHeap(),0,str);
434 str = NULL;
436 if (rc)
437 *rc = r;
438 return str;
441 int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
443 int rc = -1;
444 DWORD i;
446 for (i = 0; i < package->loaded_components; i++)
448 if (strcmpW(Component,package->components[i].Component)==0)
450 rc = i;
451 break;
454 return rc;
457 int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
459 int rc = -1;
460 DWORD i;
462 for (i = 0; i < package->loaded_features; i++)
464 if (strcmpW(Feature,package->features[i].Feature)==0)
466 rc = i;
467 break;
470 return rc;
473 int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
475 int rc = -1;
476 DWORD i;
478 for (i = 0; i < package->loaded_files; i++)
480 if (strcmpW(file,package->files[i].File)==0)
482 rc = i;
483 break;
486 return rc;
489 int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
491 DWORD i;
492 DWORD index;
494 if (!package)
495 return -2;
497 for (i=0; i < package->loaded_files; i++)
498 if (strcmpW(package->files[i].File,name)==0)
499 return -1;
501 index = package->loaded_files;
502 package->loaded_files++;
503 if (package->loaded_files== 1)
504 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
505 else
506 package->files = HeapReAlloc(GetProcessHeap(),0,
507 package->files , package->loaded_files * sizeof(MSIFILE));
509 memset(&package->files[index],0,sizeof(MSIFILE));
511 package->files[index].File = dupstrW(name);
512 package->files[index].TargetPath = dupstrW(path);
513 package->files[index].Temporary = TRUE;
515 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
517 return 0;
520 static void remove_tracked_tempfiles(MSIPACKAGE* package)
522 DWORD i;
524 if (!package)
525 return;
527 for (i = 0; i < package->loaded_files; i++)
529 if (package->files[i].Temporary)
531 TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
532 DeleteFileW(package->files[i].TargetPath);
538 /* wrapper to resist a need for a full rewrite right now */
539 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
541 if (ptr)
543 MSIRECORD *rec = MSI_CreateRecord(1);
544 DWORD size = 0;
546 MSI_RecordSetStringW(rec,0,ptr);
547 MSI_FormatRecordW(package,rec,NULL,&size);
548 if (size >= 0)
550 size++;
551 *data = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
552 if (size > 1)
553 MSI_FormatRecordW(package,rec,*data,&size);
554 else
555 *data[0] = 0;
556 msiobj_release( &rec->hdr );
557 return sizeof(WCHAR)*size;
559 msiobj_release( &rec->hdr );
562 *data = NULL;
563 return 0;
566 /* Called when the package is being closed */
567 void ACTION_free_package_structures( MSIPACKAGE* package)
569 INT i;
571 TRACE("Freeing package action data\n");
573 remove_tracked_tempfiles(package);
575 /* No dynamic buffers in features */
576 if (package->features && package->loaded_features > 0)
577 HeapFree(GetProcessHeap(),0,package->features);
579 for (i = 0; i < package->loaded_folders; i++)
581 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
582 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
583 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
584 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
585 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
586 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
588 if (package->folders && package->loaded_folders > 0)
589 HeapFree(GetProcessHeap(),0,package->folders);
591 for (i = 0; i < package->loaded_components; i++)
592 HeapFree(GetProcessHeap(),0,package->components[i].FullKeypath);
594 if (package->components && package->loaded_components > 0)
595 HeapFree(GetProcessHeap(),0,package->components);
597 for (i = 0; i < package->loaded_files; i++)
599 HeapFree(GetProcessHeap(),0,package->files[i].File);
600 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
601 HeapFree(GetProcessHeap(),0,package->files[i].Version);
602 HeapFree(GetProcessHeap(),0,package->files[i].Language);
603 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
604 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
607 if (package->files && package->loaded_files > 0)
608 HeapFree(GetProcessHeap(),0,package->files);
610 for (i = 0; i < package->DeferredActionCount; i++)
611 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
612 HeapFree(GetProcessHeap(),0,package->DeferredAction);
614 for (i = 0; i < package->CommitActionCount; i++)
615 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
616 HeapFree(GetProcessHeap(),0,package->CommitAction);
618 HeapFree(GetProcessHeap(),0,package->PackagePath);
621 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
623 MSIRECORD * row;
625 row = MSI_CreateRecord(4);
626 MSI_RecordSetInteger(row,1,a);
627 MSI_RecordSetInteger(row,2,b);
628 MSI_RecordSetInteger(row,3,c);
629 MSI_RecordSetInteger(row,4,d);
630 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
631 msiobj_release(&row->hdr);
633 msi_dialog_check_messages(package->dialog, NULL);
636 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
638 static const WCHAR Query_t[] =
639 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
640 'A','c','t','i','o', 'n','T','e','x','t',' ','W','H','E','R','E',' ',
641 'A','c','t','i','o','n',' ','=', ' ','\'','%','s','\'',0};
642 WCHAR message[1024];
643 UINT rc;
644 MSIQUERY * view;
645 MSIRECORD * row = 0;
646 DWORD size;
648 if (!package->LastAction || strcmpW(package->LastAction,action))
650 rc = MSI_OpenQuery(package->db, &view, Query_t, action);
651 if (rc != ERROR_SUCCESS)
652 return;
654 rc = MSI_ViewExecute(view, 0);
655 if (rc != ERROR_SUCCESS)
657 MSI_ViewClose(view);
658 return;
660 rc = MSI_ViewFetch(view,&row);
661 if (rc != ERROR_SUCCESS)
663 MSI_ViewClose(view);
664 return;
667 if (MSI_RecordIsNull(row,3))
669 msiobj_release(&row->hdr);
670 MSI_ViewClose(view);
671 msiobj_release(&view->hdr);
672 return;
675 /* update the cached actionformat */
676 HeapFree(GetProcessHeap(),0,package->ActionFormat);
677 package->ActionFormat = load_dynamic_stringW(row,3);
679 HeapFree(GetProcessHeap(),0,package->LastAction);
680 package->LastAction = dupstrW(action);
682 msiobj_release(&row->hdr);
683 MSI_ViewClose(view);
684 msiobj_release(&view->hdr);
687 MSI_RecordSetStringW(record,0,package->ActionFormat);
688 size = 1024;
689 MSI_FormatRecordW(package,record,message,&size);
691 row = MSI_CreateRecord(1);
692 MSI_RecordSetStringW(row,1,message);
694 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
695 msiobj_release(&row->hdr);
699 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
701 static const WCHAR template_s[]=
702 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
703 '.',0};
704 static const WCHAR format[] =
705 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
706 static const WCHAR Query_t[] =
707 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
708 'A','c','t','i','o', 'n','T','e','x','t',' ','W','H','E','R','E', ' ',
709 'A','c','t','i','o','n',' ','=', ' ','\'','%','s','\'',0};
710 WCHAR message[1024];
711 WCHAR timet[0x100];
712 UINT rc;
713 MSIQUERY * view;
714 MSIRECORD * row = 0;
715 WCHAR *ActionText=NULL;
717 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
719 rc = MSI_OpenQuery(package->db, &view, Query_t, action);
720 if (rc != ERROR_SUCCESS)
721 return;
722 rc = MSI_ViewExecute(view, 0);
723 if (rc != ERROR_SUCCESS)
725 MSI_ViewClose(view);
726 msiobj_release(&view->hdr);
727 return;
729 rc = MSI_ViewFetch(view,&row);
730 if (rc != ERROR_SUCCESS)
732 MSI_ViewClose(view);
733 msiobj_release(&view->hdr);
734 return;
737 ActionText = load_dynamic_stringW(row,2);
738 msiobj_release(&row->hdr);
739 MSI_ViewClose(view);
740 msiobj_release(&view->hdr);
742 sprintfW(message,template_s,timet,action,ActionText);
744 row = MSI_CreateRecord(1);
745 MSI_RecordSetStringW(row,1,message);
747 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
748 msiobj_release(&row->hdr);
749 HeapFree(GetProcessHeap(),0,ActionText);
752 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
753 UINT rc)
755 MSIRECORD * row;
756 static const WCHAR template_s[]=
757 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
758 '%','s', '.',0};
759 static const WCHAR template_e[]=
760 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
761 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
762 '%','i','.',0};
763 static const WCHAR format[] =
764 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
765 WCHAR message[1024];
766 WCHAR timet[0x100];
768 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
769 if (start)
770 sprintfW(message,template_s,timet,action);
771 else
772 sprintfW(message,template_e,timet,action,rc);
774 row = MSI_CreateRecord(1);
775 MSI_RecordSetStringW(row,1,message);
777 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
778 msiobj_release(&row->hdr);
782 * build_directory_name()
784 * This function is to save messing round with directory names
785 * It handles adding backslashes between path segments,
786 * and can add \ at the end of the directory name if told to.
788 * It takes a variable number of arguments.
789 * It always allocates a new string for the result, so make sure
790 * to free the return value when finished with it.
792 * The first arg is the number of path segments that follow.
793 * The arguments following count are a list of path segments.
794 * A path segment may be NULL.
796 * Path segments will be added with a \ separating them.
797 * A \ will not be added after the last segment, however if the
798 * last segment is NULL, then the last character will be a \
801 static LPWSTR build_directory_name(DWORD count, ...)
803 DWORD sz = 1, i;
804 LPWSTR dir;
805 va_list va;
807 va_start(va,count);
808 for(i=0; i<count; i++)
810 LPCWSTR str = va_arg(va,LPCWSTR);
811 if (str)
812 sz += strlenW(str) + 1;
814 va_end(va);
816 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
817 dir[0]=0;
819 va_start(va,count);
820 for(i=0; i<count; i++)
822 LPCWSTR str = va_arg(va,LPCWSTR);
823 if (!str)
824 continue;
825 strcatW(dir, str);
826 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
827 strcatW(dir, cszbs);
829 return dir;
832 static BOOL ACTION_VerifyComponentForAction(MSIPACKAGE* package, INT index,
833 INSTALLSTATE check )
835 if (package->components[index].Installed == check)
836 return FALSE;
838 if (package->components[index].ActionRequest == check)
839 return TRUE;
840 else
841 return FALSE;
844 static BOOL ACTION_VerifyFeatureForAction(MSIPACKAGE* package, INT index,
845 INSTALLSTATE check )
847 if (package->features[index].Installed == check)
848 return FALSE;
850 if (package->features[index].ActionRequest == check)
851 return TRUE;
852 else
853 return FALSE;
857 /****************************************************
858 * TOP level entry points
859 *****************************************************/
861 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
862 LPCWSTR szCommandLine)
864 DWORD sz;
865 WCHAR buffer[10];
866 UINT rc;
867 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
868 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
869 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
871 MSI_SetPropertyW(package, szAction, szInstall);
872 package->ExecuteSequenceRun = FALSE;
874 if (szPackagePath)
876 LPWSTR p, check, path;
878 package->PackagePath = dupstrW(szPackagePath);
879 path = dupstrW(szPackagePath);
880 p = strrchrW(path,'\\');
881 if (p)
883 p++;
884 *p=0;
886 else
888 HeapFree(GetProcessHeap(),0,path);
889 path = HeapAlloc(GetProcessHeap(),0,MAX_PATH*sizeof(WCHAR));
890 GetCurrentDirectoryW(MAX_PATH,path);
891 strcatW(path,cszbs);
894 check = load_dynamic_property(package, cszSourceDir,NULL);
895 if (!check)
896 MSI_SetPropertyW(package, cszSourceDir, path);
897 else
898 HeapFree(GetProcessHeap(), 0, check);
900 HeapFree(GetProcessHeap(), 0, path);
903 if (szCommandLine)
905 LPWSTR ptr,ptr2;
906 ptr = (LPWSTR)szCommandLine;
908 while (*ptr)
910 WCHAR *prop = NULL;
911 WCHAR *val = NULL;
913 TRACE("Looking at %s\n",debugstr_w(ptr));
915 ptr2 = strchrW(ptr,'=');
916 if (ptr2)
918 BOOL quote=FALSE;
919 DWORD len = 0;
921 while (*ptr == ' ') ptr++;
922 len = ptr2-ptr;
923 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
924 strncpyW(prop,ptr,len);
925 prop[len]=0;
926 ptr2++;
928 len = 0;
929 ptr = ptr2;
930 while (*ptr && (quote || (!quote && *ptr!=' ')))
932 if (*ptr == '"')
933 quote = !quote;
934 ptr++;
935 len++;
938 if (*ptr2=='"')
940 ptr2++;
941 len -= 2;
943 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
944 strncpyW(val,ptr2,len);
945 val[len] = 0;
947 if (strlenW(prop) > 0)
949 TRACE("Found commandline property (%s) = (%s)\n",
950 debugstr_w(prop), debugstr_w(val));
951 MSI_SetPropertyW(package,prop,val);
953 HeapFree(GetProcessHeap(),0,val);
954 HeapFree(GetProcessHeap(),0,prop);
956 ptr++;
960 sz = 10;
961 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
963 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
965 rc = ACTION_ProcessUISequence(package);
966 if (rc == ERROR_SUCCESS)
967 rc = ACTION_ProcessExecSequence(package,TRUE);
969 else
970 rc = ACTION_ProcessExecSequence(package,FALSE);
972 else
973 rc = ACTION_ProcessExecSequence(package,FALSE);
975 if (rc == -1)
977 /* install was halted but should be considered a success */
978 rc = ERROR_SUCCESS;
981 /* process the ending type action */
982 if (rc == ERROR_SUCCESS)
983 ACTION_PerformActionSequence(package,-1);
984 else if (rc == ERROR_INSTALL_USEREXIT)
985 ACTION_PerformActionSequence(package,-2);
986 else if (rc == ERROR_FUNCTION_FAILED)
987 ACTION_PerformActionSequence(package,-3);
988 else if (rc == ERROR_INSTALL_SUSPEND)
989 ACTION_PerformActionSequence(package,-4);
991 /* finish up running custom actions */
992 ACTION_FinishCustomActions(package);
994 return rc;
997 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq)
999 MSIQUERY * view;
1000 UINT rc;
1001 WCHAR buffer[0x100];
1002 DWORD sz = 0x100;
1003 MSIRECORD * row = 0;
1004 static const WCHAR ExecSeqQuery[] =
1005 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1006 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1007 'S','e','q','u','e','n','c','e',' ', 'W','H','E','R','E',' ',
1008 'S','e','q','u','e','n','c','e',' ', '=',' ','%','i',0};
1010 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1012 if (rc == ERROR_SUCCESS)
1014 rc = MSI_ViewExecute(view, 0);
1016 if (rc != ERROR_SUCCESS)
1018 MSI_ViewClose(view);
1019 msiobj_release(&view->hdr);
1020 goto end;
1023 TRACE("Running the actions\n");
1025 rc = MSI_ViewFetch(view,&row);
1026 if (rc != ERROR_SUCCESS)
1028 rc = ERROR_SUCCESS;
1029 goto end;
1032 /* check conditions */
1033 if (!MSI_RecordIsNull(row,2))
1035 LPWSTR cond = NULL;
1036 cond = load_dynamic_stringW(row,2);
1038 if (cond)
1040 /* this is a hack to skip errors in the condition code */
1041 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
1043 HeapFree(GetProcessHeap(),0,cond);
1044 msiobj_release(&row->hdr);
1045 goto end;
1047 else
1048 HeapFree(GetProcessHeap(),0,cond);
1052 sz=0x100;
1053 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1054 if (rc != ERROR_SUCCESS)
1056 ERR("Error is %x\n",rc);
1057 msiobj_release(&row->hdr);
1058 goto end;
1061 rc = ACTION_PerformAction(package,buffer);
1062 msiobj_release(&row->hdr);
1063 end:
1064 MSI_ViewClose(view);
1065 msiobj_release(&view->hdr);
1067 else
1068 rc = ERROR_SUCCESS;
1070 return rc;
1073 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
1075 MSIQUERY * view;
1076 UINT rc;
1077 static const WCHAR ExecSeqQuery[] =
1078 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1079 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1080 'S','e','q','u','e','n','c','e',' ', 'W','H','E','R','E',' ',
1081 'S','e','q','u','e','n','c','e',' ', '>',' ','%','i',' ',
1082 'O','R','D','E','R',' ', 'B','Y',' ',
1083 'S','e','q','u','e','n','c','e',0 };
1084 MSIRECORD * row = 0;
1085 static const WCHAR IVQuery[] =
1086 {'S','E','L','E','C','T',' ','S','e','q','u','e','n','c','e',' ',
1087 'F','R','O','M',' ','I','n','s','t','a','l','l',
1088 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
1089 'W','H','E','R','E',' ','A','c','t','i','o','n',' ','=',' ','`',
1090 'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`', 0};
1091 INT seq = 0;
1094 if (package->ExecuteSequenceRun)
1096 TRACE("Execute Sequence already Run\n");
1097 return ERROR_SUCCESS;
1100 package->ExecuteSequenceRun = TRUE;
1102 /* get the sequence number */
1103 if (UIran)
1105 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
1106 if (rc != ERROR_SUCCESS)
1107 return rc;
1108 rc = MSI_ViewExecute(view, 0);
1109 if (rc != ERROR_SUCCESS)
1111 MSI_ViewClose(view);
1112 msiobj_release(&view->hdr);
1113 return rc;
1115 rc = MSI_ViewFetch(view,&row);
1116 if (rc != ERROR_SUCCESS)
1118 MSI_ViewClose(view);
1119 msiobj_release(&view->hdr);
1120 return rc;
1122 seq = MSI_RecordGetInteger(row,1);
1123 msiobj_release(&row->hdr);
1124 MSI_ViewClose(view);
1125 msiobj_release(&view->hdr);
1128 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1129 if (rc == ERROR_SUCCESS)
1131 rc = MSI_ViewExecute(view, 0);
1133 if (rc != ERROR_SUCCESS)
1135 MSI_ViewClose(view);
1136 msiobj_release(&view->hdr);
1137 goto end;
1140 TRACE("Running the actions\n");
1142 while (1)
1144 WCHAR buffer[0x100];
1145 DWORD sz = 0x100;
1147 rc = MSI_ViewFetch(view,&row);
1148 if (rc != ERROR_SUCCESS)
1150 rc = ERROR_SUCCESS;
1151 break;
1154 /* check conditions */
1155 if (!MSI_RecordIsNull(row,2))
1157 LPWSTR cond = NULL;
1158 cond = load_dynamic_stringW(row,2);
1160 if (cond)
1162 /* this is a hack to skip errors in the condition code */
1163 if (MSI_EvaluateConditionW(package, cond) ==
1164 MSICONDITION_FALSE)
1166 HeapFree(GetProcessHeap(),0,cond);
1167 msiobj_release(&row->hdr);
1168 continue;
1170 else
1171 HeapFree(GetProcessHeap(),0,cond);
1175 sz=0x100;
1176 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1177 if (rc != ERROR_SUCCESS)
1179 ERR("Error is %x\n",rc);
1180 msiobj_release(&row->hdr);
1181 break;
1184 rc = ACTION_PerformAction(package,buffer);
1186 if (rc == ERROR_FUNCTION_NOT_CALLED)
1187 rc = ERROR_SUCCESS;
1189 if (rc != ERROR_SUCCESS)
1191 ERR("Execution halted due to error (%i)\n",rc);
1192 msiobj_release(&row->hdr);
1193 break;
1196 msiobj_release(&row->hdr);
1199 MSI_ViewClose(view);
1200 msiobj_release(&view->hdr);
1203 end:
1204 return rc;
1208 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1210 MSIQUERY * view;
1211 UINT rc;
1212 static const WCHAR ExecSeqQuery [] =
1213 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1214 'I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1215 ' ','W','H','E','R','E',' ', 'S','e','q','u','e','n','c','e',' ',
1216 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1217 'S','e','q','u','e','n','c','e',0};
1219 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1221 if (rc == ERROR_SUCCESS)
1223 rc = MSI_ViewExecute(view, 0);
1225 if (rc != ERROR_SUCCESS)
1227 MSI_ViewClose(view);
1228 msiobj_release(&view->hdr);
1229 goto end;
1232 TRACE("Running the actions \n");
1234 while (1)
1236 WCHAR buffer[0x100];
1237 DWORD sz = 0x100;
1238 MSIRECORD * row = 0;
1240 rc = MSI_ViewFetch(view,&row);
1241 if (rc != ERROR_SUCCESS)
1243 rc = ERROR_SUCCESS;
1244 break;
1247 /* check conditions */
1248 if (!MSI_RecordIsNull(row,2))
1250 LPWSTR cond = NULL;
1251 cond = load_dynamic_stringW(row,2);
1253 if (cond)
1255 /* this is a hack to skip errors in the condition code */
1256 if (MSI_EvaluateConditionW(package, cond) ==
1257 MSICONDITION_FALSE)
1259 HeapFree(GetProcessHeap(),0,cond);
1260 msiobj_release(&row->hdr);
1261 continue;
1263 else
1264 HeapFree(GetProcessHeap(),0,cond);
1268 sz=0x100;
1269 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1270 if (rc != ERROR_SUCCESS)
1272 ERR("Error is %x\n",rc);
1273 msiobj_release(&row->hdr);
1274 break;
1277 rc = ACTION_PerformUIAction(package,buffer);
1279 if (rc == ERROR_FUNCTION_NOT_CALLED)
1280 rc = ERROR_SUCCESS;
1282 if (rc != ERROR_SUCCESS)
1284 ERR("Execution halted due to error (%i)\n",rc);
1285 msiobj_release(&row->hdr);
1286 break;
1289 msiobj_release(&row->hdr);
1292 MSI_ViewClose(view);
1293 msiobj_release(&view->hdr);
1296 end:
1297 return rc;
1300 /********************************************************
1301 * ACTION helper functions and functions that perform the actions
1302 *******************************************************/
1303 BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action, UINT* rc)
1305 BOOL ret = FALSE;
1307 int i;
1308 i = 0;
1309 while (StandardActions[i].action != NULL)
1311 if (strcmpW(StandardActions[i].action, action)==0)
1313 ui_actioninfo(package, action, TRUE, 0);
1314 ui_actionstart(package, action);
1315 if (StandardActions[i].handler)
1317 *rc = StandardActions[i].handler(package);
1319 else
1321 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action));
1322 *rc = ERROR_SUCCESS;
1324 ui_actioninfo(package, action, FALSE, *rc);
1325 ret = TRUE;
1326 break;
1328 i++;
1330 return ret;
1333 BOOL ACTION_HandleDialogBox(MSIPACKAGE *package, LPCWSTR dialog, UINT* rc)
1335 BOOL ret = FALSE;
1338 * for the UI when we get that working
1340 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1342 *rc = package->CurrentInstallState;
1343 ret = TRUE;
1346 return ret;
1349 BOOL ACTION_HandleCustomAction(MSIPACKAGE* package, LPCWSTR action, UINT* rc)
1351 BOOL ret=FALSE;
1352 UINT arc;
1354 arc = ACTION_CustomAction(package,action,FALSE);
1356 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1358 *rc = arc;
1359 ret = TRUE;
1361 return ret;
1365 * A lot of actions are really important even if they don't do anything
1366 * explicit... Lots of properties are set at the beginning of the installation
1367 * CostFinalize does a bunch of work to translate the directories and such
1369 * But until I get write access to the database that is hard, so I am going to
1370 * hack it to see if I can get something to run.
1372 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
1374 UINT rc = ERROR_SUCCESS;
1375 BOOL handled;
1377 TRACE("Performing action (%s)\n",debugstr_w(action));
1379 handled = ACTION_HandleStandardAction(package, action, &rc);
1381 if (!handled)
1382 handled = ACTION_HandleCustomAction(package, action, &rc);
1384 if (!handled)
1386 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1387 rc = ERROR_FUNCTION_NOT_CALLED;
1390 package->CurrentInstallState = rc;
1391 return rc;
1394 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action)
1396 UINT rc = ERROR_SUCCESS;
1397 BOOL handled = FALSE;
1399 TRACE("Performing action (%s)\n",debugstr_w(action));
1401 handled = ACTION_HandleStandardAction(package, action, &rc);
1403 if (!handled)
1404 handled = ACTION_HandleCustomAction(package, action, &rc);
1406 if (!handled)
1407 handled = ACTION_HandleDialogBox(package, action, &rc);
1409 msi_dialog_check_messages( package->dialog, NULL );
1411 if (!handled)
1413 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1414 rc = ERROR_FUNCTION_NOT_CALLED;
1417 package->CurrentInstallState = rc;
1418 return rc;
1421 /***********************************************************************
1422 * create_full_pathW
1424 * Recursively create all directories in the path.
1426 * shamelessly stolen from setupapi/queue.c
1428 static BOOL create_full_pathW(const WCHAR *path)
1430 BOOL ret = TRUE;
1431 int len;
1432 WCHAR *new_path;
1434 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1435 sizeof(WCHAR));
1437 strcpyW(new_path, path);
1439 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1440 new_path[len - 1] = 0;
1442 while(!CreateDirectoryW(new_path, NULL))
1444 WCHAR *slash;
1445 DWORD last_error = GetLastError();
1446 if(last_error == ERROR_ALREADY_EXISTS)
1447 break;
1449 if(last_error != ERROR_PATH_NOT_FOUND)
1451 ret = FALSE;
1452 break;
1455 if(!(slash = strrchrW(new_path, '\\')))
1457 ret = FALSE;
1458 break;
1461 len = slash - new_path;
1462 new_path[len] = 0;
1463 if(!create_full_pathW(new_path))
1465 ret = FALSE;
1466 break;
1468 new_path[len] = '\\';
1471 HeapFree(GetProcessHeap(), 0, new_path);
1472 return ret;
1476 * Also we cannot enable/disable components either, so for now I am just going
1477 * to do all the directories for all the components.
1479 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1481 static const WCHAR ExecSeqQuery[] =
1482 {'S','E','L','E','C','T',' ','D','i','r','e','c','t','o','r','y','_',
1483 ' ','F','R','O','M',' ',
1484 'C','r','e','a','t','e','F','o','l','d','e','r',0 };
1485 UINT rc;
1486 MSIQUERY *view;
1487 MSIFOLDER *folder;
1489 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1490 if (rc != ERROR_SUCCESS)
1491 return ERROR_SUCCESS;
1493 rc = MSI_ViewExecute(view, 0);
1494 if (rc != ERROR_SUCCESS)
1496 MSI_ViewClose(view);
1497 msiobj_release(&view->hdr);
1498 return rc;
1501 while (1)
1503 WCHAR dir[0x100];
1504 LPWSTR full_path;
1505 DWORD sz;
1506 MSIRECORD *row = NULL, *uirow;
1508 rc = MSI_ViewFetch(view,&row);
1509 if (rc != ERROR_SUCCESS)
1511 rc = ERROR_SUCCESS;
1512 break;
1515 sz=0x100;
1516 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1518 if (rc!= ERROR_SUCCESS)
1520 ERR("Unable to get folder id \n");
1521 msiobj_release(&row->hdr);
1522 continue;
1525 sz = MAX_PATH;
1526 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1527 if (!full_path)
1529 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1530 msiobj_release(&row->hdr);
1531 continue;
1534 TRACE("Folder is %s\n",debugstr_w(full_path));
1536 /* UI stuff */
1537 uirow = MSI_CreateRecord(1);
1538 MSI_RecordSetStringW(uirow,1,full_path);
1539 ui_actiondata(package,szCreateFolders,uirow);
1540 msiobj_release( &uirow->hdr );
1542 if (folder->State == 0)
1543 create_full_pathW(full_path);
1545 folder->State = 3;
1547 msiobj_release(&row->hdr);
1548 HeapFree(GetProcessHeap(),0,full_path);
1550 MSI_ViewClose(view);
1551 msiobj_release(&view->hdr);
1553 return rc;
1556 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1558 int index = package->loaded_components;
1559 DWORD sz;
1561 /* fill in the data */
1563 package->loaded_components++;
1564 if (package->loaded_components == 1)
1565 package->components = HeapAlloc(GetProcessHeap(),0,
1566 sizeof(MSICOMPONENT));
1567 else
1568 package->components = HeapReAlloc(GetProcessHeap(),0,
1569 package->components, package->loaded_components *
1570 sizeof(MSICOMPONENT));
1572 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1574 sz = 96;
1575 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1577 TRACE("Loading Component %s\n",
1578 debugstr_w(package->components[index].Component));
1580 sz = 0x100;
1581 if (!MSI_RecordIsNull(row,2))
1582 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1584 sz = 96;
1585 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1587 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1589 sz = 0x100;
1590 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1592 sz = 96;
1593 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1595 package->components[index].Installed = INSTALLSTATE_UNKNOWN;
1596 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1597 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1599 package->components[index].Enabled = TRUE;
1601 return index;
1604 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1606 int index = package->loaded_features;
1607 DWORD sz;
1608 static const WCHAR Query1[] =
1609 {'S','E','L','E','C','T',' ','C','o','m','p','o','n','e','n','t','_',
1610 ' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1611 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ',
1612 'F','e', 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1613 static const WCHAR Query2[] =
1614 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1615 'C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ',
1616 'C','o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1617 MSIQUERY * view;
1618 MSIQUERY * view2;
1619 MSIRECORD * row2;
1620 MSIRECORD * row3;
1621 UINT rc;
1623 /* fill in the data */
1625 package->loaded_features ++;
1626 if (package->loaded_features == 1)
1627 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1628 else
1629 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1630 package->loaded_features * sizeof(MSIFEATURE));
1632 memset(&package->features[index],0,sizeof(MSIFEATURE));
1634 sz = 96;
1635 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1637 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1639 sz = 96;
1640 if (!MSI_RecordIsNull(row,2))
1641 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1643 sz = 0x100;
1644 if (!MSI_RecordIsNull(row,3))
1645 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1647 sz = 0x100;
1648 if (!MSI_RecordIsNull(row,4))
1649 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1651 if (!MSI_RecordIsNull(row,5))
1652 package->features[index].Display = MSI_RecordGetInteger(row,5);
1654 package->features[index].Level= MSI_RecordGetInteger(row,6);
1656 sz = 96;
1657 if (!MSI_RecordIsNull(row,7))
1658 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1660 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1662 package->features[index].Installed = INSTALLSTATE_UNKNOWN;
1663 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1664 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1666 /* load feature components */
1668 rc = MSI_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1669 if (rc != ERROR_SUCCESS)
1670 return;
1671 rc = MSI_ViewExecute(view,0);
1672 if (rc != ERROR_SUCCESS)
1674 MSI_ViewClose(view);
1675 msiobj_release(&view->hdr);
1676 return;
1678 while (1)
1680 DWORD sz = 0x100;
1681 WCHAR buffer[0x100];
1682 DWORD rc;
1683 INT c_indx;
1684 INT cnt = package->features[index].ComponentCount;
1686 rc = MSI_ViewFetch(view,&row2);
1687 if (rc != ERROR_SUCCESS)
1688 break;
1690 sz = 0x100;
1691 MSI_RecordGetStringW(row2,1,buffer,&sz);
1693 /* check to see if the component is already loaded */
1694 c_indx = get_loaded_component(package,buffer);
1695 if (c_indx != -1)
1697 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1698 c_indx);
1699 package->features[index].Components[cnt] = c_indx;
1700 package->features[index].ComponentCount ++;
1701 continue;
1704 rc = MSI_OpenQuery(package->db, &view2, Query2, buffer);
1705 if (rc != ERROR_SUCCESS)
1707 msiobj_release( &row2->hdr );
1708 continue;
1710 rc = MSI_ViewExecute(view2,0);
1711 if (rc != ERROR_SUCCESS)
1713 msiobj_release( &row2->hdr );
1714 MSI_ViewClose(view2);
1715 msiobj_release( &view2->hdr );
1716 continue;
1718 while (1)
1720 DWORD rc;
1722 rc = MSI_ViewFetch(view2,&row3);
1723 if (rc != ERROR_SUCCESS)
1724 break;
1725 c_indx = load_component(package,row3);
1726 msiobj_release( &row3->hdr );
1728 package->features[index].Components[cnt] = c_indx;
1729 package->features[index].ComponentCount ++;
1730 TRACE("Loaded new component to index %i\n",c_indx);
1732 MSI_ViewClose(view2);
1733 msiobj_release( &view2->hdr );
1734 msiobj_release( &row2->hdr );
1736 MSI_ViewClose(view);
1737 msiobj_release(&view->hdr);
1741 * I am not doing any of the costing functionality yet.
1742 * Mostly looking at doing the Component and Feature loading
1744 * The native MSI does A LOT of modification to tables here. Mostly adding
1745 * a lot of temporary columns to the Feature and Component tables.
1747 * note: Native msi also tracks the short filename. But I am only going to
1748 * track the long ones. Also looking at this directory table
1749 * it appears that the directory table does not get the parents
1750 * resolved base on property only based on their entries in the
1751 * directory table.
1753 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1755 MSIQUERY * view;
1756 MSIRECORD * row;
1757 UINT rc;
1758 static const WCHAR Query_all[] =
1759 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1760 'F','e','a','t','u','r','e',0};
1761 static const WCHAR szCosting[] =
1762 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1763 static const WCHAR szZero[] = { '0', 0 };
1765 MSI_SetPropertyW(package, szCosting, szZero);
1766 MSI_SetPropertyW(package, cszRootDrive , c_colon);
1768 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1769 if (rc != ERROR_SUCCESS)
1770 return rc;
1771 rc = MSI_ViewExecute(view,0);
1772 if (rc != ERROR_SUCCESS)
1774 MSI_ViewClose(view);
1775 msiobj_release(&view->hdr);
1776 return rc;
1778 while (1)
1780 DWORD rc;
1782 rc = MSI_ViewFetch(view,&row);
1783 if (rc != ERROR_SUCCESS)
1784 break;
1786 load_feature(package,row);
1787 msiobj_release(&row->hdr);
1789 MSI_ViewClose(view);
1790 msiobj_release(&view->hdr);
1792 return ERROR_SUCCESS;
1795 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1797 DWORD index = package->loaded_files;
1798 DWORD i;
1799 LPWSTR buffer;
1801 /* fill in the data */
1803 package->loaded_files++;
1804 if (package->loaded_files== 1)
1805 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1806 else
1807 package->files = HeapReAlloc(GetProcessHeap(),0,
1808 package->files , package->loaded_files * sizeof(MSIFILE));
1810 memset(&package->files[index],0,sizeof(MSIFILE));
1812 package->files[index].File = load_dynamic_stringW(row, 1);
1813 buffer = load_dynamic_stringW(row, 2);
1815 package->files[index].ComponentIndex = -1;
1816 for (i = 0; i < package->loaded_components; i++)
1817 if (strcmpW(package->components[i].Component,buffer)==0)
1819 package->files[index].ComponentIndex = i;
1820 break;
1822 if (package->files[index].ComponentIndex == -1)
1823 ERR("Unfound Component %s\n",debugstr_w(buffer));
1824 HeapFree(GetProcessHeap(), 0, buffer);
1826 package->files[index].FileName = load_dynamic_stringW(row,3);
1828 reduce_to_longfilename(package->files[index].FileName);
1830 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1831 package->files[index].Version = load_dynamic_stringW(row, 5);
1832 package->files[index].Language = load_dynamic_stringW(row, 6);
1833 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1834 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1836 package->files[index].Temporary = FALSE;
1837 package->files[index].State = 0;
1839 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1841 return ERROR_SUCCESS;
1844 static UINT ACTION_FileCost(MSIPACKAGE *package)
1846 MSIQUERY * view;
1847 MSIRECORD * row;
1848 UINT rc;
1849 static const WCHAR Query[] =
1850 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1851 'F','i','l','e',' ', 'O','R','D','E','R',' ','B','Y',' ',
1852 'S','e','q','u','e','n','c','e', 0};
1854 if (!package)
1855 return ERROR_INVALID_HANDLE;
1857 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1858 if (rc != ERROR_SUCCESS)
1859 return ERROR_SUCCESS;
1861 rc = MSI_ViewExecute(view, 0);
1862 if (rc != ERROR_SUCCESS)
1864 MSI_ViewClose(view);
1865 msiobj_release(&view->hdr);
1866 return ERROR_SUCCESS;
1869 while (1)
1871 rc = MSI_ViewFetch(view,&row);
1872 if (rc != ERROR_SUCCESS)
1874 rc = ERROR_SUCCESS;
1875 break;
1877 load_file(package,row);
1878 msiobj_release(&row->hdr);
1880 MSI_ViewClose(view);
1881 msiobj_release(&view->hdr);
1883 return ERROR_SUCCESS;
1886 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1888 static const WCHAR Query[] =
1889 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1890 'D','i','r','e','c', 't','o','r','y',' ','W','H','E','R','E',' ','`',
1891 'D','i','r','e','c','t', 'o','r','y','`',' ','=',' ','`','%','s','`',
1893 UINT rc;
1894 MSIQUERY * view;
1895 LPWSTR ptargetdir, targetdir, parent, srcdir;
1896 MSIRECORD * row = 0;
1897 INT index = -1;
1898 DWORD i;
1900 TRACE("Looking for dir %s\n",debugstr_w(dir));
1902 for (i = 0; i < package->loaded_folders; i++)
1904 if (strcmpW(package->folders[i].Directory,dir)==0)
1906 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1907 return i;
1911 TRACE("Working to load %s\n",debugstr_w(dir));
1913 index = package->loaded_folders++;
1914 if (package->loaded_folders==1)
1915 package->folders = HeapAlloc(GetProcessHeap(),0,
1916 sizeof(MSIFOLDER));
1917 else
1918 package->folders= HeapReAlloc(GetProcessHeap(),0,
1919 package->folders, package->loaded_folders*
1920 sizeof(MSIFOLDER));
1922 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1924 package->folders[index].Directory = dupstrW(dir);
1926 rc = MSI_OpenQuery(package->db, &view, Query, dir);
1927 if (rc != ERROR_SUCCESS)
1928 return -1;
1930 rc = MSI_ViewExecute(view, 0);
1931 if (rc != ERROR_SUCCESS)
1933 MSI_ViewClose(view);
1934 msiobj_release(&view->hdr);
1935 return -1;
1938 rc = MSI_ViewFetch(view,&row);
1939 if (rc != ERROR_SUCCESS)
1941 MSI_ViewClose(view);
1942 msiobj_release(&view->hdr);
1943 return -1;
1946 ptargetdir = targetdir = load_dynamic_stringW(row,3);
1948 /* split src and target dir */
1949 if (strchrW(targetdir,':'))
1951 srcdir=strchrW(targetdir,':');
1952 *srcdir=0;
1953 srcdir ++;
1955 else
1956 srcdir=NULL;
1958 /* for now only pick long filename versions */
1959 if (strchrW(targetdir,'|'))
1961 targetdir = strchrW(targetdir,'|');
1962 *targetdir = 0;
1963 targetdir ++;
1965 if (srcdir && strchrW(srcdir,'|'))
1967 srcdir= strchrW(srcdir,'|');
1968 *srcdir= 0;
1969 srcdir ++;
1972 /* now check for root dirs */
1973 if (targetdir[0] == '.' && targetdir[1] == 0)
1974 targetdir = NULL;
1976 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1977 srcdir = NULL;
1979 if (targetdir)
1981 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
1982 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
1983 package->folders[index].TargetDefault = dupstrW(targetdir);
1986 if (srcdir)
1987 package->folders[index].SourceDefault = dupstrW(srcdir);
1988 else if (targetdir)
1989 package->folders[index].SourceDefault = dupstrW(targetdir);
1990 HeapFree(GetProcessHeap(), 0, ptargetdir);
1992 parent = load_dynamic_stringW(row,2);
1993 if (parent)
1995 i = load_folder(package,parent);
1996 package->folders[index].ParentIndex = i;
1997 TRACE("Parent is index %i... %s %s\n",
1998 package->folders[index].ParentIndex,
1999 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2000 debugstr_w(parent));
2002 else
2003 package->folders[index].ParentIndex = -2;
2004 HeapFree(GetProcessHeap(), 0, parent);
2006 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2008 msiobj_release(&row->hdr);
2009 MSI_ViewClose(view);
2010 msiobj_release(&view->hdr);
2011 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2012 return index;
2016 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
2017 BOOL set_prop, MSIFOLDER **folder)
2019 DWORD i;
2020 LPWSTR p, path = NULL;
2022 TRACE("Working to resolve %s\n",debugstr_w(name));
2024 /* special resolving for Target and Source root dir */
2025 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2027 if (!source)
2029 path = load_dynamic_property(package,cszTargetDir,NULL);
2030 if (!path)
2032 path = load_dynamic_property(package,cszRootDrive,NULL);
2033 if (set_prop)
2034 MSI_SetPropertyW(package,cszTargetDir,path);
2036 if (folder)
2038 for (i = 0; i < package->loaded_folders; i++)
2040 if (strcmpW(package->folders[i].Directory,name)==0)
2041 break;
2043 *folder = &(package->folders[i]);
2045 return path;
2047 else
2049 path = load_dynamic_property(package,cszSourceDir,NULL);
2050 if (!path)
2052 path = load_dynamic_property(package,cszDatabase,NULL);
2053 if (path)
2055 p = strrchrW(path,'\\');
2056 if (p)
2057 *(p+1) = 0;
2060 if (folder)
2062 for (i = 0; i < package->loaded_folders; i++)
2064 if (strcmpW(package->folders[i].Directory,name)==0)
2065 break;
2067 *folder = &(package->folders[i]);
2069 return path;
2073 for (i = 0; i < package->loaded_folders; i++)
2075 if (strcmpW(package->folders[i].Directory,name)==0)
2076 break;
2079 if (i >= package->loaded_folders)
2080 return NULL;
2082 if (folder)
2083 *folder = &(package->folders[i]);
2085 if (!source && package->folders[i].ResolvedTarget)
2087 path = dupstrW(package->folders[i].ResolvedTarget);
2088 TRACE(" already resolved to %s\n",debugstr_w(path));
2089 return path;
2091 else if (source && package->folders[i].ResolvedSource)
2093 path = dupstrW(package->folders[i].ResolvedSource);
2094 return path;
2096 else if (!source && package->folders[i].Property)
2098 path = build_directory_name(2, package->folders[i].Property, NULL);
2100 TRACE(" internally set to %s\n",debugstr_w(path));
2101 if (set_prop)
2102 MSI_SetPropertyW(package,name,path);
2103 return path;
2106 if (package->folders[i].ParentIndex >= 0)
2108 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2110 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2112 p = resolve_folder(package, parent, source, set_prop, NULL);
2113 if (!source)
2115 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2116 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2117 package->folders[i].ResolvedTarget = dupstrW(path);
2118 TRACE(" resolved into %s\n",debugstr_w(path));
2119 if (set_prop)
2120 MSI_SetPropertyW(package,name,path);
2122 else
2124 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2125 package->folders[i].ResolvedSource = dupstrW(path);
2127 HeapFree(GetProcessHeap(),0,p);
2129 return path;
2132 /* scan for and update current install states */
2133 void ACTION_UpdateInstallStates(MSIPACKAGE *package)
2135 int i;
2136 LPWSTR productcode;
2138 productcode = load_dynamic_property(package,szProductCode,NULL);
2140 for (i = 0; i < package->loaded_components; i++)
2142 INSTALLSTATE res;
2143 res = MsiGetComponentPathW(productcode,
2144 package->components[i].ComponentId , NULL, NULL);
2145 if (res < 0)
2146 res = INSTALLSTATE_ABSENT;
2147 package->components[i].Installed = res;
2150 for (i = 0; i < package->loaded_features; i++)
2152 INSTALLSTATE res = -10;
2153 int j;
2154 for (j = 0; j < package->features[i].ComponentCount; j++)
2156 MSICOMPONENT* component = &package->components[package->features[i].
2157 Components[j]];
2158 if (res == -10)
2159 res = component->Installed;
2160 else
2162 if (res == component->Installed)
2163 continue;
2165 if (res != component->Installed)
2166 res = INSTALLSTATE_INCOMPLETE;
2172 /* update compoennt state based on a feature change */
2173 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
2175 int i;
2176 INSTALLSTATE newstate;
2177 MSIFEATURE *feature;
2179 i = get_loaded_feature(package,szFeature);
2180 if (i < 0)
2181 return;
2183 feature = &package->features[i];
2184 newstate = feature->ActionRequest;
2186 for( i = 0; i < feature->ComponentCount; i++)
2188 MSICOMPONENT* component = &package->components[feature->Components[i]];
2190 if (!component->Enabled)
2191 continue;
2192 else
2194 if (newstate == INSTALLSTATE_LOCAL)
2195 component->ActionRequest = INSTALLSTATE_LOCAL;
2196 else
2198 int j,k;
2200 component->ActionRequest = newstate;
2202 /*if any other feature wants is local we need to set it local*/
2203 for (j = 0;
2204 j < package->loaded_features &&
2205 component->ActionRequest != INSTALLSTATE_LOCAL;
2206 j++)
2208 for (k = 0; k < package->features[j].ComponentCount; k++)
2209 if ( package->features[j].Components[k] ==
2210 feature->Components[i] )
2212 if (package->features[j].ActionRequest ==
2213 INSTALLSTATE_LOCAL)
2214 component->ActionRequest = INSTALLSTATE_LOCAL;
2215 break;
2223 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
2224 INSTALLSTATE state)
2226 static const WCHAR all[]={'A','L','L',0};
2227 LPWSTR override = NULL;
2228 INT i;
2229 BOOL rc = FALSE;
2231 override = load_dynamic_property(package, property, NULL);
2232 if (override)
2234 rc = TRUE;
2235 for(i = 0; i < package->loaded_features; i++)
2237 if (strcmpiW(override,all)==0)
2239 package->features[i].ActionRequest= state;
2240 package->features[i].Action = state;
2242 else
2244 LPWSTR ptr = override;
2245 LPWSTR ptr2 = strchrW(override,',');
2247 while (ptr)
2249 if ((ptr2 &&
2250 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2251 || (!ptr2 &&
2252 strcmpW(ptr,package->features[i].Feature)==0))
2254 package->features[i].ActionRequest= state;
2255 package->features[i].Action = state;
2256 break;
2258 if (ptr2)
2260 ptr=ptr2+1;
2261 ptr2 = strchrW(ptr,',');
2263 else
2264 break;
2268 HeapFree(GetProcessHeap(),0,override);
2271 return rc;
2274 static UINT SetFeatureStates(MSIPACKAGE *package)
2276 LPWSTR level;
2277 INT install_level;
2278 DWORD i;
2279 INT j;
2280 static const WCHAR szlevel[] =
2281 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2282 static const WCHAR szAddLocal[] =
2283 {'A','D','D','L','O','C','A','L',0};
2284 static const WCHAR szRemove[] =
2285 {'R','E','M','O','V','E',0};
2286 BOOL override = FALSE;
2288 /* I do not know if this is where it should happen.. but */
2290 TRACE("Checking Install Level\n");
2292 level = load_dynamic_property(package,szlevel,NULL);
2293 if (level)
2295 install_level = atoiW(level);
2296 HeapFree(GetProcessHeap(), 0, level);
2298 else
2299 install_level = 1;
2301 /* ok hereis the _real_ rub
2302 * all these activation/deactivation things happen in order and things
2303 * later on the list override things earlier on the list.
2304 * 1) INSTALLLEVEL processing
2305 * 2) ADDLOCAL
2306 * 3) REMOVE
2307 * 4) ADDSOURCE
2308 * 5) ADDDEFAULT
2309 * 6) REINSTALL
2310 * 7) COMPADDLOCAL
2311 * 8) COMPADDSOURCE
2312 * 9) FILEADDLOCAL
2313 * 10) FILEADDSOURCE
2314 * 11) FILEADDDEFAULT
2315 * I have confirmed that if ADDLOCAL is stated then the INSTALLLEVEL is
2316 * ignored for all the features. seems strange, especially since it is not
2317 * documented anywhere, but it is how it works.
2319 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
2320 * REMOVE are the big ones, since we don't handle administrative installs
2321 * yet anyway.
2323 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
2324 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
2326 if (!override)
2328 for(i = 0; i < package->loaded_features; i++)
2330 BOOL feature_state = ((package->features[i].Level > 0) &&
2331 (package->features[i].Level <= install_level));
2333 if (feature_state)
2335 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
2336 package->features[i].Action = INSTALLSTATE_LOCAL;
2342 * now we want to enable or disable components base on feature
2345 for(i = 0; i < package->loaded_features; i++)
2347 MSIFEATURE* feature = &package->features[i];
2348 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2349 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2350 feature->ActionRequest);
2352 for( j = 0; j < feature->ComponentCount; j++)
2354 MSICOMPONENT* component = &package->components[
2355 feature->Components[j]];
2357 if (!component->Enabled)
2359 component->Action = INSTALLSTATE_UNKNOWN;
2360 component->ActionRequest = INSTALLSTATE_UNKNOWN;
2362 else
2364 if (feature->Action == INSTALLSTATE_LOCAL)
2366 component->Action = INSTALLSTATE_LOCAL;
2367 component->ActionRequest = INSTALLSTATE_LOCAL;
2369 else if (feature->ActionRequest == INSTALLSTATE_ABSENT)
2371 if (component->Action == INSTALLSTATE_UNKNOWN)
2373 component->Action = INSTALLSTATE_ABSENT;
2374 component->ActionRequest = INSTALLSTATE_ABSENT;
2381 for(i = 0; i < package->loaded_components; i++)
2383 MSICOMPONENT* component= &package->components[i];
2385 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2386 debugstr_w(component->Component), component->Installed,
2387 component->Action, component->ActionRequest);
2391 return ERROR_SUCCESS;
2395 * A lot is done in this function aside from just the costing.
2396 * The costing needs to be implemented at some point but for now I am going
2397 * to focus on the directory building
2400 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2402 static const WCHAR ExecSeqQuery[] =
2403 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2404 'D','i','r','e','c','t','o','r','y',0};
2405 static const WCHAR ConditionQuery[] =
2406 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2407 'C','o','n','d','i','t','i','o','n',0};
2408 static const WCHAR szCosting[] =
2409 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2410 static const WCHAR szlevel[] =
2411 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2412 static const WCHAR szOne[] = { '1', 0 };
2413 UINT rc;
2414 MSIQUERY * view;
2415 DWORD i;
2416 LPWSTR level;
2418 TRACE("Building Directory properties\n");
2420 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2421 if (rc == ERROR_SUCCESS)
2423 rc = MSI_ViewExecute(view, 0);
2424 if (rc != ERROR_SUCCESS)
2426 MSI_ViewClose(view);
2427 msiobj_release(&view->hdr);
2428 return rc;
2431 while (1)
2433 WCHAR name[0x100];
2434 LPWSTR path;
2435 MSIRECORD * row = 0;
2436 DWORD sz;
2438 rc = MSI_ViewFetch(view,&row);
2439 if (rc != ERROR_SUCCESS)
2441 rc = ERROR_SUCCESS;
2442 break;
2445 sz=0x100;
2446 MSI_RecordGetStringW(row,1,name,&sz);
2448 /* This helper function now does ALL the work */
2449 TRACE("Dir %s ...\n",debugstr_w(name));
2450 load_folder(package,name);
2451 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2452 TRACE("resolves to %s\n",debugstr_w(path));
2453 HeapFree( GetProcessHeap(), 0, path);
2455 msiobj_release(&row->hdr);
2457 MSI_ViewClose(view);
2458 msiobj_release(&view->hdr);
2461 TRACE("File calculations %i files\n",package->loaded_files);
2463 for (i = 0; i < package->loaded_files; i++)
2465 MSICOMPONENT* comp = NULL;
2466 MSIFILE* file= NULL;
2468 file = &package->files[i];
2469 if (file->ComponentIndex >= 0)
2470 comp = &package->components[file->ComponentIndex];
2472 if (file->Temporary == TRUE)
2473 continue;
2475 if (comp)
2477 LPWSTR p;
2479 /* calculate target */
2480 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2482 HeapFree(GetProcessHeap(),0,file->TargetPath);
2484 TRACE("file %s is named %s\n",
2485 debugstr_w(file->File),debugstr_w(file->FileName));
2487 file->TargetPath = build_directory_name(2, p, file->FileName);
2489 HeapFree(GetProcessHeap(),0,p);
2491 TRACE("file %s resolves to %s\n",
2492 debugstr_w(file->File),debugstr_w(file->TargetPath));
2494 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2496 file->State = 1;
2497 comp->Cost += file->FileSize;
2499 else
2501 if (file->Version)
2503 DWORD handle;
2504 DWORD versize;
2505 UINT sz;
2506 LPVOID version;
2507 static const WCHAR name[] =
2508 {'\\',0};
2509 static const WCHAR name_fmt[] =
2510 {'%','u','.','%','u','.','%','u','.','%','u',0};
2511 WCHAR filever[0x100];
2512 VS_FIXEDFILEINFO *lpVer;
2514 TRACE("Version comparison.. \n");
2515 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2516 version = HeapAlloc(GetProcessHeap(),0,versize);
2517 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2519 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2521 sprintfW(filever,name_fmt,
2522 HIWORD(lpVer->dwFileVersionMS),
2523 LOWORD(lpVer->dwFileVersionMS),
2524 HIWORD(lpVer->dwFileVersionLS),
2525 LOWORD(lpVer->dwFileVersionLS));
2527 TRACE("new %s old %s\n", debugstr_w(file->Version),
2528 debugstr_w(filever));
2529 if (strcmpiW(filever,file->Version)<0)
2531 file->State = 2;
2532 FIXME("cost should be diff in size\n");
2533 comp->Cost += file->FileSize;
2535 else
2536 file->State = 3;
2537 HeapFree(GetProcessHeap(),0,version);
2539 else
2540 file->State = 3;
2545 TRACE("Evaluating Condition Table\n");
2547 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2548 if (rc == ERROR_SUCCESS)
2550 rc = MSI_ViewExecute(view, 0);
2551 if (rc != ERROR_SUCCESS)
2553 MSI_ViewClose(view);
2554 msiobj_release(&view->hdr);
2555 return rc;
2558 while (1)
2560 WCHAR Feature[0x100];
2561 MSIRECORD * row = 0;
2562 DWORD sz;
2563 int feature_index;
2565 rc = MSI_ViewFetch(view,&row);
2567 if (rc != ERROR_SUCCESS)
2569 rc = ERROR_SUCCESS;
2570 break;
2573 sz = 0x100;
2574 MSI_RecordGetStringW(row,1,Feature,&sz);
2576 feature_index = get_loaded_feature(package,Feature);
2577 if (feature_index < 0)
2578 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2579 else
2581 LPWSTR Condition;
2582 Condition = load_dynamic_stringW(row,3);
2584 if (MSI_EvaluateConditionW(package,Condition) ==
2585 MSICONDITION_TRUE)
2587 int level = MSI_RecordGetInteger(row,2);
2588 TRACE("Reseting feature %s to level %i\n",
2589 debugstr_w(Feature), level);
2590 package->features[feature_index].Level = level;
2592 HeapFree(GetProcessHeap(),0,Condition);
2595 msiobj_release(&row->hdr);
2597 MSI_ViewClose(view);
2598 msiobj_release(&view->hdr);
2601 TRACE("Enabling or Disabling Components\n");
2602 for (i = 0; i < package->loaded_components; i++)
2604 if (package->components[i].Condition[0])
2606 if (MSI_EvaluateConditionW(package,
2607 package->components[i].Condition) == MSICONDITION_FALSE)
2609 TRACE("Disabling component %s\n",
2610 debugstr_w(package->components[i].Component));
2611 package->components[i].Enabled = FALSE;
2616 MSI_SetPropertyW(package,szCosting,szOne);
2617 /* set default run level if not set */
2618 level = load_dynamic_property(package,szlevel,NULL);
2619 if (!level)
2620 MSI_SetPropertyW(package,szlevel, szOne);
2621 else
2622 HeapFree(GetProcessHeap(),0,level);
2624 ACTION_UpdateInstallStates(package);
2626 return SetFeatureStates(package);
2630 * This is a helper function for handling embedded cabinet media
2632 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2633 WCHAR* source)
2635 UINT rc;
2636 USHORT* data;
2637 UINT size;
2638 DWORD write;
2639 HANDLE the_file;
2640 WCHAR tmp[MAX_PATH];
2642 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2643 if (rc != ERROR_SUCCESS)
2644 return rc;
2646 write = MAX_PATH;
2647 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2648 GetTempPathW(MAX_PATH,tmp);
2650 GetTempFileNameW(tmp,stream_name,0,source);
2652 track_tempfile(package,strrchrW(source,'\\'), source);
2653 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2654 FILE_ATTRIBUTE_NORMAL, NULL);
2656 if (the_file == INVALID_HANDLE_VALUE)
2658 rc = ERROR_FUNCTION_FAILED;
2659 goto end;
2662 WriteFile(the_file,data,size,&write,NULL);
2663 CloseHandle(the_file);
2664 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2665 end:
2666 HeapFree(GetProcessHeap(),0,data);
2667 return rc;
2671 /* Support functions for FDI functions */
2672 typedef struct
2674 MSIPACKAGE* package;
2675 LPCSTR cab_path;
2676 LPCSTR file_name;
2677 } CabData;
2679 static void * cabinet_alloc(ULONG cb)
2681 return HeapAlloc(GetProcessHeap(), 0, cb);
2684 static void cabinet_free(void *pv)
2686 HeapFree(GetProcessHeap(), 0, pv);
2689 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2691 DWORD dwAccess = 0;
2692 DWORD dwShareMode = 0;
2693 DWORD dwCreateDisposition = OPEN_EXISTING;
2694 switch (oflag & _O_ACCMODE)
2696 case _O_RDONLY:
2697 dwAccess = GENERIC_READ;
2698 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2699 break;
2700 case _O_WRONLY:
2701 dwAccess = GENERIC_WRITE;
2702 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2703 break;
2704 case _O_RDWR:
2705 dwAccess = GENERIC_READ | GENERIC_WRITE;
2706 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2707 break;
2709 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2710 dwCreateDisposition = CREATE_NEW;
2711 else if (oflag & _O_CREAT)
2712 dwCreateDisposition = CREATE_ALWAYS;
2713 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
2714 dwCreateDisposition, 0, NULL);
2717 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2719 DWORD dwRead;
2720 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2721 return dwRead;
2722 return 0;
2725 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2727 DWORD dwWritten;
2728 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2729 return dwWritten;
2730 return 0;
2733 static int cabinet_close(INT_PTR hf)
2735 return CloseHandle((HANDLE)hf) ? 0 : -1;
2738 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2740 /* flags are compatible and so are passed straight through */
2741 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2744 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2746 /* FIXME: try to do more processing in this function */
2747 switch (fdint)
2749 case fdintCOPY_FILE:
2751 CabData *data = (CabData*) pfdin->pv;
2752 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2753 char *file;
2755 LPWSTR trackname;
2756 LPWSTR trackpath;
2757 LPWSTR tracknametmp;
2758 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2760 if (data->file_name && strcmp(data->file_name,pfdin->psz1))
2761 return 0;
2763 file = cabinet_alloc((len+1)*sizeof(char));
2764 strcpy(file, data->cab_path);
2765 strcat(file, pfdin->psz1);
2767 TRACE("file: %s\n", debugstr_a(file));
2769 /* track this file so it can be deleted if not installed */
2770 trackpath=strdupAtoW(file);
2771 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2772 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2773 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2775 strcpyW(trackname,tmpprefix);
2776 strcatW(trackname,tracknametmp);
2778 track_tempfile(data->package, trackname, trackpath);
2780 HeapFree(GetProcessHeap(),0,trackpath);
2781 HeapFree(GetProcessHeap(),0,trackname);
2782 HeapFree(GetProcessHeap(),0,tracknametmp);
2784 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2786 case fdintCLOSE_FILE_INFO:
2788 FILETIME ft;
2789 FILETIME ftLocal;
2790 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2791 return -1;
2792 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2793 return -1;
2794 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2795 return -1;
2797 cabinet_close(pfdin->hf);
2798 return 1;
2800 default:
2801 return 0;
2805 /***********************************************************************
2806 * extract_cabinet_file
2808 * Extract files from a cab file.
2810 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2811 const WCHAR* path, const WCHAR* file)
2813 HFDI hfdi;
2814 ERF erf;
2815 BOOL ret;
2816 char *cabinet;
2817 char *cab_path;
2818 char *file_name;
2819 CabData data;
2821 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2822 debugstr_w(file), debugstr_w(path));
2824 hfdi = FDICreate(cabinet_alloc,
2825 cabinet_free,
2826 cabinet_open,
2827 cabinet_read,
2828 cabinet_write,
2829 cabinet_close,
2830 cabinet_seek,
2832 &erf);
2833 if (!hfdi)
2835 ERR("FDICreate failed\n");
2836 return FALSE;
2839 if (!(cabinet = strdupWtoA( source )))
2841 FDIDestroy(hfdi);
2842 return FALSE;
2844 if (!(cab_path = strdupWtoA( path )))
2846 FDIDestroy(hfdi);
2847 HeapFree(GetProcessHeap(), 0, cabinet);
2848 return FALSE;
2851 data.package = package;
2852 data.cab_path = cab_path;
2853 if (file)
2854 file_name = strdupWtoA(file);
2855 else
2856 file_name = NULL;
2857 data.file_name = file_name;
2859 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
2861 if (!ret)
2862 ERR("FDICopy failed\n");
2864 FDIDestroy(hfdi);
2866 HeapFree(GetProcessHeap(), 0, cabinet);
2867 HeapFree(GetProcessHeap(), 0, cab_path);
2868 HeapFree(GetProcessHeap(), 0, file_name);
2870 return ret;
2873 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2874 WCHAR* path, WCHAR* file)
2876 UINT rc;
2877 MSIQUERY * view;
2878 MSIRECORD * row = 0;
2879 static WCHAR source[MAX_PATH];
2880 static const WCHAR ExecSeqQuery[] =
2881 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2882 'M','e','d','i','a',' ','W','H','E','R','E',' ',
2883 'L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%',
2884 'i',' ','O','R','D','E','R',' ','B','Y',' ',
2885 'L','a','s','t','S','e','q','u','e','n','c','e',0};
2886 WCHAR Query[1024];
2887 WCHAR cab[0x100];
2888 DWORD sz=0x100;
2889 INT seq;
2890 static UINT last_sequence = 0;
2892 if (sequence <= last_sequence)
2894 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2895 /*extract_a_cabinet_file(package, source,path,file); */
2896 return ERROR_SUCCESS;
2899 sprintfW(Query,ExecSeqQuery,sequence);
2901 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2902 if (rc != ERROR_SUCCESS)
2903 return rc;
2905 rc = MSI_ViewExecute(view, 0);
2906 if (rc != ERROR_SUCCESS)
2908 MSI_ViewClose(view);
2909 msiobj_release(&view->hdr);
2910 return rc;
2913 rc = MSI_ViewFetch(view,&row);
2914 if (rc != ERROR_SUCCESS)
2916 MSI_ViewClose(view);
2917 msiobj_release(&view->hdr);
2918 return rc;
2920 seq = MSI_RecordGetInteger(row,2);
2921 last_sequence = seq;
2923 if (!MSI_RecordIsNull(row,4))
2925 sz=0x100;
2926 MSI_RecordGetStringW(row,4,cab,&sz);
2927 TRACE("Source is CAB %s\n",debugstr_w(cab));
2928 /* the stream does not contain the # character */
2929 if (cab[0]=='#')
2931 writeout_cabinet_stream(package,&cab[1],source);
2932 strcpyW(path,source);
2933 *(strrchrW(path,'\\')+1)=0;
2935 else
2937 sz = MAX_PATH;
2938 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2940 ERR("No Source dir defined \n");
2941 rc = ERROR_FUNCTION_FAILED;
2943 else
2945 strcpyW(path,source);
2946 strcatW(source,cab);
2947 /* extract the cab file into a folder in the temp folder */
2948 sz = MAX_PATH;
2949 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2950 != ERROR_SUCCESS)
2951 GetTempPathW(MAX_PATH,path);
2954 rc = !extract_a_cabinet_file(package, source,path,NULL);
2956 else
2958 sz = MAX_PATH;
2959 MSI_GetPropertyW(package,cszSourceDir,source,&sz);
2960 strcpyW(path,source);
2962 msiobj_release(&row->hdr);
2963 MSI_ViewClose(view);
2964 msiobj_release(&view->hdr);
2965 return rc;
2968 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2970 UINT rc = ERROR_SUCCESS;
2971 MSIFOLDER *folder;
2972 LPWSTR install_path;
2974 install_path = resolve_folder(package, package->components[component].Directory,
2975 FALSE, FALSE, &folder);
2976 if (!install_path)
2977 return ERROR_FUNCTION_FAILED;
2979 /* create the path */
2980 if (folder->State == 0)
2982 create_full_pathW(install_path);
2983 folder->State = 2;
2985 HeapFree(GetProcessHeap(), 0, install_path);
2987 return rc;
2990 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
2992 UINT rc = ERROR_SUCCESS;
2993 DWORD index;
2994 MSIRECORD * uirow;
2995 WCHAR uipath[MAX_PATH];
2997 if (!package)
2998 return ERROR_INVALID_HANDLE;
3000 /* increment progress bar each time action data is sent */
3001 ui_progress(package,1,1,0,0);
3003 for (index = 0; index < package->loaded_files; index++)
3005 WCHAR path_to_source[MAX_PATH];
3006 MSIFILE *file;
3008 file = &package->files[index];
3010 if (file->Temporary)
3011 continue;
3014 if (!ACTION_VerifyComponentForAction(package, file->ComponentIndex,
3015 INSTALLSTATE_LOCAL))
3017 ui_progress(package,2,file->FileSize,0,0);
3018 TRACE("File %s is not scheduled for install\n",
3019 debugstr_w(file->File));
3021 continue;
3024 if ((file->State == 1) || (file->State == 2))
3026 LPWSTR p;
3027 INT len;
3028 MSICOMPONENT* comp = NULL;
3030 TRACE("Installing %s\n",debugstr_w(file->File));
3031 rc = ready_media_for_file(package,file->Sequence,path_to_source,
3032 file->File);
3034 * WARNING!
3035 * our file table could change here because a new temp file
3036 * may have been created
3038 file = &package->files[index];
3039 if (rc != ERROR_SUCCESS)
3041 ERR("Unable to ready media\n");
3042 rc = ERROR_FUNCTION_FAILED;
3043 break;
3046 create_component_directory( package, file->ComponentIndex);
3048 /* recalculate file paths because things may have changed */
3050 if (file->ComponentIndex >= 0)
3051 comp = &package->components[file->ComponentIndex];
3053 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3054 HeapFree(GetProcessHeap(),0,file->TargetPath);
3056 file->TargetPath = build_directory_name(2, p, file->FileName);
3058 len = strlenW(path_to_source) + strlenW(file->File) + 2;
3059 file->SourcePath = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3060 strcpyW(file->SourcePath, path_to_source);
3061 strcatW(file->SourcePath, file->File);
3063 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3064 debugstr_w(file->TargetPath));
3066 /* the UI chunk */
3067 uirow=MSI_CreateRecord(9);
3068 MSI_RecordSetStringW(uirow,1,file->File);
3069 strcpyW(uipath,file->TargetPath);
3070 *(strrchrW(uipath,'\\')+1)=0;
3071 MSI_RecordSetStringW(uirow,9,uipath);
3072 MSI_RecordSetInteger(uirow,6,file->FileSize);
3073 ui_actiondata(package,szInstallFiles,uirow);
3074 msiobj_release( &uirow->hdr );
3075 ui_progress(package,2,file->FileSize,0,0);
3077 if (!MoveFileW(file->SourcePath,file->TargetPath))
3079 rc = GetLastError();
3080 ERR("Unable to move file (%s -> %s) (error %d)\n",
3081 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3082 rc);
3083 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3085 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3086 DeleteFileW(file->SourcePath);
3087 rc = 0;
3089 else if (rc == ERROR_FILE_NOT_FOUND)
3091 ERR("Source File Not Found! Continuing\n");
3092 rc = 0;
3094 else
3096 ERR("Ignoring Error and continuing...\n");
3097 rc = 0;
3100 else
3101 file->State = 4;
3105 return rc;
3108 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3109 LPWSTR* file_source)
3111 DWORD index;
3113 if (!package)
3114 return ERROR_INVALID_HANDLE;
3116 for (index = 0; index < package->loaded_files; index ++)
3118 if (strcmpW(file_key,package->files[index].File)==0)
3120 if (package->files[index].State >= 2)
3122 *file_source = dupstrW(package->files[index].TargetPath);
3123 return ERROR_SUCCESS;
3125 else
3126 return ERROR_FILE_NOT_FOUND;
3130 return ERROR_FUNCTION_FAILED;
3133 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3135 UINT rc;
3136 MSIQUERY * view;
3137 MSIRECORD * row = 0;
3138 static const WCHAR ExecSeqQuery[] =
3139 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3140 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
3142 if (!package)
3143 return ERROR_INVALID_HANDLE;
3145 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3146 if (rc != ERROR_SUCCESS)
3147 return ERROR_SUCCESS;
3149 rc = MSI_ViewExecute(view, 0);
3150 if (rc != ERROR_SUCCESS)
3152 MSI_ViewClose(view);
3153 msiobj_release(&view->hdr);
3154 return rc;
3157 while (1)
3159 WCHAR file_key[0x100];
3160 WCHAR *file_source = NULL;
3161 WCHAR dest_name[0x100];
3162 LPWSTR dest_path, dest;
3163 WCHAR component[0x100];
3164 INT component_index;
3166 DWORD sz=0x100;
3168 rc = MSI_ViewFetch(view,&row);
3169 if (rc != ERROR_SUCCESS)
3171 rc = ERROR_SUCCESS;
3172 break;
3175 sz=0x100;
3176 rc = MSI_RecordGetStringW(row,2,component,&sz);
3177 if (rc != ERROR_SUCCESS)
3179 ERR("Unable to get component\n");
3180 msiobj_release(&row->hdr);
3181 break;
3184 component_index = get_loaded_component(package,component);
3186 if (!ACTION_VerifyComponentForAction(package, component_index,
3187 INSTALLSTATE_LOCAL))
3189 TRACE("Skipping copy due to disabled component\n");
3191 /* the action taken was the same as the current install state */
3192 package->components[component_index].Action =
3193 package->components[component_index].Installed;
3195 msiobj_release(&row->hdr);
3196 continue;
3199 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3201 sz=0x100;
3202 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3203 if (rc != ERROR_SUCCESS)
3205 ERR("Unable to get file key\n");
3206 msiobj_release(&row->hdr);
3207 break;
3210 rc = get_file_target(package,file_key,&file_source);
3212 if (rc != ERROR_SUCCESS)
3214 ERR("Original file unknown %s\n",debugstr_w(file_key));
3215 msiobj_release(&row->hdr);
3216 HeapFree(GetProcessHeap(),0,file_source);
3217 continue;
3220 if (MSI_RecordIsNull(row,4))
3222 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3224 else
3226 sz=0x100;
3227 MSI_RecordGetStringW(row,4,dest_name,&sz);
3228 reduce_to_longfilename(dest_name);
3231 if (MSI_RecordIsNull(row,5))
3233 LPWSTR p;
3234 dest_path = dupstrW(file_source);
3235 p = strrchrW(dest_path,'\\');
3236 if (p)
3237 *p=0;
3239 else
3241 WCHAR destkey[0x100];
3242 sz=0x100;
3243 MSI_RecordGetStringW(row,5,destkey,&sz);
3244 sz = 0x100;
3245 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3246 if (!dest_path)
3248 ERR("Unable to get destination folder\n");
3249 msiobj_release(&row->hdr);
3250 HeapFree(GetProcessHeap(),0,file_source);
3251 break;
3255 dest = build_directory_name(2, dest_path, dest_name);
3257 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3258 debugstr_w(dest));
3260 if (strcmpW(file_source,dest))
3261 rc = !CopyFileW(file_source,dest,TRUE);
3262 else
3263 rc = ERROR_SUCCESS;
3265 if (rc != ERROR_SUCCESS)
3266 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source), debugstr_w(dest_path), GetLastError());
3268 FIXME("We should track these duplicate files as well\n");
3270 msiobj_release(&row->hdr);
3271 HeapFree(GetProcessHeap(),0,dest_path);
3272 HeapFree(GetProcessHeap(),0,dest);
3273 HeapFree(GetProcessHeap(),0,file_source);
3275 MSI_ViewClose(view);
3276 msiobj_release(&view->hdr);
3277 return rc;
3281 /* OK this value is "interpreted" and then formatted based on the
3282 first few characters */
3283 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3284 DWORD *size)
3286 LPSTR data = NULL;
3287 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3289 if (value[1]=='x')
3291 LPWSTR ptr;
3292 CHAR byte[5];
3293 LPWSTR deformated;
3294 int count;
3296 deformat_string(package, &value[2], &deformated);
3298 /* binary value type */
3299 ptr = deformated;
3300 *type=REG_BINARY;
3301 *size = strlenW(ptr)/2;
3302 data = HeapAlloc(GetProcessHeap(),0,*size);
3304 byte[0] = '0';
3305 byte[1] = 'x';
3306 byte[4] = 0;
3307 count = 0;
3308 while (*ptr)
3310 byte[2]= *ptr;
3311 ptr++;
3312 byte[3]= *ptr;
3313 ptr++;
3314 data[count] = (BYTE)strtol(byte,NULL,0);
3315 count ++;
3317 HeapFree(GetProcessHeap(),0,deformated);
3319 TRACE("Data %li bytes(%i)\n",*size,count);
3321 else
3323 LPWSTR deformated;
3324 LPWSTR p;
3325 DWORD d = 0;
3326 deformat_string(package, &value[1], &deformated);
3328 *type=REG_DWORD;
3329 *size = sizeof(DWORD);
3330 data = HeapAlloc(GetProcessHeap(),0,*size);
3331 p = deformated;
3332 if (*p == '-')
3333 p++;
3334 while (*p)
3336 if ( (*p < '0') || (*p > '9') )
3337 break;
3338 d *= 10;
3339 d += (*p - '0');
3340 p++;
3342 if (deformated[0] == '-')
3343 d = -d;
3344 *(LPDWORD)data = d;
3345 TRACE("DWORD %li\n",*(LPDWORD)data);
3347 HeapFree(GetProcessHeap(),0,deformated);
3350 else
3352 static const WCHAR szMulti[] = {'[','~',']',0};
3353 WCHAR *ptr;
3354 *type=REG_SZ;
3356 if (value[0]=='#')
3358 if (value[1]=='%')
3360 ptr = &value[2];
3361 *type=REG_EXPAND_SZ;
3363 else
3364 ptr = &value[1];
3366 else
3367 ptr=value;
3369 if (strstrW(value,szMulti))
3370 *type = REG_MULTI_SZ;
3372 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3374 return data;
3377 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3379 UINT rc;
3380 MSIQUERY * view;
3381 MSIRECORD * row = 0;
3382 static const WCHAR ExecSeqQuery[] =
3383 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3384 'R','e','g','i','s','t','r','y',0 };
3386 if (!package)
3387 return ERROR_INVALID_HANDLE;
3389 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3390 if (rc != ERROR_SUCCESS)
3391 return ERROR_SUCCESS;
3393 rc = MSI_ViewExecute(view, 0);
3394 if (rc != ERROR_SUCCESS)
3396 MSI_ViewClose(view);
3397 msiobj_release(&view->hdr);
3398 return rc;
3401 /* increment progress bar each time action data is sent */
3402 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3404 while (1)
3406 static const WCHAR szHCR[] =
3407 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3408 'R','O','O','T','\\',0};
3409 static const WCHAR szHCU[] =
3410 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3411 'U','S','E','R','\\',0};
3412 static const WCHAR szHLM[] =
3413 {'H','K','E','Y','_','L','O','C','A','L','_',
3414 'M','A','C','H','I','N','E','\\',0};
3415 static const WCHAR szHU[] =
3416 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3418 LPSTR value_data = NULL;
3419 HKEY root_key, hkey;
3420 DWORD type,size;
3421 LPWSTR value, key, name, component, deformated;
3422 LPCWSTR szRoot;
3423 INT component_index;
3424 MSIRECORD * uirow;
3425 LPWSTR uikey;
3426 INT root;
3428 rc = MSI_ViewFetch(view,&row);
3429 if (rc != ERROR_SUCCESS)
3431 rc = ERROR_SUCCESS;
3432 break;
3434 ui_progress(package,2,0,0,0);
3436 value = NULL;
3437 key = NULL;
3438 uikey = NULL;
3439 name = NULL;
3441 component = load_dynamic_stringW(row, 6);
3442 component_index = get_loaded_component(package,component);
3444 if (!ACTION_VerifyComponentForAction(package, component_index,
3445 INSTALLSTATE_LOCAL))
3447 TRACE("Skipping write due to disabled component\n");
3448 msiobj_release(&row->hdr);
3450 package->components[component_index].Action =
3451 package->components[component_index].Installed;
3453 goto next;
3456 package->components[component_index].Action = INSTALLSTATE_LOCAL;
3458 name = load_dynamic_stringW(row, 4);
3459 if( MSI_RecordIsNull(row,5) && name )
3461 /* null values can have special meanings */
3462 if (name[0]=='-' && name[1] == 0)
3464 msiobj_release(&row->hdr);
3465 goto next;
3467 else if ((name[0]=='+' && name[1] == 0) ||
3468 (name[0] == '*' && name[1] == 0))
3470 HeapFree(GetProcessHeap(),0,name);
3471 name = NULL;
3475 root = MSI_RecordGetInteger(row,2);
3476 key = load_dynamic_stringW(row, 3);
3479 /* get the root key */
3480 switch (root)
3482 case 0: root_key = HKEY_CLASSES_ROOT;
3483 szRoot = szHCR;
3484 break;
3485 case 1: root_key = HKEY_CURRENT_USER;
3486 szRoot = szHCU;
3487 break;
3488 case 2: root_key = HKEY_LOCAL_MACHINE;
3489 szRoot = szHLM;
3490 break;
3491 case 3: root_key = HKEY_USERS;
3492 szRoot = szHU;
3493 break;
3494 default:
3495 ERR("Unknown root %i\n",root);
3496 root_key=NULL;
3497 szRoot = NULL;
3498 break;
3500 if (!root_key)
3502 msiobj_release(&row->hdr);
3503 goto next;
3506 deformat_string(package, key , &deformated);
3507 size = strlenW(deformated) + strlenW(szRoot) + 1;
3508 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3509 strcpyW(uikey,szRoot);
3510 strcatW(uikey,deformated);
3512 if (RegCreateKeyW( root_key, deformated, &hkey))
3514 ERR("Could not create key %s\n",debugstr_w(deformated));
3515 msiobj_release(&row->hdr);
3516 HeapFree(GetProcessHeap(),0,deformated);
3517 goto next;
3519 HeapFree(GetProcessHeap(),0,deformated);
3521 value = load_dynamic_stringW(row,5);
3522 if (value)
3523 value_data = parse_value(package, value, &type, &size);
3524 else
3526 value_data = NULL;
3527 size = 0;
3528 type = REG_SZ;
3531 deformat_string(package, name, &deformated);
3533 TRACE("Setting value %s\n",debugstr_w(deformated));
3534 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3536 uirow = MSI_CreateRecord(3);
3537 MSI_RecordSetStringW(uirow,2,deformated);
3538 MSI_RecordSetStringW(uirow,1,uikey);
3540 if (type == REG_SZ)
3541 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3542 else
3543 MSI_RecordSetStringW(uirow,3,value);
3545 ui_actiondata(package,szWriteRegistryValues,uirow);
3546 msiobj_release( &uirow->hdr );
3548 HeapFree(GetProcessHeap(),0,value_data);
3549 HeapFree(GetProcessHeap(),0,value);
3550 HeapFree(GetProcessHeap(),0,deformated);
3552 msiobj_release(&row->hdr);
3553 RegCloseKey(hkey);
3554 next:
3555 HeapFree(GetProcessHeap(),0,uikey);
3556 HeapFree(GetProcessHeap(),0,key);
3557 HeapFree(GetProcessHeap(),0,name);
3558 HeapFree(GetProcessHeap(),0,component);
3560 MSI_ViewClose(view);
3561 msiobj_release(&view->hdr);
3562 return rc;
3565 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3567 return ERROR_SUCCESS;
3571 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3573 DWORD progress = 0;
3574 DWORD total = 0;
3575 static const WCHAR q1[]=
3576 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3577 'R','e','g','i','s','t','r','y',0};
3578 UINT rc;
3579 MSIQUERY * view;
3580 MSIRECORD * row = 0;
3581 int i;
3583 TRACE(" InstallValidate \n");
3585 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3586 if (rc != ERROR_SUCCESS)
3587 return ERROR_SUCCESS;
3589 rc = MSI_ViewExecute(view, 0);
3590 if (rc != ERROR_SUCCESS)
3592 MSI_ViewClose(view);
3593 msiobj_release(&view->hdr);
3594 return rc;
3596 while (1)
3598 rc = MSI_ViewFetch(view,&row);
3599 if (rc != ERROR_SUCCESS)
3601 rc = ERROR_SUCCESS;
3602 break;
3604 progress +=1;
3606 msiobj_release(&row->hdr);
3608 MSI_ViewClose(view);
3609 msiobj_release(&view->hdr);
3611 total = total + progress * REG_PROGRESS_VALUE;
3612 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3613 for (i=0; i < package->loaded_files; i++)
3614 total += package->files[i].FileSize;
3615 ui_progress(package,0,total,0,0);
3617 return ERROR_SUCCESS;
3620 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3622 UINT rc;
3623 MSIQUERY * view = NULL;
3624 MSIRECORD * row = 0;
3625 static const WCHAR ExecSeqQuery[] =
3626 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3627 'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3628 static const WCHAR title[]=
3629 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3631 TRACE("Checking launch conditions\n");
3633 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3634 if (rc != ERROR_SUCCESS)
3635 return ERROR_SUCCESS;
3637 rc = MSI_ViewExecute(view, 0);
3638 if (rc != ERROR_SUCCESS)
3640 MSI_ViewClose(view);
3641 msiobj_release(&view->hdr);
3642 return rc;
3645 rc = ERROR_SUCCESS;
3646 while (rc == ERROR_SUCCESS)
3648 LPWSTR cond = NULL;
3649 LPWSTR message = NULL;
3651 rc = MSI_ViewFetch(view,&row);
3652 if (rc != ERROR_SUCCESS)
3654 rc = ERROR_SUCCESS;
3655 break;
3658 cond = load_dynamic_stringW(row,1);
3660 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3662 LPWSTR deformated;
3663 message = load_dynamic_stringW(row,2);
3664 deformat_string(package,message,&deformated);
3665 MessageBoxW(NULL,deformated,title,MB_OK);
3666 HeapFree(GetProcessHeap(),0,message);
3667 HeapFree(GetProcessHeap(),0,deformated);
3668 rc = ERROR_FUNCTION_FAILED;
3670 HeapFree(GetProcessHeap(),0,cond);
3671 msiobj_release(&row->hdr);
3673 MSI_ViewClose(view);
3674 msiobj_release(&view->hdr);
3675 return rc;
3678 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3679 component_index)
3681 MSICOMPONENT* cmp = &package->components[component_index];
3683 if (cmp->KeyPath[0]==0)
3685 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3686 return p;
3688 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
3690 MSIQUERY * view;
3691 MSIRECORD * row = 0;
3692 UINT rc,root,len;
3693 LPWSTR key,deformated,buffer,name,deformated_name;
3694 static const WCHAR ExecSeqQuery[] =
3695 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3696 'R','e','g','i','s','t','r','y',' ','W','H','E','R','E',' ',
3697 'R','e','g','i','s','t','r','y',' ','=',' ' ,'`','%','s','`',0 };
3698 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
3699 static const WCHAR fmt2[]=
3700 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3702 rc = MSI_OpenQuery(package->db,&view,ExecSeqQuery,cmp->KeyPath);
3704 if (rc!=ERROR_SUCCESS)
3705 return NULL;
3707 rc = MSI_ViewExecute(view, 0);
3708 if (rc != ERROR_SUCCESS)
3710 MSI_ViewClose(view);
3711 msiobj_release(&view->hdr);
3712 return NULL;
3715 rc = MSI_ViewFetch(view,&row);
3716 if (rc != ERROR_SUCCESS)
3718 MSI_ViewClose(view);
3719 msiobj_release(&view->hdr);
3720 return NULL;
3723 root = MSI_RecordGetInteger(row,2);
3724 key = load_dynamic_stringW(row, 3);
3725 name = load_dynamic_stringW(row, 4);
3726 deformat_string(package, key , &deformated);
3727 deformat_string(package, name, &deformated_name);
3729 len = strlenW(deformated) + 6;
3730 if (deformated_name)
3731 len+=strlenW(deformated_name);
3733 buffer = HeapAlloc(GetProcessHeap(),0, len *sizeof(WCHAR));
3735 if (deformated_name)
3736 sprintfW(buffer,fmt2,root,deformated,deformated_name);
3737 else
3738 sprintfW(buffer,fmt,root,deformated);
3740 HeapFree(GetProcessHeap(),0,key);
3741 HeapFree(GetProcessHeap(),0,deformated);
3742 HeapFree(GetProcessHeap(),0,name);
3743 HeapFree(GetProcessHeap(),0,deformated_name);
3744 msiobj_release(&row->hdr);
3745 MSI_ViewClose(view);
3746 msiobj_release(&view->hdr);
3748 return buffer;
3750 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
3752 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3753 return NULL;
3755 else
3757 int j;
3758 j = get_loaded_file(package,cmp->KeyPath);
3760 if (j>=0)
3762 LPWSTR p = dupstrW(package->files[j].TargetPath);
3763 return p;
3766 return NULL;
3769 static HKEY openSharedDLLsKey()
3771 HKEY hkey=0;
3772 static const WCHAR path[] =
3773 {'S','o','f','t','w','a','r','e','\\',
3774 'M','i','c','r','o','s','o','f','t','\\',
3775 'W','i','n','d','o','w','s','\\',
3776 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3777 'S','h','a','r','e','d','D','L','L','s',0};
3779 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
3780 return hkey;
3783 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
3785 HKEY hkey;
3786 DWORD count=0;
3787 DWORD type;
3788 DWORD sz = sizeof(count);
3789 DWORD rc;
3791 hkey = openSharedDLLsKey();
3792 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
3793 if (rc != ERROR_SUCCESS)
3794 count = 0;
3795 RegCloseKey(hkey);
3796 return count;
3799 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
3801 HKEY hkey;
3803 hkey = openSharedDLLsKey();
3804 if (count > 0)
3805 RegSetValueExW(hkey,path,0,REG_DWORD,
3806 (LPBYTE)&count,sizeof(count));
3807 else
3808 RegDeleteValueW(hkey,path);
3809 RegCloseKey(hkey);
3810 return count;
3814 * Return TRUE if the count should be written out and FALSE if not
3816 static void ACTION_RefCountComponent( MSIPACKAGE* package, UINT index)
3818 INT count = 0;
3819 BOOL write = FALSE;
3820 INT j;
3822 /* only refcount DLLs */
3823 if (package->components[index].KeyPath[0]==0 ||
3824 package->components[index].Attributes &
3825 msidbComponentAttributesRegistryKeyPath ||
3826 package->components[index].Attributes &
3827 msidbComponentAttributesODBCDataSource)
3828 write = FALSE;
3829 else
3831 count = ACTION_GetSharedDLLsCount(package->components[index].
3832 FullKeypath);
3833 write = (count > 0);
3835 if (package->components[index].Attributes &
3836 msidbComponentAttributesSharedDllRefCount)
3837 write = TRUE;
3840 /* increment counts */
3841 for (j = 0; j < package->loaded_features; j++)
3843 int i;
3845 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_LOCAL))
3846 continue;
3848 for (i = 0; i < package->features[j].ComponentCount; i++)
3850 if (package->features[j].Components[i] == index)
3851 count++;
3854 /* decrement counts */
3855 for (j = 0; j < package->loaded_features; j++)
3857 int i;
3858 if (!ACTION_VerifyFeatureForAction(package,j,INSTALLSTATE_ABSENT))
3859 continue;
3861 for (i = 0; i < package->features[j].ComponentCount; i++)
3863 if (package->features[j].Components[i] == index)
3864 count--;
3868 /* ref count all the files in the component */
3869 if (write)
3870 for (j = 0; j < package->loaded_files; j++)
3872 if (package->files[j].Temporary)
3873 continue;
3874 if (package->files[j].ComponentIndex == index)
3875 ACTION_WriteSharedDLLsCount(package->files[j].TargetPath,count);
3878 /* add a count for permenent */
3879 if (package->components[index].Attributes &
3880 msidbComponentAttributesPermanent)
3881 count ++;
3883 package->components[index].RefCount = count;
3885 if (write)
3886 ACTION_WriteSharedDLLsCount(package->components[index].FullKeypath,
3887 package->components[index].RefCount);
3891 * Ok further analysis makes me think that this work is
3892 * actually done in the PublishComponents and PublishFeatures
3893 * step, and not here. It appears like the keypath and all that is
3894 * resolved in this step, however actually written in the Publish steps.
3895 * But we will leave it here for now because it is unclear
3897 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3899 LPWSTR productcode;
3900 WCHAR squished_pc[GUID_SIZE];
3901 WCHAR squished_cc[GUID_SIZE];
3902 UINT rc;
3903 DWORD i;
3904 HKEY hkey=0,hkey2=0;
3906 if (!package)
3907 return ERROR_INVALID_HANDLE;
3909 /* writes the Component and Features values to the registry */
3910 productcode = load_dynamic_property(package,szProductCode,&rc);
3911 if (!productcode)
3912 return rc;
3914 rc = MSIREG_OpenComponents(&hkey);
3915 if (rc != ERROR_SUCCESS)
3916 goto end;
3918 squash_guid(productcode,squished_pc);
3919 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
3920 for (i = 0; i < package->loaded_components; i++)
3922 ui_progress(package,2,0,0,0);
3923 if (package->components[i].ComponentId[0]!=0)
3925 WCHAR *keypath = NULL;
3926 MSIRECORD * uirow;
3928 squash_guid(package->components[i].ComponentId,squished_cc);
3929 rc = RegCreateKeyW(hkey,squished_cc,&hkey2);
3930 if (rc != ERROR_SUCCESS)
3931 continue;
3933 keypath = resolve_keypath(package,i);
3934 package->components[i].FullKeypath = keypath;
3936 /* do the refcounting */
3937 ACTION_RefCountComponent( package, i);
3939 TRACE("Component %s, Keypath=%s, RefCount=%i\n",
3940 debugstr_w(package->components[i].Component),
3941 debugstr_w(package->components[i].FullKeypath),
3942 package->components[i].RefCount);
3944 * Write the keypath out if the component is to be registered
3945 * and delete the key if the component is to be deregistered
3947 if (ACTION_VerifyComponentForAction(package, i,
3948 INSTALLSTATE_LOCAL))
3950 if (keypath)
3952 RegSetValueExW(hkey2,squished_pc,0,REG_SZ,(LPVOID)keypath,
3953 (strlenW(keypath)+1)*sizeof(WCHAR));
3955 if (package->components[i].Attributes &
3956 msidbComponentAttributesPermanent)
3958 static const WCHAR szPermKey[] =
3959 { '0','0','0','0','0','0','0','0','0','0','0','0',
3960 '0','0','0','0','0','0','0', '0','0','0','0','0',
3961 '0','0','0','0','0','0','0','0',0};
3963 RegSetValueExW(hkey2,szPermKey,0,REG_SZ,
3964 (LPVOID)keypath,
3965 (strlenW(keypath)+1)*sizeof(WCHAR));
3968 RegCloseKey(hkey2);
3970 /* UI stuff */
3971 uirow = MSI_CreateRecord(3);
3972 MSI_RecordSetStringW(uirow,1,productcode);
3973 MSI_RecordSetStringW(uirow,2,package->components[i].
3974 ComponentId);
3975 MSI_RecordSetStringW(uirow,3,keypath);
3976 ui_actiondata(package,szProcessComponents,uirow);
3977 msiobj_release( &uirow->hdr );
3980 else if (ACTION_VerifyComponentForAction(package, i,
3981 INSTALLSTATE_ABSENT))
3983 DWORD res;
3984 RegDeleteValueW(hkey2,squished_pc);
3986 /* if the key is empty delete it */
3987 res = RegEnumKeyExW(hkey2,0,NULL,0,0,NULL,0,NULL);
3988 RegCloseKey(hkey2);
3989 if (res == ERROR_NO_MORE_ITEMS)
3990 RegDeleteKeyW(hkey,squished_cc);
3992 /* UI stuff */
3993 uirow = MSI_CreateRecord(2);
3994 MSI_RecordSetStringW(uirow,1,productcode);
3995 MSI_RecordSetStringW(uirow,2,package->components[i].
3996 ComponentId);
3997 ui_actiondata(package,szProcessComponents,uirow);
3998 msiobj_release( &uirow->hdr );
4002 end:
4003 HeapFree(GetProcessHeap(), 0, productcode);
4004 RegCloseKey(hkey);
4005 return rc;
4008 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4011 * OK this is a bit confusing.. I am given a _Component key and I believe
4012 * that the file that is being registered as a type library is the "key file
4013 * of that component" which I interpret to mean "The file in the KeyPath of
4014 * that component".
4016 UINT rc;
4017 MSIQUERY * view;
4018 MSIRECORD * row = 0;
4019 static const WCHAR Query[] =
4020 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4021 'T','y','p','e','L','i','b',0};
4022 ITypeLib *ptLib;
4023 HRESULT res;
4025 if (!package)
4026 return ERROR_INVALID_HANDLE;
4028 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4029 if (rc != ERROR_SUCCESS)
4030 return ERROR_SUCCESS;
4032 rc = MSI_ViewExecute(view, 0);
4033 if (rc != ERROR_SUCCESS)
4035 MSI_ViewClose(view);
4036 msiobj_release(&view->hdr);
4037 return rc;
4040 while (1)
4042 WCHAR component[0x100];
4043 DWORD sz;
4044 INT index;
4046 rc = MSI_ViewFetch(view,&row);
4047 if (rc != ERROR_SUCCESS)
4049 rc = ERROR_SUCCESS;
4050 break;
4053 sz = 0x100;
4054 MSI_RecordGetStringW(row,3,component,&sz);
4056 index = get_loaded_component(package,component);
4057 if (index < 0)
4059 msiobj_release(&row->hdr);
4060 continue;
4063 if (!ACTION_VerifyComponentForAction(package, index,
4064 INSTALLSTATE_LOCAL))
4066 TRACE("Skipping typelib reg due to disabled component\n");
4067 msiobj_release(&row->hdr);
4069 package->components[index].Action =
4070 package->components[index].Installed;
4072 continue;
4075 package->components[index].Action = INSTALLSTATE_LOCAL;
4077 index = get_loaded_file(package,package->components[index].KeyPath);
4079 if (index < 0)
4081 msiobj_release(&row->hdr);
4082 continue;
4085 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
4086 if (SUCCEEDED(res))
4088 LPWSTR help;
4089 WCHAR helpid[0x100];
4091 sz = 0x100;
4092 MSI_RecordGetStringW(row,6,helpid,&sz);
4094 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4095 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
4096 HeapFree(GetProcessHeap(),0,help);
4098 if (!SUCCEEDED(res))
4099 ERR("Failed to register type library %s\n",
4100 debugstr_w(package->files[index].TargetPath));
4101 else
4103 /* Yes the row has more fields than I need, but #1 is
4104 correct and the only one I need. Why make a new row? */
4106 ui_actiondata(package,szRegisterTypeLibraries,row);
4108 TRACE("Registered %s\n",
4109 debugstr_w(package->files[index].TargetPath));
4112 if (ptLib)
4113 ITypeLib_Release(ptLib);
4115 else
4116 ERR("Failed to load type library %s\n",
4117 debugstr_w(package->files[index].TargetPath));
4119 msiobj_release(&row->hdr);
4121 MSI_ViewClose(view);
4122 msiobj_release(&view->hdr);
4123 return rc;
4127 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
4129 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4130 UINT rc;
4131 MSIQUERY * view;
4132 MSIRECORD * row = 0;
4133 static const WCHAR ExecSeqQuery[] =
4134 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4135 'A','p','p','I' ,'d',' ','w','h','e','r','e',' ',
4136 'A','p','p','I','d','=','`','%','s','`',0};
4137 HKEY hkey2,hkey3;
4138 LPWSTR buffer=0;
4140 if (!package)
4141 return ERROR_INVALID_HANDLE;
4143 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
4144 if (rc != ERROR_SUCCESS)
4145 return rc;
4147 rc = MSI_ViewExecute(view, 0);
4148 if (rc != ERROR_SUCCESS)
4150 MSI_ViewClose(view);
4151 msiobj_release(&view->hdr);
4152 return rc;
4155 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
4156 RegCreateKeyW(hkey2,clsid,&hkey3);
4157 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
4158 (strlenW(app)+1)*sizeof(WCHAR));
4160 rc = MSI_ViewFetch(view,&row);
4161 if (rc != ERROR_SUCCESS)
4163 MSI_ViewClose(view);
4164 msiobj_release(&view->hdr);
4165 return rc;
4168 if (!MSI_RecordIsNull(row,2))
4170 LPWSTR deformated=0;
4171 UINT size;
4172 static const WCHAR szRemoteServerName[] =
4173 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
4175 buffer = load_dynamic_stringW(row,2);
4176 size = deformat_string(package,buffer,&deformated);
4177 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
4178 size);
4179 HeapFree(GetProcessHeap(),0,deformated);
4180 HeapFree(GetProcessHeap(),0,buffer);
4183 if (!MSI_RecordIsNull(row,3))
4185 static const WCHAR szLocalService[] =
4186 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
4187 UINT size;
4188 buffer = load_dynamic_stringW(row,3);
4189 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4190 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
4191 HeapFree(GetProcessHeap(),0,buffer);
4194 if (!MSI_RecordIsNull(row,4))
4196 static const WCHAR szService[] =
4197 {'S','e','r','v','i','c','e',
4198 'P','a','r','a','m','e','t','e','r','s',0};
4199 UINT size;
4200 buffer = load_dynamic_stringW(row,4);
4201 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4202 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
4203 HeapFree(GetProcessHeap(),0,buffer);
4206 if (!MSI_RecordIsNull(row,5))
4208 static const WCHAR szDLL[] =
4209 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
4210 UINT size;
4211 buffer = load_dynamic_stringW(row,5);
4212 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4213 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
4214 HeapFree(GetProcessHeap(),0,buffer);
4217 if (!MSI_RecordIsNull(row,6))
4219 static const WCHAR szActivate[] =
4220 {'A','c','t','i','v','a','t','e','A','s',
4221 'S','t','o','r','a','g','e',0};
4222 static const WCHAR szY[] = {'Y',0};
4224 if (MSI_RecordGetInteger(row,6))
4225 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
4228 if (!MSI_RecordIsNull(row,7))
4230 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
4231 static const WCHAR szUser[] =
4232 {'I','n','t','e','r','a','c','t','i','v','e',' ',
4233 'U','s','e','r',0};
4235 if (MSI_RecordGetInteger(row,7))
4236 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
4239 msiobj_release(&row->hdr);
4240 MSI_ViewClose(view);
4241 msiobj_release(&view->hdr);
4242 RegCloseKey(hkey3);
4243 RegCloseKey(hkey2);
4244 return rc;
4247 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
4250 * Again I am assuming the words, "Whose key file represents" when referring
4251 * to a Component as to meaning that Components KeyPath file
4253 * Also there is a very strong connection between ClassInfo and ProgID
4254 * that I am mostly glossing over.
4255 * What would be more propper is to load the ClassInfo and the ProgID info
4256 * into memory data structures and then be able to enable and disable them
4257 * based on component.
4260 UINT rc;
4261 MSIQUERY * view;
4262 MSIRECORD * row = 0;
4263 static const WCHAR ExecSeqQuery[] =
4264 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4265 'C','l','a','s','s',0};
4266 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4267 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
4268 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4269 static const WCHAR szSpace[] = {' ',0};
4270 HKEY hkey,hkey2,hkey3;
4271 LPWSTR argument,deformated;
4273 if (!package)
4274 return ERROR_INVALID_HANDLE;
4276 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
4277 if (rc != ERROR_SUCCESS)
4278 return ERROR_FUNCTION_FAILED;
4280 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4281 if (rc != ERROR_SUCCESS)
4283 rc = ERROR_SUCCESS;
4284 goto end;
4287 rc = MSI_ViewExecute(view, 0);
4288 if (rc != ERROR_SUCCESS)
4290 MSI_ViewClose(view);
4291 msiobj_release(&view->hdr);
4292 goto end;
4295 while (1)
4297 WCHAR clsid[0x100];
4298 WCHAR buffer[0x100];
4299 WCHAR desc[0x100];
4300 DWORD sz;
4301 INT index;
4302 DWORD size;
4304 rc = MSI_ViewFetch(view,&row);
4305 if (rc != ERROR_SUCCESS)
4307 rc = ERROR_SUCCESS;
4308 break;
4311 sz=0x100;
4312 MSI_RecordGetStringW(row,3,buffer,&sz);
4314 index = get_loaded_component(package,buffer);
4316 if (index < 0)
4318 msiobj_release(&row->hdr);
4319 continue;
4322 if (!ACTION_VerifyComponentForAction(package, index,
4323 INSTALLSTATE_LOCAL))
4325 TRACE("Skipping class reg due to disabled component\n");
4326 msiobj_release(&row->hdr);
4328 package->components[index].Action =
4329 package->components[index].Installed;
4331 continue;
4334 package->components[index].Action = INSTALLSTATE_LOCAL;
4336 sz=0x100;
4337 MSI_RecordGetStringW(row,1,clsid,&sz);
4338 RegCreateKeyW(hkey,clsid,&hkey2);
4340 if (!MSI_RecordIsNull(row,5))
4342 sz=0x100;
4343 MSI_RecordGetStringW(row,5,desc,&sz);
4345 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
4346 (strlenW(desc)+1)*sizeof(WCHAR));
4348 else
4349 desc[0]=0;
4351 sz=0x100;
4352 MSI_RecordGetStringW(row,2,buffer,&sz);
4354 RegCreateKeyW(hkey2,buffer,&hkey3);
4356 index = get_loaded_file(package,package->components[index].KeyPath);
4358 argument = load_dynamic_stringW(row,11);
4359 size = deformat_string(package,argument,&deformated);
4360 if (deformated)
4361 size+=sizeof(WCHAR);
4362 HeapFree(GetProcessHeap(),0,argument);
4363 size += (strlenW(package->files[index].TargetPath))*sizeof(WCHAR);
4365 argument = (LPWSTR)HeapAlloc(GetProcessHeap(),0,size+sizeof(WCHAR));
4366 strcpyW(argument,package->files[index].TargetPath);
4367 if (deformated)
4369 strcatW(argument,szSpace);
4370 strcatW(argument,deformated);
4373 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4374 HeapFree(GetProcessHeap(),0,deformated);
4375 HeapFree(GetProcessHeap(),0,argument);
4377 RegCloseKey(hkey3);
4379 if (!MSI_RecordIsNull(row,4))
4381 sz=0x100;
4382 MSI_RecordGetStringW(row,4,buffer,&sz);
4384 RegCreateKeyW(hkey2,szProgID,&hkey3);
4386 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4387 (strlenW(buffer)+1)*sizeof(WCHAR));
4389 RegCloseKey(hkey3);
4392 if (!MSI_RecordIsNull(row,6))
4394 sz=0x100;
4395 MSI_RecordGetStringW(row,6,buffer,&sz);
4397 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4398 (strlenW(buffer)+1)*sizeof(WCHAR));
4400 register_appid(package,buffer,desc);
4404 if (!MSI_RecordIsNull(row,7))
4406 FIXME("Process field 7\n");
4409 if (!MSI_RecordIsNull(row,8))
4411 static const WCHAR szDefaultIcon[] =
4412 {'D','e','f','a','u','l','t','I','c','o','n',0};
4414 LPWSTR FileName = load_dynamic_stringW(row,8);
4415 LPWSTR FilePath;
4416 INT index;
4418 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
4419 build_icon_path(package,FileName,&FilePath);
4420 if (!MSI_RecordIsNull(row,9))
4422 static const WCHAR index_fmt[] = {',','%','i',0};
4423 WCHAR index_buf[20];
4424 index = MSI_RecordGetInteger(row,9);
4425 sprintfW(index_buf,index_fmt,index);
4426 size = strlenW(FilePath)+strlenW(index_buf)+1;
4427 size *= sizeof(WCHAR);
4428 HeapReAlloc(GetProcessHeap(),0,FilePath,size);
4430 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)FilePath,
4431 (strlenW(FilePath)+1) * sizeof(WCHAR));
4432 HeapFree(GetProcessHeap(),0,FilePath);
4433 HeapFree(GetProcessHeap(),0,FileName);
4434 RegCloseKey(hkey3);
4437 if (!MSI_RecordIsNull(row,10))
4439 static const WCHAR szInproc32[] =
4440 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
4442 static const WCHAR szInproc[] =
4443 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
4444 INT i = MSI_RecordGetInteger(row,10);
4445 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
4447 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
4448 static const WCHAR ole32[] =
4449 {'o','l','e','3','2','.','d','l','l',0};
4450 switch(i)
4452 case 1:
4453 size = strlenW(ole2) * sizeof(WCHAR);
4454 RegCreateKeyW(hkey2,szInproc,&hkey3);
4455 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4456 RegCloseKey(hkey3);
4457 break;
4458 case 2:
4459 size = strlenW(ole32) * sizeof(WCHAR);
4460 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4461 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4462 RegCloseKey(hkey3);
4463 break;
4464 case 3:
4465 size = strlenW(ole2) * sizeof(WCHAR);
4466 RegCreateKeyW(hkey2,szInproc,&hkey3);
4467 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole2, size);
4468 RegCloseKey(hkey3);
4469 size = strlenW(ole32) * sizeof(WCHAR);
4470 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4471 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)ole32,size);
4472 RegCloseKey(hkey3);
4473 break;
4477 else
4479 RegCreateKeyW(hkey2,szInproc32,&hkey3);
4480 argument = load_dynamic_stringW(row,10);
4481 reduce_to_longfilename(argument);
4482 size = strlenW(argument)*sizeof(WCHAR);
4484 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPVOID)argument, size);
4485 HeapFree(GetProcessHeap(),0,argument);
4487 RegCloseKey(hkey3);
4491 RegCloseKey(hkey2);
4493 ui_actiondata(package,szRegisterClassInfo,row);
4495 msiobj_release(&row->hdr);
4497 MSI_ViewClose(view);
4498 msiobj_release(&view->hdr);
4500 end:
4501 RegCloseKey(hkey);
4502 return rc;
4505 static UINT register_progid_base(MSIPACKAGE* package, MSIRECORD * row,
4506 LPWSTR clsid)
4508 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4509 static const WCHAR szDefaultIcon[] =
4510 {'D','e','f','a','u','l','t','I','c','o','n',0};
4511 HKEY hkey,hkey2;
4512 WCHAR buffer[0x100];
4513 DWORD sz;
4516 sz = 0x100;
4517 MSI_RecordGetStringW(row,1,buffer,&sz);
4518 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4520 if (!MSI_RecordIsNull(row,4))
4522 sz = 0x100;
4523 MSI_RecordGetStringW(row,4,buffer,&sz);
4524 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4525 sizeof(WCHAR));
4528 if (!MSI_RecordIsNull(row,3))
4530 sz = 0x100;
4532 MSI_RecordGetStringW(row,3,buffer,&sz);
4533 RegCreateKeyW(hkey,szCLSID,&hkey2);
4534 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4535 sizeof(WCHAR));
4537 if (clsid)
4538 strcpyW(clsid,buffer);
4540 RegCloseKey(hkey2);
4542 else
4544 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4545 return ERROR_FUNCTION_FAILED;
4547 if (!MSI_RecordIsNull(row,5))
4549 INT index = MSI_RecordGetInteger(row,6);
4550 LPWSTR FileName = load_dynamic_stringW(row,5);
4551 LPWSTR FilePath,IconPath;
4552 static const WCHAR fmt[] = {'%','s',',','%','i',0};
4554 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4555 build_icon_path(package,FileName,&FilePath);
4557 IconPath = HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
4558 sizeof(WCHAR));
4560 sprintfW(IconPath,fmt,FilePath,index);
4561 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)IconPath,
4562 (strlenW(IconPath)+1) * sizeof(WCHAR));
4563 HeapFree(GetProcessHeap(),0,FilePath);
4564 HeapFree(GetProcessHeap(),0,FileName);
4565 RegCloseKey(hkey2);
4567 return ERROR_SUCCESS;
4570 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4572 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4573 LPWSTR clsid)
4575 UINT rc;
4576 MSIQUERY * view;
4577 MSIRECORD * row = 0;
4578 static const WCHAR Query_t[] =
4579 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4580 'P','r','o','g' ,'I','d',' ','W','H','E','R','E',' ',
4581 'P','r','o','g','I','d',' ','=',' ','`' ,'%','s','`',0};
4583 if (!package)
4584 return ERROR_INVALID_HANDLE;
4586 rc = MSI_OpenQuery(package->db, &view, Query_t, parent);
4587 if (rc != ERROR_SUCCESS)
4588 return rc;
4590 rc = MSI_ViewExecute(view, 0);
4591 if (rc != ERROR_SUCCESS)
4593 MSI_ViewClose(view);
4594 msiobj_release(&view->hdr);
4595 return rc;
4598 rc = MSI_ViewFetch(view,&row);
4599 if (rc != ERROR_SUCCESS)
4601 MSI_ViewClose(view);
4602 msiobj_release(&view->hdr);
4603 return rc;
4606 register_progid(package,row,clsid);
4608 msiobj_release(&row->hdr);
4609 MSI_ViewClose(view);
4610 msiobj_release(&view->hdr);
4611 return rc;
4614 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4616 UINT rc = ERROR_SUCCESS;
4618 if (MSI_RecordIsNull(row,2))
4619 rc = register_progid_base(package,row,clsid);
4620 else
4622 WCHAR buffer[0x1000];
4623 DWORD sz, disp;
4624 HKEY hkey,hkey2;
4625 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4626 static const WCHAR szDefaultIcon[] =
4627 {'D','e','f','a','u','l','t','I','c','o','n',0};
4629 /* check if already registered */
4630 sz = 0x100;
4631 MSI_RecordGetStringW(row,1,buffer,&sz);
4632 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4633 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4634 if (disp == REG_OPENED_EXISTING_KEY)
4636 TRACE("Key already registered\n");
4637 RegCloseKey(hkey);
4638 return rc;
4641 sz = 0x100;
4642 MSI_RecordGetStringW(row,2,buffer,&sz);
4643 rc = register_parent_progid(package,buffer,clsid);
4645 /* clsid is same as parent */
4646 RegCreateKeyW(hkey,szCLSID,&hkey2);
4647 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4648 sizeof(WCHAR));
4650 RegCloseKey(hkey2);
4653 if (!MSI_RecordIsNull(row,4))
4655 sz = 0x100;
4656 MSI_RecordGetStringW(row,4,buffer,&sz);
4657 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4658 (strlenW(buffer)+1) * sizeof(WCHAR));
4661 if (!MSI_RecordIsNull(row,5))
4663 LPWSTR FileName = load_dynamic_stringW(row,5);
4664 LPWSTR FilePath;
4665 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
4666 build_icon_path(package,FileName,&FilePath);
4667 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)FilePath,
4668 (strlenW(FilePath)+1) * sizeof(WCHAR));
4669 HeapFree(GetProcessHeap(),0,FilePath);
4670 HeapFree(GetProcessHeap(),0,FileName);
4671 RegCloseKey(hkey2);
4674 RegCloseKey(hkey);
4676 return rc;
4679 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4682 * Sigh, here I am just brute force registering all progids
4683 * this needs to be linked to the Classes that have been registered
4684 * but the easiest way to do that is to load all these stuff into
4685 * memory for easy checking.
4687 * Gives me something to continue to work toward.
4689 UINT rc;
4690 MSIQUERY * view;
4691 MSIRECORD * row = 0;
4692 static const WCHAR Query[] =
4693 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
4694 'P','r','o','g','I','d',0};
4696 if (!package)
4697 return ERROR_INVALID_HANDLE;
4699 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4700 if (rc != ERROR_SUCCESS)
4701 return ERROR_SUCCESS;
4703 rc = MSI_ViewExecute(view, 0);
4704 if (rc != ERROR_SUCCESS)
4706 MSI_ViewClose(view);
4707 msiobj_release(&view->hdr);
4708 return rc;
4711 while (1)
4713 WCHAR clsid[0x1000];
4715 rc = MSI_ViewFetch(view,&row);
4716 if (rc != ERROR_SUCCESS)
4718 rc = ERROR_SUCCESS;
4719 break;
4722 register_progid(package,row,clsid);
4723 ui_actiondata(package,szRegisterProgIdInfo,row);
4725 msiobj_release(&row->hdr);
4727 MSI_ViewClose(view);
4728 msiobj_release(&view->hdr);
4729 return rc;
4732 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4733 LPWSTR *FilePath)
4735 LPWSTR ProductCode;
4736 LPWSTR SystemFolder;
4737 LPWSTR dest;
4738 UINT rc;
4740 static const WCHAR szInstaller[] =
4741 {'I','n','s','t','a','l','l','e','r','\\',0};
4742 static const WCHAR szFolder[] =
4743 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4745 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4746 if (!ProductCode)
4747 return rc;
4749 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4751 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4753 create_full_pathW(dest);
4755 *FilePath = build_directory_name(2, dest, icon_name);
4757 HeapFree(GetProcessHeap(),0,SystemFolder);
4758 HeapFree(GetProcessHeap(),0,ProductCode);
4759 HeapFree(GetProcessHeap(),0,dest);
4760 return ERROR_SUCCESS;
4763 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4765 UINT rc;
4766 MSIQUERY * view;
4767 MSIRECORD * row = 0;
4768 static const WCHAR Query[] =
4769 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4770 'S','h','o','r','t','c','u','t',0};
4771 IShellLinkW *sl;
4772 IPersistFile *pf;
4773 HRESULT res;
4775 if (!package)
4776 return ERROR_INVALID_HANDLE;
4778 res = CoInitialize( NULL );
4779 if (FAILED (res))
4781 ERR("CoInitialize failed\n");
4782 return ERROR_FUNCTION_FAILED;
4785 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4786 if (rc != ERROR_SUCCESS)
4787 return ERROR_SUCCESS;
4789 rc = MSI_ViewExecute(view, 0);
4790 if (rc != ERROR_SUCCESS)
4792 MSI_ViewClose(view);
4793 msiobj_release(&view->hdr);
4794 return rc;
4797 while (1)
4799 LPWSTR target_file, target_folder;
4800 WCHAR buffer[0x100];
4801 DWORD sz;
4802 DWORD index;
4803 static const WCHAR szlnk[]={'.','l','n','k',0};
4805 rc = MSI_ViewFetch(view,&row);
4806 if (rc != ERROR_SUCCESS)
4808 rc = ERROR_SUCCESS;
4809 break;
4812 sz = 0x100;
4813 MSI_RecordGetStringW(row,4,buffer,&sz);
4815 index = get_loaded_component(package,buffer);
4817 if (index < 0)
4819 msiobj_release(&row->hdr);
4820 continue;
4823 if (!ACTION_VerifyComponentForAction(package, index,
4824 INSTALLSTATE_LOCAL))
4826 TRACE("Skipping shortcut creation due to disabled component\n");
4827 msiobj_release(&row->hdr);
4829 package->components[index].Action =
4830 package->components[index].Installed;
4832 continue;
4835 package->components[index].Action = INSTALLSTATE_LOCAL;
4837 ui_actiondata(package,szCreateShortcuts,row);
4839 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4840 &IID_IShellLinkW, (LPVOID *) &sl );
4842 if (FAILED(res))
4844 ERR("Is IID_IShellLink\n");
4845 msiobj_release(&row->hdr);
4846 continue;
4849 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4850 if( FAILED( res ) )
4852 ERR("Is IID_IPersistFile\n");
4853 msiobj_release(&row->hdr);
4854 continue;
4857 sz = 0x100;
4858 MSI_RecordGetStringW(row,2,buffer,&sz);
4859 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4861 /* may be needed because of a bug somehwere else */
4862 create_full_pathW(target_folder);
4864 sz = 0x100;
4865 MSI_RecordGetStringW(row,3,buffer,&sz);
4866 reduce_to_longfilename(buffer);
4867 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4868 strcatW(buffer,szlnk);
4869 target_file = build_directory_name(2, target_folder, buffer);
4870 HeapFree(GetProcessHeap(),0,target_folder);
4872 sz = 0x100;
4873 MSI_RecordGetStringW(row,5,buffer,&sz);
4874 if (strchrW(buffer,'['))
4876 LPWSTR deformated;
4877 deformat_string(package,buffer,&deformated);
4878 IShellLinkW_SetPath(sl,deformated);
4879 HeapFree(GetProcessHeap(),0,deformated);
4881 else
4883 LPWSTR keypath;
4884 FIXME("poorly handled shortcut format, advertised shortcut\n");
4885 keypath = dupstrW(package->components[index].FullKeypath);
4886 IShellLinkW_SetPath(sl,keypath);
4887 HeapFree(GetProcessHeap(),0,keypath);
4890 if (!MSI_RecordIsNull(row,6))
4892 LPWSTR deformated;
4893 sz = 0x100;
4894 MSI_RecordGetStringW(row,6,buffer,&sz);
4895 deformat_string(package,buffer,&deformated);
4896 IShellLinkW_SetArguments(sl,deformated);
4897 HeapFree(GetProcessHeap(),0,deformated);
4900 if (!MSI_RecordIsNull(row,7))
4902 LPWSTR deformated;
4903 deformated = load_dynamic_stringW(row,7);
4904 IShellLinkW_SetDescription(sl,deformated);
4905 HeapFree(GetProcessHeap(),0,deformated);
4908 if (!MSI_RecordIsNull(row,8))
4909 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4911 if (!MSI_RecordIsNull(row,9))
4913 WCHAR *Path = NULL;
4914 INT index;
4916 sz = 0x100;
4917 MSI_RecordGetStringW(row,9,buffer,&sz);
4919 build_icon_path(package,buffer,&Path);
4920 index = MSI_RecordGetInteger(row,10);
4922 IShellLinkW_SetIconLocation(sl,Path,index);
4923 HeapFree(GetProcessHeap(),0,Path);
4926 if (!MSI_RecordIsNull(row,11))
4927 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4929 if (!MSI_RecordIsNull(row,12))
4931 LPWSTR Path;
4932 sz = 0x100;
4933 MSI_RecordGetStringW(row,12,buffer,&sz);
4934 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
4935 IShellLinkW_SetWorkingDirectory(sl,Path);
4936 HeapFree(GetProcessHeap(), 0, Path);
4939 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4940 IPersistFile_Save(pf,target_file,FALSE);
4942 HeapFree(GetProcessHeap(),0,target_file);
4944 IPersistFile_Release( pf );
4945 IShellLinkW_Release( sl );
4947 msiobj_release(&row->hdr);
4949 MSI_ViewClose(view);
4950 msiobj_release(&view->hdr);
4953 CoUninitialize();
4955 return rc;
4960 * 99% of the work done here is only done for
4961 * advertised installs. However this is where the
4962 * Icon table is processed and written out
4963 * so that is what I am going to do here.
4965 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4967 UINT rc;
4968 MSIQUERY * view;
4969 MSIRECORD * row = 0;
4970 static const WCHAR Query[]=
4971 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4972 'I','c','o','n',0};
4973 DWORD sz;
4974 /* for registry stuff */
4975 LPWSTR productcode;
4976 HKEY hkey=0;
4977 HKEY hukey=0;
4978 static const WCHAR szProductName[] =
4979 {'P','r','o','d','u','c','t','N','a','m','e',0};
4980 static const WCHAR szPackageCode[] =
4981 {'P','a','c','k','a','g','e','C','o','d','e',0};
4982 LPWSTR buffer;
4983 DWORD size;
4984 MSIHANDLE hDb, hSumInfo;
4986 if (!package)
4987 return ERROR_INVALID_HANDLE;
4989 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4990 if (rc != ERROR_SUCCESS)
4991 goto next;
4993 rc = MSI_ViewExecute(view, 0);
4994 if (rc != ERROR_SUCCESS)
4996 MSI_ViewClose(view);
4997 msiobj_release(&view->hdr);
4998 goto next;
5001 while (1)
5003 HANDLE the_file;
5004 WCHAR *FilePath=NULL;
5005 WCHAR *FileName=NULL;
5006 CHAR buffer[1024];
5008 rc = MSI_ViewFetch(view,&row);
5009 if (rc != ERROR_SUCCESS)
5011 rc = ERROR_SUCCESS;
5012 break;
5015 FileName = load_dynamic_stringW(row,1);
5016 if (!FileName)
5018 ERR("Unable to get FileName\n");
5019 msiobj_release(&row->hdr);
5020 continue;
5023 build_icon_path(package,FileName,&FilePath);
5025 HeapFree(GetProcessHeap(),0,FileName);
5027 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
5029 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
5030 FILE_ATTRIBUTE_NORMAL, NULL);
5032 if (the_file == INVALID_HANDLE_VALUE)
5034 ERR("Unable to create file %s\n",debugstr_w(FilePath));
5035 msiobj_release(&row->hdr);
5036 HeapFree(GetProcessHeap(),0,FilePath);
5037 continue;
5042 DWORD write;
5043 sz = 1024;
5044 rc = MSI_RecordReadStream(row,2,buffer,&sz);
5045 if (rc != ERROR_SUCCESS)
5047 ERR("Failed to get stream\n");
5048 CloseHandle(the_file);
5049 DeleteFileW(FilePath);
5050 break;
5052 WriteFile(the_file,buffer,sz,&write,NULL);
5053 } while (sz == 1024);
5055 HeapFree(GetProcessHeap(),0,FilePath);
5057 CloseHandle(the_file);
5058 msiobj_release(&row->hdr);
5060 MSI_ViewClose(view);
5061 msiobj_release(&view->hdr);
5063 next:
5064 /* ok there is a lot more done here but i need to figure out what */
5065 productcode = load_dynamic_property(package,szProductCode,&rc);
5066 if (!productcode)
5067 return rc;
5069 rc = MSIREG_OpenProductsKey(productcode,&hkey,TRUE);
5070 if (rc != ERROR_SUCCESS)
5071 goto end;
5073 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5074 if (rc != ERROR_SUCCESS)
5075 goto end;
5078 buffer = load_dynamic_property(package,szProductName,NULL);
5079 size = strlenW(buffer)*sizeof(WCHAR);
5080 RegSetValueExW(hukey,szProductName,0,REG_SZ, (LPSTR)buffer,size);
5081 HeapFree(GetProcessHeap(),0,buffer);
5082 FIXME("Need to write more keys to the user registry\n");
5084 hDb= alloc_msihandle( &package->db->hdr );
5085 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
5086 MsiCloseHandle(hDb);
5087 if (rc == ERROR_SUCCESS)
5089 WCHAR guidbuffer[0x200];
5090 size = 0x200;
5091 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
5092 guidbuffer, &size);
5093 if (rc == ERROR_SUCCESS)
5095 WCHAR squashed[GUID_SIZE];
5096 /* for now we only care about the first guid */
5097 LPWSTR ptr = strchrW(guidbuffer,';');
5098 if (ptr) *ptr = 0;
5099 squash_guid(guidbuffer,squashed);
5100 size = strlenW(squashed)*sizeof(WCHAR);
5101 RegSetValueExW(hukey,szPackageCode,0,REG_SZ, (LPSTR)squashed,
5102 size);
5104 else
5106 ERR("Unable to query Revision_Number... \n");
5107 rc = ERROR_SUCCESS;
5109 MsiCloseHandle(hSumInfo);
5111 else
5113 ERR("Unable to open Summary Information\n");
5114 rc = ERROR_SUCCESS;
5117 end:
5119 HeapFree(GetProcessHeap(),0,productcode);
5120 RegCloseKey(hkey);
5121 RegCloseKey(hukey);
5123 return rc;
5126 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
5128 UINT rc;
5129 MSIQUERY * view;
5130 MSIRECORD * row = 0;
5131 static const WCHAR ExecSeqQuery[] =
5132 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5133 'I','n','i','F','i','l','e',0};
5134 static const WCHAR szWindowsFolder[] =
5135 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
5137 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5138 if (rc != ERROR_SUCCESS)
5140 TRACE("no IniFile table\n");
5141 return ERROR_SUCCESS;
5144 rc = MSI_ViewExecute(view, 0);
5145 if (rc != ERROR_SUCCESS)
5147 MSI_ViewClose(view);
5148 msiobj_release(&view->hdr);
5149 return rc;
5152 while (1)
5154 LPWSTR component,filename,dirproperty,section,key,value,identifier;
5155 LPWSTR deformated_section, deformated_key, deformated_value;
5156 LPWSTR folder, fullname = NULL;
5157 MSIRECORD * uirow;
5158 INT component_index,action;
5160 rc = MSI_ViewFetch(view,&row);
5161 if (rc != ERROR_SUCCESS)
5163 rc = ERROR_SUCCESS;
5164 break;
5167 component = load_dynamic_stringW(row, 8);
5168 component_index = get_loaded_component(package,component);
5169 HeapFree(GetProcessHeap(),0,component);
5171 if (!ACTION_VerifyComponentForAction(package, component_index,
5172 INSTALLSTATE_LOCAL))
5174 TRACE("Skipping ini file due to disabled component\n");
5175 msiobj_release(&row->hdr);
5177 package->components[component_index].Action =
5178 package->components[component_index].Installed;
5180 continue;
5183 package->components[component_index].Action = INSTALLSTATE_LOCAL;
5185 identifier = load_dynamic_stringW(row,1);
5186 filename = load_dynamic_stringW(row,2);
5187 dirproperty = load_dynamic_stringW(row,3);
5188 section = load_dynamic_stringW(row,4);
5189 key = load_dynamic_stringW(row,5);
5190 value = load_dynamic_stringW(row,6);
5191 action = MSI_RecordGetInteger(row,7);
5193 deformat_string(package,section,&deformated_section);
5194 deformat_string(package,key,&deformated_key);
5195 deformat_string(package,value,&deformated_value);
5197 if (dirproperty)
5199 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
5200 if (!folder)
5201 folder = load_dynamic_property(package,dirproperty,NULL);
5203 else
5204 folder = load_dynamic_property(package, szWindowsFolder, NULL);
5206 if (!folder)
5208 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
5209 goto cleanup;
5212 fullname = build_directory_name(3, folder, filename, NULL);
5214 if (action == 0)
5216 TRACE("Adding value %s to section %s in %s\n",
5217 debugstr_w(deformated_key), debugstr_w(deformated_section),
5218 debugstr_w(fullname));
5219 WritePrivateProfileStringW(deformated_section, deformated_key,
5220 deformated_value, fullname);
5222 else if (action == 1)
5224 WCHAR returned[10];
5225 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
5226 returned, 10, fullname);
5227 if (returned[0] == 0)
5229 TRACE("Adding value %s to section %s in %s\n",
5230 debugstr_w(deformated_key), debugstr_w(deformated_section),
5231 debugstr_w(fullname));
5233 WritePrivateProfileStringW(deformated_section, deformated_key,
5234 deformated_value, fullname);
5237 else if (action == 3)
5239 FIXME("Append to existing section not yet implemented\n");
5242 uirow = MSI_CreateRecord(4);
5243 MSI_RecordSetStringW(uirow,1,identifier);
5244 MSI_RecordSetStringW(uirow,2,deformated_section);
5245 MSI_RecordSetStringW(uirow,3,deformated_key);
5246 MSI_RecordSetStringW(uirow,4,deformated_value);
5247 ui_actiondata(package,szWriteIniValues,uirow);
5248 msiobj_release( &uirow->hdr );
5249 cleanup:
5250 HeapFree(GetProcessHeap(),0,identifier);
5251 HeapFree(GetProcessHeap(),0,fullname);
5252 HeapFree(GetProcessHeap(),0,filename);
5253 HeapFree(GetProcessHeap(),0,key);
5254 HeapFree(GetProcessHeap(),0,value);
5255 HeapFree(GetProcessHeap(),0,section);
5256 HeapFree(GetProcessHeap(),0,dirproperty);
5257 HeapFree(GetProcessHeap(),0,folder);
5258 HeapFree(GetProcessHeap(),0,deformated_key);
5259 HeapFree(GetProcessHeap(),0,deformated_value);
5260 HeapFree(GetProcessHeap(),0,deformated_section);
5261 msiobj_release(&row->hdr);
5263 MSI_ViewClose(view);
5264 msiobj_release(&view->hdr);
5265 return rc;
5268 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
5270 UINT rc;
5271 MSIQUERY * view;
5272 MSIRECORD * row = 0;
5273 static const WCHAR ExecSeqQuery[] =
5274 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5275 'S','e','l','f','R','e','g',0};
5277 static const WCHAR ExeStr[] =
5278 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ',0};
5279 STARTUPINFOW si;
5280 PROCESS_INFORMATION info;
5281 BOOL brc;
5283 memset(&si,0,sizeof(STARTUPINFOW));
5285 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5286 if (rc != ERROR_SUCCESS)
5288 TRACE("no SelfReg table\n");
5289 return ERROR_SUCCESS;
5292 rc = MSI_ViewExecute(view, 0);
5293 if (rc != ERROR_SUCCESS)
5295 MSI_ViewClose(view);
5296 msiobj_release(&view->hdr);
5297 return rc;
5300 while (1)
5302 LPWSTR filename;
5303 INT index;
5304 DWORD len;
5306 rc = MSI_ViewFetch(view,&row);
5307 if (rc != ERROR_SUCCESS)
5309 rc = ERROR_SUCCESS;
5310 break;
5313 filename = load_dynamic_stringW(row,1);
5314 index = get_loaded_file(package,filename);
5316 if (index < 0)
5318 ERR("Unable to find file id %s\n",debugstr_w(filename));
5319 HeapFree(GetProcessHeap(),0,filename);
5320 msiobj_release(&row->hdr);
5321 continue;
5323 HeapFree(GetProcessHeap(),0,filename);
5325 len = strlenW(ExeStr);
5326 len += strlenW(package->files[index].TargetPath);
5327 len +=2;
5329 filename = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
5330 strcpyW(filename,ExeStr);
5331 strcatW(filename,package->files[index].TargetPath);
5333 TRACE("Registering %s\n",debugstr_w(filename));
5334 brc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
5335 c_colon, &si, &info);
5337 if (brc)
5338 msi_dialog_check_messages(package->dialog, info.hProcess);
5340 HeapFree(GetProcessHeap(),0,filename);
5341 msiobj_release(&row->hdr);
5343 MSI_ViewClose(view);
5344 msiobj_release(&view->hdr);
5345 return rc;
5348 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
5350 LPWSTR productcode;
5351 UINT rc;
5352 DWORD i;
5353 HKEY hkey=0;
5354 HKEY hukey=0;
5356 if (!package)
5357 return ERROR_INVALID_HANDLE;
5359 productcode = load_dynamic_property(package,szProductCode,&rc);
5360 if (!productcode)
5361 return rc;
5363 rc = MSIREG_OpenFeaturesKey(productcode,&hkey,TRUE);
5364 if (rc != ERROR_SUCCESS)
5365 goto end;
5367 rc = MSIREG_OpenUserFeaturesKey(productcode,&hukey,TRUE);
5368 if (rc != ERROR_SUCCESS)
5369 goto end;
5371 /* here the guids are base 85 encoded */
5372 for (i = 0; i < package->loaded_features; i++)
5374 LPWSTR data = NULL;
5375 GUID clsid;
5376 int j;
5377 INT size;
5379 if (!ACTION_VerifyFeatureForAction(package,i,INSTALLSTATE_LOCAL))
5380 continue;
5382 size = package->features[i].ComponentCount*21;
5383 size +=1;
5384 if (package->features[i].Feature_Parent[0])
5385 size += strlenW(package->features[i].Feature_Parent)+2;
5387 data = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
5389 data[0] = 0;
5390 for (j = 0; j < package->features[i].ComponentCount; j++)
5392 WCHAR buf[21];
5393 memset(buf,0,sizeof(buf));
5394 TRACE("From %s\n",debugstr_w(package->components
5395 [package->features[i].Components[j]].ComponentId));
5396 CLSIDFromString(package->components
5397 [package->features[i].Components[j]].ComponentId,
5398 &clsid);
5399 encode_base85_guid(&clsid,buf);
5400 TRACE("to %s\n",debugstr_w(buf));
5401 strcatW(data,buf);
5403 if (package->features[i].Feature_Parent[0])
5405 static const WCHAR sep[] = {'\2',0};
5406 strcatW(data,sep);
5407 strcatW(data,package->features[i].Feature_Parent);
5410 size = (strlenW(data)+1)*sizeof(WCHAR);
5411 RegSetValueExW(hkey,package->features[i].Feature,0,REG_SZ,
5412 (LPSTR)data,size);
5413 HeapFree(GetProcessHeap(),0,data);
5415 size = strlenW(package->features[i].Feature_Parent)*sizeof(WCHAR);
5416 RegSetValueExW(hukey,package->features[i].Feature,0,REG_SZ,
5417 (LPSTR)package->features[i].Feature_Parent,size);
5420 end:
5421 RegCloseKey(hkey);
5422 RegCloseKey(hukey);
5423 HeapFree(GetProcessHeap(), 0, productcode);
5424 return rc;
5427 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
5429 HKEY hkey=0;
5430 LPWSTR buffer;
5431 LPWSTR productcode;
5432 UINT rc,i;
5433 DWORD size;
5434 static WCHAR szNONE[] = {0};
5435 static const WCHAR szWindowsInstaler[] =
5436 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
5437 static const WCHAR szPropKeys[][80] =
5439 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
5440 {'A','R','P','C','O','N','T','A','C','T',0},
5441 {'A','R','P','C','O','M','M','E','N','T','S',0},
5442 {'P','r','o','d','u','c','t','N','a','m','e',0},
5443 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
5444 {'A','R','P','H','E','L','P','L','I','N','K',0},
5445 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
5446 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
5447 {'S','o','u','r','c','e','D','i','r',0},
5448 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
5449 {'A','R','P','R','E','A','D','M','E',0},
5450 {'A','R','P','S','I','Z','E',0},
5451 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
5452 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
5453 {0},
5456 static const WCHAR szRegKeys[][80] =
5458 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
5459 {'C','o','n','t','a','c','t',0},
5460 {'C','o','m','m','e','n','t','s',0},
5461 {'D','i','s','p','l','a','y','N','a','m','e',0},
5462 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
5463 {'H','e','l','p','L','i','n','k',0},
5464 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
5465 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
5466 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
5467 {'P','u','b','l','i','s','h','e','r',0},
5468 {'R','e','a','d','m','e',0},
5469 {'S','i','z','e',0},
5470 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
5471 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
5472 {0},
5475 static const WCHAR installerPathFmt[] = {
5476 '%','s','\\',
5477 'I','n','s','t','a','l','l','e','r','\\',0};
5478 static const WCHAR fmt[] = {
5479 '%','s','\\',
5480 'I','n','s','t','a','l','l','e','r','\\',
5481 '%','x','.','m','s','i',0};
5482 static const WCHAR szLocalPackage[]=
5483 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
5484 WCHAR windir[MAX_PATH], path[MAX_PATH], packagefile[MAX_PATH];
5485 INT num,start;
5487 if (!package)
5488 return ERROR_INVALID_HANDLE;
5490 productcode = load_dynamic_property(package,szProductCode,&rc);
5491 if (!productcode)
5492 return rc;
5494 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
5495 if (rc != ERROR_SUCCESS)
5496 goto end;
5498 /* dump all the info i can grab */
5499 FIXME("Flesh out more information \n");
5501 i = 0;
5502 while (szPropKeys[i][0]!=0)
5504 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
5505 if (rc != ERROR_SUCCESS)
5506 buffer = szNONE;
5507 size = strlenW(buffer)*sizeof(WCHAR);
5508 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
5509 i++;
5512 rc = 0x1;
5513 size = sizeof(rc);
5514 RegSetValueExW(hkey,szWindowsInstaler,0,REG_DWORD,(LPSTR)&rc,size);
5516 /* copy the package locally */
5517 num = GetTickCount() & 0xffff;
5518 if (!num)
5519 num = 1;
5520 start = num;
5521 GetWindowsDirectoryW(windir, sizeof(windir) / sizeof(windir[0]));
5522 snprintfW(packagefile,sizeof(packagefile)/sizeof(packagefile[0]),fmt,
5523 windir,num);
5526 HANDLE handle = CreateFileW(packagefile,GENERIC_WRITE, 0, NULL,
5527 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
5528 if (handle != INVALID_HANDLE_VALUE)
5530 CloseHandle(handle);
5531 break;
5533 if (GetLastError() != ERROR_FILE_EXISTS &&
5534 GetLastError() != ERROR_SHARING_VIOLATION)
5535 break;
5536 if (!(++num & 0xffff)) num = 1;
5537 sprintfW(packagefile,fmt,num);
5538 } while (num != start);
5540 snprintfW(path,sizeof(path)/sizeof(path[0]),installerPathFmt,windir);
5541 create_full_pathW(path);
5542 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
5543 CopyFileW(package->PackagePath,packagefile,FALSE);
5544 size = strlenW(packagefile)*sizeof(WCHAR);
5545 RegSetValueExW(hkey,szLocalPackage,0,REG_SZ,(LPSTR)packagefile,size);
5547 end:
5548 HeapFree(GetProcessHeap(),0,productcode);
5549 RegCloseKey(hkey);
5551 return ERROR_SUCCESS;
5554 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
5556 int i;
5557 if (!package)
5558 return ERROR_INVALID_HANDLE;
5560 for (i = 0; i < package->DeferredActionCount; i++)
5562 LPWSTR action;
5563 action = package->DeferredAction[i];
5564 ui_actionstart(package, action);
5565 TRACE("Executing Action (%s)\n",debugstr_w(action));
5566 ACTION_CustomAction(package,action,TRUE);
5567 HeapFree(GetProcessHeap(),0,package->DeferredAction[i]);
5569 HeapFree(GetProcessHeap(),0,package->DeferredAction);
5571 package->DeferredActionCount = 0;
5572 package->DeferredAction = NULL;
5574 return ERROR_SUCCESS;
5577 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
5579 int i;
5580 if (!package)
5581 return ERROR_INVALID_HANDLE;
5583 /* first do the same as an InstallExecute */
5584 ACTION_InstallExecute(package);
5586 /* then handle Commit Actions */
5587 for (i = 0; i < package->CommitActionCount; i++)
5589 LPWSTR action;
5590 action = package->CommitAction[i];
5591 ui_actionstart(package, action);
5592 TRACE("Executing Commit Action (%s)\n",debugstr_w(action));
5593 ACTION_CustomAction(package,action,TRUE);
5594 HeapFree(GetProcessHeap(),0,package->CommitAction[i]);
5596 HeapFree(GetProcessHeap(),0,package->CommitAction);
5598 package->CommitActionCount = 0;
5599 package->CommitAction = NULL;
5601 return ERROR_SUCCESS;
5604 static UINT ACTION_ForceReboot(MSIPACKAGE *package)
5606 static const WCHAR RunOnce[] = {
5607 'S','o','f','t','w','a','r','e','\\',
5608 'M','i','c','r','o','s','o','f','t','\\',
5609 'W','i','n','d','o','w','s','\\',
5610 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5611 'R','u','n','O','n','c','e',0};
5612 static const WCHAR InstallRunOnce[] = {
5613 'S','o','f','t','w','a','r','e','\\',
5614 'M','i','c','r','o','s','o','f','t','\\',
5615 'W','i','n','d','o','w','s','\\',
5616 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5617 'I','n','s','t','a','l','l','e','r','\\',
5618 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
5620 static const WCHAR msiexec_fmt[] = {
5621 '%','s',
5622 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5623 '\"','%','s','\"',0};
5624 static const WCHAR install_fmt[] = {
5625 '/','I',' ','\"','%','s','\"',' ',
5626 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5627 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5628 WCHAR buffer[256], sysdir[MAX_PATH];
5629 HKEY hkey,hukey;
5630 LPWSTR productcode;
5631 WCHAR squished_pc[100];
5632 INT rc;
5633 DWORD size;
5634 static const WCHAR szLUS[] = {
5635 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
5636 static const WCHAR szSourceList[] = {
5637 'S','o','u','r','c','e','L','i','s','t',0};
5638 static const WCHAR szPackageName[] = {
5639 'P','a','c','k','a','g','e','N','a','m','e',0};
5641 if (!package)
5642 return ERROR_INVALID_HANDLE;
5644 productcode = load_dynamic_property(package,szProductCode,&rc);
5645 if (!productcode)
5646 return rc;
5648 squash_guid(productcode,squished_pc);
5650 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
5651 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
5652 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
5653 squished_pc);
5655 size = strlenW(buffer)*sizeof(WCHAR);
5656 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5657 RegCloseKey(hkey);
5659 TRACE("Reboot command %s\n",debugstr_w(buffer));
5661 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
5662 sprintfW(buffer,install_fmt,productcode,squished_pc);
5664 size = strlenW(buffer)*sizeof(WCHAR);
5665 RegSetValueExW(hkey,squished_pc,0,REG_SZ,(LPSTR)buffer,size);
5666 RegCloseKey(hkey);
5668 rc = MSIREG_OpenUserProductsKey(productcode,&hukey,TRUE);
5669 if (rc == ERROR_SUCCESS)
5671 HKEY hukey2;
5672 LPWSTR buf;
5673 RegCreateKeyW(hukey, szSourceList, &hukey2);
5674 buf = load_dynamic_property(package,cszSourceDir,NULL);
5675 size = strlenW(buf)*sizeof(WCHAR);
5676 RegSetValueExW(hukey2,szLUS,0,REG_SZ,(LPSTR)buf,size);
5677 HeapFree(GetProcessHeap(),0,buf);
5679 buf = strrchrW(package->PackagePath,'\\');
5680 if (buf)
5682 buf++;
5683 size = strlenW(buf)*sizeof(WCHAR);
5684 RegSetValueExW(hukey2,szPackageName,0,REG_SZ,(LPSTR)buf,size);
5687 RegCloseKey(hukey2);
5689 HeapFree(GetProcessHeap(),0,productcode);
5691 return ERROR_INSTALL_SUSPEND;
5694 UINT ACTION_ResolveSource(MSIPACKAGE* package)
5697 * we are currently doing what should be done here in the top level Install
5698 * however for Adminastrative and uninstalls this step will be needed
5700 return ERROR_SUCCESS;
5704 static UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
5706 UINT rc;
5707 MSIQUERY * view;
5708 MSIRECORD * row = 0;
5709 static const WCHAR ExecSeqQuery[] =
5710 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5711 'E','x','t','e','n','s','i','o','n',0};
5712 static const WCHAR szContentType[] =
5713 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
5714 HKEY hkey;
5716 if (!package)
5717 return ERROR_INVALID_HANDLE;
5719 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5720 if (rc != ERROR_SUCCESS)
5722 rc = ERROR_SUCCESS;
5723 goto end;
5726 rc = MSI_ViewExecute(view, 0);
5727 if (rc != ERROR_SUCCESS)
5729 MSI_ViewClose(view);
5730 msiobj_release(&view->hdr);
5731 goto end;
5734 while (1)
5736 WCHAR buffer[0x100];
5737 WCHAR extension[257];
5738 LPWSTR exten;
5739 DWORD sz;
5740 INT index;
5742 rc = MSI_ViewFetch(view,&row);
5743 if (rc != ERROR_SUCCESS)
5745 rc = ERROR_SUCCESS;
5746 break;
5749 sz=0x100;
5750 MSI_RecordGetStringW(row,2,buffer,&sz);
5752 index = get_loaded_component(package,buffer);
5754 if (index < 0)
5756 msiobj_release(&row->hdr);
5757 continue;
5760 if (!ACTION_VerifyComponentForAction(package, index,
5761 INSTALLSTATE_LOCAL))
5763 TRACE("Skipping extension reg due to disabled component\n");
5764 msiobj_release(&row->hdr);
5766 package->components[index].Action =
5767 package->components[index].Installed;
5769 continue;
5772 package->components[index].Action = INSTALLSTATE_LOCAL;
5774 exten = load_dynamic_stringW(row,1);
5775 extension[0] = '.';
5776 extension[1] = 0;
5777 strcatW(extension,exten);
5778 HeapFree(GetProcessHeap(),0,exten);
5780 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
5782 if (!MSI_RecordIsNull(row,4))
5784 LPWSTR mime = load_dynamic_stringW(row,4);
5785 RegSetValueExW(hkey,szContentType,0,REG_SZ,(LPVOID)mime,
5786 (strlenW(mime)+1)*sizeof(WCHAR));
5787 HeapFree(GetProcessHeap(),0,mime);
5790 if (!MSI_RecordIsNull(row,3))
5792 static const WCHAR szSN[] =
5793 {'\\','S','h','e','l','l','N','e','w',0};
5794 HKEY hkey2;
5795 LPWSTR newkey;
5796 LPWSTR progid= load_dynamic_stringW(row,3);
5798 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid,
5799 (strlenW(progid)+1)*sizeof(WCHAR));
5801 newkey = HeapAlloc(GetProcessHeap(),0,
5802 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
5804 strcpyW(newkey,progid);
5805 strcatW(newkey,szSN);
5806 RegCreateKeyW(hkey,newkey,&hkey2);
5807 RegCloseKey(hkey2);
5809 HeapFree(GetProcessHeap(),0,progid);
5810 HeapFree(GetProcessHeap(),0,newkey);
5814 RegCloseKey(hkey);
5816 ui_actiondata(package,szRegisterExtensionInfo,row);
5818 msiobj_release(&row->hdr);
5820 MSI_ViewClose(view);
5821 msiobj_release(&view->hdr);
5823 end:
5824 return rc;
5827 static UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
5829 UINT rc;
5830 MSIQUERY * view;
5831 MSIRECORD * row = 0;
5832 static const WCHAR ExecSeqQuery[] =
5833 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5834 'M','I','M','E',0};
5835 static const WCHAR szExten[] =
5836 {'E','x','t','e','n','s','i','o','n',0 };
5837 HKEY hkey;
5839 if (!package)
5840 return ERROR_INVALID_HANDLE;
5842 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5843 if (rc != ERROR_SUCCESS)
5845 rc = ERROR_SUCCESS;
5846 goto end;
5849 rc = MSI_ViewExecute(view, 0);
5850 if (rc != ERROR_SUCCESS)
5852 MSI_ViewClose(view);
5853 msiobj_release(&view->hdr);
5854 goto end;
5857 while (1)
5859 WCHAR extension[257];
5860 LPWSTR exten;
5861 LPWSTR mime;
5862 static const WCHAR fmt[] =
5863 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
5864 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
5865 LPWSTR key;
5867 rc = MSI_ViewFetch(view,&row);
5868 if (rc != ERROR_SUCCESS)
5870 rc = ERROR_SUCCESS;
5871 break;
5874 mime = load_dynamic_stringW(row,1);
5875 exten = load_dynamic_stringW(row,2);
5876 extension[0] = '.';
5877 extension[1] = 0;
5878 strcatW(extension,exten);
5879 HeapFree(GetProcessHeap(),0,exten);
5881 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
5882 sizeof(WCHAR));
5883 sprintfW(key,fmt,mime);
5884 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
5885 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
5886 (strlenW(extension)+1)*sizeof(WCHAR));
5888 HeapFree(GetProcessHeap(),0,mime);
5889 HeapFree(GetProcessHeap(),0,key);
5891 if (!MSI_RecordIsNull(row,3))
5893 FIXME("Handle non null for field 3\n");
5896 RegCloseKey(hkey);
5898 ui_actiondata(package,szRegisterMIMEInfo,row);
5900 msiobj_release(&row->hdr);
5902 MSI_ViewClose(view);
5903 msiobj_release(&view->hdr);
5905 end:
5906 return rc;
5909 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
5911 static const WCHAR szProductID[]=
5912 {'P','r','o','d','u','c','t','I','D',0};
5913 HKEY hkey=0;
5914 LPWSTR buffer;
5915 LPWSTR productcode;
5916 LPWSTR productid;
5917 UINT rc,i;
5918 DWORD size;
5920 static const WCHAR szPropKeys[][80] =
5922 {'P','r','o','d','u','c','t','I','D',0},
5923 {'U','S','E','R','N','A','M','E',0},
5924 {'C','O','M','P','A','N','Y','N','A','M','E',0},
5925 {0},
5928 static const WCHAR szRegKeys[][80] =
5930 {'P','r','o','d','u','c','t','I','D',0},
5931 {'R','e','g','O','w','n','e','r',0},
5932 {'R','e','g','C','o','m','p','a','n','y',0},
5933 {0},
5936 if (!package)
5937 return ERROR_INVALID_HANDLE;
5939 productid = load_dynamic_property(package,szProductID,&rc);
5940 if (!productid)
5941 return ERROR_SUCCESS;
5943 productcode = load_dynamic_property(package,szProductCode,&rc);
5944 if (!productcode)
5945 return rc;
5947 rc = MSIREG_OpenUninstallKey(productcode,&hkey,TRUE);
5948 if (rc != ERROR_SUCCESS)
5949 goto end;
5951 i = 0;
5952 while (szPropKeys[i][0]!=0)
5954 buffer = load_dynamic_property(package,szPropKeys[i],&rc);
5955 if (rc == ERROR_SUCCESS)
5957 size = strlenW(buffer)*sizeof(WCHAR);
5958 RegSetValueExW(hkey,szRegKeys[i],0,REG_SZ,(LPSTR)buffer,size);
5960 i++;
5963 end:
5964 HeapFree(GetProcessHeap(),0,productcode);
5965 HeapFree(GetProcessHeap(),0,productid);
5966 RegCloseKey(hkey);
5968 return ERROR_SUCCESS;
5972 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
5974 UINT rc;
5975 rc = ACTION_ProcessExecSequence(package,TRUE);
5976 return rc;
5981 * Code based off of code located here
5982 * http://www.codeproject.com/gdi/fontnamefromfile.asp
5984 * Using string index 4 (full font name) instead of 1 (family name)
5986 static LPWSTR load_ttfname_from(LPCWSTR filename)
5988 HANDLE handle;
5989 LPWSTR ret = NULL;
5990 int i;
5992 typedef struct _tagTT_OFFSET_TABLE{
5993 USHORT uMajorVersion;
5994 USHORT uMinorVersion;
5995 USHORT uNumOfTables;
5996 USHORT uSearchRange;
5997 USHORT uEntrySelector;
5998 USHORT uRangeShift;
5999 }TT_OFFSET_TABLE;
6001 typedef struct _tagTT_TABLE_DIRECTORY{
6002 char szTag[4]; /* table name */
6003 ULONG uCheckSum; /* Check sum */
6004 ULONG uOffset; /* Offset from beginning of file */
6005 ULONG uLength; /* length of the table in bytes */
6006 }TT_TABLE_DIRECTORY;
6008 typedef struct _tagTT_NAME_TABLE_HEADER{
6009 USHORT uFSelector; /* format selector. Always 0 */
6010 USHORT uNRCount; /* Name Records count */
6011 USHORT uStorageOffset; /* Offset for strings storage,
6012 * from start of the table */
6013 }TT_NAME_TABLE_HEADER;
6015 typedef struct _tagTT_NAME_RECORD{
6016 USHORT uPlatformID;
6017 USHORT uEncodingID;
6018 USHORT uLanguageID;
6019 USHORT uNameID;
6020 USHORT uStringLength;
6021 USHORT uStringOffset; /* from start of storage area */
6022 }TT_NAME_RECORD;
6024 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
6025 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
6027 handle = CreateFileW(filename ,GENERIC_READ, 0, NULL, OPEN_EXISTING,
6028 FILE_ATTRIBUTE_NORMAL, 0 );
6029 if (handle != INVALID_HANDLE_VALUE)
6031 TT_TABLE_DIRECTORY tblDir;
6032 BOOL bFound = FALSE;
6033 TT_OFFSET_TABLE ttOffsetTable;
6035 ReadFile(handle,&ttOffsetTable, sizeof(TT_OFFSET_TABLE),NULL,NULL);
6036 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
6037 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
6038 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
6040 if (ttOffsetTable.uMajorVersion != 1 ||
6041 ttOffsetTable.uMinorVersion != 0)
6042 return NULL;
6044 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
6046 ReadFile(handle,&tblDir, sizeof(TT_TABLE_DIRECTORY),NULL,NULL);
6047 if (strncmp(tblDir.szTag,"name",4)==0)
6049 bFound = TRUE;
6050 tblDir.uLength = SWAPLONG(tblDir.uLength);
6051 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
6052 break;
6056 if (bFound)
6058 TT_NAME_TABLE_HEADER ttNTHeader;
6059 TT_NAME_RECORD ttRecord;
6061 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
6062 ReadFile(handle,&ttNTHeader, sizeof(TT_NAME_TABLE_HEADER),
6063 NULL,NULL);
6065 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
6066 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
6067 bFound = FALSE;
6068 for(i=0; i<ttNTHeader.uNRCount; i++)
6070 ReadFile(handle,&ttRecord, sizeof(TT_NAME_RECORD),NULL,NULL);
6071 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
6072 /* 4 is the Full Font Name */
6073 if(ttRecord.uNameID == 4)
6075 int nPos;
6076 LPSTR buf;
6077 static const LPSTR tt = " (TrueType)";
6079 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
6080 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
6081 nPos = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
6082 SetFilePointer(handle, tblDir.uOffset +
6083 ttRecord.uStringOffset +
6084 ttNTHeader.uStorageOffset,
6085 NULL, FILE_BEGIN);
6086 buf = HeapAlloc(GetProcessHeap(), 0,
6087 ttRecord.uStringLength + 1 + strlen(tt));
6088 memset(buf, 0, ttRecord.uStringLength + 1 + strlen(tt));
6089 ReadFile(handle, buf, ttRecord.uStringLength, NULL, NULL);
6090 if (strlen(buf) > 0)
6092 strcat(buf,tt);
6093 ret = strdupAtoW(buf);
6094 HeapFree(GetProcessHeap(),0,buf);
6095 break;
6098 HeapFree(GetProcessHeap(),0,buf);
6099 SetFilePointer(handle,nPos, NULL, FILE_BEGIN);
6103 CloseHandle(handle);
6106 TRACE("Returning fontname %s\n",debugstr_w(ret));
6107 return ret;
6110 static UINT ACTION_RegisterFonts(MSIPACKAGE *package)
6112 UINT rc;
6113 MSIQUERY * view;
6114 MSIRECORD * row = 0;
6115 static const WCHAR ExecSeqQuery[] =
6116 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6117 'F','o','n','t',0};
6118 static const WCHAR regfont1[] =
6119 {'S','o','f','t','w','a','r','e','\\',
6120 'M','i','c','r','o','s','o','f','t','\\',
6121 'W','i','n','d','o','w','s',' ','N','T','\\',
6122 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6123 'F','o','n','t','s',0};
6124 static const WCHAR regfont2[] =
6125 {'S','o','f','t','w','a','r','e','\\',
6126 'M','i','c','r','o','s','o','f','t','\\',
6127 'W','i','n','d','o','w','s','\\',
6128 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6129 'F','o','n','t','s',0};
6130 HKEY hkey1;
6131 HKEY hkey2;
6133 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6134 if (rc != ERROR_SUCCESS)
6135 return rc;
6137 rc = MSI_ViewExecute(view, 0);
6138 if (rc != ERROR_SUCCESS)
6140 MSI_ViewClose(view);
6141 msiobj_release(&view->hdr);
6142 return rc;
6145 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont1,&hkey1);
6146 RegCreateKeyW(HKEY_LOCAL_MACHINE,regfont2,&hkey2);
6148 while (1)
6150 LPWSTR name;
6151 LPWSTR file;
6152 UINT index;
6153 DWORD size;
6155 rc = MSI_ViewFetch(view,&row);
6156 if (rc != ERROR_SUCCESS)
6158 rc = ERROR_SUCCESS;
6159 break;
6162 file = load_dynamic_stringW(row,1);
6163 index = get_loaded_file(package,file);
6164 if (index < 0)
6166 ERR("Unable to load file\n");
6167 HeapFree(GetProcessHeap(),0,file);
6168 continue;
6171 /* check to make sure that component is installed */
6172 if (!ACTION_VerifyComponentForAction(package,
6173 package->files[index].ComponentIndex, INSTALLSTATE_LOCAL))
6175 TRACE("Skipping: Component not scheduled for install\n");
6176 HeapFree(GetProcessHeap(),0,file);
6178 msiobj_release(&row->hdr);
6180 continue;
6183 if (MSI_RecordIsNull(row,2))
6184 name = load_ttfname_from(package->files[index].TargetPath);
6185 else
6186 name = load_dynamic_stringW(row,2);
6188 if (name)
6190 size = strlenW(package->files[index].FileName) * sizeof(WCHAR);
6191 RegSetValueExW(hkey1,name,0,REG_SZ,
6192 (LPBYTE)package->files[index].FileName,size);
6193 RegSetValueExW(hkey2,name,0,REG_SZ,
6194 (LPBYTE)package->files[index].FileName,size);
6197 HeapFree(GetProcessHeap(),0,file);
6198 HeapFree(GetProcessHeap(),0,name);
6199 msiobj_release(&row->hdr);
6201 MSI_ViewClose(view);
6202 msiobj_release(&view->hdr);
6204 RegCloseKey(hkey1);
6205 RegCloseKey(hkey2);
6207 return rc;
6210 /* Msi functions that seem appropriate here */
6211 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
6213 LPWSTR szwAction;
6214 UINT rc;
6216 TRACE(" exteral attempt at action %s\n",szAction);
6218 if (!szAction)
6219 return ERROR_FUNCTION_FAILED;
6220 if (hInstall == 0)
6221 return ERROR_FUNCTION_FAILED;
6223 szwAction = strdupAtoW(szAction);
6225 if (!szwAction)
6226 return ERROR_FUNCTION_FAILED;
6229 rc = MsiDoActionW(hInstall, szwAction);
6230 HeapFree(GetProcessHeap(),0,szwAction);
6231 return rc;
6234 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
6236 MSIPACKAGE *package;
6237 UINT ret = ERROR_INVALID_HANDLE;
6239 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
6241 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6242 if( package )
6244 ret = ACTION_PerformUIAction(package,szAction);
6245 msiobj_release( &package->hdr );
6247 return ret;
6250 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
6251 LPSTR szPathBuf, DWORD* pcchPathBuf)
6253 LPWSTR szwFolder;
6254 LPWSTR szwPathBuf;
6255 UINT rc;
6257 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
6259 if (!szFolder)
6260 return ERROR_FUNCTION_FAILED;
6261 if (hInstall == 0)
6262 return ERROR_FUNCTION_FAILED;
6264 szwFolder = strdupAtoW(szFolder);
6266 if (!szwFolder)
6267 return ERROR_FUNCTION_FAILED;
6269 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
6271 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
6273 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
6274 *pcchPathBuf, NULL, NULL );
6276 HeapFree(GetProcessHeap(),0,szwFolder);
6277 HeapFree(GetProcessHeap(),0,szwPathBuf);
6279 return rc;
6282 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
6283 szPathBuf, DWORD* pcchPathBuf)
6285 LPWSTR path;
6286 UINT rc = ERROR_FUNCTION_FAILED;
6287 MSIPACKAGE *package;
6289 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
6291 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6292 if (!package)
6293 return ERROR_INVALID_HANDLE;
6294 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
6295 msiobj_release( &package->hdr );
6297 if (path && (strlenW(path) > *pcchPathBuf))
6299 *pcchPathBuf = strlenW(path)+1;
6300 rc = ERROR_MORE_DATA;
6302 else if (path)
6304 *pcchPathBuf = strlenW(path)+1;
6305 strcpyW(szPathBuf,path);
6306 TRACE("Returning Path %s\n",debugstr_w(path));
6307 rc = ERROR_SUCCESS;
6309 HeapFree(GetProcessHeap(),0,path);
6311 return rc;
6315 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
6316 LPSTR szPathBuf, DWORD* pcchPathBuf)
6318 LPWSTR szwFolder;
6319 LPWSTR szwPathBuf;
6320 UINT rc;
6322 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
6324 if (!szFolder)
6325 return ERROR_FUNCTION_FAILED;
6326 if (hInstall == 0)
6327 return ERROR_FUNCTION_FAILED;
6329 szwFolder = strdupAtoW(szFolder);
6330 if (!szwFolder)
6331 return ERROR_FUNCTION_FAILED;
6333 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
6335 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
6337 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
6338 *pcchPathBuf, NULL, NULL );
6340 HeapFree(GetProcessHeap(),0,szwFolder);
6341 HeapFree(GetProcessHeap(),0,szwPathBuf);
6343 return rc;
6346 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
6347 szPathBuf, DWORD* pcchPathBuf)
6349 LPWSTR path;
6350 UINT rc = ERROR_FUNCTION_FAILED;
6351 MSIPACKAGE *package;
6353 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
6355 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6356 if( !package )
6357 return ERROR_INVALID_HANDLE;
6358 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
6359 msiobj_release( &package->hdr );
6361 if (path && strlenW(path) > *pcchPathBuf)
6363 *pcchPathBuf = strlenW(path)+1;
6364 rc = ERROR_MORE_DATA;
6366 else if (path)
6368 *pcchPathBuf = strlenW(path)+1;
6369 strcpyW(szPathBuf,path);
6370 TRACE("Returning Path %s\n",debugstr_w(path));
6371 rc = ERROR_SUCCESS;
6373 HeapFree(GetProcessHeap(),0,path);
6375 return rc;
6379 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
6380 LPCSTR szFolderPath)
6382 LPWSTR szwFolder;
6383 LPWSTR szwFolderPath;
6384 UINT rc;
6386 if (!szFolder)
6387 return ERROR_FUNCTION_FAILED;
6388 if (hInstall == 0)
6389 return ERROR_FUNCTION_FAILED;
6391 szwFolder = strdupAtoW(szFolder);
6392 if (!szwFolder)
6393 return ERROR_FUNCTION_FAILED;
6395 szwFolderPath = strdupAtoW(szFolderPath);
6396 if (!szwFolderPath)
6398 HeapFree(GetProcessHeap(),0,szwFolder);
6399 return ERROR_FUNCTION_FAILED;
6402 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
6404 HeapFree(GetProcessHeap(),0,szwFolder);
6405 HeapFree(GetProcessHeap(),0,szwFolderPath);
6407 return rc;
6410 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
6411 LPCWSTR szFolderPath)
6413 DWORD i;
6414 LPWSTR path = NULL;
6415 LPWSTR path2 = NULL;
6416 MSIFOLDER *folder;
6418 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
6420 if (package==NULL)
6421 return ERROR_INVALID_HANDLE;
6423 if (szFolderPath[0]==0)
6424 return ERROR_FUNCTION_FAILED;
6426 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
6427 return ERROR_FUNCTION_FAILED;
6429 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
6431 if (!path)
6432 return ERROR_INVALID_PARAMETER;
6434 HeapFree(GetProcessHeap(),0,folder->Property);
6435 folder->Property = build_directory_name(2, szFolderPath, NULL);
6437 if (strcmpiW(path, folder->Property) == 0)
6440 * Resolved Target has not really changed, so just
6441 * set this folder and do not recalculate everything.
6443 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
6444 folder->ResolvedTarget = NULL;
6445 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
6446 HeapFree(GetProcessHeap(),0,path2);
6448 else
6450 for (i = 0; i < package->loaded_folders; i++)
6452 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
6453 package->folders[i].ResolvedTarget=NULL;
6456 for (i = 0; i < package->loaded_folders; i++)
6458 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
6459 TRUE, NULL);
6460 HeapFree(GetProcessHeap(),0,path2);
6463 HeapFree(GetProcessHeap(),0,path);
6465 return ERROR_SUCCESS;
6468 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
6469 LPCWSTR szFolderPath)
6471 MSIPACKAGE *package;
6472 UINT ret;
6474 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
6476 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6477 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
6478 msiobj_release( &package->hdr );
6479 return ret;
6482 /***********************************************************************
6483 * MsiGetMode (MSI.@)
6485 * Returns an internal installer state (if it is running in a mode iRunMode)
6487 * PARAMS
6488 * hInstall [I] Handle to the installation
6489 * hRunMode [I] Checking run mode
6490 * MSIRUNMODE_ADMIN Administrative mode
6491 * MSIRUNMODE_ADVERTISE Advertisement mode
6492 * MSIRUNMODE_MAINTENANCE Maintenance mode
6493 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
6494 * MSIRUNMODE_LOGENABLED Log file is writing
6495 * MSIRUNMODE_OPERATIONS Operations in progress??
6496 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
6497 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
6498 * MSIRUNMODE_CABINET Files from cabinet are installed
6499 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
6500 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
6501 * MSIRUNMODE_RESERVED11 Reserved
6502 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
6503 * MSIRUNMODE_ZAWENABLED Demand installation is supported
6504 * MSIRUNMODE_RESERVED14 Reserved
6505 * MSIRUNMODE_RESERVED15 Reserved
6506 * MSIRUNMODE_SCHEDULED called from install script
6507 * MSIRUNMODE_ROLLBACK called from rollback script
6508 * MSIRUNMODE_COMMIT called from commit script
6510 * RETURNS
6511 * In the state: TRUE
6512 * Not in the state: FALSE
6516 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
6518 FIXME("STUB (iRunMode=%i)\n",iRunMode);
6519 return TRUE;
6523 * According to the docs, when this is called it immediately recalculates
6524 * all the component states as well
6526 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
6527 INSTALLSTATE iState)
6529 LPWSTR szwFeature = NULL;
6530 UINT rc;
6532 szwFeature = strdupAtoW(szFeature);
6534 if (!szwFeature)
6535 return ERROR_FUNCTION_FAILED;
6537 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
6539 HeapFree(GetProcessHeap(),0,szwFeature);
6541 return rc;
6544 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
6545 INSTALLSTATE iState)
6547 MSIPACKAGE* package;
6548 INT index;
6550 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
6552 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6553 if (!package)
6554 return ERROR_INVALID_HANDLE;
6556 index = get_loaded_feature(package,szFeature);
6557 if (index < 0)
6558 return ERROR_UNKNOWN_FEATURE;
6560 package->features[index].ActionRequest= iState;
6561 ACTION_UpdateComponentStates(package,szFeature);
6563 return ERROR_SUCCESS;
6566 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
6567 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6569 LPWSTR szwFeature = NULL;
6570 UINT rc;
6572 szwFeature = strdupAtoW(szFeature);
6574 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
6576 HeapFree( GetProcessHeap(), 0 , szwFeature);
6578 return rc;
6581 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
6582 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6584 INT index;
6586 index = get_loaded_feature(package,szFeature);
6587 if (index < 0)
6588 return ERROR_UNKNOWN_FEATURE;
6590 if (piInstalled)
6591 *piInstalled = package->features[index].Installed;
6593 if (piAction)
6594 *piAction = package->features[index].Action;
6596 TRACE("returning %i %i\n",*piInstalled,*piAction);
6598 return ERROR_SUCCESS;
6601 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
6602 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6604 MSIPACKAGE* package;
6605 UINT ret;
6607 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
6608 piAction);
6610 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6611 if (!package)
6612 return ERROR_INVALID_HANDLE;
6613 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
6614 msiobj_release( &package->hdr );
6615 return ret;
6618 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
6619 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6621 LPWSTR szwComponent= NULL;
6622 UINT rc;
6624 szwComponent= strdupAtoW(szComponent);
6626 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
6628 HeapFree( GetProcessHeap(), 0 , szwComponent);
6630 return rc;
6633 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
6634 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6636 INT index;
6638 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
6639 piAction);
6641 index = get_loaded_component(package,szComponent);
6642 if (index < 0)
6643 return ERROR_UNKNOWN_COMPONENT;
6645 if (piInstalled)
6646 *piInstalled = package->components[index].Installed;
6648 if (piAction)
6649 *piAction = package->components[index].Action;
6651 TRACE("states (%i, %i)\n",
6652 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
6654 return ERROR_SUCCESS;
6657 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
6658 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
6660 MSIPACKAGE* package;
6661 UINT ret;
6663 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
6664 piInstalled, piAction);
6666 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
6667 if (!package)
6668 return ERROR_INVALID_HANDLE;
6669 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
6670 msiobj_release( &package->hdr );
6671 return ret;
6674 #if 0
6675 static UINT ACTION_Template(MSIPACKAGE *package)
6677 UINT rc;
6678 MSIQUERY * view;
6679 MSIRECORD * row = 0;
6680 static const WCHAR ExecSeqQuery[] = {0};
6682 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
6683 if (rc != ERROR_SUCCESS)
6684 return rc;
6686 rc = MSI_ViewExecute(view, 0);
6687 if (rc != ERROR_SUCCESS)
6689 MSI_ViewClose(view);
6690 msiobj_release(&view->hdr);
6691 return rc;
6694 while (1)
6696 rc = MSI_ViewFetch(view,&row);
6697 if (rc != ERROR_SUCCESS)
6699 rc = ERROR_SUCCESS;
6700 break;
6703 msiobj_release(&row->hdr);
6705 MSI_ViewClose(view);
6706 msiobj_release(&view->hdr);
6707 return rc;
6709 #endif