msi: Fix the ProcessComponents action to handle the package context.
[wine.git] / dlls / msi / action.c
blob30bb7cf3cad7e014594a445680e2f390fdcf70da
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004,2005 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winreg.h"
29 #include "winsvc.h"
30 #include "odbcinst.h"
31 #include "wine/debug.h"
32 #include "msidefs.h"
33 #include "msipriv.h"
34 #include "winuser.h"
35 #include "shlobj.h"
36 #include "objbase.h"
37 #include "mscoree.h"
38 #include "fusion.h"
39 #include "shlwapi.h"
40 #include "wine/unicode.h"
41 #include "winver.h"
43 #define REG_PROGRESS_VALUE 13200
44 #define COMPONENT_PROGRESS_VALUE 24000
46 WINE_DEFAULT_DEBUG_CHANNEL(msi);
49 * Prototypes
51 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
52 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
53 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI);
54 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action, UINT* rc, BOOL force);
57 * consts and values used
59 static const WCHAR c_colon[] = {'C',':','\\',0};
61 static const WCHAR szCreateFolders[] =
62 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
63 static const WCHAR szCostFinalize[] =
64 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
65 const WCHAR szInstallFiles[] =
66 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
67 const WCHAR szDuplicateFiles[] =
68 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
69 static const WCHAR szWriteRegistryValues[] =
70 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
71 'V','a','l','u','e','s',0};
72 static const WCHAR szCostInitialize[] =
73 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
74 static const WCHAR szFileCost[] =
75 {'F','i','l','e','C','o','s','t',0};
76 static const WCHAR szInstallInitialize[] =
77 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
78 static const WCHAR szInstallValidate[] =
79 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
80 static const WCHAR szLaunchConditions[] =
81 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
82 static const WCHAR szProcessComponents[] =
83 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
84 static const WCHAR szRegisterTypeLibraries[] =
85 {'R','e','g','i','s','t','e','r','T','y','p','e',
86 'L','i','b','r','a','r','i','e','s',0};
87 const WCHAR szRegisterClassInfo[] =
88 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
89 const WCHAR szRegisterProgIdInfo[] =
90 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
91 static const WCHAR szCreateShortcuts[] =
92 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
93 static const WCHAR szPublishProduct[] =
94 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
95 static const WCHAR szWriteIniValues[] =
96 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
97 static const WCHAR szSelfRegModules[] =
98 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
99 static const WCHAR szPublishFeatures[] =
100 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
101 static const WCHAR szRegisterProduct[] =
102 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
103 static const WCHAR szInstallExecute[] =
104 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
105 static const WCHAR szInstallExecuteAgain[] =
106 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
107 'A','g','a','i','n',0};
108 static const WCHAR szInstallFinalize[] =
109 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
110 static const WCHAR szForceReboot[] =
111 {'F','o','r','c','e','R','e','b','o','o','t',0};
112 static const WCHAR szResolveSource[] =
113 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
114 static const WCHAR szAppSearch[] =
115 {'A','p','p','S','e','a','r','c','h',0};
116 static const WCHAR szAllocateRegistrySpace[] =
117 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
118 'S','p','a','c','e',0};
119 static const WCHAR szBindImage[] =
120 {'B','i','n','d','I','m','a','g','e',0};
121 static const WCHAR szCCPSearch[] =
122 {'C','C','P','S','e','a','r','c','h',0};
123 static const WCHAR szDeleteServices[] =
124 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
125 static const WCHAR szDisableRollback[] =
126 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
127 static const WCHAR szExecuteAction[] =
128 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
129 const WCHAR szFindRelatedProducts[] =
130 {'F','i','n','d','R','e','l','a','t','e','d',
131 'P','r','o','d','u','c','t','s',0};
132 static const WCHAR szInstallAdminPackage[] =
133 {'I','n','s','t','a','l','l','A','d','m','i','n',
134 'P','a','c','k','a','g','e',0};
135 static const WCHAR szInstallSFPCatalogFile[] =
136 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
137 'F','i','l','e',0};
138 static const WCHAR szIsolateComponents[] =
139 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
140 const WCHAR szMigrateFeatureStates[] =
141 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
142 'S','t','a','t','e','s',0};
143 const WCHAR szMoveFiles[] =
144 {'M','o','v','e','F','i','l','e','s',0};
145 static const WCHAR szMsiPublishAssemblies[] =
146 {'M','s','i','P','u','b','l','i','s','h',
147 'A','s','s','e','m','b','l','i','e','s',0};
148 static const WCHAR szMsiUnpublishAssemblies[] =
149 {'M','s','i','U','n','p','u','b','l','i','s','h',
150 'A','s','s','e','m','b','l','i','e','s',0};
151 static const WCHAR szInstallODBC[] =
152 {'I','n','s','t','a','l','l','O','D','B','C',0};
153 static const WCHAR szInstallServices[] =
154 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
155 const WCHAR szPatchFiles[] =
156 {'P','a','t','c','h','F','i','l','e','s',0};
157 static const WCHAR szPublishComponents[] =
158 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
159 static const WCHAR szRegisterComPlus[] =
160 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
161 const WCHAR szRegisterExtensionInfo[] =
162 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
163 'I','n','f','o',0};
164 static const WCHAR szRegisterFonts[] =
165 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
166 const WCHAR szRegisterMIMEInfo[] =
167 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
168 static const WCHAR szRegisterUser[] =
169 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
170 const WCHAR szRemoveDuplicateFiles[] =
171 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
172 'F','i','l','e','s',0};
173 static const WCHAR szRemoveEnvironmentStrings[] =
174 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
175 'S','t','r','i','n','g','s',0};
176 const WCHAR szRemoveExistingProducts[] =
177 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
178 'P','r','o','d','u','c','t','s',0};
179 const WCHAR szRemoveFiles[] =
180 {'R','e','m','o','v','e','F','i','l','e','s',0};
181 static const WCHAR szRemoveFolders[] =
182 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
183 static const WCHAR szRemoveIniValues[] =
184 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
185 static const WCHAR szRemoveODBC[] =
186 {'R','e','m','o','v','e','O','D','B','C',0};
187 static const WCHAR szRemoveRegistryValues[] =
188 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
189 'V','a','l','u','e','s',0};
190 static const WCHAR szRemoveShortcuts[] =
191 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
192 static const WCHAR szRMCCPSearch[] =
193 {'R','M','C','C','P','S','e','a','r','c','h',0};
194 static const WCHAR szScheduleReboot[] =
195 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
196 static const WCHAR szSelfUnregModules[] =
197 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
198 static const WCHAR szSetODBCFolders[] =
199 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
200 static const WCHAR szStartServices[] =
201 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
202 static const WCHAR szStopServices[] =
203 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
204 static const WCHAR szUnpublishComponents[] =
205 {'U','n','p','u','b','l','i','s','h',
206 'C','o','m','p','o','n','e','n','t','s',0};
207 static const WCHAR szUnpublishFeatures[] =
208 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
209 const WCHAR szUnregisterClassInfo[] =
210 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
211 'I','n','f','o',0};
212 static const WCHAR szUnregisterComPlus[] =
213 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
214 const WCHAR szUnregisterExtensionInfo[] =
215 {'U','n','r','e','g','i','s','t','e','r',
216 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
217 static const WCHAR szUnregisterFonts[] =
218 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
219 const WCHAR szUnregisterMIMEInfo[] =
220 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
221 const WCHAR szUnregisterProgIdInfo[] =
222 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
223 'I','n','f','o',0};
224 static const WCHAR szUnregisterTypeLibraries[] =
225 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
226 'L','i','b','r','a','r','i','e','s',0};
227 static const WCHAR szValidateProductID[] =
228 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
229 static const WCHAR szWriteEnvironmentStrings[] =
230 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
231 'S','t','r','i','n','g','s',0};
233 /* action handlers */
234 typedef UINT (*STANDARDACTIONHANDLER)(MSIPACKAGE*);
236 struct _actions {
237 LPCWSTR action;
238 STANDARDACTIONHANDLER handler;
242 /********************************************************
243 * helper functions
244 ********************************************************/
246 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
248 static const WCHAR Query_t[] =
249 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
250 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
251 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
252 ' ','\'','%','s','\'',0};
253 MSIRECORD * row;
255 row = MSI_QueryGetRecord( package->db, Query_t, action );
256 if (!row)
257 return;
258 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
259 msiobj_release(&row->hdr);
262 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
263 UINT rc)
265 MSIRECORD * row;
266 static const WCHAR template_s[]=
267 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
268 '%','s', '.',0};
269 static const WCHAR template_e[]=
270 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
271 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
272 '%','i','.',0};
273 static const WCHAR format[] =
274 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
275 WCHAR message[1024];
276 WCHAR timet[0x100];
278 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
279 if (start)
280 sprintfW(message,template_s,timet,action);
281 else
282 sprintfW(message,template_e,timet,action,rc);
284 row = MSI_CreateRecord(1);
285 MSI_RecordSetStringW(row,1,message);
287 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
288 msiobj_release(&row->hdr);
291 UINT msi_parse_command_line( MSIPACKAGE *package, LPCWSTR szCommandLine )
293 LPCWSTR ptr,ptr2;
294 BOOL quote;
295 DWORD len;
296 LPWSTR prop = NULL, val = NULL;
298 if (!szCommandLine)
299 return ERROR_SUCCESS;
301 ptr = szCommandLine;
303 while (*ptr)
305 if (*ptr==' ')
307 ptr++;
308 continue;
311 TRACE("Looking at %s\n",debugstr_w(ptr));
313 ptr2 = strchrW(ptr,'=');
314 if (!ptr2)
316 ERR("command line contains unknown string : %s\n", debugstr_w(ptr));
317 break;
320 quote = FALSE;
322 len = ptr2-ptr;
323 prop = msi_alloc((len+1)*sizeof(WCHAR));
324 memcpy(prop,ptr,len*sizeof(WCHAR));
325 prop[len]=0;
326 ptr2++;
328 len = 0;
329 ptr = ptr2;
330 while (*ptr && (quote || (!quote && *ptr!=' ')))
332 if (*ptr == '"')
333 quote = !quote;
334 ptr++;
335 len++;
338 if (*ptr2=='"')
340 ptr2++;
341 len -= 2;
343 val = msi_alloc((len+1)*sizeof(WCHAR));
344 memcpy(val,ptr2,len*sizeof(WCHAR));
345 val[len] = 0;
347 if (lstrlenW(prop) > 0)
349 TRACE("Found commandline property (%s) = (%s)\n",
350 debugstr_w(prop), debugstr_w(val));
351 MSI_SetPropertyW(package,prop,val);
353 msi_free(val);
354 msi_free(prop);
357 return ERROR_SUCCESS;
361 static LPWSTR* msi_split_string( LPCWSTR str, WCHAR sep )
363 LPCWSTR pc;
364 LPWSTR p, *ret = NULL;
365 UINT count = 0;
367 if (!str)
368 return ret;
370 /* count the number of substrings */
371 for ( pc = str, count = 0; pc; count++ )
373 pc = strchrW( pc, sep );
374 if (pc)
375 pc++;
378 /* allocate space for an array of substring pointers and the substrings */
379 ret = msi_alloc( (count+1) * sizeof (LPWSTR) +
380 (lstrlenW(str)+1) * sizeof(WCHAR) );
381 if (!ret)
382 return ret;
384 /* copy the string and set the pointers */
385 p = (LPWSTR) &ret[count+1];
386 lstrcpyW( p, str );
387 for( count = 0; (ret[count] = p); count++ )
389 p = strchrW( p, sep );
390 if (p)
391 *p++ = 0;
394 return ret;
397 static UINT msi_check_transform_applicable( MSIPACKAGE *package, IStorage *patch )
399 WCHAR szProductCode[] = { 'P','r','o','d','u','c','t','C','o','d','e',0 };
400 LPWSTR prod_code, patch_product;
401 UINT ret;
403 prod_code = msi_dup_property( package, szProductCode );
404 patch_product = msi_get_suminfo_product( patch );
406 TRACE("db = %s patch = %s\n", debugstr_w(prod_code), debugstr_w(patch_product));
408 if ( strstrW( patch_product, prod_code ) )
409 ret = ERROR_SUCCESS;
410 else
411 ret = ERROR_FUNCTION_FAILED;
413 msi_free( patch_product );
414 msi_free( prod_code );
416 return ret;
419 static UINT msi_apply_substorage_transform( MSIPACKAGE *package,
420 MSIDATABASE *patch_db, LPCWSTR name )
422 UINT ret = ERROR_FUNCTION_FAILED;
423 IStorage *stg = NULL;
424 HRESULT r;
426 TRACE("%p %s\n", package, debugstr_w(name) );
428 if (*name++ != ':')
430 ERR("expected a colon in %s\n", debugstr_w(name));
431 return ERROR_FUNCTION_FAILED;
434 r = IStorage_OpenStorage( patch_db->storage, name, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &stg );
435 if (SUCCEEDED(r))
437 ret = msi_check_transform_applicable( package, stg );
438 if (ret == ERROR_SUCCESS)
439 msi_table_apply_transform( package->db, stg );
440 else
441 TRACE("substorage transform %s wasn't applicable\n", debugstr_w(name));
442 IStorage_Release( stg );
444 else
445 ERR("failed to open substorage %s\n", debugstr_w(name));
447 return ERROR_SUCCESS;
450 static UINT msi_check_patch_applicable( MSIPACKAGE *package, MSISUMMARYINFO *si )
452 static const WCHAR szProdCode[] = { 'P','r','o','d','u','c','t','C','o','d','e',0 };
453 LPWSTR guid_list, *guids, product_code;
454 UINT i, ret = ERROR_FUNCTION_FAILED;
456 product_code = msi_dup_property( package, szProdCode );
457 if (!product_code)
459 /* FIXME: the property ProductCode should be written into the DB somewhere */
460 ERR("no product code to check\n");
461 return ERROR_SUCCESS;
464 guid_list = msi_suminfo_dup_string( si, PID_TEMPLATE );
465 guids = msi_split_string( guid_list, ';' );
466 for ( i = 0; guids[i] && ret != ERROR_SUCCESS; i++ )
468 if (!lstrcmpW( guids[i], product_code ))
469 ret = ERROR_SUCCESS;
471 msi_free( guids );
472 msi_free( guid_list );
473 msi_free( product_code );
475 return ret;
478 static UINT msi_parse_patch_summary( MSIPACKAGE *package, MSIDATABASE *patch_db )
480 MSISUMMARYINFO *si;
481 LPWSTR str, *substorage;
482 UINT i, r = ERROR_SUCCESS;
484 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
485 if (!si)
486 return ERROR_FUNCTION_FAILED;
488 msi_check_patch_applicable( package, si );
490 /* enumerate the substorage */
491 str = msi_suminfo_dup_string( si, PID_LASTAUTHOR );
492 substorage = msi_split_string( str, ';' );
493 for ( i = 0; substorage && substorage[i] && r == ERROR_SUCCESS; i++ )
494 r = msi_apply_substorage_transform( package, patch_db, substorage[i] );
495 msi_free( substorage );
496 msi_free( str );
498 /* FIXME: parse the sources in PID_REVNUMBER and do something with them... */
500 msiobj_release( &si->hdr );
502 return r;
505 static UINT msi_apply_patch_package( MSIPACKAGE *package, LPCWSTR file )
507 MSIDATABASE *patch_db = NULL;
508 UINT r;
510 TRACE("%p %s\n", package, debugstr_w( file ) );
512 /* FIXME:
513 * We probably want to make sure we only open a patch collection here.
514 * Patch collections (.msp) and databases (.msi) have different GUIDs
515 * but currently MSI_OpenDatabaseW will accept both.
517 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &patch_db );
518 if ( r != ERROR_SUCCESS )
520 ERR("failed to open patch collection %s\n", debugstr_w( file ) );
521 return r;
524 msi_parse_patch_summary( package, patch_db );
527 * There might be a CAB file in the patch package,
528 * so append it to the list of storage to search for streams.
530 append_storage_to_db( package->db, patch_db->storage );
532 msiobj_release( &patch_db->hdr );
534 return ERROR_SUCCESS;
537 /* get the PATCH property, and apply all the patches it specifies */
538 static UINT msi_apply_patches( MSIPACKAGE *package )
540 static const WCHAR szPatch[] = { 'P','A','T','C','H',0 };
541 LPWSTR patch_list, *patches;
542 UINT i, r = ERROR_SUCCESS;
544 patch_list = msi_dup_property( package, szPatch );
546 TRACE("patches to be applied: %s\n", debugstr_w( patch_list ) );
548 patches = msi_split_string( patch_list, ';' );
549 for( i=0; patches && patches[i] && r == ERROR_SUCCESS; i++ )
550 r = msi_apply_patch_package( package, patches[i] );
552 msi_free( patches );
553 msi_free( patch_list );
555 return r;
558 static UINT msi_apply_transforms( MSIPACKAGE *package )
560 static const WCHAR szTransforms[] = {
561 'T','R','A','N','S','F','O','R','M','S',0 };
562 LPWSTR xform_list, *xforms;
563 UINT i, r = ERROR_SUCCESS;
565 xform_list = msi_dup_property( package, szTransforms );
566 xforms = msi_split_string( xform_list, ';' );
568 for( i=0; xforms && xforms[i] && r == ERROR_SUCCESS; i++ )
570 if (xforms[i][0] == ':')
571 r = msi_apply_substorage_transform( package, package->db, xforms[i] );
572 else
573 r = MSI_DatabaseApplyTransformW( package->db, xforms[i], 0 );
576 msi_free( xforms );
577 msi_free( xform_list );
579 return r;
582 static BOOL ui_sequence_exists( MSIPACKAGE *package )
584 MSIQUERY *view;
585 UINT rc;
587 static const WCHAR ExecSeqQuery [] =
588 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
589 '`','I','n','s','t','a','l','l',
590 'U','I','S','e','q','u','e','n','c','e','`',
591 ' ','W','H','E','R','E',' ',
592 '`','S','e','q','u','e','n','c','e','`',' ',
593 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
594 '`','S','e','q','u','e','n','c','e','`',0};
596 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
597 if (rc == ERROR_SUCCESS)
599 msiobj_release(&view->hdr);
600 return TRUE;
603 return FALSE;
606 static UINT msi_set_sourcedir_props(MSIPACKAGE *package, BOOL replace)
608 LPWSTR p, db;
609 LPWSTR source, check;
610 DWORD len;
612 static const WCHAR szOriginalDatabase[] =
613 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
615 db = msi_dup_property( package, szOriginalDatabase );
616 if (!db)
617 return ERROR_OUTOFMEMORY;
619 p = strrchrW( db, '\\' );
620 if (!p)
622 p = strrchrW( db, '/' );
623 if (!p)
625 msi_free(db);
626 return ERROR_SUCCESS;
630 len = p - db + 2;
631 source = msi_alloc( len * sizeof(WCHAR) );
632 lstrcpynW( source, db, len );
634 check = msi_dup_property( package, cszSourceDir );
635 if (!check || replace)
636 MSI_SetPropertyW( package, cszSourceDir, source );
638 msi_free( check );
640 check = msi_dup_property( package, cszSOURCEDIR );
641 if (!check || replace)
642 MSI_SetPropertyW( package, cszSOURCEDIR, source );
644 msi_free( check );
645 msi_free( source );
646 msi_free( db );
648 return ERROR_SUCCESS;
651 static UINT msi_set_context(MSIPACKAGE *package)
653 WCHAR val[10];
654 DWORD sz = 10;
655 DWORD num;
656 UINT r;
658 static const WCHAR szOne[] = {'1',0};
659 static const WCHAR szAllUsers[] = {'A','L','L','U','S','E','R','S',0};
661 package->Context = MSIINSTALLCONTEXT_USERUNMANAGED;
663 r = MSI_GetPropertyW(package, szAllUsers, val, &sz);
664 if (r == ERROR_SUCCESS)
666 num = atolW(val);
667 if (num == 1 || num == 2)
668 package->Context = MSIINSTALLCONTEXT_MACHINE;
671 MSI_SetPropertyW(package, szAllUsers, szOne);
672 return ERROR_SUCCESS;
675 /****************************************************
676 * TOP level entry points
677 *****************************************************/
679 UINT MSI_InstallPackage( MSIPACKAGE *package, LPCWSTR szPackagePath,
680 LPCWSTR szCommandLine )
682 UINT rc;
683 BOOL ui = FALSE, ui_exists;
684 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
685 static const WCHAR szAction[] = {'A','C','T','I','O','N',0};
686 static const WCHAR szInstall[] = {'I','N','S','T','A','L','L',0};
688 MSI_SetPropertyW(package, szAction, szInstall);
690 package->script = msi_alloc_zero(sizeof(MSISCRIPT));
692 package->script->InWhatSequence = SEQUENCE_INSTALL;
694 if (szPackagePath)
696 LPWSTR p, dir;
697 LPCWSTR file;
699 dir = strdupW(szPackagePath);
700 p = strrchrW(dir, '\\');
701 if (p)
703 *(++p) = 0;
704 file = szPackagePath + (p - dir);
706 else
708 msi_free(dir);
709 dir = msi_alloc(MAX_PATH*sizeof(WCHAR));
710 GetCurrentDirectoryW(MAX_PATH, dir);
711 lstrcatW(dir, cszbs);
712 file = szPackagePath;
715 msi_free( package->PackagePath );
716 package->PackagePath = msi_alloc((lstrlenW(dir) + lstrlenW(file) + 1) * sizeof(WCHAR));
717 if (!package->PackagePath)
719 msi_free(dir);
720 return ERROR_OUTOFMEMORY;
723 lstrcpyW(package->PackagePath, dir);
724 lstrcatW(package->PackagePath, file);
725 msi_free(dir);
727 msi_set_sourcedir_props(package, FALSE);
730 msi_parse_command_line( package, szCommandLine );
732 msi_apply_transforms( package );
733 msi_apply_patches( package );
735 /* properties may have been added by a transform */
736 msi_clone_properties( package );
737 msi_set_context( package );
739 if ( (msi_get_property_int(package, szUILevel, 0) & INSTALLUILEVEL_MASK) >= INSTALLUILEVEL_REDUCED )
741 package->script->InWhatSequence |= SEQUENCE_UI;
742 rc = ACTION_ProcessUISequence(package);
743 ui = TRUE;
744 ui_exists = ui_sequence_exists(package);
745 if (rc == ERROR_SUCCESS || !ui_exists)
747 package->script->InWhatSequence |= SEQUENCE_EXEC;
748 rc = ACTION_ProcessExecSequence(package,ui_exists);
751 else
752 rc = ACTION_ProcessExecSequence(package,FALSE);
754 package->script->CurrentlyScripting= FALSE;
756 /* process the ending type action */
757 if (rc == ERROR_SUCCESS)
758 ACTION_PerformActionSequence(package,-1,ui);
759 else if (rc == ERROR_INSTALL_USEREXIT)
760 ACTION_PerformActionSequence(package,-2,ui);
761 else if (rc == ERROR_INSTALL_SUSPEND)
762 ACTION_PerformActionSequence(package,-4,ui);
763 else /* failed */
764 ACTION_PerformActionSequence(package,-3,ui);
766 /* finish up running custom actions */
767 ACTION_FinishCustomActions(package);
769 return rc;
772 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq, BOOL UI)
774 UINT rc = ERROR_SUCCESS;
775 MSIRECORD * row = 0;
776 static const WCHAR ExecSeqQuery[] =
777 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
778 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
779 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
780 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
782 static const WCHAR UISeqQuery[] =
783 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
784 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
785 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
786 ' ', '=',' ','%','i',0};
788 if (UI)
789 row = MSI_QueryGetRecord(package->db, UISeqQuery, seq);
790 else
791 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, seq);
793 if (row)
795 LPCWSTR action, cond;
797 TRACE("Running the actions\n");
799 /* check conditions */
800 cond = MSI_RecordGetString(row,2);
802 /* this is a hack to skip errors in the condition code */
803 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
804 goto end;
806 action = MSI_RecordGetString(row,1);
807 if (!action)
809 ERR("failed to fetch action\n");
810 rc = ERROR_FUNCTION_FAILED;
811 goto end;
814 if (UI)
815 rc = ACTION_PerformUIAction(package,action,-1);
816 else
817 rc = ACTION_PerformAction(package,action,-1,FALSE);
818 end:
819 msiobj_release(&row->hdr);
821 else
822 rc = ERROR_SUCCESS;
824 return rc;
827 typedef struct {
828 MSIPACKAGE* package;
829 BOOL UI;
830 } iterate_action_param;
832 static UINT ITERATE_Actions(MSIRECORD *row, LPVOID param)
834 iterate_action_param *iap= (iterate_action_param*)param;
835 UINT rc;
836 LPCWSTR cond, action;
838 action = MSI_RecordGetString(row,1);
839 if (!action)
841 ERR("Error is retrieving action name\n");
842 return ERROR_FUNCTION_FAILED;
845 /* check conditions */
846 cond = MSI_RecordGetString(row,2);
848 /* this is a hack to skip errors in the condition code */
849 if (MSI_EvaluateConditionW(iap->package, cond) == MSICONDITION_FALSE)
851 TRACE("Skipping action: %s (condition is false)\n", debugstr_w(action));
852 return ERROR_SUCCESS;
855 if (iap->UI)
856 rc = ACTION_PerformUIAction(iap->package,action,-1);
857 else
858 rc = ACTION_PerformAction(iap->package,action,-1,FALSE);
860 msi_dialog_check_messages( NULL );
862 if (iap->package->CurrentInstallState != ERROR_SUCCESS )
863 rc = iap->package->CurrentInstallState;
865 if (rc == ERROR_FUNCTION_NOT_CALLED)
866 rc = ERROR_SUCCESS;
868 if (rc != ERROR_SUCCESS)
869 ERR("Execution halted, action %s returned %i\n", debugstr_w(action), rc);
871 return rc;
874 UINT MSI_Sequence( MSIPACKAGE *package, LPCWSTR szTable, INT iSequenceMode )
876 MSIQUERY * view;
877 UINT r;
878 static const WCHAR query[] =
879 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
880 '`','%','s','`',
881 ' ','W','H','E','R','E',' ',
882 '`','S','e','q','u','e','n','c','e','`',' ',
883 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
884 '`','S','e','q','u','e','n','c','e','`',0};
885 iterate_action_param iap;
888 * FIXME: probably should be checking UILevel in the
889 * ACTION_PerformUIAction/ACTION_PerformAction
890 * rather than saving the UI level here. Those
891 * two functions can be merged too.
893 iap.package = package;
894 iap.UI = TRUE;
896 TRACE("%p %s %i\n", package, debugstr_w(szTable), iSequenceMode );
898 r = MSI_OpenQuery( package->db, &view, query, szTable );
899 if (r == ERROR_SUCCESS)
901 r = MSI_IterateRecords( view, NULL, ITERATE_Actions, &iap );
902 msiobj_release(&view->hdr);
905 return r;
908 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
910 MSIQUERY * view;
911 UINT rc;
912 static const WCHAR ExecSeqQuery[] =
913 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
914 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
915 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
916 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
917 'O','R','D','E','R',' ', 'B','Y',' ',
918 '`','S','e','q','u','e','n','c','e','`',0 };
919 MSIRECORD * row = 0;
920 static const WCHAR IVQuery[] =
921 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
922 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
923 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
924 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
925 ' ','\'', 'I','n','s','t','a','l','l',
926 'V','a','l','i','d','a','t','e','\'', 0};
927 INT seq = 0;
928 iterate_action_param iap;
930 iap.package = package;
931 iap.UI = FALSE;
933 if (package->script->ExecuteSequenceRun)
935 TRACE("Execute Sequence already Run\n");
936 return ERROR_SUCCESS;
939 package->script->ExecuteSequenceRun = TRUE;
941 /* get the sequence number */
942 if (UIran)
944 row = MSI_QueryGetRecord(package->db, IVQuery);
945 if( !row )
946 return ERROR_FUNCTION_FAILED;
947 seq = MSI_RecordGetInteger(row,1);
948 msiobj_release(&row->hdr);
951 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, seq);
952 if (rc == ERROR_SUCCESS)
954 TRACE("Running the actions\n");
956 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
957 msiobj_release(&view->hdr);
960 return rc;
963 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
965 MSIQUERY * view;
966 UINT rc;
967 static const WCHAR ExecSeqQuery [] =
968 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
969 '`','I','n','s','t','a','l','l',
970 'U','I','S','e','q','u','e','n','c','e','`',
971 ' ','W','H','E','R','E',' ',
972 '`','S','e','q','u','e','n','c','e','`',' ',
973 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
974 '`','S','e','q','u','e','n','c','e','`',0};
975 iterate_action_param iap;
977 iap.package = package;
978 iap.UI = TRUE;
980 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
982 if (rc == ERROR_SUCCESS)
984 TRACE("Running the actions\n");
986 rc = MSI_IterateRecords(view, NULL, ITERATE_Actions, &iap);
987 msiobj_release(&view->hdr);
990 return rc;
993 /********************************************************
994 * ACTION helper functions and functions that perform the actions
995 *******************************************************/
996 static BOOL ACTION_HandleCustomAction( MSIPACKAGE* package, LPCWSTR action,
997 UINT* rc, UINT script, BOOL force )
999 BOOL ret=FALSE;
1000 UINT arc;
1002 arc = ACTION_CustomAction(package, action, script, force);
1004 if (arc != ERROR_CALL_NOT_IMPLEMENTED)
1006 *rc = arc;
1007 ret = TRUE;
1009 return ret;
1013 * A lot of actions are really important even if they don't do anything
1014 * explicit... Lots of properties are set at the beginning of the installation
1015 * CostFinalize does a bunch of work to translate the directories and such
1017 * But until I get write access to the database that is hard, so I am going to
1018 * hack it to see if I can get something to run.
1020 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, UINT script, BOOL force)
1022 UINT rc = ERROR_SUCCESS;
1023 BOOL handled;
1025 TRACE("Performing action (%s)\n",debugstr_w(action));
1027 handled = ACTION_HandleStandardAction(package, action, &rc, force);
1029 if (!handled)
1030 handled = ACTION_HandleCustomAction(package, action, &rc, script, force);
1032 if (!handled)
1034 WARN("unhandled msi action %s\n",debugstr_w(action));
1035 rc = ERROR_FUNCTION_NOT_CALLED;
1038 return rc;
1041 UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action, UINT script)
1043 UINT rc = ERROR_SUCCESS;
1044 BOOL handled = FALSE;
1046 TRACE("Performing action (%s)\n",debugstr_w(action));
1048 handled = ACTION_HandleStandardAction(package, action, &rc,TRUE);
1050 if (!handled)
1051 handled = ACTION_HandleCustomAction(package, action, &rc, script, FALSE);
1053 if( !handled && ACTION_DialogBox(package,action) == ERROR_SUCCESS )
1054 handled = TRUE;
1056 if (!handled)
1058 WARN("unhandled msi action %s\n",debugstr_w(action));
1059 rc = ERROR_FUNCTION_NOT_CALLED;
1062 return rc;
1067 * Actual Action Handlers
1070 static UINT ITERATE_CreateFolders(MSIRECORD *row, LPVOID param)
1072 MSIPACKAGE *package = (MSIPACKAGE*)param;
1073 LPCWSTR dir;
1074 LPWSTR full_path;
1075 MSIRECORD *uirow;
1076 MSIFOLDER *folder;
1078 dir = MSI_RecordGetString(row,1);
1079 if (!dir)
1081 ERR("Unable to get folder id\n");
1082 return ERROR_SUCCESS;
1085 full_path = resolve_folder(package,dir,FALSE,FALSE,TRUE,&folder);
1086 if (!full_path)
1088 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1089 return ERROR_SUCCESS;
1092 TRACE("Folder is %s\n",debugstr_w(full_path));
1094 /* UI stuff */
1095 uirow = MSI_CreateRecord(1);
1096 MSI_RecordSetStringW(uirow,1,full_path);
1097 ui_actiondata(package,szCreateFolders,uirow);
1098 msiobj_release( &uirow->hdr );
1100 if (folder->State == 0)
1101 create_full_pathW(full_path);
1103 folder->State = 3;
1105 msi_free(full_path);
1106 return ERROR_SUCCESS;
1109 /* FIXME: probably should merge this with the above function */
1110 static UINT msi_create_directory( MSIPACKAGE* package, LPCWSTR dir )
1112 UINT rc = ERROR_SUCCESS;
1113 MSIFOLDER *folder;
1114 LPWSTR install_path;
1116 install_path = resolve_folder(package, dir, FALSE, FALSE, TRUE, &folder);
1117 if (!install_path)
1118 return ERROR_FUNCTION_FAILED;
1120 /* create the path */
1121 if (folder->State == 0)
1123 create_full_pathW(install_path);
1124 folder->State = 2;
1126 msi_free(install_path);
1128 return rc;
1131 UINT msi_create_component_directories( MSIPACKAGE *package )
1133 MSICOMPONENT *comp;
1135 /* create all the folders required by the components are going to install */
1136 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1138 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL))
1139 continue;
1140 msi_create_directory( package, comp->Directory );
1143 return ERROR_SUCCESS;
1147 * Also we cannot enable/disable components either, so for now I am just going
1148 * to do all the directories for all the components.
1150 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1152 static const WCHAR ExecSeqQuery[] =
1153 {'S','E','L','E','C','T',' ',
1154 '`','D','i','r','e','c','t','o','r','y','_','`',
1155 ' ','F','R','O','M',' ',
1156 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
1157 UINT rc;
1158 MSIQUERY *view;
1160 /* create all the empty folders specified in the CreateFolder table */
1161 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1162 if (rc != ERROR_SUCCESS)
1163 return ERROR_SUCCESS;
1165 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateFolders, package);
1166 msiobj_release(&view->hdr);
1168 msi_create_component_directories( package );
1170 return rc;
1173 static UINT load_component( MSIRECORD *row, LPVOID param )
1175 MSIPACKAGE *package = param;
1176 MSICOMPONENT *comp;
1178 comp = msi_alloc_zero( sizeof(MSICOMPONENT) );
1179 if (!comp)
1180 return ERROR_FUNCTION_FAILED;
1182 list_add_tail( &package->components, &comp->entry );
1184 /* fill in the data */
1185 comp->Component = msi_dup_record_field( row, 1 );
1187 TRACE("Loading Component %s\n", debugstr_w(comp->Component));
1189 comp->ComponentId = msi_dup_record_field( row, 2 );
1190 comp->Directory = msi_dup_record_field( row, 3 );
1191 comp->Attributes = MSI_RecordGetInteger(row,4);
1192 comp->Condition = msi_dup_record_field( row, 5 );
1193 comp->KeyPath = msi_dup_record_field( row, 6 );
1195 comp->Installed = INSTALLSTATE_UNKNOWN;
1196 msi_component_set_state( comp, INSTALLSTATE_UNKNOWN );
1198 return ERROR_SUCCESS;
1201 static UINT load_all_components( MSIPACKAGE *package )
1203 static const WCHAR query[] = {
1204 'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1205 '`','C','o','m','p','o','n','e','n','t','`',0 };
1206 MSIQUERY *view;
1207 UINT r;
1209 if (!list_empty(&package->components))
1210 return ERROR_SUCCESS;
1212 r = MSI_DatabaseOpenViewW( package->db, query, &view );
1213 if (r != ERROR_SUCCESS)
1214 return r;
1216 r = MSI_IterateRecords(view, NULL, load_component, package);
1217 msiobj_release(&view->hdr);
1218 return r;
1221 typedef struct {
1222 MSIPACKAGE *package;
1223 MSIFEATURE *feature;
1224 } _ilfs;
1226 static UINT add_feature_component( MSIFEATURE *feature, MSICOMPONENT *comp )
1228 ComponentList *cl;
1230 cl = msi_alloc( sizeof (*cl) );
1231 if ( !cl )
1232 return ERROR_NOT_ENOUGH_MEMORY;
1233 cl->component = comp;
1234 list_add_tail( &feature->Components, &cl->entry );
1236 return ERROR_SUCCESS;
1239 static UINT add_feature_child( MSIFEATURE *parent, MSIFEATURE *child )
1241 FeatureList *fl;
1243 fl = msi_alloc( sizeof(*fl) );
1244 if ( !fl )
1245 return ERROR_NOT_ENOUGH_MEMORY;
1246 fl->feature = child;
1247 list_add_tail( &parent->Children, &fl->entry );
1249 return ERROR_SUCCESS;
1252 static UINT iterate_load_featurecomponents(MSIRECORD *row, LPVOID param)
1254 _ilfs* ilfs= (_ilfs*)param;
1255 LPCWSTR component;
1256 MSICOMPONENT *comp;
1258 component = MSI_RecordGetString(row,1);
1260 /* check to see if the component is already loaded */
1261 comp = get_loaded_component( ilfs->package, component );
1262 if (!comp)
1264 ERR("unknown component %s\n", debugstr_w(component));
1265 return ERROR_FUNCTION_FAILED;
1268 add_feature_component( ilfs->feature, comp );
1269 comp->Enabled = TRUE;
1271 return ERROR_SUCCESS;
1274 static MSIFEATURE *find_feature_by_name( MSIPACKAGE *package, LPCWSTR name )
1276 MSIFEATURE *feature;
1278 if ( !name )
1279 return NULL;
1281 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1283 if ( !lstrcmpW( feature->Feature, name ) )
1284 return feature;
1287 return NULL;
1290 static UINT load_feature(MSIRECORD * row, LPVOID param)
1292 MSIPACKAGE* package = (MSIPACKAGE*)param;
1293 MSIFEATURE* feature;
1294 static const WCHAR Query1[] =
1295 {'S','E','L','E','C','T',' ',
1296 '`','C','o','m','p','o','n','e','n','t','_','`',
1297 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1298 'C','o','m','p','o','n','e','n','t','s','`',' ',
1299 'W','H','E','R','E',' ',
1300 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1301 MSIQUERY * view;
1302 UINT rc;
1303 _ilfs ilfs;
1305 /* fill in the data */
1307 feature = msi_alloc_zero( sizeof (MSIFEATURE) );
1308 if (!feature)
1309 return ERROR_NOT_ENOUGH_MEMORY;
1311 list_init( &feature->Children );
1312 list_init( &feature->Components );
1314 feature->Feature = msi_dup_record_field( row, 1 );
1316 TRACE("Loading feature %s\n",debugstr_w(feature->Feature));
1318 feature->Feature_Parent = msi_dup_record_field( row, 2 );
1319 feature->Title = msi_dup_record_field( row, 3 );
1320 feature->Description = msi_dup_record_field( row, 4 );
1322 if (!MSI_RecordIsNull(row,5))
1323 feature->Display = MSI_RecordGetInteger(row,5);
1325 feature->Level= MSI_RecordGetInteger(row,6);
1326 feature->Directory = msi_dup_record_field( row, 7 );
1327 feature->Attributes = MSI_RecordGetInteger(row,8);
1329 feature->Installed = INSTALLSTATE_UNKNOWN;
1330 msi_feature_set_state( feature, INSTALLSTATE_UNKNOWN );
1332 list_add_tail( &package->features, &feature->entry );
1334 /* load feature components */
1336 rc = MSI_OpenQuery( package->db, &view, Query1, feature->Feature );
1337 if (rc != ERROR_SUCCESS)
1338 return ERROR_SUCCESS;
1340 ilfs.package = package;
1341 ilfs.feature = feature;
1343 MSI_IterateRecords(view, NULL, iterate_load_featurecomponents , &ilfs);
1344 msiobj_release(&view->hdr);
1346 return ERROR_SUCCESS;
1349 static UINT find_feature_children(MSIRECORD * row, LPVOID param)
1351 MSIPACKAGE* package = (MSIPACKAGE*)param;
1352 MSIFEATURE *parent, *child;
1354 child = find_feature_by_name( package, MSI_RecordGetString( row, 1 ) );
1355 if (!child)
1356 return ERROR_FUNCTION_FAILED;
1358 if (!child->Feature_Parent)
1359 return ERROR_SUCCESS;
1361 parent = find_feature_by_name( package, child->Feature_Parent );
1362 if (!parent)
1363 return ERROR_FUNCTION_FAILED;
1365 add_feature_child( parent, child );
1366 return ERROR_SUCCESS;
1369 static UINT load_all_features( MSIPACKAGE *package )
1371 static const WCHAR query[] = {
1372 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1373 '`','F','e','a','t','u','r','e','`',' ','O','R','D','E','R',
1374 ' ','B','Y',' ','`','D','i','s','p','l','a','y','`',0};
1375 MSIQUERY *view;
1376 UINT r;
1378 if (!list_empty(&package->features))
1379 return ERROR_SUCCESS;
1381 r = MSI_DatabaseOpenViewW( package->db, query, &view );
1382 if (r != ERROR_SUCCESS)
1383 return r;
1385 r = MSI_IterateRecords( view, NULL, load_feature, package );
1386 if (r != ERROR_SUCCESS)
1387 return r;
1389 r = MSI_IterateRecords( view, NULL, find_feature_children, package );
1390 msiobj_release( &view->hdr );
1392 return r;
1395 static LPWSTR folder_split_path(LPWSTR p, WCHAR ch)
1397 if (!p)
1398 return p;
1399 p = strchrW(p, ch);
1400 if (!p)
1401 return p;
1402 *p = 0;
1403 return p+1;
1406 static UINT load_file_hash(MSIPACKAGE *package, MSIFILE *file)
1408 static const WCHAR query[] = {
1409 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1410 '`','M','s','i','F','i','l','e','H','a','s','h','`',' ',
1411 'W','H','E','R','E',' ','`','F','i','l','e','_','`',' ','=',' ','\'','%','s','\'',0};
1412 MSIQUERY *view = NULL;
1413 MSIRECORD *row = NULL;
1414 UINT r;
1416 TRACE("%s\n", debugstr_w(file->File));
1418 r = MSI_OpenQuery(package->db, &view, query, file->File);
1419 if (r != ERROR_SUCCESS)
1420 goto done;
1422 r = MSI_ViewExecute(view, NULL);
1423 if (r != ERROR_SUCCESS)
1424 goto done;
1426 r = MSI_ViewFetch(view, &row);
1427 if (r != ERROR_SUCCESS)
1428 goto done;
1430 file->hash.dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
1431 file->hash.dwData[0] = MSI_RecordGetInteger(row, 3);
1432 file->hash.dwData[1] = MSI_RecordGetInteger(row, 4);
1433 file->hash.dwData[2] = MSI_RecordGetInteger(row, 5);
1434 file->hash.dwData[3] = MSI_RecordGetInteger(row, 6);
1436 done:
1437 if (view) msiobj_release(&view->hdr);
1438 if (row) msiobj_release(&row->hdr);
1439 return r;
1442 static UINT load_file(MSIRECORD *row, LPVOID param)
1444 MSIPACKAGE* package = (MSIPACKAGE*)param;
1445 LPCWSTR component;
1446 MSIFILE *file;
1448 /* fill in the data */
1450 file = msi_alloc_zero( sizeof (MSIFILE) );
1451 if (!file)
1452 return ERROR_NOT_ENOUGH_MEMORY;
1454 file->File = msi_dup_record_field( row, 1 );
1456 component = MSI_RecordGetString( row, 2 );
1457 file->Component = get_loaded_component( package, component );
1459 if (!file->Component)
1460 ERR("Unfound Component %s\n",debugstr_w(component));
1462 file->FileName = msi_dup_record_field( row, 3 );
1463 reduce_to_longfilename( file->FileName );
1465 file->ShortName = msi_dup_record_field( row, 3 );
1466 file->LongName = strdupW( folder_split_path(file->ShortName, '|'));
1468 file->FileSize = MSI_RecordGetInteger( row, 4 );
1469 file->Version = msi_dup_record_field( row, 5 );
1470 file->Language = msi_dup_record_field( row, 6 );
1471 file->Attributes = MSI_RecordGetInteger( row, 7 );
1472 file->Sequence = MSI_RecordGetInteger( row, 8 );
1474 file->state = msifs_invalid;
1476 /* if the compressed bits are not set in the file attributes,
1477 * then read the information from the package word count property
1479 if (file->Attributes & msidbFileAttributesCompressed)
1481 file->IsCompressed = TRUE;
1483 else if (file->Attributes & msidbFileAttributesNoncompressed)
1485 file->IsCompressed = FALSE;
1487 else
1489 file->IsCompressed = package->WordCount & MSIWORDCOUNT_COMPRESSED;
1492 if (!file->IsCompressed)
1494 LPWSTR p, path;
1496 p = resolve_folder(package, file->Component->Directory,
1497 TRUE, FALSE, TRUE, NULL);
1498 path = build_directory_name(2, p, file->ShortName);
1500 if (file->LongName &&
1501 GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
1503 msi_free(path);
1504 path = build_directory_name(2, p, file->LongName);
1507 file->SourcePath = path;
1508 msi_free(p);
1511 load_file_hash(package, file);
1513 TRACE("File Loaded (%s)\n",debugstr_w(file->File));
1515 list_add_tail( &package->files, &file->entry );
1517 return ERROR_SUCCESS;
1520 static UINT load_all_files(MSIPACKAGE *package)
1522 MSIQUERY * view;
1523 UINT rc;
1524 static const WCHAR Query[] =
1525 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1526 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1527 '`','S','e','q','u','e','n','c','e','`', 0};
1529 if (!list_empty(&package->files))
1530 return ERROR_SUCCESS;
1532 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1533 if (rc != ERROR_SUCCESS)
1534 return ERROR_SUCCESS;
1536 rc = MSI_IterateRecords(view, NULL, load_file, package);
1537 msiobj_release(&view->hdr);
1539 return ERROR_SUCCESS;
1542 static UINT load_folder( MSIRECORD *row, LPVOID param )
1544 MSIPACKAGE *package = param;
1545 static const WCHAR szDot[] = { '.',0 };
1546 static WCHAR szEmpty[] = { 0 };
1547 LPWSTR p, tgt_short, tgt_long, src_short, src_long;
1548 MSIFOLDER *folder;
1550 folder = msi_alloc_zero( sizeof (MSIFOLDER) );
1551 if (!folder)
1552 return ERROR_NOT_ENOUGH_MEMORY;
1554 folder->Directory = msi_dup_record_field( row, 1 );
1556 TRACE("%s\n", debugstr_w(folder->Directory));
1558 p = msi_dup_record_field(row, 3);
1560 /* split src and target dir */
1561 tgt_short = p;
1562 src_short = folder_split_path( p, ':' );
1564 /* split the long and short paths */
1565 tgt_long = folder_split_path( tgt_short, '|' );
1566 src_long = folder_split_path( src_short, '|' );
1568 /* check for no-op dirs */
1569 if (!lstrcmpW(szDot, tgt_short))
1570 tgt_short = szEmpty;
1571 if (!lstrcmpW(szDot, src_short))
1572 src_short = szEmpty;
1574 if (!tgt_long)
1575 tgt_long = tgt_short;
1577 if (!src_short) {
1578 src_short = tgt_short;
1579 src_long = tgt_long;
1582 if (!src_long)
1583 src_long = src_short;
1585 /* FIXME: use the target short path too */
1586 folder->TargetDefault = strdupW(tgt_long);
1587 folder->SourceShortPath = strdupW(src_short);
1588 folder->SourceLongPath = strdupW(src_long);
1589 msi_free(p);
1591 TRACE("TargetDefault = %s\n",debugstr_w( folder->TargetDefault ));
1592 TRACE("SourceLong = %s\n", debugstr_w( folder->SourceLongPath ));
1593 TRACE("SourceShort = %s\n", debugstr_w( folder->SourceShortPath ));
1595 folder->Parent = msi_dup_record_field( row, 2 );
1597 folder->Property = msi_dup_property( package, folder->Directory );
1599 list_add_tail( &package->folders, &folder->entry );
1601 TRACE("returning %p\n", folder);
1603 return ERROR_SUCCESS;
1606 static UINT load_all_folders( MSIPACKAGE *package )
1608 static const WCHAR query[] = {
1609 'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1610 '`','D','i','r','e','c','t','o','r','y','`',0 };
1611 MSIQUERY *view;
1612 UINT r;
1614 if (!list_empty(&package->folders))
1615 return ERROR_SUCCESS;
1617 r = MSI_DatabaseOpenViewW( package->db, query, &view );
1618 if (r != ERROR_SUCCESS)
1619 return r;
1621 r = MSI_IterateRecords(view, NULL, load_folder, package);
1622 msiobj_release(&view->hdr);
1623 return r;
1627 * I am not doing any of the costing functionality yet.
1628 * Mostly looking at doing the Component and Feature loading
1630 * The native MSI does A LOT of modification to tables here. Mostly adding
1631 * a lot of temporary columns to the Feature and Component tables.
1633 * note: Native msi also tracks the short filename. But I am only going to
1634 * track the long ones. Also looking at this directory table
1635 * it appears that the directory table does not get the parents
1636 * resolved base on property only based on their entries in the
1637 * directory table.
1639 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1641 static const WCHAR szCosting[] =
1642 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1643 static const WCHAR szZero[] = { '0', 0 };
1645 MSI_SetPropertyW(package, szCosting, szZero);
1646 MSI_SetPropertyW(package, cszRootDrive, c_colon);
1648 load_all_folders( package );
1649 load_all_components( package );
1650 load_all_features( package );
1651 load_all_files( package );
1653 return ERROR_SUCCESS;
1656 static UINT execute_script(MSIPACKAGE *package, UINT script )
1658 UINT i;
1659 UINT rc = ERROR_SUCCESS;
1661 TRACE("Executing Script %i\n",script);
1663 if (!package->script)
1665 ERR("no script!\n");
1666 return ERROR_FUNCTION_FAILED;
1669 for (i = 0; i < package->script->ActionCount[script]; i++)
1671 LPWSTR action;
1672 action = package->script->Actions[script][i];
1673 ui_actionstart(package, action);
1674 TRACE("Executing Action (%s)\n",debugstr_w(action));
1675 rc = ACTION_PerformAction(package, action, script, TRUE);
1676 if (rc != ERROR_SUCCESS)
1677 break;
1679 msi_free_action_script(package, script);
1680 return rc;
1683 static UINT ACTION_FileCost(MSIPACKAGE *package)
1685 return ERROR_SUCCESS;
1688 static void ACTION_GetComponentInstallStates(MSIPACKAGE *package)
1690 MSICOMPONENT *comp;
1692 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
1694 INSTALLSTATE res;
1696 if (!comp->ComponentId)
1697 continue;
1699 res = MsiGetComponentPathW( package->ProductCode,
1700 comp->ComponentId, NULL, NULL);
1701 if (res < 0)
1702 res = INSTALLSTATE_ABSENT;
1703 comp->Installed = res;
1707 /* scan for and update current install states */
1708 static void ACTION_UpdateFeatureInstallStates(MSIPACKAGE *package)
1710 MSICOMPONENT *comp;
1711 MSIFEATURE *feature;
1713 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1715 ComponentList *cl;
1716 INSTALLSTATE res = INSTALLSTATE_ABSENT;
1718 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1720 comp= cl->component;
1722 if (!comp->ComponentId)
1724 res = INSTALLSTATE_ABSENT;
1725 break;
1728 if (res == INSTALLSTATE_ABSENT)
1729 res = comp->Installed;
1730 else
1732 if (res == comp->Installed)
1733 continue;
1735 if (res != INSTALLSTATE_DEFAULT && res != INSTALLSTATE_LOCAL &&
1736 res != INSTALLSTATE_SOURCE)
1738 res = INSTALLSTATE_INCOMPLETE;
1742 feature->Installed = res;
1746 static BOOL process_state_property (MSIPACKAGE* package, LPCWSTR property,
1747 INSTALLSTATE state)
1749 static const WCHAR all[]={'A','L','L',0};
1750 LPWSTR override;
1751 MSIFEATURE *feature;
1753 override = msi_dup_property( package, property );
1754 if (!override)
1755 return FALSE;
1757 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1759 if (strcmpiW(override,all)==0)
1760 msi_feature_set_state( feature, state );
1761 else
1763 LPWSTR ptr = override;
1764 LPWSTR ptr2 = strchrW(override,',');
1766 while (ptr)
1768 if ((ptr2 && strncmpW(ptr,feature->Feature, ptr2-ptr)==0)
1769 || (!ptr2 && strcmpW(ptr,feature->Feature)==0))
1771 msi_feature_set_state( feature, state );
1772 break;
1774 if (ptr2)
1776 ptr=ptr2+1;
1777 ptr2 = strchrW(ptr,',');
1779 else
1780 break;
1784 msi_free(override);
1786 return TRUE;
1789 UINT MSI_SetFeatureStates(MSIPACKAGE *package)
1791 int install_level;
1792 static const WCHAR szlevel[] =
1793 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1794 static const WCHAR szAddLocal[] =
1795 {'A','D','D','L','O','C','A','L',0};
1796 static const WCHAR szAddSource[] =
1797 {'A','D','D','S','O','U','R','C','E',0};
1798 static const WCHAR szRemove[] =
1799 {'R','E','M','O','V','E',0};
1800 static const WCHAR szReinstall[] =
1801 {'R','E','I','N','S','T','A','L','L',0};
1802 BOOL override = FALSE;
1803 MSICOMPONENT* component;
1804 MSIFEATURE *feature;
1807 /* I do not know if this is where it should happen.. but */
1809 TRACE("Checking Install Level\n");
1811 install_level = msi_get_property_int( package, szlevel, 1 );
1813 /* ok here is the _real_ rub
1814 * all these activation/deactivation things happen in order and things
1815 * later on the list override things earlier on the list.
1816 * 1) INSTALLLEVEL processing
1817 * 2) ADDLOCAL
1818 * 3) REMOVE
1819 * 4) ADDSOURCE
1820 * 5) ADDDEFAULT
1821 * 6) REINSTALL
1822 * 7) COMPADDLOCAL
1823 * 8) COMPADDSOURCE
1824 * 9) FILEADDLOCAL
1825 * 10) FILEADDSOURCE
1826 * 11) FILEADDDEFAULT
1828 * I am still ignoring a lot of these. But that is ok for now, ADDLOCAL and
1829 * REMOVE are the big ones, since we don't handle administrative installs
1830 * yet anyway.
1832 override |= process_state_property(package,szAddLocal,INSTALLSTATE_LOCAL);
1833 override |= process_state_property(package,szRemove,INSTALLSTATE_ABSENT);
1834 override |= process_state_property(package,szAddSource,INSTALLSTATE_SOURCE);
1835 override |= process_state_property(package,szReinstall,INSTALLSTATE_LOCAL);
1837 if (!override)
1839 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1841 BOOL feature_state = ((feature->Level > 0) &&
1842 (feature->Level <= install_level));
1844 if ((feature_state) && (feature->Action == INSTALLSTATE_UNKNOWN))
1846 if (feature->Attributes & msidbFeatureAttributesFavorSource)
1847 msi_feature_set_state( feature, INSTALLSTATE_SOURCE );
1848 else if (feature->Attributes & msidbFeatureAttributesFavorAdvertise)
1849 msi_feature_set_state( feature, INSTALLSTATE_ADVERTISED );
1850 else
1851 msi_feature_set_state( feature, INSTALLSTATE_LOCAL );
1855 /* disable child features of unselected parent features */
1856 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1858 FeatureList *fl;
1860 if (feature->Level > 0 && feature->Level <= install_level)
1861 continue;
1863 LIST_FOR_EACH_ENTRY( fl, &feature->Children, FeatureList, entry )
1864 msi_feature_set_state( fl->feature, INSTALLSTATE_UNKNOWN );
1867 else
1869 /* set the Preselected Property */
1870 static const WCHAR szPreselected[] = {'P','r','e','s','e','l','e','c','t','e','d',0};
1871 static const WCHAR szOne[] = { '1', 0 };
1873 MSI_SetPropertyW(package,szPreselected,szOne);
1877 * now we want to enable or disable components base on feature
1880 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1882 ComponentList *cl;
1884 TRACE("Examining Feature %s (Level %i, Installed %i, Action %i)\n",
1885 debugstr_w(feature->Feature), feature->Level, feature->Installed, feature->Action);
1887 if (!feature->Level)
1888 continue;
1890 /* features with components that have compressed files are made local */
1891 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1893 if (cl->component->Enabled &&
1894 cl->component->ForceLocalState &&
1895 feature->Action == INSTALLSTATE_SOURCE)
1897 msi_feature_set_state( feature, INSTALLSTATE_LOCAL );
1898 break;
1902 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
1904 component = cl->component;
1906 if (!component->Enabled)
1907 continue;
1909 switch (feature->Action)
1911 case INSTALLSTATE_ABSENT:
1912 component->anyAbsent = 1;
1913 break;
1914 case INSTALLSTATE_ADVERTISED:
1915 component->hasAdvertiseFeature = 1;
1916 break;
1917 case INSTALLSTATE_SOURCE:
1918 component->hasSourceFeature = 1;
1919 break;
1920 case INSTALLSTATE_LOCAL:
1921 component->hasLocalFeature = 1;
1922 break;
1923 case INSTALLSTATE_DEFAULT:
1924 if (feature->Attributes & msidbFeatureAttributesFavorAdvertise)
1925 component->hasAdvertiseFeature = 1;
1926 else if (feature->Attributes & msidbFeatureAttributesFavorSource)
1927 component->hasSourceFeature = 1;
1928 else
1929 component->hasLocalFeature = 1;
1930 break;
1931 default:
1932 break;
1937 LIST_FOR_EACH_ENTRY( component, &package->components, MSICOMPONENT, entry )
1939 /* if the component isn't enabled, leave it alone */
1940 if (!component->Enabled)
1941 continue;
1943 /* check if it's local or source */
1944 if (!(component->Attributes & msidbComponentAttributesOptional) &&
1945 (component->hasLocalFeature || component->hasSourceFeature))
1947 if ((component->Attributes & msidbComponentAttributesSourceOnly) &&
1948 !component->ForceLocalState)
1949 msi_component_set_state( component, INSTALLSTATE_SOURCE );
1950 else
1951 msi_component_set_state( component, INSTALLSTATE_LOCAL );
1952 continue;
1955 /* if any feature is local, the component must be local too */
1956 if (component->hasLocalFeature)
1958 msi_component_set_state( component, INSTALLSTATE_LOCAL );
1959 continue;
1962 if (component->hasSourceFeature)
1964 msi_component_set_state( component, INSTALLSTATE_SOURCE );
1965 continue;
1968 if (component->hasAdvertiseFeature)
1970 msi_component_set_state( component, INSTALLSTATE_ADVERTISED );
1971 continue;
1974 TRACE("nobody wants component %s\n", debugstr_w(component->Component));
1975 if (component->anyAbsent)
1976 msi_component_set_state(component, INSTALLSTATE_ABSENT);
1979 LIST_FOR_EACH_ENTRY( component, &package->components, MSICOMPONENT, entry )
1981 if (component->Action == INSTALLSTATE_DEFAULT)
1983 TRACE("%s was default, setting to local\n", debugstr_w(component->Component));
1984 msi_component_set_state( component, INSTALLSTATE_LOCAL );
1987 TRACE("Result: Component %s (Installed %i, Action %i)\n",
1988 debugstr_w(component->Component), component->Installed, component->Action);
1992 return ERROR_SUCCESS;
1995 static UINT ITERATE_CostFinalizeDirectories(MSIRECORD *row, LPVOID param)
1997 MSIPACKAGE *package = (MSIPACKAGE*)param;
1998 LPCWSTR name;
1999 LPWSTR path;
2000 MSIFOLDER *f;
2002 name = MSI_RecordGetString(row,1);
2004 f = get_loaded_folder(package, name);
2005 if (!f) return ERROR_SUCCESS;
2007 /* reset the ResolvedTarget */
2008 msi_free(f->ResolvedTarget);
2009 f->ResolvedTarget = NULL;
2011 /* This helper function now does ALL the work */
2012 TRACE("Dir %s ...\n",debugstr_w(name));
2013 path = resolve_folder(package,name,FALSE,TRUE,TRUE,NULL);
2014 TRACE("resolves to %s\n",debugstr_w(path));
2015 msi_free(path);
2017 return ERROR_SUCCESS;
2020 static UINT ITERATE_CostFinalizeConditions(MSIRECORD *row, LPVOID param)
2022 MSIPACKAGE *package = (MSIPACKAGE*)param;
2023 LPCWSTR name;
2024 MSIFEATURE *feature;
2026 name = MSI_RecordGetString( row, 1 );
2028 feature = get_loaded_feature( package, name );
2029 if (!feature)
2030 ERR("FAILED to find loaded feature %s\n",debugstr_w(name));
2031 else
2033 LPCWSTR Condition;
2034 Condition = MSI_RecordGetString(row,3);
2036 if (MSI_EvaluateConditionW(package,Condition) == MSICONDITION_TRUE)
2038 int level = MSI_RecordGetInteger(row,2);
2039 TRACE("Resetting feature %s to level %i\n", debugstr_w(name), level);
2040 feature->Level = level;
2043 return ERROR_SUCCESS;
2046 static LPWSTR msi_get_disk_file_version( LPCWSTR filename )
2048 static const WCHAR name_fmt[] =
2049 {'%','u','.','%','u','.','%','u','.','%','u',0};
2050 static const WCHAR name[] = {'\\',0};
2051 VS_FIXEDFILEINFO *lpVer;
2052 WCHAR filever[0x100];
2053 LPVOID version;
2054 DWORD versize;
2055 DWORD handle;
2056 UINT sz;
2058 TRACE("%s\n", debugstr_w(filename));
2060 versize = GetFileVersionInfoSizeW( filename, &handle );
2061 if (!versize)
2062 return NULL;
2064 version = msi_alloc( versize );
2065 GetFileVersionInfoW( filename, 0, versize, version );
2067 if (!VerQueryValueW( version, name, (LPVOID*)&lpVer, &sz ))
2069 msi_free( version );
2070 return NULL;
2073 sprintfW( filever, name_fmt,
2074 HIWORD(lpVer->dwFileVersionMS),
2075 LOWORD(lpVer->dwFileVersionMS),
2076 HIWORD(lpVer->dwFileVersionLS),
2077 LOWORD(lpVer->dwFileVersionLS));
2079 msi_free( version );
2081 return strdupW( filever );
2084 static UINT msi_check_file_install_states( MSIPACKAGE *package )
2086 LPWSTR file_version;
2087 MSIFILE *file;
2089 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2091 MSICOMPONENT* comp = file->Component;
2092 LPWSTR p;
2094 if (!comp)
2095 continue;
2097 if (file->IsCompressed)
2098 comp->ForceLocalState = TRUE;
2100 /* calculate target */
2101 p = resolve_folder(package, comp->Directory, FALSE, FALSE, TRUE, NULL);
2103 msi_free(file->TargetPath);
2105 TRACE("file %s is named %s\n",
2106 debugstr_w(file->File), debugstr_w(file->FileName));
2108 file->TargetPath = build_directory_name(2, p, file->FileName);
2110 msi_free(p);
2112 TRACE("file %s resolves to %s\n",
2113 debugstr_w(file->File), debugstr_w(file->TargetPath));
2115 /* don't check files of components that aren't installed */
2116 if (comp->Installed == INSTALLSTATE_UNKNOWN ||
2117 comp->Installed == INSTALLSTATE_ABSENT)
2119 file->state = msifs_missing; /* assume files are missing */
2120 continue;
2123 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2125 file->state = msifs_missing;
2126 comp->Cost += file->FileSize;
2127 comp->Installed = INSTALLSTATE_INCOMPLETE;
2128 continue;
2131 if (file->Version &&
2132 (file_version = msi_get_disk_file_version( file->TargetPath )))
2134 TRACE("new %s old %s\n", debugstr_w(file->Version),
2135 debugstr_w(file_version));
2136 /* FIXME: seems like a bad way to compare version numbers */
2137 if (lstrcmpiW(file_version, file->Version)<0)
2139 file->state = msifs_overwrite;
2140 comp->Cost += file->FileSize;
2141 comp->Installed = INSTALLSTATE_INCOMPLETE;
2143 else
2144 file->state = msifs_present;
2145 msi_free( file_version );
2147 else
2148 file->state = msifs_present;
2151 return ERROR_SUCCESS;
2155 * A lot is done in this function aside from just the costing.
2156 * The costing needs to be implemented at some point but for now I am going
2157 * to focus on the directory building
2160 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2162 static const WCHAR ExecSeqQuery[] =
2163 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2164 '`','D','i','r','e','c','t','o','r','y','`',0};
2165 static const WCHAR ConditionQuery[] =
2166 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2167 '`','C','o','n','d','i','t','i','o','n','`',0};
2168 static const WCHAR szCosting[] =
2169 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2170 static const WCHAR szlevel[] =
2171 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2172 static const WCHAR szOutOfDiskSpace[] =
2173 {'O','u','t','O','f','D','i','s','k','S','p','a','c','e',0};
2174 static const WCHAR szOne[] = { '1', 0 };
2175 static const WCHAR szZero[] = { '0', 0 };
2176 MSICOMPONENT *comp;
2177 UINT rc;
2178 MSIQUERY * view;
2179 LPWSTR level;
2181 if ( 1 == msi_get_property_int( package, szCosting, 0 ) )
2182 return ERROR_SUCCESS;
2184 TRACE("Building Directory properties\n");
2186 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2187 if (rc == ERROR_SUCCESS)
2189 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeDirectories,
2190 package);
2191 msiobj_release(&view->hdr);
2194 /* read components states from the registry */
2195 ACTION_GetComponentInstallStates(package);
2197 TRACE("File calculations\n");
2198 msi_check_file_install_states( package );
2200 TRACE("Evaluating Condition Table\n");
2202 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2203 if (rc == ERROR_SUCCESS)
2205 rc = MSI_IterateRecords(view, NULL, ITERATE_CostFinalizeConditions,
2206 package);
2207 msiobj_release(&view->hdr);
2210 TRACE("Enabling or Disabling Components\n");
2211 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2213 if (MSI_EvaluateConditionW(package, comp->Condition) == MSICONDITION_FALSE)
2215 TRACE("Disabling component %s\n", debugstr_w(comp->Component));
2216 comp->Enabled = FALSE;
2220 MSI_SetPropertyW(package,szCosting,szOne);
2221 /* set default run level if not set */
2222 level = msi_dup_property( package, szlevel );
2223 if (!level)
2224 MSI_SetPropertyW(package,szlevel, szOne);
2225 msi_free(level);
2227 /* FIXME: check volume disk space */
2228 MSI_SetPropertyW(package, szOutOfDiskSpace, szZero);
2230 ACTION_UpdateFeatureInstallStates(package);
2232 return MSI_SetFeatureStates(package);
2235 /* OK this value is "interpreted" and then formatted based on the
2236 first few characters */
2237 static LPSTR parse_value(MSIPACKAGE *package, LPCWSTR value, DWORD *type,
2238 DWORD *size)
2240 LPSTR data = NULL;
2242 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
2244 if (value[1]=='x')
2246 LPWSTR ptr;
2247 CHAR byte[5];
2248 LPWSTR deformated = NULL;
2249 int count;
2251 deformat_string(package, &value[2], &deformated);
2253 /* binary value type */
2254 ptr = deformated;
2255 *type = REG_BINARY;
2256 if (strlenW(ptr)%2)
2257 *size = (strlenW(ptr)/2)+1;
2258 else
2259 *size = strlenW(ptr)/2;
2261 data = msi_alloc(*size);
2263 byte[0] = '0';
2264 byte[1] = 'x';
2265 byte[4] = 0;
2266 count = 0;
2267 /* if uneven pad with a zero in front */
2268 if (strlenW(ptr)%2)
2270 byte[2]= '0';
2271 byte[3]= *ptr;
2272 ptr++;
2273 data[count] = (BYTE)strtol(byte,NULL,0);
2274 count ++;
2275 TRACE("Uneven byte count\n");
2277 while (*ptr)
2279 byte[2]= *ptr;
2280 ptr++;
2281 byte[3]= *ptr;
2282 ptr++;
2283 data[count] = (BYTE)strtol(byte,NULL,0);
2284 count ++;
2286 msi_free(deformated);
2288 TRACE("Data %i bytes(%i)\n",*size,count);
2290 else
2292 LPWSTR deformated;
2293 LPWSTR p;
2294 DWORD d = 0;
2295 deformat_string(package, &value[1], &deformated);
2297 *type=REG_DWORD;
2298 *size = sizeof(DWORD);
2299 data = msi_alloc(*size);
2300 p = deformated;
2301 if (*p == '-')
2302 p++;
2303 while (*p)
2305 if ( (*p < '0') || (*p > '9') )
2306 break;
2307 d *= 10;
2308 d += (*p - '0');
2309 p++;
2311 if (deformated[0] == '-')
2312 d = -d;
2313 *(LPDWORD)data = d;
2314 TRACE("DWORD %i\n",*(LPDWORD)data);
2316 msi_free(deformated);
2319 else
2321 static const WCHAR szMulti[] = {'[','~',']',0};
2322 LPCWSTR ptr;
2323 *type=REG_SZ;
2325 if (value[0]=='#')
2327 if (value[1]=='%')
2329 ptr = &value[2];
2330 *type=REG_EXPAND_SZ;
2332 else
2333 ptr = &value[1];
2335 else
2336 ptr=value;
2338 if (strstrW(value,szMulti))
2339 *type = REG_MULTI_SZ;
2341 /* remove initial delimiter */
2342 if (!strncmpW(value, szMulti, 3))
2343 ptr = value + 3;
2345 *size = deformat_string(package, ptr,(LPWSTR*)&data);
2347 /* add double NULL terminator */
2348 if (*type == REG_MULTI_SZ)
2350 *size += 2 * sizeof(WCHAR); /* two NULL terminators */
2351 data = msi_realloc_zero(data, *size);
2354 return data;
2357 static UINT ITERATE_WriteRegistryValues(MSIRECORD *row, LPVOID param)
2359 MSIPACKAGE *package = (MSIPACKAGE*)param;
2360 static const WCHAR szHCR[] =
2361 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
2362 'R','O','O','T','\\',0};
2363 static const WCHAR szHCU[] =
2364 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
2365 'U','S','E','R','\\',0};
2366 static const WCHAR szHLM[] =
2367 {'H','K','E','Y','_','L','O','C','A','L','_',
2368 'M','A','C','H','I','N','E','\\',0};
2369 static const WCHAR szHU[] =
2370 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2372 LPSTR value_data = NULL;
2373 HKEY root_key, hkey;
2374 DWORD type,size;
2375 LPWSTR deformated;
2376 LPCWSTR szRoot, component, name, key, value;
2377 MSICOMPONENT *comp;
2378 MSIRECORD * uirow;
2379 LPWSTR uikey;
2380 INT root;
2381 BOOL check_first = FALSE;
2382 UINT rc;
2384 ui_progress(package,2,0,0,0);
2386 value = NULL;
2387 key = NULL;
2388 uikey = NULL;
2389 name = NULL;
2391 component = MSI_RecordGetString(row, 6);
2392 comp = get_loaded_component(package,component);
2393 if (!comp)
2394 return ERROR_SUCCESS;
2396 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL))
2398 TRACE("Skipping write due to disabled component %s\n",
2399 debugstr_w(component));
2401 comp->Action = comp->Installed;
2403 return ERROR_SUCCESS;
2406 comp->Action = INSTALLSTATE_LOCAL;
2408 name = MSI_RecordGetString(row, 4);
2409 if( MSI_RecordIsNull(row,5) && name )
2411 /* null values can have special meanings */
2412 if (name[0]=='-' && name[1] == 0)
2413 return ERROR_SUCCESS;
2414 else if ((name[0]=='+' && name[1] == 0) ||
2415 (name[0] == '*' && name[1] == 0))
2416 name = NULL;
2417 check_first = TRUE;
2420 root = MSI_RecordGetInteger(row,2);
2421 key = MSI_RecordGetString(row, 3);
2423 /* get the root key */
2424 switch (root)
2426 case -1:
2428 static const WCHAR szALLUSER[] = {'A','L','L','U','S','E','R','S',0};
2429 LPWSTR all_users = msi_dup_property( package, szALLUSER );
2430 if (all_users && all_users[0] == '1')
2432 root_key = HKEY_LOCAL_MACHINE;
2433 szRoot = szHLM;
2435 else
2437 root_key = HKEY_CURRENT_USER;
2438 szRoot = szHCU;
2440 msi_free(all_users);
2442 break;
2443 case 0: root_key = HKEY_CLASSES_ROOT;
2444 szRoot = szHCR;
2445 break;
2446 case 1: root_key = HKEY_CURRENT_USER;
2447 szRoot = szHCU;
2448 break;
2449 case 2: root_key = HKEY_LOCAL_MACHINE;
2450 szRoot = szHLM;
2451 break;
2452 case 3: root_key = HKEY_USERS;
2453 szRoot = szHU;
2454 break;
2455 default:
2456 ERR("Unknown root %i\n",root);
2457 root_key=NULL;
2458 szRoot = NULL;
2459 break;
2461 if (!root_key)
2462 return ERROR_SUCCESS;
2464 deformat_string(package, key , &deformated);
2465 size = strlenW(deformated) + strlenW(szRoot) + 1;
2466 uikey = msi_alloc(size*sizeof(WCHAR));
2467 strcpyW(uikey,szRoot);
2468 strcatW(uikey,deformated);
2470 if (RegCreateKeyW( root_key, deformated, &hkey))
2472 ERR("Could not create key %s\n",debugstr_w(deformated));
2473 msi_free(deformated);
2474 msi_free(uikey);
2475 return ERROR_SUCCESS;
2477 msi_free(deformated);
2479 value = MSI_RecordGetString(row,5);
2480 if (value)
2481 value_data = parse_value(package, value, &type, &size);
2482 else
2484 static const WCHAR szEmpty[] = {0};
2485 value_data = (LPSTR)strdupW(szEmpty);
2486 size = sizeof(szEmpty);
2487 type = REG_SZ;
2490 deformat_string(package, name, &deformated);
2492 if (!check_first)
2494 TRACE("Setting value %s of %s\n",debugstr_w(deformated),
2495 debugstr_w(uikey));
2496 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE)value_data, size);
2498 else
2500 DWORD sz = 0;
2501 rc = RegQueryValueExW(hkey, deformated, NULL, NULL, NULL, &sz);
2502 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2504 TRACE("value %s of %s checked already exists\n",
2505 debugstr_w(deformated), debugstr_w(uikey));
2507 else
2509 TRACE("Checked and setting value %s of %s\n",
2510 debugstr_w(deformated), debugstr_w(uikey));
2511 if (deformated || size)
2512 RegSetValueExW(hkey, deformated, 0, type, (LPBYTE) value_data, size);
2515 RegCloseKey(hkey);
2517 uirow = MSI_CreateRecord(3);
2518 MSI_RecordSetStringW(uirow,2,deformated);
2519 MSI_RecordSetStringW(uirow,1,uikey);
2521 if (type == REG_SZ)
2522 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2523 else
2524 MSI_RecordSetStringW(uirow,3,value);
2526 ui_actiondata(package,szWriteRegistryValues,uirow);
2527 msiobj_release( &uirow->hdr );
2529 msi_free(value_data);
2530 msi_free(deformated);
2531 msi_free(uikey);
2533 return ERROR_SUCCESS;
2536 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2538 UINT rc;
2539 MSIQUERY * view;
2540 static const WCHAR ExecSeqQuery[] =
2541 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2542 '`','R','e','g','i','s','t','r','y','`',0 };
2544 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2545 if (rc != ERROR_SUCCESS)
2546 return ERROR_SUCCESS;
2548 /* increment progress bar each time action data is sent */
2549 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
2551 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteRegistryValues, package);
2553 msiobj_release(&view->hdr);
2554 return rc;
2557 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
2559 package->script->CurrentlyScripting = TRUE;
2561 return ERROR_SUCCESS;
2565 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
2567 MSICOMPONENT *comp;
2568 DWORD progress = 0;
2569 DWORD total = 0;
2570 static const WCHAR q1[]=
2571 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2572 '`','R','e','g','i','s','t','r','y','`',0};
2573 UINT rc;
2574 MSIQUERY * view;
2575 MSIFEATURE *feature;
2576 MSIFILE *file;
2578 TRACE("InstallValidate\n");
2580 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
2581 if (rc == ERROR_SUCCESS)
2583 MSI_IterateRecords( view, &progress, NULL, package );
2584 msiobj_release( &view->hdr );
2585 total += progress * REG_PROGRESS_VALUE;
2588 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2589 total += COMPONENT_PROGRESS_VALUE;
2591 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2592 total += file->FileSize;
2594 ui_progress(package,0,total,0,0);
2596 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2598 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2599 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2600 feature->ActionRequest);
2603 return ERROR_SUCCESS;
2606 static UINT ITERATE_LaunchConditions(MSIRECORD *row, LPVOID param)
2608 MSIPACKAGE* package = (MSIPACKAGE*)param;
2609 LPCWSTR cond = NULL;
2610 LPCWSTR message = NULL;
2611 UINT r;
2613 static const WCHAR title[]=
2614 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2616 cond = MSI_RecordGetString(row,1);
2618 r = MSI_EvaluateConditionW(package,cond);
2619 if (r == MSICONDITION_FALSE)
2621 if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
2623 LPWSTR deformated;
2624 message = MSI_RecordGetString(row,2);
2625 deformat_string(package,message,&deformated);
2626 MessageBoxW(NULL,deformated,title,MB_OK);
2627 msi_free(deformated);
2630 return ERROR_INSTALL_FAILURE;
2633 return ERROR_SUCCESS;
2636 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
2638 UINT rc;
2639 MSIQUERY * view = NULL;
2640 static const WCHAR ExecSeqQuery[] =
2641 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2642 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2644 TRACE("Checking launch conditions\n");
2646 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2647 if (rc != ERROR_SUCCESS)
2648 return ERROR_SUCCESS;
2650 rc = MSI_IterateRecords(view, NULL, ITERATE_LaunchConditions, package);
2651 msiobj_release(&view->hdr);
2653 return rc;
2656 static LPWSTR resolve_keypath( MSIPACKAGE* package, MSICOMPONENT *cmp )
2659 if (!cmp->KeyPath)
2660 return resolve_folder(package,cmp->Directory,FALSE,FALSE,TRUE,NULL);
2662 if (cmp->Attributes & msidbComponentAttributesRegistryKeyPath)
2664 MSIRECORD * row = 0;
2665 UINT root,len;
2666 LPWSTR deformated,buffer,deformated_name;
2667 LPCWSTR key,name;
2668 static const WCHAR ExecSeqQuery[] =
2669 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2670 '`','R','e','g','i','s','t','r','y','`',' ',
2671 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2672 ' ','=',' ' ,'\'','%','s','\'',0 };
2673 static const WCHAR fmt[]={'%','0','2','i',':','\\','%','s','\\',0};
2674 static const WCHAR fmt2[]=
2675 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2677 row = MSI_QueryGetRecord(package->db, ExecSeqQuery,cmp->KeyPath);
2678 if (!row)
2679 return NULL;
2681 root = MSI_RecordGetInteger(row,2);
2682 key = MSI_RecordGetString(row, 3);
2683 name = MSI_RecordGetString(row, 4);
2684 deformat_string(package, key , &deformated);
2685 deformat_string(package, name, &deformated_name);
2687 len = strlenW(deformated) + 6;
2688 if (deformated_name)
2689 len+=strlenW(deformated_name);
2691 buffer = msi_alloc( len *sizeof(WCHAR));
2693 if (deformated_name)
2694 sprintfW(buffer,fmt2,root,deformated,deformated_name);
2695 else
2696 sprintfW(buffer,fmt,root,deformated);
2698 msi_free(deformated);
2699 msi_free(deformated_name);
2700 msiobj_release(&row->hdr);
2702 return buffer;
2704 else if (cmp->Attributes & msidbComponentAttributesODBCDataSource)
2706 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2707 return NULL;
2709 else
2711 MSIFILE *file = get_loaded_file( package, cmp->KeyPath );
2713 if (file)
2714 return strdupW( file->TargetPath );
2716 return NULL;
2719 static HKEY openSharedDLLsKey(void)
2721 HKEY hkey=0;
2722 static const WCHAR path[] =
2723 {'S','o','f','t','w','a','r','e','\\',
2724 'M','i','c','r','o','s','o','f','t','\\',
2725 'W','i','n','d','o','w','s','\\',
2726 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2727 'S','h','a','r','e','d','D','L','L','s',0};
2729 RegCreateKeyW(HKEY_LOCAL_MACHINE,path,&hkey);
2730 return hkey;
2733 static UINT ACTION_GetSharedDLLsCount(LPCWSTR dll)
2735 HKEY hkey;
2736 DWORD count=0;
2737 DWORD type;
2738 DWORD sz = sizeof(count);
2739 DWORD rc;
2741 hkey = openSharedDLLsKey();
2742 rc = RegQueryValueExW(hkey, dll, NULL, &type, (LPBYTE)&count, &sz);
2743 if (rc != ERROR_SUCCESS)
2744 count = 0;
2745 RegCloseKey(hkey);
2746 return count;
2749 static UINT ACTION_WriteSharedDLLsCount(LPCWSTR path, UINT count)
2751 HKEY hkey;
2753 hkey = openSharedDLLsKey();
2754 if (count > 0)
2755 msi_reg_set_val_dword( hkey, path, count );
2756 else
2757 RegDeleteValueW(hkey,path);
2758 RegCloseKey(hkey);
2759 return count;
2763 * Return TRUE if the count should be written out and FALSE if not
2765 static void ACTION_RefCountComponent( MSIPACKAGE* package, MSICOMPONENT *comp )
2767 MSIFEATURE *feature;
2768 INT count = 0;
2769 BOOL write = FALSE;
2771 /* only refcount DLLs */
2772 if (comp->KeyPath == NULL ||
2773 comp->Attributes & msidbComponentAttributesRegistryKeyPath ||
2774 comp->Attributes & msidbComponentAttributesODBCDataSource)
2775 write = FALSE;
2776 else
2778 count = ACTION_GetSharedDLLsCount( comp->FullKeypath);
2779 write = (count > 0);
2781 if (comp->Attributes & msidbComponentAttributesSharedDllRefCount)
2782 write = TRUE;
2785 /* increment counts */
2786 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2788 ComponentList *cl;
2790 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ))
2791 continue;
2793 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2795 if ( cl->component == comp )
2796 count++;
2800 /* decrement counts */
2801 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
2803 ComponentList *cl;
2805 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ABSENT ))
2806 continue;
2808 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
2810 if ( cl->component == comp )
2811 count--;
2815 /* ref count all the files in the component */
2816 if (write)
2818 MSIFILE *file;
2820 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
2822 if (file->Component == comp)
2823 ACTION_WriteSharedDLLsCount( file->TargetPath, count );
2827 /* add a count for permanent */
2828 if (comp->Attributes & msidbComponentAttributesPermanent)
2829 count ++;
2831 comp->RefCount = count;
2833 if (write)
2834 ACTION_WriteSharedDLLsCount( comp->FullKeypath, comp->RefCount );
2838 * Ok further analysis makes me think that this work is
2839 * actually done in the PublishComponents and PublishFeatures
2840 * step, and not here. It appears like the keypath and all that is
2841 * resolved in this step, however actually written in the Publish steps.
2842 * But we will leave it here for now because it is unclear
2844 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
2846 WCHAR squished_pc[GUID_SIZE];
2847 WCHAR squished_cc[GUID_SIZE];
2848 UINT rc;
2849 MSICOMPONENT *comp;
2850 HKEY hkey;
2852 TRACE("\n");
2854 /* writes the Component values to the registry */
2856 squash_guid(package->ProductCode,squished_pc);
2857 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
2859 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
2861 MSIRECORD * uirow;
2863 ui_progress(package,2,0,0,0);
2864 if (!comp->ComponentId)
2865 continue;
2867 squash_guid(comp->ComponentId,squished_cc);
2869 msi_free(comp->FullKeypath);
2870 comp->FullKeypath = resolve_keypath( package, comp );
2872 /* do the refcounting */
2873 ACTION_RefCountComponent( package, comp );
2875 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2876 debugstr_w(comp->Component),
2877 debugstr_w(squished_cc),
2878 debugstr_w(comp->FullKeypath),
2879 comp->RefCount);
2881 * Write the keypath out if the component is to be registered
2882 * and delete the key if the component is to be unregistered
2884 if (ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL))
2886 if (!comp->FullKeypath)
2887 continue;
2889 if (package->Context == MSIINSTALLCONTEXT_MACHINE)
2890 rc = MSIREG_OpenLocalUserDataComponentKey(comp->ComponentId, &hkey, TRUE);
2891 else
2892 rc = MSIREG_OpenUserDataComponentKey(comp->ComponentId, &hkey, TRUE);
2894 if (rc != ERROR_SUCCESS)
2895 continue;
2897 if (comp->Attributes & msidbComponentAttributesPermanent)
2899 static const WCHAR szPermKey[] =
2900 { '0','0','0','0','0','0','0','0','0','0','0','0',
2901 '0','0','0','0','0','0','0','0','0','0','0','0',
2902 '0','0','0','0','0','0','0','0',0 };
2904 msi_reg_set_val_str(hkey, szPermKey, comp->FullKeypath);
2907 msi_reg_set_val_str(hkey, squished_pc, comp->FullKeypath);
2908 RegCloseKey(hkey);
2910 else if (ACTION_VerifyComponentForAction(comp, INSTALLSTATE_ABSENT))
2912 if (package->Context == MSIINSTALLCONTEXT_MACHINE)
2913 MSIREG_DeleteLocalUserDataComponentKey(comp->ComponentId);
2914 else
2915 MSIREG_DeleteUserDataComponentKey(comp->ComponentId);
2918 /* UI stuff */
2919 uirow = MSI_CreateRecord(3);
2920 MSI_RecordSetStringW(uirow,1,package->ProductCode);
2921 MSI_RecordSetStringW(uirow,2,comp->ComponentId);
2922 MSI_RecordSetStringW(uirow,3,comp->FullKeypath);
2923 ui_actiondata(package,szProcessComponents,uirow);
2924 msiobj_release( &uirow->hdr );
2927 return ERROR_SUCCESS;
2930 typedef struct {
2931 CLSID clsid;
2932 LPWSTR source;
2934 LPWSTR path;
2935 ITypeLib *ptLib;
2936 } typelib_struct;
2938 static BOOL CALLBACK Typelib_EnumResNameProc( HMODULE hModule, LPCWSTR lpszType,
2939 LPWSTR lpszName, LONG_PTR lParam)
2941 TLIBATTR *attr;
2942 typelib_struct *tl_struct = (typelib_struct*) lParam;
2943 static const WCHAR fmt[] = {'%','s','\\','%','i',0};
2944 int sz;
2945 HRESULT res;
2947 if (!IS_INTRESOURCE(lpszName))
2949 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName));
2950 return TRUE;
2953 sz = strlenW(tl_struct->source)+4;
2954 sz *= sizeof(WCHAR);
2956 if ((INT_PTR)lpszName == 1)
2957 tl_struct->path = strdupW(tl_struct->source);
2958 else
2960 tl_struct->path = msi_alloc(sz);
2961 sprintfW(tl_struct->path,fmt,tl_struct->source, lpszName);
2964 TRACE("trying %s\n", debugstr_w(tl_struct->path));
2965 res = LoadTypeLib(tl_struct->path,&tl_struct->ptLib);
2966 if (!SUCCEEDED(res))
2968 msi_free(tl_struct->path);
2969 tl_struct->path = NULL;
2971 return TRUE;
2974 ITypeLib_GetLibAttr(tl_struct->ptLib, &attr);
2975 if (IsEqualGUID(&(tl_struct->clsid),&(attr->guid)))
2977 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2978 return FALSE;
2981 msi_free(tl_struct->path);
2982 tl_struct->path = NULL;
2984 ITypeLib_ReleaseTLibAttr(tl_struct->ptLib, attr);
2985 ITypeLib_Release(tl_struct->ptLib);
2987 return TRUE;
2990 static UINT ITERATE_RegisterTypeLibraries(MSIRECORD *row, LPVOID param)
2992 MSIPACKAGE* package = (MSIPACKAGE*)param;
2993 LPCWSTR component;
2994 MSICOMPONENT *comp;
2995 MSIFILE *file;
2996 typelib_struct tl_struct;
2997 HMODULE module;
2998 static const WCHAR szTYPELIB[] = {'T','Y','P','E','L','I','B',0};
3000 component = MSI_RecordGetString(row,3);
3001 comp = get_loaded_component(package,component);
3002 if (!comp)
3003 return ERROR_SUCCESS;
3005 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL))
3007 TRACE("Skipping typelib reg due to disabled component\n");
3009 comp->Action = comp->Installed;
3011 return ERROR_SUCCESS;
3014 comp->Action = INSTALLSTATE_LOCAL;
3016 file = get_loaded_file( package, comp->KeyPath );
3017 if (!file)
3018 return ERROR_SUCCESS;
3020 module = LoadLibraryExW( file->TargetPath, NULL, LOAD_LIBRARY_AS_DATAFILE );
3021 if (module)
3023 LPCWSTR guid;
3024 guid = MSI_RecordGetString(row,1);
3025 CLSIDFromString((LPWSTR)guid, &tl_struct.clsid);
3026 tl_struct.source = strdupW( file->TargetPath );
3027 tl_struct.path = NULL;
3029 EnumResourceNamesW(module, szTYPELIB, Typelib_EnumResNameProc,
3030 (LONG_PTR)&tl_struct);
3032 if (tl_struct.path)
3034 LPWSTR help = NULL;
3035 LPCWSTR helpid;
3036 HRESULT res;
3038 helpid = MSI_RecordGetString(row,6);
3040 if (helpid)
3041 help = resolve_folder(package,helpid,FALSE,FALSE,TRUE,NULL);
3042 res = RegisterTypeLib(tl_struct.ptLib,tl_struct.path,help);
3043 msi_free(help);
3045 if (!SUCCEEDED(res))
3046 ERR("Failed to register type library %s\n",
3047 debugstr_w(tl_struct.path));
3048 else
3050 ui_actiondata(package,szRegisterTypeLibraries,row);
3052 TRACE("Registered %s\n", debugstr_w(tl_struct.path));
3055 ITypeLib_Release(tl_struct.ptLib);
3056 msi_free(tl_struct.path);
3058 else
3059 ERR("Failed to load type library %s\n",
3060 debugstr_w(tl_struct.source));
3062 FreeLibrary(module);
3063 msi_free(tl_struct.source);
3065 else
3066 ERR("Could not load file! %s\n", debugstr_w(file->TargetPath));
3068 return ERROR_SUCCESS;
3071 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
3074 * OK this is a bit confusing.. I am given a _Component key and I believe
3075 * that the file that is being registered as a type library is the "key file
3076 * of that component" which I interpret to mean "The file in the KeyPath of
3077 * that component".
3079 UINT rc;
3080 MSIQUERY * view;
3081 static const WCHAR Query[] =
3082 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3083 '`','T','y','p','e','L','i','b','`',0};
3085 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3086 if (rc != ERROR_SUCCESS)
3087 return ERROR_SUCCESS;
3089 rc = MSI_IterateRecords(view, NULL, ITERATE_RegisterTypeLibraries, package);
3090 msiobj_release(&view->hdr);
3091 return rc;
3094 static UINT ITERATE_CreateShortcuts(MSIRECORD *row, LPVOID param)
3096 MSIPACKAGE *package = (MSIPACKAGE*)param;
3097 LPWSTR target_file, target_folder, filename;
3098 LPCWSTR buffer, extension;
3099 MSICOMPONENT *comp;
3100 static const WCHAR szlnk[]={'.','l','n','k',0};
3101 IShellLinkW *sl = NULL;
3102 IPersistFile *pf = NULL;
3103 HRESULT res;
3105 buffer = MSI_RecordGetString(row,4);
3106 comp = get_loaded_component(package,buffer);
3107 if (!comp)
3108 return ERROR_SUCCESS;
3110 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL ))
3112 TRACE("Skipping shortcut creation due to disabled component\n");
3114 comp->Action = comp->Installed;
3116 return ERROR_SUCCESS;
3119 comp->Action = INSTALLSTATE_LOCAL;
3121 ui_actiondata(package,szCreateShortcuts,row);
3123 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3124 &IID_IShellLinkW, (LPVOID *) &sl );
3126 if (FAILED( res ))
3128 ERR("CLSID_ShellLink not available\n");
3129 goto err;
3132 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
3133 if (FAILED( res ))
3135 ERR("QueryInterface(IID_IPersistFile) failed\n");
3136 goto err;
3139 buffer = MSI_RecordGetString(row,2);
3140 target_folder = resolve_folder(package, buffer,FALSE,FALSE,TRUE,NULL);
3142 /* may be needed because of a bug somewhere else */
3143 create_full_pathW(target_folder);
3145 filename = msi_dup_record_field( row, 3 );
3146 reduce_to_longfilename(filename);
3148 extension = strchrW(filename,'.');
3149 if (!extension || strcmpiW(extension,szlnk))
3151 int len = strlenW(filename);
3152 filename = msi_realloc(filename, len * sizeof(WCHAR) + sizeof(szlnk));
3153 memcpy(filename + len, szlnk, sizeof(szlnk));
3155 target_file = build_directory_name(2, target_folder, filename);
3156 msi_free(target_folder);
3157 msi_free(filename);
3159 buffer = MSI_RecordGetString(row,5);
3160 if (strchrW(buffer,'['))
3162 LPWSTR deformated;
3163 deformat_string(package,buffer,&deformated);
3164 IShellLinkW_SetPath(sl,deformated);
3165 msi_free(deformated);
3167 else
3169 FIXME("poorly handled shortcut format, advertised shortcut\n");
3170 IShellLinkW_SetPath(sl,comp->FullKeypath);
3173 if (!MSI_RecordIsNull(row,6))
3175 LPWSTR deformated;
3176 buffer = MSI_RecordGetString(row,6);
3177 deformat_string(package,buffer,&deformated);
3178 IShellLinkW_SetArguments(sl,deformated);
3179 msi_free(deformated);
3182 if (!MSI_RecordIsNull(row,7))
3184 buffer = MSI_RecordGetString(row,7);
3185 IShellLinkW_SetDescription(sl,buffer);
3188 if (!MSI_RecordIsNull(row,8))
3189 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
3191 if (!MSI_RecordIsNull(row,9))
3193 LPWSTR Path;
3194 INT index;
3196 buffer = MSI_RecordGetString(row,9);
3198 Path = build_icon_path(package,buffer);
3199 index = MSI_RecordGetInteger(row,10);
3201 /* no value means 0 */
3202 if (index == MSI_NULL_INTEGER)
3203 index = 0;
3205 IShellLinkW_SetIconLocation(sl,Path,index);
3206 msi_free(Path);
3209 if (!MSI_RecordIsNull(row,11))
3210 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
3212 if (!MSI_RecordIsNull(row,12))
3214 LPWSTR Path;
3215 buffer = MSI_RecordGetString(row,12);
3216 Path = resolve_folder(package, buffer, FALSE, FALSE, TRUE, NULL);
3217 if (Path)
3218 IShellLinkW_SetWorkingDirectory(sl,Path);
3219 msi_free(Path);
3222 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
3223 IPersistFile_Save(pf,target_file,FALSE);
3225 msi_free(target_file);
3227 err:
3228 if (pf)
3229 IPersistFile_Release( pf );
3230 if (sl)
3231 IShellLinkW_Release( sl );
3233 return ERROR_SUCCESS;
3236 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
3238 UINT rc;
3239 HRESULT res;
3240 MSIQUERY * view;
3241 static const WCHAR Query[] =
3242 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3243 '`','S','h','o','r','t','c','u','t','`',0};
3245 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3246 if (rc != ERROR_SUCCESS)
3247 return ERROR_SUCCESS;
3249 res = CoInitialize( NULL );
3250 if (FAILED (res))
3252 ERR("CoInitialize failed\n");
3253 return ERROR_FUNCTION_FAILED;
3256 rc = MSI_IterateRecords(view, NULL, ITERATE_CreateShortcuts, package);
3257 msiobj_release(&view->hdr);
3259 CoUninitialize();
3261 return rc;
3264 static UINT ITERATE_PublishProduct(MSIRECORD *row, LPVOID param)
3266 MSIPACKAGE* package = (MSIPACKAGE*)param;
3267 HANDLE the_file;
3268 LPWSTR FilePath;
3269 LPCWSTR FileName;
3270 CHAR buffer[1024];
3271 DWORD sz;
3272 UINT rc;
3273 MSIRECORD *uirow;
3275 FileName = MSI_RecordGetString(row,1);
3276 if (!FileName)
3278 ERR("Unable to get FileName\n");
3279 return ERROR_SUCCESS;
3282 FilePath = build_icon_path(package,FileName);
3284 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
3286 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
3287 FILE_ATTRIBUTE_NORMAL, NULL);
3289 if (the_file == INVALID_HANDLE_VALUE)
3291 ERR("Unable to create file %s\n",debugstr_w(FilePath));
3292 msi_free(FilePath);
3293 return ERROR_SUCCESS;
3298 DWORD write;
3299 sz = 1024;
3300 rc = MSI_RecordReadStream(row,2,buffer,&sz);
3301 if (rc != ERROR_SUCCESS)
3303 ERR("Failed to get stream\n");
3304 CloseHandle(the_file);
3305 DeleteFileW(FilePath);
3306 break;
3308 WriteFile(the_file,buffer,sz,&write,NULL);
3309 } while (sz == 1024);
3311 msi_free(FilePath);
3313 CloseHandle(the_file);
3315 uirow = MSI_CreateRecord(1);
3316 MSI_RecordSetStringW(uirow,1,FileName);
3317 ui_actiondata(package,szPublishProduct,uirow);
3318 msiobj_release( &uirow->hdr );
3320 return ERROR_SUCCESS;
3323 static BOOL msi_check_publish(MSIPACKAGE *package)
3325 MSIFEATURE *feature;
3327 LIST_FOR_EACH_ENTRY(feature, &package->features, MSIFEATURE, entry)
3329 if (feature->ActionRequest == INSTALLSTATE_LOCAL)
3330 return TRUE;
3333 return FALSE;
3337 * 99% of the work done here is only done for
3338 * advertised installs. However this is where the
3339 * Icon table is processed and written out
3340 * so that is what I am going to do here.
3342 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
3344 UINT rc;
3345 LPWSTR packname;
3346 MSIQUERY * view;
3347 MSISOURCELISTINFO *info;
3348 MSIMEDIADISK *disk;
3349 static const WCHAR Query[]=
3350 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3351 '`','I','c','o','n','`',0};
3352 /* for registry stuff */
3353 HKEY hkey=0;
3354 HKEY hukey=0;
3355 HKEY hudkey=0, props=0;
3356 HKEY source;
3357 static const WCHAR szProductLanguage[] =
3358 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3359 static const WCHAR szARPProductIcon[] =
3360 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
3361 static const WCHAR szProductVersion[] =
3362 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3363 static const WCHAR szSourceList[] =
3364 {'S','o','u','r','c','e','L','i','s','t',0};
3365 static const WCHAR szEmpty[] = {0};
3366 DWORD langid;
3367 LPWSTR buffer;
3368 DWORD size;
3369 MSIHANDLE hDb, hSumInfo;
3371 /* FIXME: also need to publish if the product is in advertise mode */
3372 if (!msi_check_publish(package))
3373 return ERROR_SUCCESS;
3375 /* write out icon files */
3377 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3378 if (rc == ERROR_SUCCESS)
3380 MSI_IterateRecords(view, NULL, ITERATE_PublishProduct, package);
3381 msiobj_release(&view->hdr);
3384 /* ok there is a lot more done here but i need to figure out what */
3386 if (package->Context == MSIINSTALLCONTEXT_MACHINE)
3388 rc = MSIREG_OpenLocalClassesProductKey(package->ProductCode, &hukey, TRUE);
3389 if (rc != ERROR_SUCCESS)
3390 goto end;
3392 rc = MSIREG_OpenLocalSystemInstallProps(package->ProductCode, &props, TRUE);
3393 if (rc != ERROR_SUCCESS)
3394 goto end;
3396 else
3398 rc = MSIREG_OpenProductsKey(package->ProductCode,&hkey,TRUE);
3399 if (rc != ERROR_SUCCESS)
3400 goto end;
3402 rc = MSIREG_OpenUserProductsKey(package->ProductCode,&hukey,TRUE);
3403 if (rc != ERROR_SUCCESS)
3404 goto end;
3406 rc = MSIREG_OpenCurrentUserInstallProps(package->ProductCode, &props, TRUE);
3407 if (rc != ERROR_SUCCESS)
3408 goto end;
3411 rc = RegCreateKeyW(hukey, szSourceList, &source);
3412 if (rc != ERROR_SUCCESS)
3413 goto end;
3415 RegCloseKey(source);
3417 rc = MSIREG_OpenUserDataProductKey(package->ProductCode,&hudkey,TRUE);
3418 if (rc != ERROR_SUCCESS)
3419 goto end;
3421 buffer = msi_dup_property( package, INSTALLPROPERTY_PRODUCTNAMEW );
3422 msi_reg_set_val_str( hukey, INSTALLPROPERTY_PRODUCTNAMEW, buffer );
3423 msi_free(buffer);
3425 langid = msi_get_property_int( package, szProductLanguage, 0 );
3426 msi_reg_set_val_dword( hukey, INSTALLPROPERTY_LANGUAGEW, langid );
3428 packname = strrchrW( package->PackagePath, '\\' ) + 1;
3429 msi_reg_set_val_str( hukey, INSTALLPROPERTY_PACKAGENAMEW, packname );
3431 /* FIXME */
3432 msi_reg_set_val_dword( hukey, INSTALLPROPERTY_AUTHORIZED_LUA_APPW, 0 );
3433 msi_reg_set_val_dword( props, INSTALLPROPERTY_INSTANCETYPEW, 0 );
3435 buffer = msi_dup_property( package, szARPProductIcon );
3436 if (buffer)
3438 LPWSTR path = build_icon_path(package,buffer);
3439 msi_reg_set_val_str( hukey, INSTALLPROPERTY_PRODUCTICONW, path );
3440 msi_free( path );
3442 msi_free(buffer);
3444 buffer = msi_dup_property( package, szProductVersion );
3445 if (buffer)
3447 DWORD verdword = msi_version_str_to_dword(buffer);
3448 msi_reg_set_val_dword( hukey, INSTALLPROPERTY_VERSIONW, verdword );
3450 msi_free(buffer);
3452 buffer = strrchrW( package->PackagePath, '\\') + 1;
3453 rc = MsiSourceListSetInfoW( package->ProductCode, NULL,
3454 package->Context, MSICODE_PRODUCT,
3455 INSTALLPROPERTY_PACKAGENAMEW, buffer );
3456 if (rc != ERROR_SUCCESS)
3457 goto end;
3459 rc = MsiSourceListSetInfoW( package->ProductCode, NULL,
3460 package->Context, MSICODE_PRODUCT,
3461 INSTALLPROPERTY_MEDIAPACKAGEPATHW, szEmpty );
3462 if (rc != ERROR_SUCCESS)
3463 goto end;
3465 rc = MsiSourceListSetInfoW( package->ProductCode, NULL,
3466 package->Context, MSICODE_PRODUCT,
3467 INSTALLPROPERTY_DISKPROMPTW, szEmpty );
3468 if (rc != ERROR_SUCCESS)
3469 goto end;
3471 /* FIXME: Need to write more keys to the user registry */
3473 hDb= alloc_msihandle( &package->db->hdr );
3474 if (!hDb) {
3475 rc = ERROR_NOT_ENOUGH_MEMORY;
3476 goto end;
3478 rc = MsiGetSummaryInformationW(hDb, NULL, 0, &hSumInfo);
3479 MsiCloseHandle(hDb);
3480 if (rc == ERROR_SUCCESS)
3482 WCHAR guidbuffer[0x200];
3483 size = 0x200;
3484 rc = MsiSummaryInfoGetPropertyW(hSumInfo, 9, NULL, NULL, NULL,
3485 guidbuffer, &size);
3486 if (rc == ERROR_SUCCESS)
3488 /* for now we only care about the first guid */
3489 LPWSTR ptr = strchrW(guidbuffer,';');
3490 if (ptr) *ptr = 0;
3491 msi_reg_set_val_str( hukey, INSTALLPROPERTY_PACKAGECODEW, guidbuffer );
3493 else
3495 ERR("Unable to query Revision_Number...\n");
3496 rc = ERROR_SUCCESS;
3498 MsiCloseHandle(hSumInfo);
3500 else
3502 ERR("Unable to open Summary Information\n");
3503 rc = ERROR_SUCCESS;
3506 /* publish the SourceList info */
3507 LIST_FOR_EACH_ENTRY(info, &package->sourcelist_info, MSISOURCELISTINFO, entry)
3509 if (!lstrcmpW(info->property, INSTALLPROPERTY_LASTUSEDSOURCEW))
3510 msi_set_last_used_source(package->ProductCode, NULL, info->context,
3511 info->options, info->value);
3512 else
3513 MsiSourceListSetInfoW(package->ProductCode, NULL,
3514 info->context, info->options,
3515 info->property, info->value);
3518 LIST_FOR_EACH_ENTRY(disk, &package->sourcelist_media, MSIMEDIADISK, entry)
3520 MsiSourceListAddMediaDiskW(package->ProductCode, NULL,
3521 disk->context, disk->options,
3522 disk->disk_id, disk->volume_label, disk->disk_prompt);
3525 end:
3526 RegCloseKey(hkey);
3527 RegCloseKey(hukey);
3528 RegCloseKey(hudkey);
3529 RegCloseKey(props);
3531 return rc;
3534 static UINT ITERATE_WriteIniValues(MSIRECORD *row, LPVOID param)
3536 MSIPACKAGE *package = (MSIPACKAGE*)param;
3537 LPCWSTR component,section,key,value,identifier,filename,dirproperty;
3538 LPWSTR deformated_section, deformated_key, deformated_value;
3539 LPWSTR folder, fullname = NULL;
3540 MSIRECORD * uirow;
3541 INT action;
3542 MSICOMPONENT *comp;
3543 static const WCHAR szWindowsFolder[] =
3544 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3546 component = MSI_RecordGetString(row, 8);
3547 comp = get_loaded_component(package,component);
3549 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL))
3551 TRACE("Skipping ini file due to disabled component %s\n",
3552 debugstr_w(component));
3554 comp->Action = comp->Installed;
3556 return ERROR_SUCCESS;
3559 comp->Action = INSTALLSTATE_LOCAL;
3561 identifier = MSI_RecordGetString(row,1);
3562 filename = MSI_RecordGetString(row,2);
3563 dirproperty = MSI_RecordGetString(row,3);
3564 section = MSI_RecordGetString(row,4);
3565 key = MSI_RecordGetString(row,5);
3566 value = MSI_RecordGetString(row,6);
3567 action = MSI_RecordGetInteger(row,7);
3569 deformat_string(package,section,&deformated_section);
3570 deformat_string(package,key,&deformated_key);
3571 deformat_string(package,value,&deformated_value);
3573 if (dirproperty)
3575 folder = resolve_folder(package, dirproperty, FALSE, FALSE, TRUE, NULL);
3576 if (!folder)
3577 folder = msi_dup_property( package, dirproperty );
3579 else
3580 folder = msi_dup_property( package, szWindowsFolder );
3582 if (!folder)
3584 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
3585 goto cleanup;
3588 fullname = build_directory_name(2, folder, filename);
3590 if (action == 0)
3592 TRACE("Adding value %s to section %s in %s\n",
3593 debugstr_w(deformated_key), debugstr_w(deformated_section),
3594 debugstr_w(fullname));
3595 WritePrivateProfileStringW(deformated_section, deformated_key,
3596 deformated_value, fullname);
3598 else if (action == 1)
3600 WCHAR returned[10];
3601 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
3602 returned, 10, fullname);
3603 if (returned[0] == 0)
3605 TRACE("Adding value %s to section %s in %s\n",
3606 debugstr_w(deformated_key), debugstr_w(deformated_section),
3607 debugstr_w(fullname));
3609 WritePrivateProfileStringW(deformated_section, deformated_key,
3610 deformated_value, fullname);
3613 else if (action == 3)
3614 FIXME("Append to existing section not yet implemented\n");
3616 uirow = MSI_CreateRecord(4);
3617 MSI_RecordSetStringW(uirow,1,identifier);
3618 MSI_RecordSetStringW(uirow,2,deformated_section);
3619 MSI_RecordSetStringW(uirow,3,deformated_key);
3620 MSI_RecordSetStringW(uirow,4,deformated_value);
3621 ui_actiondata(package,szWriteIniValues,uirow);
3622 msiobj_release( &uirow->hdr );
3623 cleanup:
3624 msi_free(fullname);
3625 msi_free(folder);
3626 msi_free(deformated_key);
3627 msi_free(deformated_value);
3628 msi_free(deformated_section);
3629 return ERROR_SUCCESS;
3632 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
3634 UINT rc;
3635 MSIQUERY * view;
3636 static const WCHAR ExecSeqQuery[] =
3637 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3638 '`','I','n','i','F','i','l','e','`',0};
3640 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3641 if (rc != ERROR_SUCCESS)
3643 TRACE("no IniFile table\n");
3644 return ERROR_SUCCESS;
3647 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteIniValues, package);
3648 msiobj_release(&view->hdr);
3649 return rc;
3652 static UINT ITERATE_SelfRegModules(MSIRECORD *row, LPVOID param)
3654 MSIPACKAGE *package = (MSIPACKAGE*)param;
3655 LPCWSTR filename;
3656 LPWSTR FullName;
3657 MSIFILE *file;
3658 DWORD len;
3659 static const WCHAR ExeStr[] =
3660 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3661 static const WCHAR close[] = {'\"',0};
3662 STARTUPINFOW si;
3663 PROCESS_INFORMATION info;
3664 BOOL brc;
3665 MSIRECORD *uirow;
3666 LPWSTR uipath, p;
3668 memset(&si,0,sizeof(STARTUPINFOW));
3670 filename = MSI_RecordGetString(row,1);
3671 file = get_loaded_file( package, filename );
3673 if (!file)
3675 ERR("Unable to find file id %s\n",debugstr_w(filename));
3676 return ERROR_SUCCESS;
3679 len = strlenW(ExeStr) + strlenW( file->TargetPath ) + 2;
3681 FullName = msi_alloc(len*sizeof(WCHAR));
3682 strcpyW(FullName,ExeStr);
3683 strcatW( FullName, file->TargetPath );
3684 strcatW(FullName,close);
3686 TRACE("Registering %s\n",debugstr_w(FullName));
3687 brc = CreateProcessW(NULL, FullName, NULL, NULL, FALSE, 0, NULL, c_colon,
3688 &si, &info);
3690 if (brc)
3691 msi_dialog_check_messages(info.hProcess);
3693 msi_free(FullName);
3695 /* the UI chunk */
3696 uirow = MSI_CreateRecord( 2 );
3697 uipath = strdupW( file->TargetPath );
3698 p = strrchrW(uipath,'\\');
3699 if (p)
3700 p[0]=0;
3701 MSI_RecordSetStringW( uirow, 1, &p[1] );
3702 MSI_RecordSetStringW( uirow, 2, uipath);
3703 ui_actiondata( package, szSelfRegModules, uirow);
3704 msiobj_release( &uirow->hdr );
3705 msi_free( uipath );
3706 /* FIXME: call ui_progress? */
3708 return ERROR_SUCCESS;
3711 static UINT ACTION_SelfRegModules(MSIPACKAGE *package)
3713 UINT rc;
3714 MSIQUERY * view;
3715 static const WCHAR ExecSeqQuery[] =
3716 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3717 '`','S','e','l','f','R','e','g','`',0};
3719 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3720 if (rc != ERROR_SUCCESS)
3722 TRACE("no SelfReg table\n");
3723 return ERROR_SUCCESS;
3726 MSI_IterateRecords(view, NULL, ITERATE_SelfRegModules, package);
3727 msiobj_release(&view->hdr);
3729 return ERROR_SUCCESS;
3732 static UINT ACTION_PublishFeatures(MSIPACKAGE *package)
3734 MSIFEATURE *feature;
3735 UINT rc;
3736 HKEY hkey=0;
3737 HKEY hukey=0;
3738 HKEY userdata=0;
3740 if (!msi_check_publish(package))
3741 return ERROR_SUCCESS;
3743 rc = MSIREG_OpenFeaturesKey(package->ProductCode,&hkey,TRUE);
3744 if (rc != ERROR_SUCCESS)
3745 goto end;
3747 rc = MSIREG_OpenUserFeaturesKey(package->ProductCode,&hukey,TRUE);
3748 if (rc != ERROR_SUCCESS)
3749 goto end;
3751 rc = MSIREG_OpenUserDataFeaturesKey(package->ProductCode, &userdata, TRUE);
3752 if (rc != ERROR_SUCCESS)
3753 goto end;
3755 /* here the guids are base 85 encoded */
3756 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
3758 ComponentList *cl;
3759 LPWSTR data = NULL;
3760 GUID clsid;
3761 INT size;
3762 BOOL absent = FALSE;
3763 MSIRECORD *uirow;
3765 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ) &&
3766 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_SOURCE ) &&
3767 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED ))
3768 absent = TRUE;
3770 size = 1;
3771 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3773 size += 21;
3775 if (feature->Feature_Parent)
3776 size += strlenW( feature->Feature_Parent )+2;
3778 data = msi_alloc(size * sizeof(WCHAR));
3780 data[0] = 0;
3781 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
3783 MSICOMPONENT* component = cl->component;
3784 WCHAR buf[21];
3786 buf[0] = 0;
3787 if (component->ComponentId)
3789 TRACE("From %s\n",debugstr_w(component->ComponentId));
3790 CLSIDFromString(component->ComponentId, &clsid);
3791 encode_base85_guid(&clsid,buf);
3792 TRACE("to %s\n",debugstr_w(buf));
3793 strcatW(data,buf);
3797 if (feature->Feature_Parent)
3799 static const WCHAR sep[] = {'\2',0};
3800 strcatW(data,sep);
3801 strcatW(data,feature->Feature_Parent);
3804 msi_reg_set_val_str( hkey, feature->Feature, data );
3805 msi_reg_set_val_str( userdata, feature->Feature, data );
3806 msi_free(data);
3808 size = 0;
3809 if (feature->Feature_Parent)
3810 size = strlenW(feature->Feature_Parent)*sizeof(WCHAR);
3811 if (!absent)
3813 static const WCHAR emptyW[] = {0};
3814 size += sizeof(WCHAR);
3815 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3816 (LPBYTE)(feature->Feature_Parent ? feature->Feature_Parent : emptyW),size);
3818 else
3820 size += 2*sizeof(WCHAR);
3821 data = msi_alloc(size);
3822 data[0] = 0x6;
3823 data[1] = 0;
3824 if (feature->Feature_Parent)
3825 strcpyW( &data[1], feature->Feature_Parent );
3826 RegSetValueExW(hukey,feature->Feature,0,REG_SZ,
3827 (LPBYTE)data,size);
3828 msi_free(data);
3831 /* the UI chunk */
3832 uirow = MSI_CreateRecord( 1 );
3833 MSI_RecordSetStringW( uirow, 1, feature->Feature );
3834 ui_actiondata( package, szPublishFeatures, uirow);
3835 msiobj_release( &uirow->hdr );
3836 /* FIXME: call ui_progress? */
3839 end:
3840 RegCloseKey(hkey);
3841 RegCloseKey(hukey);
3842 return rc;
3845 static UINT msi_unpublish_feature(MSIPACKAGE *package, MSIFEATURE *feature)
3847 UINT r;
3848 HKEY hkey;
3850 TRACE("unpublishing feature %s\n", debugstr_w(feature->Feature));
3852 r = MSIREG_OpenUserFeaturesKey(package->ProductCode, &hkey, FALSE);
3853 if (r == ERROR_SUCCESS)
3855 RegDeleteValueW(hkey, feature->Feature);
3856 RegCloseKey(hkey);
3859 r = MSIREG_OpenUserDataFeaturesKey(package->ProductCode, &hkey, FALSE);
3860 if (r == ERROR_SUCCESS)
3862 RegDeleteValueW(hkey, feature->Feature);
3863 RegCloseKey(hkey);
3866 return ERROR_SUCCESS;
3869 static BOOL msi_check_unpublish(MSIPACKAGE *package)
3871 MSIFEATURE *feature;
3873 LIST_FOR_EACH_ENTRY(feature, &package->features, MSIFEATURE, entry)
3875 if (feature->ActionRequest != INSTALLSTATE_ABSENT)
3876 return FALSE;
3879 return TRUE;
3882 static UINT ACTION_UnpublishFeatures(MSIPACKAGE *package)
3884 MSIFEATURE *feature;
3886 if (!msi_check_unpublish(package))
3887 return ERROR_SUCCESS;
3889 LIST_FOR_EACH_ENTRY(feature, &package->features, MSIFEATURE, entry)
3891 msi_unpublish_feature(package, feature);
3894 return ERROR_SUCCESS;
3897 static UINT msi_get_local_package_name( LPWSTR path )
3899 static const WCHAR szInstaller[] = {
3900 '\\','I','n','s','t','a','l','l','e','r','\\',0};
3901 static const WCHAR fmt[] = { '%','x','.','m','s','i',0};
3902 DWORD time, len, i;
3903 HANDLE handle;
3905 time = GetTickCount();
3906 GetWindowsDirectoryW( path, MAX_PATH );
3907 lstrcatW( path, szInstaller );
3908 CreateDirectoryW( path, NULL );
3910 len = lstrlenW(path);
3911 for (i=0; i<0x10000; i++)
3913 snprintfW( &path[len], MAX_PATH - len, fmt, (time+i)&0xffff );
3914 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
3915 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
3916 if (handle != INVALID_HANDLE_VALUE)
3918 CloseHandle(handle);
3919 break;
3921 if (GetLastError() != ERROR_FILE_EXISTS &&
3922 GetLastError() != ERROR_SHARING_VIOLATION)
3923 return ERROR_FUNCTION_FAILED;
3926 return ERROR_SUCCESS;
3929 static UINT msi_make_package_local( MSIPACKAGE *package, HKEY hkey )
3931 WCHAR packagefile[MAX_PATH];
3932 HKEY props;
3933 UINT r;
3935 r = msi_get_local_package_name( packagefile );
3936 if (r != ERROR_SUCCESS)
3937 return r;
3939 TRACE("Copying to local package %s\n",debugstr_w(packagefile));
3941 r = CopyFileW( package->db->path, packagefile, FALSE);
3943 if (!r)
3945 ERR("Unable to copy package (%s -> %s) (error %d)\n",
3946 debugstr_w(package->db->path), debugstr_w(packagefile), GetLastError());
3947 return ERROR_FUNCTION_FAILED;
3950 msi_reg_set_val_str( hkey, INSTALLPROPERTY_LOCALPACKAGEW, packagefile );
3952 r = MSIREG_OpenCurrentUserInstallProps(package->ProductCode, &props, TRUE);
3953 if (r != ERROR_SUCCESS)
3954 return r;
3956 msi_reg_set_val_str(props, INSTALLPROPERTY_LOCALPACKAGEW, packagefile);
3957 RegCloseKey(props);
3958 return ERROR_SUCCESS;
3961 static UINT msi_write_uninstall_property_vals( MSIPACKAGE *package, HKEY hkey )
3963 LPWSTR prop, val, key;
3964 static const LPCSTR propval[] = {
3965 "ARPAUTHORIZEDCDFPREFIX", "AuthorizedCDFPrefix",
3966 "ARPCONTACT", "Contact",
3967 "ARPCOMMENTS", "Comments",
3968 "ProductName", "DisplayName",
3969 "ProductVersion", "DisplayVersion",
3970 "ARPHELPLINK", "HelpLink",
3971 "ARPHELPTELEPHONE", "HelpTelephone",
3972 "ARPINSTALLLOCATION", "InstallLocation",
3973 "SourceDir", "InstallSource",
3974 "Manufacturer", "Publisher",
3975 "ARPREADME", "Readme",
3976 "ARPSIZE", "Size",
3977 "ARPURLINFOABOUT", "URLInfoAbout",
3978 "ARPURLUPDATEINFO", "URLUpdateInfo",
3979 NULL,
3981 const LPCSTR *p = propval;
3983 while( *p )
3985 prop = strdupAtoW( *p++ );
3986 key = strdupAtoW( *p++ );
3987 val = msi_dup_property( package, prop );
3988 msi_reg_set_val_str( hkey, key, val );
3989 msi_free(val);
3990 msi_free(key);
3991 msi_free(prop);
3993 return ERROR_SUCCESS;
3996 static UINT ACTION_RegisterProduct(MSIPACKAGE *package)
3998 HKEY hkey=0;
3999 HKEY hudkey=0, props=0;
4000 LPWSTR buffer = NULL;
4001 UINT rc;
4002 DWORD size, langid;
4003 static const WCHAR szWindowsInstaller[] =
4004 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
4005 static const WCHAR szUpgradeCode[] =
4006 {'U','p','g','r','a','d','e','C','o','d','e',0};
4007 static const WCHAR modpath_fmt[] =
4008 {'M','s','i','E','x','e','c','.','e','x','e',' ',
4009 '/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
4010 static const WCHAR szModifyPath[] =
4011 {'M','o','d','i','f','y','P','a','t','h',0};
4012 static const WCHAR szUninstallString[] =
4013 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
4014 static const WCHAR szEstimatedSize[] =
4015 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
4016 static const WCHAR szProductLanguage[] =
4017 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
4018 static const WCHAR szProductVersion[] =
4019 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
4020 static const WCHAR szProductName[] =
4021 {'P','r','o','d','u','c','t','N','a','m','e',0};
4022 static const WCHAR szDisplayName[] =
4023 {'D','i','s','p','l','a','y','N','a','m','e',0};
4024 static const WCHAR szDisplayVersion[] =
4025 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
4026 static const WCHAR szManufacturer[] =
4027 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
4029 SYSTEMTIME systime;
4030 static const WCHAR date_fmt[] = {'%','i','%','0','2','i','%','0','2','i',0};
4031 LPWSTR upgrade_code;
4032 WCHAR szDate[9];
4034 /* FIXME: also need to publish if the product is in advertise mode */
4035 if (!msi_check_publish(package))
4036 return ERROR_SUCCESS;
4038 rc = MSIREG_OpenUninstallKey(package->ProductCode,&hkey,TRUE);
4039 if (rc != ERROR_SUCCESS)
4040 return rc;
4042 if (package->Context == MSIINSTALLCONTEXT_MACHINE)
4044 rc = MSIREG_OpenLocalSystemInstallProps(package->ProductCode, &props, TRUE);
4045 if (rc != ERROR_SUCCESS)
4046 return rc;
4048 else
4050 rc = MSIREG_OpenCurrentUserInstallProps(package->ProductCode, &props, TRUE);
4051 if (rc != ERROR_SUCCESS)
4052 return rc;
4055 /* dump all the info i can grab */
4056 /* FIXME: Flesh out more information */
4058 msi_write_uninstall_property_vals( package, hkey );
4060 msi_reg_set_val_dword( hkey, szWindowsInstaller, 1 );
4062 msi_make_package_local( package, hkey );
4064 /* do ModifyPath and UninstallString */
4065 size = deformat_string(package,modpath_fmt,&buffer);
4066 RegSetValueExW(hkey,szModifyPath,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
4067 RegSetValueExW(hkey,szUninstallString,0,REG_EXPAND_SZ,(LPBYTE)buffer,size);
4068 msi_free(buffer);
4070 /* FIXME: Write real Estimated Size when we have it */
4071 msi_reg_set_val_dword( hkey, szEstimatedSize, 0 );
4073 buffer = msi_dup_property( package, szProductName );
4074 msi_reg_set_val_str( props, szDisplayName, buffer );
4075 msi_free(buffer);
4077 buffer = msi_dup_property( package, cszSourceDir );
4078 msi_reg_set_val_str( props, INSTALLPROPERTY_INSTALLSOURCEW, buffer);
4079 msi_free(buffer);
4081 buffer = msi_dup_property( package, szManufacturer );
4082 msi_reg_set_val_str( props, INSTALLPROPERTY_PUBLISHERW, buffer);
4083 msi_free(buffer);
4085 GetLocalTime(&systime);
4086 sprintfW(szDate,date_fmt,systime.wYear,systime.wMonth,systime.wDay);
4087 msi_reg_set_val_str( hkey, INSTALLPROPERTY_INSTALLDATEW, szDate );
4088 msi_reg_set_val_str( props, INSTALLPROPERTY_INSTALLDATEW, szDate );
4090 langid = msi_get_property_int( package, szProductLanguage, 0 );
4091 msi_reg_set_val_dword( hkey, INSTALLPROPERTY_LANGUAGEW, langid );
4093 buffer = msi_dup_property( package, szProductVersion );
4094 msi_reg_set_val_str( props, szDisplayVersion, buffer );
4095 if (buffer)
4097 DWORD verdword = msi_version_str_to_dword(buffer);
4099 msi_reg_set_val_dword( hkey, INSTALLPROPERTY_VERSIONW, verdword );
4100 msi_reg_set_val_dword( props, INSTALLPROPERTY_VERSIONW, verdword );
4101 msi_reg_set_val_dword( hkey, INSTALLPROPERTY_VERSIONMAJORW, verdword>>24 );
4102 msi_reg_set_val_dword( props, INSTALLPROPERTY_VERSIONMAJORW, verdword>>24 );
4103 msi_reg_set_val_dword( hkey, INSTALLPROPERTY_VERSIONMINORW, (verdword>>16)&0x00FF );
4104 msi_reg_set_val_dword( props, INSTALLPROPERTY_VERSIONMINORW, (verdword>>16)&0x00FF );
4106 msi_free(buffer);
4108 /* Handle Upgrade Codes */
4109 upgrade_code = msi_dup_property( package, szUpgradeCode );
4110 if (upgrade_code)
4112 HKEY hkey2;
4113 WCHAR squashed[33];
4114 MSIREG_OpenUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
4115 squash_guid(package->ProductCode,squashed);
4116 msi_reg_set_val_str( hkey2, squashed, NULL );
4117 RegCloseKey(hkey2);
4118 MSIREG_OpenUserUpgradeCodesKey(upgrade_code, &hkey2, TRUE);
4119 squash_guid(package->ProductCode,squashed);
4120 msi_reg_set_val_str( hkey2, squashed, NULL );
4121 RegCloseKey(hkey2);
4123 msi_free(upgrade_code);
4126 RegCloseKey(hkey);
4128 rc = MSIREG_OpenUserDataProductKey(package->ProductCode, &hudkey, TRUE);
4129 if (rc != ERROR_SUCCESS)
4130 return rc;
4132 RegCloseKey(hudkey);
4134 msi_reg_set_val_dword( props, szWindowsInstaller, 1 );
4135 RegCloseKey(props);
4137 return ERROR_SUCCESS;
4140 static UINT ACTION_InstallExecute(MSIPACKAGE *package)
4142 return execute_script(package,INSTALL_SCRIPT);
4145 static UINT msi_unpublish_product(MSIPACKAGE *package)
4147 LPWSTR remove = NULL;
4148 LPWSTR *features = NULL;
4149 BOOL full_uninstall = TRUE;
4150 MSIFEATURE *feature;
4152 static const WCHAR szRemove[] = {'R','E','M','O','V','E',0};
4153 static const WCHAR szAll[] = {'A','L','L',0};
4155 remove = msi_dup_property(package, szRemove);
4156 if (!remove)
4157 return ERROR_SUCCESS;
4159 features = msi_split_string(remove, ',');
4160 if (!features)
4162 msi_free(remove);
4163 ERR("REMOVE feature list is empty!\n");
4164 return ERROR_FUNCTION_FAILED;
4167 if (!lstrcmpW(features[0], szAll))
4168 full_uninstall = TRUE;
4169 else
4171 LIST_FOR_EACH_ENTRY(feature, &package->features, MSIFEATURE, entry)
4173 if (feature->Action != INSTALLSTATE_ABSENT)
4174 full_uninstall = FALSE;
4178 if (!full_uninstall)
4179 goto done;
4181 MSIREG_DeleteProductKey(package->ProductCode);
4182 MSIREG_DeleteUserProductKey(package->ProductCode);
4183 MSIREG_DeleteUserDataProductKey(package->ProductCode);
4184 MSIREG_DeleteUserFeaturesKey(package->ProductCode);
4185 MSIREG_DeleteUninstallKey(package->ProductCode);
4187 done:
4188 msi_free(remove);
4189 msi_free(features);
4190 return ERROR_SUCCESS;
4193 static UINT ACTION_InstallFinalize(MSIPACKAGE *package)
4195 UINT rc;
4197 rc = msi_unpublish_product(package);
4198 if (rc != ERROR_SUCCESS)
4199 return rc;
4201 /* turn off scheduling */
4202 package->script->CurrentlyScripting= FALSE;
4204 /* first do the same as an InstallExecute */
4205 rc = ACTION_InstallExecute(package);
4206 if (rc != ERROR_SUCCESS)
4207 return rc;
4209 /* then handle Commit Actions */
4210 rc = execute_script(package,COMMIT_SCRIPT);
4212 return rc;
4215 UINT ACTION_ForceReboot(MSIPACKAGE *package)
4217 static const WCHAR RunOnce[] = {
4218 'S','o','f','t','w','a','r','e','\\',
4219 'M','i','c','r','o','s','o','f','t','\\',
4220 'W','i','n','d','o','w','s','\\',
4221 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4222 'R','u','n','O','n','c','e',0};
4223 static const WCHAR InstallRunOnce[] = {
4224 'S','o','f','t','w','a','r','e','\\',
4225 'M','i','c','r','o','s','o','f','t','\\',
4226 'W','i','n','d','o','w','s','\\',
4227 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4228 'I','n','s','t','a','l','l','e','r','\\',
4229 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
4231 static const WCHAR msiexec_fmt[] = {
4232 '%','s',
4233 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
4234 '\"','%','s','\"',0};
4235 static const WCHAR install_fmt[] = {
4236 '/','I',' ','\"','%','s','\"',' ',
4237 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
4238 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
4239 WCHAR buffer[256], sysdir[MAX_PATH];
4240 HKEY hkey;
4241 WCHAR squished_pc[100];
4243 squash_guid(package->ProductCode,squished_pc);
4245 GetSystemDirectoryW(sysdir, sizeof(sysdir)/sizeof(sysdir[0]));
4246 RegCreateKeyW(HKEY_LOCAL_MACHINE,RunOnce,&hkey);
4247 snprintfW(buffer,sizeof(buffer)/sizeof(buffer[0]),msiexec_fmt,sysdir,
4248 squished_pc);
4250 msi_reg_set_val_str( hkey, squished_pc, buffer );
4251 RegCloseKey(hkey);
4253 TRACE("Reboot command %s\n",debugstr_w(buffer));
4255 RegCreateKeyW(HKEY_LOCAL_MACHINE,InstallRunOnce,&hkey);
4256 sprintfW(buffer,install_fmt,package->ProductCode,squished_pc);
4258 msi_reg_set_val_str( hkey, squished_pc, buffer );
4259 RegCloseKey(hkey);
4261 return ERROR_INSTALL_SUSPEND;
4264 static UINT ACTION_ResolveSource(MSIPACKAGE* package)
4266 DWORD attrib;
4267 UINT rc;
4270 * We are currently doing what should be done here in the top level Install
4271 * however for Administrative and uninstalls this step will be needed
4273 if (!package->PackagePath)
4274 return ERROR_SUCCESS;
4276 msi_set_sourcedir_props(package, TRUE);
4278 attrib = GetFileAttributesW(package->db->path);
4279 if (attrib == INVALID_FILE_ATTRIBUTES)
4281 LPWSTR prompt;
4282 LPWSTR msg;
4283 DWORD size = 0;
4285 rc = MsiSourceListGetInfoW(package->ProductCode, NULL,
4286 package->Context, MSICODE_PRODUCT,
4287 INSTALLPROPERTY_DISKPROMPTW,NULL,&size);
4288 if (rc == ERROR_MORE_DATA)
4290 prompt = msi_alloc(size * sizeof(WCHAR));
4291 MsiSourceListGetInfoW(package->ProductCode, NULL,
4292 package->Context, MSICODE_PRODUCT,
4293 INSTALLPROPERTY_DISKPROMPTW,prompt,&size);
4295 else
4296 prompt = strdupW(package->db->path);
4298 msg = generate_error_string(package,1302,1,prompt);
4299 while(attrib == INVALID_FILE_ATTRIBUTES)
4301 rc = MessageBoxW(NULL,msg,NULL,MB_OKCANCEL);
4302 if (rc == IDCANCEL)
4304 rc = ERROR_INSTALL_USEREXIT;
4305 break;
4307 attrib = GetFileAttributesW(package->db->path);
4309 msi_free(prompt);
4310 rc = ERROR_SUCCESS;
4312 else
4313 return ERROR_SUCCESS;
4315 return rc;
4318 static UINT ACTION_RegisterUser(MSIPACKAGE *package)
4320 HKEY hkey=0;
4321 LPWSTR buffer;
4322 LPWSTR productid;
4323 UINT rc,i;
4325 static const WCHAR szPropKeys[][80] =
4327 {'P','r','o','d','u','c','t','I','D',0},
4328 {'U','S','E','R','N','A','M','E',0},
4329 {'C','O','M','P','A','N','Y','N','A','M','E',0},
4330 {0},
4333 static const WCHAR szRegKeys[][80] =
4335 {'P','r','o','d','u','c','t','I','D',0},
4336 {'R','e','g','O','w','n','e','r',0},
4337 {'R','e','g','C','o','m','p','a','n','y',0},
4338 {0},
4341 if (msi_check_unpublish(package))
4343 MSIREG_DeleteUserDataProductKey(package->ProductCode);
4344 return ERROR_SUCCESS;
4347 productid = msi_dup_property( package, INSTALLPROPERTY_PRODUCTIDW );
4348 if (!productid)
4349 return ERROR_SUCCESS;
4351 rc = MSIREG_OpenCurrentUserInstallProps(package->ProductCode, &hkey, TRUE);
4352 if (rc != ERROR_SUCCESS)
4353 goto end;
4355 for( i = 0; szPropKeys[i][0]; i++ )
4357 buffer = msi_dup_property( package, szPropKeys[i] );
4358 msi_reg_set_val_str( hkey, szRegKeys[i], buffer );
4359 msi_free( buffer );
4362 end:
4363 msi_free(productid);
4364 RegCloseKey(hkey);
4366 /* FIXME: call ui_actiondata */
4368 return rc;
4372 static UINT ACTION_ExecuteAction(MSIPACKAGE *package)
4374 UINT rc;
4376 package->script->InWhatSequence |= SEQUENCE_EXEC;
4377 rc = ACTION_ProcessExecSequence(package,FALSE);
4378 return rc;
4382 static UINT ITERATE_PublishComponent(MSIRECORD *rec, LPVOID param)
4384 MSIPACKAGE *package = (MSIPACKAGE*)param;
4385 LPCWSTR compgroupid=NULL;
4386 LPCWSTR feature=NULL;
4387 LPCWSTR text = NULL;
4388 LPCWSTR qualifier = NULL;
4389 LPCWSTR component = NULL;
4390 LPWSTR advertise = NULL;
4391 LPWSTR output = NULL;
4392 HKEY hkey;
4393 UINT rc = ERROR_SUCCESS;
4394 MSICOMPONENT *comp;
4395 DWORD sz = 0;
4396 MSIRECORD *uirow;
4398 component = MSI_RecordGetString(rec,3);
4399 comp = get_loaded_component(package,component);
4401 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL ) &&
4402 !ACTION_VerifyComponentForAction( comp, INSTALLSTATE_SOURCE ) &&
4403 !ACTION_VerifyComponentForAction( comp, INSTALLSTATE_ADVERTISED ))
4405 TRACE("Skipping: Component %s not scheduled for install\n",
4406 debugstr_w(component));
4408 return ERROR_SUCCESS;
4411 compgroupid = MSI_RecordGetString(rec,1);
4412 qualifier = MSI_RecordGetString(rec,2);
4414 rc = MSIREG_OpenUserComponentsKey(compgroupid, &hkey, TRUE);
4415 if (rc != ERROR_SUCCESS)
4416 goto end;
4418 text = MSI_RecordGetString(rec,4);
4419 feature = MSI_RecordGetString(rec,5);
4421 advertise = create_component_advertise_string(package, comp, feature);
4423 sz = strlenW(advertise);
4425 if (text)
4426 sz += lstrlenW(text);
4428 sz+=3;
4429 sz *= sizeof(WCHAR);
4431 output = msi_alloc_zero(sz);
4432 strcpyW(output,advertise);
4433 msi_free(advertise);
4435 if (text)
4436 strcatW(output,text);
4438 msi_reg_set_val_multi_str( hkey, qualifier, output );
4440 end:
4441 RegCloseKey(hkey);
4442 msi_free(output);
4444 /* the UI chunk */
4445 uirow = MSI_CreateRecord( 2 );
4446 MSI_RecordSetStringW( uirow, 1, compgroupid );
4447 MSI_RecordSetStringW( uirow, 2, qualifier);
4448 ui_actiondata( package, szPublishComponents, uirow);
4449 msiobj_release( &uirow->hdr );
4450 /* FIXME: call ui_progress? */
4452 return rc;
4456 * At present I am ignorning the advertised components part of this and only
4457 * focusing on the qualified component sets
4459 static UINT ACTION_PublishComponents(MSIPACKAGE *package)
4461 UINT rc;
4462 MSIQUERY * view;
4463 static const WCHAR ExecSeqQuery[] =
4464 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4465 '`','P','u','b','l','i','s','h',
4466 'C','o','m','p','o','n','e','n','t','`',0};
4468 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4469 if (rc != ERROR_SUCCESS)
4470 return ERROR_SUCCESS;
4472 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishComponent, package);
4473 msiobj_release(&view->hdr);
4475 return rc;
4478 static UINT ITERATE_InstallService(MSIRECORD *rec, LPVOID param)
4480 MSIPACKAGE *package = (MSIPACKAGE*)param;
4481 MSIRECORD *row;
4482 MSIFILE *file;
4483 SC_HANDLE hscm, service = NULL;
4484 LPCWSTR comp, depends, pass;
4485 LPWSTR name = NULL, disp = NULL;
4486 LPCWSTR load_order, serv_name, key;
4487 DWORD serv_type, start_type;
4488 DWORD err_control;
4490 static const WCHAR query[] =
4491 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
4492 '`','C','o','m','p','o','n','e','n','t','`',' ',
4493 'W','H','E','R','E',' ',
4494 '`','C','o','m','p','o','n','e','n','t','`',' ',
4495 '=','\'','%','s','\'',0};
4497 hscm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, GENERIC_WRITE);
4498 if (!hscm)
4500 ERR("Failed to open the SC Manager!\n");
4501 goto done;
4504 start_type = MSI_RecordGetInteger(rec, 5);
4505 if (start_type == SERVICE_BOOT_START || start_type == SERVICE_SYSTEM_START)
4506 goto done;
4508 depends = MSI_RecordGetString(rec, 8);
4509 if (depends && *depends)
4510 FIXME("Dependency list unhandled!\n");
4512 deformat_string(package, MSI_RecordGetString(rec, 2), &name);
4513 deformat_string(package, MSI_RecordGetString(rec, 3), &disp);
4514 serv_type = MSI_RecordGetInteger(rec, 4);
4515 err_control = MSI_RecordGetInteger(rec, 6);
4516 load_order = MSI_RecordGetString(rec, 7);
4517 serv_name = MSI_RecordGetString(rec, 9);
4518 pass = MSI_RecordGetString(rec, 10);
4519 comp = MSI_RecordGetString(rec, 12);
4521 /* fetch the service path */
4522 row = MSI_QueryGetRecord(package->db, query, comp);
4523 if (!row)
4525 ERR("Control query failed!\n");
4526 goto done;
4529 key = MSI_RecordGetString(row, 6);
4531 file = get_loaded_file(package, key);
4532 msiobj_release(&row->hdr);
4533 if (!file)
4535 ERR("Failed to load the service file\n");
4536 goto done;
4539 service = CreateServiceW(hscm, name, disp, GENERIC_ALL, serv_type,
4540 start_type, err_control, file->TargetPath,
4541 load_order, NULL, NULL, serv_name, pass);
4542 if (!service)
4544 if (GetLastError() != ERROR_SERVICE_EXISTS)
4545 ERR("Failed to create service %s: %d\n", debugstr_w(name), GetLastError());
4548 done:
4549 CloseServiceHandle(service);
4550 CloseServiceHandle(hscm);
4551 msi_free(name);
4552 msi_free(disp);
4554 return ERROR_SUCCESS;
4557 static UINT ACTION_InstallServices( MSIPACKAGE *package )
4559 UINT rc;
4560 MSIQUERY * view;
4561 static const WCHAR ExecSeqQuery[] =
4562 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4563 'S','e','r','v','i','c','e','I','n','s','t','a','l','l',0};
4565 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4566 if (rc != ERROR_SUCCESS)
4567 return ERROR_SUCCESS;
4569 rc = MSI_IterateRecords(view, NULL, ITERATE_InstallService, package);
4570 msiobj_release(&view->hdr);
4572 return rc;
4575 /* converts arg1[~]arg2[~]arg3 to a list of ptrs to the strings */
4576 static LPCWSTR *msi_service_args_to_vector(LPWSTR args, DWORD *numargs)
4578 LPCWSTR *vector, *temp_vector;
4579 LPWSTR p, q;
4580 DWORD sep_len;
4582 static const WCHAR separator[] = {'[','~',']',0};
4584 *numargs = 0;
4585 sep_len = sizeof(separator) / sizeof(WCHAR) - 1;
4587 if (!args)
4588 return NULL;
4590 vector = msi_alloc(sizeof(LPWSTR));
4591 if (!vector)
4592 return NULL;
4594 p = args;
4597 (*numargs)++;
4598 vector[*numargs - 1] = p;
4600 if ((q = strstrW(p, separator)))
4602 *q = '\0';
4604 temp_vector = msi_realloc(vector, (*numargs + 1) * sizeof(LPWSTR));
4605 if (!temp_vector)
4607 msi_free(vector);
4608 return NULL;
4610 vector = temp_vector;
4612 p = q + sep_len;
4614 } while (q);
4616 return vector;
4619 static UINT ITERATE_StartService(MSIRECORD *rec, LPVOID param)
4621 MSIPACKAGE *package = (MSIPACKAGE *)param;
4622 MSICOMPONENT *comp;
4623 SC_HANDLE scm, service = NULL;
4624 LPCWSTR name, *vector = NULL;
4625 LPWSTR args;
4626 DWORD event, numargs;
4627 UINT r = ERROR_FUNCTION_FAILED;
4629 comp = get_loaded_component(package, MSI_RecordGetString(rec, 6));
4630 if (!comp || comp->Action == INSTALLSTATE_UNKNOWN || comp->Action == INSTALLSTATE_ABSENT)
4631 return ERROR_SUCCESS;
4633 name = MSI_RecordGetString(rec, 2);
4634 event = MSI_RecordGetInteger(rec, 3);
4635 args = strdupW(MSI_RecordGetString(rec, 4));
4637 if (!(event & msidbServiceControlEventStart))
4638 return ERROR_SUCCESS;
4640 scm = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT);
4641 if (!scm)
4643 ERR("Failed to open the service control manager\n");
4644 goto done;
4647 service = OpenServiceW(scm, name, SERVICE_START);
4648 if (!service)
4650 ERR("Failed to open service %s\n", debugstr_w(name));
4651 goto done;
4654 vector = msi_service_args_to_vector(args, &numargs);
4656 if (!StartServiceW(service, numargs, vector))
4658 ERR("Failed to start service %s\n", debugstr_w(name));
4659 goto done;
4662 r = ERROR_SUCCESS;
4664 done:
4665 CloseServiceHandle(service);
4666 CloseServiceHandle(scm);
4668 msi_free(args);
4669 msi_free(vector);
4670 return r;
4673 static UINT ACTION_StartServices( MSIPACKAGE *package )
4675 UINT rc;
4676 MSIQUERY *view;
4678 static const WCHAR query[] = {
4679 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4680 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
4682 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
4683 if (rc != ERROR_SUCCESS)
4684 return ERROR_SUCCESS;
4686 rc = MSI_IterateRecords(view, NULL, ITERATE_StartService, package);
4687 msiobj_release(&view->hdr);
4689 return rc;
4692 static BOOL stop_service_dependents(SC_HANDLE scm, SC_HANDLE service)
4694 DWORD i, needed, count;
4695 ENUM_SERVICE_STATUSW *dependencies;
4696 SERVICE_STATUS ss;
4697 SC_HANDLE depserv;
4699 if (EnumDependentServicesW(service, SERVICE_ACTIVE, NULL,
4700 0, &needed, &count))
4701 return TRUE;
4703 if (GetLastError() != ERROR_MORE_DATA)
4704 return FALSE;
4706 dependencies = msi_alloc(needed);
4707 if (!dependencies)
4708 return FALSE;
4710 if (!EnumDependentServicesW(service, SERVICE_ACTIVE, dependencies,
4711 needed, &needed, &count))
4712 goto error;
4714 for (i = 0; i < count; i++)
4716 depserv = OpenServiceW(scm, dependencies[i].lpServiceName,
4717 SERVICE_STOP | SERVICE_QUERY_STATUS);
4718 if (!depserv)
4719 goto error;
4721 if (!ControlService(depserv, SERVICE_CONTROL_STOP, &ss))
4722 goto error;
4725 return TRUE;
4727 error:
4728 msi_free(dependencies);
4729 return FALSE;
4732 static UINT ITERATE_StopService(MSIRECORD *rec, LPVOID param)
4734 MSIPACKAGE *package = (MSIPACKAGE *)param;
4735 MSICOMPONENT *comp;
4736 SERVICE_STATUS status;
4737 SERVICE_STATUS_PROCESS ssp;
4738 SC_HANDLE scm = NULL, service = NULL;
4739 LPWSTR name, args;
4740 DWORD event, needed;
4742 event = MSI_RecordGetInteger(rec, 3);
4743 if (!(event & msidbServiceControlEventStop))
4744 return ERROR_SUCCESS;
4746 comp = get_loaded_component(package, MSI_RecordGetString(rec, 6));
4747 if (!comp || comp->Action == INSTALLSTATE_UNKNOWN || comp->Action == INSTALLSTATE_ABSENT)
4748 return ERROR_SUCCESS;
4750 deformat_string(package, MSI_RecordGetString(rec, 2), &name);
4751 deformat_string(package, MSI_RecordGetString(rec, 4), &args);
4752 args = strdupW(MSI_RecordGetString(rec, 4));
4754 scm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
4755 if (!scm)
4757 WARN("Failed to open the SCM: %d\n", GetLastError());
4758 goto done;
4761 service = OpenServiceW(scm, name,
4762 SERVICE_STOP |
4763 SERVICE_QUERY_STATUS |
4764 SERVICE_ENUMERATE_DEPENDENTS);
4765 if (!service)
4767 WARN("Failed to open service (%s): %d\n",
4768 debugstr_w(name), GetLastError());
4769 goto done;
4772 if (!QueryServiceStatusEx(service, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp,
4773 sizeof(SERVICE_STATUS_PROCESS), &needed))
4775 WARN("Failed to query service status (%s): %d\n",
4776 debugstr_w(name), GetLastError());
4777 goto done;
4780 if (ssp.dwCurrentState == SERVICE_STOPPED)
4781 goto done;
4783 stop_service_dependents(scm, service);
4785 if (!ControlService(service, SERVICE_CONTROL_STOP, &status))
4786 WARN("Failed to stop service (%s): %d\n", debugstr_w(name), GetLastError());
4788 done:
4789 CloseServiceHandle(service);
4790 CloseServiceHandle(scm);
4791 msi_free(name);
4792 msi_free(args);
4794 return ERROR_SUCCESS;
4797 static UINT ACTION_StopServices( MSIPACKAGE *package )
4799 UINT rc;
4800 MSIQUERY *view;
4802 static const WCHAR query[] = {
4803 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4804 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
4806 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
4807 if (rc != ERROR_SUCCESS)
4808 return ERROR_SUCCESS;
4810 rc = MSI_IterateRecords(view, NULL, ITERATE_StopService, package);
4811 msiobj_release(&view->hdr);
4813 return rc;
4816 static MSIFILE *msi_find_file( MSIPACKAGE *package, LPCWSTR filename )
4818 MSIFILE *file;
4820 LIST_FOR_EACH_ENTRY(file, &package->files, MSIFILE, entry)
4822 if (!lstrcmpW(file->File, filename))
4823 return file;
4826 return NULL;
4829 static UINT ITERATE_InstallODBCDriver( MSIRECORD *rec, LPVOID param )
4831 MSIPACKAGE *package = (MSIPACKAGE*)param;
4832 LPWSTR driver, driver_path, ptr;
4833 WCHAR outpath[MAX_PATH];
4834 MSIFILE *driver_file, *setup_file;
4835 LPCWSTR desc;
4836 DWORD len, usage;
4837 UINT r = ERROR_SUCCESS;
4839 static const WCHAR driver_fmt[] = {
4840 'D','r','i','v','e','r','=','%','s',0};
4841 static const WCHAR setup_fmt[] = {
4842 'S','e','t','u','p','=','%','s',0};
4843 static const WCHAR usage_fmt[] = {
4844 'F','i','l','e','U','s','a','g','e','=','1',0};
4846 desc = MSI_RecordGetString(rec, 3);
4848 driver_file = msi_find_file(package, MSI_RecordGetString(rec, 4));
4849 setup_file = msi_find_file(package, MSI_RecordGetString(rec, 5));
4851 if (!driver_file || !setup_file)
4853 ERR("ODBC Driver entry not found!\n");
4854 return ERROR_FUNCTION_FAILED;
4857 len = lstrlenW(desc) + lstrlenW(driver_fmt) + lstrlenW(driver_file->FileName) +
4858 lstrlenW(setup_fmt) + lstrlenW(setup_file->FileName) +
4859 lstrlenW(usage_fmt) + 1;
4860 driver = msi_alloc(len * sizeof(WCHAR));
4861 if (!driver)
4862 return ERROR_OUTOFMEMORY;
4864 ptr = driver;
4865 lstrcpyW(ptr, desc);
4866 ptr += lstrlenW(ptr) + 1;
4868 sprintfW(ptr, driver_fmt, driver_file->FileName);
4869 ptr += lstrlenW(ptr) + 1;
4871 sprintfW(ptr, setup_fmt, setup_file->FileName);
4872 ptr += lstrlenW(ptr) + 1;
4874 lstrcpyW(ptr, usage_fmt);
4875 ptr += lstrlenW(ptr) + 1;
4876 *ptr = '\0';
4878 driver_path = strdupW(driver_file->TargetPath);
4879 ptr = strrchrW(driver_path, '\\');
4880 if (ptr) *ptr = '\0';
4882 if (!SQLInstallDriverExW(driver, driver_path, outpath, MAX_PATH,
4883 NULL, ODBC_INSTALL_COMPLETE, &usage))
4885 ERR("Failed to install SQL driver!\n");
4886 r = ERROR_FUNCTION_FAILED;
4889 msi_free(driver);
4890 msi_free(driver_path);
4892 return r;
4895 static UINT ITERATE_InstallODBCTranslator( MSIRECORD *rec, LPVOID param )
4897 MSIPACKAGE *package = (MSIPACKAGE*)param;
4898 LPWSTR translator, translator_path, ptr;
4899 WCHAR outpath[MAX_PATH];
4900 MSIFILE *translator_file, *setup_file;
4901 LPCWSTR desc;
4902 DWORD len, usage;
4903 UINT r = ERROR_SUCCESS;
4905 static const WCHAR translator_fmt[] = {
4906 'T','r','a','n','s','l','a','t','o','r','=','%','s',0};
4907 static const WCHAR setup_fmt[] = {
4908 'S','e','t','u','p','=','%','s',0};
4910 desc = MSI_RecordGetString(rec, 3);
4912 translator_file = msi_find_file(package, MSI_RecordGetString(rec, 4));
4913 setup_file = msi_find_file(package, MSI_RecordGetString(rec, 5));
4915 if (!translator_file || !setup_file)
4917 ERR("ODBC Translator entry not found!\n");
4918 return ERROR_FUNCTION_FAILED;
4921 len = lstrlenW(desc) + lstrlenW(translator_fmt) + lstrlenW(translator_file->FileName) +
4922 lstrlenW(setup_fmt) + lstrlenW(setup_file->FileName) + 1;
4923 translator = msi_alloc(len * sizeof(WCHAR));
4924 if (!translator)
4925 return ERROR_OUTOFMEMORY;
4927 ptr = translator;
4928 lstrcpyW(ptr, desc);
4929 ptr += lstrlenW(ptr) + 1;
4931 sprintfW(ptr, translator_fmt, translator_file->FileName);
4932 ptr += lstrlenW(ptr) + 1;
4934 sprintfW(ptr, setup_fmt, setup_file->FileName);
4935 ptr += lstrlenW(ptr) + 1;
4936 *ptr = '\0';
4938 translator_path = strdupW(translator_file->TargetPath);
4939 ptr = strrchrW(translator_path, '\\');
4940 if (ptr) *ptr = '\0';
4942 if (!SQLInstallTranslatorExW(translator, translator_path, outpath, MAX_PATH,
4943 NULL, ODBC_INSTALL_COMPLETE, &usage))
4945 ERR("Failed to install SQL translator!\n");
4946 r = ERROR_FUNCTION_FAILED;
4949 msi_free(translator);
4950 msi_free(translator_path);
4952 return r;
4955 static UINT ITERATE_InstallODBCDataSource( MSIRECORD *rec, LPVOID param )
4957 LPWSTR attrs;
4958 LPCWSTR desc, driver;
4959 WORD request = ODBC_ADD_SYS_DSN;
4960 INT registration;
4961 DWORD len;
4962 UINT r = ERROR_SUCCESS;
4964 static const WCHAR attrs_fmt[] = {
4965 'D','S','N','=','%','s',0 };
4967 desc = MSI_RecordGetString(rec, 3);
4968 driver = MSI_RecordGetString(rec, 4);
4969 registration = MSI_RecordGetInteger(rec, 5);
4971 if (registration == msidbODBCDataSourceRegistrationPerMachine) request = ODBC_ADD_SYS_DSN;
4972 else if (registration == msidbODBCDataSourceRegistrationPerUser) request = ODBC_ADD_DSN;
4974 len = lstrlenW(attrs_fmt) + lstrlenW(desc) + 1 + 1;
4975 attrs = msi_alloc(len * sizeof(WCHAR));
4976 if (!attrs)
4977 return ERROR_OUTOFMEMORY;
4979 sprintfW(attrs, attrs_fmt, desc);
4980 attrs[len - 1] = '\0';
4982 if (!SQLConfigDataSourceW(NULL, request, driver, attrs))
4984 ERR("Failed to install SQL data source!\n");
4985 r = ERROR_FUNCTION_FAILED;
4988 msi_free(attrs);
4990 return r;
4993 static UINT ACTION_InstallODBC( MSIPACKAGE *package )
4995 UINT rc;
4996 MSIQUERY *view;
4998 static const WCHAR driver_query[] = {
4999 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5000 'O','D','B','C','D','r','i','v','e','r',0 };
5002 static const WCHAR translator_query[] = {
5003 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5004 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0 };
5006 static const WCHAR source_query[] = {
5007 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5008 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0 };
5010 rc = MSI_DatabaseOpenViewW(package->db, driver_query, &view);
5011 if (rc != ERROR_SUCCESS)
5012 return ERROR_SUCCESS;
5014 rc = MSI_IterateRecords(view, NULL, ITERATE_InstallODBCDriver, package);
5015 msiobj_release(&view->hdr);
5017 rc = MSI_DatabaseOpenViewW(package->db, translator_query, &view);
5018 if (rc != ERROR_SUCCESS)
5019 return ERROR_SUCCESS;
5021 rc = MSI_IterateRecords(view, NULL, ITERATE_InstallODBCTranslator, package);
5022 msiobj_release(&view->hdr);
5024 rc = MSI_DatabaseOpenViewW(package->db, source_query, &view);
5025 if (rc != ERROR_SUCCESS)
5026 return ERROR_SUCCESS;
5028 rc = MSI_IterateRecords(view, NULL, ITERATE_InstallODBCDataSource, package);
5029 msiobj_release(&view->hdr);
5031 return rc;
5034 #define ENV_ACT_SETALWAYS 0x1
5035 #define ENV_ACT_SETABSENT 0x2
5036 #define ENV_ACT_REMOVE 0x4
5037 #define ENV_ACT_REMOVEMATCH 0x8
5039 #define ENV_MOD_MACHINE 0x20000000
5040 #define ENV_MOD_APPEND 0x40000000
5041 #define ENV_MOD_PREFIX 0x80000000
5042 #define ENV_MOD_MASK 0xC0000000
5044 #define check_flag_combo(x, y) ((x) & ~(y)) == (y)
5046 static LONG env_set_flags( LPCWSTR *name, LPCWSTR *value, DWORD *flags )
5048 LPCWSTR cptr = *name;
5049 LPCWSTR ptr = *value;
5051 static const WCHAR prefix[] = {'[','~',']',0};
5052 static const int prefix_len = 3;
5054 *flags = 0;
5055 while (*cptr)
5057 if (*cptr == '=')
5058 *flags |= ENV_ACT_SETALWAYS;
5059 else if (*cptr == '+')
5060 *flags |= ENV_ACT_SETABSENT;
5061 else if (*cptr == '-')
5062 *flags |= ENV_ACT_REMOVE;
5063 else if (*cptr == '!')
5064 *flags |= ENV_ACT_REMOVEMATCH;
5065 else if (*cptr == '*')
5066 *flags |= ENV_MOD_MACHINE;
5067 else
5068 break;
5070 cptr++;
5071 (*name)++;
5074 if (!*cptr)
5076 ERR("Missing environment variable\n");
5077 return ERROR_FUNCTION_FAILED;
5080 if (!strncmpW(ptr, prefix, prefix_len))
5082 *flags |= ENV_MOD_APPEND;
5083 *value += lstrlenW(prefix);
5085 else if (lstrlenW(*value) >= prefix_len)
5087 ptr += lstrlenW(ptr) - prefix_len;
5088 if (!lstrcmpW(ptr, prefix))
5090 *flags |= ENV_MOD_PREFIX;
5091 /* the "[~]" will be removed by deformat_string */;
5095 if (!*flags ||
5096 check_flag_combo(*flags, ENV_ACT_SETALWAYS | ENV_ACT_SETABSENT) ||
5097 check_flag_combo(*flags, ENV_ACT_REMOVEMATCH | ENV_ACT_SETABSENT) ||
5098 check_flag_combo(*flags, ENV_ACT_REMOVEMATCH | ENV_ACT_SETALWAYS) ||
5099 check_flag_combo(*flags, ENV_ACT_SETABSENT | ENV_MOD_MASK))
5101 ERR("Invalid flags: %08x\n", *flags);
5102 return ERROR_FUNCTION_FAILED;
5105 return ERROR_SUCCESS;
5108 static UINT ITERATE_WriteEnvironmentString( MSIRECORD *rec, LPVOID param )
5110 MSIPACKAGE *package = param;
5111 LPCWSTR name, value;
5112 LPWSTR data = NULL, newval = NULL;
5113 LPWSTR deformatted = NULL, ptr;
5114 DWORD flags, type, size;
5115 LONG res;
5116 HKEY env = NULL, root;
5117 LPCWSTR environment;
5119 static const WCHAR user_env[] =
5120 {'E','n','v','i','r','o','n','m','e','n','t',0};
5121 static const WCHAR machine_env[] =
5122 {'S','y','s','t','e','m','\\',
5123 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
5124 'C','o','n','t','r','o','l','\\',
5125 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
5126 'E','n','v','i','r','o','n','m','e','n','t',0};
5127 static const WCHAR semicolon[] = {';',0};
5129 name = MSI_RecordGetString(rec, 2);
5130 value = MSI_RecordGetString(rec, 3);
5132 res = env_set_flags(&name, &value, &flags);
5133 if (res != ERROR_SUCCESS)
5134 goto done;
5136 deformat_string(package, value, &deformatted);
5137 if (!deformatted)
5139 res = ERROR_OUTOFMEMORY;
5140 goto done;
5143 value = deformatted;
5145 if (flags & ENV_MOD_MACHINE)
5147 environment = machine_env;
5148 root = HKEY_LOCAL_MACHINE;
5150 else
5152 environment = user_env;
5153 root = HKEY_CURRENT_USER;
5156 res = RegCreateKeyExW(root, environment, 0, NULL, 0,
5157 KEY_ALL_ACCESS, NULL, &env, NULL);
5158 if (res != ERROR_SUCCESS)
5159 goto done;
5161 if (flags & ENV_ACT_REMOVE)
5162 FIXME("Not removing environment variable on uninstall!\n");
5164 size = 0;
5165 res = RegQueryValueExW(env, name, NULL, &type, NULL, &size);
5166 if ((res != ERROR_SUCCESS && res != ERROR_FILE_NOT_FOUND) ||
5167 (res == ERROR_SUCCESS && type != REG_SZ && type != REG_EXPAND_SZ))
5168 goto done;
5170 if (res != ERROR_FILE_NOT_FOUND)
5172 if (flags & ENV_ACT_SETABSENT)
5174 res = ERROR_SUCCESS;
5175 goto done;
5178 data = msi_alloc(size);
5179 if (!data)
5181 RegCloseKey(env);
5182 return ERROR_OUTOFMEMORY;
5185 res = RegQueryValueExW(env, name, NULL, &type, (LPVOID)data, &size);
5186 if (res != ERROR_SUCCESS)
5187 goto done;
5189 if (flags & ENV_ACT_REMOVEMATCH && (!value || !lstrcmpW(data, value)))
5191 res = RegDeleteKeyW(env, name);
5192 goto done;
5195 size = (lstrlenW(value) + 1 + size) * sizeof(WCHAR);
5196 newval = msi_alloc(size);
5197 ptr = newval;
5198 if (!newval)
5200 res = ERROR_OUTOFMEMORY;
5201 goto done;
5204 if (!(flags & ENV_MOD_MASK))
5205 lstrcpyW(newval, value);
5206 else
5208 if (flags & ENV_MOD_PREFIX)
5210 lstrcpyW(newval, value);
5211 lstrcatW(newval, semicolon);
5212 ptr = newval + lstrlenW(value) + 1;
5215 lstrcpyW(ptr, data);
5217 if (flags & ENV_MOD_APPEND)
5219 lstrcatW(newval, semicolon);
5220 lstrcatW(newval, value);
5224 else
5226 size = (lstrlenW(value) + 1) * sizeof(WCHAR);
5227 newval = msi_alloc(size);
5228 if (!newval)
5230 res = ERROR_OUTOFMEMORY;
5231 goto done;
5234 lstrcpyW(newval, value);
5237 TRACE("setting %s to %s\n", debugstr_w(name), debugstr_w(newval));
5238 res = RegSetValueExW(env, name, 0, type, (LPVOID)newval, size);
5240 done:
5241 if (env) RegCloseKey(env);
5242 msi_free(deformatted);
5243 msi_free(data);
5244 msi_free(newval);
5245 return res;
5248 static UINT ACTION_WriteEnvironmentStrings( MSIPACKAGE *package )
5250 UINT rc;
5251 MSIQUERY * view;
5252 static const WCHAR ExecSeqQuery[] =
5253 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5254 '`','E','n','v','i','r','o','n','m','e','n','t','`',0};
5255 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5256 if (rc != ERROR_SUCCESS)
5257 return ERROR_SUCCESS;
5259 rc = MSI_IterateRecords(view, NULL, ITERATE_WriteEnvironmentString, package);
5260 msiobj_release(&view->hdr);
5262 return rc;
5265 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
5267 typedef struct
5269 struct list entry;
5270 LPWSTR sourcename;
5271 LPWSTR destname;
5272 LPWSTR source;
5273 LPWSTR dest;
5274 } FILE_LIST;
5276 static BOOL msi_move_file(LPCWSTR source, LPCWSTR dest, int options)
5278 BOOL ret;
5280 if (GetFileAttributesW(source) == FILE_ATTRIBUTE_DIRECTORY ||
5281 GetFileAttributesW(dest) == FILE_ATTRIBUTE_DIRECTORY)
5283 WARN("Source or dest is directory, not moving\n");
5284 return FALSE;
5287 if (options == msidbMoveFileOptionsMove)
5289 TRACE("moving %s -> %s\n", debugstr_w(source), debugstr_w(dest));
5290 ret = MoveFileExW(source, dest, MOVEFILE_REPLACE_EXISTING);
5291 if (!ret)
5293 WARN("MoveFile failed: %d\n", GetLastError());
5294 return FALSE;
5297 else
5299 TRACE("copying %s -> %s\n", debugstr_w(source), debugstr_w(dest));
5300 ret = CopyFileW(source, dest, FALSE);
5301 if (!ret)
5303 WARN("CopyFile failed: %d\n", GetLastError());
5304 return FALSE;
5308 return TRUE;
5311 static LPWSTR wildcard_to_file(LPWSTR wildcard, LPWSTR filename)
5313 LPWSTR path, ptr;
5314 DWORD dirlen, pathlen;
5316 ptr = strrchrW(wildcard, '\\');
5317 dirlen = ptr - wildcard + 1;
5319 pathlen = dirlen + lstrlenW(filename) + 1;
5320 path = msi_alloc(pathlen * sizeof(WCHAR));
5322 lstrcpynW(path, wildcard, dirlen + 1);
5323 lstrcatW(path, filename);
5325 return path;
5328 static void free_file_entry(FILE_LIST *file)
5330 msi_free(file->source);
5331 msi_free(file->dest);
5332 msi_free(file);
5335 static void free_list(FILE_LIST *list)
5337 while (!list_empty(&list->entry))
5339 FILE_LIST *file = LIST_ENTRY(list_head(&list->entry), FILE_LIST, entry);
5341 list_remove(&file->entry);
5342 free_file_entry(file);
5346 static BOOL add_wildcard(FILE_LIST *files, LPWSTR source, LPWSTR dest)
5348 FILE_LIST *new, *file;
5349 LPWSTR ptr, filename;
5350 DWORD size;
5352 new = msi_alloc_zero(sizeof(FILE_LIST));
5353 if (!new)
5354 return FALSE;
5356 new->source = strdupW(source);
5357 ptr = strrchrW(dest, '\\') + 1;
5358 filename = strrchrW(new->source, '\\') + 1;
5360 new->sourcename = filename;
5362 if (*ptr)
5363 new->destname = ptr;
5364 else
5365 new->destname = new->sourcename;
5367 size = (ptr - dest) + lstrlenW(filename) + 1;
5368 new->dest = msi_alloc(size * sizeof(WCHAR));
5369 if (!new->dest)
5371 free_file_entry(new);
5372 return FALSE;
5375 lstrcpynW(new->dest, dest, ptr - dest + 1);
5376 lstrcatW(new->dest, filename);
5378 if (list_empty(&files->entry))
5380 list_add_head(&files->entry, &new->entry);
5381 return TRUE;
5384 LIST_FOR_EACH_ENTRY(file, &files->entry, FILE_LIST, entry)
5386 if (lstrcmpW(source, file->source) < 0)
5388 list_add_before(&file->entry, &new->entry);
5389 return TRUE;
5393 list_add_after(&file->entry, &new->entry);
5394 return TRUE;
5397 static BOOL move_files_wildcard(LPWSTR source, LPWSTR dest, int options)
5399 WIN32_FIND_DATAW wfd;
5400 HANDLE hfile;
5401 LPWSTR path;
5402 BOOL res;
5403 FILE_LIST files, *file;
5404 DWORD size;
5406 hfile = FindFirstFileW(source, &wfd);
5407 if (hfile == INVALID_HANDLE_VALUE) return FALSE;
5409 list_init(&files.entry);
5411 for (res = TRUE; res; res = FindNextFileW(hfile, &wfd))
5413 if (is_dot_dir(wfd.cFileName)) continue;
5415 path = wildcard_to_file(source, wfd.cFileName);
5416 if (!path)
5418 res = FALSE;
5419 goto done;
5422 add_wildcard(&files, path, dest);
5423 msi_free(path);
5426 /* no files match the wildcard */
5427 if (list_empty(&files.entry))
5428 goto done;
5430 /* only the first wildcard match gets renamed to dest */
5431 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
5432 size = (strrchrW(file->dest, '\\') - file->dest) + lstrlenW(file->destname) + 2;
5433 file->dest = msi_realloc(file->dest, size * sizeof(WCHAR));
5434 if (!file->dest)
5436 res = FALSE;
5437 goto done;
5440 lstrcpyW(strrchrW(file->dest, '\\') + 1, file->destname);
5442 while (!list_empty(&files.entry))
5444 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
5446 msi_move_file((LPCWSTR)file->source, (LPCWSTR)file->dest, options);
5448 list_remove(&file->entry);
5449 free_file_entry(file);
5452 res = TRUE;
5454 done:
5455 free_list(&files);
5456 FindClose(hfile);
5457 return res;
5460 static UINT ITERATE_MoveFiles( MSIRECORD *rec, LPVOID param )
5462 MSIPACKAGE *package = param;
5463 MSICOMPONENT *comp;
5464 LPCWSTR sourcename, destname;
5465 LPWSTR sourcedir = NULL, destdir = NULL;
5466 LPWSTR source = NULL, dest = NULL;
5467 int options;
5468 DWORD size;
5469 BOOL ret, wildcards;
5471 static const WCHAR backslash[] = {'\\',0};
5473 comp = get_loaded_component(package, MSI_RecordGetString(rec, 2));
5474 if (!comp || !comp->Enabled ||
5475 !(comp->Action & (INSTALLSTATE_LOCAL | INSTALLSTATE_SOURCE)))
5477 TRACE("Component not set for install, not moving file\n");
5478 return ERROR_SUCCESS;
5481 sourcename = MSI_RecordGetString(rec, 3);
5482 destname = MSI_RecordGetString(rec, 4);
5483 options = MSI_RecordGetInteger(rec, 7);
5485 sourcedir = msi_dup_property(package, MSI_RecordGetString(rec, 5));
5486 if (!sourcedir)
5487 goto done;
5489 destdir = msi_dup_property(package, MSI_RecordGetString(rec, 6));
5490 if (!destdir)
5491 goto done;
5493 if (!sourcename)
5495 if (GetFileAttributesW(sourcedir) == INVALID_FILE_ATTRIBUTES)
5496 goto done;
5498 source = strdupW(sourcedir);
5499 if (!source)
5500 goto done;
5502 else
5504 size = lstrlenW(sourcedir) + lstrlenW(sourcename) + 2;
5505 source = msi_alloc(size * sizeof(WCHAR));
5506 if (!source)
5507 goto done;
5509 lstrcpyW(source, sourcedir);
5510 if (source[lstrlenW(source) - 1] != '\\')
5511 lstrcatW(source, backslash);
5512 lstrcatW(source, sourcename);
5515 wildcards = strchrW(source, '*') || strchrW(source, '?');
5517 if (!destname && !wildcards)
5519 destname = strdupW(sourcename);
5520 if (!destname)
5521 goto done;
5524 size = 0;
5525 if (destname)
5526 size = lstrlenW(destname);
5528 size += lstrlenW(destdir) + 2;
5529 dest = msi_alloc(size * sizeof(WCHAR));
5530 if (!dest)
5531 goto done;
5533 lstrcpyW(dest, destdir);
5534 if (dest[lstrlenW(dest) - 1] != '\\')
5535 lstrcatW(dest, backslash);
5537 if (destname)
5538 lstrcatW(dest, destname);
5540 if (GetFileAttributesW(destdir) == INVALID_FILE_ATTRIBUTES)
5542 ret = CreateDirectoryW(destdir, NULL);
5543 if (!ret)
5545 WARN("CreateDirectory failed: %d\n", GetLastError());
5546 return ERROR_SUCCESS;
5550 if (!wildcards)
5551 msi_move_file(source, dest, options);
5552 else
5553 move_files_wildcard(source, dest, options);
5555 done:
5556 msi_free(sourcedir);
5557 msi_free(destdir);
5558 msi_free(source);
5559 msi_free(dest);
5561 return ERROR_SUCCESS;
5564 static UINT ACTION_MoveFiles( MSIPACKAGE *package )
5566 UINT rc;
5567 MSIQUERY *view;
5569 static const WCHAR ExecSeqQuery[] =
5570 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5571 '`','M','o','v','e','F','i','l','e','`',0};
5573 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5574 if (rc != ERROR_SUCCESS)
5575 return ERROR_SUCCESS;
5577 rc = MSI_IterateRecords(view, NULL, ITERATE_MoveFiles, package);
5578 msiobj_release(&view->hdr);
5580 return rc;
5583 static HRESULT (WINAPI *pCreateAssemblyCache)(IAssemblyCache **ppAsmCache,
5584 DWORD dwReserved);
5585 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR szDllName, LPCWSTR szVersion,
5586 LPVOID pvReserved, HMODULE *phModDll);
5588 static BOOL init_functionpointers(void)
5590 HRESULT hr;
5591 HMODULE hfusion;
5592 HMODULE hmscoree;
5594 static const WCHAR szFusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
5596 hmscoree = LoadLibraryA("mscoree.dll");
5597 if (!hmscoree)
5599 WARN("mscoree.dll not available\n");
5600 return FALSE;
5603 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
5604 if (!pLoadLibraryShim)
5606 WARN("LoadLibraryShim not available\n");
5607 FreeLibrary(hmscoree);
5608 return FALSE;
5611 hr = pLoadLibraryShim(szFusion, NULL, NULL, &hfusion);
5612 if (FAILED(hr))
5614 WARN("fusion.dll not available\n");
5615 FreeLibrary(hmscoree);
5616 return FALSE;
5619 pCreateAssemblyCache = (void *)GetProcAddress(hfusion, "CreateAssemblyCache");
5621 FreeLibrary(hmscoree);
5622 return TRUE;
5625 static UINT install_assembly(LPWSTR path)
5627 IAssemblyCache *cache;
5628 HRESULT hr;
5629 UINT r = ERROR_FUNCTION_FAILED;
5631 if (!init_functionpointers() || !pCreateAssemblyCache)
5632 return ERROR_FUNCTION_FAILED;
5634 hr = pCreateAssemblyCache(&cache, 0);
5635 if (FAILED(hr))
5636 goto done;
5638 hr = IAssemblyCache_InstallAssembly(cache, 0, path, NULL);
5639 if (FAILED(hr))
5640 ERR("Failed to install assembly: %s %08x\n", debugstr_w(path), hr);
5642 r = ERROR_SUCCESS;
5644 done:
5645 IAssemblyCache_Release(cache);
5646 return r;
5649 static UINT ITERATE_PublishAssembly( MSIRECORD *rec, LPVOID param )
5651 MSIPACKAGE *package = param;
5652 MSICOMPONENT *comp;
5653 MSIFEATURE *feature;
5654 MSIFILE *file;
5655 WCHAR path[MAX_PATH];
5656 LPCWSTR app;
5657 DWORD attr;
5658 UINT r;
5660 comp = get_loaded_component(package, MSI_RecordGetString(rec, 1));
5661 if (!comp || !comp->Enabled ||
5662 !(comp->Action & (INSTALLSTATE_LOCAL | INSTALLSTATE_SOURCE)))
5664 ERR("Component not set for install, not publishing assembly\n");
5665 return ERROR_SUCCESS;
5668 feature = find_feature_by_name(package, MSI_RecordGetString(rec, 2));
5669 if (feature)
5670 msi_feature_set_state(feature, INSTALLSTATE_LOCAL);
5672 if (MSI_RecordGetString(rec, 3))
5673 FIXME("Manifest unhandled\n");
5675 app = MSI_RecordGetString(rec, 4);
5676 if (app)
5678 FIXME("Assembly should be privately installed\n");
5679 return ERROR_SUCCESS;
5682 attr = MSI_RecordGetInteger(rec, 5);
5683 if (attr == msidbAssemblyAttributesWin32)
5685 FIXME("Win32 assemblies not handled\n");
5686 return ERROR_SUCCESS;
5689 /* FIXME: extract all files belonging to this component */
5690 file = msi_find_file(package, comp->KeyPath);
5691 if (!file)
5693 ERR("File %s not found\n", debugstr_w(comp->KeyPath));
5694 return ERROR_FUNCTION_FAILED;
5697 GetTempPathW(MAX_PATH, path);
5699 if (file->IsCompressed)
5701 r = msi_extract_file(package, file, path);
5702 if (r != ERROR_SUCCESS)
5704 ERR("Failed to extract temporary assembly\n");
5705 return r;
5708 PathAddBackslashW(path);
5709 lstrcatW(path, file->FileName);
5711 else
5713 PathAddBackslashW(path);
5714 lstrcatW(path, file->FileName);
5716 if (!CopyFileW(file->SourcePath, path, FALSE))
5718 ERR("Failed to copy temporary assembly: %d\n", GetLastError());
5719 return ERROR_FUNCTION_FAILED;
5723 r = install_assembly(path);
5724 if (r != ERROR_SUCCESS)
5725 ERR("Failed to install assembly\n");
5727 /* FIXME: write Installer assembly reg values */
5729 return r;
5732 static UINT ACTION_MsiPublishAssemblies( MSIPACKAGE *package )
5734 UINT rc;
5735 MSIQUERY *view;
5737 static const WCHAR ExecSeqQuery[] =
5738 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5739 '`','M','s','i','A','s','s','e','m','b','l','y','`',0};
5741 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5742 if (rc != ERROR_SUCCESS)
5743 return ERROR_SUCCESS;
5745 rc = MSI_IterateRecords(view, NULL, ITERATE_PublishAssembly, package);
5746 msiobj_release(&view->hdr);
5748 return rc;
5751 static UINT msi_unimplemented_action_stub( MSIPACKAGE *package,
5752 LPCSTR action, LPCWSTR table )
5754 static const WCHAR query[] = {
5755 'S','E','L','E','C','T',' ','*',' ',
5756 'F','R','O','M',' ','`','%','s','`',0 };
5757 MSIQUERY *view = NULL;
5758 DWORD count = 0;
5759 UINT r;
5761 r = MSI_OpenQuery( package->db, &view, query, table );
5762 if (r == ERROR_SUCCESS)
5764 r = MSI_IterateRecords(view, &count, NULL, package);
5765 msiobj_release(&view->hdr);
5768 if (count)
5769 FIXME("%s -> %u ignored %s table values\n",
5770 action, count, debugstr_w(table));
5772 return ERROR_SUCCESS;
5775 static UINT ACTION_AllocateRegistrySpace( MSIPACKAGE *package )
5777 TRACE("%p\n", package);
5778 return ERROR_SUCCESS;
5781 static UINT ACTION_RemoveIniValues( MSIPACKAGE *package )
5783 static const WCHAR table[] =
5784 {'R','e','m','o','v','e','I','n','i','F','i','l','e',0 };
5785 return msi_unimplemented_action_stub( package, "RemoveIniValues", table );
5788 static UINT ACTION_PatchFiles( MSIPACKAGE *package )
5790 static const WCHAR table[] = { 'P','a','t','c','h',0 };
5791 return msi_unimplemented_action_stub( package, "PatchFiles", table );
5794 static UINT ACTION_BindImage( MSIPACKAGE *package )
5796 static const WCHAR table[] = { 'B','i','n','d','I','m','a','g','e',0 };
5797 return msi_unimplemented_action_stub( package, "BindImage", table );
5800 static UINT ACTION_IsolateComponents( MSIPACKAGE *package )
5802 static const WCHAR table[] = {
5803 'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t',0 };
5804 return msi_unimplemented_action_stub( package, "IsolateComponents", table );
5807 static UINT ACTION_MigrateFeatureStates( MSIPACKAGE *package )
5809 static const WCHAR table[] = { 'U','p','g','r','a','d','e',0 };
5810 return msi_unimplemented_action_stub( package, "MigrateFeatureStates", table );
5813 static UINT ACTION_SelfUnregModules( MSIPACKAGE *package )
5815 static const WCHAR table[] = { 'S','e','l','f','R','e','g',0 };
5816 return msi_unimplemented_action_stub( package, "SelfUnregModules", table );
5819 static UINT ACTION_DeleteServices( MSIPACKAGE *package )
5821 static const WCHAR table[] = {
5822 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
5823 return msi_unimplemented_action_stub( package, "DeleteServices", table );
5825 static UINT ACTION_ValidateProductID( MSIPACKAGE *package )
5827 static const WCHAR table[] = {
5828 'P','r','o','d','u','c','t','I','D',0 };
5829 return msi_unimplemented_action_stub( package, "ValidateProductID", table );
5832 static UINT ACTION_RemoveEnvironmentStrings( MSIPACKAGE *package )
5834 static const WCHAR table[] = {
5835 'E','n','v','i','r','o','n','m','e','n','t',0 };
5836 return msi_unimplemented_action_stub( package, "RemoveEnvironmentStrings", table );
5839 static UINT ACTION_MsiUnpublishAssemblies( MSIPACKAGE *package )
5841 static const WCHAR table[] = {
5842 'M','s','i','A','s','s','e','m','b','l','y',0 };
5843 return msi_unimplemented_action_stub( package, "MsiUnpublishAssemblies", table );
5846 static UINT ACTION_UnregisterFonts( MSIPACKAGE *package )
5848 static const WCHAR table[] = { 'F','o','n','t',0 };
5849 return msi_unimplemented_action_stub( package, "UnregisterFonts", table );
5852 static UINT ACTION_RMCCPSearch( MSIPACKAGE *package )
5854 static const WCHAR table[] = { 'C','C','P','S','e','a','r','c','h',0 };
5855 return msi_unimplemented_action_stub( package, "RMCCPSearch", table );
5858 static UINT ACTION_RegisterComPlus( MSIPACKAGE *package )
5860 static const WCHAR table[] = { 'C','o','m','p','l','u','s',0 };
5861 return msi_unimplemented_action_stub( package, "RegisterComPlus", table );
5864 static UINT ACTION_UnregisterComPlus( MSIPACKAGE *package )
5866 static const WCHAR table[] = { 'C','o','m','p','l','u','s',0 };
5867 return msi_unimplemented_action_stub( package, "UnregisterComPlus", table );
5870 static UINT ACTION_InstallSFPCatalogFile( MSIPACKAGE *package )
5872 static const WCHAR table[] = { 'S','F','P','C','a','t','a','l','o','g',0 };
5873 return msi_unimplemented_action_stub( package, "InstallSFPCatalogFile", table );
5876 static UINT ACTION_RemoveDuplicateFiles( MSIPACKAGE *package )
5878 static const WCHAR table[] = { 'D','u','p','l','i','c','a','t','e','F','i','l','e',0 };
5879 return msi_unimplemented_action_stub( package, "RemoveDuplicateFiles", table );
5882 static UINT ACTION_RemoveExistingProducts( MSIPACKAGE *package )
5884 static const WCHAR table[] = { 'U','p','g','r','a','d','e',0 };
5885 return msi_unimplemented_action_stub( package, "RemoveExistingProducts", table );
5888 static UINT ACTION_RemoveFolders( MSIPACKAGE *package )
5890 static const WCHAR table[] = { 'C','r','e','a','t','e','F','o','l','d','e','r',0 };
5891 return msi_unimplemented_action_stub( package, "RemoveFolders", table );
5894 static UINT ACTION_RemoveODBC( MSIPACKAGE *package )
5896 static const WCHAR table[] = { 'O','D','B','C','D','r','i','v','e','r',0 };
5897 return msi_unimplemented_action_stub( package, "RemoveODBC", table );
5900 static UINT ACTION_RemoveRegistryValues( MSIPACKAGE *package )
5902 static const WCHAR table[] = { 'R','e','m','o','v','e','R','e','g','i','s','t','r','y',0 };
5903 return msi_unimplemented_action_stub( package, "RemoveRegistryValues", table );
5906 static UINT ACTION_RemoveShortcuts( MSIPACKAGE *package )
5908 static const WCHAR table[] = { 'S','h','o','r','t','c','u','t',0 };
5909 return msi_unimplemented_action_stub( package, "RemoveShortcuts", table );
5912 static UINT ACTION_UnpublishComponents( MSIPACKAGE *package )
5914 static const WCHAR table[] = { 'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t',0 };
5915 return msi_unimplemented_action_stub( package, "UnpublishComponents", table );
5918 static UINT ACTION_UnregisterClassInfo( MSIPACKAGE *package )
5920 static const WCHAR table[] = { 'A','p','p','I','d',0 };
5921 return msi_unimplemented_action_stub( package, "UnregisterClassInfo", table );
5924 static UINT ACTION_UnregisterExtensionInfo( MSIPACKAGE *package )
5926 static const WCHAR table[] = { 'E','x','t','e','n','s','i','o','n',0 };
5927 return msi_unimplemented_action_stub( package, "UnregisterExtensionInfo", table );
5930 static UINT ACTION_UnregisterMIMEInfo( MSIPACKAGE *package )
5932 static const WCHAR table[] = { 'M','I','M','E',0 };
5933 return msi_unimplemented_action_stub( package, "UnregisterMIMEInfo", table );
5936 static UINT ACTION_UnregisterProgIdInfo( MSIPACKAGE *package )
5938 static const WCHAR table[] = { 'P','r','o','g','I','d',0 };
5939 return msi_unimplemented_action_stub( package, "UnregisterProgIdInfo", table );
5942 static UINT ACTION_UnregisterTypeLibraries( MSIPACKAGE *package )
5944 static const WCHAR table[] = { 'T','y','p','e','L','i','b',0 };
5945 return msi_unimplemented_action_stub( package, "UnregisterTypeLibraries", table );
5948 static const struct _actions StandardActions[] = {
5949 { szAllocateRegistrySpace, ACTION_AllocateRegistrySpace },
5950 { szAppSearch, ACTION_AppSearch },
5951 { szBindImage, ACTION_BindImage },
5952 { szCCPSearch, ACTION_CCPSearch },
5953 { szCostFinalize, ACTION_CostFinalize },
5954 { szCostInitialize, ACTION_CostInitialize },
5955 { szCreateFolders, ACTION_CreateFolders },
5956 { szCreateShortcuts, ACTION_CreateShortcuts },
5957 { szDeleteServices, ACTION_DeleteServices },
5958 { szDisableRollback, NULL },
5959 { szDuplicateFiles, ACTION_DuplicateFiles },
5960 { szExecuteAction, ACTION_ExecuteAction },
5961 { szFileCost, ACTION_FileCost },
5962 { szFindRelatedProducts, ACTION_FindRelatedProducts },
5963 { szForceReboot, ACTION_ForceReboot },
5964 { szInstallAdminPackage, NULL },
5965 { szInstallExecute, ACTION_InstallExecute },
5966 { szInstallExecuteAgain, ACTION_InstallExecute },
5967 { szInstallFiles, ACTION_InstallFiles},
5968 { szInstallFinalize, ACTION_InstallFinalize },
5969 { szInstallInitialize, ACTION_InstallInitialize },
5970 { szInstallSFPCatalogFile, ACTION_InstallSFPCatalogFile },
5971 { szInstallValidate, ACTION_InstallValidate },
5972 { szIsolateComponents, ACTION_IsolateComponents },
5973 { szLaunchConditions, ACTION_LaunchConditions },
5974 { szMigrateFeatureStates, ACTION_MigrateFeatureStates },
5975 { szMoveFiles, ACTION_MoveFiles },
5976 { szMsiPublishAssemblies, ACTION_MsiPublishAssemblies },
5977 { szMsiUnpublishAssemblies, ACTION_MsiUnpublishAssemblies },
5978 { szInstallODBC, ACTION_InstallODBC },
5979 { szInstallServices, ACTION_InstallServices },
5980 { szPatchFiles, ACTION_PatchFiles },
5981 { szProcessComponents, ACTION_ProcessComponents },
5982 { szPublishComponents, ACTION_PublishComponents },
5983 { szPublishFeatures, ACTION_PublishFeatures },
5984 { szPublishProduct, ACTION_PublishProduct },
5985 { szRegisterClassInfo, ACTION_RegisterClassInfo },
5986 { szRegisterComPlus, ACTION_RegisterComPlus},
5987 { szRegisterExtensionInfo, ACTION_RegisterExtensionInfo },
5988 { szRegisterFonts, ACTION_RegisterFonts },
5989 { szRegisterMIMEInfo, ACTION_RegisterMIMEInfo },
5990 { szRegisterProduct, ACTION_RegisterProduct },
5991 { szRegisterProgIdInfo, ACTION_RegisterProgIdInfo },
5992 { szRegisterTypeLibraries, ACTION_RegisterTypeLibraries },
5993 { szRegisterUser, ACTION_RegisterUser },
5994 { szRemoveDuplicateFiles, ACTION_RemoveDuplicateFiles },
5995 { szRemoveEnvironmentStrings, ACTION_RemoveEnvironmentStrings },
5996 { szRemoveExistingProducts, ACTION_RemoveExistingProducts },
5997 { szRemoveFiles, ACTION_RemoveFiles },
5998 { szRemoveFolders, ACTION_RemoveFolders },
5999 { szRemoveIniValues, ACTION_RemoveIniValues },
6000 { szRemoveODBC, ACTION_RemoveODBC },
6001 { szRemoveRegistryValues, ACTION_RemoveRegistryValues },
6002 { szRemoveShortcuts, ACTION_RemoveShortcuts },
6003 { szResolveSource, ACTION_ResolveSource },
6004 { szRMCCPSearch, ACTION_RMCCPSearch },
6005 { szScheduleReboot, NULL },
6006 { szSelfRegModules, ACTION_SelfRegModules },
6007 { szSelfUnregModules, ACTION_SelfUnregModules },
6008 { szSetODBCFolders, NULL },
6009 { szStartServices, ACTION_StartServices },
6010 { szStopServices, ACTION_StopServices },
6011 { szUnpublishComponents, ACTION_UnpublishComponents },
6012 { szUnpublishFeatures, ACTION_UnpublishFeatures },
6013 { szUnregisterClassInfo, ACTION_UnregisterClassInfo },
6014 { szUnregisterComPlus, ACTION_UnregisterComPlus },
6015 { szUnregisterExtensionInfo, ACTION_UnregisterExtensionInfo },
6016 { szUnregisterFonts, ACTION_UnregisterFonts },
6017 { szUnregisterMIMEInfo, ACTION_UnregisterMIMEInfo },
6018 { szUnregisterProgIdInfo, ACTION_UnregisterProgIdInfo },
6019 { szUnregisterTypeLibraries, ACTION_UnregisterTypeLibraries },
6020 { szValidateProductID, ACTION_ValidateProductID },
6021 { szWriteEnvironmentStrings, ACTION_WriteEnvironmentStrings },
6022 { szWriteIniValues, ACTION_WriteIniValues },
6023 { szWriteRegistryValues, ACTION_WriteRegistryValues },
6024 { NULL, NULL },
6027 static BOOL ACTION_HandleStandardAction(MSIPACKAGE *package, LPCWSTR action,
6028 UINT* rc, BOOL force )
6030 BOOL ret = FALSE;
6031 BOOL run = force;
6032 int i;
6034 if (!run && !package->script->CurrentlyScripting)
6035 run = TRUE;
6037 if (!run)
6039 if (strcmpW(action,szInstallFinalize) == 0 ||
6040 strcmpW(action,szInstallExecute) == 0 ||
6041 strcmpW(action,szInstallExecuteAgain) == 0)
6042 run = TRUE;
6045 i = 0;
6046 while (StandardActions[i].action != NULL)
6048 if (strcmpW(StandardActions[i].action, action)==0)
6050 if (!run)
6052 ui_actioninfo(package, action, TRUE, 0);
6053 *rc = schedule_action(package,INSTALL_SCRIPT,action);
6054 ui_actioninfo(package, action, FALSE, *rc);
6056 else
6058 ui_actionstart(package, action);
6059 if (StandardActions[i].handler)
6061 *rc = StandardActions[i].handler(package);
6063 else
6065 FIXME("unhandled standard action %s\n",debugstr_w(action));
6066 *rc = ERROR_SUCCESS;
6069 ret = TRUE;
6070 break;
6072 i++;
6074 return ret;