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 szAllocateRegistrySpace
[] =
96 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y','S','p','a','c','e',0};
97 static const WCHAR szBindImage
[] =
98 {'B','i','n','d','I','m','a','g','e',0};
99 static const WCHAR szDeleteServices
[] =
100 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
101 static const WCHAR szDisableRollback
[] =
102 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
103 static const WCHAR szExecuteAction
[] =
104 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
105 static const WCHAR szInstallAdminPackage
[] =
106 {'I','n','s','t','a','l','l','A','d','m','i','n','P','a','c','k','a','g','e',0};
107 static const WCHAR szInstallSFPCatalogFile
[] =
108 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g','F','i','l','e',0};
109 static const WCHAR szIsolateComponents
[] =
110 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
111 static const WCHAR szMigrateFeatureStates
[] =
112 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e','S','t','a','t','e','s',0};
113 static const WCHAR szMsiPublishAssemblies
[] =
114 {'M','s','i','P','u','b','l','i','s','h','A','s','s','e','m','b','l','i','e','s',0};
115 static const WCHAR szMsiUnpublishAssemblies
[] =
116 {'M','s','i','U','n','p','u','b','l','i','s','h','A','s','s','e','m','b','l','i','e','s',0};
117 static const WCHAR szInstallODBC
[] =
118 {'I','n','s','t','a','l','l','O','D','B','C',0};
119 static const WCHAR szInstallServices
[] =
120 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
121 static const WCHAR szPatchFiles
[] =
122 {'P','a','t','c','h','F','i','l','e','s',0};
123 static const WCHAR szPublishComponents
[] =
124 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
125 static const WCHAR szRegisterComPlus
[] =
126 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
127 static const WCHAR szRegisterUser
[] =
128 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
129 static const WCHAR szRemoveEnvironmentStrings
[] =
130 {'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};
131 static const WCHAR szRemoveExistingProducts
[] =
132 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g','P','r','o','d','u','c','t','s',0};
133 static const WCHAR szRemoveFolders
[] =
134 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
135 static const WCHAR szRemoveIniValues
[] =
136 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
137 static const WCHAR szRemoveODBC
[] =
138 {'R','e','m','o','v','e','O','D','B','C',0};
139 static const WCHAR szRemoveRegistryValues
[] =
140 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
141 static const WCHAR szRemoveShortcuts
[] =
142 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
143 static const WCHAR szRMCCPSearch
[] =
144 {'R','M','C','C','P','S','e','a','r','c','h',0};
145 static const WCHAR szScheduleReboot
[] =
146 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
147 static const WCHAR szSelfUnregModules
[] =
148 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
149 static const WCHAR szSetODBCFolders
[] =
150 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
151 static const WCHAR szStartServices
[] =
152 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
153 static const WCHAR szStopServices
[] =
154 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
155 static const WCHAR szUnpublishComponents
[] =
156 {'U','n','p','u','b','l','i','s','h', 'C','o','m','p','o','n','e','n','t','s',0};
157 static const WCHAR szUnpublishFeatures
[] =
158 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
159 static const WCHAR szUnregisterComPlus
[] =
160 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
161 static const WCHAR szUnregisterTypeLibraries
[] =
162 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r','i','e','s',0};
163 static const WCHAR szValidateProductID
[] =
164 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
165 static const WCHAR szWriteEnvironmentStrings
[] =
166 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t','S','t','r','i','n','g','s',0};
168 /********************************************************
170 ********************************************************/
172 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
174 static const WCHAR Query_t
[] =
175 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
176 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
177 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
178 ' ','\'','%','s','\'',0};
181 row
= MSI_QueryGetRecord( package
->db
, Query_t
, action
);
184 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
185 msiobj_release(&row
->hdr
);
188 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
192 static const WCHAR template_s
[]=
193 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
195 static const WCHAR template_e
[]=
196 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
197 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
199 static const WCHAR format
[] =
200 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
204 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
206 sprintfW(message
,template_s
,timet
,action
);
208 sprintfW(message
,template_e
,timet
,action
,rc
);
210 row
= MSI_CreateRecord(1);
211 MSI_RecordSetStringW(row
,1,message
);
213 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
214 msiobj_release(&row
->hdr
);
217 UINT
msi_parse_command_line( MSIPACKAGE
*package
, LPCWSTR szCommandLine
,
223 LPWSTR prop
= NULL
, val
= NULL
;
226 return ERROR_SUCCESS
;
238 TRACE("Looking at %s\n",debugstr_w(ptr
));
240 ptr2
= strchrW(ptr
,'=');
243 ERR("command line contains unknown string : %s\n", debugstr_w(ptr
));
250 prop
= msi_alloc((len
+1)*sizeof(WCHAR
));
251 memcpy(prop
,ptr
,len
*sizeof(WCHAR
));
261 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
274 val
= msi_alloc((len
+1)*sizeof(WCHAR
));
275 memcpy(val
,ptr2
,len
*sizeof(WCHAR
));
278 if (lstrlenW(prop
) > 0)
280 UINT r
= msi_set_property( package
->db
, prop
, val
);
282 TRACE("Found commandline property (%s) = (%s)\n",
283 debugstr_w(prop
), debugstr_w(val
));
285 if (r
== ERROR_SUCCESS
&& !strcmpW( prop
, cszSourceDir
))
286 msi_reset_folders( package
, TRUE
);
292 return ERROR_SUCCESS
;
296 static LPWSTR
* msi_split_string( LPCWSTR str
, WCHAR sep
)
299 LPWSTR p
, *ret
= NULL
;
305 /* count the number of substrings */
306 for ( pc
= str
, count
= 0; pc
; count
++ )
308 pc
= strchrW( pc
, sep
);
313 /* allocate space for an array of substring pointers and the substrings */
314 ret
= msi_alloc( (count
+1) * sizeof (LPWSTR
) +
315 (lstrlenW(str
)+1) * sizeof(WCHAR
) );
319 /* copy the string and set the pointers */
320 p
= (LPWSTR
) &ret
[count
+1];
322 for( count
= 0; (ret
[count
] = p
); count
++ )
324 p
= strchrW( p
, sep
);
332 static UINT
msi_check_transform_applicable( MSIPACKAGE
*package
, IStorage
*patch
)
334 static const WCHAR szSystemLanguageID
[] =
335 { 'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0 };
337 LPWSTR prod_code
, patch_product
, langid
= NULL
, template = NULL
;
338 UINT ret
= ERROR_FUNCTION_FAILED
;
340 prod_code
= msi_dup_property( package
->db
, szProductCode
);
341 patch_product
= msi_get_suminfo_product( patch
);
343 TRACE("db = %s patch = %s\n", debugstr_w(prod_code
), debugstr_w(patch_product
));
345 if ( strstrW( patch_product
, prod_code
) )
350 si
= MSI_GetSummaryInformationW( patch
, 0 );
353 ERR("no summary information!\n");
357 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
360 ERR("no template property!\n");
361 msiobj_release( &si
->hdr
);
368 msiobj_release( &si
->hdr
);
372 langid
= msi_dup_property( package
->db
, szSystemLanguageID
);
375 msiobj_release( &si
->hdr
);
379 p
= strchrW( template, ';' );
380 if (p
&& (!strcmpW( p
+ 1, langid
) || !strcmpW( p
+ 1, szZero
)))
382 TRACE("applicable transform\n");
386 /* FIXME: check platform */
388 msiobj_release( &si
->hdr
);
392 msi_free( patch_product
);
393 msi_free( prod_code
);
394 msi_free( template );
400 static UINT
msi_apply_substorage_transform( MSIPACKAGE
*package
,
401 MSIDATABASE
*patch_db
, LPCWSTR name
)
403 UINT ret
= ERROR_FUNCTION_FAILED
;
404 IStorage
*stg
= NULL
;
407 TRACE("%p %s\n", package
, debugstr_w(name
) );
411 ERR("expected a colon in %s\n", debugstr_w(name
));
412 return ERROR_FUNCTION_FAILED
;
415 r
= IStorage_OpenStorage( patch_db
->storage
, name
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg
);
418 ret
= msi_check_transform_applicable( package
, stg
);
419 if (ret
== ERROR_SUCCESS
)
420 msi_table_apply_transform( package
->db
, stg
);
422 TRACE("substorage transform %s wasn't applicable\n", debugstr_w(name
));
423 IStorage_Release( stg
);
426 ERR("failed to open substorage %s\n", debugstr_w(name
));
428 return ERROR_SUCCESS
;
431 UINT
msi_check_patch_applicable( MSIPACKAGE
*package
, MSISUMMARYINFO
*si
)
433 LPWSTR guid_list
, *guids
, product_code
;
434 UINT i
, ret
= ERROR_FUNCTION_FAILED
;
436 product_code
= msi_dup_property( package
->db
, szProductCode
);
439 /* FIXME: the property ProductCode should be written into the DB somewhere */
440 ERR("no product code to check\n");
441 return ERROR_SUCCESS
;
444 guid_list
= msi_suminfo_dup_string( si
, PID_TEMPLATE
);
445 guids
= msi_split_string( guid_list
, ';' );
446 for ( i
= 0; guids
[i
] && ret
!= ERROR_SUCCESS
; i
++ )
448 if (!lstrcmpW( guids
[i
], product_code
))
452 msi_free( guid_list
);
453 msi_free( product_code
);
458 static UINT
msi_set_media_source_prop(MSIPACKAGE
*package
)
461 MSIRECORD
*rec
= NULL
;
466 static const WCHAR query
[] = {'S','E','L','E','C','T',' ',
467 '`','S','o','u','r','c','e','`',' ','F','R','O','M',' ',
468 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
469 '`','S','o','u','r','c','e','`',' ','I','S',' ',
470 'N','O','T',' ','N','U','L','L',0};
472 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
473 if (r
!= ERROR_SUCCESS
)
476 r
= MSI_ViewExecute(view
, 0);
477 if (r
!= ERROR_SUCCESS
)
480 if (MSI_ViewFetch(view
, &rec
) == ERROR_SUCCESS
)
482 prop
= MSI_RecordGetString(rec
, 1);
483 patch
= msi_dup_property(package
->db
, szPatch
);
484 msi_set_property(package
->db
, prop
, patch
);
489 if (rec
) msiobj_release(&rec
->hdr
);
490 msiobj_release(&view
->hdr
);
495 UINT
msi_parse_patch_summary( MSISUMMARYINFO
*si
, MSIPATCHINFO
**patch
)
498 UINT r
= ERROR_SUCCESS
;
501 pi
= msi_alloc_zero( sizeof(MSIPATCHINFO
) );
503 return ERROR_OUTOFMEMORY
;
505 pi
->patchcode
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
509 return ERROR_OUTOFMEMORY
;
515 msi_free( pi
->patchcode
);
517 return ERROR_PATCH_PACKAGE_INVALID
;
520 p
= strchrW( p
+ 1, '}' );
523 msi_free( pi
->patchcode
);
525 return ERROR_PATCH_PACKAGE_INVALID
;
530 FIXME("patch obsoletes %s\n", debugstr_w(p
+ 1));
534 TRACE("patch code %s\n", debugstr_w(pi
->patchcode
));
536 pi
->transforms
= msi_suminfo_dup_string( si
, PID_LASTAUTHOR
);
539 msi_free( pi
->patchcode
);
541 return ERROR_OUTOFMEMORY
;
548 UINT
msi_apply_patch_db( MSIPACKAGE
*package
, MSIDATABASE
*patch_db
, MSIPATCHINFO
*patch
)
550 UINT i
, r
= ERROR_SUCCESS
;
553 /* apply substorage transforms */
554 substorage
= msi_split_string( patch
->transforms
, ';' );
555 for (i
= 0; substorage
&& substorage
[i
] && r
== ERROR_SUCCESS
; i
++)
556 r
= msi_apply_substorage_transform( package
, patch_db
, substorage
[i
] );
558 msi_free( substorage
);
559 if (r
!= ERROR_SUCCESS
)
562 msi_set_media_source_prop( package
);
565 * There might be a CAB file in the patch package,
566 * so append it to the list of storages to search for streams.
568 append_storage_to_db( package
->db
, patch_db
->storage
);
570 patch
->state
= MSIPATCHSTATE_APPLIED
;
571 list_add_tail( &package
->patches
, &patch
->entry
);
572 return ERROR_SUCCESS
;
575 static UINT
msi_apply_patch_package( MSIPACKAGE
*package
, LPCWSTR file
)
577 static const WCHAR dotmsp
[] = {'.','m','s','p',0};
578 MSIDATABASE
*patch_db
= NULL
;
579 WCHAR localfile
[MAX_PATH
];
581 MSIPATCHINFO
*patch
= NULL
;
582 UINT r
= ERROR_SUCCESS
;
584 TRACE("%p %s\n", package
, debugstr_w( file
) );
586 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
+ MSIDBOPEN_PATCHFILE
, &patch_db
);
587 if ( r
!= ERROR_SUCCESS
)
589 ERR("failed to open patch collection %s\n", debugstr_w( file
) );
593 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
596 msiobj_release( &patch_db
->hdr
);
597 return ERROR_FUNCTION_FAILED
;
600 r
= msi_check_patch_applicable( package
, si
);
601 if (r
!= ERROR_SUCCESS
)
603 TRACE("patch not applicable\n");
608 r
= msi_parse_patch_summary( si
, &patch
);
609 if ( r
!= ERROR_SUCCESS
)
612 r
= msi_get_local_package_name( localfile
, dotmsp
);
613 if ( r
!= ERROR_SUCCESS
)
616 TRACE("copying to local package %s\n", debugstr_w(localfile
));
618 if (!CopyFileW( file
, localfile
, FALSE
))
620 ERR("Unable to copy package (%s -> %s) (error %u)\n",
621 debugstr_w(file
), debugstr_w(localfile
), GetLastError());
625 patch
->localfile
= strdupW( localfile
);
627 r
= msi_apply_patch_db( package
, patch_db
, patch
);
628 if ( r
!= ERROR_SUCCESS
)
629 WARN("patch failed to apply %u\n", r
);
632 msiobj_release( &si
->hdr
);
633 msiobj_release( &patch_db
->hdr
);
634 if (patch
&& r
!= ERROR_SUCCESS
)
636 if (patch
->localfile
)
637 DeleteFileW( patch
->localfile
);
639 msi_free( patch
->patchcode
);
640 msi_free( patch
->transforms
);
641 msi_free( patch
->localfile
);
647 /* get the PATCH property, and apply all the patches it specifies */
648 static UINT
msi_apply_patches( MSIPACKAGE
*package
)
650 LPWSTR patch_list
, *patches
;
651 UINT i
, r
= ERROR_SUCCESS
;
653 patch_list
= msi_dup_property( package
->db
, szPatch
);
655 TRACE("patches to be applied: %s\n", debugstr_w( patch_list
) );
657 patches
= msi_split_string( patch_list
, ';' );
658 for( i
=0; patches
&& patches
[i
] && r
== ERROR_SUCCESS
; i
++ )
659 r
= msi_apply_patch_package( package
, patches
[i
] );
662 msi_free( patch_list
);
667 static UINT
msi_apply_transforms( MSIPACKAGE
*package
)
669 static const WCHAR szTransforms
[] = {
670 'T','R','A','N','S','F','O','R','M','S',0 };
671 LPWSTR xform_list
, *xforms
;
672 UINT i
, r
= ERROR_SUCCESS
;
674 xform_list
= msi_dup_property( package
->db
, szTransforms
);
675 xforms
= msi_split_string( xform_list
, ';' );
677 for( i
=0; xforms
&& xforms
[i
] && r
== ERROR_SUCCESS
; i
++ )
679 if (xforms
[i
][0] == ':')
680 r
= msi_apply_substorage_transform( package
, package
->db
, xforms
[i
] );
682 r
= MSI_DatabaseApplyTransformW( package
->db
, xforms
[i
], 0 );
686 msi_free( xform_list
);
691 static BOOL
ui_sequence_exists( MSIPACKAGE
*package
)
696 static const WCHAR ExecSeqQuery
[] =
697 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
698 '`','I','n','s','t','a','l','l',
699 'U','I','S','e','q','u','e','n','c','e','`',
700 ' ','W','H','E','R','E',' ',
701 '`','S','e','q','u','e','n','c','e','`',' ',
702 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
703 '`','S','e','q','u','e','n','c','e','`',0};
705 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
706 if (rc
== ERROR_SUCCESS
)
708 msiobj_release(&view
->hdr
);
715 UINT
msi_set_sourcedir_props(MSIPACKAGE
*package
, BOOL replace
)
717 LPWSTR source
, check
;
719 if (msi_get_property_int( package
->db
, szInstalled
, 0 ))
723 MSIREG_OpenInstallProps( package
->ProductCode
, package
->Context
, NULL
, &hkey
, FALSE
);
724 source
= msi_reg_get_val_str( hkey
, INSTALLPROPERTY_INSTALLSOURCEW
);
732 db
= msi_dup_property( package
->db
, szOriginalDatabase
);
734 return ERROR_OUTOFMEMORY
;
736 p
= strrchrW( db
, '\\' );
739 p
= strrchrW( db
, '/' );
743 return ERROR_SUCCESS
;
748 source
= msi_alloc( len
* sizeof(WCHAR
) );
749 lstrcpynW( source
, db
, len
);
753 check
= msi_dup_property( package
->db
, cszSourceDir
);
754 if (!check
|| replace
)
756 UINT r
= msi_set_property( package
->db
, cszSourceDir
, source
);
757 if (r
== ERROR_SUCCESS
)
758 msi_reset_folders( package
, TRUE
);
762 check
= msi_dup_property( package
->db
, cszSOURCEDIR
);
763 if (!check
|| replace
)
764 msi_set_property( package
->db
, cszSOURCEDIR
, source
);
769 return ERROR_SUCCESS
;
772 static BOOL
needs_ui_sequence(MSIPACKAGE
*package
)
774 INT level
= msi_get_property_int(package
->db
, szUILevel
, 0);
775 return (level
& INSTALLUILEVEL_MASK
) >= INSTALLUILEVEL_REDUCED
;
778 UINT
msi_set_context(MSIPACKAGE
*package
)
782 package
->Context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
784 num
= msi_get_property_int(package
->db
, szAllUsers
, 0);
785 if (num
== 1 || num
== 2)
786 package
->Context
= MSIINSTALLCONTEXT_MACHINE
;
788 return ERROR_SUCCESS
;
791 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
794 LPCWSTR cond
, action
;
795 MSIPACKAGE
*package
= param
;
797 action
= MSI_RecordGetString(row
,1);
800 ERR("Error is retrieving action name\n");
801 return ERROR_FUNCTION_FAILED
;
804 /* check conditions */
805 cond
= MSI_RecordGetString(row
,2);
807 /* this is a hack to skip errors in the condition code */
808 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
810 TRACE("Skipping action: %s (condition is false)\n", debugstr_w(action
));
811 return ERROR_SUCCESS
;
814 if (needs_ui_sequence(package
))
815 rc
= ACTION_PerformUIAction(package
, action
, -1);
817 rc
= ACTION_PerformAction(package
, action
, -1);
819 msi_dialog_check_messages( NULL
);
821 if (package
->CurrentInstallState
!= ERROR_SUCCESS
)
822 rc
= package
->CurrentInstallState
;
824 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
827 if (rc
!= ERROR_SUCCESS
)
828 ERR("Execution halted, action %s returned %i\n", debugstr_w(action
), rc
);
833 UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR szTable
, INT iSequenceMode
)
837 static const WCHAR query
[] =
838 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
840 ' ','W','H','E','R','E',' ',
841 '`','S','e','q','u','e','n','c','e','`',' ',
842 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
843 '`','S','e','q','u','e','n','c','e','`',0};
845 TRACE("%p %s %i\n", package
, debugstr_w(szTable
), iSequenceMode
);
847 r
= MSI_OpenQuery( package
->db
, &view
, query
, szTable
);
848 if (r
== ERROR_SUCCESS
)
850 r
= MSI_IterateRecords( view
, NULL
, ITERATE_Actions
, package
);
851 msiobj_release(&view
->hdr
);
857 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
861 static const WCHAR ExecSeqQuery
[] =
862 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
863 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
864 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
865 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
866 'O','R','D','E','R',' ', 'B','Y',' ',
867 '`','S','e','q','u','e','n','c','e','`',0 };
868 static const WCHAR IVQuery
[] =
869 {'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
870 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
871 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
872 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
873 ' ','\'', 'I','n','s','t','a','l','l',
874 'V','a','l','i','d','a','t','e','\'', 0};
877 if (package
->script
->ExecuteSequenceRun
)
879 TRACE("Execute Sequence already Run\n");
880 return ERROR_SUCCESS
;
883 package
->script
->ExecuteSequenceRun
= TRUE
;
885 /* get the sequence number */
888 MSIRECORD
*row
= MSI_QueryGetRecord(package
->db
, IVQuery
);
890 return ERROR_FUNCTION_FAILED
;
891 seq
= MSI_RecordGetInteger(row
,1);
892 msiobj_release(&row
->hdr
);
895 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
896 if (rc
== ERROR_SUCCESS
)
898 TRACE("Running the actions\n");
900 msi_set_property(package
->db
, cszSourceDir
, NULL
);
902 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
903 msiobj_release(&view
->hdr
);
909 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
913 static const WCHAR ExecSeqQuery
[] =
914 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
915 '`','I','n','s','t','a','l','l',
916 'U','I','S','e','q','u','e','n','c','e','`',
917 ' ','W','H','E','R','E',' ',
918 '`','S','e','q','u','e','n','c','e','`',' ',
919 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
920 '`','S','e','q','u','e','n','c','e','`',0};
922 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
923 if (rc
== ERROR_SUCCESS
)
925 TRACE("Running the actions\n");
927 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
928 msiobj_release(&view
->hdr
);
934 /********************************************************
935 * ACTION helper functions and functions that perform the actions
936 *******************************************************/
937 static BOOL
ACTION_HandleCustomAction( MSIPACKAGE
* package
, LPCWSTR action
,
938 UINT
* rc
, UINT script
, BOOL force
)
943 arc
= ACTION_CustomAction(package
, action
, script
, force
);
945 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
954 * Actual Action Handlers
957 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
959 MSIPACKAGE
*package
= param
;
960 LPCWSTR dir
, component
;
966 component
= MSI_RecordGetString(row
, 2);
967 comp
= get_loaded_component(package
, component
);
969 return ERROR_SUCCESS
;
973 TRACE("component is disabled\n");
974 return ERROR_SUCCESS
;
977 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
979 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
980 comp
->Action
= comp
->Installed
;
981 return ERROR_SUCCESS
;
983 comp
->Action
= INSTALLSTATE_LOCAL
;
985 dir
= MSI_RecordGetString(row
,1);
988 ERR("Unable to get folder id\n");
989 return ERROR_SUCCESS
;
992 uirow
= MSI_CreateRecord(1);
993 MSI_RecordSetStringW(uirow
, 1, dir
);
994 ui_actiondata(package
, szCreateFolders
, uirow
);
995 msiobj_release(&uirow
->hdr
);
997 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,TRUE
,&folder
);
1000 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
1001 return ERROR_SUCCESS
;
1004 TRACE("Folder is %s\n",debugstr_w(full_path
));
1006 if (folder
->State
== 0)
1007 create_full_pathW(full_path
);
1011 msi_free(full_path
);
1012 return ERROR_SUCCESS
;
1015 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
1017 static const WCHAR ExecSeqQuery
[] =
1018 {'S','E','L','E','C','T',' ',
1019 '`','D','i','r','e','c','t','o','r','y','_','`',
1020 ' ','F','R','O','M',' ',
1021 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0 };
1025 /* create all the empty folders specified in the CreateFolder table */
1026 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1027 if (rc
!= ERROR_SUCCESS
)
1028 return ERROR_SUCCESS
;
1030 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
1031 msiobj_release(&view
->hdr
);
1036 static UINT
ITERATE_RemoveFolders( MSIRECORD
*row
, LPVOID param
)
1038 MSIPACKAGE
*package
= param
;
1039 LPCWSTR dir
, component
;
1045 component
= MSI_RecordGetString(row
, 2);
1046 comp
= get_loaded_component(package
, component
);
1048 return ERROR_SUCCESS
;
1052 TRACE("component is disabled\n");
1053 return ERROR_SUCCESS
;
1056 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
1058 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
1059 comp
->Action
= comp
->Installed
;
1060 return ERROR_SUCCESS
;
1062 comp
->Action
= INSTALLSTATE_ABSENT
;
1064 dir
= MSI_RecordGetString( row
, 1 );
1067 ERR("Unable to get folder id\n");
1068 return ERROR_SUCCESS
;
1071 full_path
= resolve_folder( package
, dir
, FALSE
, FALSE
, TRUE
, &folder
);
1074 ERR("Unable to resolve folder id %s\n", debugstr_w(dir
));
1075 return ERROR_SUCCESS
;
1078 TRACE("folder is %s\n", debugstr_w(full_path
));
1080 uirow
= MSI_CreateRecord( 1 );
1081 MSI_RecordSetStringW( uirow
, 1, dir
);
1082 ui_actiondata( package
, szRemoveFolders
, uirow
);
1083 msiobj_release( &uirow
->hdr
);
1085 RemoveDirectoryW( full_path
);
1088 msi_free( full_path
);
1089 return ERROR_SUCCESS
;
1092 static UINT
ACTION_RemoveFolders( MSIPACKAGE
*package
)
1094 static const WCHAR query
[] =
1095 {'S','E','L','E','C','T',' ', '`','D','i','r','e','c','t','o','r','y','_','`',
1096 ' ','F','R','O','M',' ', '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
1101 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1102 if (rc
!= ERROR_SUCCESS
)
1103 return ERROR_SUCCESS
;
1105 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveFolders
, package
);
1106 msiobj_release( &view
->hdr
);
1111 static UINT
load_component( MSIRECORD
*row
, LPVOID param
)
1113 MSIPACKAGE
*package
= param
;
1116 comp
= msi_alloc_zero( sizeof(MSICOMPONENT
) );
1118 return ERROR_FUNCTION_FAILED
;
1120 list_add_tail( &package
->components
, &comp
->entry
);
1122 /* fill in the data */
1123 comp
->Component
= msi_dup_record_field( row
, 1 );
1125 TRACE("Loading Component %s\n", debugstr_w(comp
->Component
));
1127 comp
->ComponentId
= msi_dup_record_field( row
, 2 );
1128 comp
->Directory
= msi_dup_record_field( row
, 3 );
1129 comp
->Attributes
= MSI_RecordGetInteger(row
,4);
1130 comp
->Condition
= msi_dup_record_field( row
, 5 );
1131 comp
->KeyPath
= msi_dup_record_field( row
, 6 );
1133 comp
->Installed
= INSTALLSTATE_UNKNOWN
;
1134 msi_component_set_state(package
, comp
, INSTALLSTATE_UNKNOWN
);
1136 return ERROR_SUCCESS
;
1139 static UINT
load_all_components( MSIPACKAGE
*package
)
1141 static const WCHAR query
[] = {
1142 'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1143 '`','C','o','m','p','o','n','e','n','t','`',0 };
1147 if (!list_empty(&package
->components
))
1148 return ERROR_SUCCESS
;
1150 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1151 if (r
!= ERROR_SUCCESS
)
1154 r
= MSI_IterateRecords(view
, NULL
, load_component
, package
);
1155 msiobj_release(&view
->hdr
);
1160 MSIPACKAGE
*package
;
1161 MSIFEATURE
*feature
;
1164 static UINT
add_feature_component( MSIFEATURE
*feature
, MSICOMPONENT
*comp
)
1168 cl
= msi_alloc( sizeof (*cl
) );
1170 return ERROR_NOT_ENOUGH_MEMORY
;
1171 cl
->component
= comp
;
1172 list_add_tail( &feature
->Components
, &cl
->entry
);
1174 return ERROR_SUCCESS
;
1177 static UINT
add_feature_child( MSIFEATURE
*parent
, MSIFEATURE
*child
)
1181 fl
= msi_alloc( sizeof(*fl
) );
1183 return ERROR_NOT_ENOUGH_MEMORY
;
1184 fl
->feature
= child
;
1185 list_add_tail( &parent
->Children
, &fl
->entry
);
1187 return ERROR_SUCCESS
;
1190 static UINT
iterate_load_featurecomponents(MSIRECORD
*row
, LPVOID param
)
1192 _ilfs
* ilfs
= param
;
1196 component
= MSI_RecordGetString(row
,1);
1198 /* check to see if the component is already loaded */
1199 comp
= get_loaded_component( ilfs
->package
, component
);
1202 ERR("unknown component %s\n", debugstr_w(component
));
1203 return ERROR_FUNCTION_FAILED
;
1206 add_feature_component( ilfs
->feature
, comp
);
1207 comp
->Enabled
= TRUE
;
1209 return ERROR_SUCCESS
;
1212 static MSIFEATURE
*find_feature_by_name( MSIPACKAGE
*package
, LPCWSTR name
)
1214 MSIFEATURE
*feature
;
1219 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1221 if ( !lstrcmpW( feature
->Feature
, name
) )
1228 static UINT
load_feature(MSIRECORD
* row
, LPVOID param
)
1230 MSIPACKAGE
* package
= param
;
1231 MSIFEATURE
* feature
;
1232 static const WCHAR Query1
[] =
1233 {'S','E','L','E','C','T',' ',
1234 '`','C','o','m','p','o','n','e','n','t','_','`',
1235 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1236 'C','o','m','p','o','n','e','n','t','s','`',' ',
1237 'W','H','E','R','E',' ',
1238 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1243 /* fill in the data */
1245 feature
= msi_alloc_zero( sizeof (MSIFEATURE
) );
1247 return ERROR_NOT_ENOUGH_MEMORY
;
1249 list_init( &feature
->Children
);
1250 list_init( &feature
->Components
);
1252 feature
->Feature
= msi_dup_record_field( row
, 1 );
1254 TRACE("Loading feature %s\n",debugstr_w(feature
->Feature
));
1256 feature
->Feature_Parent
= msi_dup_record_field( row
, 2 );
1257 feature
->Title
= msi_dup_record_field( row
, 3 );
1258 feature
->Description
= msi_dup_record_field( row
, 4 );
1260 if (!MSI_RecordIsNull(row
,5))
1261 feature
->Display
= MSI_RecordGetInteger(row
,5);
1263 feature
->Level
= MSI_RecordGetInteger(row
,6);
1264 feature
->Directory
= msi_dup_record_field( row
, 7 );
1265 feature
->Attributes
= MSI_RecordGetInteger(row
,8);
1267 feature
->Installed
= INSTALLSTATE_UNKNOWN
;
1268 msi_feature_set_state(package
, feature
, INSTALLSTATE_UNKNOWN
);
1270 list_add_tail( &package
->features
, &feature
->entry
);
1272 /* load feature components */
1274 rc
= MSI_OpenQuery( package
->db
, &view
, Query1
, feature
->Feature
);
1275 if (rc
!= ERROR_SUCCESS
)
1276 return ERROR_SUCCESS
;
1278 ilfs
.package
= package
;
1279 ilfs
.feature
= feature
;
1281 MSI_IterateRecords(view
, NULL
, iterate_load_featurecomponents
, &ilfs
);
1282 msiobj_release(&view
->hdr
);
1284 return ERROR_SUCCESS
;
1287 static UINT
find_feature_children(MSIRECORD
* row
, LPVOID param
)
1289 MSIPACKAGE
* package
= param
;
1290 MSIFEATURE
*parent
, *child
;
1292 child
= find_feature_by_name( package
, MSI_RecordGetString( row
, 1 ) );
1294 return ERROR_FUNCTION_FAILED
;
1296 if (!child
->Feature_Parent
)
1297 return ERROR_SUCCESS
;
1299 parent
= find_feature_by_name( package
, child
->Feature_Parent
);
1301 return ERROR_FUNCTION_FAILED
;
1303 add_feature_child( parent
, child
);
1304 return ERROR_SUCCESS
;
1307 static UINT
load_all_features( MSIPACKAGE
*package
)
1309 static const WCHAR query
[] = {
1310 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1311 '`','F','e','a','t','u','r','e','`',' ','O','R','D','E','R',
1312 ' ','B','Y',' ','`','D','i','s','p','l','a','y','`',0};
1316 if (!list_empty(&package
->features
))
1317 return ERROR_SUCCESS
;
1319 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1320 if (r
!= ERROR_SUCCESS
)
1323 r
= MSI_IterateRecords( view
, NULL
, load_feature
, package
);
1324 if (r
!= ERROR_SUCCESS
)
1327 r
= MSI_IterateRecords( view
, NULL
, find_feature_children
, package
);
1328 msiobj_release( &view
->hdr
);
1333 static LPWSTR
folder_split_path(LPWSTR p
, WCHAR ch
)
1344 static UINT
load_file_hash(MSIPACKAGE
*package
, MSIFILE
*file
)
1346 static const WCHAR query
[] = {
1347 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1348 '`','M','s','i','F','i','l','e','H','a','s','h','`',' ',
1349 'W','H','E','R','E',' ','`','F','i','l','e','_','`',' ','=',' ','\'','%','s','\'',0};
1350 MSIQUERY
*view
= NULL
;
1351 MSIRECORD
*row
= NULL
;
1354 TRACE("%s\n", debugstr_w(file
->File
));
1356 r
= MSI_OpenQuery(package
->db
, &view
, query
, file
->File
);
1357 if (r
!= ERROR_SUCCESS
)
1360 r
= MSI_ViewExecute(view
, NULL
);
1361 if (r
!= ERROR_SUCCESS
)
1364 r
= MSI_ViewFetch(view
, &row
);
1365 if (r
!= ERROR_SUCCESS
)
1368 file
->hash
.dwFileHashInfoSize
= sizeof(MSIFILEHASHINFO
);
1369 file
->hash
.dwData
[0] = MSI_RecordGetInteger(row
, 3);
1370 file
->hash
.dwData
[1] = MSI_RecordGetInteger(row
, 4);
1371 file
->hash
.dwData
[2] = MSI_RecordGetInteger(row
, 5);
1372 file
->hash
.dwData
[3] = MSI_RecordGetInteger(row
, 6);
1375 if (view
) msiobj_release(&view
->hdr
);
1376 if (row
) msiobj_release(&row
->hdr
);
1380 static UINT
load_file_disk_id( MSIPACKAGE
*package
, MSIFILE
*file
)
1383 static const WCHAR query
[] = {
1384 'S','E','L','E','C','T',' ','`','D','i','s','k','I','d','`',' ', 'F','R','O','M',' ',
1385 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
1386 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',' ','%','i',0};
1388 row
= MSI_QueryGetRecord( package
->db
, query
, file
->Sequence
);
1391 WARN("query failed\n");
1392 return ERROR_FUNCTION_FAILED
;
1395 file
->disk_id
= MSI_RecordGetInteger( row
, 1 );
1396 msiobj_release( &row
->hdr
);
1397 return ERROR_SUCCESS
;
1400 static UINT
load_file(MSIRECORD
*row
, LPVOID param
)
1402 MSIPACKAGE
* package
= param
;
1406 /* fill in the data */
1408 file
= msi_alloc_zero( sizeof (MSIFILE
) );
1410 return ERROR_NOT_ENOUGH_MEMORY
;
1412 file
->File
= msi_dup_record_field( row
, 1 );
1414 component
= MSI_RecordGetString( row
, 2 );
1415 file
->Component
= get_loaded_component( package
, component
);
1417 if (!file
->Component
)
1419 WARN("Component not found: %s\n", debugstr_w(component
));
1420 msi_free(file
->File
);
1422 return ERROR_SUCCESS
;
1425 file
->FileName
= msi_dup_record_field( row
, 3 );
1426 reduce_to_longfilename( file
->FileName
);
1428 file
->ShortName
= msi_dup_record_field( row
, 3 );
1429 file
->LongName
= strdupW( folder_split_path(file
->ShortName
, '|'));
1431 file
->FileSize
= MSI_RecordGetInteger( row
, 4 );
1432 file
->Version
= msi_dup_record_field( row
, 5 );
1433 file
->Language
= msi_dup_record_field( row
, 6 );
1434 file
->Attributes
= MSI_RecordGetInteger( row
, 7 );
1435 file
->Sequence
= MSI_RecordGetInteger( row
, 8 );
1437 file
->state
= msifs_invalid
;
1439 /* if the compressed bits are not set in the file attributes,
1440 * then read the information from the package word count property
1442 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1444 file
->IsCompressed
= FALSE
;
1446 else if (file
->Attributes
&
1447 (msidbFileAttributesCompressed
| msidbFileAttributesPatchAdded
))
1449 file
->IsCompressed
= TRUE
;
1451 else if (file
->Attributes
& msidbFileAttributesNoncompressed
)
1453 file
->IsCompressed
= FALSE
;
1457 file
->IsCompressed
= package
->WordCount
& msidbSumInfoSourceTypeCompressed
;
1460 load_file_hash(package
, file
);
1461 load_file_disk_id(package
, file
);
1463 TRACE("File Loaded (%s)\n",debugstr_w(file
->File
));
1465 list_add_tail( &package
->files
, &file
->entry
);
1467 return ERROR_SUCCESS
;
1470 static UINT
load_all_files(MSIPACKAGE
*package
)
1474 static const WCHAR Query
[] =
1475 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1476 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1477 '`','S','e','q','u','e','n','c','e','`', 0};
1479 if (!list_empty(&package
->files
))
1480 return ERROR_SUCCESS
;
1482 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1483 if (rc
!= ERROR_SUCCESS
)
1484 return ERROR_SUCCESS
;
1486 rc
= MSI_IterateRecords(view
, NULL
, load_file
, package
);
1487 msiobj_release(&view
->hdr
);
1489 return ERROR_SUCCESS
;
1492 static UINT
load_folder( MSIRECORD
*row
, LPVOID param
)
1494 MSIPACKAGE
*package
= param
;
1495 static WCHAR szEmpty
[] = { 0 };
1496 LPWSTR p
, tgt_short
, tgt_long
, src_short
, src_long
;
1499 folder
= msi_alloc_zero( sizeof (MSIFOLDER
) );
1501 return ERROR_NOT_ENOUGH_MEMORY
;
1503 folder
->Directory
= msi_dup_record_field( row
, 1 );
1505 TRACE("%s\n", debugstr_w(folder
->Directory
));
1507 p
= msi_dup_record_field(row
, 3);
1509 /* split src and target dir */
1511 src_short
= folder_split_path( p
, ':' );
1513 /* split the long and short paths */
1514 tgt_long
= folder_split_path( tgt_short
, '|' );
1515 src_long
= folder_split_path( src_short
, '|' );
1517 /* check for no-op dirs */
1518 if (!lstrcmpW(szDot
, tgt_short
))
1519 tgt_short
= szEmpty
;
1520 if (!lstrcmpW(szDot
, src_short
))
1521 src_short
= szEmpty
;
1524 tgt_long
= tgt_short
;
1527 src_short
= tgt_short
;
1528 src_long
= tgt_long
;
1532 src_long
= src_short
;
1534 /* FIXME: use the target short path too */
1535 folder
->TargetDefault
= strdupW(tgt_long
);
1536 folder
->SourceShortPath
= strdupW(src_short
);
1537 folder
->SourceLongPath
= strdupW(src_long
);
1540 TRACE("TargetDefault = %s\n",debugstr_w( folder
->TargetDefault
));
1541 TRACE("SourceLong = %s\n", debugstr_w( folder
->SourceLongPath
));
1542 TRACE("SourceShort = %s\n", debugstr_w( folder
->SourceShortPath
));
1544 folder
->Parent
= msi_dup_record_field( row
, 2 );
1546 folder
->Property
= msi_dup_property( package
->db
, folder
->Directory
);
1548 list_add_tail( &package
->folders
, &folder
->entry
);
1550 TRACE("returning %p\n", folder
);
1552 return ERROR_SUCCESS
;
1555 static UINT
load_all_folders( MSIPACKAGE
*package
)
1557 static const WCHAR query
[] = {
1558 'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1559 '`','D','i','r','e','c','t','o','r','y','`',0 };
1563 if (!list_empty(&package
->folders
))
1564 return ERROR_SUCCESS
;
1566 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1567 if (r
!= ERROR_SUCCESS
)
1570 r
= MSI_IterateRecords(view
, NULL
, load_folder
, package
);
1571 msiobj_release(&view
->hdr
);
1576 * I am not doing any of the costing functionality yet.
1577 * Mostly looking at doing the Component and Feature loading
1579 * The native MSI does A LOT of modification to tables here. Mostly adding
1580 * a lot of temporary columns to the Feature and Component tables.
1582 * note: Native msi also tracks the short filename. But I am only going to
1583 * track the long ones. Also looking at this directory table
1584 * it appears that the directory table does not get the parents
1585 * resolved base on property only based on their entries in the
1588 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1590 static const WCHAR szCosting
[] =
1591 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1593 msi_set_property( package
->db
, szCosting
, szZero
);
1594 msi_set_property( package
->db
, cszRootDrive
, c_colon
);
1596 load_all_folders( package
);
1597 load_all_components( package
);
1598 load_all_features( package
);
1599 load_all_files( package
);
1601 return ERROR_SUCCESS
;
1604 static UINT
execute_script(MSIPACKAGE
*package
, UINT script
)
1607 UINT rc
= ERROR_SUCCESS
;
1609 TRACE("Executing Script %i\n",script
);
1611 if (!package
->script
)
1613 ERR("no script!\n");
1614 return ERROR_FUNCTION_FAILED
;
1617 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
1620 action
= package
->script
->Actions
[script
][i
];
1621 ui_actionstart(package
, action
);
1622 TRACE("Executing Action (%s)\n",debugstr_w(action
));
1623 rc
= ACTION_PerformAction(package
, action
, script
);
1624 if (rc
!= ERROR_SUCCESS
)
1627 msi_free_action_script(package
, script
);
1631 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1633 return ERROR_SUCCESS
;
1636 static void ACTION_GetComponentInstallStates(MSIPACKAGE
*package
)
1642 state
= MsiQueryProductStateW(package
->ProductCode
);
1644 LIST_FOR_EACH_ENTRY(comp
, &package
->components
, MSICOMPONENT
, entry
)
1646 if (!comp
->ComponentId
)
1649 if (state
!= INSTALLSTATE_LOCAL
&& state
!= INSTALLSTATE_DEFAULT
)
1650 comp
->Installed
= INSTALLSTATE_ABSENT
;
1653 r
= MsiQueryComponentStateW(package
->ProductCode
, NULL
,
1654 package
->Context
, comp
->ComponentId
,
1656 if (r
!= ERROR_SUCCESS
)
1657 comp
->Installed
= INSTALLSTATE_ABSENT
;
1662 static void ACTION_GetFeatureInstallStates(MSIPACKAGE
*package
)
1664 MSIFEATURE
*feature
;
1667 state
= MsiQueryProductStateW(package
->ProductCode
);
1669 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1671 if (state
!= INSTALLSTATE_LOCAL
&& state
!= INSTALLSTATE_DEFAULT
)
1672 feature
->Installed
= INSTALLSTATE_ABSENT
;
1675 feature
->Installed
= MsiQueryFeatureStateW(package
->ProductCode
,
1681 static BOOL
process_state_property(MSIPACKAGE
* package
, int level
,
1682 LPCWSTR property
, INSTALLSTATE state
)
1685 MSIFEATURE
*feature
;
1687 override
= msi_dup_property( package
->db
, property
);
1691 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1693 if (lstrcmpW(property
, szRemove
) &&
1694 (feature
->Level
<= 0 || feature
->Level
> level
))
1697 if (!strcmpW(property
, szReinstall
)) state
= feature
->Installed
;
1699 if (strcmpiW(override
, szAll
)==0)
1700 msi_feature_set_state(package
, feature
, state
);
1703 LPWSTR ptr
= override
;
1704 LPWSTR ptr2
= strchrW(override
,',');
1708 int len
= ptr2
- ptr
;
1710 if ((ptr2
&& strlenW(feature
->Feature
) == len
&& !strncmpW(ptr
, feature
->Feature
, len
))
1711 || (!ptr2
&& !strcmpW(ptr
, feature
->Feature
)))
1713 msi_feature_set_state(package
, feature
, state
);
1719 ptr2
= strchrW(ptr
,',');
1731 static BOOL
process_overrides( MSIPACKAGE
*package
, int level
)
1733 static const WCHAR szAddLocal
[] =
1734 {'A','D','D','L','O','C','A','L',0};
1735 static const WCHAR szAddSource
[] =
1736 {'A','D','D','S','O','U','R','C','E',0};
1737 static const WCHAR szAdvertise
[] =
1738 {'A','D','V','E','R','T','I','S','E',0};
1741 /* all these activation/deactivation things happen in order and things
1742 * later on the list override things earlier on the list.
1744 * 0 INSTALLLEVEL processing
1757 ret
|= process_state_property( package
, level
, szAddLocal
, INSTALLSTATE_LOCAL
);
1758 ret
|= process_state_property( package
, level
, szRemove
, INSTALLSTATE_ABSENT
);
1759 ret
|= process_state_property( package
, level
, szAddSource
, INSTALLSTATE_SOURCE
);
1760 ret
|= process_state_property( package
, level
, szReinstall
, INSTALLSTATE_UNKNOWN
);
1761 ret
|= process_state_property( package
, level
, szAdvertise
, INSTALLSTATE_ADVERTISED
);
1764 msi_set_property( package
->db
, szPreselected
, szOne
);
1769 UINT
MSI_SetFeatureStates(MSIPACKAGE
*package
)
1772 static const WCHAR szlevel
[] =
1773 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
1774 MSICOMPONENT
* component
;
1775 MSIFEATURE
*feature
;
1777 TRACE("Checking Install Level\n");
1779 level
= msi_get_property_int(package
->db
, szlevel
, 1);
1781 if (!msi_get_property_int( package
->db
, szPreselected
, 0 ))
1783 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1785 BOOL feature_state
= ((feature
->Level
> 0) &&
1786 (feature
->Level
<= level
));
1788 if (feature_state
&& feature
->ActionRequest
== INSTALLSTATE_UNKNOWN
)
1790 if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1791 msi_feature_set_state(package
, feature
, INSTALLSTATE_SOURCE
);
1792 else if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1793 msi_feature_set_state(package
, feature
, INSTALLSTATE_ADVERTISED
);
1795 msi_feature_set_state(package
, feature
, INSTALLSTATE_LOCAL
);
1799 /* disable child features of unselected parent features */
1800 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1804 if (feature
->Level
> 0 && feature
->Level
<= level
)
1807 LIST_FOR_EACH_ENTRY( fl
, &feature
->Children
, FeatureList
, entry
)
1808 msi_feature_set_state(package
, fl
->feature
, INSTALLSTATE_UNKNOWN
);
1813 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1815 BOOL selected
= feature
->Level
> 0 && feature
->Level
<= level
;
1817 if (selected
&& feature
->ActionRequest
== INSTALLSTATE_UNKNOWN
)
1819 msi_feature_set_state(package
, feature
, feature
->Installed
);
1825 * now we want to enable or disable components based on feature
1827 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1831 TRACE("Examining Feature %s (Level %d Installed %d Request %d Action %d)\n",
1832 debugstr_w(feature
->Feature
), feature
->Level
, feature
->Installed
,
1833 feature
->ActionRequest
, feature
->Action
);
1835 if (!feature
->Level
)
1838 /* features with components that have compressed files are made local */
1839 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1841 if (cl
->component
->ForceLocalState
&&
1842 feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1844 msi_feature_set_state(package
, feature
, INSTALLSTATE_LOCAL
);
1849 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1851 component
= cl
->component
;
1853 switch (feature
->ActionRequest
)
1855 case INSTALLSTATE_ABSENT
:
1856 component
->anyAbsent
= 1;
1858 case INSTALLSTATE_ADVERTISED
:
1859 component
->hasAdvertiseFeature
= 1;
1861 case INSTALLSTATE_SOURCE
:
1862 component
->hasSourceFeature
= 1;
1864 case INSTALLSTATE_LOCAL
:
1865 component
->hasLocalFeature
= 1;
1867 case INSTALLSTATE_DEFAULT
:
1868 if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1869 component
->hasAdvertiseFeature
= 1;
1870 else if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1871 component
->hasSourceFeature
= 1;
1873 component
->hasLocalFeature
= 1;
1881 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1883 /* check if it's local or source */
1884 if (!(component
->Attributes
& msidbComponentAttributesOptional
) &&
1885 (component
->hasLocalFeature
|| component
->hasSourceFeature
))
1887 if ((component
->Attributes
& msidbComponentAttributesSourceOnly
) &&
1888 !component
->ForceLocalState
)
1889 msi_component_set_state(package
, component
, INSTALLSTATE_SOURCE
);
1891 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
1895 /* if any feature is local, the component must be local too */
1896 if (component
->hasLocalFeature
)
1898 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
1902 if (component
->hasSourceFeature
)
1904 msi_component_set_state(package
, component
, INSTALLSTATE_SOURCE
);
1908 if (component
->hasAdvertiseFeature
)
1910 msi_component_set_state(package
, component
, INSTALLSTATE_ADVERTISED
);
1914 TRACE("nobody wants component %s\n", debugstr_w(component
->Component
));
1915 if (component
->anyAbsent
)
1916 msi_component_set_state(package
, component
, INSTALLSTATE_ABSENT
);
1919 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1921 if (component
->ActionRequest
== INSTALLSTATE_DEFAULT
)
1923 TRACE("%s was default, setting to local\n", debugstr_w(component
->Component
));
1924 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
1927 TRACE("Result: Component %s (Installed %d Request %d Action %d)\n",
1928 debugstr_w(component
->Component
), component
->Installed
, component
->ActionRequest
, component
->Action
);
1931 return ERROR_SUCCESS
;
1934 static UINT
ITERATE_CostFinalizeDirectories(MSIRECORD
*row
, LPVOID param
)
1936 MSIPACKAGE
*package
= param
;
1941 name
= MSI_RecordGetString(row
,1);
1943 f
= get_loaded_folder(package
, name
);
1944 if (!f
) return ERROR_SUCCESS
;
1946 /* reset the ResolvedTarget */
1947 msi_free(f
->ResolvedTarget
);
1948 f
->ResolvedTarget
= NULL
;
1950 /* This helper function now does ALL the work */
1951 TRACE("Dir %s ...\n",debugstr_w(name
));
1952 path
= resolve_folder(package
,name
,FALSE
,TRUE
,TRUE
,NULL
);
1953 TRACE("resolves to %s\n",debugstr_w(path
));
1956 return ERROR_SUCCESS
;
1959 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1961 MSIPACKAGE
*package
= param
;
1963 MSIFEATURE
*feature
;
1965 name
= MSI_RecordGetString( row
, 1 );
1967 feature
= get_loaded_feature( package
, name
);
1969 ERR("FAILED to find loaded feature %s\n",debugstr_w(name
));
1973 Condition
= MSI_RecordGetString(row
,3);
1975 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
1977 int level
= MSI_RecordGetInteger(row
,2);
1978 TRACE("Resetting feature %s to level %i\n", debugstr_w(name
), level
);
1979 feature
->Level
= level
;
1982 return ERROR_SUCCESS
;
1985 VS_FIXEDFILEINFO
*msi_get_disk_file_version( LPCWSTR filename
)
1987 static const WCHAR name
[] = {'\\',0};
1988 VS_FIXEDFILEINFO
*ptr
, *ret
;
1990 DWORD versize
, handle
;
1993 TRACE("%s\n", debugstr_w(filename
));
1995 versize
= GetFileVersionInfoSizeW( filename
, &handle
);
1999 version
= msi_alloc( versize
);
2003 GetFileVersionInfoW( filename
, 0, versize
, version
);
2005 if (!VerQueryValueW( version
, name
, (LPVOID
*)&ptr
, &sz
))
2007 msi_free( version
);
2011 ret
= msi_alloc( sz
);
2012 memcpy( ret
, ptr
, sz
);
2014 msi_free( version
);
2018 int msi_compare_file_versions( VS_FIXEDFILEINFO
*fi
, const WCHAR
*version
)
2022 msi_parse_version_string( version
, &ms
, &ls
);
2024 if (fi
->dwFileVersionMS
> ms
) return 1;
2025 else if (fi
->dwFileVersionMS
< ms
) return -1;
2026 else if (fi
->dwFileVersionLS
> ls
) return 1;
2027 else if (fi
->dwFileVersionLS
< ls
) return -1;
2031 static DWORD
get_disk_file_size( LPCWSTR filename
)
2036 TRACE("%s\n", debugstr_w(filename
));
2038 file
= CreateFileW( filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
2039 if (file
== INVALID_HANDLE_VALUE
)
2040 return INVALID_FILE_SIZE
;
2042 size
= GetFileSize( file
, NULL
);
2043 CloseHandle( file
);
2047 static BOOL
hash_matches( MSIFILE
*file
)
2050 MSIFILEHASHINFO hash
;
2052 hash
.dwFileHashInfoSize
= sizeof(MSIFILEHASHINFO
);
2053 r
= MsiGetFileHashW( file
->TargetPath
, 0, &hash
);
2054 if (r
!= ERROR_SUCCESS
)
2057 return !memcmp( &hash
, &file
->hash
, sizeof(MSIFILEHASHINFO
) );
2060 static UINT
set_file_install_states( MSIPACKAGE
*package
)
2062 VS_FIXEDFILEINFO
*file_version
;
2065 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2067 MSICOMPONENT
* comp
= file
->Component
;
2074 if (file
->IsCompressed
)
2075 comp
->ForceLocalState
= TRUE
;
2077 /* calculate target */
2078 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, TRUE
, NULL
);
2079 msi_free(file
->TargetPath
);
2081 TRACE("file %s is named %s\n", debugstr_w(file
->File
), debugstr_w(file
->FileName
));
2083 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
2086 TRACE("file %s resolves to %s\n", debugstr_w(file
->File
), debugstr_w(file
->TargetPath
));
2088 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
2090 file
->state
= msifs_missing
;
2091 comp
->Cost
+= file
->FileSize
;
2094 if (file
->Version
&& (file_version
= msi_get_disk_file_version( file
->TargetPath
)))
2096 TRACE("new %s old %u.%u.%u.%u\n", debugstr_w(file
->Version
),
2097 HIWORD(file_version
->dwFileVersionMS
),
2098 LOWORD(file_version
->dwFileVersionMS
),
2099 HIWORD(file_version
->dwFileVersionLS
),
2100 LOWORD(file_version
->dwFileVersionLS
));
2102 if (msi_compare_file_versions( file_version
, file
->Version
) < 0)
2104 file
->state
= msifs_overwrite
;
2105 comp
->Cost
+= file
->FileSize
;
2109 TRACE("Destination file version equal or greater, not overwriting\n");
2110 file
->state
= msifs_present
;
2112 msi_free( file_version
);
2115 if ((file_size
= get_disk_file_size( file
->TargetPath
)) != file
->FileSize
)
2117 file
->state
= msifs_overwrite
;
2118 comp
->Cost
+= file
->FileSize
- file_size
;
2121 if (file
->hash
.dwFileHashInfoSize
&& hash_matches( file
))
2123 TRACE("File hashes match, not overwriting\n");
2124 file
->state
= msifs_present
;
2127 file
->state
= msifs_overwrite
;
2128 comp
->Cost
+= file
->FileSize
- file_size
;
2131 return ERROR_SUCCESS
;
2135 * A lot is done in this function aside from just the costing.
2136 * The costing needs to be implemented at some point but for now I am going
2137 * to focus on the directory building
2140 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2142 static const WCHAR ExecSeqQuery
[] =
2143 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2144 '`','D','i','r','e','c','t','o','r','y','`',0};
2145 static const WCHAR ConditionQuery
[] =
2146 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2147 '`','C','o','n','d','i','t','i','o','n','`',0};
2148 static const WCHAR szCosting
[] =
2149 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2150 static const WCHAR szlevel
[] =
2151 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2152 static const WCHAR szOutOfDiskSpace
[] =
2153 {'O','u','t','O','f','D','i','s','k','S','p','a','c','e',0};
2155 UINT rc
= ERROR_SUCCESS
;
2159 TRACE("Building Directory properties\n");
2161 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2162 if (rc
== ERROR_SUCCESS
)
2164 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CostFinalizeDirectories
,
2166 msiobj_release(&view
->hdr
);
2169 /* read components states from the registry */
2170 ACTION_GetComponentInstallStates(package
);
2171 ACTION_GetFeatureInstallStates(package
);
2173 TRACE("Calculating file install states\n");
2174 set_file_install_states( package
);
2176 if (!process_overrides( package
, msi_get_property_int( package
->db
, szlevel
, 1 ) ))
2178 TRACE("Evaluating feature conditions\n");
2180 rc
= MSI_DatabaseOpenViewW( package
->db
, ConditionQuery
, &view
);
2181 if (rc
== ERROR_SUCCESS
)
2183 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_CostFinalizeConditions
, package
);
2184 msiobj_release( &view
->hdr
);
2187 TRACE("Evaluating component conditions\n");
2189 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2191 if (MSI_EvaluateConditionW( package
, comp
->Condition
) == MSICONDITION_FALSE
)
2193 TRACE("Disabling component %s\n", debugstr_w(comp
->Component
));
2194 comp
->Enabled
= FALSE
;
2197 comp
->Enabled
= TRUE
;
2200 msi_set_property( package
->db
, szCosting
, szOne
);
2201 /* set default run level if not set */
2202 level
= msi_dup_property( package
->db
, szlevel
);
2204 msi_set_property( package
->db
, szlevel
, szOne
);
2207 /* FIXME: check volume disk space */
2208 msi_set_property( package
->db
, szOutOfDiskSpace
, szZero
);
2210 return MSI_SetFeatureStates(package
);
2213 /* OK this value is "interpreted" and then formatted based on the
2214 first few characters */
2215 static LPSTR
parse_value(MSIPACKAGE
*package
, LPCWSTR value
, DWORD
*type
,
2220 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
2226 LPWSTR deformated
= NULL
;
2229 deformat_string(package
, &value
[2], &deformated
);
2231 /* binary value type */
2235 *size
= (strlenW(ptr
)/2)+1;
2237 *size
= strlenW(ptr
)/2;
2239 data
= msi_alloc(*size
);
2245 /* if uneven pad with a zero in front */
2251 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2253 TRACE("Uneven byte count\n");
2261 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2264 msi_free(deformated
);
2266 TRACE("Data %i bytes(%i)\n",*size
,count
);
2273 deformat_string(package
, &value
[1], &deformated
);
2276 *size
= sizeof(DWORD
);
2277 data
= msi_alloc(*size
);
2283 if ( (*p
< '0') || (*p
> '9') )
2289 if (deformated
[0] == '-')
2292 TRACE("DWORD %i\n",*(LPDWORD
)data
);
2294 msi_free(deformated
);
2299 static const WCHAR szMulti
[] = {'[','~',']',0};
2308 *type
=REG_EXPAND_SZ
;
2316 if (strstrW(value
,szMulti
))
2317 *type
= REG_MULTI_SZ
;
2319 /* remove initial delimiter */
2320 if (!strncmpW(value
, szMulti
, 3))
2323 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
2325 /* add double NULL terminator */
2326 if (*type
== REG_MULTI_SZ
)
2328 *size
+= 2 * sizeof(WCHAR
); /* two NULL terminators */
2329 data
= msi_realloc_zero(data
, *size
);
2335 static const WCHAR
*get_root_key( MSIPACKAGE
*package
, INT root
, HKEY
*root_key
)
2342 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ))
2344 *root_key
= HKEY_LOCAL_MACHINE
;
2349 *root_key
= HKEY_CURRENT_USER
;
2354 *root_key
= HKEY_CLASSES_ROOT
;
2358 *root_key
= HKEY_CURRENT_USER
;
2362 *root_key
= HKEY_LOCAL_MACHINE
;
2366 *root_key
= HKEY_USERS
;
2370 ERR("Unknown root %i\n", root
);
2377 static WCHAR
*get_keypath( MSIPACKAGE
*package
, HKEY root
, const WCHAR
*path
)
2379 static const WCHAR prefixW
[] = {'S','O','F','T','W','A','R','E','\\'};
2380 static const UINT len
= sizeof(prefixW
) / sizeof(prefixW
[0]);
2382 if (is_64bit
&& package
->platform
== PLATFORM_INTEL
&&
2383 root
== HKEY_LOCAL_MACHINE
&& !strncmpiW( path
, prefixW
, len
))
2388 size
= (strlenW( path
) + strlenW( szWow6432Node
) + 1) * sizeof(WCHAR
);
2389 path_32node
= msi_alloc( size
);
2393 memcpy( path_32node
, path
, len
* sizeof(WCHAR
) );
2394 path_32node
[len
] = 0;
2395 strcatW( path_32node
, szWow6432Node
);
2396 strcatW( path_32node
, szBackSlash
);
2397 strcatW( path_32node
, path
+ len
);
2401 return strdupW( path
);
2404 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
2406 MSIPACKAGE
*package
= param
;
2407 LPSTR value_data
= NULL
;
2408 HKEY root_key
, hkey
;
2410 LPWSTR deformated
, uikey
, keypath
;
2411 LPCWSTR szRoot
, component
, name
, key
, value
;
2415 BOOL check_first
= FALSE
;
2418 ui_progress(package
,2,0,0,0);
2420 component
= MSI_RecordGetString(row
, 6);
2421 comp
= get_loaded_component(package
,component
);
2423 return ERROR_SUCCESS
;
2427 TRACE("component is disabled\n");
2428 return ERROR_SUCCESS
;
2431 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
2433 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
2434 comp
->Action
= comp
->Installed
;
2435 return ERROR_SUCCESS
;
2437 comp
->Action
= INSTALLSTATE_LOCAL
;
2439 name
= MSI_RecordGetString(row
, 4);
2440 if( MSI_RecordIsNull(row
,5) && name
)
2442 /* null values can have special meanings */
2443 if (name
[0]=='-' && name
[1] == 0)
2444 return ERROR_SUCCESS
;
2445 else if ((name
[0]=='+' && name
[1] == 0) ||
2446 (name
[0] == '*' && name
[1] == 0))
2451 root
= MSI_RecordGetInteger(row
,2);
2452 key
= MSI_RecordGetString(row
, 3);
2454 szRoot
= get_root_key( package
, root
, &root_key
);
2456 return ERROR_SUCCESS
;
2458 deformat_string(package
, key
, &deformated
);
2459 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
2460 uikey
= msi_alloc(size
*sizeof(WCHAR
));
2461 strcpyW(uikey
,szRoot
);
2462 strcatW(uikey
,deformated
);
2464 keypath
= get_keypath( package
, root_key
, deformated
);
2465 msi_free( deformated
);
2466 if (RegCreateKeyW( root_key
, keypath
, &hkey
))
2468 ERR("Could not create key %s\n", debugstr_w(keypath
));
2470 return ERROR_SUCCESS
;
2473 value
= MSI_RecordGetString(row
,5);
2475 value_data
= parse_value(package
, value
, &type
, &size
);
2478 value_data
= (LPSTR
)strdupW(szEmpty
);
2479 size
= sizeof(szEmpty
);
2483 deformat_string(package
, name
, &deformated
);
2487 TRACE("Setting value %s of %s\n",debugstr_w(deformated
),
2489 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
)value_data
, size
);
2494 rc
= RegQueryValueExW(hkey
, deformated
, NULL
, NULL
, NULL
, &sz
);
2495 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
2497 TRACE("value %s of %s checked already exists\n",
2498 debugstr_w(deformated
), debugstr_w(uikey
));
2502 TRACE("Checked and setting value %s of %s\n",
2503 debugstr_w(deformated
), debugstr_w(uikey
));
2504 if (deformated
|| size
)
2505 RegSetValueExW(hkey
, deformated
, 0, type
, (LPBYTE
) value_data
, size
);
2510 uirow
= MSI_CreateRecord(3);
2511 MSI_RecordSetStringW(uirow
,2,deformated
);
2512 MSI_RecordSetStringW(uirow
,1,uikey
);
2513 if (type
== REG_SZ
|| type
== REG_EXPAND_SZ
)
2514 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2515 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2516 msiobj_release( &uirow
->hdr
);
2518 msi_free(value_data
);
2519 msi_free(deformated
);
2522 return ERROR_SUCCESS
;
2525 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2529 static const WCHAR ExecSeqQuery
[] =
2530 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2531 '`','R','e','g','i','s','t','r','y','`',0 };
2533 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2534 if (rc
!= ERROR_SUCCESS
)
2535 return ERROR_SUCCESS
;
2537 /* increment progress bar each time action data is sent */
2538 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
2540 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2542 msiobj_release(&view
->hdr
);
2546 static void delete_reg_key_or_value( HKEY hkey_root
, LPCWSTR key
, LPCWSTR value
, BOOL delete_key
)
2550 DWORD num_subkeys
, num_values
;
2554 if ((res
= RegDeleteTreeW( hkey_root
, key
)))
2556 WARN("Failed to delete key %s (%d)\n", debugstr_w(key
), res
);
2561 if (!(res
= RegOpenKeyW( hkey_root
, key
, &hkey
)))
2563 if ((res
= RegDeleteValueW( hkey
, value
)))
2565 WARN("Failed to delete value %s (%d)\n", debugstr_w(value
), res
);
2567 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, &num_subkeys
, NULL
, NULL
, &num_values
,
2568 NULL
, NULL
, NULL
, NULL
);
2569 RegCloseKey( hkey
);
2571 if (!res
&& !num_subkeys
&& !num_values
)
2573 TRACE("Removing empty key %s\n", debugstr_w(key
));
2574 RegDeleteKeyW( hkey_root
, key
);
2578 WARN("Failed to open key %s (%d)\n", debugstr_w(key
), res
);
2582 static UINT
ITERATE_RemoveRegistryValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
2584 MSIPACKAGE
*package
= param
;
2585 LPCWSTR component
, name
, key_str
, root_key_str
;
2586 LPWSTR deformated_key
, deformated_name
, ui_key_str
, keypath
;
2589 BOOL delete_key
= FALSE
;
2594 ui_progress( package
, 2, 0, 0, 0 );
2596 component
= MSI_RecordGetString( row
, 6 );
2597 comp
= get_loaded_component( package
, component
);
2599 return ERROR_SUCCESS
;
2603 TRACE("component is disabled\n");
2604 return ERROR_SUCCESS
;
2607 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
2609 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
2610 comp
->Action
= comp
->Installed
;
2611 return ERROR_SUCCESS
;
2613 comp
->Action
= INSTALLSTATE_ABSENT
;
2615 name
= MSI_RecordGetString( row
, 4 );
2616 if (MSI_RecordIsNull( row
, 5 ) && name
)
2618 if (name
[0] == '+' && !name
[1])
2619 return ERROR_SUCCESS
;
2620 else if ((name
[0] == '-' && !name
[1]) || (name
[0] == '*' && !name
[1]))
2627 root
= MSI_RecordGetInteger( row
, 2 );
2628 key_str
= MSI_RecordGetString( row
, 3 );
2630 root_key_str
= get_root_key( package
, root
, &hkey_root
);
2632 return ERROR_SUCCESS
;
2634 deformat_string( package
, key_str
, &deformated_key
);
2635 size
= strlenW( deformated_key
) + strlenW( root_key_str
) + 1;
2636 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
2637 strcpyW( ui_key_str
, root_key_str
);
2638 strcatW( ui_key_str
, deformated_key
);
2640 deformat_string( package
, name
, &deformated_name
);
2642 keypath
= get_keypath( package
, hkey_root
, deformated_key
);
2643 msi_free( deformated_key
);
2644 delete_reg_key_or_value( hkey_root
, keypath
, deformated_name
, delete_key
);
2645 msi_free( keypath
);
2647 uirow
= MSI_CreateRecord( 2 );
2648 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
2649 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
2651 ui_actiondata( package
, szRemoveRegistryValues
, uirow
);
2652 msiobj_release( &uirow
->hdr
);
2654 msi_free( ui_key_str
);
2655 msi_free( deformated_name
);
2656 return ERROR_SUCCESS
;
2659 static UINT
ITERATE_RemoveRegistryValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
2661 MSIPACKAGE
*package
= param
;
2662 LPCWSTR component
, name
, key_str
, root_key_str
;
2663 LPWSTR deformated_key
, deformated_name
, ui_key_str
, keypath
;
2666 BOOL delete_key
= FALSE
;
2671 ui_progress( package
, 2, 0, 0, 0 );
2673 component
= MSI_RecordGetString( row
, 5 );
2674 comp
= get_loaded_component( package
, component
);
2676 return ERROR_SUCCESS
;
2680 TRACE("component is disabled\n");
2681 return ERROR_SUCCESS
;
2684 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
2686 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
2687 comp
->Action
= comp
->Installed
;
2688 return ERROR_SUCCESS
;
2690 comp
->Action
= INSTALLSTATE_LOCAL
;
2692 if ((name
= MSI_RecordGetString( row
, 4 )))
2694 if (name
[0] == '-' && !name
[1])
2701 root
= MSI_RecordGetInteger( row
, 2 );
2702 key_str
= MSI_RecordGetString( row
, 3 );
2704 root_key_str
= get_root_key( package
, root
, &hkey_root
);
2706 return ERROR_SUCCESS
;
2708 deformat_string( package
, key_str
, &deformated_key
);
2709 size
= strlenW( deformated_key
) + strlenW( root_key_str
) + 1;
2710 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
2711 strcpyW( ui_key_str
, root_key_str
);
2712 strcatW( ui_key_str
, deformated_key
);
2714 deformat_string( package
, name
, &deformated_name
);
2716 keypath
= get_keypath( package
, hkey_root
, deformated_key
);
2717 msi_free( deformated_key
);
2718 delete_reg_key_or_value( hkey_root
, keypath
, deformated_name
, delete_key
);
2719 msi_free( keypath
);
2721 uirow
= MSI_CreateRecord( 2 );
2722 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
2723 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
2725 ui_actiondata( package
, szRemoveRegistryValues
, uirow
);
2726 msiobj_release( &uirow
->hdr
);
2728 msi_free( ui_key_str
);
2729 msi_free( deformated_name
);
2730 return ERROR_SUCCESS
;
2733 static UINT
ACTION_RemoveRegistryValues( MSIPACKAGE
*package
)
2737 static const WCHAR registry_query
[] =
2738 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2739 '`','R','e','g','i','s','t','r','y','`',0 };
2740 static const WCHAR remove_registry_query
[] =
2741 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2742 '`','R','e','m','o','v','e','R','e','g','i','s','t','r','y','`',0 };
2744 /* increment progress bar each time action data is sent */
2745 ui_progress( package
, 1, REG_PROGRESS_VALUE
, 1, 0 );
2747 rc
= MSI_DatabaseOpenViewW( package
->db
, registry_query
, &view
);
2748 if (rc
== ERROR_SUCCESS
)
2750 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnUninstall
, package
);
2751 msiobj_release( &view
->hdr
);
2752 if (rc
!= ERROR_SUCCESS
)
2756 rc
= MSI_DatabaseOpenViewW( package
->db
, remove_registry_query
, &view
);
2757 if (rc
== ERROR_SUCCESS
)
2759 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnInstall
, package
);
2760 msiobj_release( &view
->hdr
);
2761 if (rc
!= ERROR_SUCCESS
)
2765 return ERROR_SUCCESS
;
2768 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
2770 package
->script
->CurrentlyScripting
= TRUE
;
2772 return ERROR_SUCCESS
;
2776 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
2781 static const WCHAR q1
[]=
2782 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2783 '`','R','e','g','i','s','t','r','y','`',0};
2786 MSIFEATURE
*feature
;
2789 TRACE("InstallValidate\n");
2791 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
2792 if (rc
== ERROR_SUCCESS
)
2794 MSI_IterateRecords( view
, &progress
, NULL
, package
);
2795 msiobj_release( &view
->hdr
);
2796 total
+= progress
* REG_PROGRESS_VALUE
;
2799 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2800 total
+= COMPONENT_PROGRESS_VALUE
;
2802 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2803 total
+= file
->FileSize
;
2805 ui_progress(package
,0,total
,0,0);
2807 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
2809 TRACE("Feature: %s Installed %d Request %d Action %d\n",
2810 debugstr_w(feature
->Feature
), feature
->Installed
,
2811 feature
->ActionRequest
, feature
->Action
);
2814 return ERROR_SUCCESS
;
2817 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
2819 MSIPACKAGE
* package
= param
;
2820 LPCWSTR cond
= NULL
;
2821 LPCWSTR message
= NULL
;
2824 static const WCHAR title
[]=
2825 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2827 cond
= MSI_RecordGetString(row
,1);
2829 r
= MSI_EvaluateConditionW(package
,cond
);
2830 if (r
== MSICONDITION_FALSE
)
2832 if ((gUILevel
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
2835 message
= MSI_RecordGetString(row
,2);
2836 deformat_string(package
,message
,&deformated
);
2837 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
2838 msi_free(deformated
);
2841 return ERROR_INSTALL_FAILURE
;
2844 return ERROR_SUCCESS
;
2847 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
2850 MSIQUERY
* view
= NULL
;
2851 static const WCHAR ExecSeqQuery
[] =
2852 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2853 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
2855 TRACE("Checking launch conditions\n");
2857 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2858 if (rc
!= ERROR_SUCCESS
)
2859 return ERROR_SUCCESS
;
2861 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
2862 msiobj_release(&view
->hdr
);
2867 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, MSICOMPONENT
*cmp
)
2871 return resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,TRUE
,NULL
);
2873 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
2875 MSIRECORD
* row
= 0;
2877 LPWSTR deformated
,buffer
,deformated_name
;
2879 static const WCHAR ExecSeqQuery
[] =
2880 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2881 '`','R','e','g','i','s','t','r','y','`',' ',
2882 'W','H','E','R','E',' ', '`','R','e','g','i','s','t','r','y','`',
2883 ' ','=',' ' ,'\'','%','s','\'',0 };
2884 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
2885 static const WCHAR fmt2
[]=
2886 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
2888 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
,cmp
->KeyPath
);
2892 root
= MSI_RecordGetInteger(row
,2);
2893 key
= MSI_RecordGetString(row
, 3);
2894 name
= MSI_RecordGetString(row
, 4);
2895 deformat_string(package
, key
, &deformated
);
2896 deformat_string(package
, name
, &deformated_name
);
2898 len
= strlenW(deformated
) + 6;
2899 if (deformated_name
)
2900 len
+=strlenW(deformated_name
);
2902 buffer
= msi_alloc( len
*sizeof(WCHAR
));
2904 if (deformated_name
)
2905 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
2907 sprintfW(buffer
,fmt
,root
,deformated
);
2909 msi_free(deformated
);
2910 msi_free(deformated_name
);
2911 msiobj_release(&row
->hdr
);
2915 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2917 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
2922 MSIFILE
*file
= get_loaded_file( package
, cmp
->KeyPath
);
2925 return strdupW( file
->TargetPath
);
2930 static HKEY
openSharedDLLsKey(void)
2933 static const WCHAR path
[] =
2934 {'S','o','f','t','w','a','r','e','\\',
2935 'M','i','c','r','o','s','o','f','t','\\',
2936 'W','i','n','d','o','w','s','\\',
2937 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2938 'S','h','a','r','e','d','D','L','L','s',0};
2940 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
2944 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
2949 DWORD sz
= sizeof(count
);
2952 hkey
= openSharedDLLsKey();
2953 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
2954 if (rc
!= ERROR_SUCCESS
)
2960 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
2964 hkey
= openSharedDLLsKey();
2966 msi_reg_set_val_dword( hkey
, path
, count
);
2968 RegDeleteValueW(hkey
,path
);
2974 * Return TRUE if the count should be written out and FALSE if not
2976 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, MSICOMPONENT
*comp
)
2978 MSIFEATURE
*feature
;
2982 /* only refcount DLLs */
2983 if (comp
->KeyPath
== NULL
||
2984 comp
->Attributes
& msidbComponentAttributesRegistryKeyPath
||
2985 comp
->Attributes
& msidbComponentAttributesODBCDataSource
)
2989 count
= ACTION_GetSharedDLLsCount( comp
->FullKeypath
);
2990 write
= (count
> 0);
2992 if (comp
->Attributes
& msidbComponentAttributesSharedDllRefCount
)
2996 /* increment counts */
2997 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3001 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
)
3004 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3006 if ( cl
->component
== comp
)
3011 /* decrement counts */
3012 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3016 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
3019 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3021 if ( cl
->component
== comp
)
3026 /* ref count all the files in the component */
3031 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
3033 if (file
->Component
== comp
)
3034 ACTION_WriteSharedDLLsCount( file
->TargetPath
, count
);
3038 /* add a count for permanent */
3039 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
3042 comp
->RefCount
= count
;
3045 ACTION_WriteSharedDLLsCount( comp
->FullKeypath
, comp
->RefCount
);
3048 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
3050 WCHAR squished_pc
[GUID_SIZE
];
3051 WCHAR squished_cc
[GUID_SIZE
];
3058 squash_guid(package
->ProductCode
,squished_pc
);
3059 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
3061 msi_set_sourcedir_props(package
, FALSE
);
3063 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
3067 ui_progress(package
,2,0,0,0);
3068 if (!comp
->ComponentId
)
3071 squash_guid(comp
->ComponentId
,squished_cc
);
3073 msi_free(comp
->FullKeypath
);
3074 comp
->FullKeypath
= resolve_keypath( package
, comp
);
3076 ACTION_RefCountComponent( package
, comp
);
3078 TRACE("Component %s (%s), Keypath=%s, RefCount=%i Request=%u\n",
3079 debugstr_w(comp
->Component
),
3080 debugstr_w(squished_cc
),
3081 debugstr_w(comp
->FullKeypath
),
3083 comp
->ActionRequest
);
3085 if (comp
->ActionRequest
== INSTALLSTATE_LOCAL
||
3086 comp
->ActionRequest
== INSTALLSTATE_SOURCE
)
3088 if (!comp
->FullKeypath
)
3091 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3092 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, szLocalSid
,
3095 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, NULL
,
3098 if (rc
!= ERROR_SUCCESS
)
3101 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
3103 static const WCHAR szPermKey
[] =
3104 { '0','0','0','0','0','0','0','0','0','0','0','0',
3105 '0','0','0','0','0','0','0','0','0','0','0','0',
3106 '0','0','0','0','0','0','0','0',0 };
3108 msi_reg_set_val_str(hkey
, szPermKey
, comp
->FullKeypath
);
3111 if (comp
->ActionRequest
== INSTALLSTATE_LOCAL
)
3112 msi_reg_set_val_str(hkey
, squished_pc
, comp
->FullKeypath
);
3118 WCHAR source
[MAX_PATH
];
3119 WCHAR base
[MAX_PATH
];
3122 static const WCHAR fmt
[] = {'%','0','2','d','\\',0};
3123 static const WCHAR query
[] = {
3124 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3125 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3126 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
3127 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
3128 '`','D','i','s','k','I','d','`',0};
3130 file
= get_loaded_file(package
, comp
->KeyPath
);
3134 row
= MSI_QueryGetRecord(package
->db
, query
, file
->Sequence
);
3135 sprintfW(source
, fmt
, MSI_RecordGetInteger(row
, 1));
3136 ptr2
= strrchrW(source
, '\\') + 1;
3137 msiobj_release(&row
->hdr
);
3139 lstrcpyW(base
, package
->PackagePath
);
3140 ptr
= strrchrW(base
, '\\');
3143 sourcepath
= resolve_file_source(package
, file
);
3144 ptr
= sourcepath
+ lstrlenW(base
);
3145 lstrcpyW(ptr2
, ptr
);
3146 msi_free(sourcepath
);
3148 msi_reg_set_val_str(hkey
, squished_pc
, source
);
3152 else if (comp
->ActionRequest
== INSTALLSTATE_ABSENT
)
3154 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3155 MSIREG_DeleteUserDataComponentKey(comp
->ComponentId
, szLocalSid
);
3157 MSIREG_DeleteUserDataComponentKey(comp
->ComponentId
, NULL
);
3159 comp
->Action
= comp
->ActionRequest
;
3162 uirow
= MSI_CreateRecord(3);
3163 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
3164 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
3165 MSI_RecordSetStringW(uirow
,3,comp
->FullKeypath
);
3166 ui_actiondata(package
,szProcessComponents
,uirow
);
3167 msiobj_release( &uirow
->hdr
);
3170 return ERROR_SUCCESS
;
3181 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
3182 LPWSTR lpszName
, LONG_PTR lParam
)
3185 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
3186 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
3190 if (!IS_INTRESOURCE(lpszName
))
3192 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
3196 sz
= strlenW(tl_struct
->source
)+4;
3197 sz
*= sizeof(WCHAR
);
3199 if ((INT_PTR
)lpszName
== 1)
3200 tl_struct
->path
= strdupW(tl_struct
->source
);
3203 tl_struct
->path
= msi_alloc(sz
);
3204 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
3207 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
3208 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
3211 msi_free(tl_struct
->path
);
3212 tl_struct
->path
= NULL
;
3217 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
3218 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
3220 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3224 msi_free(tl_struct
->path
);
3225 tl_struct
->path
= NULL
;
3227 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3228 ITypeLib_Release(tl_struct
->ptLib
);
3233 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
3235 MSIPACKAGE
* package
= param
;
3239 typelib_struct tl_struct
;
3244 component
= MSI_RecordGetString(row
,3);
3245 comp
= get_loaded_component(package
,component
);
3247 return ERROR_SUCCESS
;
3251 TRACE("component is disabled\n");
3252 return ERROR_SUCCESS
;
3255 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
3257 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
3258 comp
->Action
= comp
->Installed
;
3259 return ERROR_SUCCESS
;
3261 comp
->Action
= INSTALLSTATE_LOCAL
;
3263 file
= get_loaded_file( package
, comp
->KeyPath
);
3265 return ERROR_SUCCESS
;
3267 ui_actiondata( package
, szRegisterTypeLibraries
, row
);
3269 module
= LoadLibraryExW( file
->TargetPath
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
3273 guid
= MSI_RecordGetString(row
,1);
3274 CLSIDFromString((LPCWSTR
)guid
, &tl_struct
.clsid
);
3275 tl_struct
.source
= strdupW( file
->TargetPath
);
3276 tl_struct
.path
= NULL
;
3278 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
3279 (LONG_PTR
)&tl_struct
);
3287 helpid
= MSI_RecordGetString(row
,6);
3290 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,TRUE
,NULL
);
3291 res
= RegisterTypeLib(tl_struct
.ptLib
,tl_struct
.path
,help
);
3295 ERR("Failed to register type library %s\n",
3296 debugstr_w(tl_struct
.path
));
3298 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
3300 ITypeLib_Release(tl_struct
.ptLib
);
3301 msi_free(tl_struct
.path
);
3304 ERR("Failed to load type library %s\n",
3305 debugstr_w(tl_struct
.source
));
3307 FreeLibrary(module
);
3308 msi_free(tl_struct
.source
);
3312 hr
= LoadTypeLibEx(file
->TargetPath
, REGKIND_REGISTER
, &tlib
);
3315 ERR("Failed to load type library: %08x\n", hr
);
3316 return ERROR_INSTALL_FAILURE
;
3319 ITypeLib_Release(tlib
);
3322 return ERROR_SUCCESS
;
3325 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
3328 * OK this is a bit confusing.. I am given a _Component key and I believe
3329 * that the file that is being registered as a type library is the "key file
3330 * of that component" which I interpret to mean "The file in the KeyPath of
3335 static const WCHAR Query
[] =
3336 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3337 '`','T','y','p','e','L','i','b','`',0};
3339 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3340 if (rc
!= ERROR_SUCCESS
)
3341 return ERROR_SUCCESS
;
3343 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
3344 msiobj_release(&view
->hdr
);
3348 static UINT
ITERATE_UnregisterTypeLibraries( MSIRECORD
*row
, LPVOID param
)
3350 MSIPACKAGE
*package
= param
;
3351 LPCWSTR component
, guid
;
3359 component
= MSI_RecordGetString( row
, 3 );
3360 comp
= get_loaded_component( package
, component
);
3362 return ERROR_SUCCESS
;
3366 TRACE("component is disabled\n");
3367 return ERROR_SUCCESS
;
3370 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
3372 TRACE("Component not scheduled for removal %s\n", debugstr_w(component
));
3373 comp
->Action
= comp
->Installed
;
3374 return ERROR_SUCCESS
;
3376 comp
->Action
= INSTALLSTATE_ABSENT
;
3378 ui_actiondata( package
, szUnregisterTypeLibraries
, row
);
3380 guid
= MSI_RecordGetString( row
, 1 );
3381 CLSIDFromString( (LPCWSTR
)guid
, &libid
);
3382 version
= MSI_RecordGetInteger( row
, 4 );
3383 language
= MSI_RecordGetInteger( row
, 2 );
3386 syskind
= SYS_WIN64
;
3388 syskind
= SYS_WIN32
;
3391 hr
= UnRegisterTypeLib( &libid
, (version
>> 8) & 0xffff, version
& 0xff, language
, syskind
);
3394 WARN("Failed to unregister typelib: %08x\n", hr
);
3397 return ERROR_SUCCESS
;
3400 static UINT
ACTION_UnregisterTypeLibraries( MSIPACKAGE
*package
)
3404 static const WCHAR query
[] =
3405 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3406 '`','T','y','p','e','L','i','b','`',0};
3408 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
3409 if (rc
!= ERROR_SUCCESS
)
3410 return ERROR_SUCCESS
;
3412 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnregisterTypeLibraries
, package
);
3413 msiobj_release( &view
->hdr
);
3417 static WCHAR
*get_link_file( MSIPACKAGE
*package
, MSIRECORD
*row
)
3419 static const WCHAR szlnk
[] = {'.','l','n','k',0};
3420 LPCWSTR directory
, extension
;
3421 LPWSTR link_folder
, link_file
, filename
;
3423 directory
= MSI_RecordGetString( row
, 2 );
3424 link_folder
= resolve_folder( package
, directory
, FALSE
, FALSE
, TRUE
, NULL
);
3426 /* may be needed because of a bug somewhere else */
3427 create_full_pathW( link_folder
);
3429 filename
= msi_dup_record_field( row
, 3 );
3430 reduce_to_longfilename( filename
);
3432 extension
= strchrW( filename
, '.' );
3433 if (!extension
|| strcmpiW( extension
, szlnk
))
3435 int len
= strlenW( filename
);
3436 filename
= msi_realloc( filename
, len
* sizeof(WCHAR
) + sizeof(szlnk
) );
3437 memcpy( filename
+ len
, szlnk
, sizeof(szlnk
) );
3439 link_file
= build_directory_name( 2, link_folder
, filename
);
3440 msi_free( link_folder
);
3441 msi_free( filename
);
3446 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
3448 MSIPACKAGE
*package
= param
;
3449 LPWSTR link_file
, deformated
, path
;
3450 LPCWSTR component
, target
;
3452 IShellLinkW
*sl
= NULL
;
3453 IPersistFile
*pf
= NULL
;
3456 component
= MSI_RecordGetString(row
, 4);
3457 comp
= get_loaded_component(package
, component
);
3459 return ERROR_SUCCESS
;
3463 TRACE("component is disabled\n");
3464 return ERROR_SUCCESS
;
3467 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
3469 TRACE("Component not scheduled for installation %s\n", debugstr_w(component
));
3470 comp
->Action
= comp
->Installed
;
3471 return ERROR_SUCCESS
;
3473 comp
->Action
= INSTALLSTATE_LOCAL
;
3475 ui_actiondata(package
,szCreateShortcuts
,row
);
3477 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3478 &IID_IShellLinkW
, (LPVOID
*) &sl
);
3482 ERR("CLSID_ShellLink not available\n");
3486 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
3489 ERR("QueryInterface(IID_IPersistFile) failed\n");
3493 target
= MSI_RecordGetString(row
, 5);
3494 if (strchrW(target
, '['))
3496 deformat_string(package
, target
, &deformated
);
3497 IShellLinkW_SetPath(sl
,deformated
);
3498 msi_free(deformated
);
3502 FIXME("poorly handled shortcut format, advertised shortcut\n");
3503 IShellLinkW_SetPath(sl
,comp
->FullKeypath
);
3506 if (!MSI_RecordIsNull(row
,6))
3508 LPCWSTR arguments
= MSI_RecordGetString(row
, 6);
3509 deformat_string(package
, arguments
, &deformated
);
3510 IShellLinkW_SetArguments(sl
,deformated
);
3511 msi_free(deformated
);
3514 if (!MSI_RecordIsNull(row
,7))
3516 LPCWSTR description
= MSI_RecordGetString(row
, 7);
3517 IShellLinkW_SetDescription(sl
, description
);
3520 if (!MSI_RecordIsNull(row
,8))
3521 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
3523 if (!MSI_RecordIsNull(row
,9))
3526 LPCWSTR icon
= MSI_RecordGetString(row
, 9);
3528 path
= build_icon_path(package
, icon
);
3529 index
= MSI_RecordGetInteger(row
,10);
3531 /* no value means 0 */
3532 if (index
== MSI_NULL_INTEGER
)
3535 IShellLinkW_SetIconLocation(sl
, path
, index
);
3539 if (!MSI_RecordIsNull(row
,11))
3540 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
3542 if (!MSI_RecordIsNull(row
,12))
3544 LPCWSTR wkdir
= MSI_RecordGetString(row
, 12);
3545 path
= resolve_folder(package
, wkdir
, FALSE
, FALSE
, TRUE
, NULL
);
3547 IShellLinkW_SetWorkingDirectory(sl
, path
);
3551 link_file
= get_link_file(package
, row
);
3553 TRACE("Writing shortcut to %s\n", debugstr_w(link_file
));
3554 IPersistFile_Save(pf
, link_file
, FALSE
);
3556 msi_free(link_file
);
3560 IPersistFile_Release( pf
);
3562 IShellLinkW_Release( sl
);
3564 return ERROR_SUCCESS
;
3567 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
3572 static const WCHAR Query
[] =
3573 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3574 '`','S','h','o','r','t','c','u','t','`',0};
3576 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3577 if (rc
!= ERROR_SUCCESS
)
3578 return ERROR_SUCCESS
;
3580 res
= CoInitialize( NULL
);
3582 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
3583 msiobj_release(&view
->hdr
);
3591 static UINT
ITERATE_RemoveShortcuts( MSIRECORD
*row
, LPVOID param
)
3593 MSIPACKAGE
*package
= param
;
3598 component
= MSI_RecordGetString( row
, 4 );
3599 comp
= get_loaded_component( package
, component
);
3601 return ERROR_SUCCESS
;
3605 TRACE("component is disabled\n");
3606 return ERROR_SUCCESS
;
3609 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
3611 TRACE("Component not scheduled for removal %s\n", debugstr_w(component
));
3612 comp
->Action
= comp
->Installed
;
3613 return ERROR_SUCCESS
;
3615 comp
->Action
= INSTALLSTATE_ABSENT
;
3617 ui_actiondata( package
, szRemoveShortcuts
, row
);
3619 link_file
= get_link_file( package
, row
);
3621 TRACE("Removing shortcut file %s\n", debugstr_w( link_file
));
3622 if (!DeleteFileW( link_file
))
3624 WARN("Failed to remove shortcut file %u\n", GetLastError());
3626 msi_free( link_file
);
3628 return ERROR_SUCCESS
;
3631 static UINT
ACTION_RemoveShortcuts( MSIPACKAGE
*package
)
3635 static const WCHAR query
[] =
3636 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3637 '`','S','h','o','r','t','c','u','t','`',0};
3639 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
3640 if (rc
!= ERROR_SUCCESS
)
3641 return ERROR_SUCCESS
;
3643 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveShortcuts
, package
);
3644 msiobj_release( &view
->hdr
);
3649 static UINT
ITERATE_PublishIcon(MSIRECORD
*row
, LPVOID param
)
3651 MSIPACKAGE
* package
= param
;
3659 FileName
= MSI_RecordGetString(row
,1);
3662 ERR("Unable to get FileName\n");
3663 return ERROR_SUCCESS
;
3666 FilePath
= build_icon_path(package
,FileName
);
3668 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
3670 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
3671 FILE_ATTRIBUTE_NORMAL
, NULL
);
3673 if (the_file
== INVALID_HANDLE_VALUE
)
3675 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
3677 return ERROR_SUCCESS
;
3684 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
3685 if (rc
!= ERROR_SUCCESS
)
3687 ERR("Failed to get stream\n");
3688 CloseHandle(the_file
);
3689 DeleteFileW(FilePath
);
3692 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
3693 } while (sz
== 1024);
3696 CloseHandle(the_file
);
3698 return ERROR_SUCCESS
;
3701 static UINT
msi_publish_icons(MSIPACKAGE
*package
)
3706 static const WCHAR query
[]= {
3707 'S','E','L','E','C','T',' ','*',' ',
3708 'F','R','O','M',' ','`','I','c','o','n','`',0};
3710 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
3711 if (r
== ERROR_SUCCESS
)
3713 MSI_IterateRecords(view
, NULL
, ITERATE_PublishIcon
, package
);
3714 msiobj_release(&view
->hdr
);
3717 return ERROR_SUCCESS
;
3720 static UINT
msi_publish_sourcelist(MSIPACKAGE
*package
, HKEY hkey
)
3726 MSISOURCELISTINFO
*info
;
3728 r
= RegCreateKeyW(hkey
, szSourceList
, &source
);
3729 if (r
!= ERROR_SUCCESS
)
3732 RegCloseKey(source
);
3734 buffer
= strrchrW(package
->PackagePath
, '\\') + 1;
3735 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3736 package
->Context
, MSICODE_PRODUCT
,
3737 INSTALLPROPERTY_PACKAGENAMEW
, buffer
);
3738 if (r
!= ERROR_SUCCESS
)
3741 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3742 package
->Context
, MSICODE_PRODUCT
,
3743 INSTALLPROPERTY_MEDIAPACKAGEPATHW
, szEmpty
);
3744 if (r
!= ERROR_SUCCESS
)
3747 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3748 package
->Context
, MSICODE_PRODUCT
,
3749 INSTALLPROPERTY_DISKPROMPTW
, szEmpty
);
3750 if (r
!= ERROR_SUCCESS
)
3753 LIST_FOR_EACH_ENTRY(info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
3755 if (!lstrcmpW(info
->property
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
3756 msi_set_last_used_source(package
->ProductCode
, NULL
, info
->context
,
3757 info
->options
, info
->value
);
3759 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3760 info
->context
, info
->options
,
3761 info
->property
, info
->value
);
3764 LIST_FOR_EACH_ENTRY(disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
3766 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
3767 disk
->context
, disk
->options
,
3768 disk
->disk_id
, disk
->volume_label
, disk
->disk_prompt
);
3771 return ERROR_SUCCESS
;
3774 static UINT
msi_publish_product_properties(MSIPACKAGE
*package
, HKEY hkey
)
3776 MSIHANDLE hdb
, suminfo
;
3777 WCHAR guids
[MAX_PATH
];
3778 WCHAR packcode
[SQUISH_GUID_SIZE
];
3785 static const WCHAR szProductLanguage
[] =
3786 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
3787 static const WCHAR szARPProductIcon
[] =
3788 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
3789 static const WCHAR szProductVersion
[] =
3790 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
3791 static const WCHAR szAssignment
[] =
3792 {'A','s','s','i','g','n','m','e','n','t',0};
3793 static const WCHAR szAdvertiseFlags
[] =
3794 {'A','d','v','e','r','t','i','s','e','F','l','a','g','s',0};
3795 static const WCHAR szClients
[] =
3796 {'C','l','i','e','n','t','s',0};
3797 static const WCHAR szColon
[] = {':',0};
3799 buffer
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
3800 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTNAMEW
, buffer
);
3803 langid
= msi_get_property_int(package
->db
, szProductLanguage
, 0);
3804 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
3807 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
, 0);
3809 buffer
= msi_dup_property(package
->db
, szARPProductIcon
);
3812 LPWSTR path
= build_icon_path(package
,buffer
);
3813 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTICONW
, path
);
3818 buffer
= msi_dup_property(package
->db
, szProductVersion
);
3821 DWORD verdword
= msi_version_str_to_dword(buffer
);
3822 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
3826 msi_reg_set_val_dword(hkey
, szAssignment
, 0);
3827 msi_reg_set_val_dword(hkey
, szAdvertiseFlags
, 0x184);
3828 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_INSTANCETYPEW
, 0);
3829 msi_reg_set_val_str(hkey
, szClients
, szColon
);
3831 hdb
= alloc_msihandle(&package
->db
->hdr
);
3833 return ERROR_NOT_ENOUGH_MEMORY
;
3835 r
= MsiGetSummaryInformationW(hdb
, NULL
, 0, &suminfo
);
3836 MsiCloseHandle(hdb
);
3837 if (r
!= ERROR_SUCCESS
)
3841 r
= MsiSummaryInfoGetPropertyW(suminfo
, PID_REVNUMBER
, NULL
, NULL
,
3842 NULL
, guids
, &size
);
3843 if (r
!= ERROR_SUCCESS
)
3846 ptr
= strchrW(guids
, ';');
3848 squash_guid(guids
, packcode
);
3849 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PACKAGECODEW
, packcode
);
3852 MsiCloseHandle(suminfo
);
3853 return ERROR_SUCCESS
;
3856 static UINT
msi_publish_upgrade_code(MSIPACKAGE
*package
)
3861 WCHAR squashed_pc
[SQUISH_GUID_SIZE
];
3863 upgrade
= msi_dup_property(package
->db
, szUpgradeCode
);
3865 return ERROR_SUCCESS
;
3867 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3869 r
= MSIREG_OpenClassesUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
3870 if (r
!= ERROR_SUCCESS
)
3875 r
= MSIREG_OpenUserUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
3876 if (r
!= ERROR_SUCCESS
)
3880 squash_guid(package
->ProductCode
, squashed_pc
);
3881 msi_reg_set_val_str(hkey
, squashed_pc
, NULL
);
3890 static BOOL
msi_check_publish(MSIPACKAGE
*package
)
3892 MSIFEATURE
*feature
;
3894 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
3896 if (feature
->ActionRequest
== INSTALLSTATE_LOCAL
)
3903 static BOOL
msi_check_unpublish(MSIPACKAGE
*package
)
3905 MSIFEATURE
*feature
;
3907 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
3909 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
3916 static UINT
msi_publish_patches( MSIPACKAGE
*package
)
3918 static const WCHAR szAllPatches
[] = {'A','l','l','P','a','t','c','h','e','s',0};
3919 WCHAR patch_squashed
[GUID_SIZE
];
3920 HKEY patches_key
= NULL
, product_patches_key
= NULL
, product_key
;
3922 MSIPATCHINFO
*patch
;
3924 WCHAR
*p
, *all_patches
= NULL
;
3927 r
= MSIREG_OpenProductKey( package
->ProductCode
, NULL
, package
->Context
, &product_key
, TRUE
);
3928 if (r
!= ERROR_SUCCESS
)
3929 return ERROR_FUNCTION_FAILED
;
3931 res
= RegCreateKeyExW( product_key
, szPatches
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &patches_key
, NULL
);
3932 if (res
!= ERROR_SUCCESS
)
3934 r
= ERROR_FUNCTION_FAILED
;
3938 r
= MSIREG_OpenUserDataProductPatchesKey( package
->ProductCode
, package
->Context
, &product_patches_key
, TRUE
);
3939 if (r
!= ERROR_SUCCESS
)
3942 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
3944 squash_guid( patch
->patchcode
, patch_squashed
);
3945 len
+= strlenW( patch_squashed
) + 1;
3948 p
= all_patches
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
3952 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
3956 squash_guid( patch
->patchcode
, p
);
3957 p
+= strlenW( p
) + 1;
3959 res
= RegSetValueExW( patches_key
, patch_squashed
, 0, REG_SZ
,
3960 (const BYTE
*)patch
->transforms
,
3961 (strlenW(patch
->transforms
) + 1) * sizeof(WCHAR
) );
3962 if (res
!= ERROR_SUCCESS
)
3965 r
= MSIREG_OpenUserDataPatchKey( patch
->patchcode
, package
->Context
, &patch_key
, TRUE
);
3966 if (r
!= ERROR_SUCCESS
)
3969 res
= RegSetValueExW( patch_key
, szLocalPackage
, 0, REG_SZ
,
3970 (const BYTE
*)patch
->localfile
,
3971 (strlenW(patch
->localfile
) + 1) * sizeof(WCHAR
) );
3972 RegCloseKey( patch_key
);
3973 if (res
!= ERROR_SUCCESS
)
3976 res
= RegCreateKeyExW( product_patches_key
, patch_squashed
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &patch_key
, NULL
);
3977 if (res
!= ERROR_SUCCESS
)
3980 res
= RegSetValueExW( patch_key
, szState
, 0, REG_DWORD
, (const BYTE
*)&patch
->state
, sizeof(patch
->state
) );
3981 RegCloseKey( patch_key
);
3982 if (res
!= ERROR_SUCCESS
)
3986 all_patches
[len
] = 0;
3987 res
= RegSetValueExW( patches_key
, szPatches
, 0, REG_MULTI_SZ
,
3988 (const BYTE
*)all_patches
, (len
+ 1) * sizeof(WCHAR
) );
3989 if (res
!= ERROR_SUCCESS
)
3992 res
= RegSetValueExW( product_patches_key
, szAllPatches
, 0, REG_MULTI_SZ
,
3993 (const BYTE
*)all_patches
, (len
+ 1) * sizeof(WCHAR
) );
3994 if (res
!= ERROR_SUCCESS
)
3995 r
= ERROR_FUNCTION_FAILED
;
3998 RegCloseKey( product_patches_key
);
3999 RegCloseKey( patches_key
);
4000 RegCloseKey( product_key
);
4001 msi_free( all_patches
);
4006 * 99% of the work done here is only done for
4007 * advertised installs. However this is where the
4008 * Icon table is processed and written out
4009 * so that is what I am going to do here.
4011 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
4014 HKEY hukey
= NULL
, hudkey
= NULL
;
4017 if (!list_empty(&package
->patches
))
4019 rc
= msi_publish_patches(package
);
4020 if (rc
!= ERROR_SUCCESS
)
4024 /* FIXME: also need to publish if the product is in advertise mode */
4025 if (!msi_check_publish(package
))
4026 return ERROR_SUCCESS
;
4028 rc
= MSIREG_OpenProductKey(package
->ProductCode
, NULL
, package
->Context
,
4030 if (rc
!= ERROR_SUCCESS
)
4033 rc
= MSIREG_OpenUserDataProductKey(package
->ProductCode
, package
->Context
,
4034 NULL
, &hudkey
, TRUE
);
4035 if (rc
!= ERROR_SUCCESS
)
4038 rc
= msi_publish_upgrade_code(package
);
4039 if (rc
!= ERROR_SUCCESS
)
4042 rc
= msi_publish_product_properties(package
, hukey
);
4043 if (rc
!= ERROR_SUCCESS
)
4046 rc
= msi_publish_sourcelist(package
, hukey
);
4047 if (rc
!= ERROR_SUCCESS
)
4050 rc
= msi_publish_icons(package
);
4053 uirow
= MSI_CreateRecord( 1 );
4054 MSI_RecordSetStringW( uirow
, 1, package
->ProductCode
);
4055 ui_actiondata( package
, szPublishProduct
, uirow
);
4056 msiobj_release( &uirow
->hdr
);
4059 RegCloseKey(hudkey
);
4064 static WCHAR
*get_ini_file_name( MSIPACKAGE
*package
, MSIRECORD
*row
)
4066 WCHAR
*filename
, *ptr
, *folder
, *ret
;
4067 const WCHAR
*dirprop
;
4069 filename
= msi_dup_record_field( row
, 2 );
4070 if (filename
&& (ptr
= strchrW( filename
, '|' )))
4075 dirprop
= MSI_RecordGetString( row
, 3 );
4078 folder
= resolve_folder( package
, dirprop
, FALSE
, FALSE
, TRUE
, NULL
);
4080 folder
= msi_dup_property( package
->db
, dirprop
);
4083 folder
= msi_dup_property( package
->db
, szWindowsFolder
);
4087 ERR("Unable to resolve folder %s\n", debugstr_w(dirprop
));
4088 msi_free( filename
);
4092 ret
= build_directory_name( 2, folder
, ptr
);
4094 msi_free( filename
);
4099 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
4101 MSIPACKAGE
*package
= param
;
4102 LPCWSTR component
, section
, key
, value
, identifier
;
4103 LPWSTR deformated_section
, deformated_key
, deformated_value
, fullname
;
4108 component
= MSI_RecordGetString(row
, 8);
4109 comp
= get_loaded_component(package
,component
);
4111 return ERROR_SUCCESS
;
4115 TRACE("component is disabled\n");
4116 return ERROR_SUCCESS
;
4119 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4121 TRACE("Component not scheduled for installation %s\n", debugstr_w(component
));
4122 comp
->Action
= comp
->Installed
;
4123 return ERROR_SUCCESS
;
4125 comp
->Action
= INSTALLSTATE_LOCAL
;
4127 identifier
= MSI_RecordGetString(row
,1);
4128 section
= MSI_RecordGetString(row
,4);
4129 key
= MSI_RecordGetString(row
,5);
4130 value
= MSI_RecordGetString(row
,6);
4131 action
= MSI_RecordGetInteger(row
,7);
4133 deformat_string(package
,section
,&deformated_section
);
4134 deformat_string(package
,key
,&deformated_key
);
4135 deformat_string(package
,value
,&deformated_value
);
4137 fullname
= get_ini_file_name(package
, row
);
4141 TRACE("Adding value %s to section %s in %s\n",
4142 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
4143 debugstr_w(fullname
));
4144 WritePrivateProfileStringW(deformated_section
, deformated_key
,
4145 deformated_value
, fullname
);
4147 else if (action
== 1)
4150 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
4151 returned
, 10, fullname
);
4152 if (returned
[0] == 0)
4154 TRACE("Adding value %s to section %s in %s\n",
4155 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
4156 debugstr_w(fullname
));
4158 WritePrivateProfileStringW(deformated_section
, deformated_key
,
4159 deformated_value
, fullname
);
4162 else if (action
== 3)
4163 FIXME("Append to existing section not yet implemented\n");
4165 uirow
= MSI_CreateRecord(4);
4166 MSI_RecordSetStringW(uirow
,1,identifier
);
4167 MSI_RecordSetStringW(uirow
,2,deformated_section
);
4168 MSI_RecordSetStringW(uirow
,3,deformated_key
);
4169 MSI_RecordSetStringW(uirow
,4,deformated_value
);
4170 ui_actiondata(package
,szWriteIniValues
,uirow
);
4171 msiobj_release( &uirow
->hdr
);
4174 msi_free(deformated_key
);
4175 msi_free(deformated_value
);
4176 msi_free(deformated_section
);
4177 return ERROR_SUCCESS
;
4180 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
4184 static const WCHAR ExecSeqQuery
[] =
4185 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4186 '`','I','n','i','F','i','l','e','`',0};
4188 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4189 if (rc
!= ERROR_SUCCESS
)
4191 TRACE("no IniFile table\n");
4192 return ERROR_SUCCESS
;
4195 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
4196 msiobj_release(&view
->hdr
);
4200 static UINT
ITERATE_RemoveIniValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
4202 MSIPACKAGE
*package
= param
;
4203 LPCWSTR component
, section
, key
, value
, identifier
;
4204 LPWSTR deformated_section
, deformated_key
, deformated_value
, filename
;
4209 component
= MSI_RecordGetString( row
, 8 );
4210 comp
= get_loaded_component( package
, component
);
4212 return ERROR_SUCCESS
;
4216 TRACE("component is disabled\n");
4217 return ERROR_SUCCESS
;
4220 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
4222 TRACE("Component not scheduled for removal %s\n", debugstr_w(component
));
4223 comp
->Action
= comp
->Installed
;
4224 return ERROR_SUCCESS
;
4226 comp
->Action
= INSTALLSTATE_ABSENT
;
4228 identifier
= MSI_RecordGetString( row
, 1 );
4229 section
= MSI_RecordGetString( row
, 4 );
4230 key
= MSI_RecordGetString( row
, 5 );
4231 value
= MSI_RecordGetString( row
, 6 );
4232 action
= MSI_RecordGetInteger( row
, 7 );
4234 deformat_string( package
, section
, &deformated_section
);
4235 deformat_string( package
, key
, &deformated_key
);
4236 deformat_string( package
, value
, &deformated_value
);
4238 if (action
== msidbIniFileActionAddLine
|| action
== msidbIniFileActionCreateLine
)
4240 filename
= get_ini_file_name( package
, row
);
4242 TRACE("Removing key %s from section %s in %s\n",
4243 debugstr_w(deformated_key
), debugstr_w(deformated_section
), debugstr_w(filename
));
4245 if (!WritePrivateProfileStringW( deformated_section
, deformated_key
, NULL
, filename
))
4247 WARN("Unable to remove key %u\n", GetLastError());
4249 msi_free( filename
);
4252 FIXME("Unsupported action %d\n", action
);
4255 uirow
= MSI_CreateRecord( 4 );
4256 MSI_RecordSetStringW( uirow
, 1, identifier
);
4257 MSI_RecordSetStringW( uirow
, 2, deformated_section
);
4258 MSI_RecordSetStringW( uirow
, 3, deformated_key
);
4259 MSI_RecordSetStringW( uirow
, 4, deformated_value
);
4260 ui_actiondata( package
, szRemoveIniValues
, uirow
);
4261 msiobj_release( &uirow
->hdr
);
4263 msi_free( deformated_key
);
4264 msi_free( deformated_value
);
4265 msi_free( deformated_section
);
4266 return ERROR_SUCCESS
;
4269 static UINT
ITERATE_RemoveIniValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
4271 MSIPACKAGE
*package
= param
;
4272 LPCWSTR component
, section
, key
, value
, identifier
;
4273 LPWSTR deformated_section
, deformated_key
, deformated_value
, filename
;
4278 component
= MSI_RecordGetString( row
, 8 );
4279 comp
= get_loaded_component( package
, component
);
4281 return ERROR_SUCCESS
;
4285 TRACE("component is disabled\n");
4286 return ERROR_SUCCESS
;
4289 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
4291 TRACE("Component not scheduled for installation %s\n", debugstr_w(component
));
4292 comp
->Action
= comp
->Installed
;
4293 return ERROR_SUCCESS
;
4295 comp
->Action
= INSTALLSTATE_LOCAL
;
4297 identifier
= MSI_RecordGetString( row
, 1 );
4298 section
= MSI_RecordGetString( row
, 4 );
4299 key
= MSI_RecordGetString( row
, 5 );
4300 value
= MSI_RecordGetString( row
, 6 );
4301 action
= MSI_RecordGetInteger( row
, 7 );
4303 deformat_string( package
, section
, &deformated_section
);
4304 deformat_string( package
, key
, &deformated_key
);
4305 deformat_string( package
, value
, &deformated_value
);
4307 if (action
== msidbIniFileActionRemoveLine
)
4309 filename
= get_ini_file_name( package
, row
);
4311 TRACE("Removing key %s from section %s in %s\n",
4312 debugstr_w(deformated_key
), debugstr_w(deformated_section
), debugstr_w(filename
));
4314 if (!WritePrivateProfileStringW( deformated_section
, deformated_key
, NULL
, filename
))
4316 WARN("Unable to remove key %u\n", GetLastError());
4318 msi_free( filename
);
4321 FIXME("Unsupported action %d\n", action
);
4323 uirow
= MSI_CreateRecord( 4 );
4324 MSI_RecordSetStringW( uirow
, 1, identifier
);
4325 MSI_RecordSetStringW( uirow
, 2, deformated_section
);
4326 MSI_RecordSetStringW( uirow
, 3, deformated_key
);
4327 MSI_RecordSetStringW( uirow
, 4, deformated_value
);
4328 ui_actiondata( package
, szRemoveIniValues
, uirow
);
4329 msiobj_release( &uirow
->hdr
);
4331 msi_free( deformated_key
);
4332 msi_free( deformated_value
);
4333 msi_free( deformated_section
);
4334 return ERROR_SUCCESS
;
4337 static UINT
ACTION_RemoveIniValues( MSIPACKAGE
*package
)
4341 static const WCHAR query
[] =
4342 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4343 '`','I','n','i','F','i','l','e','`',0};
4344 static const WCHAR remove_query
[] =
4345 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4346 '`','R','e','m','o','v','e','I','n','i','F','i','l','e','`',0};
4348 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4349 if (rc
== ERROR_SUCCESS
)
4351 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveIniValuesOnUninstall
, package
);
4352 msiobj_release( &view
->hdr
);
4353 if (rc
!= ERROR_SUCCESS
)
4357 rc
= MSI_DatabaseOpenViewW( package
->db
, remove_query
, &view
);
4358 if (rc
== ERROR_SUCCESS
)
4360 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveIniValuesOnInstall
, package
);
4361 msiobj_release( &view
->hdr
);
4362 if (rc
!= ERROR_SUCCESS
)
4366 return ERROR_SUCCESS
;
4369 static void register_dll( const WCHAR
*dll
, BOOL unregister
)
4373 hmod
= LoadLibraryExW( dll
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
4376 HRESULT (WINAPI
*func_ptr
)( void );
4377 const char *func
= unregister
? "DllUnregisterServer" : "DllRegisterServer";
4379 func_ptr
= (void *)GetProcAddress( hmod
, func
);
4382 HRESULT hr
= func_ptr();
4384 WARN("failed to register dll 0x%08x\n", hr
);
4387 WARN("entry point %s not found\n", func
);
4388 FreeLibrary( hmod
);
4391 WARN("failed to load library %u\n", GetLastError());
4394 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
4396 MSIPACKAGE
*package
= param
;
4401 filename
= MSI_RecordGetString(row
,1);
4402 file
= get_loaded_file( package
, filename
);
4406 ERR("Unable to find file id %s\n",debugstr_w(filename
));
4407 return ERROR_SUCCESS
;
4410 TRACE("Registering %s\n", debugstr_w( file
->TargetPath
));
4412 register_dll( file
->TargetPath
, FALSE
);
4414 uirow
= MSI_CreateRecord( 2 );
4415 MSI_RecordSetStringW( uirow
, 1, filename
);
4416 MSI_RecordSetStringW( uirow
, 2, file
->Component
->Directory
);
4417 ui_actiondata( package
, szSelfRegModules
, uirow
);
4418 msiobj_release( &uirow
->hdr
);
4420 return ERROR_SUCCESS
;
4423 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
4427 static const WCHAR ExecSeqQuery
[] =
4428 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4429 '`','S','e','l','f','R','e','g','`',0};
4431 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4432 if (rc
!= ERROR_SUCCESS
)
4434 TRACE("no SelfReg table\n");
4435 return ERROR_SUCCESS
;
4438 MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
4439 msiobj_release(&view
->hdr
);
4441 return ERROR_SUCCESS
;
4444 static UINT
ITERATE_SelfUnregModules( MSIRECORD
*row
, LPVOID param
)
4446 MSIPACKAGE
*package
= param
;
4451 filename
= MSI_RecordGetString( row
, 1 );
4452 file
= get_loaded_file( package
, filename
);
4456 ERR("Unable to find file id %s\n", debugstr_w(filename
));
4457 return ERROR_SUCCESS
;
4460 TRACE("Unregistering %s\n", debugstr_w( file
->TargetPath
));
4462 register_dll( file
->TargetPath
, TRUE
);
4464 uirow
= MSI_CreateRecord( 2 );
4465 MSI_RecordSetStringW( uirow
, 1, filename
);
4466 MSI_RecordSetStringW( uirow
, 2, file
->Component
->Directory
);
4467 ui_actiondata( package
, szSelfUnregModules
, uirow
);
4468 msiobj_release( &uirow
->hdr
);
4470 return ERROR_SUCCESS
;
4473 static UINT
ACTION_SelfUnregModules( MSIPACKAGE
*package
)
4477 static const WCHAR query
[] =
4478 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4479 '`','S','e','l','f','R','e','g','`',0};
4481 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4482 if (rc
!= ERROR_SUCCESS
)
4484 TRACE("no SelfReg table\n");
4485 return ERROR_SUCCESS
;
4488 MSI_IterateRecords( view
, NULL
, ITERATE_SelfUnregModules
, package
);
4489 msiobj_release( &view
->hdr
);
4491 return ERROR_SUCCESS
;
4494 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
4496 MSIFEATURE
*feature
;
4498 HKEY hkey
= NULL
, userdata
= NULL
;
4500 if (!msi_check_publish(package
))
4501 return ERROR_SUCCESS
;
4503 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
, package
->Context
,
4505 if (rc
!= ERROR_SUCCESS
)
4508 rc
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, package
->Context
,
4510 if (rc
!= ERROR_SUCCESS
)
4513 /* here the guids are base 85 encoded */
4514 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
4520 BOOL absent
= FALSE
;
4523 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
4524 feature
->ActionRequest
!= INSTALLSTATE_SOURCE
&&
4525 feature
->ActionRequest
!= INSTALLSTATE_ADVERTISED
) absent
= TRUE
;
4528 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4532 if (feature
->Feature_Parent
)
4533 size
+= strlenW( feature
->Feature_Parent
)+2;
4535 data
= msi_alloc(size
* sizeof(WCHAR
));
4538 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4540 MSICOMPONENT
* component
= cl
->component
;
4544 if (component
->ComponentId
)
4546 TRACE("From %s\n",debugstr_w(component
->ComponentId
));
4547 CLSIDFromString(component
->ComponentId
, &clsid
);
4548 encode_base85_guid(&clsid
,buf
);
4549 TRACE("to %s\n",debugstr_w(buf
));
4554 if (feature
->Feature_Parent
)
4556 static const WCHAR sep
[] = {'\2',0};
4558 strcatW(data
,feature
->Feature_Parent
);
4561 msi_reg_set_val_str( userdata
, feature
->Feature
, data
);
4565 if (feature
->Feature_Parent
)
4566 size
= strlenW(feature
->Feature_Parent
)*sizeof(WCHAR
);
4569 size
+= sizeof(WCHAR
);
4570 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
4571 (const BYTE
*)(feature
->Feature_Parent
? feature
->Feature_Parent
: szEmpty
),size
);
4575 size
+= 2*sizeof(WCHAR
);
4576 data
= msi_alloc(size
);
4579 if (feature
->Feature_Parent
)
4580 strcpyW( &data
[1], feature
->Feature_Parent
);
4581 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
4587 uirow
= MSI_CreateRecord( 1 );
4588 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
4589 ui_actiondata( package
, szPublishFeatures
, uirow
);
4590 msiobj_release( &uirow
->hdr
);
4591 /* FIXME: call ui_progress? */
4596 RegCloseKey(userdata
);
4600 static UINT
msi_unpublish_feature(MSIPACKAGE
*package
, MSIFEATURE
*feature
)
4606 TRACE("unpublishing feature %s\n", debugstr_w(feature
->Feature
));
4608 r
= MSIREG_OpenFeaturesKey(package
->ProductCode
, package
->Context
,
4610 if (r
== ERROR_SUCCESS
)
4612 RegDeleteValueW(hkey
, feature
->Feature
);
4616 r
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, package
->Context
,
4618 if (r
== ERROR_SUCCESS
)
4620 RegDeleteValueW(hkey
, feature
->Feature
);
4624 uirow
= MSI_CreateRecord( 1 );
4625 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
4626 ui_actiondata( package
, szUnpublishFeatures
, uirow
);
4627 msiobj_release( &uirow
->hdr
);
4629 return ERROR_SUCCESS
;
4632 static UINT
ACTION_UnpublishFeatures(MSIPACKAGE
*package
)
4634 MSIFEATURE
*feature
;
4636 if (!msi_check_unpublish(package
))
4637 return ERROR_SUCCESS
;
4639 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4641 msi_unpublish_feature(package
, feature
);
4644 return ERROR_SUCCESS
;
4647 static UINT
msi_publish_install_properties(MSIPACKAGE
*package
, HKEY hkey
)
4651 WCHAR date
[9], *val
, *buffer
;
4652 const WCHAR
*prop
, *key
;
4654 static const WCHAR date_fmt
[] = {'%','i','%','0','2','i','%','0','2','i',0};
4655 static const WCHAR szWindowsInstaller
[] =
4656 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
4657 static const WCHAR modpath_fmt
[] =
4658 {'M','s','i','E','x','e','c','.','e','x','e',' ',
4659 '/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
4660 static const WCHAR szModifyPath
[] =
4661 {'M','o','d','i','f','y','P','a','t','h',0};
4662 static const WCHAR szUninstallString
[] =
4663 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
4664 static const WCHAR szEstimatedSize
[] =
4665 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
4666 static const WCHAR szProductLanguage
[] =
4667 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
4668 static const WCHAR szProductVersion
[] =
4669 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0};
4670 static const WCHAR szDisplayVersion
[] =
4671 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
4672 static const WCHAR szInstallSource
[] =
4673 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0};
4674 static const WCHAR szARPAUTHORIZEDCDFPREFIX
[] =
4675 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0};
4676 static const WCHAR szAuthorizedCDFPrefix
[] =
4677 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0};
4678 static const WCHAR szARPCONTACT
[] =
4679 {'A','R','P','C','O','N','T','A','C','T',0};
4680 static const WCHAR szContact
[] =
4681 {'C','o','n','t','a','c','t',0};
4682 static const WCHAR szARPCOMMENTS
[] =
4683 {'A','R','P','C','O','M','M','E','N','T','S',0};
4684 static const WCHAR szComments
[] =
4685 {'C','o','m','m','e','n','t','s',0};
4686 static const WCHAR szProductName
[] =
4687 {'P','r','o','d','u','c','t','N','a','m','e',0};
4688 static const WCHAR szDisplayName
[] =
4689 {'D','i','s','p','l','a','y','N','a','m','e',0};
4690 static const WCHAR szARPHELPLINK
[] =
4691 {'A','R','P','H','E','L','P','L','I','N','K',0};
4692 static const WCHAR szHelpLink
[] =
4693 {'H','e','l','p','L','i','n','k',0};
4694 static const WCHAR szARPHELPTELEPHONE
[] =
4695 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0};
4696 static const WCHAR szHelpTelephone
[] =
4697 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0};
4698 static const WCHAR szARPINSTALLLOCATION
[] =
4699 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0};
4700 static const WCHAR szInstallLocation
[] =
4701 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0};
4702 static const WCHAR szManufacturer
[] =
4703 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
4704 static const WCHAR szPublisher
[] =
4705 {'P','u','b','l','i','s','h','e','r',0};
4706 static const WCHAR szARPREADME
[] =
4707 {'A','R','P','R','E','A','D','M','E',0};
4708 static const WCHAR szReadme
[] =
4709 {'R','e','a','d','M','e',0};
4710 static const WCHAR szARPSIZE
[] =
4711 {'A','R','P','S','I','Z','E',0};
4712 static const WCHAR szSize
[] =
4713 {'S','i','z','e',0};
4714 static const WCHAR szARPURLINFOABOUT
[] =
4715 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0};
4716 static const WCHAR szURLInfoAbout
[] =
4717 {'U','R','L','I','n','f','o','A','b','o','u','t',0};
4718 static const WCHAR szARPURLUPDATEINFO
[] =
4719 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0};
4720 static const WCHAR szURLUpdateInfo
[] =
4721 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0};
4723 static const WCHAR
*propval
[] = {
4724 szARPAUTHORIZEDCDFPREFIX
, szAuthorizedCDFPrefix
,
4725 szARPCONTACT
, szContact
,
4726 szARPCOMMENTS
, szComments
,
4727 szProductName
, szDisplayName
,
4728 szARPHELPLINK
, szHelpLink
,
4729 szARPHELPTELEPHONE
, szHelpTelephone
,
4730 szARPINSTALLLOCATION
, szInstallLocation
,
4731 cszSourceDir
, szInstallSource
,
4732 szManufacturer
, szPublisher
,
4733 szARPREADME
, szReadme
,
4735 szARPURLINFOABOUT
, szURLInfoAbout
,
4736 szARPURLUPDATEINFO
, szURLUpdateInfo
,
4739 const WCHAR
**p
= propval
;
4745 val
= msi_dup_property(package
->db
, prop
);
4746 msi_reg_set_val_str(hkey
, key
, val
);
4750 msi_reg_set_val_dword(hkey
, szWindowsInstaller
, 1);
4752 size
= deformat_string(package
, modpath_fmt
, &buffer
);
4753 RegSetValueExW(hkey
, szModifyPath
, 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
4754 RegSetValueExW(hkey
, szUninstallString
, 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
4757 /* FIXME: Write real Estimated Size when we have it */
4758 msi_reg_set_val_dword(hkey
, szEstimatedSize
, 0);
4760 GetLocalTime(&systime
);
4761 sprintfW(date
, date_fmt
, systime
.wYear
, systime
.wMonth
, systime
.wDay
);
4762 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_INSTALLDATEW
, date
);
4764 langid
= msi_get_property_int(package
->db
, szProductLanguage
, 0);
4765 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
4767 buffer
= msi_dup_property(package
->db
, szProductVersion
);
4768 msi_reg_set_val_str(hkey
, szDisplayVersion
, buffer
);
4771 DWORD verdword
= msi_version_str_to_dword(buffer
);
4773 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
4774 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMAJORW
, verdword
>> 24);
4775 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMINORW
, (verdword
>> 16) & 0xFF);
4779 return ERROR_SUCCESS
;
4782 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
4784 WCHAR squashed_pc
[SQUISH_GUID_SIZE
];
4786 LPWSTR upgrade_code
;
4791 /* FIXME: also need to publish if the product is in advertise mode */
4792 if (!msi_check_publish(package
))
4793 return ERROR_SUCCESS
;
4795 rc
= MSIREG_OpenUninstallKey(package
, &hkey
, TRUE
);
4796 if (rc
!= ERROR_SUCCESS
)
4799 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
,
4800 NULL
, &props
, TRUE
);
4801 if (rc
!= ERROR_SUCCESS
)
4804 msi_reg_set_val_str( props
, INSTALLPROPERTY_LOCALPACKAGEW
, package
->db
->localfile
);
4805 msi_free( package
->db
->localfile
);
4806 package
->db
->localfile
= NULL
;
4808 rc
= msi_publish_install_properties(package
, hkey
);
4809 if (rc
!= ERROR_SUCCESS
)
4812 rc
= msi_publish_install_properties(package
, props
);
4813 if (rc
!= ERROR_SUCCESS
)
4816 upgrade_code
= msi_dup_property(package
->db
, szUpgradeCode
);
4819 MSIREG_OpenUpgradeCodesKey(upgrade_code
, &upgrade
, TRUE
);
4820 squash_guid(package
->ProductCode
, squashed_pc
);
4821 msi_reg_set_val_str(upgrade
, squashed_pc
, NULL
);
4822 RegCloseKey(upgrade
);
4823 msi_free(upgrade_code
);
4827 uirow
= MSI_CreateRecord( 1 );
4828 MSI_RecordSetStringW( uirow
, 1, package
->ProductCode
);
4829 ui_actiondata( package
, szRegisterProduct
, uirow
);
4830 msiobj_release( &uirow
->hdr
);
4833 return ERROR_SUCCESS
;
4836 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
4838 return execute_script(package
,INSTALL_SCRIPT
);
4841 static UINT
msi_unpublish_product(MSIPACKAGE
*package
, WCHAR
*remove
)
4843 WCHAR
*upgrade
, **features
;
4844 BOOL full_uninstall
= TRUE
;
4845 MSIFEATURE
*feature
;
4846 MSIPATCHINFO
*patch
;
4848 static const WCHAR szUpgradeCode
[] =
4849 {'U','p','g','r','a','d','e','C','o','d','e',0};
4851 features
= msi_split_string(remove
, ',');
4854 ERR("REMOVE feature list is empty!\n");
4855 return ERROR_FUNCTION_FAILED
;
4858 if (!lstrcmpW(features
[0], szAll
))
4859 full_uninstall
= TRUE
;
4862 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4864 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
4865 full_uninstall
= FALSE
;
4870 if (!full_uninstall
)
4871 return ERROR_SUCCESS
;
4873 MSIREG_DeleteProductKey(package
->ProductCode
);
4874 MSIREG_DeleteUserDataProductKey(package
->ProductCode
);
4875 MSIREG_DeleteUninstallKey(package
);
4877 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
4879 MSIREG_DeleteLocalClassesProductKey(package
->ProductCode
);
4880 MSIREG_DeleteLocalClassesFeaturesKey(package
->ProductCode
);
4884 MSIREG_DeleteUserProductKey(package
->ProductCode
);
4885 MSIREG_DeleteUserFeaturesKey(package
->ProductCode
);
4888 upgrade
= msi_dup_property(package
->db
, szUpgradeCode
);
4891 MSIREG_DeleteUserUpgradeCodesKey(upgrade
);
4895 LIST_FOR_EACH_ENTRY(patch
, &package
->patches
, MSIPATCHINFO
, entry
)
4897 MSIREG_DeleteUserDataPatchKey(patch
->patchcode
, package
->Context
);
4900 return ERROR_SUCCESS
;
4903 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
4908 /* turn off scheduling */
4909 package
->script
->CurrentlyScripting
= FALSE
;
4911 /* first do the same as an InstallExecute */
4912 rc
= ACTION_InstallExecute(package
);
4913 if (rc
!= ERROR_SUCCESS
)
4916 /* then handle Commit Actions */
4917 rc
= execute_script(package
,COMMIT_SCRIPT
);
4918 if (rc
!= ERROR_SUCCESS
)
4921 remove
= msi_dup_property(package
->db
, szRemove
);
4923 rc
= msi_unpublish_product(package
, remove
);
4929 UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
4931 static const WCHAR RunOnce
[] = {
4932 'S','o','f','t','w','a','r','e','\\',
4933 'M','i','c','r','o','s','o','f','t','\\',
4934 'W','i','n','d','o','w','s','\\',
4935 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4936 'R','u','n','O','n','c','e',0};
4937 static const WCHAR InstallRunOnce
[] = {
4938 'S','o','f','t','w','a','r','e','\\',
4939 'M','i','c','r','o','s','o','f','t','\\',
4940 'W','i','n','d','o','w','s','\\',
4941 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
4942 'I','n','s','t','a','l','l','e','r','\\',
4943 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
4945 static const WCHAR msiexec_fmt
[] = {
4947 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
4948 '\"','%','s','\"',0};
4949 static const WCHAR install_fmt
[] = {
4950 '/','I',' ','\"','%','s','\"',' ',
4951 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
4952 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
4953 WCHAR buffer
[256], sysdir
[MAX_PATH
];
4955 WCHAR squished_pc
[100];
4957 squash_guid(package
->ProductCode
,squished_pc
);
4959 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
4960 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
4961 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
4964 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
4967 TRACE("Reboot command %s\n",debugstr_w(buffer
));
4969 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
4970 sprintfW(buffer
,install_fmt
,package
->ProductCode
,squished_pc
);
4972 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
4975 return ERROR_INSTALL_SUSPEND
;
4978 static UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
4984 * We are currently doing what should be done here in the top level Install
4985 * however for Administrative and uninstalls this step will be needed
4987 if (!package
->PackagePath
)
4988 return ERROR_SUCCESS
;
4990 msi_set_sourcedir_props(package
, TRUE
);
4992 attrib
= GetFileAttributesW(package
->db
->path
);
4993 if (attrib
== INVALID_FILE_ATTRIBUTES
)
4999 rc
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
5000 package
->Context
, MSICODE_PRODUCT
,
5001 INSTALLPROPERTY_DISKPROMPTW
,NULL
,&size
);
5002 if (rc
== ERROR_MORE_DATA
)
5004 prompt
= msi_alloc(size
* sizeof(WCHAR
));
5005 MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
5006 package
->Context
, MSICODE_PRODUCT
,
5007 INSTALLPROPERTY_DISKPROMPTW
,prompt
,&size
);
5010 prompt
= strdupW(package
->db
->path
);
5012 msg
= generate_error_string(package
,1302,1,prompt
);
5013 while(attrib
== INVALID_FILE_ATTRIBUTES
)
5015 rc
= MessageBoxW(NULL
,msg
,NULL
,MB_OKCANCEL
);
5018 rc
= ERROR_INSTALL_USEREXIT
;
5021 attrib
= GetFileAttributesW(package
->db
->path
);
5027 return ERROR_SUCCESS
;
5032 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
5035 LPWSTR buffer
, productid
= NULL
;
5036 UINT i
, rc
= ERROR_SUCCESS
;
5039 static const WCHAR szPropKeys
[][80] =
5041 {'P','r','o','d','u','c','t','I','D',0},
5042 {'U','S','E','R','N','A','M','E',0},
5043 {'C','O','M','P','A','N','Y','N','A','M','E',0},
5047 static const WCHAR szRegKeys
[][80] =
5049 {'P','r','o','d','u','c','t','I','D',0},
5050 {'R','e','g','O','w','n','e','r',0},
5051 {'R','e','g','C','o','m','p','a','n','y',0},
5055 if (msi_check_unpublish(package
))
5057 MSIREG_DeleteUserDataProductKey(package
->ProductCode
);
5061 productid
= msi_dup_property( package
->db
, INSTALLPROPERTY_PRODUCTIDW
);
5065 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
,
5067 if (rc
!= ERROR_SUCCESS
)
5070 for( i
= 0; szPropKeys
[i
][0]; i
++ )
5072 buffer
= msi_dup_property( package
->db
, szPropKeys
[i
] );
5073 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
5078 uirow
= MSI_CreateRecord( 1 );
5079 MSI_RecordSetStringW( uirow
, 1, productid
);
5080 ui_actiondata( package
, szRegisterUser
, uirow
);
5081 msiobj_release( &uirow
->hdr
);
5083 msi_free(productid
);
5089 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
5093 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
5094 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
5099 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
5101 MSIPACKAGE
*package
= param
;
5102 LPCWSTR compgroupid
, component
, feature
, qualifier
, text
;
5103 LPWSTR advertise
= NULL
, output
= NULL
;
5111 feature
= MSI_RecordGetString(rec
, 5);
5112 feat
= get_loaded_feature(package
, feature
);
5114 return ERROR_SUCCESS
;
5116 if (feat
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
5117 feat
->ActionRequest
!= INSTALLSTATE_SOURCE
&&
5118 feat
->ActionRequest
!= INSTALLSTATE_ADVERTISED
)
5120 TRACE("Feature %s not scheduled for installation\n", debugstr_w(feature
));
5121 feat
->Action
= feat
->Installed
;
5122 return ERROR_SUCCESS
;
5125 component
= MSI_RecordGetString(rec
, 3);
5126 comp
= get_loaded_component(package
, component
);
5128 return ERROR_SUCCESS
;
5130 compgroupid
= MSI_RecordGetString(rec
,1);
5131 qualifier
= MSI_RecordGetString(rec
,2);
5133 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
5134 if (rc
!= ERROR_SUCCESS
)
5137 text
= MSI_RecordGetString(rec
,4);
5138 advertise
= create_component_advertise_string(package
, comp
, feature
);
5140 sz
= strlenW(advertise
);
5143 sz
+= lstrlenW(text
);
5146 sz
*= sizeof(WCHAR
);
5148 output
= msi_alloc_zero(sz
);
5149 strcpyW(output
,advertise
);
5150 msi_free(advertise
);
5153 strcatW(output
,text
);
5155 msi_reg_set_val_multi_str( hkey
, qualifier
, output
);
5162 uirow
= MSI_CreateRecord( 2 );
5163 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
5164 MSI_RecordSetStringW( uirow
, 2, qualifier
);
5165 ui_actiondata( package
, szPublishComponents
, uirow
);
5166 msiobj_release( &uirow
->hdr
);
5167 /* FIXME: call ui_progress? */
5173 * At present I am ignorning the advertised components part of this and only
5174 * focusing on the qualified component sets
5176 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
5180 static const WCHAR ExecSeqQuery
[] =
5181 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5182 '`','P','u','b','l','i','s','h',
5183 'C','o','m','p','o','n','e','n','t','`',0};
5185 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5186 if (rc
!= ERROR_SUCCESS
)
5187 return ERROR_SUCCESS
;
5189 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
5190 msiobj_release(&view
->hdr
);
5195 static UINT
ITERATE_UnpublishComponent( MSIRECORD
*rec
, LPVOID param
)
5197 static const WCHAR szInstallerComponents
[] = {
5198 'S','o','f','t','w','a','r','e','\\',
5199 'M','i','c','r','o','s','o','f','t','\\',
5200 'I','n','s','t','a','l','l','e','r','\\',
5201 'C','o','m','p','o','n','e','n','t','s','\\',0};
5203 MSIPACKAGE
*package
= param
;
5204 LPCWSTR compgroupid
, component
, feature
, qualifier
;
5208 WCHAR squashed
[GUID_SIZE
], keypath
[MAX_PATH
];
5211 feature
= MSI_RecordGetString( rec
, 5 );
5212 feat
= get_loaded_feature( package
, feature
);
5214 return ERROR_SUCCESS
;
5216 if (feat
->ActionRequest
!= INSTALLSTATE_ABSENT
)
5218 TRACE("Feature %s not scheduled for removal\n", debugstr_w(feature
));
5219 feat
->Action
= feat
->Installed
;
5220 return ERROR_SUCCESS
;
5223 component
= MSI_RecordGetString( rec
, 3 );
5224 comp
= get_loaded_component( package
, component
);
5226 return ERROR_SUCCESS
;
5228 compgroupid
= MSI_RecordGetString( rec
, 1 );
5229 qualifier
= MSI_RecordGetString( rec
, 2 );
5231 squash_guid( compgroupid
, squashed
);
5232 strcpyW( keypath
, szInstallerComponents
);
5233 strcatW( keypath
, squashed
);
5235 res
= RegDeleteKeyW( HKEY_CURRENT_USER
, keypath
);
5236 if (res
!= ERROR_SUCCESS
)
5238 WARN("Unable to delete component key %d\n", res
);
5241 uirow
= MSI_CreateRecord( 2 );
5242 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
5243 MSI_RecordSetStringW( uirow
, 2, qualifier
);
5244 ui_actiondata( package
, szUnpublishComponents
, uirow
);
5245 msiobj_release( &uirow
->hdr
);
5247 return ERROR_SUCCESS
;
5250 static UINT
ACTION_UnpublishComponents( MSIPACKAGE
*package
)
5254 static const WCHAR query
[] =
5255 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5256 '`','P','u','b','l','i','s','h',
5257 'C','o','m','p','o','n','e','n','t','`',0};
5259 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
5260 if (rc
!= ERROR_SUCCESS
)
5261 return ERROR_SUCCESS
;
5263 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnpublishComponent
, package
);
5264 msiobj_release( &view
->hdr
);
5269 static UINT
ITERATE_InstallService(MSIRECORD
*rec
, LPVOID param
)
5271 MSIPACKAGE
*package
= param
;
5274 SC_HANDLE hscm
, service
= NULL
;
5275 LPCWSTR comp
, depends
, pass
;
5276 LPWSTR name
= NULL
, disp
= NULL
;
5277 LPCWSTR load_order
, serv_name
, key
;
5278 DWORD serv_type
, start_type
;
5281 static const WCHAR query
[] =
5282 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
5283 '`','C','o','m','p','o','n','e','n','t','`',' ',
5284 'W','H','E','R','E',' ',
5285 '`','C','o','m','p','o','n','e','n','t','`',' ',
5286 '=','\'','%','s','\'',0};
5288 hscm
= OpenSCManagerW(NULL
, SERVICES_ACTIVE_DATABASEW
, GENERIC_WRITE
);
5291 ERR("Failed to open the SC Manager!\n");
5295 start_type
= MSI_RecordGetInteger(rec
, 5);
5296 if (start_type
== SERVICE_BOOT_START
|| start_type
== SERVICE_SYSTEM_START
)
5299 depends
= MSI_RecordGetString(rec
, 8);
5300 if (depends
&& *depends
)
5301 FIXME("Dependency list unhandled!\n");
5303 deformat_string(package
, MSI_RecordGetString(rec
, 2), &name
);
5304 deformat_string(package
, MSI_RecordGetString(rec
, 3), &disp
);
5305 serv_type
= MSI_RecordGetInteger(rec
, 4);
5306 err_control
= MSI_RecordGetInteger(rec
, 6);
5307 load_order
= MSI_RecordGetString(rec
, 7);
5308 serv_name
= MSI_RecordGetString(rec
, 9);
5309 pass
= MSI_RecordGetString(rec
, 10);
5310 comp
= MSI_RecordGetString(rec
, 12);
5312 /* fetch the service path */
5313 row
= MSI_QueryGetRecord(package
->db
, query
, comp
);
5316 ERR("Control query failed!\n");
5320 key
= MSI_RecordGetString(row
, 6);
5322 file
= get_loaded_file(package
, key
);
5323 msiobj_release(&row
->hdr
);
5326 ERR("Failed to load the service file\n");
5330 service
= CreateServiceW(hscm
, name
, disp
, GENERIC_ALL
, serv_type
,
5331 start_type
, err_control
, file
->TargetPath
,
5332 load_order
, NULL
, NULL
, serv_name
, pass
);
5335 if (GetLastError() != ERROR_SERVICE_EXISTS
)
5336 ERR("Failed to create service %s: %d\n", debugstr_w(name
), GetLastError());
5340 CloseServiceHandle(service
);
5341 CloseServiceHandle(hscm
);
5345 return ERROR_SUCCESS
;
5348 static UINT
ACTION_InstallServices( MSIPACKAGE
*package
)
5352 static const WCHAR ExecSeqQuery
[] =
5353 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5354 'S','e','r','v','i','c','e','I','n','s','t','a','l','l',0};
5356 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5357 if (rc
!= ERROR_SUCCESS
)
5358 return ERROR_SUCCESS
;
5360 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallService
, package
);
5361 msiobj_release(&view
->hdr
);
5366 /* converts arg1[~]arg2[~]arg3 to a list of ptrs to the strings */
5367 static LPCWSTR
*msi_service_args_to_vector(LPWSTR args
, DWORD
*numargs
)
5369 LPCWSTR
*vector
, *temp_vector
;
5373 static const WCHAR separator
[] = {'[','~',']',0};
5376 sep_len
= sizeof(separator
) / sizeof(WCHAR
) - 1;
5381 vector
= msi_alloc(sizeof(LPWSTR
));
5389 vector
[*numargs
- 1] = p
;
5391 if ((q
= strstrW(p
, separator
)))
5395 temp_vector
= msi_realloc(vector
, (*numargs
+ 1) * sizeof(LPWSTR
));
5401 vector
= temp_vector
;
5410 static UINT
ITERATE_StartService(MSIRECORD
*rec
, LPVOID param
)
5412 MSIPACKAGE
*package
= param
;
5415 SC_HANDLE scm
= NULL
, service
= NULL
;
5416 LPCWSTR component
, *vector
= NULL
;
5417 LPWSTR name
, args
, display_name
= NULL
;
5418 DWORD event
, numargs
, len
;
5419 UINT r
= ERROR_FUNCTION_FAILED
;
5421 component
= MSI_RecordGetString(rec
, 6);
5422 comp
= get_loaded_component(package
, component
);
5424 return ERROR_SUCCESS
;
5428 TRACE("component is disabled\n");
5429 return ERROR_SUCCESS
;
5432 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
5434 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
5435 comp
->Action
= comp
->Installed
;
5436 return ERROR_SUCCESS
;
5438 comp
->Action
= INSTALLSTATE_LOCAL
;
5440 deformat_string(package
, MSI_RecordGetString(rec
, 2), &name
);
5441 deformat_string(package
, MSI_RecordGetString(rec
, 4), &args
);
5442 event
= MSI_RecordGetInteger(rec
, 3);
5444 if (!(event
& msidbServiceControlEventStart
))
5450 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_CONNECT
);
5453 ERR("Failed to open the service control manager\n");
5458 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
5459 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
5461 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
5462 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
5465 service
= OpenServiceW(scm
, name
, SERVICE_START
);
5468 ERR("Failed to open service %s (%u)\n", debugstr_w(name
), GetLastError());
5472 vector
= msi_service_args_to_vector(args
, &numargs
);
5474 if (!StartServiceW(service
, numargs
, vector
) &&
5475 GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
)
5477 ERR("Failed to start service %s (%u)\n", debugstr_w(name
), GetLastError());
5484 uirow
= MSI_CreateRecord( 2 );
5485 MSI_RecordSetStringW( uirow
, 1, display_name
);
5486 MSI_RecordSetStringW( uirow
, 2, name
);
5487 ui_actiondata( package
, szStartServices
, uirow
);
5488 msiobj_release( &uirow
->hdr
);
5490 CloseServiceHandle(service
);
5491 CloseServiceHandle(scm
);
5496 msi_free(display_name
);
5500 static UINT
ACTION_StartServices( MSIPACKAGE
*package
)
5505 static const WCHAR query
[] = {
5506 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5507 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
5509 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
5510 if (rc
!= ERROR_SUCCESS
)
5511 return ERROR_SUCCESS
;
5513 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StartService
, package
);
5514 msiobj_release(&view
->hdr
);
5519 static BOOL
stop_service_dependents(SC_HANDLE scm
, SC_HANDLE service
)
5521 DWORD i
, needed
, count
;
5522 ENUM_SERVICE_STATUSW
*dependencies
;
5526 if (EnumDependentServicesW(service
, SERVICE_ACTIVE
, NULL
,
5527 0, &needed
, &count
))
5530 if (GetLastError() != ERROR_MORE_DATA
)
5533 dependencies
= msi_alloc(needed
);
5537 if (!EnumDependentServicesW(service
, SERVICE_ACTIVE
, dependencies
,
5538 needed
, &needed
, &count
))
5541 for (i
= 0; i
< count
; i
++)
5543 depserv
= OpenServiceW(scm
, dependencies
[i
].lpServiceName
,
5544 SERVICE_STOP
| SERVICE_QUERY_STATUS
);
5548 if (!ControlService(depserv
, SERVICE_CONTROL_STOP
, &ss
))
5555 msi_free(dependencies
);
5559 static UINT
stop_service( LPCWSTR name
)
5561 SC_HANDLE scm
= NULL
, service
= NULL
;
5562 SERVICE_STATUS status
;
5563 SERVICE_STATUS_PROCESS ssp
;
5566 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
5569 WARN("Failed to open the SCM: %d\n", GetLastError());
5573 service
= OpenServiceW(scm
, name
,
5575 SERVICE_QUERY_STATUS
|
5576 SERVICE_ENUMERATE_DEPENDENTS
);
5579 WARN("Failed to open service (%s): %d\n", debugstr_w(name
), GetLastError());
5583 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
, (LPBYTE
)&ssp
,
5584 sizeof(SERVICE_STATUS_PROCESS
), &needed
))
5586 WARN("Failed to query service status (%s): %d\n", debugstr_w(name
), GetLastError());
5590 if (ssp
.dwCurrentState
== SERVICE_STOPPED
)
5593 stop_service_dependents(scm
, service
);
5595 if (!ControlService(service
, SERVICE_CONTROL_STOP
, &status
))
5596 WARN("Failed to stop service (%s): %d\n", debugstr_w(name
), GetLastError());
5599 CloseServiceHandle(service
);
5600 CloseServiceHandle(scm
);
5602 return ERROR_SUCCESS
;
5605 static UINT
ITERATE_StopService( MSIRECORD
*rec
, LPVOID param
)
5607 MSIPACKAGE
*package
= param
;
5611 LPWSTR name
= NULL
, display_name
= NULL
;
5615 event
= MSI_RecordGetInteger( rec
, 3 );
5616 if (!(event
& msidbServiceControlEventStop
))
5617 return ERROR_SUCCESS
;
5619 component
= MSI_RecordGetString( rec
, 6 );
5620 comp
= get_loaded_component( package
, component
);
5622 return ERROR_SUCCESS
;
5626 TRACE("component is disabled\n");
5627 return ERROR_SUCCESS
;
5630 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
5632 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
5633 comp
->Action
= comp
->Installed
;
5634 return ERROR_SUCCESS
;
5636 comp
->Action
= INSTALLSTATE_ABSENT
;
5638 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_CONNECT
);
5641 ERR("Failed to open the service control manager\n");
5646 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
5647 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
5649 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
5650 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
5652 CloseServiceHandle( scm
);
5654 deformat_string( package
, MSI_RecordGetString( rec
, 2 ), &name
);
5655 stop_service( name
);
5658 uirow
= MSI_CreateRecord( 2 );
5659 MSI_RecordSetStringW( uirow
, 1, display_name
);
5660 MSI_RecordSetStringW( uirow
, 2, name
);
5661 ui_actiondata( package
, szStopServices
, uirow
);
5662 msiobj_release( &uirow
->hdr
);
5665 msi_free( display_name
);
5666 return ERROR_SUCCESS
;
5669 static UINT
ACTION_StopServices( MSIPACKAGE
*package
)
5674 static const WCHAR query
[] = {
5675 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5676 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
5678 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
5679 if (rc
!= ERROR_SUCCESS
)
5680 return ERROR_SUCCESS
;
5682 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StopService
, package
);
5683 msiobj_release(&view
->hdr
);
5688 static UINT
ITERATE_DeleteService( MSIRECORD
*rec
, LPVOID param
)
5690 MSIPACKAGE
*package
= param
;
5694 LPWSTR name
= NULL
, display_name
= NULL
;
5696 SC_HANDLE scm
= NULL
, service
= NULL
;
5698 event
= MSI_RecordGetInteger( rec
, 3 );
5699 if (!(event
& msidbServiceControlEventDelete
))
5700 return ERROR_SUCCESS
;
5702 component
= MSI_RecordGetString(rec
, 6);
5703 comp
= get_loaded_component(package
, component
);
5705 return ERROR_SUCCESS
;
5709 TRACE("component is disabled\n");
5710 return ERROR_SUCCESS
;
5713 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
5715 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
5716 comp
->Action
= comp
->Installed
;
5717 return ERROR_SUCCESS
;
5719 comp
->Action
= INSTALLSTATE_ABSENT
;
5721 deformat_string( package
, MSI_RecordGetString(rec
, 2), &name
);
5722 stop_service( name
);
5724 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
5727 WARN("Failed to open the SCM: %d\n", GetLastError());
5732 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
5733 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
5735 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
5736 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
5739 service
= OpenServiceW( scm
, name
, DELETE
);
5742 WARN("Failed to open service (%s): %u\n", debugstr_w(name
), GetLastError());
5746 if (!DeleteService( service
))
5747 WARN("Failed to delete service (%s): %u\n", debugstr_w(name
), GetLastError());
5750 uirow
= MSI_CreateRecord( 2 );
5751 MSI_RecordSetStringW( uirow
, 1, display_name
);
5752 MSI_RecordSetStringW( uirow
, 2, name
);
5753 ui_actiondata( package
, szDeleteServices
, uirow
);
5754 msiobj_release( &uirow
->hdr
);
5756 CloseServiceHandle( service
);
5757 CloseServiceHandle( scm
);
5759 msi_free( display_name
);
5761 return ERROR_SUCCESS
;
5764 static UINT
ACTION_DeleteServices( MSIPACKAGE
*package
)
5769 static const WCHAR query
[] = {
5770 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5771 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
5773 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
5774 if (rc
!= ERROR_SUCCESS
)
5775 return ERROR_SUCCESS
;
5777 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_DeleteService
, package
);
5778 msiobj_release( &view
->hdr
);
5783 static MSIFILE
*msi_find_file( MSIPACKAGE
*package
, LPCWSTR filename
)
5787 LIST_FOR_EACH_ENTRY(file
, &package
->files
, MSIFILE
, entry
)
5789 if (!lstrcmpW(file
->File
, filename
))
5796 static UINT
ITERATE_InstallODBCDriver( MSIRECORD
*rec
, LPVOID param
)
5798 MSIPACKAGE
*package
= param
;
5799 LPWSTR driver
, driver_path
, ptr
;
5800 WCHAR outpath
[MAX_PATH
];
5801 MSIFILE
*driver_file
, *setup_file
;
5805 UINT r
= ERROR_SUCCESS
;
5807 static const WCHAR driver_fmt
[] = {
5808 'D','r','i','v','e','r','=','%','s',0};
5809 static const WCHAR setup_fmt
[] = {
5810 'S','e','t','u','p','=','%','s',0};
5811 static const WCHAR usage_fmt
[] = {
5812 'F','i','l','e','U','s','a','g','e','=','1',0};
5814 desc
= MSI_RecordGetString(rec
, 3);
5816 driver_file
= msi_find_file(package
, MSI_RecordGetString(rec
, 4));
5817 setup_file
= msi_find_file(package
, MSI_RecordGetString(rec
, 5));
5821 ERR("ODBC Driver entry not found!\n");
5822 return ERROR_FUNCTION_FAILED
;
5825 len
= lstrlenW(desc
) + lstrlenW(driver_fmt
) + lstrlenW(driver_file
->FileName
);
5827 len
+= lstrlenW(setup_fmt
) + lstrlenW(setup_file
->FileName
);
5828 len
+= lstrlenW(usage_fmt
) + 2; /* \0\0 */
5830 driver
= msi_alloc(len
* sizeof(WCHAR
));
5832 return ERROR_OUTOFMEMORY
;
5835 lstrcpyW(ptr
, desc
);
5836 ptr
+= lstrlenW(ptr
) + 1;
5838 len
= sprintfW(ptr
, driver_fmt
, driver_file
->FileName
);
5843 len
= sprintfW(ptr
, setup_fmt
, setup_file
->FileName
);
5847 lstrcpyW(ptr
, usage_fmt
);
5848 ptr
+= lstrlenW(ptr
) + 1;
5851 driver_path
= strdupW(driver_file
->TargetPath
);
5852 ptr
= strrchrW(driver_path
, '\\');
5853 if (ptr
) *ptr
= '\0';
5855 if (!SQLInstallDriverExW(driver
, driver_path
, outpath
, MAX_PATH
,
5856 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
5858 ERR("Failed to install SQL driver!\n");
5859 r
= ERROR_FUNCTION_FAILED
;
5862 uirow
= MSI_CreateRecord( 5 );
5863 MSI_RecordSetStringW( uirow
, 1, desc
);
5864 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
5865 MSI_RecordSetStringW( uirow
, 3, driver_file
->Component
->Directory
);
5866 ui_actiondata( package
, szInstallODBC
, uirow
);
5867 msiobj_release( &uirow
->hdr
);
5870 msi_free(driver_path
);
5875 static UINT
ITERATE_InstallODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
5877 MSIPACKAGE
*package
= param
;
5878 LPWSTR translator
, translator_path
, ptr
;
5879 WCHAR outpath
[MAX_PATH
];
5880 MSIFILE
*translator_file
, *setup_file
;
5884 UINT r
= ERROR_SUCCESS
;
5886 static const WCHAR translator_fmt
[] = {
5887 'T','r','a','n','s','l','a','t','o','r','=','%','s',0};
5888 static const WCHAR setup_fmt
[] = {
5889 'S','e','t','u','p','=','%','s',0};
5891 desc
= MSI_RecordGetString(rec
, 3);
5893 translator_file
= msi_find_file(package
, MSI_RecordGetString(rec
, 4));
5894 setup_file
= msi_find_file(package
, MSI_RecordGetString(rec
, 5));
5896 if (!translator_file
)
5898 ERR("ODBC Translator entry not found!\n");
5899 return ERROR_FUNCTION_FAILED
;
5902 len
= lstrlenW(desc
) + lstrlenW(translator_fmt
) + lstrlenW(translator_file
->FileName
) + 2; /* \0\0 */
5904 len
+= lstrlenW(setup_fmt
) + lstrlenW(setup_file
->FileName
);
5906 translator
= msi_alloc(len
* sizeof(WCHAR
));
5908 return ERROR_OUTOFMEMORY
;
5911 lstrcpyW(ptr
, desc
);
5912 ptr
+= lstrlenW(ptr
) + 1;
5914 len
= sprintfW(ptr
, translator_fmt
, translator_file
->FileName
);
5919 len
= sprintfW(ptr
, setup_fmt
, setup_file
->FileName
);
5924 translator_path
= strdupW(translator_file
->TargetPath
);
5925 ptr
= strrchrW(translator_path
, '\\');
5926 if (ptr
) *ptr
= '\0';
5928 if (!SQLInstallTranslatorExW(translator
, translator_path
, outpath
, MAX_PATH
,
5929 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
5931 ERR("Failed to install SQL translator!\n");
5932 r
= ERROR_FUNCTION_FAILED
;
5935 uirow
= MSI_CreateRecord( 5 );
5936 MSI_RecordSetStringW( uirow
, 1, desc
);
5937 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
5938 MSI_RecordSetStringW( uirow
, 3, translator_file
->Component
->Directory
);
5939 ui_actiondata( package
, szInstallODBC
, uirow
);
5940 msiobj_release( &uirow
->hdr
);
5942 msi_free(translator
);
5943 msi_free(translator_path
);
5948 static UINT
ITERATE_InstallODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
5950 MSIPACKAGE
*package
= param
;
5952 LPCWSTR desc
, driver
;
5953 WORD request
= ODBC_ADD_SYS_DSN
;
5956 UINT r
= ERROR_SUCCESS
;
5959 static const WCHAR attrs_fmt
[] = {
5960 'D','S','N','=','%','s',0 };
5962 desc
= MSI_RecordGetString(rec
, 3);
5963 driver
= MSI_RecordGetString(rec
, 4);
5964 registration
= MSI_RecordGetInteger(rec
, 5);
5966 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_ADD_SYS_DSN
;
5967 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_ADD_DSN
;
5969 len
= lstrlenW(attrs_fmt
) + lstrlenW(desc
) + 2; /* \0\0 */
5970 attrs
= msi_alloc(len
* sizeof(WCHAR
));
5972 return ERROR_OUTOFMEMORY
;
5974 len
= sprintfW(attrs
, attrs_fmt
, desc
);
5977 if (!SQLConfigDataSourceW(NULL
, request
, driver
, attrs
))
5979 ERR("Failed to install SQL data source!\n");
5980 r
= ERROR_FUNCTION_FAILED
;
5983 uirow
= MSI_CreateRecord( 5 );
5984 MSI_RecordSetStringW( uirow
, 1, desc
);
5985 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
5986 MSI_RecordSetInteger( uirow
, 3, request
);
5987 ui_actiondata( package
, szInstallODBC
, uirow
);
5988 msiobj_release( &uirow
->hdr
);
5995 static UINT
ACTION_InstallODBC( MSIPACKAGE
*package
)
6000 static const WCHAR driver_query
[] = {
6001 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6002 'O','D','B','C','D','r','i','v','e','r',0 };
6004 static const WCHAR translator_query
[] = {
6005 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6006 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0 };
6008 static const WCHAR source_query
[] = {
6009 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6010 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0 };
6012 rc
= MSI_DatabaseOpenViewW(package
->db
, driver_query
, &view
);
6013 if (rc
!= ERROR_SUCCESS
)
6014 return ERROR_SUCCESS
;
6016 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDriver
, package
);
6017 msiobj_release(&view
->hdr
);
6019 rc
= MSI_DatabaseOpenViewW(package
->db
, translator_query
, &view
);
6020 if (rc
!= ERROR_SUCCESS
)
6021 return ERROR_SUCCESS
;
6023 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCTranslator
, package
);
6024 msiobj_release(&view
->hdr
);
6026 rc
= MSI_DatabaseOpenViewW(package
->db
, source_query
, &view
);
6027 if (rc
!= ERROR_SUCCESS
)
6028 return ERROR_SUCCESS
;
6030 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDataSource
, package
);
6031 msiobj_release(&view
->hdr
);
6036 static UINT
ITERATE_RemoveODBCDriver( MSIRECORD
*rec
, LPVOID param
)
6038 MSIPACKAGE
*package
= param
;
6043 desc
= MSI_RecordGetString( rec
, 3 );
6044 if (!SQLRemoveDriverW( desc
, FALSE
, &usage
))
6046 WARN("Failed to remove ODBC driver\n");
6050 FIXME("Usage count reached 0\n");
6053 uirow
= MSI_CreateRecord( 2 );
6054 MSI_RecordSetStringW( uirow
, 1, desc
);
6055 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6056 ui_actiondata( package
, szRemoveODBC
, uirow
);
6057 msiobj_release( &uirow
->hdr
);
6059 return ERROR_SUCCESS
;
6062 static UINT
ITERATE_RemoveODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
6064 MSIPACKAGE
*package
= param
;
6069 desc
= MSI_RecordGetString( rec
, 3 );
6070 if (!SQLRemoveTranslatorW( desc
, &usage
))
6072 WARN("Failed to remove ODBC translator\n");
6076 FIXME("Usage count reached 0\n");
6079 uirow
= MSI_CreateRecord( 2 );
6080 MSI_RecordSetStringW( uirow
, 1, desc
);
6081 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6082 ui_actiondata( package
, szRemoveODBC
, uirow
);
6083 msiobj_release( &uirow
->hdr
);
6085 return ERROR_SUCCESS
;
6088 static UINT
ITERATE_RemoveODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
6090 MSIPACKAGE
*package
= param
;
6093 LPCWSTR desc
, driver
;
6094 WORD request
= ODBC_REMOVE_SYS_DSN
;
6098 static const WCHAR attrs_fmt
[] = {
6099 'D','S','N','=','%','s',0 };
6101 desc
= MSI_RecordGetString( rec
, 3 );
6102 driver
= MSI_RecordGetString( rec
, 4 );
6103 registration
= MSI_RecordGetInteger( rec
, 5 );
6105 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_REMOVE_SYS_DSN
;
6106 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_REMOVE_DSN
;
6108 len
= strlenW( attrs_fmt
) + strlenW( desc
) + 2; /* \0\0 */
6109 attrs
= msi_alloc( len
* sizeof(WCHAR
) );
6111 return ERROR_OUTOFMEMORY
;
6113 FIXME("Use ODBCSourceAttribute table\n");
6115 len
= sprintfW( attrs
, attrs_fmt
, desc
);
6118 if (!SQLConfigDataSourceW( NULL
, request
, driver
, attrs
))
6120 WARN("Failed to remove ODBC data source\n");
6124 uirow
= MSI_CreateRecord( 3 );
6125 MSI_RecordSetStringW( uirow
, 1, desc
);
6126 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6127 MSI_RecordSetInteger( uirow
, 3, request
);
6128 ui_actiondata( package
, szRemoveODBC
, uirow
);
6129 msiobj_release( &uirow
->hdr
);
6131 return ERROR_SUCCESS
;
6134 static UINT
ACTION_RemoveODBC( MSIPACKAGE
*package
)
6139 static const WCHAR driver_query
[] = {
6140 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6141 'O','D','B','C','D','r','i','v','e','r',0 };
6143 static const WCHAR translator_query
[] = {
6144 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6145 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0 };
6147 static const WCHAR source_query
[] = {
6148 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6149 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0 };
6151 rc
= MSI_DatabaseOpenViewW( package
->db
, driver_query
, &view
);
6152 if (rc
!= ERROR_SUCCESS
)
6153 return ERROR_SUCCESS
;
6155 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDriver
, package
);
6156 msiobj_release( &view
->hdr
);
6158 rc
= MSI_DatabaseOpenViewW( package
->db
, translator_query
, &view
);
6159 if (rc
!= ERROR_SUCCESS
)
6160 return ERROR_SUCCESS
;
6162 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCTranslator
, package
);
6163 msiobj_release( &view
->hdr
);
6165 rc
= MSI_DatabaseOpenViewW( package
->db
, source_query
, &view
);
6166 if (rc
!= ERROR_SUCCESS
)
6167 return ERROR_SUCCESS
;
6169 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDataSource
, package
);
6170 msiobj_release( &view
->hdr
);
6175 #define ENV_ACT_SETALWAYS 0x1
6176 #define ENV_ACT_SETABSENT 0x2
6177 #define ENV_ACT_REMOVE 0x4
6178 #define ENV_ACT_REMOVEMATCH 0x8
6180 #define ENV_MOD_MACHINE 0x20000000
6181 #define ENV_MOD_APPEND 0x40000000
6182 #define ENV_MOD_PREFIX 0x80000000
6183 #define ENV_MOD_MASK 0xC0000000
6185 #define check_flag_combo(x, y) ((x) & ~(y)) == (y)
6187 static UINT
env_parse_flags( LPCWSTR
*name
, LPCWSTR
*value
, DWORD
*flags
)
6189 LPCWSTR cptr
= *name
;
6191 static const WCHAR prefix
[] = {'[','~',']',0};
6192 static const int prefix_len
= 3;
6198 *flags
|= ENV_ACT_SETALWAYS
;
6199 else if (*cptr
== '+')
6200 *flags
|= ENV_ACT_SETABSENT
;
6201 else if (*cptr
== '-')
6202 *flags
|= ENV_ACT_REMOVE
;
6203 else if (*cptr
== '!')
6204 *flags
|= ENV_ACT_REMOVEMATCH
;
6205 else if (*cptr
== '*')
6206 *flags
|= ENV_MOD_MACHINE
;
6216 ERR("Missing environment variable\n");
6217 return ERROR_FUNCTION_FAILED
;
6222 LPCWSTR ptr
= *value
;
6223 if (!strncmpW(ptr
, prefix
, prefix_len
))
6225 if (ptr
[prefix_len
] == szSemiColon
[0])
6227 *flags
|= ENV_MOD_APPEND
;
6228 *value
+= lstrlenW(prefix
);
6235 else if (lstrlenW(*value
) >= prefix_len
)
6237 ptr
+= lstrlenW(ptr
) - prefix_len
;
6238 if (!lstrcmpW(ptr
, prefix
))
6240 if ((ptr
-1) > *value
&& *(ptr
-1) == szSemiColon
[0])
6242 *flags
|= ENV_MOD_PREFIX
;
6243 /* the "[~]" will be removed by deformat_string */;
6253 if (check_flag_combo(*flags
, ENV_ACT_SETALWAYS
| ENV_ACT_SETABSENT
) ||
6254 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETABSENT
) ||
6255 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETALWAYS
) ||
6256 check_flag_combo(*flags
, ENV_ACT_SETABSENT
| ENV_MOD_MASK
))
6258 ERR("Invalid flags: %08x\n", *flags
);
6259 return ERROR_FUNCTION_FAILED
;
6263 *flags
= ENV_ACT_SETALWAYS
| ENV_ACT_REMOVE
;
6265 return ERROR_SUCCESS
;
6268 static UINT
open_env_key( DWORD flags
, HKEY
*key
)
6270 static const WCHAR user_env
[] =
6271 {'E','n','v','i','r','o','n','m','e','n','t',0};
6272 static const WCHAR machine_env
[] =
6273 {'S','y','s','t','e','m','\\',
6274 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
6275 'C','o','n','t','r','o','l','\\',
6276 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
6277 'E','n','v','i','r','o','n','m','e','n','t',0};
6282 if (flags
& ENV_MOD_MACHINE
)
6285 root
= HKEY_LOCAL_MACHINE
;
6290 root
= HKEY_CURRENT_USER
;
6293 res
= RegOpenKeyExW( root
, env
, 0, KEY_ALL_ACCESS
, key
);
6294 if (res
!= ERROR_SUCCESS
)
6296 WARN("Failed to open key %s (%d)\n", debugstr_w(env
), res
);
6297 return ERROR_FUNCTION_FAILED
;
6300 return ERROR_SUCCESS
;
6303 static UINT
ITERATE_WriteEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
6305 MSIPACKAGE
*package
= param
;
6306 LPCWSTR name
, value
, component
;
6307 LPWSTR data
= NULL
, newval
= NULL
, deformatted
= NULL
, ptr
;
6308 DWORD flags
, type
, size
;
6315 component
= MSI_RecordGetString(rec
, 4);
6316 comp
= get_loaded_component(package
, component
);
6318 return ERROR_SUCCESS
;
6322 TRACE("component is disabled\n");
6323 return ERROR_SUCCESS
;
6326 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
6328 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
6329 comp
->Action
= comp
->Installed
;
6330 return ERROR_SUCCESS
;
6332 comp
->Action
= INSTALLSTATE_LOCAL
;
6334 name
= MSI_RecordGetString(rec
, 2);
6335 value
= MSI_RecordGetString(rec
, 3);
6337 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
6339 res
= env_parse_flags(&name
, &value
, &flags
);
6340 if (res
!= ERROR_SUCCESS
|| !value
)
6343 if (value
&& !deformat_string(package
, value
, &deformatted
))
6345 res
= ERROR_OUTOFMEMORY
;
6349 value
= deformatted
;
6351 res
= open_env_key( flags
, &env
);
6352 if (res
!= ERROR_SUCCESS
)
6355 if (flags
& ENV_MOD_MACHINE
)
6356 action
|= 0x20000000;
6360 res
= RegQueryValueExW(env
, name
, NULL
, &type
, NULL
, &size
);
6361 if ((res
!= ERROR_SUCCESS
&& res
!= ERROR_FILE_NOT_FOUND
) ||
6362 (res
== ERROR_SUCCESS
&& type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
))
6365 if ((res
== ERROR_FILE_NOT_FOUND
|| !(flags
& ENV_MOD_MASK
)))
6369 /* Nothing to do. */
6372 res
= ERROR_SUCCESS
;
6376 /* If we are appending but the string was empty, strip ; */
6377 if ((flags
& ENV_MOD_APPEND
) && (value
[0] == szSemiColon
[0])) value
++;
6379 size
= (lstrlenW(value
) + 1) * sizeof(WCHAR
);
6380 newval
= strdupW(value
);
6383 res
= ERROR_OUTOFMEMORY
;
6391 /* Contrary to MSDN, +-variable to [~];path works */
6392 if (flags
& ENV_ACT_SETABSENT
&& !(flags
& ENV_MOD_MASK
))
6394 res
= ERROR_SUCCESS
;
6398 data
= msi_alloc(size
);
6402 return ERROR_OUTOFMEMORY
;
6405 res
= RegQueryValueExW(env
, name
, NULL
, &type
, (LPVOID
)data
, &size
);
6406 if (res
!= ERROR_SUCCESS
)
6409 if (flags
& ENV_ACT_REMOVEMATCH
&& (!value
|| !lstrcmpW(data
, value
)))
6412 res
= RegDeleteValueW(env
, name
);
6413 if (res
!= ERROR_SUCCESS
)
6414 WARN("Failed to remove value %s (%d)\n", debugstr_w(name
), res
);
6418 size
= (lstrlenW(data
) + 1) * sizeof(WCHAR
);
6419 if (flags
& ENV_MOD_MASK
)
6423 if (flags
& ENV_MOD_APPEND
) multiplier
++;
6424 if (flags
& ENV_MOD_PREFIX
) multiplier
++;
6425 mod_size
= lstrlenW(value
) * multiplier
;
6426 size
+= mod_size
* sizeof(WCHAR
);
6429 newval
= msi_alloc(size
);
6433 res
= ERROR_OUTOFMEMORY
;
6437 if (flags
& ENV_MOD_PREFIX
)
6439 lstrcpyW(newval
, value
);
6440 ptr
= newval
+ lstrlenW(value
);
6441 action
|= 0x80000000;
6444 lstrcpyW(ptr
, data
);
6446 if (flags
& ENV_MOD_APPEND
)
6448 lstrcatW(newval
, value
);
6449 action
|= 0x40000000;
6452 TRACE("setting %s to %s\n", debugstr_w(name
), debugstr_w(newval
));
6453 res
= RegSetValueExW(env
, name
, 0, type
, (LPVOID
)newval
, size
);
6456 WARN("Failed to set %s to %s (%d)\n", debugstr_w(name
), debugstr_w(newval
), res
);
6460 uirow
= MSI_CreateRecord( 3 );
6461 MSI_RecordSetStringW( uirow
, 1, name
);
6462 MSI_RecordSetStringW( uirow
, 2, newval
);
6463 MSI_RecordSetInteger( uirow
, 3, action
);
6464 ui_actiondata( package
, szWriteEnvironmentStrings
, uirow
);
6465 msiobj_release( &uirow
->hdr
);
6467 if (env
) RegCloseKey(env
);
6468 msi_free(deformatted
);
6474 static UINT
ACTION_WriteEnvironmentStrings( MSIPACKAGE
*package
)
6478 static const WCHAR ExecSeqQuery
[] =
6479 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6480 '`','E','n','v','i','r','o','n','m','e','n','t','`',0};
6481 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
6482 if (rc
!= ERROR_SUCCESS
)
6483 return ERROR_SUCCESS
;
6485 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteEnvironmentString
, package
);
6486 msiobj_release(&view
->hdr
);
6491 static UINT
ITERATE_RemoveEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
6493 MSIPACKAGE
*package
= param
;
6494 LPCWSTR name
, value
, component
;
6495 LPWSTR deformatted
= NULL
;
6504 component
= MSI_RecordGetString( rec
, 4 );
6505 comp
= get_loaded_component( package
, component
);
6507 return ERROR_SUCCESS
;
6511 TRACE("component is disabled\n");
6512 return ERROR_SUCCESS
;
6515 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
6517 TRACE("Component not scheduled for removal: %s\n", debugstr_w(component
));
6518 comp
->Action
= comp
->Installed
;
6519 return ERROR_SUCCESS
;
6521 comp
->Action
= INSTALLSTATE_ABSENT
;
6523 name
= MSI_RecordGetString( rec
, 2 );
6524 value
= MSI_RecordGetString( rec
, 3 );
6526 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
6528 r
= env_parse_flags( &name
, &value
, &flags
);
6529 if (r
!= ERROR_SUCCESS
)
6532 if (!(flags
& ENV_ACT_REMOVE
))
6534 TRACE("Environment variable %s not marked for removal\n", debugstr_w(name
));
6535 return ERROR_SUCCESS
;
6538 if (value
&& !deformat_string( package
, value
, &deformatted
))
6539 return ERROR_OUTOFMEMORY
;
6541 value
= deformatted
;
6543 r
= open_env_key( flags
, &env
);
6544 if (r
!= ERROR_SUCCESS
)
6550 if (flags
& ENV_MOD_MACHINE
)
6551 action
|= 0x20000000;
6553 TRACE("Removing %s\n", debugstr_w(name
));
6555 res
= RegDeleteValueW( env
, name
);
6556 if (res
!= ERROR_SUCCESS
)
6558 WARN("Failed to delete value %s (%d)\n", debugstr_w(name
), res
);
6563 uirow
= MSI_CreateRecord( 3 );
6564 MSI_RecordSetStringW( uirow
, 1, name
);
6565 MSI_RecordSetStringW( uirow
, 2, value
);
6566 MSI_RecordSetInteger( uirow
, 3, action
);
6567 ui_actiondata( package
, szRemoveEnvironmentStrings
, uirow
);
6568 msiobj_release( &uirow
->hdr
);
6570 if (env
) RegCloseKey( env
);
6571 msi_free( deformatted
);
6575 static UINT
ACTION_RemoveEnvironmentStrings( MSIPACKAGE
*package
)
6579 static const WCHAR query
[] =
6580 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6581 '`','E','n','v','i','r','o','n','m','e','n','t','`',0};
6583 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
6584 if (rc
!= ERROR_SUCCESS
)
6585 return ERROR_SUCCESS
;
6587 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveEnvironmentString
, package
);
6588 msiobj_release( &view
->hdr
);
6593 typedef struct tagMSIASSEMBLY
6596 MSICOMPONENT
*component
;
6597 MSIFEATURE
*feature
;
6601 LPWSTR display_name
;
6606 static HRESULT (WINAPI
*pCreateAssemblyCache
)(IAssemblyCache
**ppAsmCache
,
6608 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR szDllName
, LPCWSTR szVersion
,
6609 LPVOID pvReserved
, HMODULE
*phModDll
);
6611 static BOOL
init_functionpointers(void)
6617 static const WCHAR szFusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
6619 hmscoree
= LoadLibraryA("mscoree.dll");
6622 WARN("mscoree.dll not available\n");
6626 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
6627 if (!pLoadLibraryShim
)
6629 WARN("LoadLibraryShim not available\n");
6630 FreeLibrary(hmscoree
);
6634 hr
= pLoadLibraryShim(szFusion
, NULL
, NULL
, &hfusion
);
6637 WARN("fusion.dll not available\n");
6638 FreeLibrary(hmscoree
);
6642 pCreateAssemblyCache
= (void *)GetProcAddress(hfusion
, "CreateAssemblyCache");
6644 FreeLibrary(hmscoree
);
6648 static UINT
install_assembly(MSIPACKAGE
*package
, MSIASSEMBLY
*assembly
,
6651 IAssemblyCache
*cache
;
6654 UINT r
= ERROR_FUNCTION_FAILED
;
6656 TRACE("installing assembly: %s\n", debugstr_w(path
));
6658 uirow
= MSI_CreateRecord( 2 );
6659 MSI_RecordSetStringW( uirow
, 2, assembly
->display_name
);
6660 ui_actiondata( package
, szMsiPublishAssemblies
, uirow
);
6661 msiobj_release( &uirow
->hdr
);
6663 if (assembly
->feature
)
6664 msi_feature_set_state(package
, assembly
->feature
, INSTALLSTATE_LOCAL
);
6666 if (assembly
->manifest
)
6667 FIXME("Manifest unhandled\n");
6669 if (assembly
->application
)
6671 FIXME("Assembly should be privately installed\n");
6672 return ERROR_SUCCESS
;
6675 if (assembly
->attributes
== msidbAssemblyAttributesWin32
)
6677 FIXME("Win32 assemblies not handled\n");
6678 return ERROR_SUCCESS
;
6681 hr
= pCreateAssemblyCache(&cache
, 0);
6685 hr
= IAssemblyCache_InstallAssembly(cache
, 0, path
, NULL
);
6687 ERR("Failed to install assembly: %s %08x\n", debugstr_w(path
), hr
);
6692 IAssemblyCache_Release(cache
);
6696 typedef struct tagASSEMBLY_LIST
6698 MSIPACKAGE
*package
;
6699 IAssemblyCache
*cache
;
6700 struct list
*assemblies
;
6703 typedef struct tagASSEMBLY_NAME
6711 static UINT
parse_assembly_name(MSIRECORD
*rec
, LPVOID param
)
6713 ASSEMBLY_NAME
*asmname
= param
;
6714 LPCWSTR name
= MSI_RecordGetString(rec
, 2);
6715 LPWSTR val
= msi_dup_record_field(rec
, 3);
6717 static const WCHAR Name
[] = {'N','a','m','e',0};
6718 static const WCHAR Version
[] = {'V','e','r','s','i','o','n',0};
6719 static const WCHAR Culture
[] = {'C','u','l','t','u','r','e',0};
6720 static const WCHAR PublicKeyToken
[] = {
6721 'P','u','b','l','i','c','K','e','y','T','o','k','e','n',0};
6723 if (!strcmpiW(name
, Name
))
6724 asmname
->name
= val
;
6725 else if (!strcmpiW(name
, Version
))
6726 asmname
->version
= val
;
6727 else if (!strcmpiW(name
, Culture
))
6728 asmname
->culture
= val
;
6729 else if (!strcmpiW(name
, PublicKeyToken
))
6730 asmname
->pubkeytoken
= val
;
6734 return ERROR_SUCCESS
;
6737 static void append_str(LPWSTR
*str
, DWORD
*size
, LPCWSTR append
)
6741 *size
= lstrlenW(append
) + 1;
6742 *str
= msi_alloc((*size
) * sizeof(WCHAR
));
6743 lstrcpyW(*str
, append
);
6747 (*size
) += lstrlenW(append
);
6748 *str
= msi_realloc(*str
, (*size
) * sizeof(WCHAR
));
6749 lstrcatW(*str
, append
);
6752 static WCHAR
*get_assembly_display_name( MSIDATABASE
*db
, MSICOMPONENT
*comp
)
6754 static const WCHAR separator
[] = {',',' ',0};
6755 static const WCHAR Version
[] = {'V','e','r','s','i','o','n','=',0};
6756 static const WCHAR Culture
[] = {'C','u','l','t','u','r','e','=',0};
6757 static const WCHAR PublicKeyToken
[] = {'P','u','b','l','i','c','K','e','y','T','o','k','e','n','=',0};
6758 static const WCHAR query
[] = {
6759 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6760 '`','M','s','i','A','s','s','e','m','b','l','y','N','a','m','e','`',' ',
6761 'W','H','E','R','E',' ','`','C','o','m','p','o','n','e','n','t','_','`',
6762 '=','\'','%','s','\'',0};
6765 LPWSTR display_name
;
6769 display_name
= NULL
;
6770 memset( &name
, 0, sizeof(ASSEMBLY_NAME
) );
6772 r
= MSI_OpenQuery( db
, &view
, query
, comp
->Component
);
6773 if (r
!= ERROR_SUCCESS
)
6776 MSI_IterateRecords( view
, NULL
, parse_assembly_name
, &name
);
6777 msiobj_release( &view
->hdr
);
6781 ERR("No assembly name specified!\n");
6785 append_str( &display_name
, &size
, name
.name
);
6789 append_str( &display_name
, &size
, separator
);
6790 append_str( &display_name
, &size
, Version
);
6791 append_str( &display_name
, &size
, name
.version
);
6795 append_str( &display_name
, &size
, separator
);
6796 append_str( &display_name
, &size
, Culture
);
6797 append_str( &display_name
, &size
, name
.culture
);
6799 if (name
.pubkeytoken
)
6801 append_str( &display_name
, &size
, separator
);
6802 append_str( &display_name
, &size
, PublicKeyToken
);
6803 append_str( &display_name
, &size
, name
.pubkeytoken
);
6806 msi_free( name
.name
);
6807 msi_free( name
.version
);
6808 msi_free( name
.culture
);
6809 msi_free( name
.pubkeytoken
);
6811 return display_name
;
6814 static BOOL
check_assembly_installed( MSIDATABASE
*db
, IAssemblyCache
*cache
, MSICOMPONENT
*comp
)
6816 ASSEMBLY_INFO asminfo
;
6821 disp
= get_assembly_display_name( db
, comp
);
6825 memset( &asminfo
, 0, sizeof(ASSEMBLY_INFO
) );
6826 asminfo
.cbAssemblyInfo
= sizeof(ASSEMBLY_INFO
);
6828 hr
= IAssemblyCache_QueryAssemblyInfo( cache
, QUERYASMINFO_FLAG_VALIDATE
, disp
, &asminfo
);
6830 found
= (asminfo
.dwAssemblyFlags
== ASSEMBLYINFO_FLAG_INSTALLED
);
6836 static UINT
load_assembly(MSIRECORD
*rec
, LPVOID param
)
6838 ASSEMBLY_LIST
*list
= param
;
6839 MSIASSEMBLY
*assembly
;
6842 assembly
= msi_alloc_zero(sizeof(MSIASSEMBLY
));
6844 return ERROR_OUTOFMEMORY
;
6846 component
= MSI_RecordGetString(rec
, 1);
6847 assembly
->component
= get_loaded_component(list
->package
, component
);
6848 if (!assembly
->component
)
6849 return ERROR_SUCCESS
;
6851 if (assembly
->component
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
6852 assembly
->component
->ActionRequest
!= INSTALLSTATE_SOURCE
)
6854 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
6855 assembly
->component
->Action
= assembly
->component
->Installed
;
6856 return ERROR_SUCCESS
;
6858 assembly
->component
->Action
= assembly
->component
->ActionRequest
;
6860 assembly
->feature
= find_feature_by_name(list
->package
, MSI_RecordGetString(rec
, 2));
6861 assembly
->file
= msi_find_file(list
->package
, assembly
->component
->KeyPath
);
6863 if (!assembly
->file
)
6865 ERR("File %s not found\n", debugstr_w(assembly
->component
->KeyPath
));
6866 return ERROR_FUNCTION_FAILED
;
6869 assembly
->manifest
= strdupW(MSI_RecordGetString(rec
, 3));
6870 assembly
->application
= strdupW(MSI_RecordGetString(rec
, 4));
6871 assembly
->attributes
= MSI_RecordGetInteger(rec
, 5);
6873 if (assembly
->application
)
6876 DWORD size
= sizeof(version
)/sizeof(WCHAR
);
6878 /* FIXME: we should probably check the manifest file here */
6880 if (!MsiGetFileVersionW(assembly
->file
->TargetPath
, version
, &size
, NULL
, NULL
) &&
6881 (!assembly
->file
->Version
|| strcmpW(version
, assembly
->file
->Version
) >= 0))
6883 assembly
->installed
= TRUE
;
6887 assembly
->installed
= check_assembly_installed(list
->package
->db
,
6889 assembly
->component
);
6891 list_add_head(list
->assemblies
, &assembly
->entry
);
6892 return ERROR_SUCCESS
;
6895 static UINT
load_assemblies(MSIPACKAGE
*package
, struct list
*assemblies
)
6897 IAssemblyCache
*cache
= NULL
;
6903 static const WCHAR query
[] =
6904 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6905 '`','M','s','i','A','s','s','e','m','b','l','y','`',0};
6907 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
6908 if (r
!= ERROR_SUCCESS
)
6909 return ERROR_SUCCESS
;
6911 hr
= pCreateAssemblyCache(&cache
, 0);
6913 return ERROR_FUNCTION_FAILED
;
6915 list
.package
= package
;
6917 list
.assemblies
= assemblies
;
6919 r
= MSI_IterateRecords(view
, NULL
, load_assembly
, &list
);
6920 msiobj_release(&view
->hdr
);
6922 IAssemblyCache_Release(cache
);
6927 static void free_assemblies(struct list
*assemblies
)
6929 struct list
*item
, *cursor
;
6931 LIST_FOR_EACH_SAFE(item
, cursor
, assemblies
)
6933 MSIASSEMBLY
*assembly
= LIST_ENTRY(item
, MSIASSEMBLY
, entry
);
6935 list_remove(&assembly
->entry
);
6936 msi_free(assembly
->application
);
6937 msi_free(assembly
->manifest
);
6938 msi_free(assembly
->display_name
);
6943 static BOOL
find_assembly(struct list
*assemblies
, LPCWSTR file
, MSIASSEMBLY
**out
)
6945 MSIASSEMBLY
*assembly
;
6947 LIST_FOR_EACH_ENTRY(assembly
, assemblies
, MSIASSEMBLY
, entry
)
6949 if (!lstrcmpW(assembly
->file
->File
, file
))
6959 static BOOL
installassembly_cb(MSIPACKAGE
*package
, LPCWSTR file
, DWORD action
,
6960 LPWSTR
*path
, DWORD
*attrs
, PVOID user
)
6962 MSIASSEMBLY
*assembly
;
6963 WCHAR temppath
[MAX_PATH
];
6964 struct list
*assemblies
= user
;
6967 if (!find_assembly(assemblies
, file
, &assembly
))
6970 GetTempPathW(MAX_PATH
, temppath
);
6971 PathAddBackslashW(temppath
);
6972 lstrcatW(temppath
, assembly
->file
->FileName
);
6974 if (action
== MSICABEXTRACT_BEGINEXTRACT
)
6976 if (assembly
->installed
)
6979 *path
= strdupW(temppath
);
6980 *attrs
= assembly
->file
->Attributes
;
6982 else if (action
== MSICABEXTRACT_FILEEXTRACTED
)
6984 assembly
->installed
= TRUE
;
6986 r
= install_assembly(package
, assembly
, temppath
);
6987 if (r
!= ERROR_SUCCESS
)
6988 ERR("Failed to install assembly\n");
6994 static UINT
ACTION_MsiPublishAssemblies( MSIPACKAGE
*package
)
6997 struct list assemblies
= LIST_INIT(assemblies
);
6998 MSIASSEMBLY
*assembly
;
7001 if (!init_functionpointers() || !pCreateAssemblyCache
)
7002 return ERROR_FUNCTION_FAILED
;
7004 r
= load_assemblies(package
, &assemblies
);
7005 if (r
!= ERROR_SUCCESS
)
7008 if (list_empty(&assemblies
))
7011 mi
= msi_alloc_zero(sizeof(MSIMEDIAINFO
));
7014 r
= ERROR_OUTOFMEMORY
;
7018 LIST_FOR_EACH_ENTRY(assembly
, &assemblies
, MSIASSEMBLY
, entry
)
7020 if (assembly
->installed
&& !mi
->is_continuous
)
7023 if (assembly
->file
->IsCompressed
)
7025 if (assembly
->file
->disk_id
!= mi
->disk_id
|| mi
->is_continuous
)
7029 r
= ready_media(package
, assembly
->file
, mi
);
7030 if (r
!= ERROR_SUCCESS
)
7032 ERR("Failed to ready media\n");
7037 data
.package
= package
;
7038 data
.cb
= installassembly_cb
;
7039 data
.user
= &assemblies
;
7041 if (!msi_cabextract(package
, mi
, &data
))
7043 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi
->cabinet
));
7044 r
= ERROR_FUNCTION_FAILED
;
7051 LPWSTR source
= resolve_file_source(package
, assembly
->file
);
7053 r
= install_assembly(package
, assembly
, source
);
7054 if (r
!= ERROR_SUCCESS
)
7055 ERR("Failed to install assembly\n");
7060 /* FIXME: write Installer assembly reg values */
7064 free_assemblies(&assemblies
);
7068 static UINT
ACTION_ValidateProductID( MSIPACKAGE
*package
)
7070 LPWSTR key
, template, id
;
7071 UINT r
= ERROR_SUCCESS
;
7073 id
= msi_dup_property( package
->db
, szProductID
);
7077 return ERROR_SUCCESS
;
7079 template = msi_dup_property( package
->db
, szPIDTemplate
);
7080 key
= msi_dup_property( package
->db
, szPIDKEY
);
7082 if (key
&& template)
7084 FIXME( "partial stub: template %s key %s\n", debugstr_w(template), debugstr_w(key
) );
7085 r
= msi_set_property( package
->db
, szProductID
, key
);
7087 msi_free( template );
7092 static UINT
ACTION_ScheduleReboot( MSIPACKAGE
*package
)
7095 package
->need_reboot
= 1;
7096 return ERROR_SUCCESS
;
7099 static UINT
ACTION_AllocateRegistrySpace( MSIPACKAGE
*package
)
7101 static const WCHAR szAvailableFreeReg
[] =
7102 {'A','V','A','I','L','A','B','L','E','F','R','E','E','R','E','G',0};
7104 int space
= msi_get_property_int( package
->db
, szAvailableFreeReg
, 0 );
7106 TRACE("%p %d kilobytes\n", package
, space
);
7108 uirow
= MSI_CreateRecord( 1 );
7109 MSI_RecordSetInteger( uirow
, 1, space
);
7110 ui_actiondata( package
, szAllocateRegistrySpace
, uirow
);
7111 msiobj_release( &uirow
->hdr
);
7113 return ERROR_SUCCESS
;
7116 static UINT
ACTION_DisableRollback( MSIPACKAGE
*package
)
7118 FIXME("%p\n", package
);
7119 return ERROR_SUCCESS
;
7122 static UINT
ACTION_InstallAdminPackage( MSIPACKAGE
*package
)
7124 FIXME("%p\n", package
);
7125 return ERROR_SUCCESS
;
7128 static UINT
ACTION_SetODBCFolders( MSIPACKAGE
*package
)
7133 static const WCHAR driver_query
[] = {
7134 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7135 'O','D','B','C','D','r','i','v','e','r',0 };
7137 static const WCHAR translator_query
[] = {
7138 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7139 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0 };
7141 r
= MSI_DatabaseOpenViewW( package
->db
, driver_query
, &view
);
7142 if (r
== ERROR_SUCCESS
)
7145 r
= MSI_IterateRecords( view
, &count
, NULL
, package
);
7146 msiobj_release( &view
->hdr
);
7147 if (count
) FIXME("ignored %u rows in ODBCDriver table\n", count
);
7150 r
= MSI_DatabaseOpenViewW( package
->db
, translator_query
, &view
);
7151 if (r
== ERROR_SUCCESS
)
7154 r
= MSI_IterateRecords( view
, &count
, NULL
, package
);
7155 msiobj_release( &view
->hdr
);
7156 if (count
) FIXME("ignored %u rows in ODBCTranslator table\n", count
);
7159 return ERROR_SUCCESS
;
7162 static UINT
msi_unimplemented_action_stub( MSIPACKAGE
*package
,
7163 LPCSTR action
, LPCWSTR table
)
7165 static const WCHAR query
[] = {
7166 'S','E','L','E','C','T',' ','*',' ',
7167 'F','R','O','M',' ','`','%','s','`',0 };
7168 MSIQUERY
*view
= NULL
;
7172 r
= MSI_OpenQuery( package
->db
, &view
, query
, table
);
7173 if (r
== ERROR_SUCCESS
)
7175 r
= MSI_IterateRecords(view
, &count
, NULL
, package
);
7176 msiobj_release(&view
->hdr
);
7180 FIXME("%s -> %u ignored %s table values\n",
7181 action
, count
, debugstr_w(table
));
7183 return ERROR_SUCCESS
;
7186 static UINT
ACTION_PatchFiles( MSIPACKAGE
*package
)
7188 static const WCHAR table
[] = { 'P','a','t','c','h',0 };
7189 return msi_unimplemented_action_stub( package
, "PatchFiles", table
);
7192 static UINT
ACTION_BindImage( MSIPACKAGE
*package
)
7194 static const WCHAR table
[] = { 'B','i','n','d','I','m','a','g','e',0 };
7195 return msi_unimplemented_action_stub( package
, "BindImage", table
);
7198 static UINT
ACTION_IsolateComponents( MSIPACKAGE
*package
)
7200 static const WCHAR table
[] = {
7201 'I','s','o','l','a','t','e','d','C','o','m','p','o','n','e','n','t',0 };
7202 return msi_unimplemented_action_stub( package
, "IsolateComponents", table
);
7205 static UINT
ACTION_MigrateFeatureStates( MSIPACKAGE
*package
)
7207 static const WCHAR table
[] = { 'U','p','g','r','a','d','e',0 };
7208 return msi_unimplemented_action_stub( package
, "MigrateFeatureStates", table
);
7211 static UINT
ACTION_MsiUnpublishAssemblies( MSIPACKAGE
*package
)
7213 static const WCHAR table
[] = {
7214 'M','s','i','A','s','s','e','m','b','l','y',0 };
7215 return msi_unimplemented_action_stub( package
, "MsiUnpublishAssemblies", table
);
7218 static UINT
ACTION_RMCCPSearch( MSIPACKAGE
*package
)
7220 static const WCHAR table
[] = { 'C','C','P','S','e','a','r','c','h',0 };
7221 return msi_unimplemented_action_stub( package
, "RMCCPSearch", table
);
7224 static UINT
ACTION_RegisterComPlus( MSIPACKAGE
*package
)
7226 static const WCHAR table
[] = { 'C','o','m','p','l','u','s',0 };
7227 return msi_unimplemented_action_stub( package
, "RegisterComPlus", table
);
7230 static UINT
ACTION_UnregisterComPlus( MSIPACKAGE
*package
)
7232 static const WCHAR table
[] = { 'C','o','m','p','l','u','s',0 };
7233 return msi_unimplemented_action_stub( package
, "UnregisterComPlus", table
);
7236 static UINT
ACTION_InstallSFPCatalogFile( MSIPACKAGE
*package
)
7238 static const WCHAR table
[] = { 'S','F','P','C','a','t','a','l','o','g',0 };
7239 return msi_unimplemented_action_stub( package
, "InstallSFPCatalogFile", table
);
7242 static UINT
ACTION_RemoveExistingProducts( MSIPACKAGE
*package
)
7244 static const WCHAR table
[] = { 'U','p','g','r','a','d','e',0 };
7245 return msi_unimplemented_action_stub( package
, "RemoveExistingProducts", table
);
7248 typedef UINT (*STANDARDACTIONHANDLER
)(MSIPACKAGE
*);
7252 const WCHAR
*action
;
7253 UINT (*handler
)(MSIPACKAGE
*);
7257 { szAllocateRegistrySpace
, ACTION_AllocateRegistrySpace
},
7258 { szAppSearch
, ACTION_AppSearch
},
7259 { szBindImage
, ACTION_BindImage
},
7260 { szCCPSearch
, ACTION_CCPSearch
},
7261 { szCostFinalize
, ACTION_CostFinalize
},
7262 { szCostInitialize
, ACTION_CostInitialize
},
7263 { szCreateFolders
, ACTION_CreateFolders
},
7264 { szCreateShortcuts
, ACTION_CreateShortcuts
},
7265 { szDeleteServices
, ACTION_DeleteServices
},
7266 { szDisableRollback
, ACTION_DisableRollback
},
7267 { szDuplicateFiles
, ACTION_DuplicateFiles
},
7268 { szExecuteAction
, ACTION_ExecuteAction
},
7269 { szFileCost
, ACTION_FileCost
},
7270 { szFindRelatedProducts
, ACTION_FindRelatedProducts
},
7271 { szForceReboot
, ACTION_ForceReboot
},
7272 { szInstallAdminPackage
, ACTION_InstallAdminPackage
},
7273 { szInstallExecute
, ACTION_InstallExecute
},
7274 { szInstallExecuteAgain
, ACTION_InstallExecute
},
7275 { szInstallFiles
, ACTION_InstallFiles
},
7276 { szInstallFinalize
, ACTION_InstallFinalize
},
7277 { szInstallInitialize
, ACTION_InstallInitialize
},
7278 { szInstallSFPCatalogFile
, ACTION_InstallSFPCatalogFile
},
7279 { szInstallValidate
, ACTION_InstallValidate
},
7280 { szIsolateComponents
, ACTION_IsolateComponents
},
7281 { szLaunchConditions
, ACTION_LaunchConditions
},
7282 { szMigrateFeatureStates
, ACTION_MigrateFeatureStates
},
7283 { szMoveFiles
, ACTION_MoveFiles
},
7284 { szMsiPublishAssemblies
, ACTION_MsiPublishAssemblies
},
7285 { szMsiUnpublishAssemblies
, ACTION_MsiUnpublishAssemblies
},
7286 { szInstallODBC
, ACTION_InstallODBC
},
7287 { szInstallServices
, ACTION_InstallServices
},
7288 { szPatchFiles
, ACTION_PatchFiles
},
7289 { szProcessComponents
, ACTION_ProcessComponents
},
7290 { szPublishComponents
, ACTION_PublishComponents
},
7291 { szPublishFeatures
, ACTION_PublishFeatures
},
7292 { szPublishProduct
, ACTION_PublishProduct
},
7293 { szRegisterClassInfo
, ACTION_RegisterClassInfo
},
7294 { szRegisterComPlus
, ACTION_RegisterComPlus
},
7295 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
},
7296 { szRegisterFonts
, ACTION_RegisterFonts
},
7297 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
},
7298 { szRegisterProduct
, ACTION_RegisterProduct
},
7299 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
},
7300 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
},
7301 { szRegisterUser
, ACTION_RegisterUser
},
7302 { szRemoveDuplicateFiles
, ACTION_RemoveDuplicateFiles
},
7303 { szRemoveEnvironmentStrings
, ACTION_RemoveEnvironmentStrings
},
7304 { szRemoveExistingProducts
, ACTION_RemoveExistingProducts
},
7305 { szRemoveFiles
, ACTION_RemoveFiles
},
7306 { szRemoveFolders
, ACTION_RemoveFolders
},
7307 { szRemoveIniValues
, ACTION_RemoveIniValues
},
7308 { szRemoveODBC
, ACTION_RemoveODBC
},
7309 { szRemoveRegistryValues
, ACTION_RemoveRegistryValues
},
7310 { szRemoveShortcuts
, ACTION_RemoveShortcuts
},
7311 { szResolveSource
, ACTION_ResolveSource
},
7312 { szRMCCPSearch
, ACTION_RMCCPSearch
},
7313 { szScheduleReboot
, ACTION_ScheduleReboot
},
7314 { szSelfRegModules
, ACTION_SelfRegModules
},
7315 { szSelfUnregModules
, ACTION_SelfUnregModules
},
7316 { szSetODBCFolders
, ACTION_SetODBCFolders
},
7317 { szStartServices
, ACTION_StartServices
},
7318 { szStopServices
, ACTION_StopServices
},
7319 { szUnpublishComponents
, ACTION_UnpublishComponents
},
7320 { szUnpublishFeatures
, ACTION_UnpublishFeatures
},
7321 { szUnregisterClassInfo
, ACTION_UnregisterClassInfo
},
7322 { szUnregisterComPlus
, ACTION_UnregisterComPlus
},
7323 { szUnregisterExtensionInfo
, ACTION_UnregisterExtensionInfo
},
7324 { szUnregisterFonts
, ACTION_UnregisterFonts
},
7325 { szUnregisterMIMEInfo
, ACTION_UnregisterMIMEInfo
},
7326 { szUnregisterProgIdInfo
, ACTION_UnregisterProgIdInfo
},
7327 { szUnregisterTypeLibraries
, ACTION_UnregisterTypeLibraries
},
7328 { szValidateProductID
, ACTION_ValidateProductID
},
7329 { szWriteEnvironmentStrings
, ACTION_WriteEnvironmentStrings
},
7330 { szWriteIniValues
, ACTION_WriteIniValues
},
7331 { szWriteRegistryValues
, ACTION_WriteRegistryValues
},
7335 static BOOL
ACTION_HandleStandardAction( MSIPACKAGE
*package
, LPCWSTR action
, UINT
*rc
)
7341 while (StandardActions
[i
].action
!= NULL
)
7343 if (!strcmpW( StandardActions
[i
].action
, action
))
7345 ui_actionstart( package
, action
);
7346 if (StandardActions
[i
].handler
)
7348 ui_actioninfo( package
, action
, TRUE
, 0 );
7349 *rc
= StandardActions
[i
].handler( package
);
7350 ui_actioninfo( package
, action
, FALSE
, *rc
);
7354 FIXME("unhandled standard action %s\n", debugstr_w(action
));
7355 *rc
= ERROR_SUCCESS
;
7365 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, UINT script
)
7367 UINT rc
= ERROR_SUCCESS
;
7370 TRACE("Performing action (%s)\n", debugstr_w(action
));
7372 handled
= ACTION_HandleStandardAction(package
, action
, &rc
);
7375 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, script
, TRUE
);
7379 WARN("unhandled msi action %s\n", debugstr_w(action
));
7380 rc
= ERROR_FUNCTION_NOT_CALLED
;
7386 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
, UINT script
)
7388 UINT rc
= ERROR_SUCCESS
;
7389 BOOL handled
= FALSE
;
7391 TRACE("Performing action (%s)\n", debugstr_w(action
));
7393 handled
= ACTION_HandleStandardAction(package
, action
, &rc
);
7396 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, script
, FALSE
);
7398 if( !handled
&& ACTION_DialogBox(package
, action
) == ERROR_SUCCESS
)
7403 WARN("unhandled msi action %s\n", debugstr_w(action
));
7404 rc
= ERROR_FUNCTION_NOT_CALLED
;
7410 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
)
7412 UINT rc
= ERROR_SUCCESS
;
7415 static const WCHAR ExecSeqQuery
[] =
7416 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7417 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
7418 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
7419 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
7420 static const WCHAR UISeqQuery
[] =
7421 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7422 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
7423 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
7424 ' ', '=',' ','%','i',0};
7426 if (needs_ui_sequence(package
))
7427 row
= MSI_QueryGetRecord(package
->db
, UISeqQuery
, seq
);
7429 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, seq
);
7433 LPCWSTR action
, cond
;
7435 TRACE("Running the actions\n");
7437 /* check conditions */
7438 cond
= MSI_RecordGetString(row
, 2);
7440 /* this is a hack to skip errors in the condition code */
7441 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
7443 msiobj_release(&row
->hdr
);
7444 return ERROR_SUCCESS
;
7447 action
= MSI_RecordGetString(row
, 1);
7450 ERR("failed to fetch action\n");
7451 msiobj_release(&row
->hdr
);
7452 return ERROR_FUNCTION_FAILED
;
7455 if (needs_ui_sequence(package
))
7456 rc
= ACTION_PerformUIAction(package
, action
, -1);
7458 rc
= ACTION_PerformAction(package
, action
, -1);
7460 msiobj_release(&row
->hdr
);
7466 /****************************************************
7467 * TOP level entry points
7468 *****************************************************/
7470 UINT
MSI_InstallPackage( MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
7471 LPCWSTR szCommandLine
)
7476 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
7477 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
7479 msi_set_property( package
->db
, szAction
, szInstall
);
7481 package
->script
->InWhatSequence
= SEQUENCE_INSTALL
;
7488 dir
= strdupW(szPackagePath
);
7489 p
= strrchrW(dir
, '\\');
7493 file
= szPackagePath
+ (p
- dir
);
7498 dir
= msi_alloc(MAX_PATH
* sizeof(WCHAR
));
7499 GetCurrentDirectoryW(MAX_PATH
, dir
);
7500 lstrcatW(dir
, szBackSlash
);
7501 file
= szPackagePath
;
7504 msi_free( package
->PackagePath
);
7505 package
->PackagePath
= msi_alloc((lstrlenW(dir
) + lstrlenW(file
) + 1) * sizeof(WCHAR
));
7506 if (!package
->PackagePath
)
7509 return ERROR_OUTOFMEMORY
;
7512 lstrcpyW(package
->PackagePath
, dir
);
7513 lstrcatW(package
->PackagePath
, file
);
7516 msi_set_sourcedir_props(package
, FALSE
);
7519 msi_parse_command_line( package
, szCommandLine
, FALSE
);
7521 msi_apply_transforms( package
);
7522 msi_apply_patches( package
);
7524 if (!szCommandLine
&& msi_get_property_int( package
->db
, szInstalled
, 0 ))
7526 TRACE("setting reinstall property\n");
7527 msi_set_property( package
->db
, szReinstall
, szAll
);
7530 /* properties may have been added by a transform */
7531 msi_clone_properties( package
);
7533 msi_parse_command_line( package
, szCommandLine
, FALSE
);
7534 msi_adjust_privilege_properties( package
);
7535 msi_set_context( package
);
7537 if (needs_ui_sequence( package
))
7539 package
->script
->InWhatSequence
|= SEQUENCE_UI
;
7540 rc
= ACTION_ProcessUISequence(package
);
7541 ui_exists
= ui_sequence_exists(package
);
7542 if (rc
== ERROR_SUCCESS
|| !ui_exists
)
7544 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
7545 rc
= ACTION_ProcessExecSequence(package
, ui_exists
);
7549 rc
= ACTION_ProcessExecSequence(package
, FALSE
);
7551 package
->script
->CurrentlyScripting
= FALSE
;
7553 /* process the ending type action */
7554 if (rc
== ERROR_SUCCESS
)
7555 ACTION_PerformActionSequence(package
, -1);
7556 else if (rc
== ERROR_INSTALL_USEREXIT
)
7557 ACTION_PerformActionSequence(package
, -2);
7558 else if (rc
== ERROR_INSTALL_SUSPEND
)
7559 ACTION_PerformActionSequence(package
, -4);
7561 ACTION_PerformActionSequence(package
, -3);
7563 /* finish up running custom actions */
7564 ACTION_FinishCustomActions(package
);
7566 if (rc
== ERROR_SUCCESS
&& package
->need_reboot
)
7567 return ERROR_SUCCESS_REBOOT_REQUIRED
;