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
31 #include "wine/debug.h"
40 #include "wine/unicode.h"
43 #define REG_PROGRESS_VALUE 13200
44 #define COMPONENT_PROGRESS_VALUE 24000
46 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
49 * consts and values used
51 static const WCHAR c_colon
[] = {'C',':','\\',0};
53 static const WCHAR szCreateFolders
[] =
54 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
55 static const WCHAR szCostFinalize
[] =
56 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
57 static const WCHAR szWriteRegistryValues
[] =
58 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
59 static const WCHAR szCostInitialize
[] =
60 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
61 static const WCHAR szFileCost
[] =
62 {'F','i','l','e','C','o','s','t',0};
63 static const WCHAR szInstallInitialize
[] =
64 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
65 static const WCHAR szInstallValidate
[] =
66 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
67 static const WCHAR szLaunchConditions
[] =
68 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
69 static const WCHAR szProcessComponents
[] =
70 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
71 static const WCHAR szRegisterTypeLibraries
[] =
72 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r','i','e','s',0};
73 static const WCHAR szCreateShortcuts
[] =
74 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
75 static const WCHAR szPublishProduct
[] =
76 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
77 static const WCHAR szWriteIniValues
[] =
78 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
79 static const WCHAR szSelfRegModules
[] =
80 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
81 static const WCHAR szPublishFeatures
[] =
82 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
83 static const WCHAR szRegisterProduct
[] =
84 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
85 static const WCHAR szInstallExecute
[] =
86 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
87 static const WCHAR szInstallExecuteAgain
[] =
88 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e','A','g','a','i','n',0};
89 static const WCHAR szInstallFinalize
[] =
90 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
91 static const WCHAR szForceReboot
[] =
92 {'F','o','r','c','e','R','e','b','o','o','t',0};
93 static const WCHAR szResolveSource
[] =
94 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
95 static const WCHAR szAppSearch
[] =
96 {'A','p','p','S','e','a','r','c','h',0};
97 static const WCHAR szAllocateRegistrySpace
[] =
98 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y','S','p','a','c','e',0};
99 static const WCHAR szBindImage
[] =
100 {'B','i','n','d','I','m','a','g','e',0};
101 static const WCHAR szCCPSearch
[] =
102 {'C','C','P','S','e','a','r','c','h',0};
103 static const WCHAR szDeleteServices
[] =
104 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
105 static const WCHAR szDisableRollback
[] =
106 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
107 static const WCHAR szExecuteAction
[] =
108 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
109 static const WCHAR szInstallAdminPackage
[] =
110 {'I','n','s','t','a','l','l','A','d','m','i','n','P','a','c','k','a','g','e',0};
111 static const WCHAR szInstallSFPCatalogFile
[] =
112 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g','F','i','l','e',0};
113 static const WCHAR szIsolateComponents
[] =
114 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
115 static const WCHAR szMigrateFeatureStates
[] =
116 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e','S','t','a','t','e','s',0};
117 static const WCHAR szMoveFiles
[] =
118 {'M','o','v','e','F','i','l','e','s',0};
119 static const WCHAR szMsiPublishAssemblies
[] =
120 {'M','s','i','P','u','b','l','i','s','h','A','s','s','e','m','b','l','i','e','s',0};
121 static const WCHAR szMsiUnpublishAssemblies
[] =
122 {'M','s','i','U','n','p','u','b','l','i','s','h','A','s','s','e','m','b','l','i','e','s',0};
123 static const WCHAR szInstallODBC
[] =
124 {'I','n','s','t','a','l','l','O','D','B','C',0};
125 static const WCHAR szInstallServices
[] =
126 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
127 static const WCHAR szPatchFiles
[] =
128 {'P','a','t','c','h','F','i','l','e','s',0};
129 static const WCHAR szPublishComponents
[] =
130 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
131 static const WCHAR szRegisterComPlus
[] =
132 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
133 static const WCHAR szRegisterFonts
[] =
134 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
135 static const WCHAR szRegisterUser
[] =
136 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
137 static const WCHAR szRemoveEnvironmentStrings
[] =
138 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t','S','t','r','i','n','g','s',0};
139 static const WCHAR szRemoveExistingProducts
[] =
140 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g','P','r','o','d','u','c','t','s',0};
141 static const WCHAR szRemoveFolders
[] =
142 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
143 static const WCHAR szRemoveIniValues
[] =
144 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
145 static const WCHAR szRemoveODBC
[] =
146 {'R','e','m','o','v','e','O','D','B','C',0};
147 static const WCHAR szRemoveRegistryValues
[] =
148 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
149 static const WCHAR szRemoveShortcuts
[] =
150 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
151 static const WCHAR szRMCCPSearch
[] =
152 {'R','M','C','C','P','S','e','a','r','c','h',0};
153 static const WCHAR szScheduleReboot
[] =
154 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
155 static const WCHAR szSelfUnregModules
[] =
156 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
157 static const WCHAR szSetODBCFolders
[] =
158 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
159 static const WCHAR szStartServices
[] =
160 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
161 static const WCHAR szStopServices
[] =
162 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
163 static const WCHAR szUnpublishComponents
[] =
164 {'U','n','p','u','b','l','i','s','h', 'C','o','m','p','o','n','e','n','t','s',0};
165 static const WCHAR szUnpublishFeatures
[] =
166 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
167 static const WCHAR szUnregisterClassInfo
[] =
168 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
169 static const WCHAR szUnregisterComPlus
[] =
170 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
171 static const WCHAR szUnregisterExtensionInfo
[] =
172 {'U','n','r','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n','I','n','f','o',0};
173 static const WCHAR szUnregisterFonts
[] =
174 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
175 static const WCHAR szUnregisterMIMEInfo
[] =
176 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
177 static const WCHAR szUnregisterProgIdInfo
[] =
178 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
179 static const WCHAR szUnregisterTypeLibraries
[] =
180 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r','i','e','s',0};
181 static const WCHAR szValidateProductID
[] =
182 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
183 static const WCHAR szWriteEnvironmentStrings
[] =
184 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t','S','t','r','i','n','g','s',0};
186 /********************************************************
188 ********************************************************/
190 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
192 static const WCHAR Query_t
[] =
193 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
194 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
195 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
196 ' ','\'','%','s','\'',0};
199 row
= MSI_QueryGetRecord( package
->db
, Query_t
, action
);
202 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
203 msiobj_release(&row
->hdr
);
206 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
210 static const WCHAR template_s
[]=
211 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
213 static const WCHAR template_e
[]=
214 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
215 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
217 static const WCHAR format
[] =
218 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
222 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
224 sprintfW(message
,template_s
,timet
,action
);
226 sprintfW(message
,template_e
,timet
,action
,rc
);
228 row
= MSI_CreateRecord(1);
229 MSI_RecordSetStringW(row
,1,message
);
231 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
232 msiobj_release(&row
->hdr
);
235 UINT
msi_parse_command_line( MSIPACKAGE
*package
, LPCWSTR szCommandLine
,
241 LPWSTR prop
= NULL
, val
= NULL
;
244 return ERROR_SUCCESS
;
256 TRACE("Looking at %s\n",debugstr_w(ptr
));
258 ptr2
= strchrW(ptr
,'=');
261 ERR("command line contains unknown string : %s\n", debugstr_w(ptr
));
268 prop
= msi_alloc((len
+1)*sizeof(WCHAR
));
269 memcpy(prop
,ptr
,len
*sizeof(WCHAR
));
279 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
292 val
= msi_alloc((len
+1)*sizeof(WCHAR
));
293 memcpy(val
,ptr2
,len
*sizeof(WCHAR
));
296 if (lstrlenW(prop
) > 0)
298 TRACE("Found commandline property (%s) = (%s)\n",
299 debugstr_w(prop
), debugstr_w(val
));
300 MSI_SetPropertyW(package
,prop
,val
);
306 return ERROR_SUCCESS
;
310 static LPWSTR
* msi_split_string( LPCWSTR str
, WCHAR sep
)
313 LPWSTR p
, *ret
= NULL
;
319 /* count the number of substrings */
320 for ( pc
= str
, count
= 0; pc
; count
++ )
322 pc
= strchrW( pc
, sep
);
327 /* allocate space for an array of substring pointers and the substrings */
328 ret
= msi_alloc( (count
+1) * sizeof (LPWSTR
) +
329 (lstrlenW(str
)+1) * sizeof(WCHAR
) );
333 /* copy the string and set the pointers */
334 p
= (LPWSTR
) &ret
[count
+1];
336 for( count
= 0; (ret
[count
] = p
); count
++ )
338 p
= strchrW( p
, sep
);
346 static UINT
msi_check_transform_applicable( MSIPACKAGE
*package
, IStorage
*patch
)
348 static const WCHAR szSystemLanguageID
[] =
349 { 'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0 };
351 LPWSTR prod_code
, patch_product
, langid
= NULL
, template = NULL
;
352 UINT ret
= ERROR_FUNCTION_FAILED
;
354 prod_code
= msi_dup_property( package
, szProductCode
);
355 patch_product
= msi_get_suminfo_product( patch
);
357 TRACE("db = %s patch = %s\n", debugstr_w(prod_code
), debugstr_w(patch_product
));
359 if ( strstrW( patch_product
, prod_code
) )
364 si
= MSI_GetSummaryInformationW( patch
, 0 );
367 ERR("no summary information!\n");
371 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
374 ERR("no template property!\n");
375 msiobj_release( &si
->hdr
);
382 msiobj_release( &si
->hdr
);
386 langid
= msi_dup_property( package
, szSystemLanguageID
);
389 msiobj_release( &si
->hdr
);
393 p
= strchrW( template, ';' );
394 if (p
&& (!strcmpW( p
+ 1, langid
) || !strcmpW( p
+ 1, szZero
)))
396 TRACE("applicable transform\n");
400 /* FIXME: check platform */
402 msiobj_release( &si
->hdr
);
406 msi_free( patch_product
);
407 msi_free( prod_code
);
408 msi_free( template );
414 static UINT
msi_apply_substorage_transform( MSIPACKAGE
*package
,
415 MSIDATABASE
*patch_db
, LPCWSTR name
)
417 UINT ret
= ERROR_FUNCTION_FAILED
;
418 IStorage
*stg
= NULL
;
421 TRACE("%p %s\n", package
, debugstr_w(name
) );
425 ERR("expected a colon in %s\n", debugstr_w(name
));
426 return ERROR_FUNCTION_FAILED
;
429 r
= IStorage_OpenStorage( patch_db
->storage
, name
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg
);
432 ret
= msi_check_transform_applicable( package
, stg
);
433 if (ret
== ERROR_SUCCESS
)
434 msi_table_apply_transform( package
->db
, stg
);
436 TRACE("substorage transform %s wasn't applicable\n", debugstr_w(name
));
437 IStorage_Release( stg
);
440 ERR("failed to open substorage %s\n", debugstr_w(name
));
442 return ERROR_SUCCESS
;
445 UINT
msi_check_patch_applicable( MSIPACKAGE
*package
, MSISUMMARYINFO
*si
)
447 LPWSTR guid_list
, *guids
, product_code
;
448 UINT i
, ret
= ERROR_FUNCTION_FAILED
;
450 product_code
= msi_dup_property( package
, szProductCode
);
453 /* FIXME: the property ProductCode should be written into the DB somewhere */
454 ERR("no product code to check\n");
455 return ERROR_SUCCESS
;
458 guid_list
= msi_suminfo_dup_string( si
, PID_TEMPLATE
);
459 guids
= msi_split_string( guid_list
, ';' );
460 for ( i
= 0; guids
[i
] && ret
!= ERROR_SUCCESS
; i
++ )
462 if (!lstrcmpW( guids
[i
], product_code
))
466 msi_free( guid_list
);
467 msi_free( product_code
);
472 static UINT
msi_set_media_source_prop(MSIPACKAGE
*package
)
475 MSIRECORD
*rec
= NULL
;
480 static const WCHAR query
[] = {'S','E','L','E','C','T',' ',
481 '`','S','o','u','r','c','e','`',' ','F','R','O','M',' ',
482 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
483 '`','S','o','u','r','c','e','`',' ','I','S',' ',
484 'N','O','T',' ','N','U','L','L',0};
486 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
487 if (r
!= ERROR_SUCCESS
)
490 r
= MSI_ViewExecute(view
, 0);
491 if (r
!= ERROR_SUCCESS
)
494 if (MSI_ViewFetch(view
, &rec
) == ERROR_SUCCESS
)
496 prop
= MSI_RecordGetString(rec
, 1);
497 patch
= msi_dup_property(package
, szPatch
);
498 MSI_SetPropertyW(package
, prop
, patch
);
503 if (rec
) msiobj_release(&rec
->hdr
);
504 msiobj_release(&view
->hdr
);
509 static UINT
msi_parse_patch_summary( MSIPACKAGE
*package
, MSIDATABASE
*patch_db
)
512 LPWSTR str
, *substorage
;
513 UINT i
, r
= ERROR_SUCCESS
;
515 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
517 return ERROR_FUNCTION_FAILED
;
519 if (msi_check_patch_applicable( package
, si
) != ERROR_SUCCESS
)
521 TRACE("Patch not applicable\n");
522 return ERROR_SUCCESS
;
525 package
->patch
= msi_alloc(sizeof(MSIPATCHINFO
));
527 return ERROR_OUTOFMEMORY
;
529 package
->patch
->patchcode
= msi_suminfo_dup_string(si
, PID_REVNUMBER
);
530 if (!package
->patch
->patchcode
)
531 return ERROR_OUTOFMEMORY
;
533 /* enumerate the substorage */
534 str
= msi_suminfo_dup_string( si
, PID_LASTAUTHOR
);
535 package
->patch
->transforms
= str
;
537 substorage
= msi_split_string( str
, ';' );
538 for ( i
= 0; substorage
&& substorage
[i
] && r
== ERROR_SUCCESS
; i
++ )
539 r
= msi_apply_substorage_transform( package
, patch_db
, substorage
[i
] );
541 msi_free( substorage
);
542 msiobj_release( &si
->hdr
);
544 msi_set_media_source_prop(package
);
549 static UINT
msi_apply_patch_package( MSIPACKAGE
*package
, LPCWSTR file
)
551 MSIDATABASE
*patch_db
= NULL
;
554 TRACE("%p %s\n", package
, debugstr_w( file
) );
557 * We probably want to make sure we only open a patch collection here.
558 * Patch collections (.msp) and databases (.msi) have different GUIDs
559 * but currently MSI_OpenDatabaseW will accept both.
561 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &patch_db
);
562 if ( r
!= ERROR_SUCCESS
)
564 ERR("failed to open patch collection %s\n", debugstr_w( file
) );
568 msi_parse_patch_summary( package
, patch_db
);
571 * There might be a CAB file in the patch package,
572 * so append it to the list of storage to search for streams.
574 append_storage_to_db( package
->db
, patch_db
->storage
);
576 msiobj_release( &patch_db
->hdr
);
578 return ERROR_SUCCESS
;
581 /* get the PATCH property, and apply all the patches it specifies */
582 static UINT
msi_apply_patches( MSIPACKAGE
*package
)
584 LPWSTR patch_list
, *patches
;
585 UINT i
, r
= ERROR_SUCCESS
;
587 patch_list
= msi_dup_property( package
, szPatch
);
589 TRACE("patches to be applied: %s\n", debugstr_w( patch_list
) );
591 patches
= msi_split_string( patch_list
, ';' );
592 for( i
=0; patches
&& patches
[i
] && r
== ERROR_SUCCESS
; i
++ )
593 r
= msi_apply_patch_package( package
, patches
[i
] );
596 msi_free( patch_list
);
601 static UINT
msi_apply_transforms( MSIPACKAGE
*package
)
603 static const WCHAR szTransforms
[] = {
604 'T','R','A','N','S','F','O','R','M','S',0 };
605 LPWSTR xform_list
, *xforms
;
606 UINT i
, r
= ERROR_SUCCESS
;
608 xform_list
= msi_dup_property( package
, szTransforms
);
609 xforms
= msi_split_string( xform_list
, ';' );
611 for( i
=0; xforms
&& xforms
[i
] && r
== ERROR_SUCCESS
; i
++ )
613 if (xforms
[i
][0] == ':')
614 r
= msi_apply_substorage_transform( package
, package
->db
, xforms
[i
] );
616 r
= MSI_DatabaseApplyTransformW( package
->db
, xforms
[i
], 0 );
620 msi_free( xform_list
);
625 static BOOL
ui_sequence_exists( MSIPACKAGE
*package
)
630 static const WCHAR ExecSeqQuery
[] =
631 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
632 '`','I','n','s','t','a','l','l',
633 'U','I','S','e','q','u','e','n','c','e','`',
634 ' ','W','H','E','R','E',' ',
635 '`','S','e','q','u','e','n','c','e','`',' ',
636 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
637 '`','S','e','q','u','e','n','c','e','`',0};
639 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
640 if (rc
== ERROR_SUCCESS
)
642 msiobj_release(&view
->hdr
);
649 static UINT
msi_set_sourcedir_props(MSIPACKAGE
*package
, BOOL replace
)
652 LPWSTR source
, check
;
655 static const WCHAR szOriginalDatabase
[] =
656 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
658 db
= msi_dup_property( package
, szOriginalDatabase
);
660 return ERROR_OUTOFMEMORY
;
662 p
= strrchrW( db
, '\\' );
665 p
= strrchrW( db
, '/' );
669 return ERROR_SUCCESS
;
674 source
= msi_alloc( len
* sizeof(WCHAR
) );
675 lstrcpynW( source
, db
, len
);
677 check
= msi_dup_property( package
, cszSourceDir
);
678 if (!check
|| replace
)
679 MSI_SetPropertyW( package
, cszSourceDir
, source
);
683 check
= msi_dup_property( package
, cszSOURCEDIR
);
684 if (!check
|| replace
)
685 MSI_SetPropertyW( package
, cszSOURCEDIR
, source
);
691 return ERROR_SUCCESS
;
694 static BOOL
needs_ui_sequence(MSIPACKAGE
*package
)
696 INT level
= msi_get_property_int(package
, szUILevel
, 0);
697 return (level
& INSTALLUILEVEL_MASK
) >= INSTALLUILEVEL_REDUCED
;
700 static UINT
msi_set_context(MSIPACKAGE
*package
)
707 package
->Context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
709 r
= MSI_GetPropertyW(package
, szAllUsers
, val
, &sz
);
710 if (r
== ERROR_SUCCESS
)
713 if (num
== 1 || num
== 2)
714 package
->Context
= MSIINSTALLCONTEXT_MACHINE
;
717 return ERROR_SUCCESS
;
720 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
723 LPCWSTR cond
, action
;
724 MSIPACKAGE
*package
= param
;
726 action
= MSI_RecordGetString(row
,1);
729 ERR("Error is retrieving action name\n");
730 return ERROR_FUNCTION_FAILED
;
733 /* check conditions */
734 cond
= MSI_RecordGetString(row
,2);
736 /* this is a hack to skip errors in the condition code */
737 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
739 TRACE("Skipping action: %s (condition is false)\n", debugstr_w(action
));
740 return ERROR_SUCCESS
;
743 if (needs_ui_sequence(package
))
744 rc
= ACTION_PerformUIAction(package
, action
, -1);
746 rc
= ACTION_PerformAction(package
, action
, -1, FALSE
);
748 msi_dialog_check_messages( NULL
);
750 if (package
->CurrentInstallState
!= ERROR_SUCCESS
)
751 rc
= package
->CurrentInstallState
;
753 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
756 if (rc
!= ERROR_SUCCESS
)
757 ERR("Execution halted, action %s returned %i\n", debugstr_w(action
), rc
);
762 UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR szTable
, INT iSequenceMode
)
766 static const WCHAR query
[] =
767 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
769 ' ','W','H','E','R','E',' ',
770 '`','S','e','q','u','e','n','c','e','`',' ',
771 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
772 '`','S','e','q','u','e','n','c','e','`',0};
774 TRACE("%p %s %i\n", package
, debugstr_w(szTable
), iSequenceMode
);
776 r
= MSI_OpenQuery( package
->db
, &view
, query
, szTable
);
777 if (r
== ERROR_SUCCESS
)
779 r
= MSI_IterateRecords( view
, NULL
, ITERATE_Actions
, package
);
780 msiobj_release(&view
->hdr
);
786 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
790 static const WCHAR ExecSeqQuery
[] =
791 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
792 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
793 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
794 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
795 'O','R','D','E','R',' ', 'B','Y',' ',
796 '`','S','e','q','u','e','n','c','e','`',0 };
797 static const WCHAR IVQuery
[] =
798 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
799 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
800 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
801 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
802 ' ','\'', 'I','n','s','t','a','l','l',
803 'V','a','l','i','d','a','t','e','\'', 0};
806 if (package
->script
->ExecuteSequenceRun
)
808 TRACE("Execute Sequence already Run\n");
809 return ERROR_SUCCESS
;
812 package
->script
->ExecuteSequenceRun
= TRUE
;
814 /* get the sequence number */
817 MSIRECORD
*row
= MSI_QueryGetRecord(package
->db
, IVQuery
);
819 return ERROR_FUNCTION_FAILED
;
820 seq
= MSI_RecordGetInteger(row
,1);
821 msiobj_release(&row
->hdr
);
824 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
825 if (rc
== ERROR_SUCCESS
)
827 TRACE("Running the actions\n");
829 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
830 msiobj_release(&view
->hdr
);
836 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
840 static const WCHAR ExecSeqQuery
[] =
841 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
842 '`','I','n','s','t','a','l','l',
843 'U','I','S','e','q','u','e','n','c','e','`',
844 ' ','W','H','E','R','E',' ',
845 '`','S','e','q','u','e','n','c','e','`',' ',
846 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
847 '`','S','e','q','u','e','n','c','e','`',0};
849 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
850 if (rc
== ERROR_SUCCESS
)
852 TRACE("Running the actions\n");
854 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
855 msiobj_release(&view
->hdr
);
861 /********************************************************
862 * ACTION helper functions and functions that perform the actions
863 *******************************************************/
864 static BOOL
ACTION_HandleCustomAction( MSIPACKAGE
* package
, LPCWSTR action
,
865 UINT
* rc
, UINT script
, BOOL force
)
870 arc
= ACTION_CustomAction(package
, action
, script
, force
);
872 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
881 * Actual Action Handlers
884 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
886 MSIPACKAGE
*package
= param
;
887 LPCWSTR dir
, component
;
893 component
= MSI_RecordGetString(row
, 2);
894 comp
= get_loaded_component(package
, component
);
896 return ERROR_SUCCESS
;
898 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
900 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
901 comp
->Action
= comp
->Installed
;
902 return ERROR_SUCCESS
;
904 comp
->Action
= INSTALLSTATE_LOCAL
;
906 dir
= MSI_RecordGetString(row
,1);
909 ERR("Unable to get folder id\n");
910 return ERROR_SUCCESS
;
913 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,TRUE
,&folder
);
916 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
917 return ERROR_SUCCESS
;
920 TRACE("Folder is %s\n",debugstr_w(full_path
));
923 uirow
= MSI_CreateRecord(1);
924 MSI_RecordSetStringW(uirow
,1,full_path
);
925 ui_actiondata(package
,szCreateFolders
,uirow
);
926 msiobj_release( &uirow
->hdr
);
928 if (folder
->State
== 0)
929 create_full_pathW(full_path
);
934 return ERROR_SUCCESS
;
937 /* FIXME: probably should merge this with the above function */
938 static UINT
msi_create_directory( MSIPACKAGE
* package
, LPCWSTR dir
)
940 UINT rc
= ERROR_SUCCESS
;
944 install_path
= resolve_folder(package
, dir
, FALSE
, FALSE
, TRUE
, &folder
);
946 return ERROR_FUNCTION_FAILED
;
948 /* create the path */
949 if (folder
->State
== 0)
951 create_full_pathW(install_path
);
954 msi_free(install_path
);
959 UINT
msi_create_component_directories( MSIPACKAGE
*package
)
963 /* create all the folders required by the components are going to install */
964 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
966 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
968 msi_create_directory( package
, comp
->Directory
);
971 return ERROR_SUCCESS
;
974 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
976 static const WCHAR ExecSeqQuery
[] =
977 {'S','E','L','E','C','T',' ',
978 '`','D','i','r','e','c','t','o','r','y','_','`',
979 ' ','F','R','O','M',' ',
980 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
984 /* create all the empty folders specified in the CreateFolder table */
985 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
986 if (rc
!= ERROR_SUCCESS
)
987 return ERROR_SUCCESS
;
989 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
990 msiobj_release(&view
->hdr
);
995 static UINT
ITERATE_RemoveFolders( MSIRECORD
*row
, LPVOID param
)
997 MSIPACKAGE
*package
= param
;
998 LPCWSTR dir
, component
;
1004 component
= MSI_RecordGetString(row
, 2);
1005 comp
= get_loaded_component(package
, component
);
1007 return ERROR_SUCCESS
;
1009 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
1011 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
1012 comp
->Action
= comp
->Installed
;
1013 return ERROR_SUCCESS
;
1015 comp
->Action
= INSTALLSTATE_ABSENT
;
1017 dir
= MSI_RecordGetString( row
, 1 );
1020 ERR("Unable to get folder id\n");
1021 return ERROR_SUCCESS
;
1024 full_path
= resolve_folder( package
, dir
, FALSE
, FALSE
, TRUE
, &folder
);
1027 ERR("Unable to resolve folder id %s\n", debugstr_w(dir
));
1028 return ERROR_SUCCESS
;
1031 TRACE("folder is %s\n", debugstr_w(full_path
));
1033 uirow
= MSI_CreateRecord( 1 );
1034 MSI_RecordSetStringW( uirow
, 1, full_path
);
1035 ui_actiondata( package
, szRemoveFolders
, uirow
);
1036 msiobj_release( &uirow
->hdr
);
1038 RemoveDirectoryW( full_path
);
1041 msi_free( full_path
);
1042 return ERROR_SUCCESS
;
1045 static UINT
ACTION_RemoveFolders( MSIPACKAGE
*package
)
1047 static const WCHAR query
[] =
1048 {'S','E','L','E','C','T',' ', '`','D','i','r','e','c','t','o','r','y','_','`',
1049 ' ','F','R','O','M',' ', '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
1054 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1055 if (rc
!= ERROR_SUCCESS
)
1056 return ERROR_SUCCESS
;
1058 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveFolders
, package
);
1059 msiobj_release( &view
->hdr
);
1064 static UINT
load_component( MSIRECORD
*row
, LPVOID param
)
1066 MSIPACKAGE
*package
= param
;
1069 comp
= msi_alloc_zero( sizeof(MSICOMPONENT
) );
1071 return ERROR_FUNCTION_FAILED
;
1073 list_add_tail( &package
->components
, &comp
->entry
);
1075 /* fill in the data */
1076 comp
->Component
= msi_dup_record_field( row
, 1 );
1078 TRACE("Loading Component %s\n", debugstr_w(comp
->Component
));
1080 comp
->ComponentId
= msi_dup_record_field( row
, 2 );
1081 comp
->Directory
= msi_dup_record_field( row
, 3 );
1082 comp
->Attributes
= MSI_RecordGetInteger(row
,4);
1083 comp
->Condition
= msi_dup_record_field( row
, 5 );
1084 comp
->KeyPath
= msi_dup_record_field( row
, 6 );
1086 comp
->Installed
= INSTALLSTATE_UNKNOWN
;
1087 msi_component_set_state(package
, comp
, INSTALLSTATE_UNKNOWN
);
1089 return ERROR_SUCCESS
;
1092 static UINT
load_all_components( MSIPACKAGE
*package
)
1094 static const WCHAR query
[] = {
1095 'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1096 '`','C','o','m','p','o','n','e','n','t','`',0 };
1100 if (!list_empty(&package
->components
))
1101 return ERROR_SUCCESS
;
1103 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1104 if (r
!= ERROR_SUCCESS
)
1107 r
= MSI_IterateRecords(view
, NULL
, load_component
, package
);
1108 msiobj_release(&view
->hdr
);
1113 MSIPACKAGE
*package
;
1114 MSIFEATURE
*feature
;
1117 static UINT
add_feature_component( MSIFEATURE
*feature
, MSICOMPONENT
*comp
)
1121 cl
= msi_alloc( sizeof (*cl
) );
1123 return ERROR_NOT_ENOUGH_MEMORY
;
1124 cl
->component
= comp
;
1125 list_add_tail( &feature
->Components
, &cl
->entry
);
1127 return ERROR_SUCCESS
;
1130 static UINT
add_feature_child( MSIFEATURE
*parent
, MSIFEATURE
*child
)
1134 fl
= msi_alloc( sizeof(*fl
) );
1136 return ERROR_NOT_ENOUGH_MEMORY
;
1137 fl
->feature
= child
;
1138 list_add_tail( &parent
->Children
, &fl
->entry
);
1140 return ERROR_SUCCESS
;
1143 static UINT
iterate_load_featurecomponents(MSIRECORD
*row
, LPVOID param
)
1145 _ilfs
* ilfs
= param
;
1149 component
= MSI_RecordGetString(row
,1);
1151 /* check to see if the component is already loaded */
1152 comp
= get_loaded_component( ilfs
->package
, component
);
1155 ERR("unknown component %s\n", debugstr_w(component
));
1156 return ERROR_FUNCTION_FAILED
;
1159 add_feature_component( ilfs
->feature
, comp
);
1160 comp
->Enabled
= TRUE
;
1162 return ERROR_SUCCESS
;
1165 static MSIFEATURE
*find_feature_by_name( MSIPACKAGE
*package
, LPCWSTR name
)
1167 MSIFEATURE
*feature
;
1172 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1174 if ( !lstrcmpW( feature
->Feature
, name
) )
1181 static UINT
load_feature(MSIRECORD
* row
, LPVOID param
)
1183 MSIPACKAGE
* package
= param
;
1184 MSIFEATURE
* feature
;
1185 static const WCHAR Query1
[] =
1186 {'S','E','L','E','C','T',' ',
1187 '`','C','o','m','p','o','n','e','n','t','_','`',
1188 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1189 'C','o','m','p','o','n','e','n','t','s','`',' ',
1190 'W','H','E','R','E',' ',
1191 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1196 /* fill in the data */
1198 feature
= msi_alloc_zero( sizeof (MSIFEATURE
) );
1200 return ERROR_NOT_ENOUGH_MEMORY
;
1202 list_init( &feature
->Children
);
1203 list_init( &feature
->Components
);
1205 feature
->Feature
= msi_dup_record_field( row
, 1 );
1207 TRACE("Loading feature %s\n",debugstr_w(feature
->Feature
));
1209 feature
->Feature_Parent
= msi_dup_record_field( row
, 2 );
1210 feature
->Title
= msi_dup_record_field( row
, 3 );
1211 feature
->Description
= msi_dup_record_field( row
, 4 );
1213 if (!MSI_RecordIsNull(row
,5))
1214 feature
->Display
= MSI_RecordGetInteger(row
,5);
1216 feature
->Level
= MSI_RecordGetInteger(row
,6);
1217 feature
->Directory
= msi_dup_record_field( row
, 7 );
1218 feature
->Attributes
= MSI_RecordGetInteger(row
,8);
1220 feature
->Installed
= INSTALLSTATE_UNKNOWN
;
1221 msi_feature_set_state(package
, feature
, INSTALLSTATE_UNKNOWN
);
1223 list_add_tail( &package
->features
, &feature
->entry
);
1225 /* load feature components */
1227 rc
= MSI_OpenQuery( package
->db
, &view
, Query1
, feature
->Feature
);
1228 if (rc
!= ERROR_SUCCESS
)
1229 return ERROR_SUCCESS
;
1231 ilfs
.package
= package
;
1232 ilfs
.feature
= feature
;
1234 MSI_IterateRecords(view
, NULL
, iterate_load_featurecomponents
, &ilfs
);
1235 msiobj_release(&view
->hdr
);
1237 return ERROR_SUCCESS
;
1240 static UINT
find_feature_children(MSIRECORD
* row
, LPVOID param
)
1242 MSIPACKAGE
* package
= param
;
1243 MSIFEATURE
*parent
, *child
;
1245 child
= find_feature_by_name( package
, MSI_RecordGetString( row
, 1 ) );
1247 return ERROR_FUNCTION_FAILED
;
1249 if (!child
->Feature_Parent
)
1250 return ERROR_SUCCESS
;
1252 parent
= find_feature_by_name( package
, child
->Feature_Parent
);
1254 return ERROR_FUNCTION_FAILED
;
1256 add_feature_child( parent
, child
);
1257 return ERROR_SUCCESS
;
1260 static UINT
load_all_features( MSIPACKAGE
*package
)
1262 static const WCHAR query
[] = {
1263 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1264 '`','F','e','a','t','u','r','e','`',' ','O','R','D','E','R',
1265 ' ','B','Y',' ','`','D','i','s','p','l','a','y','`',0};
1269 if (!list_empty(&package
->features
))
1270 return ERROR_SUCCESS
;
1272 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1273 if (r
!= ERROR_SUCCESS
)
1276 r
= MSI_IterateRecords( view
, NULL
, load_feature
, package
);
1277 if (r
!= ERROR_SUCCESS
)
1280 r
= MSI_IterateRecords( view
, NULL
, find_feature_children
, package
);
1281 msiobj_release( &view
->hdr
);
1286 static LPWSTR
folder_split_path(LPWSTR p
, WCHAR ch
)
1297 static UINT
load_file_hash(MSIPACKAGE
*package
, MSIFILE
*file
)
1299 static const WCHAR query
[] = {
1300 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1301 '`','M','s','i','F','i','l','e','H','a','s','h','`',' ',
1302 'W','H','E','R','E',' ','`','F','i','l','e','_','`',' ','=',' ','\'','%','s','\'',0};
1303 MSIQUERY
*view
= NULL
;
1304 MSIRECORD
*row
= NULL
;
1307 TRACE("%s\n", debugstr_w(file
->File
));
1309 r
= MSI_OpenQuery(package
->db
, &view
, query
, file
->File
);
1310 if (r
!= ERROR_SUCCESS
)
1313 r
= MSI_ViewExecute(view
, NULL
);
1314 if (r
!= ERROR_SUCCESS
)
1317 r
= MSI_ViewFetch(view
, &row
);
1318 if (r
!= ERROR_SUCCESS
)
1321 file
->hash
.dwFileHashInfoSize
= sizeof(MSIFILEHASHINFO
);
1322 file
->hash
.dwData
[0] = MSI_RecordGetInteger(row
, 3);
1323 file
->hash
.dwData
[1] = MSI_RecordGetInteger(row
, 4);
1324 file
->hash
.dwData
[2] = MSI_RecordGetInteger(row
, 5);
1325 file
->hash
.dwData
[3] = MSI_RecordGetInteger(row
, 6);
1328 if (view
) msiobj_release(&view
->hdr
);
1329 if (row
) msiobj_release(&row
->hdr
);
1333 static UINT
load_file(MSIRECORD
*row
, LPVOID param
)
1335 MSIPACKAGE
* package
= param
;
1339 /* fill in the data */
1341 file
= msi_alloc_zero( sizeof (MSIFILE
) );
1343 return ERROR_NOT_ENOUGH_MEMORY
;
1345 file
->File
= msi_dup_record_field( row
, 1 );
1347 component
= MSI_RecordGetString( row
, 2 );
1348 file
->Component
= get_loaded_component( package
, component
);
1350 if (!file
->Component
)
1352 WARN("Component not found: %s\n", debugstr_w(component
));
1353 msi_free(file
->File
);
1355 return ERROR_SUCCESS
;
1358 file
->FileName
= msi_dup_record_field( row
, 3 );
1359 reduce_to_longfilename( file
->FileName
);
1361 file
->ShortName
= msi_dup_record_field( row
, 3 );
1362 file
->LongName
= strdupW( folder_split_path(file
->ShortName
, '|'));
1364 file
->FileSize
= MSI_RecordGetInteger( row
, 4 );
1365 file
->Version
= msi_dup_record_field( row
, 5 );
1366 file
->Language
= msi_dup_record_field( row
, 6 );
1367 file
->Attributes
= MSI_RecordGetInteger( row
, 7 );
1368 file
->Sequence
= MSI_RecordGetInteger( row
, 8 );
1370 file
->state
= msifs_invalid
;
1372 /* if the compressed bits are not set in the file attributes,
1373 * then read the information from the package word count property
1375 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1377 file
->IsCompressed
= FALSE
;
1379 else if (file
->Attributes
&
1380 (msidbFileAttributesCompressed
| msidbFileAttributesPatchAdded
))
1382 file
->IsCompressed
= TRUE
;
1384 else if (file
->Attributes
& msidbFileAttributesNoncompressed
)
1386 file
->IsCompressed
= FALSE
;
1390 file
->IsCompressed
= package
->WordCount
& msidbSumInfoSourceTypeCompressed
;
1393 load_file_hash(package
, file
);
1395 TRACE("File Loaded (%s)\n",debugstr_w(file
->File
));
1397 list_add_tail( &package
->files
, &file
->entry
);
1399 return ERROR_SUCCESS
;
1402 static UINT
load_all_files(MSIPACKAGE
*package
)
1406 static const WCHAR Query
[] =
1407 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1408 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1409 '`','S','e','q','u','e','n','c','e','`', 0};
1411 if (!list_empty(&package
->files
))
1412 return ERROR_SUCCESS
;
1414 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1415 if (rc
!= ERROR_SUCCESS
)
1416 return ERROR_SUCCESS
;
1418 rc
= MSI_IterateRecords(view
, NULL
, load_file
, package
);
1419 msiobj_release(&view
->hdr
);
1421 return ERROR_SUCCESS
;
1424 static UINT
load_folder( MSIRECORD
*row
, LPVOID param
)
1426 MSIPACKAGE
*package
= param
;
1427 static WCHAR szEmpty
[] = { 0 };
1428 LPWSTR p
, tgt_short
, tgt_long
, src_short
, src_long
;
1431 folder
= msi_alloc_zero( sizeof (MSIFOLDER
) );
1433 return ERROR_NOT_ENOUGH_MEMORY
;
1435 folder
->Directory
= msi_dup_record_field( row
, 1 );
1437 TRACE("%s\n", debugstr_w(folder
->Directory
));
1439 p
= msi_dup_record_field(row
, 3);
1441 /* split src and target dir */
1443 src_short
= folder_split_path( p
, ':' );
1445 /* split the long and short paths */
1446 tgt_long
= folder_split_path( tgt_short
, '|' );
1447 src_long
= folder_split_path( src_short
, '|' );
1449 /* check for no-op dirs */
1450 if (!lstrcmpW(szDot
, tgt_short
))
1451 tgt_short
= szEmpty
;
1452 if (!lstrcmpW(szDot
, src_short
))
1453 src_short
= szEmpty
;
1456 tgt_long
= tgt_short
;
1459 src_short
= tgt_short
;
1460 src_long
= tgt_long
;
1464 src_long
= src_short
;
1466 /* FIXME: use the target short path too */
1467 folder
->TargetDefault
= strdupW(tgt_long
);
1468 folder
->SourceShortPath
= strdupW(src_short
);
1469 folder
->SourceLongPath
= strdupW(src_long
);
1472 TRACE("TargetDefault = %s\n",debugstr_w( folder
->TargetDefault
));
1473 TRACE("SourceLong = %s\n", debugstr_w( folder
->SourceLongPath
));
1474 TRACE("SourceShort = %s\n", debugstr_w( folder
->SourceShortPath
));
1476 folder
->Parent
= msi_dup_record_field( row
, 2 );
1478 folder
->Property
= msi_dup_property( package
, folder
->Directory
);
1480 list_add_tail( &package
->folders
, &folder
->entry
);
1482 TRACE("returning %p\n", folder
);
1484 return ERROR_SUCCESS
;
1487 static UINT
load_all_folders( MSIPACKAGE
*package
)
1489 static const WCHAR query
[] = {
1490 'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1491 '`','D','i','r','e','c','t','o','r','y','`',0 };
1495 if (!list_empty(&package
->folders
))
1496 return ERROR_SUCCESS
;
1498 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1499 if (r
!= ERROR_SUCCESS
)
1502 r
= MSI_IterateRecords(view
, NULL
, load_folder
, package
);
1503 msiobj_release(&view
->hdr
);
1508 * I am not doing any of the costing functionality yet.
1509 * Mostly looking at doing the Component and Feature loading
1511 * The native MSI does A LOT of modification to tables here. Mostly adding
1512 * a lot of temporary columns to the Feature and Component tables.
1514 * note: Native msi also tracks the short filename. But I am only going to
1515 * track the long ones. Also looking at this directory table
1516 * it appears that the directory table does not get the parents
1517 * resolved base on property only based on their entries in the
1520 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1522 static const WCHAR szCosting
[] =
1523 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1525 MSI_SetPropertyW(package
, szCosting
, szZero
);
1526 MSI_SetPropertyW(package
, cszRootDrive
, c_colon
);
1528 load_all_folders( package
);
1529 load_all_components( package
);
1530 load_all_features( package
);
1531 load_all_files( package
);
1533 return ERROR_SUCCESS
;
1536 static UINT
execute_script(MSIPACKAGE
*package
, UINT script
)
1539 UINT rc
= ERROR_SUCCESS
;
1541 TRACE("Executing Script %i\n",script
);
1543 if (!package
->script
)
1545 ERR("no script!\n");
1546 return ERROR_FUNCTION_FAILED
;
1549 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
1552 action
= package
->script
->Actions
[script
][i
];
1553 ui_actionstart(package
, action
);
1554 TRACE("Executing Action (%s)\n",debugstr_w(action
));
1555 rc
= ACTION_PerformAction(package
, action
, script
, TRUE
);
1556 if (rc
!= ERROR_SUCCESS
)
1559 msi_free_action_script(package
, script
);
1563 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1565 return ERROR_SUCCESS
;
1568 static void ACTION_GetComponentInstallStates(MSIPACKAGE
*package
)
1574 state
= MsiQueryProductStateW(package
->ProductCode
);
1576 LIST_FOR_EACH_ENTRY(comp
, &package
->components
, MSICOMPONENT
, entry
)
1578 if (!comp
->ComponentId
)
1581 if (state
!= INSTALLSTATE_LOCAL
&& state
!= INSTALLSTATE_DEFAULT
)
1582 comp
->Installed
= INSTALLSTATE_ABSENT
;
1585 r
= MsiQueryComponentStateW(package
->ProductCode
, NULL
,
1586 package
->Context
, comp
->ComponentId
,
1588 if (r
!= ERROR_SUCCESS
)
1589 comp
->Installed
= INSTALLSTATE_ABSENT
;
1594 static void ACTION_GetFeatureInstallStates(MSIPACKAGE
*package
)
1596 MSIFEATURE
*feature
;
1599 state
= MsiQueryProductStateW(package
->ProductCode
);
1601 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1603 if (state
!= INSTALLSTATE_LOCAL
&& state
!= INSTALLSTATE_DEFAULT
)
1604 feature
->Installed
= INSTALLSTATE_ABSENT
;
1607 feature
->Installed
= MsiQueryFeatureStateW(package
->ProductCode
,
1613 static BOOL
process_state_property(MSIPACKAGE
* package
, int level
,
1614 LPCWSTR property
, INSTALLSTATE state
)
1617 MSIFEATURE
*feature
;
1619 override
= msi_dup_property( package
, property
);
1623 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1625 if (lstrcmpW(property
, szRemove
) &&
1626 (feature
->Level
<= 0 || feature
->Level
> level
))
1629 if (!strcmpW(property
, szReinstall
)) state
= feature
->Installed
;
1631 if (strcmpiW(override
, szAll
)==0)
1632 msi_feature_set_state(package
, feature
, state
);
1635 LPWSTR ptr
= override
;
1636 LPWSTR ptr2
= strchrW(override
,',');
1640 int len
= ptr2
- ptr
;
1642 if ((ptr2
&& strlenW(feature
->Feature
) == len
&& !strncmpW(ptr
, feature
->Feature
, len
))
1643 || (!ptr2
&& !strcmpW(ptr
, feature
->Feature
)))
1645 msi_feature_set_state(package
, feature
, state
);
1651 ptr2
= strchrW(ptr
,',');
1663 static BOOL
process_overrides( MSIPACKAGE
*package
, int level
)
1665 static const WCHAR szAddLocal
[] =
1666 {'A','D','D','L','O','C','A','L',0};
1667 static const WCHAR szAddSource
[] =
1668 {'A','D','D','S','O','U','R','C','E',0};
1669 static const WCHAR szAdvertise
[] =
1670 {'A','D','V','E','R','T','I','S','E',0};
1673 /* all these activation/deactivation things happen in order and things
1674 * later on the list override things earlier on the list.
1676 * 0 INSTALLLEVEL processing
1689 ret
|= process_state_property( package
, level
, szAddLocal
, INSTALLSTATE_LOCAL
);
1690 ret
|= process_state_property( package
, level
, szRemove
, INSTALLSTATE_ABSENT
);
1691 ret
|= process_state_property( package
, level
, szAddSource
, INSTALLSTATE_SOURCE
);
1692 ret
|= process_state_property( package
, level
, szReinstall
, INSTALLSTATE_UNKNOWN
);
1693 ret
|= process_state_property( package
, level
, szAdvertise
, INSTALLSTATE_ADVERTISED
);
1696 MSI_SetPropertyW( package
, szPreselected
, szOne
);
1701 UINT
MSI_SetFeatureStates(MSIPACKAGE
*package
)
1704 static const WCHAR szlevel
[] =
1705 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1706 MSICOMPONENT
* component
;
1707 MSIFEATURE
*feature
;
1709 TRACE("Checking Install Level\n");
1711 level
= msi_get_property_int(package
, szlevel
, 1);
1713 if (!msi_get_property_int( package
, szPreselected
, 0 ))
1715 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1717 BOOL feature_state
= ((feature
->Level
> 0) &&
1718 (feature
->Level
<= level
));
1720 if ((feature_state
) && (feature
->Action
== INSTALLSTATE_UNKNOWN
))
1722 if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1723 msi_feature_set_state(package
, feature
, INSTALLSTATE_SOURCE
);
1724 else if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1725 msi_feature_set_state(package
, feature
, INSTALLSTATE_ADVERTISED
);
1727 msi_feature_set_state(package
, feature
, INSTALLSTATE_LOCAL
);
1731 /* disable child features of unselected parent features */
1732 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1736 if (feature
->Level
> 0 && feature
->Level
<= level
)
1739 LIST_FOR_EACH_ENTRY( fl
, &feature
->Children
, FeatureList
, entry
)
1740 msi_feature_set_state(package
, fl
->feature
, INSTALLSTATE_UNKNOWN
);
1745 * now we want to enable or disable components base on feature
1748 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1752 TRACE("Examining Feature %s (Level %i, Installed %i, Action %i)\n",
1753 debugstr_w(feature
->Feature
), feature
->Level
, feature
->Installed
, feature
->Action
);
1755 if (!feature
->Level
)
1758 /* features with components that have compressed files are made local */
1759 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1761 if (cl
->component
->Enabled
&&
1762 cl
->component
->ForceLocalState
&&
1763 feature
->Action
== INSTALLSTATE_SOURCE
)
1765 msi_feature_set_state(package
, feature
, INSTALLSTATE_LOCAL
);
1770 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1772 component
= cl
->component
;
1774 if (!component
->Enabled
)
1777 switch (feature
->Action
)
1779 case INSTALLSTATE_ABSENT
:
1780 component
->anyAbsent
= 1;
1782 case INSTALLSTATE_ADVERTISED
:
1783 component
->hasAdvertiseFeature
= 1;
1785 case INSTALLSTATE_SOURCE
:
1786 component
->hasSourceFeature
= 1;
1788 case INSTALLSTATE_LOCAL
:
1789 component
->hasLocalFeature
= 1;
1791 case INSTALLSTATE_DEFAULT
:
1792 if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1793 component
->hasAdvertiseFeature
= 1;
1794 else if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1795 component
->hasSourceFeature
= 1;
1797 component
->hasLocalFeature
= 1;
1805 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1807 /* if the component isn't enabled, leave it alone */
1808 if (!component
->Enabled
)
1811 /* check if it's local or source */
1812 if (!(component
->Attributes
& msidbComponentAttributesOptional
) &&
1813 (component
->hasLocalFeature
|| component
->hasSourceFeature
))
1815 if ((component
->Attributes
& msidbComponentAttributesSourceOnly
) &&
1816 !component
->ForceLocalState
)
1817 msi_component_set_state(package
, component
, INSTALLSTATE_SOURCE
);
1819 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
1823 /* if any feature is local, the component must be local too */
1824 if (component
->hasLocalFeature
)
1826 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
1830 if (component
->hasSourceFeature
)
1832 msi_component_set_state(package
, component
, INSTALLSTATE_SOURCE
);
1836 if (component
->hasAdvertiseFeature
)
1838 msi_component_set_state(package
, component
, INSTALLSTATE_ADVERTISED
);
1842 TRACE("nobody wants component %s\n", debugstr_w(component
->Component
));
1843 if (component
->anyAbsent
)
1844 msi_component_set_state(package
, component
, INSTALLSTATE_ABSENT
);
1847 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1849 if (component
->Action
== INSTALLSTATE_DEFAULT
)
1851 TRACE("%s was default, setting to local\n", debugstr_w(component
->Component
));
1852 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
1855 TRACE("Result: Component %s (Installed %i, Action %i)\n",
1856 debugstr_w(component
->Component
), component
->Installed
, component
->Action
);
1860 return ERROR_SUCCESS
;
1863 static UINT
ITERATE_CostFinalizeDirectories(MSIRECORD
*row
, LPVOID param
)
1865 MSIPACKAGE
*package
= param
;
1870 name
= MSI_RecordGetString(row
,1);
1872 f
= get_loaded_folder(package
, name
);
1873 if (!f
) return ERROR_SUCCESS
;
1875 /* reset the ResolvedTarget */
1876 msi_free(f
->ResolvedTarget
);
1877 f
->ResolvedTarget
= NULL
;
1879 /* This helper function now does ALL the work */
1880 TRACE("Dir %s ...\n",debugstr_w(name
));
1881 path
= resolve_folder(package
,name
,FALSE
,TRUE
,TRUE
,NULL
);
1882 TRACE("resolves to %s\n",debugstr_w(path
));
1885 return ERROR_SUCCESS
;
1888 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1890 MSIPACKAGE
*package
= param
;
1892 MSIFEATURE
*feature
;
1894 name
= MSI_RecordGetString( row
, 1 );
1896 feature
= get_loaded_feature( package
, name
);
1898 ERR("FAILED to find loaded feature %s\n",debugstr_w(name
));
1902 Condition
= MSI_RecordGetString(row
,3);
1904 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
1906 int level
= MSI_RecordGetInteger(row
,2);
1907 TRACE("Resetting feature %s to level %i\n", debugstr_w(name
), level
);
1908 feature
->Level
= level
;
1911 return ERROR_SUCCESS
;
1914 static LPWSTR
msi_get_disk_file_version( LPCWSTR filename
)
1916 static const WCHAR name_fmt
[] =
1917 {'%','u','.','%','u','.','%','u','.','%','u',0};
1918 static const WCHAR name
[] = {'\\',0};
1919 VS_FIXEDFILEINFO
*lpVer
;
1920 WCHAR filever
[0x100];
1926 TRACE("%s\n", debugstr_w(filename
));
1928 versize
= GetFileVersionInfoSizeW( filename
, &handle
);
1932 version
= msi_alloc( versize
);
1933 GetFileVersionInfoW( filename
, 0, versize
, version
);
1935 if (!VerQueryValueW( version
, name
, (LPVOID
*)&lpVer
, &sz
))
1937 msi_free( version
);
1941 sprintfW( filever
, name_fmt
,
1942 HIWORD(lpVer
->dwFileVersionMS
),
1943 LOWORD(lpVer
->dwFileVersionMS
),
1944 HIWORD(lpVer
->dwFileVersionLS
),
1945 LOWORD(lpVer
->dwFileVersionLS
));
1947 msi_free( version
);
1949 return strdupW( filever
);
1952 static UINT
msi_check_file_install_states( MSIPACKAGE
*package
)
1954 LPWSTR file_version
;
1957 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
1959 MSICOMPONENT
* comp
= file
->Component
;
1965 if (file
->IsCompressed
)
1966 comp
->ForceLocalState
= TRUE
;
1968 /* calculate target */
1969 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, TRUE
, NULL
);
1971 msi_free(file
->TargetPath
);
1973 TRACE("file %s is named %s\n",
1974 debugstr_w(file
->File
), debugstr_w(file
->FileName
));
1976 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
1980 TRACE("file %s resolves to %s\n",
1981 debugstr_w(file
->File
), debugstr_w(file
->TargetPath
));
1983 /* don't check files of components that aren't installed */
1984 if (comp
->Installed
== INSTALLSTATE_UNKNOWN
||
1985 comp
->Installed
== INSTALLSTATE_ABSENT
)
1987 file
->state
= msifs_missing
; /* assume files are missing */
1991 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
1993 file
->state
= msifs_missing
;
1994 comp
->Cost
+= file
->FileSize
;
1998 if (file
->Version
&&
1999 (file_version
= msi_get_disk_file_version( file
->TargetPath
)))
2001 TRACE("new %s old %s\n", debugstr_w(file
->Version
),
2002 debugstr_w(file_version
));
2003 /* FIXME: seems like a bad way to compare version numbers */
2004 if (lstrcmpiW(file_version
, file
->Version
)<0)
2006 file
->state
= msifs_overwrite
;
2007 comp
->Cost
+= file
->FileSize
;
2010 file
->state
= msifs_present
;
2011 msi_free( file_version
);
2014 file
->state
= msifs_present
;
2017 return ERROR_SUCCESS
;
2021 * A lot is done in this function aside from just the costing.
2022 * The costing needs to be implemented at some point but for now I am going
2023 * to focus on the directory building
2026 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2028 static const WCHAR ExecSeqQuery
[] =
2029 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2030 '`','D','i','r','e','c','t','o','r','y','`',0};
2031 static const WCHAR ConditionQuery
[] =
2032 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2033 '`','C','o','n','d','i','t','i','o','n','`',0};
2034 static const WCHAR szCosting
[] =
2035 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2036 static const WCHAR szlevel
[] =
2037 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2038 static const WCHAR szOutOfDiskSpace
[] =
2039 {'O','u','t','O','f','D','i','s','k','S','p','a','c','e',0};
2041 UINT rc
= ERROR_SUCCESS
;
2045 TRACE("Building Directory properties\n");
2047 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2048 if (rc
== ERROR_SUCCESS
)
2050 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeDirectories
,
2052 msiobj_release(&view
->hdr
);
2055 /* read components states from the registry */
2056 ACTION_GetComponentInstallStates(package
);
2057 ACTION_GetFeatureInstallStates(package
);
2059 TRACE("File calculations\n");
2060 msi_check_file_install_states( package
);
2062 if (!process_overrides( package
, msi_get_property_int( package
, szlevel
, 1 ) ))
2064 TRACE("Evaluating Condition Table\n");
2066 rc
= MSI_DatabaseOpenViewW( package
->db
, ConditionQuery
, &view
);
2067 if (rc
== ERROR_SUCCESS
)
2069 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_CostFinalizeConditions
, package
);
2070 msiobj_release( &view
->hdr
);
2073 TRACE("Enabling or Disabling Components\n");
2074 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2076 if (MSI_EvaluateConditionW( package
, comp
->Condition
) == MSICONDITION_FALSE
)
2078 TRACE("Disabling component %s\n", debugstr_w(comp
->Component
));
2079 comp
->Enabled
= FALSE
;
2082 comp
->Enabled
= TRUE
;
2086 MSI_SetPropertyW(package
,szCosting
,szOne
);
2087 /* set default run level if not set */
2088 level
= msi_dup_property( package
, szlevel
);
2090 MSI_SetPropertyW(package
,szlevel
, szOne
);
2093 /* FIXME: check volume disk space */
2094 MSI_SetPropertyW(package
, szOutOfDiskSpace
, szZero
);
2096 return MSI_SetFeatureStates(package
);
2099 /* OK this value is "interpreted" and then formatted based on the
2100 first few characters */
2101 static LPSTR
parse_value(MSIPACKAGE
*package
, LPCWSTR value
, DWORD
*type
,
2106 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
2112 LPWSTR deformated
= NULL
;
2115 deformat_string(package
, &value
[2], &deformated
);
2117 /* binary value type */
2121 *size
= (strlenW(ptr
)/2)+1;
2123 *size
= strlenW(ptr
)/2;
2125 data
= msi_alloc(*size
);
2131 /* if uneven pad with a zero in front */
2137 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2139 TRACE("Uneven byte count\n");
2147 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2150 msi_free(deformated
);
2152 TRACE("Data %i bytes(%i)\n",*size
,count
);
2159 deformat_string(package
, &value
[1], &deformated
);
2162 *size
= sizeof(DWORD
);
2163 data
= msi_alloc(*size
);
2169 if ( (*p
< '0') || (*p
> '9') )
2175 if (deformated
[0] == '-')
2178 TRACE("DWORD %i\n",*(LPDWORD
)data
);
2180 msi_free(deformated
);
2185 static const WCHAR szMulti
[] = {'[','~',']',0};
2194 *type
=REG_EXPAND_SZ
;
2202 if (strstrW(value
,szMulti
))
2203 *type
= REG_MULTI_SZ
;
2205 /* remove initial delimiter */
2206 if (!strncmpW(value
, szMulti
, 3))
2209 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
2211 /* add double NULL terminator */
2212 if (*type
== REG_MULTI_SZ
)
2214 *size
+= 2 * sizeof(WCHAR
); /* two NULL terminators */
2215 data
= msi_realloc_zero(data
, *size
);
2221 static const WCHAR
*get_root_key( MSIPACKAGE
*package
, INT root
, HKEY
*root_key
)
2228 if (msi_get_property_int( package
, szAllUsers
, 0 ))
2230 *root_key
= HKEY_LOCAL_MACHINE
;
2235 *root_key
= HKEY_CURRENT_USER
;
2240 *root_key
= HKEY_CLASSES_ROOT
;
2244 *root_key
= HKEY_CURRENT_USER
;
2248 *root_key
= HKEY_LOCAL_MACHINE
;
2252 *root_key
= HKEY_USERS
;
2256 ERR("Unknown root %i\n", root
);
2263 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
2265 MSIPACKAGE
*package
= param
;
2266 LPSTR value_data
= NULL
;
2267 HKEY root_key
, hkey
;
2270 LPCWSTR szRoot
, component
, name
, key
, value
;
2275 BOOL check_first
= FALSE
;
2278 ui_progress(package
,2,0,0,0);
2285 component
= MSI_RecordGetString(row
, 6);
2286 comp
= get_loaded_component(package
,component
);
2288 return ERROR_SUCCESS
;
2290 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
2292 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
2293 comp
->Action
= comp
->Installed
;
2294 return ERROR_SUCCESS
;
2296 comp
->Action
= INSTALLSTATE_LOCAL
;
2298 name
= MSI_RecordGetString(row
, 4);
2299 if( MSI_RecordIsNull(row
,5) && name
)
2301 /* null values can have special meanings */
2302 if (name
[0]=='-' && name
[1] == 0)
2303 return ERROR_SUCCESS
;
2304 else if ((name
[0]=='+' && name
[1] == 0) ||
2305 (name
[0] == '*' && name
[1] == 0))
2310 root
= MSI_RecordGetInteger(row
,2);
2311 key
= MSI_RecordGetString(row
, 3);
2313 szRoot
= get_root_key( package
, root
, &root_key
);
2315 return ERROR_SUCCESS
;
2317 deformat_string(package
, key
, &deformated
);
2318 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
2319 uikey
= msi_alloc(size
*sizeof(WCHAR
));
2320 strcpyW(uikey
,szRoot
);
2321 strcatW(uikey
,deformated
);
2323 if (RegCreateKeyW( root_key
, deformated
, &hkey
))
2325 ERR("Could not create key %s\n",debugstr_w(deformated
));
2326 msi_free(deformated
);
2328 return ERROR_SUCCESS
;
2330 msi_free(deformated
);
2332 value
= MSI_RecordGetString(row
,5);
2334 value_data
= parse_value(package
, value
, &type
, &size
);
2337 value_data
= (LPSTR
)strdupW(szEmpty
);
2338 size
= sizeof(szEmpty
);
2342 deformat_string(package
, name
, &deformated
);
2346 TRACE("Setting value %s of %s\n",debugstr_w(deformated
),
2348 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
)value_data
, size
);
2353 rc
= RegQueryValueExW(hkey
, deformated
, NULL
, NULL
, NULL
, &sz
);
2354 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
2356 TRACE("value %s of %s checked already exists\n",
2357 debugstr_w(deformated
), debugstr_w(uikey
));
2361 TRACE("Checked and setting value %s of %s\n",
2362 debugstr_w(deformated
), debugstr_w(uikey
));
2363 if (deformated
|| size
)
2364 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
) value_data
, size
);
2369 uirow
= MSI_CreateRecord(3);
2370 MSI_RecordSetStringW(uirow
,2,deformated
);
2371 MSI_RecordSetStringW(uirow
,1,uikey
);
2374 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2376 MSI_RecordSetStringW(uirow
,3,value
);
2378 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2379 msiobj_release( &uirow
->hdr
);
2381 msi_free(value_data
);
2382 msi_free(deformated
);
2385 return ERROR_SUCCESS
;
2388 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2392 static const WCHAR ExecSeqQuery
[] =
2393 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2394 '`','R','e','g','i','s','t','r','y','`',0 };
2396 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2397 if (rc
!= ERROR_SUCCESS
)
2398 return ERROR_SUCCESS
;
2400 /* increment progress bar each time action data is sent */
2401 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
2403 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2405 msiobj_release(&view
->hdr
);
2409 static void delete_reg_key_or_value( HKEY hkey_root
, LPCWSTR key
, LPCWSTR value
, BOOL delete_key
)
2413 DWORD num_subkeys
, num_values
;
2417 if ((res
= RegDeleteTreeW( hkey_root
, key
)))
2419 WARN("Failed to delete key %s (%d)\n", debugstr_w(key
), res
);
2424 if (!(res
= RegOpenKeyW( hkey_root
, key
, &hkey
)))
2426 if ((res
= RegDeleteValueW( hkey
, value
)))
2428 WARN("Failed to delete value %s (%d)\n", debugstr_w(value
), res
);
2430 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, &num_subkeys
, NULL
, NULL
, &num_values
,
2431 NULL
, NULL
, NULL
, NULL
);
2432 RegCloseKey( hkey
);
2434 if (!res
&& !num_subkeys
&& !num_values
)
2436 TRACE("Removing empty key %s\n", debugstr_w(key
));
2437 RegDeleteKeyW( hkey_root
, key
);
2441 WARN("Failed to open key %s (%d)\n", debugstr_w(key
), res
);
2445 static UINT
ITERATE_RemoveRegistryValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
2447 MSIPACKAGE
*package
= param
;
2448 LPCWSTR component
, name
, key_str
, root_key_str
;
2449 LPWSTR deformated_key
, deformated_name
, ui_key_str
;
2452 BOOL delete_key
= FALSE
;
2457 ui_progress( package
, 2, 0, 0, 0 );
2459 component
= MSI_RecordGetString( row
, 6 );
2460 comp
= get_loaded_component( package
, component
);
2462 return ERROR_SUCCESS
;
2464 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
2466 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
2467 comp
->Action
= comp
->Installed
;
2468 return ERROR_SUCCESS
;
2470 comp
->Action
= INSTALLSTATE_ABSENT
;
2472 name
= MSI_RecordGetString( row
, 4 );
2473 if (MSI_RecordIsNull( row
, 5 ) && name
)
2475 if (name
[0] == '+' && !name
[1])
2476 return ERROR_SUCCESS
;
2477 else if ((name
[0] == '-' && !name
[1]) || (name
[0] == '*' && !name
[1]))
2484 root
= MSI_RecordGetInteger( row
, 2 );
2485 key_str
= MSI_RecordGetString( row
, 3 );
2487 root_key_str
= get_root_key( package
, root
, &hkey_root
);
2489 return ERROR_SUCCESS
;
2491 deformat_string( package
, key_str
, &deformated_key
);
2492 size
= strlenW( deformated_key
) + strlenW( root_key_str
) + 1;
2493 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
2494 strcpyW( ui_key_str
, root_key_str
);
2495 strcatW( ui_key_str
, deformated_key
);
2497 deformat_string( package
, name
, &deformated_name
);
2499 delete_reg_key_or_value( hkey_root
, deformated_key
, deformated_name
, delete_key
);
2500 msi_free( deformated_key
);
2502 uirow
= MSI_CreateRecord( 2 );
2503 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
2504 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
2506 ui_actiondata( package
, szRemoveRegistryValues
, uirow
);
2507 msiobj_release( &uirow
->hdr
);
2509 msi_free( ui_key_str
);
2510 msi_free( deformated_name
);
2511 return ERROR_SUCCESS
;
2514 static UINT
ITERATE_RemoveRegistryValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
2516 MSIPACKAGE
*package
= param
;
2517 LPCWSTR component
, name
, key_str
, root_key_str
;
2518 LPWSTR deformated_key
, deformated_name
, ui_key_str
;
2521 BOOL delete_key
= FALSE
;
2526 ui_progress( package
, 2, 0, 0, 0 );
2528 component
= MSI_RecordGetString( row
, 5 );
2529 comp
= get_loaded_component( package
, component
);
2531 return ERROR_SUCCESS
;
2533 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
2535 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
2536 comp
->Action
= comp
->Installed
;
2537 return ERROR_SUCCESS
;
2539 comp
->Action
= INSTALLSTATE_LOCAL
;
2541 if ((name
= MSI_RecordGetString( row
, 4 )))
2543 if (name
[0] == '-' && !name
[1])
2550 root
= MSI_RecordGetInteger( row
, 2 );
2551 key_str
= MSI_RecordGetString( row
, 3 );
2553 root_key_str
= get_root_key( package
, root
, &hkey_root
);
2555 return ERROR_SUCCESS
;
2557 deformat_string( package
, key_str
, &deformated_key
);
2558 size
= strlenW( deformated_key
) + strlenW( root_key_str
) + 1;
2559 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
2560 strcpyW( ui_key_str
, root_key_str
);
2561 strcatW( ui_key_str
, deformated_key
);
2563 deformat_string( package
, name
, &deformated_name
);
2565 delete_reg_key_or_value( hkey_root
, deformated_key
, deformated_name
, delete_key
);
2566 msi_free( deformated_key
);
2568 uirow
= MSI_CreateRecord( 2 );
2569 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
2570 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
2572 ui_actiondata( package
, szRemoveRegistryValues
, uirow
);
2573 msiobj_release( &uirow
->hdr
);
2575 msi_free( ui_key_str
);
2576 msi_free( deformated_name
);
2577 return ERROR_SUCCESS
;
2580 static UINT
ACTION_RemoveRegistryValues( MSIPACKAGE
*package
)
2584 static const WCHAR registry_query
[] =
2585 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2586 '`','R','e','g','i','s','t','r','y','`',0 };
2587 static const WCHAR remove_registry_query
[] =
2588 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2589 '`','R','e','m','o','v','e','R','e','g','i','s','t','r','y','`',0 };
2591 /* increment progress bar each time action data is sent */
2592 ui_progress( package
, 1, REG_PROGRESS_VALUE
, 1, 0 );
2594 rc
= MSI_DatabaseOpenViewW( package
->db
, registry_query
, &view
);
2595 if (rc
== ERROR_SUCCESS
)
2597 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnUninstall
, package
);
2598 msiobj_release( &view
->hdr
);
2599 if (rc
!= ERROR_SUCCESS
)
2603 rc
= MSI_DatabaseOpenViewW( package
->db
, remove_registry_query
, &view
);
2604 if (rc
== ERROR_SUCCESS
)
2606 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnInstall
, package
);
2607 msiobj_release( &view
->hdr
);
2608 if (rc
!= ERROR_SUCCESS
)
2612 return ERROR_SUCCESS
;
2615 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
2617 package
->script
->CurrentlyScripting
= TRUE
;
2619 return ERROR_SUCCESS
;
2623 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
2628 static const WCHAR q1
[]=
2629 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2630 '`','R','e','g','i','s','t','r','y','`',0};
2633 MSIFEATURE
*feature
;
2636 TRACE("InstallValidate\n");
2638 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
2639 if (rc
== ERROR_SUCCESS
)
2641 MSI_IterateRecords( view
, &progress
, NULL
, package
);
2642 msiobj_release( &view
->hdr
);
2643 total
+= progress
* REG_PROGRESS_VALUE
;
2646 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2647 total
+= COMPONENT_PROGRESS_VALUE
;
2649 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2650 total
+= file
->FileSize
;
2652 ui_progress(package
,0,total
,0,0);
2654 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2656 TRACE("Feature: %s; Installed: %i; Action %i; Request %i\n",
2657 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
2658 feature
->ActionRequest
);
2661 return ERROR_SUCCESS
;
2664 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
2666 MSIPACKAGE
* package
= param
;
2667 LPCWSTR cond
= NULL
;
2668 LPCWSTR message
= NULL
;
2671 static const WCHAR title
[]=
2672 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2674 cond
= MSI_RecordGetString(row
,1);
2676 r
= MSI_EvaluateConditionW(package
,cond
);
2677 if (r
== MSICONDITION_FALSE
)
2679 if ((gUILevel
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
2682 message
= MSI_RecordGetString(row
,2);
2683 deformat_string(package
,message
,&deformated
);
2684 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
2685 msi_free(deformated
);
2688 return ERROR_INSTALL_FAILURE
;
2691 return ERROR_SUCCESS
;
2694 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
2697 MSIQUERY
* view
= NULL
;
2698 static const WCHAR ExecSeqQuery
[] =
2699 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2700 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2702 TRACE("Checking launch conditions\n");
2704 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2705 if (rc
!= ERROR_SUCCESS
)
2706 return ERROR_SUCCESS
;
2708 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
2709 msiobj_release(&view
->hdr
);
2714 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, MSICOMPONENT
*cmp
)
2718 return resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,TRUE
,NULL
);
2720 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
2722 MSIRECORD
* row
= 0;
2724 LPWSTR deformated
,buffer
,deformated_name
;
2726 static const WCHAR ExecSeqQuery
[] =
2727 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2728 '`','R','e','g','i','s','t','r','y','`',' ',
2729 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2730 ' ','=',' ' ,'\'','%','s','\'',0 };
2731 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
2732 static const WCHAR fmt2
[]=
2733 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2735 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
,cmp
->KeyPath
);
2739 root
= MSI_RecordGetInteger(row
,2);
2740 key
= MSI_RecordGetString(row
, 3);
2741 name
= MSI_RecordGetString(row
, 4);
2742 deformat_string(package
, key
, &deformated
);
2743 deformat_string(package
, name
, &deformated_name
);
2745 len
= strlenW(deformated
) + 6;
2746 if (deformated_name
)
2747 len
+=strlenW(deformated_name
);
2749 buffer
= msi_alloc( len
*sizeof(WCHAR
));
2751 if (deformated_name
)
2752 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
2754 sprintfW(buffer
,fmt
,root
,deformated
);
2756 msi_free(deformated
);
2757 msi_free(deformated_name
);
2758 msiobj_release(&row
->hdr
);
2762 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2764 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2769 MSIFILE
*file
= get_loaded_file( package
, cmp
->KeyPath
);
2772 return strdupW( file
->TargetPath
);
2777 static HKEY
openSharedDLLsKey(void)
2780 static const WCHAR path
[] =
2781 {'S','o','f','t','w','a','r','e','\\',
2782 'M','i','c','r','o','s','o','f','t','\\',
2783 'W','i','n','d','o','w','s','\\',
2784 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2785 'S','h','a','r','e','d','D','L','L','s',0};
2787 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
2791 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
2796 DWORD sz
= sizeof(count
);
2799 hkey
= openSharedDLLsKey();
2800 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
2801 if (rc
!= ERROR_SUCCESS
)
2807 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
2811 hkey
= openSharedDLLsKey();
2813 msi_reg_set_val_dword( hkey
, path
, count
);
2815 RegDeleteValueW(hkey
,path
);
2821 * Return TRUE if the count should be written out and FALSE if not
2823 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, MSICOMPONENT
*comp
)
2825 MSIFEATURE
*feature
;
2829 /* only refcount DLLs */
2830 if (comp
->KeyPath
== NULL
||
2831 comp
->Attributes
& msidbComponentAttributesRegistryKeyPath
||
2832 comp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2836 count
= ACTION_GetSharedDLLsCount( comp
->FullKeypath
);
2837 write
= (count
> 0);
2839 if (comp
->Attributes
& msidbComponentAttributesSharedDllRefCount
)
2843 /* increment counts */
2844 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2848 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
2851 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
2853 if ( cl
->component
== comp
)
2858 /* decrement counts */
2859 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2863 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
2866 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
2868 if ( cl
->component
== comp
)
2873 /* ref count all the files in the component */
2878 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2880 if (file
->Component
== comp
)
2881 ACTION_WriteSharedDLLsCount( file
->TargetPath
, count
);
2885 /* add a count for permanent */
2886 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
2889 comp
->RefCount
= count
;
2892 ACTION_WriteSharedDLLsCount( comp
->FullKeypath
, comp
->RefCount
);
2895 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
2897 WCHAR squished_pc
[GUID_SIZE
];
2898 WCHAR squished_cc
[GUID_SIZE
];
2905 squash_guid(package
->ProductCode
,squished_pc
);
2906 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
2908 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2912 ui_progress(package
,2,0,0,0);
2913 if (!comp
->ComponentId
)
2916 squash_guid(comp
->ComponentId
,squished_cc
);
2918 msi_free(comp
->FullKeypath
);
2919 comp
->FullKeypath
= resolve_keypath( package
, comp
);
2921 ACTION_RefCountComponent( package
, comp
);
2923 TRACE("Component %s (%s), Keypath=%s, RefCount=%i\n",
2924 debugstr_w(comp
->Component
),
2925 debugstr_w(squished_cc
),
2926 debugstr_w(comp
->FullKeypath
),
2929 if (comp
->ActionRequest
== INSTALLSTATE_LOCAL
||
2930 comp
->ActionRequest
== INSTALLSTATE_SOURCE
)
2932 if (!comp
->FullKeypath
)
2935 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
2936 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, szLocalSid
,
2939 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, NULL
,
2942 if (rc
!= ERROR_SUCCESS
)
2945 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
2947 static const WCHAR szPermKey
[] =
2948 { '0','0','0','0','0','0','0','0','0','0','0','0',
2949 '0','0','0','0','0','0','0','0','0','0','0','0',
2950 '0','0','0','0','0','0','0','0',0 };
2952 msi_reg_set_val_str(hkey
, szPermKey
, comp
->FullKeypath
);
2955 if (comp
->Action
== INSTALLSTATE_LOCAL
)
2956 msi_reg_set_val_str(hkey
, squished_pc
, comp
->FullKeypath
);
2962 WCHAR source
[MAX_PATH
];
2963 WCHAR base
[MAX_PATH
];
2966 static const WCHAR fmt
[] = {'%','0','2','d','\\',0};
2967 static const WCHAR query
[] = {
2968 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2969 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
2970 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
2971 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
2972 '`','D','i','s','k','I','d','`',0};
2974 file
= get_loaded_file(package
, comp
->KeyPath
);
2978 row
= MSI_QueryGetRecord(package
->db
, query
, file
->Sequence
);
2979 sprintfW(source
, fmt
, MSI_RecordGetInteger(row
, 1));
2980 ptr2
= strrchrW(source
, '\\') + 1;
2981 msiobj_release(&row
->hdr
);
2983 lstrcpyW(base
, package
->PackagePath
);
2984 ptr
= strrchrW(base
, '\\');
2987 sourcepath
= resolve_file_source(package
, file
);
2988 ptr
= sourcepath
+ lstrlenW(base
);
2989 lstrcpyW(ptr2
, ptr
);
2990 msi_free(sourcepath
);
2992 msi_reg_set_val_str(hkey
, squished_pc
, source
);
2996 else if (comp
->ActionRequest
== INSTALLSTATE_ABSENT
)
2998 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
2999 MSIREG_DeleteUserDataComponentKey(comp
->ComponentId
, szLocalSid
);
3001 MSIREG_DeleteUserDataComponentKey(comp
->ComponentId
, NULL
);
3005 uirow
= MSI_CreateRecord(3);
3006 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
3007 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
3008 MSI_RecordSetStringW(uirow
,3,comp
->FullKeypath
);
3009 ui_actiondata(package
,szProcessComponents
,uirow
);
3010 msiobj_release( &uirow
->hdr
);
3013 return ERROR_SUCCESS
;
3024 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
3025 LPWSTR lpszName
, LONG_PTR lParam
)
3028 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
3029 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
3033 if (!IS_INTRESOURCE(lpszName
))
3035 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
3039 sz
= strlenW(tl_struct
->source
)+4;
3040 sz
*= sizeof(WCHAR
);
3042 if ((INT_PTR
)lpszName
== 1)
3043 tl_struct
->path
= strdupW(tl_struct
->source
);
3046 tl_struct
->path
= msi_alloc(sz
);
3047 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
3050 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
3051 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
3054 msi_free(tl_struct
->path
);
3055 tl_struct
->path
= NULL
;
3060 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
3061 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
3063 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3067 msi_free(tl_struct
->path
);
3068 tl_struct
->path
= NULL
;
3070 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3071 ITypeLib_Release(tl_struct
->ptLib
);
3076 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
3078 MSIPACKAGE
* package
= param
;
3082 typelib_struct tl_struct
;
3087 component
= MSI_RecordGetString(row
,3);
3088 comp
= get_loaded_component(package
,component
);
3090 return ERROR_SUCCESS
;
3092 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
3094 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
3095 comp
->Action
= comp
->Installed
;
3096 return ERROR_SUCCESS
;
3098 comp
->Action
= INSTALLSTATE_LOCAL
;
3100 file
= get_loaded_file( package
, comp
->KeyPath
);
3102 return ERROR_SUCCESS
;
3104 ui_actiondata( package
, szRegisterTypeLibraries
, row
);
3106 module
= LoadLibraryExW( file
->TargetPath
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
3110 guid
= MSI_RecordGetString(row
,1);
3111 CLSIDFromString((LPWSTR
)guid
, &tl_struct
.clsid
);
3112 tl_struct
.source
= strdupW( file
->TargetPath
);
3113 tl_struct
.path
= NULL
;
3115 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
3116 (LONG_PTR
)&tl_struct
);
3124 helpid
= MSI_RecordGetString(row
,6);
3127 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,TRUE
,NULL
);
3128 res
= RegisterTypeLib(tl_struct
.ptLib
,tl_struct
.path
,help
);
3132 ERR("Failed to register type library %s\n",
3133 debugstr_w(tl_struct
.path
));
3135 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
3137 ITypeLib_Release(tl_struct
.ptLib
);
3138 msi_free(tl_struct
.path
);
3141 ERR("Failed to load type library %s\n",
3142 debugstr_w(tl_struct
.source
));
3144 FreeLibrary(module
);
3145 msi_free(tl_struct
.source
);
3149 hr
= LoadTypeLibEx(file
->TargetPath
, REGKIND_REGISTER
, &tlib
);
3152 ERR("Failed to load type library: %08x\n", hr
);
3153 return ERROR_INSTALL_FAILURE
;
3156 ITypeLib_Release(tlib
);
3159 return ERROR_SUCCESS
;
3162 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
3165 * OK this is a bit confusing.. I am given a _Component key and I believe
3166 * that the file that is being registered as a type library is the "key file
3167 * of that component" which I interpret to mean "The file in the KeyPath of
3172 static const WCHAR Query
[] =
3173 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3174 '`','T','y','p','e','L','i','b','`',0};
3176 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3177 if (rc
!= ERROR_SUCCESS
)
3178 return ERROR_SUCCESS
;
3180 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
3181 msiobj_release(&view
->hdr
);
3185 static UINT
ITERATE_UnregisterTypeLibraries( MSIRECORD
*row
, LPVOID param
)
3187 MSIPACKAGE
*package
= param
;
3188 LPCWSTR component
, guid
;
3196 component
= MSI_RecordGetString( row
, 3 );
3197 comp
= get_loaded_component( package
, component
);
3199 return ERROR_SUCCESS
;
3201 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
3203 TRACE("Component not scheduled for removal %s\n", debugstr_w(component
));
3204 comp
->Action
= comp
->Installed
;
3205 return ERROR_SUCCESS
;
3207 comp
->Action
= INSTALLSTATE_ABSENT
;
3209 ui_actiondata( package
, szUnregisterTypeLibraries
, row
);
3211 guid
= MSI_RecordGetString( row
, 1 );
3212 CLSIDFromString( (LPWSTR
)guid
, &libid
);
3213 version
= MSI_RecordGetInteger( row
, 4 );
3214 language
= MSI_RecordGetInteger( row
, 2 );
3217 syskind
= SYS_WIN64
;
3219 syskind
= SYS_WIN32
;
3222 hr
= UnRegisterTypeLib( &libid
, (version
>> 8) & 0xffff, version
& 0xff, language
, syskind
);
3225 WARN("Failed to unregister typelib: %08x\n", hr
);
3228 return ERROR_SUCCESS
;
3231 static UINT
ACTION_UnregisterTypeLibraries( MSIPACKAGE
*package
)
3235 static const WCHAR query
[] =
3236 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3237 '`','T','y','p','e','L','i','b','`',0};
3239 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
3240 if (rc
!= ERROR_SUCCESS
)
3241 return ERROR_SUCCESS
;
3243 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnregisterTypeLibraries
, package
);
3244 msiobj_release( &view
->hdr
);
3248 static WCHAR
*get_link_file( MSIPACKAGE
*package
, MSIRECORD
*row
)
3250 static const WCHAR szlnk
[] = {'.','l','n','k',0};
3251 LPCWSTR directory
, extension
;
3252 LPWSTR link_folder
, link_file
, filename
;
3254 directory
= MSI_RecordGetString( row
, 2 );
3255 link_folder
= resolve_folder( package
, directory
, FALSE
, FALSE
, TRUE
, NULL
);
3257 /* may be needed because of a bug somewhere else */
3258 create_full_pathW( link_folder
);
3260 filename
= msi_dup_record_field( row
, 3 );
3261 reduce_to_longfilename( filename
);
3263 extension
= strchrW( filename
, '.' );
3264 if (!extension
|| strcmpiW( extension
, szlnk
))
3266 int len
= strlenW( filename
);
3267 filename
= msi_realloc( filename
, len
* sizeof(WCHAR
) + sizeof(szlnk
) );
3268 memcpy( filename
+ len
, szlnk
, sizeof(szlnk
) );
3270 link_file
= build_directory_name( 2, link_folder
, filename
);
3271 msi_free( link_folder
);
3272 msi_free( filename
);
3277 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
3279 MSIPACKAGE
*package
= param
;
3280 LPWSTR link_file
, deformated
, path
;
3281 LPCWSTR component
, target
;
3283 IShellLinkW
*sl
= NULL
;
3284 IPersistFile
*pf
= NULL
;
3287 component
= MSI_RecordGetString(row
, 4);
3288 comp
= get_loaded_component(package
, component
);
3290 return ERROR_SUCCESS
;
3292 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
3294 TRACE("Component not scheduled for installation %s\n", debugstr_w(component
));
3295 comp
->Action
= comp
->Installed
;
3296 return ERROR_SUCCESS
;
3298 comp
->Action
= INSTALLSTATE_LOCAL
;
3300 ui_actiondata(package
,szCreateShortcuts
,row
);
3302 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3303 &IID_IShellLinkW
, (LPVOID
*) &sl
);
3307 ERR("CLSID_ShellLink not available\n");
3311 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
3314 ERR("QueryInterface(IID_IPersistFile) failed\n");
3318 target
= MSI_RecordGetString(row
, 5);
3319 if (strchrW(target
, '['))
3321 deformat_string(package
, target
, &deformated
);
3322 IShellLinkW_SetPath(sl
,deformated
);
3323 msi_free(deformated
);
3327 FIXME("poorly handled shortcut format, advertised shortcut\n");
3328 IShellLinkW_SetPath(sl
,comp
->FullKeypath
);
3331 if (!MSI_RecordIsNull(row
,6))
3333 LPCWSTR arguments
= MSI_RecordGetString(row
, 6);
3334 deformat_string(package
, arguments
, &deformated
);
3335 IShellLinkW_SetArguments(sl
,deformated
);
3336 msi_free(deformated
);
3339 if (!MSI_RecordIsNull(row
,7))
3341 LPCWSTR description
= MSI_RecordGetString(row
, 7);
3342 IShellLinkW_SetDescription(sl
, description
);
3345 if (!MSI_RecordIsNull(row
,8))
3346 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
3348 if (!MSI_RecordIsNull(row
,9))
3351 LPCWSTR icon
= MSI_RecordGetString(row
, 9);
3353 path
= build_icon_path(package
, icon
);
3354 index
= MSI_RecordGetInteger(row
,10);
3356 /* no value means 0 */
3357 if (index
== MSI_NULL_INTEGER
)
3360 IShellLinkW_SetIconLocation(sl
, path
, index
);
3364 if (!MSI_RecordIsNull(row
,11))
3365 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
3367 if (!MSI_RecordIsNull(row
,12))
3369 LPCWSTR wkdir
= MSI_RecordGetString(row
, 12);
3370 path
= resolve_folder(package
, wkdir
, FALSE
, FALSE
, TRUE
, NULL
);
3372 IShellLinkW_SetWorkingDirectory(sl
, path
);
3376 link_file
= get_link_file(package
, row
);
3378 TRACE("Writing shortcut to %s\n", debugstr_w(link_file
));
3379 IPersistFile_Save(pf
, link_file
, FALSE
);
3381 msi_free(link_file
);
3385 IPersistFile_Release( pf
);
3387 IShellLinkW_Release( sl
);
3389 return ERROR_SUCCESS
;
3392 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
3397 static const WCHAR Query
[] =
3398 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3399 '`','S','h','o','r','t','c','u','t','`',0};
3401 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3402 if (rc
!= ERROR_SUCCESS
)
3403 return ERROR_SUCCESS
;
3405 res
= CoInitialize( NULL
);
3407 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
3408 msiobj_release(&view
->hdr
);
3416 static UINT
ITERATE_RemoveShortcuts( MSIRECORD
*row
, LPVOID param
)
3418 MSIPACKAGE
*package
= param
;
3423 component
= MSI_RecordGetString( row
, 4 );
3424 comp
= get_loaded_component( package
, component
);
3426 return ERROR_SUCCESS
;
3428 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
3430 TRACE("Component not scheduled for removal %s\n", debugstr_w(component
));
3431 comp
->Action
= comp
->Installed
;
3432 return ERROR_SUCCESS
;
3434 comp
->Action
= INSTALLSTATE_ABSENT
;
3436 ui_actiondata( package
, szRemoveShortcuts
, row
);
3438 link_file
= get_link_file( package
, row
);
3440 TRACE("Removing shortcut file %s\n", debugstr_w( link_file
));
3441 if (!DeleteFileW( link_file
))
3443 WARN("Failed to remove shortcut file %u\n", GetLastError());
3445 msi_free( link_file
);
3447 return ERROR_SUCCESS
;
3450 static UINT
ACTION_RemoveShortcuts( MSIPACKAGE
*package
)
3454 static const WCHAR query
[] =
3455 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3456 '`','S','h','o','r','t','c','u','t','`',0};
3458 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
3459 if (rc
!= ERROR_SUCCESS
)
3460 return ERROR_SUCCESS
;
3462 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveShortcuts
, package
);
3463 msiobj_release( &view
->hdr
);
3468 static UINT
ITERATE_PublishIcon(MSIRECORD
*row
, LPVOID param
)
3470 MSIPACKAGE
* package
= param
;
3479 FileName
= MSI_RecordGetString(row
,1);
3482 ERR("Unable to get FileName\n");
3483 return ERROR_SUCCESS
;
3486 FilePath
= build_icon_path(package
,FileName
);
3488 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
3490 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
3491 FILE_ATTRIBUTE_NORMAL
, NULL
);
3493 if (the_file
== INVALID_HANDLE_VALUE
)
3495 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
3497 return ERROR_SUCCESS
;
3504 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
3505 if (rc
!= ERROR_SUCCESS
)
3507 ERR("Failed to get stream\n");
3508 CloseHandle(the_file
);
3509 DeleteFileW(FilePath
);
3512 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
3513 } while (sz
== 1024);
3517 CloseHandle(the_file
);
3519 uirow
= MSI_CreateRecord(1);
3520 MSI_RecordSetStringW(uirow
,1,FileName
);
3521 ui_actiondata(package
,szPublishProduct
,uirow
);
3522 msiobj_release( &uirow
->hdr
);
3524 return ERROR_SUCCESS
;
3527 static UINT
msi_publish_icons(MSIPACKAGE
*package
)
3532 static const WCHAR query
[]= {
3533 'S','E','L','E','C','T',' ','*',' ',
3534 'F','R','O','M',' ','`','I','c','o','n','`',0};
3536 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
3537 if (r
== ERROR_SUCCESS
)
3539 MSI_IterateRecords(view
, NULL
, ITERATE_PublishIcon
, package
);
3540 msiobj_release(&view
->hdr
);
3543 return ERROR_SUCCESS
;
3546 static UINT
msi_publish_sourcelist(MSIPACKAGE
*package
, HKEY hkey
)
3552 MSISOURCELISTINFO
*info
;
3554 r
= RegCreateKeyW(hkey
, szSourceList
, &source
);
3555 if (r
!= ERROR_SUCCESS
)
3558 RegCloseKey(source
);
3560 buffer
= strrchrW(package
->PackagePath
, '\\') + 1;
3561 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3562 package
->Context
, MSICODE_PRODUCT
,
3563 INSTALLPROPERTY_PACKAGENAMEW
, buffer
);
3564 if (r
!= ERROR_SUCCESS
)
3567 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3568 package
->Context
, MSICODE_PRODUCT
,
3569 INSTALLPROPERTY_MEDIAPACKAGEPATHW
, szEmpty
);
3570 if (r
!= ERROR_SUCCESS
)
3573 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3574 package
->Context
, MSICODE_PRODUCT
,
3575 INSTALLPROPERTY_DISKPROMPTW
, szEmpty
);
3576 if (r
!= ERROR_SUCCESS
)
3579 LIST_FOR_EACH_ENTRY(info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
3581 if (!lstrcmpW(info
->property
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
3582 msi_set_last_used_source(package
->ProductCode
, NULL
, info
->context
,
3583 info
->options
, info
->value
);
3585 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3586 info
->context
, info
->options
,
3587 info
->property
, info
->value
);
3590 LIST_FOR_EACH_ENTRY(disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
3592 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
3593 disk
->context
, disk
->options
,
3594 disk
->disk_id
, disk
->volume_label
, disk
->disk_prompt
);
3597 return ERROR_SUCCESS
;
3600 static UINT
msi_publish_product_properties(MSIPACKAGE
*package
, HKEY hkey
)
3602 MSIHANDLE hdb
, suminfo
;
3603 WCHAR guids
[MAX_PATH
];
3604 WCHAR packcode
[SQUISH_GUID_SIZE
];
3611 static const WCHAR szProductLanguage
[] =
3612 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3613 static const WCHAR szARPProductIcon
[] =
3614 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
3615 static const WCHAR szProductVersion
[] =
3616 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3617 static const WCHAR szAssignment
[] =
3618 {'A','s','s','i','g','n','m','e','n','t',0};
3619 static const WCHAR szAdvertiseFlags
[] =
3620 {'A','d','v','e','r','t','i','s','e','F','l','a','g','s',0};
3621 static const WCHAR szClients
[] =
3622 {'C','l','i','e','n','t','s',0};
3623 static const WCHAR szColon
[] = {':',0};
3625 buffer
= msi_dup_property(package
, INSTALLPROPERTY_PRODUCTNAMEW
);
3626 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTNAMEW
, buffer
);
3629 langid
= msi_get_property_int(package
, szProductLanguage
, 0);
3630 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
3633 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
, 0);
3635 buffer
= msi_dup_property(package
, szARPProductIcon
);
3638 LPWSTR path
= build_icon_path(package
,buffer
);
3639 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTICONW
, path
);
3644 buffer
= msi_dup_property(package
, szProductVersion
);
3647 DWORD verdword
= msi_version_str_to_dword(buffer
);
3648 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
3652 msi_reg_set_val_dword(hkey
, szAssignment
, 0);
3653 msi_reg_set_val_dword(hkey
, szAdvertiseFlags
, 0x184);
3654 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_INSTANCETYPEW
, 0);
3655 msi_reg_set_val_str(hkey
, szClients
, szColon
);
3657 hdb
= alloc_msihandle(&package
->db
->hdr
);
3659 return ERROR_NOT_ENOUGH_MEMORY
;
3661 r
= MsiGetSummaryInformationW(hdb
, NULL
, 0, &suminfo
);
3662 MsiCloseHandle(hdb
);
3663 if (r
!= ERROR_SUCCESS
)
3667 r
= MsiSummaryInfoGetPropertyW(suminfo
, PID_REVNUMBER
, NULL
, NULL
,
3668 NULL
, guids
, &size
);
3669 if (r
!= ERROR_SUCCESS
)
3672 ptr
= strchrW(guids
, ';');
3674 squash_guid(guids
, packcode
);
3675 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PACKAGECODEW
, packcode
);
3678 MsiCloseHandle(suminfo
);
3679 return ERROR_SUCCESS
;
3682 static UINT
msi_publish_upgrade_code(MSIPACKAGE
*package
)
3687 WCHAR squashed_pc
[SQUISH_GUID_SIZE
];
3689 static const WCHAR szUpgradeCode
[] =
3690 {'U','p','g','r','a','d','e','C','o','d','e',0};
3692 upgrade
= msi_dup_property(package
, szUpgradeCode
);
3694 return ERROR_SUCCESS
;
3696 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3698 r
= MSIREG_OpenClassesUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
3699 if (r
!= ERROR_SUCCESS
)
3704 r
= MSIREG_OpenUserUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
3705 if (r
!= ERROR_SUCCESS
)
3709 squash_guid(package
->ProductCode
, squashed_pc
);
3710 msi_reg_set_val_str(hkey
, squashed_pc
, NULL
);
3719 static BOOL
msi_check_publish(MSIPACKAGE
*package
)
3721 MSIFEATURE
*feature
;
3723 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
3725 if (feature
->ActionRequest
== INSTALLSTATE_LOCAL
)
3732 static BOOL
msi_check_unpublish(MSIPACKAGE
*package
)
3734 MSIFEATURE
*feature
;
3736 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
3738 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
3745 static UINT
msi_publish_patch(MSIPACKAGE
*package
, HKEY prodkey
, HKEY hudkey
)
3747 WCHAR patch_squashed
[GUID_SIZE
];
3750 UINT r
= ERROR_FUNCTION_FAILED
;
3752 res
= RegCreateKeyExW(prodkey
, szPatches
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
,
3754 if (res
!= ERROR_SUCCESS
)
3755 return ERROR_FUNCTION_FAILED
;
3757 squash_guid(package
->patch
->patchcode
, patch_squashed
);
3759 res
= RegSetValueExW(patches
, szPatches
, 0, REG_MULTI_SZ
,
3760 (const BYTE
*)patch_squashed
,
3761 (lstrlenW(patch_squashed
) + 1) * sizeof(WCHAR
));
3762 if (res
!= ERROR_SUCCESS
)
3765 res
= RegSetValueExW(patches
, patch_squashed
, 0, REG_SZ
,
3766 (const BYTE
*)package
->patch
->transforms
,
3767 (lstrlenW(package
->patch
->transforms
) + 1) * sizeof(WCHAR
));
3768 if (res
== ERROR_SUCCESS
)
3772 RegCloseKey(patches
);
3777 * 99% of the work done here is only done for
3778 * advertised installs. However this is where the
3779 * Icon table is processed and written out
3780 * so that is what I am going to do here.
3782 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
3788 /* FIXME: also need to publish if the product is in advertise mode */
3789 if (!msi_check_publish(package
))
3790 return ERROR_SUCCESS
;
3792 rc
= MSIREG_OpenProductKey(package
->ProductCode
, NULL
, package
->Context
,
3794 if (rc
!= ERROR_SUCCESS
)
3797 rc
= MSIREG_OpenUserDataProductKey(package
->ProductCode
, package
->Context
,
3798 NULL
, &hudkey
, TRUE
);
3799 if (rc
!= ERROR_SUCCESS
)
3802 rc
= msi_publish_upgrade_code(package
);
3803 if (rc
!= ERROR_SUCCESS
)
3808 rc
= msi_publish_patch(package
, hukey
, hudkey
);
3809 if (rc
!= ERROR_SUCCESS
)
3813 rc
= msi_publish_product_properties(package
, hukey
);
3814 if (rc
!= ERROR_SUCCESS
)
3817 rc
= msi_publish_sourcelist(package
, hukey
);
3818 if (rc
!= ERROR_SUCCESS
)
3821 rc
= msi_publish_icons(package
);
3825 RegCloseKey(hudkey
);
3830 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
3832 MSIPACKAGE
*package
= param
;
3833 LPCWSTR component
, section
, key
, value
, identifier
, dirproperty
;
3834 LPWSTR deformated_section
, deformated_key
, deformated_value
;
3835 LPWSTR folder
, filename
, fullname
= NULL
;
3836 LPCWSTR filenameptr
;
3840 static const WCHAR szWindowsFolder
[] =
3841 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3843 component
= MSI_RecordGetString(row
, 8);
3844 comp
= get_loaded_component(package
,component
);
3846 return ERROR_SUCCESS
;
3848 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
3850 TRACE("Component not scheduled for installation %s\n", debugstr_w(component
));
3851 comp
->Action
= comp
->Installed
;
3852 return ERROR_SUCCESS
;
3854 comp
->Action
= INSTALLSTATE_LOCAL
;
3856 identifier
= MSI_RecordGetString(row
,1);
3857 dirproperty
= MSI_RecordGetString(row
,3);
3858 section
= MSI_RecordGetString(row
,4);
3859 key
= MSI_RecordGetString(row
,5);
3860 value
= MSI_RecordGetString(row
,6);
3861 action
= MSI_RecordGetInteger(row
,7);
3863 deformat_string(package
,section
,&deformated_section
);
3864 deformat_string(package
,key
,&deformated_key
);
3865 deformat_string(package
,value
,&deformated_value
);
3867 filename
= msi_dup_record_field(row
, 2);
3868 if (filename
&& (filenameptr
= strchrW(filename
, '|')))
3871 filenameptr
= filename
;
3875 folder
= resolve_folder(package
, dirproperty
, FALSE
, FALSE
, TRUE
, NULL
);
3877 folder
= msi_dup_property( package
, dirproperty
);
3880 folder
= msi_dup_property( package
, szWindowsFolder
);
3884 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty
));
3888 fullname
= build_directory_name(2, folder
, filenameptr
);
3892 TRACE("Adding value %s to section %s in %s\n",
3893 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3894 debugstr_w(fullname
));
3895 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3896 deformated_value
, fullname
);
3898 else if (action
== 1)
3901 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
3902 returned
, 10, fullname
);
3903 if (returned
[0] == 0)
3905 TRACE("Adding value %s to section %s in %s\n",
3906 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
3907 debugstr_w(fullname
));
3909 WritePrivateProfileStringW(deformated_section
, deformated_key
,
3910 deformated_value
, fullname
);
3913 else if (action
== 3)
3914 FIXME("Append to existing section not yet implemented\n");
3916 uirow
= MSI_CreateRecord(4);
3917 MSI_RecordSetStringW(uirow
,1,identifier
);
3918 MSI_RecordSetStringW(uirow
,2,deformated_section
);
3919 MSI_RecordSetStringW(uirow
,3,deformated_key
);
3920 MSI_RecordSetStringW(uirow
,4,deformated_value
);
3921 ui_actiondata(package
,szWriteIniValues
,uirow
);
3922 msiobj_release( &uirow
->hdr
);
3928 msi_free(deformated_key
);
3929 msi_free(deformated_value
);
3930 msi_free(deformated_section
);
3931 return ERROR_SUCCESS
;
3934 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
3938 static const WCHAR ExecSeqQuery
[] =
3939 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3940 '`','I','n','i','F','i','l','e','`',0};
3942 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3943 if (rc
!= ERROR_SUCCESS
)
3945 TRACE("no IniFile table\n");
3946 return ERROR_SUCCESS
;
3949 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
3950 msiobj_release(&view
->hdr
);
3954 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
3956 MSIPACKAGE
*package
= param
;
3961 static const WCHAR ExeStr
[] =
3962 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"',0};
3963 static const WCHAR close
[] = {'\"',0};
3965 PROCESS_INFORMATION info
;
3970 memset(&si
,0,sizeof(STARTUPINFOW
));
3972 filename
= MSI_RecordGetString(row
,1);
3973 file
= get_loaded_file( package
, filename
);
3977 ERR("Unable to find file id %s\n",debugstr_w(filename
));
3978 return ERROR_SUCCESS
;
3981 len
= strlenW(ExeStr
) + strlenW( file
->TargetPath
) + 2;
3983 FullName
= msi_alloc(len
*sizeof(WCHAR
));
3984 strcpyW(FullName
,ExeStr
);
3985 strcatW( FullName
, file
->TargetPath
);
3986 strcatW(FullName
,close
);
3988 TRACE("Registering %s\n",debugstr_w(FullName
));
3989 brc
= CreateProcessW(NULL
, FullName
, NULL
, NULL
, FALSE
, 0, NULL
, c_colon
,
3994 CloseHandle(info
.hThread
);
3995 msi_dialog_check_messages(info
.hProcess
);
3996 CloseHandle(info
.hProcess
);
4002 uirow
= MSI_CreateRecord( 2 );
4003 uipath
= strdupW( file
->TargetPath
);
4004 p
= strrchrW(uipath
,'\\');
4007 MSI_RecordSetStringW( uirow
, 1, &p
[1] );
4008 MSI_RecordSetStringW( uirow
, 2, uipath
);
4009 ui_actiondata( package
, szSelfRegModules
, uirow
);
4010 msiobj_release( &uirow
->hdr
);
4012 /* FIXME: call ui_progress? */
4014 return ERROR_SUCCESS
;
4017 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
4021 static const WCHAR ExecSeqQuery
[] =
4022 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4023 '`','S','e','l','f','R','e','g','`',0};
4025 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4026 if (rc
!= ERROR_SUCCESS
)
4028 TRACE("no SelfReg table\n");
4029 return ERROR_SUCCESS
;
4032 MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
4033 msiobj_release(&view
->hdr
);
4035 return ERROR_SUCCESS
;
4038 static UINT
ITERATE_SelfUnregModules( MSIRECORD
*row
, LPVOID param
)
4040 static const WCHAR regsvr32
[] =
4041 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','u',' ','\"',0};
4042 static const WCHAR close
[] = {'\"',0};
4043 MSIPACKAGE
*package
= param
;
4049 PROCESS_INFORMATION pi
;
4054 memset( &si
, 0, sizeof(STARTUPINFOW
) );
4056 filename
= MSI_RecordGetString( row
, 1 );
4057 file
= get_loaded_file( package
, filename
);
4061 ERR("Unable to find file id %s\n", debugstr_w(filename
));
4062 return ERROR_SUCCESS
;
4065 len
= strlenW( regsvr32
) + strlenW( file
->TargetPath
) + 2;
4067 cmdline
= msi_alloc( len
* sizeof(WCHAR
) );
4068 strcpyW( cmdline
, regsvr32
);
4069 strcatW( cmdline
, file
->TargetPath
);
4070 strcatW( cmdline
, close
);
4072 TRACE("Unregistering %s\n", debugstr_w(cmdline
));
4074 ret
= CreateProcessW( NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, c_colon
, &si
, &pi
);
4077 CloseHandle( pi
.hThread
);
4078 msi_dialog_check_messages( pi
.hProcess
);
4079 CloseHandle( pi
.hProcess
);
4082 msi_free( cmdline
);
4084 uirow
= MSI_CreateRecord( 2 );
4085 uipath
= strdupW( file
->TargetPath
);
4086 if ((p
= strrchrW( uipath
, '\\' )))
4089 MSI_RecordSetStringW( uirow
, 1, ++p
);
4091 MSI_RecordSetStringW( uirow
, 2, uipath
);
4092 ui_actiondata( package
, szSelfUnregModules
, uirow
);
4093 msiobj_release( &uirow
->hdr
);
4095 /* FIXME call ui_progress? */
4097 return ERROR_SUCCESS
;
4100 static UINT
ACTION_SelfUnregModules( MSIPACKAGE
*package
)
4104 static const WCHAR query
[] =
4105 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4106 '`','S','e','l','f','R','e','g','`',0};
4108 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4109 if (rc
!= ERROR_SUCCESS
)
4111 TRACE("no SelfReg table\n");
4112 return ERROR_SUCCESS
;
4115 MSI_IterateRecords( view
, NULL
, ITERATE_SelfUnregModules
, package
);
4116 msiobj_release( &view
->hdr
);
4118 return ERROR_SUCCESS
;
4121 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
4123 MSIFEATURE
*feature
;
4126 HKEY userdata
= NULL
;
4128 if (!msi_check_publish(package
))
4129 return ERROR_SUCCESS
;
4131 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
, package
->Context
,
4133 if (rc
!= ERROR_SUCCESS
)
4136 rc
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, package
->Context
,
4138 if (rc
!= ERROR_SUCCESS
)
4141 /* here the guids are base 85 encoded */
4142 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
4148 BOOL absent
= FALSE
;
4151 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
4152 feature
->ActionRequest
!= INSTALLSTATE_SOURCE
&&
4153 feature
->ActionRequest
!= INSTALLSTATE_ADVERTISED
) absent
= TRUE
;
4156 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4160 if (feature
->Feature_Parent
)
4161 size
+= strlenW( feature
->Feature_Parent
)+2;
4163 data
= msi_alloc(size
* sizeof(WCHAR
));
4166 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4168 MSICOMPONENT
* component
= cl
->component
;
4172 if (component
->ComponentId
)
4174 TRACE("From %s\n",debugstr_w(component
->ComponentId
));
4175 CLSIDFromString(component
->ComponentId
, &clsid
);
4176 encode_base85_guid(&clsid
,buf
);
4177 TRACE("to %s\n",debugstr_w(buf
));
4182 if (feature
->Feature_Parent
)
4184 static const WCHAR sep
[] = {'\2',0};
4186 strcatW(data
,feature
->Feature_Parent
);
4189 msi_reg_set_val_str( userdata
, feature
->Feature
, data
);
4193 if (feature
->Feature_Parent
)
4194 size
= strlenW(feature
->Feature_Parent
)*sizeof(WCHAR
);
4197 size
+= sizeof(WCHAR
);
4198 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
4199 (LPBYTE
)(feature
->Feature_Parent
? feature
->Feature_Parent
: szEmpty
),size
);
4203 size
+= 2*sizeof(WCHAR
);
4204 data
= msi_alloc(size
);
4207 if (feature
->Feature_Parent
)
4208 strcpyW( &data
[1], feature
->Feature_Parent
);
4209 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
4215 uirow
= MSI_CreateRecord( 1 );
4216 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
4217 ui_actiondata( package
, szPublishFeatures
, uirow
);
4218 msiobj_release( &uirow
->hdr
);
4219 /* FIXME: call ui_progress? */
4224 RegCloseKey(userdata
);
4228 static UINT
msi_unpublish_feature(MSIPACKAGE
*package
, MSIFEATURE
*feature
)
4233 TRACE("unpublishing feature %s\n", debugstr_w(feature
->Feature
));
4235 r
= MSIREG_OpenFeaturesKey(package
->ProductCode
, package
->Context
,
4237 if (r
== ERROR_SUCCESS
)
4239 RegDeleteValueW(hkey
, feature
->Feature
);
4243 r
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, package
->Context
,
4245 if (r
== ERROR_SUCCESS
)
4247 RegDeleteValueW(hkey
, feature
->Feature
);
4251 return ERROR_SUCCESS
;
4254 static UINT
ACTION_UnpublishFeatures(MSIPACKAGE
*package
)
4256 MSIFEATURE
*feature
;
4258 if (!msi_check_unpublish(package
))
4259 return ERROR_SUCCESS
;
4261 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4263 msi_unpublish_feature(package
, feature
);
4266 return ERROR_SUCCESS
;
4269 static UINT
msi_publish_install_properties(MSIPACKAGE
*package
, HKEY hkey
)
4271 LPWSTR prop
, val
, key
;
4277 static const WCHAR date_fmt
[] = {'%','i','%','0','2','i','%','0','2','i',0};
4278 static const WCHAR szWindowsInstaller
[] =
4279 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
4280 static const WCHAR modpath_fmt
[] =
4281 {'M','s','i','E','x','e','c','.','e','x','e',' ',
4282 '/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
4283 static const WCHAR szModifyPath
[] =
4284 {'M','o','d','i','f','y','P','a','t','h',0};
4285 static const WCHAR szUninstallString
[] =
4286 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
4287 static const WCHAR szEstimatedSize
[] =
4288 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
4289 static const WCHAR szProductLanguage
[] =
4290 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
4291 static const WCHAR szProductVersion
[] =
4292 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
4293 static const WCHAR szProductName
[] =
4294 {'P','r','o','d','u','c','t','N','a','m','e',0};
4295 static const WCHAR szDisplayName
[] =
4296 {'D','i','s','p','l','a','y','N','a','m','e',0};
4297 static const WCHAR szDisplayVersion
[] =
4298 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
4299 static const WCHAR szManufacturer
[] =
4300 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
4302 static const LPCSTR propval
[] = {
4303 "ARPAUTHORIZEDCDFPREFIX", "AuthorizedCDFPrefix",
4304 "ARPCONTACT", "Contact",
4305 "ARPCOMMENTS", "Comments",
4306 "ProductName", "DisplayName",
4307 "ProductVersion", "DisplayVersion",
4308 "ARPHELPLINK", "HelpLink",
4309 "ARPHELPTELEPHONE", "HelpTelephone",
4310 "ARPINSTALLLOCATION", "InstallLocation",
4311 "SourceDir", "InstallSource",
4312 "Manufacturer", "Publisher",
4313 "ARPREADME", "Readme",
4315 "ARPURLINFOABOUT", "URLInfoAbout",
4316 "ARPURLUPDATEINFO", "URLUpdateInfo",
4319 const LPCSTR
*p
= propval
;
4323 prop
= strdupAtoW(*p
++);
4324 key
= strdupAtoW(*p
++);
4325 val
= msi_dup_property(package
, prop
);
4326 msi_reg_set_val_str(hkey
, key
, val
);
4332 msi_reg_set_val_dword(hkey
, szWindowsInstaller
, 1);
4334 size
= deformat_string(package
, modpath_fmt
, &buffer
);
4335 RegSetValueExW(hkey
, szModifyPath
, 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
4336 RegSetValueExW(hkey
, szUninstallString
, 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
4339 /* FIXME: Write real Estimated Size when we have it */
4340 msi_reg_set_val_dword(hkey
, szEstimatedSize
, 0);
4342 buffer
= msi_dup_property(package
, szProductName
);
4343 msi_reg_set_val_str(hkey
, szDisplayName
, buffer
);
4346 buffer
= msi_dup_property(package
, cszSourceDir
);
4347 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_INSTALLSOURCEW
, buffer
);
4350 buffer
= msi_dup_property(package
, szManufacturer
);
4351 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PUBLISHERW
, buffer
);
4354 GetLocalTime(&systime
);
4355 sprintfW(date
, date_fmt
, systime
.wYear
, systime
.wMonth
, systime
.wDay
);
4356 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_INSTALLDATEW
, date
);
4358 langid
= msi_get_property_int(package
, szProductLanguage
, 0);
4359 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
4361 buffer
= msi_dup_property(package
, szProductVersion
);
4362 msi_reg_set_val_str(hkey
, szDisplayVersion
, buffer
);
4365 DWORD verdword
= msi_version_str_to_dword(buffer
);
4367 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
4368 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMAJORW
, verdword
>> 24);
4369 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMINORW
, (verdword
>> 16) & 0xFF);
4373 return ERROR_SUCCESS
;
4376 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
4378 WCHAR squashed_pc
[SQUISH_GUID_SIZE
];
4379 LPWSTR upgrade_code
;
4384 static const WCHAR szUpgradeCode
[] = {
4385 'U','p','g','r','a','d','e','C','o','d','e',0};
4387 /* FIXME: also need to publish if the product is in advertise mode */
4388 if (!msi_check_publish(package
))
4389 return ERROR_SUCCESS
;
4391 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
, &hkey
, TRUE
);
4392 if (rc
!= ERROR_SUCCESS
)
4395 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
,
4396 NULL
, &props
, TRUE
);
4397 if (rc
!= ERROR_SUCCESS
)
4400 msi_reg_set_val_str( props
, INSTALLPROPERTY_LOCALPACKAGEW
, package
->db
->localfile
);
4401 msi_free( package
->db
->localfile
);
4402 package
->db
->localfile
= NULL
;
4404 rc
= msi_publish_install_properties(package
, hkey
);
4405 if (rc
!= ERROR_SUCCESS
)
4408 rc
= msi_publish_install_properties(package
, props
);
4409 if (rc
!= ERROR_SUCCESS
)
4412 upgrade_code
= msi_dup_property(package
, szUpgradeCode
);
4415 MSIREG_OpenUpgradeCodesKey(upgrade_code
, &upgrade
, TRUE
);
4416 squash_guid(package
->ProductCode
, squashed_pc
);
4417 msi_reg_set_val_str(upgrade
, squashed_pc
, NULL
);
4418 RegCloseKey(upgrade
);
4419 msi_free(upgrade_code
);
4425 return ERROR_SUCCESS
;
4428 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
4430 return execute_script(package
,INSTALL_SCRIPT
);
4433 static UINT
msi_unpublish_product(MSIPACKAGE
*package
)
4436 LPWSTR remove
= NULL
;
4437 LPWSTR
*features
= NULL
;
4438 BOOL full_uninstall
= TRUE
;
4439 MSIFEATURE
*feature
;
4441 static const WCHAR szUpgradeCode
[] =
4442 {'U','p','g','r','a','d','e','C','o','d','e',0};
4444 remove
= msi_dup_property(package
, szRemove
);
4446 return ERROR_SUCCESS
;
4448 features
= msi_split_string(remove
, ',');
4452 ERR("REMOVE feature list is empty!\n");
4453 return ERROR_FUNCTION_FAILED
;
4456 if (!lstrcmpW(features
[0], szAll
))
4457 full_uninstall
= TRUE
;
4460 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4462 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
4463 full_uninstall
= FALSE
;
4467 if (!full_uninstall
)
4470 MSIREG_DeleteProductKey(package
->ProductCode
);
4471 MSIREG_DeleteUserDataProductKey(package
->ProductCode
);
4472 MSIREG_DeleteUninstallKey(package
->ProductCode
);
4474 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
4476 MSIREG_DeleteLocalClassesProductKey(package
->ProductCode
);
4477 MSIREG_DeleteLocalClassesFeaturesKey(package
->ProductCode
);
4481 MSIREG_DeleteUserProductKey(package
->ProductCode
);
4482 MSIREG_DeleteUserFeaturesKey(package
->ProductCode
);
4485 upgrade
= msi_dup_property(package
, szUpgradeCode
);
4488 MSIREG_DeleteUserUpgradeCodesKey(upgrade
);
4495 return ERROR_SUCCESS
;
4498 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
4502 rc
= msi_unpublish_product(package
);
4503 if (rc
!= ERROR_SUCCESS
)
4506 /* turn off scheduling */
4507 package
->script
->CurrentlyScripting
= FALSE
;
4509 /* first do the same as an InstallExecute */
4510 rc
= ACTION_InstallExecute(package
);
4511 if (rc
!= ERROR_SUCCESS
)
4514 /* then handle Commit Actions */
4515 rc
= execute_script(package
,COMMIT_SCRIPT
);
4520 UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
4522 static const WCHAR RunOnce
[] = {
4523 'S','o','f','t','w','a','r','e','\\',
4524 'M','i','c','r','o','s','o','f','t','\\',
4525 'W','i','n','d','o','w','s','\\',
4526 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4527 'R','u','n','O','n','c','e',0};
4528 static const WCHAR InstallRunOnce
[] = {
4529 'S','o','f','t','w','a','r','e','\\',
4530 'M','i','c','r','o','s','o','f','t','\\',
4531 'W','i','n','d','o','w','s','\\',
4532 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4533 'I','n','s','t','a','l','l','e','r','\\',
4534 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
4536 static const WCHAR msiexec_fmt
[] = {
4538 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
4539 '\"','%','s','\"',0};
4540 static const WCHAR install_fmt
[] = {
4541 '/','I',' ','\"','%','s','\"',' ',
4542 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
4543 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
4544 WCHAR buffer
[256], sysdir
[MAX_PATH
];
4546 WCHAR squished_pc
[100];
4548 squash_guid(package
->ProductCode
,squished_pc
);
4550 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
4551 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
4552 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
4555 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
4558 TRACE("Reboot command %s\n",debugstr_w(buffer
));
4560 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
4561 sprintfW(buffer
,install_fmt
,package
->ProductCode
,squished_pc
);
4563 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
4566 return ERROR_INSTALL_SUSPEND
;
4569 static UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
4575 * We are currently doing what should be done here in the top level Install
4576 * however for Administrative and uninstalls this step will be needed
4578 if (!package
->PackagePath
)
4579 return ERROR_SUCCESS
;
4581 msi_set_sourcedir_props(package
, TRUE
);
4583 attrib
= GetFileAttributesW(package
->db
->path
);
4584 if (attrib
== INVALID_FILE_ATTRIBUTES
)
4590 rc
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
4591 package
->Context
, MSICODE_PRODUCT
,
4592 INSTALLPROPERTY_DISKPROMPTW
,NULL
,&size
);
4593 if (rc
== ERROR_MORE_DATA
)
4595 prompt
= msi_alloc(size
* sizeof(WCHAR
));
4596 MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
4597 package
->Context
, MSICODE_PRODUCT
,
4598 INSTALLPROPERTY_DISKPROMPTW
,prompt
,&size
);
4601 prompt
= strdupW(package
->db
->path
);
4603 msg
= generate_error_string(package
,1302,1,prompt
);
4604 while(attrib
== INVALID_FILE_ATTRIBUTES
)
4606 rc
= MessageBoxW(NULL
,msg
,NULL
,MB_OKCANCEL
);
4609 rc
= ERROR_INSTALL_USEREXIT
;
4612 attrib
= GetFileAttributesW(package
->db
->path
);
4618 return ERROR_SUCCESS
;
4623 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
4630 static const WCHAR szPropKeys
[][80] =
4632 {'P','r','o','d','u','c','t','I','D',0},
4633 {'U','S','E','R','N','A','M','E',0},
4634 {'C','O','M','P','A','N','Y','N','A','M','E',0},
4638 static const WCHAR szRegKeys
[][80] =
4640 {'P','r','o','d','u','c','t','I','D',0},
4641 {'R','e','g','O','w','n','e','r',0},
4642 {'R','e','g','C','o','m','p','a','n','y',0},
4646 if (msi_check_unpublish(package
))
4648 MSIREG_DeleteUserDataProductKey(package
->ProductCode
);
4649 return ERROR_SUCCESS
;
4652 productid
= msi_dup_property( package
, INSTALLPROPERTY_PRODUCTIDW
);
4654 return ERROR_SUCCESS
;
4656 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
,
4658 if (rc
!= ERROR_SUCCESS
)
4661 for( i
= 0; szPropKeys
[i
][0]; i
++ )
4663 buffer
= msi_dup_property( package
, szPropKeys
[i
] );
4664 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
4669 msi_free(productid
);
4672 /* FIXME: call ui_actiondata */
4678 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
4682 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
4683 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
4688 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
4690 MSIPACKAGE
*package
= param
;
4691 LPCWSTR compgroupid
, component
, feature
, qualifier
, text
;
4692 LPWSTR advertise
= NULL
, output
= NULL
;
4700 feature
= MSI_RecordGetString(rec
, 5);
4701 feat
= get_loaded_feature(package
, feature
);
4703 return ERROR_SUCCESS
;
4705 if (feat
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
4706 feat
->ActionRequest
!= INSTALLSTATE_SOURCE
&&
4707 feat
->ActionRequest
!= INSTALLSTATE_ADVERTISED
)
4709 TRACE("Feature %s not scheduled for installation\n", debugstr_w(feature
));
4710 feat
->Action
= feat
->Installed
;
4711 return ERROR_SUCCESS
;
4714 component
= MSI_RecordGetString(rec
, 3);
4715 comp
= get_loaded_component(package
, component
);
4717 return ERROR_SUCCESS
;
4719 compgroupid
= MSI_RecordGetString(rec
,1);
4720 qualifier
= MSI_RecordGetString(rec
,2);
4722 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
4723 if (rc
!= ERROR_SUCCESS
)
4726 text
= MSI_RecordGetString(rec
,4);
4727 advertise
= create_component_advertise_string(package
, comp
, feature
);
4729 sz
= strlenW(advertise
);
4732 sz
+= lstrlenW(text
);
4735 sz
*= sizeof(WCHAR
);
4737 output
= msi_alloc_zero(sz
);
4738 strcpyW(output
,advertise
);
4739 msi_free(advertise
);
4742 strcatW(output
,text
);
4744 msi_reg_set_val_multi_str( hkey
, qualifier
, output
);
4751 uirow
= MSI_CreateRecord( 2 );
4752 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
4753 MSI_RecordSetStringW( uirow
, 2, qualifier
);
4754 ui_actiondata( package
, szPublishComponents
, uirow
);
4755 msiobj_release( &uirow
->hdr
);
4756 /* FIXME: call ui_progress? */
4762 * At present I am ignorning the advertised components part of this and only
4763 * focusing on the qualified component sets
4765 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
4769 static const WCHAR ExecSeqQuery
[] =
4770 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4771 '`','P','u','b','l','i','s','h',
4772 'C','o','m','p','o','n','e','n','t','`',0};
4774 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4775 if (rc
!= ERROR_SUCCESS
)
4776 return ERROR_SUCCESS
;
4778 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
4779 msiobj_release(&view
->hdr
);
4784 static UINT
ITERATE_UnpublishComponent( MSIRECORD
*rec
, LPVOID param
)
4786 static const WCHAR szInstallerComponents
[] = {
4787 'S','o','f','t','w','a','r','e','\\',
4788 'M','i','c','r','o','s','o','f','t','\\',
4789 'I','n','s','t','a','l','l','e','r','\\',
4790 'C','o','m','p','o','n','e','n','t','s','\\',0};
4792 MSIPACKAGE
*package
= param
;
4793 LPCWSTR compgroupid
, component
, feature
, qualifier
;
4797 WCHAR squashed
[GUID_SIZE
], keypath
[MAX_PATH
];
4800 feature
= MSI_RecordGetString( rec
, 5 );
4801 feat
= get_loaded_feature( package
, feature
);
4803 return ERROR_SUCCESS
;
4805 if (feat
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4807 TRACE("Feature %s not scheduled for removal\n", debugstr_w(feature
));
4808 feat
->Action
= feat
->Installed
;
4809 return ERROR_SUCCESS
;
4812 component
= MSI_RecordGetString( rec
, 3 );
4813 comp
= get_loaded_component( package
, component
);
4815 return ERROR_SUCCESS
;
4817 compgroupid
= MSI_RecordGetString( rec
, 1 );
4818 qualifier
= MSI_RecordGetString( rec
, 2 );
4820 squash_guid( compgroupid
, squashed
);
4821 strcpyW( keypath
, szInstallerComponents
);
4822 strcatW( keypath
, squashed
);
4824 res
= RegDeleteKeyW( HKEY_CURRENT_USER
, keypath
);
4825 if (res
!= ERROR_SUCCESS
)
4827 WARN("Unable to delete component key %d\n", res
);
4830 uirow
= MSI_CreateRecord( 2 );
4831 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
4832 MSI_RecordSetStringW( uirow
, 2, qualifier
);
4833 ui_actiondata( package
, szUnpublishComponents
, uirow
);
4834 msiobj_release( &uirow
->hdr
);
4836 return ERROR_SUCCESS
;
4839 static UINT
ACTION_UnpublishComponents( MSIPACKAGE
*package
)
4843 static const WCHAR query
[] =
4844 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4845 '`','P','u','b','l','i','s','h',
4846 'C','o','m','p','o','n','e','n','t','`',0};
4848 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4849 if (rc
!= ERROR_SUCCESS
)
4850 return ERROR_SUCCESS
;
4852 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnpublishComponent
, package
);
4853 msiobj_release( &view
->hdr
);
4858 static UINT
ITERATE_InstallService(MSIRECORD
*rec
, LPVOID param
)
4860 MSIPACKAGE
*package
= param
;
4863 SC_HANDLE hscm
, service
= NULL
;
4864 LPCWSTR comp
, depends
, pass
;
4865 LPWSTR name
= NULL
, disp
= NULL
;
4866 LPCWSTR load_order
, serv_name
, key
;
4867 DWORD serv_type
, start_type
;
4870 static const WCHAR query
[] =
4871 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
4872 '`','C','o','m','p','o','n','e','n','t','`',' ',
4873 'W','H','E','R','E',' ',
4874 '`','C','o','m','p','o','n','e','n','t','`',' ',
4875 '=','\'','%','s','\'',0};
4877 hscm
= OpenSCManagerW(NULL
, SERVICES_ACTIVE_DATABASEW
, GENERIC_WRITE
);
4880 ERR("Failed to open the SC Manager!\n");
4884 start_type
= MSI_RecordGetInteger(rec
, 5);
4885 if (start_type
== SERVICE_BOOT_START
|| start_type
== SERVICE_SYSTEM_START
)
4888 depends
= MSI_RecordGetString(rec
, 8);
4889 if (depends
&& *depends
)
4890 FIXME("Dependency list unhandled!\n");
4892 deformat_string(package
, MSI_RecordGetString(rec
, 2), &name
);
4893 deformat_string(package
, MSI_RecordGetString(rec
, 3), &disp
);
4894 serv_type
= MSI_RecordGetInteger(rec
, 4);
4895 err_control
= MSI_RecordGetInteger(rec
, 6);
4896 load_order
= MSI_RecordGetString(rec
, 7);
4897 serv_name
= MSI_RecordGetString(rec
, 9);
4898 pass
= MSI_RecordGetString(rec
, 10);
4899 comp
= MSI_RecordGetString(rec
, 12);
4901 /* fetch the service path */
4902 row
= MSI_QueryGetRecord(package
->db
, query
, comp
);
4905 ERR("Control query failed!\n");
4909 key
= MSI_RecordGetString(row
, 6);
4911 file
= get_loaded_file(package
, key
);
4912 msiobj_release(&row
->hdr
);
4915 ERR("Failed to load the service file\n");
4919 service
= CreateServiceW(hscm
, name
, disp
, GENERIC_ALL
, serv_type
,
4920 start_type
, err_control
, file
->TargetPath
,
4921 load_order
, NULL
, NULL
, serv_name
, pass
);
4924 if (GetLastError() != ERROR_SERVICE_EXISTS
)
4925 ERR("Failed to create service %s: %d\n", debugstr_w(name
), GetLastError());
4929 CloseServiceHandle(service
);
4930 CloseServiceHandle(hscm
);
4934 return ERROR_SUCCESS
;
4937 static UINT
ACTION_InstallServices( MSIPACKAGE
*package
)
4941 static const WCHAR ExecSeqQuery
[] =
4942 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4943 'S','e','r','v','i','c','e','I','n','s','t','a','l','l',0};
4945 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4946 if (rc
!= ERROR_SUCCESS
)
4947 return ERROR_SUCCESS
;
4949 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallService
, package
);
4950 msiobj_release(&view
->hdr
);
4955 /* converts arg1[~]arg2[~]arg3 to a list of ptrs to the strings */
4956 static LPCWSTR
*msi_service_args_to_vector(LPWSTR args
, DWORD
*numargs
)
4958 LPCWSTR
*vector
, *temp_vector
;
4962 static const WCHAR separator
[] = {'[','~',']',0};
4965 sep_len
= sizeof(separator
) / sizeof(WCHAR
) - 1;
4970 vector
= msi_alloc(sizeof(LPWSTR
));
4978 vector
[*numargs
- 1] = p
;
4980 if ((q
= strstrW(p
, separator
)))
4984 temp_vector
= msi_realloc(vector
, (*numargs
+ 1) * sizeof(LPWSTR
));
4990 vector
= temp_vector
;
4999 static UINT
ITERATE_StartService(MSIRECORD
*rec
, LPVOID param
)
5001 MSIPACKAGE
*package
= param
;
5003 SC_HANDLE scm
= NULL
, service
= NULL
;
5004 LPCWSTR component
, *vector
= NULL
;
5006 DWORD event
, numargs
;
5007 UINT r
= ERROR_FUNCTION_FAILED
;
5009 component
= MSI_RecordGetString(rec
, 6);
5010 comp
= get_loaded_component(package
, component
);
5012 return ERROR_SUCCESS
;
5014 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
5016 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
5017 comp
->Action
= comp
->Installed
;
5018 return ERROR_SUCCESS
;
5020 comp
->Action
= INSTALLSTATE_LOCAL
;
5022 deformat_string(package
, MSI_RecordGetString(rec
, 2), &name
);
5023 deformat_string(package
, MSI_RecordGetString(rec
, 4), &args
);
5024 event
= MSI_RecordGetInteger(rec
, 3);
5026 if (!(event
& msidbServiceControlEventStart
))
5032 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_CONNECT
);
5035 ERR("Failed to open the service control manager\n");
5039 service
= OpenServiceW(scm
, name
, SERVICE_START
);
5042 ERR("Failed to open service %s (%u)\n", debugstr_w(name
), GetLastError());
5046 vector
= msi_service_args_to_vector(args
, &numargs
);
5048 if (!StartServiceW(service
, numargs
, vector
) &&
5049 GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
)
5051 ERR("Failed to start service %s (%u)\n", debugstr_w(name
), GetLastError());
5058 CloseServiceHandle(service
);
5059 CloseServiceHandle(scm
);
5067 static UINT
ACTION_StartServices( MSIPACKAGE
*package
)
5072 static const WCHAR query
[] = {
5073 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5074 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
5076 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
5077 if (rc
!= ERROR_SUCCESS
)
5078 return ERROR_SUCCESS
;
5080 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StartService
, package
);
5081 msiobj_release(&view
->hdr
);
5086 static BOOL
stop_service_dependents(SC_HANDLE scm
, SC_HANDLE service
)
5088 DWORD i
, needed
, count
;
5089 ENUM_SERVICE_STATUSW
*dependencies
;
5093 if (EnumDependentServicesW(service
, SERVICE_ACTIVE
, NULL
,
5094 0, &needed
, &count
))
5097 if (GetLastError() != ERROR_MORE_DATA
)
5100 dependencies
= msi_alloc(needed
);
5104 if (!EnumDependentServicesW(service
, SERVICE_ACTIVE
, dependencies
,
5105 needed
, &needed
, &count
))
5108 for (i
= 0; i
< count
; i
++)
5110 depserv
= OpenServiceW(scm
, dependencies
[i
].lpServiceName
,
5111 SERVICE_STOP
| SERVICE_QUERY_STATUS
);
5115 if (!ControlService(depserv
, SERVICE_CONTROL_STOP
, &ss
))
5122 msi_free(dependencies
);
5126 static UINT
stop_service( LPCWSTR name
)
5128 SC_HANDLE scm
= NULL
, service
= NULL
;
5129 SERVICE_STATUS status
;
5130 SERVICE_STATUS_PROCESS ssp
;
5133 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
5136 WARN("Failed to open the SCM: %d\n", GetLastError());
5140 service
= OpenServiceW(scm
, name
,
5142 SERVICE_QUERY_STATUS
|
5143 SERVICE_ENUMERATE_DEPENDENTS
);
5146 WARN("Failed to open service (%s): %d\n", debugstr_w(name
), GetLastError());
5150 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
, (LPBYTE
)&ssp
,
5151 sizeof(SERVICE_STATUS_PROCESS
), &needed
))
5153 WARN("Failed to query service status (%s): %d\n", debugstr_w(name
), GetLastError());
5157 if (ssp
.dwCurrentState
== SERVICE_STOPPED
)
5160 stop_service_dependents(scm
, service
);
5162 if (!ControlService(service
, SERVICE_CONTROL_STOP
, &status
))
5163 WARN("Failed to stop service (%s): %d\n", debugstr_w(name
), GetLastError());
5166 CloseServiceHandle(service
);
5167 CloseServiceHandle(scm
);
5169 return ERROR_SUCCESS
;
5172 static UINT
ITERATE_StopService( MSIRECORD
*rec
, LPVOID param
)
5174 MSIPACKAGE
*package
= param
;
5180 event
= MSI_RecordGetInteger( rec
, 3 );
5181 if (!(event
& msidbServiceControlEventStop
))
5182 return ERROR_SUCCESS
;
5184 component
= MSI_RecordGetString( rec
, 6 );
5185 comp
= get_loaded_component( package
, component
);
5187 return ERROR_SUCCESS
;
5189 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
5191 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
5192 comp
->Action
= comp
->Installed
;
5193 return ERROR_SUCCESS
;
5195 comp
->Action
= INSTALLSTATE_ABSENT
;
5197 deformat_string( package
, MSI_RecordGetString( rec
, 2 ), &name
);
5198 stop_service( name
);
5201 return ERROR_SUCCESS
;
5204 static UINT
ACTION_StopServices( MSIPACKAGE
*package
)
5209 static const WCHAR query
[] = {
5210 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5211 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
5213 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
5214 if (rc
!= ERROR_SUCCESS
)
5215 return ERROR_SUCCESS
;
5217 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StopService
, package
);
5218 msiobj_release(&view
->hdr
);
5223 static UINT
ITERATE_DeleteService( MSIRECORD
*rec
, LPVOID param
)
5225 MSIPACKAGE
*package
= param
;
5230 SC_HANDLE scm
= NULL
, service
= NULL
;
5232 event
= MSI_RecordGetInteger( rec
, 3 );
5233 if (!(event
& msidbServiceControlEventDelete
))
5234 return ERROR_SUCCESS
;
5236 component
= MSI_RecordGetString(rec
, 6);
5237 comp
= get_loaded_component(package
, component
);
5239 return ERROR_SUCCESS
;
5241 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
5243 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
5244 comp
->Action
= comp
->Installed
;
5245 return ERROR_SUCCESS
;
5247 comp
->Action
= INSTALLSTATE_ABSENT
;
5249 deformat_string( package
, MSI_RecordGetString(rec
, 2), &name
);
5250 stop_service( name
);
5252 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
5255 WARN("Failed to open the SCM: %d\n", GetLastError());
5259 service
= OpenServiceW( scm
, name
, DELETE
);
5262 WARN("Failed to open service (%s): %u\n", debugstr_w(name
), GetLastError());
5266 if (!DeleteService( service
))
5267 WARN("Failed to delete service (%s): %u\n", debugstr_w(name
), GetLastError());
5270 CloseServiceHandle( service
);
5271 CloseServiceHandle( scm
);
5274 return ERROR_SUCCESS
;
5277 static UINT
ACTION_DeleteServices( MSIPACKAGE
*package
)
5282 static const WCHAR query
[] = {
5283 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5284 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
5286 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
5287 if (rc
!= ERROR_SUCCESS
)
5288 return ERROR_SUCCESS
;
5290 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_DeleteService
, package
);
5291 msiobj_release( &view
->hdr
);
5296 static MSIFILE
*msi_find_file( MSIPACKAGE
*package
, LPCWSTR filename
)
5300 LIST_FOR_EACH_ENTRY(file
, &package
->files
, MSIFILE
, entry
)
5302 if (!lstrcmpW(file
->File
, filename
))
5309 static UINT
ITERATE_InstallODBCDriver( MSIRECORD
*rec
, LPVOID param
)
5311 MSIPACKAGE
*package
= param
;
5312 LPWSTR driver
, driver_path
, ptr
;
5313 WCHAR outpath
[MAX_PATH
];
5314 MSIFILE
*driver_file
, *setup_file
;
5317 UINT r
= ERROR_SUCCESS
;
5319 static const WCHAR driver_fmt
[] = {
5320 'D','r','i','v','e','r','=','%','s',0};
5321 static const WCHAR setup_fmt
[] = {
5322 'S','e','t','u','p','=','%','s',0};
5323 static const WCHAR usage_fmt
[] = {
5324 'F','i','l','e','U','s','a','g','e','=','1',0};
5326 desc
= MSI_RecordGetString(rec
, 3);
5328 driver_file
= msi_find_file(package
, MSI_RecordGetString(rec
, 4));
5329 setup_file
= msi_find_file(package
, MSI_RecordGetString(rec
, 5));
5333 ERR("ODBC Driver entry not found!\n");
5334 return ERROR_FUNCTION_FAILED
;
5337 len
= lstrlenW(desc
) + lstrlenW(driver_fmt
) + lstrlenW(driver_file
->FileName
);
5339 len
+= lstrlenW(setup_fmt
) + lstrlenW(setup_file
->FileName
);
5340 len
+= lstrlenW(usage_fmt
) + 2; /* \0\0 */
5342 driver
= msi_alloc(len
* sizeof(WCHAR
));
5344 return ERROR_OUTOFMEMORY
;
5347 lstrcpyW(ptr
, desc
);
5348 ptr
+= lstrlenW(ptr
) + 1;
5350 len
= sprintfW(ptr
, driver_fmt
, driver_file
->FileName
);
5355 len
= sprintfW(ptr
, setup_fmt
, setup_file
->FileName
);
5359 lstrcpyW(ptr
, usage_fmt
);
5360 ptr
+= lstrlenW(ptr
) + 1;
5363 driver_path
= strdupW(driver_file
->TargetPath
);
5364 ptr
= strrchrW(driver_path
, '\\');
5365 if (ptr
) *ptr
= '\0';
5367 if (!SQLInstallDriverExW(driver
, driver_path
, outpath
, MAX_PATH
,
5368 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
5370 ERR("Failed to install SQL driver!\n");
5371 r
= ERROR_FUNCTION_FAILED
;
5375 msi_free(driver_path
);
5380 static UINT
ITERATE_InstallODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
5382 MSIPACKAGE
*package
= param
;
5383 LPWSTR translator
, translator_path
, ptr
;
5384 WCHAR outpath
[MAX_PATH
];
5385 MSIFILE
*translator_file
, *setup_file
;
5388 UINT r
= ERROR_SUCCESS
;
5390 static const WCHAR translator_fmt
[] = {
5391 'T','r','a','n','s','l','a','t','o','r','=','%','s',0};
5392 static const WCHAR setup_fmt
[] = {
5393 'S','e','t','u','p','=','%','s',0};
5395 desc
= MSI_RecordGetString(rec
, 3);
5397 translator_file
= msi_find_file(package
, MSI_RecordGetString(rec
, 4));
5398 setup_file
= msi_find_file(package
, MSI_RecordGetString(rec
, 5));
5400 if (!translator_file
)
5402 ERR("ODBC Translator entry not found!\n");
5403 return ERROR_FUNCTION_FAILED
;
5406 len
= lstrlenW(desc
) + lstrlenW(translator_fmt
) + lstrlenW(translator_file
->FileName
) + 2; /* \0\0 */
5408 len
+= lstrlenW(setup_fmt
) + lstrlenW(setup_file
->FileName
);
5410 translator
= msi_alloc(len
* sizeof(WCHAR
));
5412 return ERROR_OUTOFMEMORY
;
5415 lstrcpyW(ptr
, desc
);
5416 ptr
+= lstrlenW(ptr
) + 1;
5418 len
= sprintfW(ptr
, translator_fmt
, translator_file
->FileName
);
5423 len
= sprintfW(ptr
, setup_fmt
, setup_file
->FileName
);
5428 translator_path
= strdupW(translator_file
->TargetPath
);
5429 ptr
= strrchrW(translator_path
, '\\');
5430 if (ptr
) *ptr
= '\0';
5432 if (!SQLInstallTranslatorExW(translator
, translator_path
, outpath
, MAX_PATH
,
5433 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
5435 ERR("Failed to install SQL translator!\n");
5436 r
= ERROR_FUNCTION_FAILED
;
5439 msi_free(translator
);
5440 msi_free(translator_path
);
5445 static UINT
ITERATE_InstallODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
5448 LPCWSTR desc
, driver
;
5449 WORD request
= ODBC_ADD_SYS_DSN
;
5452 UINT r
= ERROR_SUCCESS
;
5454 static const WCHAR attrs_fmt
[] = {
5455 'D','S','N','=','%','s',0 };
5457 desc
= MSI_RecordGetString(rec
, 3);
5458 driver
= MSI_RecordGetString(rec
, 4);
5459 registration
= MSI_RecordGetInteger(rec
, 5);
5461 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_ADD_SYS_DSN
;
5462 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_ADD_DSN
;
5464 len
= lstrlenW(attrs_fmt
) + lstrlenW(desc
) + 2; /* \0\0 */
5465 attrs
= msi_alloc(len
* sizeof(WCHAR
));
5467 return ERROR_OUTOFMEMORY
;
5469 len
= sprintfW(attrs
, attrs_fmt
, desc
);
5472 if (!SQLConfigDataSourceW(NULL
, request
, driver
, attrs
))
5474 ERR("Failed to install SQL data source!\n");
5475 r
= ERROR_FUNCTION_FAILED
;
5483 static UINT
ACTION_InstallODBC( MSIPACKAGE
*package
)
5488 static const WCHAR driver_query
[] = {
5489 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5490 'O','D','B','C','D','r','i','v','e','r',0 };
5492 static const WCHAR translator_query
[] = {
5493 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5494 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0 };
5496 static const WCHAR source_query
[] = {
5497 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5498 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0 };
5500 rc
= MSI_DatabaseOpenViewW(package
->db
, driver_query
, &view
);
5501 if (rc
!= ERROR_SUCCESS
)
5502 return ERROR_SUCCESS
;
5504 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDriver
, package
);
5505 msiobj_release(&view
->hdr
);
5507 rc
= MSI_DatabaseOpenViewW(package
->db
, translator_query
, &view
);
5508 if (rc
!= ERROR_SUCCESS
)
5509 return ERROR_SUCCESS
;
5511 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCTranslator
, package
);
5512 msiobj_release(&view
->hdr
);
5514 rc
= MSI_DatabaseOpenViewW(package
->db
, source_query
, &view
);
5515 if (rc
!= ERROR_SUCCESS
)
5516 return ERROR_SUCCESS
;
5518 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDataSource
, package
);
5519 msiobj_release(&view
->hdr
);
5524 static UINT
ITERATE_RemoveODBCDriver( MSIRECORD
*rec
, LPVOID param
)
5529 desc
= MSI_RecordGetString( rec
, 3 );
5530 if (!SQLRemoveDriverW( desc
, FALSE
, &usage
))
5532 WARN("Failed to remove ODBC driver\n");
5536 FIXME("Usage count reached 0\n");
5539 return ERROR_SUCCESS
;
5542 static UINT
ITERATE_RemoveODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
5547 desc
= MSI_RecordGetString( rec
, 3 );
5548 if (!SQLRemoveTranslatorW( desc
, &usage
))
5550 WARN("Failed to remove ODBC translator\n");
5554 FIXME("Usage count reached 0\n");
5557 return ERROR_SUCCESS
;
5560 static UINT
ITERATE_RemoveODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
5563 LPCWSTR desc
, driver
;
5564 WORD request
= ODBC_REMOVE_SYS_DSN
;
5568 static const WCHAR attrs_fmt
[] = {
5569 'D','S','N','=','%','s',0 };
5571 desc
= MSI_RecordGetString( rec
, 3 );
5572 driver
= MSI_RecordGetString( rec
, 4 );
5573 registration
= MSI_RecordGetInteger( rec
, 5 );
5575 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_REMOVE_SYS_DSN
;
5576 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_REMOVE_DSN
;
5578 len
= strlenW( attrs_fmt
) + strlenW( desc
) + 2; /* \0\0 */
5579 attrs
= msi_alloc( len
* sizeof(WCHAR
) );
5581 return ERROR_OUTOFMEMORY
;
5583 FIXME("Use ODBCSourceAttribute table\n");
5585 len
= sprintfW( attrs
, attrs_fmt
, desc
);
5588 if (!SQLConfigDataSourceW( NULL
, request
, driver
, attrs
))
5590 WARN("Failed to remove ODBC data source\n");
5594 return ERROR_SUCCESS
;
5597 static UINT
ACTION_RemoveODBC( MSIPACKAGE
*package
)
5602 static const WCHAR driver_query
[] = {
5603 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5604 'O','D','B','C','D','r','i','v','e','r',0 };
5606 static const WCHAR translator_query
[] = {
5607 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5608 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0 };
5610 static const WCHAR source_query
[] = {
5611 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5612 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0 };
5614 rc
= MSI_DatabaseOpenViewW( package
->db
, driver_query
, &view
);
5615 if (rc
!= ERROR_SUCCESS
)
5616 return ERROR_SUCCESS
;
5618 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDriver
, package
);
5619 msiobj_release( &view
->hdr
);
5621 rc
= MSI_DatabaseOpenViewW( package
->db
, translator_query
, &view
);
5622 if (rc
!= ERROR_SUCCESS
)
5623 return ERROR_SUCCESS
;
5625 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCTranslator
, package
);
5626 msiobj_release( &view
->hdr
);
5628 rc
= MSI_DatabaseOpenViewW( package
->db
, source_query
, &view
);
5629 if (rc
!= ERROR_SUCCESS
)
5630 return ERROR_SUCCESS
;
5632 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDataSource
, package
);
5633 msiobj_release( &view
->hdr
);
5638 #define ENV_ACT_SETALWAYS 0x1
5639 #define ENV_ACT_SETABSENT 0x2
5640 #define ENV_ACT_REMOVE 0x4
5641 #define ENV_ACT_REMOVEMATCH 0x8
5643 #define ENV_MOD_MACHINE 0x20000000
5644 #define ENV_MOD_APPEND 0x40000000
5645 #define ENV_MOD_PREFIX 0x80000000
5646 #define ENV_MOD_MASK 0xC0000000
5648 #define check_flag_combo(x, y) ((x) & ~(y)) == (y)
5650 static LONG
env_set_flags( LPCWSTR
*name
, LPCWSTR
*value
, DWORD
*flags
)
5652 LPCWSTR cptr
= *name
;
5654 static const WCHAR prefix
[] = {'[','~',']',0};
5655 static const int prefix_len
= 3;
5661 *flags
|= ENV_ACT_SETALWAYS
;
5662 else if (*cptr
== '+')
5663 *flags
|= ENV_ACT_SETABSENT
;
5664 else if (*cptr
== '-')
5665 *flags
|= ENV_ACT_REMOVE
;
5666 else if (*cptr
== '!')
5667 *flags
|= ENV_ACT_REMOVEMATCH
;
5668 else if (*cptr
== '*')
5669 *flags
|= ENV_MOD_MACHINE
;
5679 ERR("Missing environment variable\n");
5680 return ERROR_FUNCTION_FAILED
;
5685 LPCWSTR ptr
= *value
;
5686 if (!strncmpW(ptr
, prefix
, prefix_len
))
5688 if (ptr
[prefix_len
] == szSemiColon
[0])
5690 *flags
|= ENV_MOD_APPEND
;
5691 *value
+= lstrlenW(prefix
);
5698 else if (lstrlenW(*value
) >= prefix_len
)
5700 ptr
+= lstrlenW(ptr
) - prefix_len
;
5701 if (!lstrcmpW(ptr
, prefix
))
5703 if ((ptr
-1) > *value
&& *(ptr
-1) == szSemiColon
[0])
5705 *flags
|= ENV_MOD_PREFIX
;
5706 /* the "[~]" will be removed by deformat_string */;
5716 if (check_flag_combo(*flags
, ENV_ACT_SETALWAYS
| ENV_ACT_SETABSENT
) ||
5717 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETABSENT
) ||
5718 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETALWAYS
) ||
5719 check_flag_combo(*flags
, ENV_ACT_SETABSENT
| ENV_MOD_MASK
))
5721 ERR("Invalid flags: %08x\n", *flags
);
5722 return ERROR_FUNCTION_FAILED
;
5726 *flags
= ENV_ACT_SETALWAYS
| ENV_ACT_REMOVE
;
5728 return ERROR_SUCCESS
;
5731 static UINT
ITERATE_WriteEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
5733 MSIPACKAGE
*package
= param
;
5734 LPCWSTR name
, value
, component
;
5735 LPWSTR data
= NULL
, newval
= NULL
;
5736 LPWSTR deformatted
= NULL
, ptr
;
5737 DWORD flags
, type
, size
;
5739 HKEY env
= NULL
, root
;
5740 LPCWSTR environment
;
5743 static const WCHAR user_env
[] =
5744 {'E','n','v','i','r','o','n','m','e','n','t',0};
5745 static const WCHAR machine_env
[] =
5746 {'S','y','s','t','e','m','\\',
5747 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
5748 'C','o','n','t','r','o','l','\\',
5749 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
5750 'E','n','v','i','r','o','n','m','e','n','t',0};
5752 component
= MSI_RecordGetString(rec
, 4);
5753 comp
= get_loaded_component(package
, component
);
5755 return ERROR_SUCCESS
;
5757 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
5759 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
5760 comp
->Action
= comp
->Installed
;
5761 return ERROR_SUCCESS
;
5763 comp
->Action
= INSTALLSTATE_LOCAL
;
5765 name
= MSI_RecordGetString(rec
, 2);
5766 value
= MSI_RecordGetString(rec
, 3);
5768 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
5770 res
= env_set_flags(&name
, &value
, &flags
);
5771 if (res
!= ERROR_SUCCESS
|| !value
)
5774 if (value
&& !deformat_string(package
, value
, &deformatted
))
5776 res
= ERROR_OUTOFMEMORY
;
5780 value
= deformatted
;
5782 if (flags
& ENV_MOD_MACHINE
)
5784 environment
= machine_env
;
5785 root
= HKEY_LOCAL_MACHINE
;
5789 environment
= user_env
;
5790 root
= HKEY_CURRENT_USER
;
5793 res
= RegCreateKeyExW(root
, environment
, 0, NULL
, 0,
5794 KEY_ALL_ACCESS
, NULL
, &env
, NULL
);
5795 if (res
!= ERROR_SUCCESS
)
5798 if (flags
& ENV_ACT_REMOVE
)
5799 FIXME("Not removing environment variable on uninstall!\n");
5803 res
= RegQueryValueExW(env
, name
, NULL
, &type
, NULL
, &size
);
5804 if ((res
!= ERROR_SUCCESS
&& res
!= ERROR_FILE_NOT_FOUND
) ||
5805 (res
== ERROR_SUCCESS
&& type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
))
5808 if ((res
== ERROR_FILE_NOT_FOUND
|| !(flags
& ENV_MOD_MASK
)))
5810 /* Nothing to do. */
5813 res
= ERROR_SUCCESS
;
5817 /* If we are appending but the string was empty, strip ; */
5818 if ((flags
& ENV_MOD_APPEND
) && (value
[0] == szSemiColon
[0])) value
++;
5820 size
= (lstrlenW(value
) + 1) * sizeof(WCHAR
);
5821 newval
= strdupW(value
);
5824 res
= ERROR_OUTOFMEMORY
;
5830 /* Contrary to MSDN, +-variable to [~];path works */
5831 if (flags
& ENV_ACT_SETABSENT
&& !(flags
& ENV_MOD_MASK
))
5833 res
= ERROR_SUCCESS
;
5837 data
= msi_alloc(size
);
5841 return ERROR_OUTOFMEMORY
;
5844 res
= RegQueryValueExW(env
, name
, NULL
, &type
, (LPVOID
)data
, &size
);
5845 if (res
!= ERROR_SUCCESS
)
5848 if (flags
& ENV_ACT_REMOVEMATCH
&& (!value
|| !lstrcmpW(data
, value
)))
5850 res
= RegDeleteKeyW(env
, name
);
5854 size
= (lstrlenW(data
) + 1) * sizeof(WCHAR
);
5855 if (flags
& ENV_MOD_MASK
)
5859 if (flags
& ENV_MOD_APPEND
) multiplier
++;
5860 if (flags
& ENV_MOD_PREFIX
) multiplier
++;
5861 mod_size
= lstrlenW(value
) * multiplier
;
5862 size
+= mod_size
* sizeof(WCHAR
);
5865 newval
= msi_alloc(size
);
5869 res
= ERROR_OUTOFMEMORY
;
5873 if (flags
& ENV_MOD_PREFIX
)
5875 lstrcpyW(newval
, value
);
5876 ptr
= newval
+ lstrlenW(value
);
5879 lstrcpyW(ptr
, data
);
5881 if (flags
& ENV_MOD_APPEND
)
5883 lstrcatW(newval
, value
);
5886 TRACE("setting %s to %s\n", debugstr_w(name
), debugstr_w(newval
));
5887 res
= RegSetValueExW(env
, name
, 0, type
, (LPVOID
)newval
, size
);
5890 if (env
) RegCloseKey(env
);
5891 msi_free(deformatted
);
5897 static UINT
ACTION_WriteEnvironmentStrings( MSIPACKAGE
*package
)
5901 static const WCHAR ExecSeqQuery
[] =
5902 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5903 '`','E','n','v','i','r','o','n','m','e','n','t','`',0};
5904 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5905 if (rc
!= ERROR_SUCCESS
)
5906 return ERROR_SUCCESS
;
5908 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteEnvironmentString
, package
);
5909 msiobj_release(&view
->hdr
);
5914 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
5925 static BOOL
msi_move_file(LPCWSTR source
, LPCWSTR dest
, int options
)
5929 if (GetFileAttributesW(source
) == FILE_ATTRIBUTE_DIRECTORY
||
5930 GetFileAttributesW(dest
) == FILE_ATTRIBUTE_DIRECTORY
)
5932 WARN("Source or dest is directory, not moving\n");
5936 if (options
== msidbMoveFileOptionsMove
)
5938 TRACE("moving %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
5939 ret
= MoveFileExW(source
, dest
, MOVEFILE_REPLACE_EXISTING
);
5942 WARN("MoveFile failed: %d\n", GetLastError());
5948 TRACE("copying %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
5949 ret
= CopyFileW(source
, dest
, FALSE
);
5952 WARN("CopyFile failed: %d\n", GetLastError());
5960 static LPWSTR
wildcard_to_file(LPWSTR wildcard
, LPWSTR filename
)
5963 DWORD dirlen
, pathlen
;
5965 ptr
= strrchrW(wildcard
, '\\');
5966 dirlen
= ptr
- wildcard
+ 1;
5968 pathlen
= dirlen
+ lstrlenW(filename
) + 1;
5969 path
= msi_alloc(pathlen
* sizeof(WCHAR
));
5971 lstrcpynW(path
, wildcard
, dirlen
+ 1);
5972 lstrcatW(path
, filename
);
5977 static void free_file_entry(FILE_LIST
*file
)
5979 msi_free(file
->source
);
5980 msi_free(file
->dest
);
5984 static void free_list(FILE_LIST
*list
)
5986 while (!list_empty(&list
->entry
))
5988 FILE_LIST
*file
= LIST_ENTRY(list_head(&list
->entry
), FILE_LIST
, entry
);
5990 list_remove(&file
->entry
);
5991 free_file_entry(file
);
5995 static BOOL
add_wildcard(FILE_LIST
*files
, LPWSTR source
, LPWSTR dest
)
5997 FILE_LIST
*new, *file
;
5998 LPWSTR ptr
, filename
;
6001 new = msi_alloc_zero(sizeof(FILE_LIST
));
6005 new->source
= strdupW(source
);
6006 ptr
= strrchrW(dest
, '\\') + 1;
6007 filename
= strrchrW(new->source
, '\\') + 1;
6009 new->sourcename
= filename
;
6012 new->destname
= ptr
;
6014 new->destname
= new->sourcename
;
6016 size
= (ptr
- dest
) + lstrlenW(filename
) + 1;
6017 new->dest
= msi_alloc(size
* sizeof(WCHAR
));
6020 free_file_entry(new);
6024 lstrcpynW(new->dest
, dest
, ptr
- dest
+ 1);
6025 lstrcatW(new->dest
, filename
);
6027 if (list_empty(&files
->entry
))
6029 list_add_head(&files
->entry
, &new->entry
);
6033 LIST_FOR_EACH_ENTRY(file
, &files
->entry
, FILE_LIST
, entry
)
6035 if (lstrcmpW(source
, file
->source
) < 0)
6037 list_add_before(&file
->entry
, &new->entry
);
6042 list_add_after(&file
->entry
, &new->entry
);
6046 static BOOL
move_files_wildcard(LPWSTR source
, LPWSTR dest
, int options
)
6048 WIN32_FIND_DATAW wfd
;
6052 FILE_LIST files
, *file
;
6055 hfile
= FindFirstFileW(source
, &wfd
);
6056 if (hfile
== INVALID_HANDLE_VALUE
) return FALSE
;
6058 list_init(&files
.entry
);
6060 for (res
= TRUE
; res
; res
= FindNextFileW(hfile
, &wfd
))
6062 if (is_dot_dir(wfd
.cFileName
)) continue;
6064 path
= wildcard_to_file(source
, wfd
.cFileName
);
6071 add_wildcard(&files
, path
, dest
);
6075 /* no files match the wildcard */
6076 if (list_empty(&files
.entry
))
6079 /* only the first wildcard match gets renamed to dest */
6080 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
6081 size
= (strrchrW(file
->dest
, '\\') - file
->dest
) + lstrlenW(file
->destname
) + 2;
6082 file
->dest
= msi_realloc(file
->dest
, size
* sizeof(WCHAR
));
6089 /* file->dest may be shorter after the reallocation, so add a NULL
6090 * terminator. This is needed for the call to strrchrW, as there will no
6091 * longer be a NULL terminator within the bounds of the allocation in this case.
6093 file
->dest
[size
- 1] = '\0';
6094 lstrcpyW(strrchrW(file
->dest
, '\\') + 1, file
->destname
);
6096 while (!list_empty(&files
.entry
))
6098 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
6100 msi_move_file(file
->source
, file
->dest
, options
);
6102 list_remove(&file
->entry
);
6103 free_file_entry(file
);
6114 static UINT
ITERATE_MoveFiles( MSIRECORD
*rec
, LPVOID param
)
6116 MSIPACKAGE
*package
= param
;
6118 LPCWSTR sourcename
, component
;
6119 LPWSTR destname
= NULL
;
6120 LPWSTR sourcedir
= NULL
, destdir
= NULL
;
6121 LPWSTR source
= NULL
, dest
= NULL
;
6124 BOOL ret
, wildcards
;
6126 component
= MSI_RecordGetString(rec
, 2);
6127 comp
= get_loaded_component(package
, component
);
6129 return ERROR_SUCCESS
;
6131 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
&& comp
->ActionRequest
!= INSTALLSTATE_SOURCE
)
6133 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
6134 comp
->Action
= comp
->Installed
;
6135 return ERROR_SUCCESS
;
6137 comp
->Action
= comp
->ActionRequest
;
6139 sourcename
= MSI_RecordGetString(rec
, 3);
6140 options
= MSI_RecordGetInteger(rec
, 7);
6142 sourcedir
= msi_dup_property(package
, MSI_RecordGetString(rec
, 5));
6146 destdir
= msi_dup_property(package
, MSI_RecordGetString(rec
, 6));
6152 if (GetFileAttributesW(sourcedir
) == INVALID_FILE_ATTRIBUTES
)
6155 source
= strdupW(sourcedir
);
6161 size
= lstrlenW(sourcedir
) + lstrlenW(sourcename
) + 2;
6162 source
= msi_alloc(size
* sizeof(WCHAR
));
6166 lstrcpyW(source
, sourcedir
);
6167 if (source
[lstrlenW(source
) - 1] != '\\')
6168 lstrcatW(source
, szBackSlash
);
6169 lstrcatW(source
, sourcename
);
6172 wildcards
= strchrW(source
, '*') || strchrW(source
, '?');
6174 if (MSI_RecordIsNull(rec
, 4))
6178 destname
= strdupW(sourcename
);
6185 destname
= strdupW(MSI_RecordGetString(rec
, 4));
6187 reduce_to_longfilename(destname
);
6192 size
= lstrlenW(destname
);
6194 size
+= lstrlenW(destdir
) + 2;
6195 dest
= msi_alloc(size
* sizeof(WCHAR
));
6199 lstrcpyW(dest
, destdir
);
6200 if (dest
[lstrlenW(dest
) - 1] != '\\')
6201 lstrcatW(dest
, szBackSlash
);
6204 lstrcatW(dest
, destname
);
6206 if (GetFileAttributesW(destdir
) == INVALID_FILE_ATTRIBUTES
)
6208 ret
= CreateDirectoryW(destdir
, NULL
);
6211 WARN("CreateDirectory failed: %d\n", GetLastError());
6212 return ERROR_SUCCESS
;
6217 msi_move_file(source
, dest
, options
);
6219 move_files_wildcard(source
, dest
, options
);
6222 msi_free(sourcedir
);
6228 return ERROR_SUCCESS
;
6231 static UINT
ACTION_MoveFiles( MSIPACKAGE
*package
)
6236 static const WCHAR ExecSeqQuery
[] =
6237 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6238 '`','M','o','v','e','F','i','l','e','`',0};
6240 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
6241 if (rc
!= ERROR_SUCCESS
)
6242 return ERROR_SUCCESS
;
6244 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_MoveFiles
, package
);
6245 msiobj_release(&view
->hdr
);
6250 typedef struct tagMSIASSEMBLY
6253 MSICOMPONENT
*component
;
6254 MSIFEATURE
*feature
;
6262 static HRESULT (WINAPI
*pCreateAssemblyCache
)(IAssemblyCache
**ppAsmCache
,
6264 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR szDllName
, LPCWSTR szVersion
,
6265 LPVOID pvReserved
, HMODULE
*phModDll
);
6267 static BOOL
init_functionpointers(void)
6273 static const WCHAR szFusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
6275 hmscoree
= LoadLibraryA("mscoree.dll");
6278 WARN("mscoree.dll not available\n");
6282 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
6283 if (!pLoadLibraryShim
)
6285 WARN("LoadLibraryShim not available\n");
6286 FreeLibrary(hmscoree
);
6290 hr
= pLoadLibraryShim(szFusion
, NULL
, NULL
, &hfusion
);
6293 WARN("fusion.dll not available\n");
6294 FreeLibrary(hmscoree
);
6298 pCreateAssemblyCache
= (void *)GetProcAddress(hfusion
, "CreateAssemblyCache");
6300 FreeLibrary(hmscoree
);
6304 static UINT
install_assembly(MSIPACKAGE
*package
, MSIASSEMBLY
*assembly
,
6307 IAssemblyCache
*cache
;
6309 UINT r
= ERROR_FUNCTION_FAILED
;
6311 TRACE("installing assembly: %s\n", debugstr_w(path
));
6313 if (assembly
->feature
)
6314 msi_feature_set_state(package
, assembly
->feature
, INSTALLSTATE_LOCAL
);
6316 if (assembly
->manifest
)
6317 FIXME("Manifest unhandled\n");
6319 if (assembly
->application
)
6321 FIXME("Assembly should be privately installed\n");
6322 return ERROR_SUCCESS
;
6325 if (assembly
->attributes
== msidbAssemblyAttributesWin32
)
6327 FIXME("Win32 assemblies not handled\n");
6328 return ERROR_SUCCESS
;
6331 hr
= pCreateAssemblyCache(&cache
, 0);
6335 hr
= IAssemblyCache_InstallAssembly(cache
, 0, path
, NULL
);
6337 ERR("Failed to install assembly: %s %08x\n", debugstr_w(path
), hr
);
6342 IAssemblyCache_Release(cache
);
6346 typedef struct tagASSEMBLY_LIST
6348 MSIPACKAGE
*package
;
6349 IAssemblyCache
*cache
;
6350 struct list
*assemblies
;
6353 typedef struct tagASSEMBLY_NAME
6361 static UINT
parse_assembly_name(MSIRECORD
*rec
, LPVOID param
)
6363 ASSEMBLY_NAME
*asmname
= param
;
6364 LPCWSTR name
= MSI_RecordGetString(rec
, 2);
6365 LPWSTR val
= msi_dup_record_field(rec
, 3);
6367 static const WCHAR Name
[] = {'N','a','m','e',0};
6368 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
6369 static const WCHAR Culture
[] = {'C','u','l','t','u','r','e',0};
6370 static const WCHAR PublicKeyToken
[] = {
6371 'P','u','b','l','i','c','K','e','y','T','o','k','e','n',0};
6373 if (!strcmpiW(name
, Name
))
6374 asmname
->name
= val
;
6375 else if (!strcmpiW(name
, Version
))
6376 asmname
->version
= val
;
6377 else if (!strcmpiW(name
, Culture
))
6378 asmname
->culture
= val
;
6379 else if (!strcmpiW(name
, PublicKeyToken
))
6380 asmname
->pubkeytoken
= val
;
6384 return ERROR_SUCCESS
;
6387 static void append_str(LPWSTR
*str
, DWORD
*size
, LPCWSTR append
)
6391 *size
= lstrlenW(append
) + 1;
6392 *str
= msi_alloc((*size
) * sizeof(WCHAR
));
6393 lstrcpyW(*str
, append
);
6397 (*size
) += lstrlenW(append
);
6398 *str
= msi_realloc(*str
, (*size
) * sizeof(WCHAR
));
6399 lstrcatW(*str
, append
);
6402 static BOOL
check_assembly_installed(MSIDATABASE
*db
, IAssemblyCache
*cache
,
6405 ASSEMBLY_INFO asminfo
;
6413 static const WCHAR separator
[] = {',',' ',0};
6414 static const WCHAR Version
[] = {'V','e','r','s','i','o','n','=',0};
6415 static const WCHAR Culture
[] = {'C','u','l','t','u','r','e','=',0};
6416 static const WCHAR PublicKeyToken
[] = {
6417 'P','u','b','l','i','c','K','e','y','T','o','k','e','n','=',0};
6418 static const WCHAR query
[] = {
6419 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6420 '`','M','s','i','A','s','s','e','m','b','l','y','N','a','m','e','`',' ',
6421 'W','H','E','R','E',' ','`','C','o','m','p','o','n','e','n','t','_','`',
6422 '=','\'','%','s','\'',0};
6426 ZeroMemory(&name
, sizeof(ASSEMBLY_NAME
));
6427 ZeroMemory(&asminfo
, sizeof(ASSEMBLY_INFO
));
6429 r
= MSI_OpenQuery(db
, &view
, query
, comp
->Component
);
6430 if (r
!= ERROR_SUCCESS
)
6431 return ERROR_SUCCESS
;
6433 MSI_IterateRecords(view
, NULL
, parse_assembly_name
, &name
);
6434 msiobj_release(&view
->hdr
);
6438 ERR("No assembly name specified!\n");
6442 append_str(&disp
, &size
, name
.name
);
6446 append_str(&disp
, &size
, separator
);
6447 append_str(&disp
, &size
, Version
);
6448 append_str(&disp
, &size
, name
.version
);
6453 append_str(&disp
, &size
, separator
);
6454 append_str(&disp
, &size
, Culture
);
6455 append_str(&disp
, &size
, name
.culture
);
6458 if (name
.pubkeytoken
)
6460 append_str(&disp
, &size
, separator
);
6461 append_str(&disp
, &size
, PublicKeyToken
);
6462 append_str(&disp
, &size
, name
.pubkeytoken
);
6465 asminfo
.cbAssemblyInfo
= sizeof(ASSEMBLY_INFO
);
6466 IAssemblyCache_QueryAssemblyInfo(cache
, QUERYASMINFO_FLAG_VALIDATE
,
6468 found
= (asminfo
.dwAssemblyFlags
== ASSEMBLYINFO_FLAG_INSTALLED
);
6472 msi_free(name
.name
);
6473 msi_free(name
.version
);
6474 msi_free(name
.culture
);
6475 msi_free(name
.pubkeytoken
);
6480 static UINT
load_assembly(MSIRECORD
*rec
, LPVOID param
)
6482 ASSEMBLY_LIST
*list
= param
;
6483 MSIASSEMBLY
*assembly
;
6486 assembly
= msi_alloc_zero(sizeof(MSIASSEMBLY
));
6488 return ERROR_OUTOFMEMORY
;
6490 component
= MSI_RecordGetString(rec
, 1);
6491 assembly
->component
= get_loaded_component(list
->package
, component
);
6492 if (!assembly
->component
)
6493 return ERROR_SUCCESS
;
6495 if (assembly
->component
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
6496 assembly
->component
->ActionRequest
!= INSTALLSTATE_SOURCE
)
6498 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
6499 assembly
->component
->Action
= assembly
->component
->Installed
;
6500 return ERROR_SUCCESS
;
6502 assembly
->component
->Action
= assembly
->component
->ActionRequest
;
6504 assembly
->feature
= find_feature_by_name(list
->package
, MSI_RecordGetString(rec
, 2));
6505 assembly
->file
= msi_find_file(list
->package
, assembly
->component
->KeyPath
);
6507 if (!assembly
->file
)
6509 ERR("File %s not found\n", debugstr_w(assembly
->component
->KeyPath
));
6510 return ERROR_FUNCTION_FAILED
;
6513 assembly
->manifest
= strdupW(MSI_RecordGetString(rec
, 3));
6514 assembly
->application
= strdupW(MSI_RecordGetString(rec
, 4));
6515 assembly
->attributes
= MSI_RecordGetInteger(rec
, 5);
6517 if (assembly
->application
)
6520 DWORD size
= sizeof(version
)/sizeof(WCHAR
);
6522 /* FIXME: we should probably check the manifest file here */
6524 if (!MsiGetFileVersionW(assembly
->file
->TargetPath
, version
, &size
, NULL
, NULL
) &&
6525 (!assembly
->file
->Version
|| strcmpW(version
, assembly
->file
->Version
) >= 0))
6527 assembly
->installed
= TRUE
;
6531 assembly
->installed
= check_assembly_installed(list
->package
->db
,
6533 assembly
->component
);
6535 list_add_head(list
->assemblies
, &assembly
->entry
);
6536 return ERROR_SUCCESS
;
6539 static UINT
load_assemblies(MSIPACKAGE
*package
, struct list
*assemblies
)
6541 IAssemblyCache
*cache
= NULL
;
6547 static const WCHAR query
[] =
6548 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6549 '`','M','s','i','A','s','s','e','m','b','l','y','`',0};
6551 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
6552 if (r
!= ERROR_SUCCESS
)
6553 return ERROR_SUCCESS
;
6555 hr
= pCreateAssemblyCache(&cache
, 0);
6557 return ERROR_FUNCTION_FAILED
;
6559 list
.package
= package
;
6561 list
.assemblies
= assemblies
;
6563 r
= MSI_IterateRecords(view
, NULL
, load_assembly
, &list
);
6564 msiobj_release(&view
->hdr
);
6566 IAssemblyCache_Release(cache
);
6571 static void free_assemblies(struct list
*assemblies
)
6573 struct list
*item
, *cursor
;
6575 LIST_FOR_EACH_SAFE(item
, cursor
, assemblies
)
6577 MSIASSEMBLY
*assembly
= LIST_ENTRY(item
, MSIASSEMBLY
, entry
);
6579 list_remove(&assembly
->entry
);
6580 msi_free(assembly
->application
);
6581 msi_free(assembly
->manifest
);
6586 static BOOL
find_assembly(struct list
*assemblies
, LPCWSTR file
, MSIASSEMBLY
**out
)
6588 MSIASSEMBLY
*assembly
;
6590 LIST_FOR_EACH_ENTRY(assembly
, assemblies
, MSIASSEMBLY
, entry
)
6592 if (!lstrcmpW(assembly
->file
->File
, file
))
6602 static BOOL
installassembly_cb(MSIPACKAGE
*package
, LPCWSTR file
, DWORD action
,
6603 LPWSTR
*path
, DWORD
*attrs
, PVOID user
)
6605 MSIASSEMBLY
*assembly
;
6606 WCHAR temppath
[MAX_PATH
];
6607 struct list
*assemblies
= user
;
6610 if (!find_assembly(assemblies
, file
, &assembly
))
6613 GetTempPathW(MAX_PATH
, temppath
);
6614 PathAddBackslashW(temppath
);
6615 lstrcatW(temppath
, assembly
->file
->FileName
);
6617 if (action
== MSICABEXTRACT_BEGINEXTRACT
)
6619 if (assembly
->installed
)
6622 *path
= strdupW(temppath
);
6623 *attrs
= assembly
->file
->Attributes
;
6625 else if (action
== MSICABEXTRACT_FILEEXTRACTED
)
6627 assembly
->installed
= TRUE
;
6629 r
= install_assembly(package
, assembly
, temppath
);
6630 if (r
!= ERROR_SUCCESS
)
6631 ERR("Failed to install assembly\n");
6637 static UINT
ACTION_MsiPublishAssemblies( MSIPACKAGE
*package
)
6640 struct list assemblies
= LIST_INIT(assemblies
);
6641 MSIASSEMBLY
*assembly
;
6644 if (!init_functionpointers() || !pCreateAssemblyCache
)
6645 return ERROR_FUNCTION_FAILED
;
6647 r
= load_assemblies(package
, &assemblies
);
6648 if (r
!= ERROR_SUCCESS
)
6651 if (list_empty(&assemblies
))
6654 mi
= msi_alloc_zero(sizeof(MSIMEDIAINFO
));
6657 r
= ERROR_OUTOFMEMORY
;
6661 LIST_FOR_EACH_ENTRY(assembly
, &assemblies
, MSIASSEMBLY
, entry
)
6663 if (assembly
->installed
&& !mi
->is_continuous
)
6666 if (assembly
->file
->Sequence
> mi
->last_sequence
|| mi
->is_continuous
||
6667 (assembly
->file
->IsCompressed
&& !mi
->is_extracted
))
6671 r
= ready_media(package
, assembly
->file
, mi
);
6672 if (r
!= ERROR_SUCCESS
)
6674 ERR("Failed to ready media\n");
6679 data
.package
= package
;
6680 data
.cb
= installassembly_cb
;
6681 data
.user
= &assemblies
;
6683 if (assembly
->file
->IsCompressed
&&
6684 !msi_cabextract(package
, mi
, &data
))
6686 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi
->cabinet
));
6687 r
= ERROR_FUNCTION_FAILED
;
6692 if (!assembly
->file
->IsCompressed
)
6694 LPWSTR source
= resolve_file_source(package
, assembly
->file
);
6696 r
= install_assembly(package
, assembly
, source
);
6697 if (r
!= ERROR_SUCCESS
)
6698 ERR("Failed to install assembly\n");
6703 /* FIXME: write Installer assembly reg values */
6707 free_assemblies(&assemblies
);
6711 static UINT
ACTION_ValidateProductID( MSIPACKAGE
*package
)
6713 LPWSTR key
, template, id
;
6714 UINT r
= ERROR_SUCCESS
;
6716 id
= msi_dup_property( package
, szProductID
);
6720 return ERROR_SUCCESS
;
6722 template = msi_dup_property( package
, szPIDTemplate
);
6723 key
= msi_dup_property( package
, szPIDKEY
);
6725 if (key
&& template)
6727 FIXME( "partial stub: template %s key %s\n", debugstr_w(template), debugstr_w(key
) );
6728 r
= MSI_SetPropertyW( package
, szProductID
, key
);
6730 msi_free( template );
6735 static UINT
ACTION_ScheduleReboot( MSIPACKAGE
*package
)
6738 package
->need_reboot
= 1;
6739 return ERROR_SUCCESS
;
6742 static UINT
ACTION_AllocateRegistrySpace( MSIPACKAGE
*package
)
6744 static const WCHAR szAvailableFreeReg
[] =
6745 {'A','V','A','I','L','A','B','L','E','F','R','E','E','R','E','G',0};
6747 TRACE("%p %d kilobytes\n", package
, msi_get_property_int( package
, szAvailableFreeReg
, 0 ));
6748 return ERROR_SUCCESS
;
6751 static UINT
ACTION_DisableRollback( MSIPACKAGE
*package
)
6753 FIXME("%p\n", package
);
6754 return ERROR_SUCCESS
;
6757 static UINT
ACTION_InstallAdminPackage( MSIPACKAGE
*package
)
6759 FIXME("%p\n", package
);
6760 return ERROR_SUCCESS
;
6763 static UINT
msi_unimplemented_action_stub( MSIPACKAGE
*package
,
6764 LPCSTR action
, LPCWSTR table
)
6766 static const WCHAR query
[] = {
6767 'S','E','L','E','C','T',' ','*',' ',
6768 'F','R','O','M',' ','`','%','s','`',0 };
6769 MSIQUERY
*view
= NULL
;
6773 r
= MSI_OpenQuery( package
->db
, &view
, query
, table
);
6774 if (r
== ERROR_SUCCESS
)
6776 r
= MSI_IterateRecords(view
, &count
, NULL
, package
);
6777 msiobj_release(&view
->hdr
);
6781 FIXME("%s -> %u ignored %s table values\n",
6782 action
, count
, debugstr_w(table
));
6784 return ERROR_SUCCESS
;
6787 static UINT
ACTION_RemoveIniValues( MSIPACKAGE
*package
)
6789 static const WCHAR table
[] =
6790 {'R','e','m','o','v','e','I','n','i','F','i','l','e',0 };
6791 return msi_unimplemented_action_stub( package
, "RemoveIniValues", table
);
6794 static UINT
ACTION_PatchFiles( MSIPACKAGE
*package
)
6796 static const WCHAR table
[] = { 'P','a','t','c','h',0 };
6797 return msi_unimplemented_action_stub( package
, "PatchFiles", table
);
6800 static UINT
ACTION_BindImage( MSIPACKAGE
*package
)
6802 static const WCHAR table
[] = { 'B','i','n','d','I','m','a','g','e',0 };
6803 return msi_unimplemented_action_stub( package
, "BindImage", table
);
6806 static UINT
ACTION_IsolateComponents( MSIPACKAGE
*package
)
6808 static const WCHAR table
[] = {
6809 'I','s','o','l','a','t','e','d','C','o','m','p','o','n','e','n','t',0 };
6810 return msi_unimplemented_action_stub( package
, "IsolateComponents", table
);
6813 static UINT
ACTION_MigrateFeatureStates( MSIPACKAGE
*package
)
6815 static const WCHAR table
[] = { 'U','p','g','r','a','d','e',0 };
6816 return msi_unimplemented_action_stub( package
, "MigrateFeatureStates", table
);
6819 static UINT
ACTION_RemoveEnvironmentStrings( MSIPACKAGE
*package
)
6821 static const WCHAR table
[] = {
6822 'E','n','v','i','r','o','n','m','e','n','t',0 };
6823 return msi_unimplemented_action_stub( package
, "RemoveEnvironmentStrings", table
);
6826 static UINT
ACTION_MsiUnpublishAssemblies( MSIPACKAGE
*package
)
6828 static const WCHAR table
[] = {
6829 'M','s','i','A','s','s','e','m','b','l','y',0 };
6830 return msi_unimplemented_action_stub( package
, "MsiUnpublishAssemblies", table
);
6833 static UINT
ACTION_RMCCPSearch( MSIPACKAGE
*package
)
6835 static const WCHAR table
[] = { 'C','C','P','S','e','a','r','c','h',0 };
6836 return msi_unimplemented_action_stub( package
, "RMCCPSearch", table
);
6839 static UINT
ACTION_RegisterComPlus( MSIPACKAGE
*package
)
6841 static const WCHAR table
[] = { 'C','o','m','p','l','u','s',0 };
6842 return msi_unimplemented_action_stub( package
, "RegisterComPlus", table
);
6845 static UINT
ACTION_UnregisterComPlus( MSIPACKAGE
*package
)
6847 static const WCHAR table
[] = { 'C','o','m','p','l','u','s',0 };
6848 return msi_unimplemented_action_stub( package
, "UnregisterComPlus", table
);
6851 static UINT
ACTION_InstallSFPCatalogFile( MSIPACKAGE
*package
)
6853 static const WCHAR table
[] = { 'S','F','P','C','a','t','a','l','o','g',0 };
6854 return msi_unimplemented_action_stub( package
, "InstallSFPCatalogFile", table
);
6857 static UINT
ACTION_RemoveExistingProducts( MSIPACKAGE
*package
)
6859 static const WCHAR table
[] = { 'U','p','g','r','a','d','e',0 };
6860 return msi_unimplemented_action_stub( package
, "RemoveExistingProducts", table
);
6863 static UINT
ACTION_SetODBCFolders( MSIPACKAGE
*package
)
6865 static const WCHAR table
[] = { 'D','i','r','e','c','t','o','r','y',0 };
6866 return msi_unimplemented_action_stub( package
, "SetODBCFolders", table
);
6869 static UINT
ACTION_UnregisterClassInfo( MSIPACKAGE
*package
)
6871 static const WCHAR table
[] = { 'A','p','p','I','d',0 };
6872 return msi_unimplemented_action_stub( package
, "UnregisterClassInfo", table
);
6875 static UINT
ACTION_UnregisterExtensionInfo( MSIPACKAGE
*package
)
6877 static const WCHAR table
[] = { 'E','x','t','e','n','s','i','o','n',0 };
6878 return msi_unimplemented_action_stub( package
, "UnregisterExtensionInfo", table
);
6881 static UINT
ACTION_UnregisterMIMEInfo( MSIPACKAGE
*package
)
6883 static const WCHAR table
[] = { 'M','I','M','E',0 };
6884 return msi_unimplemented_action_stub( package
, "UnregisterMIMEInfo", table
);
6887 static UINT
ACTION_UnregisterProgIdInfo( MSIPACKAGE
*package
)
6889 static const WCHAR table
[] = { 'P','r','o','g','I','d',0 };
6890 return msi_unimplemented_action_stub( package
, "UnregisterProgIdInfo", table
);
6893 typedef UINT (*STANDARDACTIONHANDLER
)(MSIPACKAGE
*);
6897 const WCHAR
*action
;
6898 UINT (*handler
)(MSIPACKAGE
*);
6902 { szAllocateRegistrySpace
, ACTION_AllocateRegistrySpace
},
6903 { szAppSearch
, ACTION_AppSearch
},
6904 { szBindImage
, ACTION_BindImage
},
6905 { szCCPSearch
, ACTION_CCPSearch
},
6906 { szCostFinalize
, ACTION_CostFinalize
},
6907 { szCostInitialize
, ACTION_CostInitialize
},
6908 { szCreateFolders
, ACTION_CreateFolders
},
6909 { szCreateShortcuts
, ACTION_CreateShortcuts
},
6910 { szDeleteServices
, ACTION_DeleteServices
},
6911 { szDisableRollback
, ACTION_DisableRollback
},
6912 { szDuplicateFiles
, ACTION_DuplicateFiles
},
6913 { szExecuteAction
, ACTION_ExecuteAction
},
6914 { szFileCost
, ACTION_FileCost
},
6915 { szFindRelatedProducts
, ACTION_FindRelatedProducts
},
6916 { szForceReboot
, ACTION_ForceReboot
},
6917 { szInstallAdminPackage
, ACTION_InstallAdminPackage
},
6918 { szInstallExecute
, ACTION_InstallExecute
},
6919 { szInstallExecuteAgain
, ACTION_InstallExecute
},
6920 { szInstallFiles
, ACTION_InstallFiles
},
6921 { szInstallFinalize
, ACTION_InstallFinalize
},
6922 { szInstallInitialize
, ACTION_InstallInitialize
},
6923 { szInstallSFPCatalogFile
, ACTION_InstallSFPCatalogFile
},
6924 { szInstallValidate
, ACTION_InstallValidate
},
6925 { szIsolateComponents
, ACTION_IsolateComponents
},
6926 { szLaunchConditions
, ACTION_LaunchConditions
},
6927 { szMigrateFeatureStates
, ACTION_MigrateFeatureStates
},
6928 { szMoveFiles
, ACTION_MoveFiles
},
6929 { szMsiPublishAssemblies
, ACTION_MsiPublishAssemblies
},
6930 { szMsiUnpublishAssemblies
, ACTION_MsiUnpublishAssemblies
},
6931 { szInstallODBC
, ACTION_InstallODBC
},
6932 { szInstallServices
, ACTION_InstallServices
},
6933 { szPatchFiles
, ACTION_PatchFiles
},
6934 { szProcessComponents
, ACTION_ProcessComponents
},
6935 { szPublishComponents
, ACTION_PublishComponents
},
6936 { szPublishFeatures
, ACTION_PublishFeatures
},
6937 { szPublishProduct
, ACTION_PublishProduct
},
6938 { szRegisterClassInfo
, ACTION_RegisterClassInfo
},
6939 { szRegisterComPlus
, ACTION_RegisterComPlus
},
6940 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
},
6941 { szRegisterFonts
, ACTION_RegisterFonts
},
6942 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
},
6943 { szRegisterProduct
, ACTION_RegisterProduct
},
6944 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
},
6945 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
},
6946 { szRegisterUser
, ACTION_RegisterUser
},
6947 { szRemoveDuplicateFiles
, ACTION_RemoveDuplicateFiles
},
6948 { szRemoveEnvironmentStrings
, ACTION_RemoveEnvironmentStrings
},
6949 { szRemoveExistingProducts
, ACTION_RemoveExistingProducts
},
6950 { szRemoveFiles
, ACTION_RemoveFiles
},
6951 { szRemoveFolders
, ACTION_RemoveFolders
},
6952 { szRemoveIniValues
, ACTION_RemoveIniValues
},
6953 { szRemoveODBC
, ACTION_RemoveODBC
},
6954 { szRemoveRegistryValues
, ACTION_RemoveRegistryValues
},
6955 { szRemoveShortcuts
, ACTION_RemoveShortcuts
},
6956 { szResolveSource
, ACTION_ResolveSource
},
6957 { szRMCCPSearch
, ACTION_RMCCPSearch
},
6958 { szScheduleReboot
, ACTION_ScheduleReboot
},
6959 { szSelfRegModules
, ACTION_SelfRegModules
},
6960 { szSelfUnregModules
, ACTION_SelfUnregModules
},
6961 { szSetODBCFolders
, ACTION_SetODBCFolders
},
6962 { szStartServices
, ACTION_StartServices
},
6963 { szStopServices
, ACTION_StopServices
},
6964 { szUnpublishComponents
, ACTION_UnpublishComponents
},
6965 { szUnpublishFeatures
, ACTION_UnpublishFeatures
},
6966 { szUnregisterClassInfo
, ACTION_UnregisterClassInfo
},
6967 { szUnregisterComPlus
, ACTION_UnregisterComPlus
},
6968 { szUnregisterExtensionInfo
, ACTION_UnregisterExtensionInfo
},
6969 { szUnregisterFonts
, ACTION_UnregisterFonts
},
6970 { szUnregisterMIMEInfo
, ACTION_UnregisterMIMEInfo
},
6971 { szUnregisterProgIdInfo
, ACTION_UnregisterProgIdInfo
},
6972 { szUnregisterTypeLibraries
, ACTION_UnregisterTypeLibraries
},
6973 { szValidateProductID
, ACTION_ValidateProductID
},
6974 { szWriteEnvironmentStrings
, ACTION_WriteEnvironmentStrings
},
6975 { szWriteIniValues
, ACTION_WriteIniValues
},
6976 { szWriteRegistryValues
, ACTION_WriteRegistryValues
},
6980 static BOOL
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
,
6981 UINT
* rc
, BOOL force
)
6987 if (!run
&& !package
->script
->CurrentlyScripting
)
6992 if (strcmpW(action
,szInstallFinalize
) == 0 ||
6993 strcmpW(action
,szInstallExecute
) == 0 ||
6994 strcmpW(action
,szInstallExecuteAgain
) == 0)
6999 while (StandardActions
[i
].action
!= NULL
)
7001 if (strcmpW(StandardActions
[i
].action
, action
)==0)
7005 ui_actioninfo(package
, action
, TRUE
, 0);
7006 *rc
= schedule_action(package
,INSTALL_SCRIPT
,action
);
7007 ui_actioninfo(package
, action
, FALSE
, *rc
);
7011 ui_actionstart(package
, action
);
7012 if (StandardActions
[i
].handler
)
7014 *rc
= StandardActions
[i
].handler(package
);
7018 FIXME("unhandled standard action %s\n",debugstr_w(action
));
7019 *rc
= ERROR_SUCCESS
;
7030 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, UINT script
, BOOL force
)
7032 UINT rc
= ERROR_SUCCESS
;
7035 TRACE("Performing action (%s)\n", debugstr_w(action
));
7037 handled
= ACTION_HandleStandardAction(package
, action
, &rc
, force
);
7040 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, script
, force
);
7044 WARN("unhandled msi action %s\n", debugstr_w(action
));
7045 rc
= ERROR_FUNCTION_NOT_CALLED
;
7051 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
, UINT script
)
7053 UINT rc
= ERROR_SUCCESS
;
7054 BOOL handled
= FALSE
;
7056 TRACE("Performing action (%s)\n", debugstr_w(action
));
7058 handled
= ACTION_HandleStandardAction(package
, action
, &rc
,TRUE
);
7061 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, script
, FALSE
);
7063 if( !handled
&& ACTION_DialogBox(package
, action
) == ERROR_SUCCESS
)
7068 WARN("unhandled msi action %s\n", debugstr_w(action
));
7069 rc
= ERROR_FUNCTION_NOT_CALLED
;
7075 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
)
7077 UINT rc
= ERROR_SUCCESS
;
7080 static const WCHAR ExecSeqQuery
[] =
7081 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7082 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
7083 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
7084 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
7085 static const WCHAR UISeqQuery
[] =
7086 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7087 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
7088 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
7089 ' ', '=',' ','%','i',0};
7091 if (needs_ui_sequence(package
))
7092 row
= MSI_QueryGetRecord(package
->db
, UISeqQuery
, seq
);
7094 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, seq
);
7098 LPCWSTR action
, cond
;
7100 TRACE("Running the actions\n");
7102 /* check conditions */
7103 cond
= MSI_RecordGetString(row
, 2);
7105 /* this is a hack to skip errors in the condition code */
7106 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
7108 msiobj_release(&row
->hdr
);
7109 return ERROR_SUCCESS
;
7112 action
= MSI_RecordGetString(row
, 1);
7115 ERR("failed to fetch action\n");
7116 msiobj_release(&row
->hdr
);
7117 return ERROR_FUNCTION_FAILED
;
7120 if (needs_ui_sequence(package
))
7121 rc
= ACTION_PerformUIAction(package
, action
, -1);
7123 rc
= ACTION_PerformAction(package
, action
, -1, FALSE
);
7125 msiobj_release(&row
->hdr
);
7131 /****************************************************
7132 * TOP level entry points
7133 *****************************************************/
7135 UINT
MSI_InstallPackage( MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
7136 LPCWSTR szCommandLine
)
7141 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
7142 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
7144 MSI_SetPropertyW(package
, szAction
, szInstall
);
7146 package
->script
->InWhatSequence
= SEQUENCE_INSTALL
;
7153 dir
= strdupW(szPackagePath
);
7154 p
= strrchrW(dir
, '\\');
7158 file
= szPackagePath
+ (p
- dir
);
7163 dir
= msi_alloc(MAX_PATH
* sizeof(WCHAR
));
7164 GetCurrentDirectoryW(MAX_PATH
, dir
);
7165 lstrcatW(dir
, szBackSlash
);
7166 file
= szPackagePath
;
7169 msi_free( package
->PackagePath
);
7170 package
->PackagePath
= msi_alloc((lstrlenW(dir
) + lstrlenW(file
) + 1) * sizeof(WCHAR
));
7171 if (!package
->PackagePath
)
7174 return ERROR_OUTOFMEMORY
;
7177 lstrcpyW(package
->PackagePath
, dir
);
7178 lstrcatW(package
->PackagePath
, file
);
7181 msi_set_sourcedir_props(package
, FALSE
);
7184 msi_parse_command_line( package
, szCommandLine
, FALSE
);
7186 msi_apply_transforms( package
);
7187 msi_apply_patches( package
);
7189 if (!szCommandLine
&& msi_get_property_int( package
, szInstalled
, 0 ))
7191 TRACE("setting reinstall property\n");
7192 MSI_SetPropertyW( package
, szReinstall
, szAll
);
7195 /* properties may have been added by a transform */
7196 msi_clone_properties( package
);
7197 msi_set_context( package
);
7199 if (needs_ui_sequence( package
))
7201 package
->script
->InWhatSequence
|= SEQUENCE_UI
;
7202 rc
= ACTION_ProcessUISequence(package
);
7203 ui_exists
= ui_sequence_exists(package
);
7204 if (rc
== ERROR_SUCCESS
|| !ui_exists
)
7206 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
7207 rc
= ACTION_ProcessExecSequence(package
, ui_exists
);
7211 rc
= ACTION_ProcessExecSequence(package
, FALSE
);
7213 package
->script
->CurrentlyScripting
= FALSE
;
7215 /* process the ending type action */
7216 if (rc
== ERROR_SUCCESS
)
7217 ACTION_PerformActionSequence(package
, -1);
7218 else if (rc
== ERROR_INSTALL_USEREXIT
)
7219 ACTION_PerformActionSequence(package
, -2);
7220 else if (rc
== ERROR_INSTALL_SUSPEND
)
7221 ACTION_PerformActionSequence(package
, -4);
7223 ACTION_PerformActionSequence(package
, -3);
7225 /* finish up running custom actions */
7226 ACTION_FinishCustomActions(package
);
7228 if (rc
== ERROR_SUCCESS
&& package
->need_reboot
)
7229 return ERROR_SUCCESS_REBOOT_REQUIRED
;