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
27 #define REG_PROGRESS_VALUE 13200
28 #define COMPONENT_PROGRESS_VALUE 24000
30 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
32 static const WCHAR szCreateFolders
[] =
33 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
34 static const WCHAR szCostFinalize
[] =
35 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
36 static const WCHAR szWriteRegistryValues
[] =
37 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
38 static const WCHAR szFileCost
[] =
39 {'F','i','l','e','C','o','s','t',0};
40 static const WCHAR szInstallInitialize
[] =
41 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
42 static const WCHAR szInstallValidate
[] =
43 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
44 static const WCHAR szLaunchConditions
[] =
45 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
46 static const WCHAR szProcessComponents
[] =
47 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
48 static const WCHAR szRegisterTypeLibraries
[] =
49 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r','i','e','s',0};
50 static const WCHAR szCreateShortcuts
[] =
51 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
52 static const WCHAR szPublishProduct
[] =
53 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
54 static const WCHAR szWriteIniValues
[] =
55 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
56 static const WCHAR szSelfRegModules
[] =
57 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
58 static const WCHAR szPublishFeatures
[] =
59 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
60 static const WCHAR szRegisterProduct
[] =
61 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
62 static const WCHAR szInstallExecute
[] =
63 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
64 static const WCHAR szInstallExecuteAgain
[] =
65 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e','A','g','a','i','n',0};
66 static const WCHAR szInstallFinalize
[] =
67 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
68 static const WCHAR szForceReboot
[] =
69 {'F','o','r','c','e','R','e','b','o','o','t',0};
70 static const WCHAR szResolveSource
[] =
71 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
72 static const WCHAR szAllocateRegistrySpace
[] =
73 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y','S','p','a','c','e',0};
74 static const WCHAR szBindImage
[] =
75 {'B','i','n','d','I','m','a','g','e',0};
76 static const WCHAR szDeleteServices
[] =
77 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
78 static const WCHAR szDisableRollback
[] =
79 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
80 static const WCHAR szExecuteAction
[] =
81 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
82 static const WCHAR szInstallAdminPackage
[] =
83 {'I','n','s','t','a','l','l','A','d','m','i','n','P','a','c','k','a','g','e',0};
84 static const WCHAR szInstallSFPCatalogFile
[] =
85 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g','F','i','l','e',0};
86 static const WCHAR szIsolateComponents
[] =
87 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
88 static const WCHAR szMigrateFeatureStates
[] =
89 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e','S','t','a','t','e','s',0};
90 static const WCHAR szMsiUnpublishAssemblies
[] =
91 {'M','s','i','U','n','p','u','b','l','i','s','h','A','s','s','e','m','b','l','i','e','s',0};
92 static const WCHAR szInstallODBC
[] =
93 {'I','n','s','t','a','l','l','O','D','B','C',0};
94 static const WCHAR szInstallServices
[] =
95 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
96 static const WCHAR szPublishComponents
[] =
97 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
98 static const WCHAR szRegisterComPlus
[] =
99 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
100 static const WCHAR szRegisterUser
[] =
101 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
102 static const WCHAR szRemoveEnvironmentStrings
[] =
103 {'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};
104 static const WCHAR szRemoveExistingProducts
[] =
105 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g','P','r','o','d','u','c','t','s',0};
106 static const WCHAR szRemoveFolders
[] =
107 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
108 static const WCHAR szRemoveIniValues
[] =
109 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
110 static const WCHAR szRemoveODBC
[] =
111 {'R','e','m','o','v','e','O','D','B','C',0};
112 static const WCHAR szRemoveRegistryValues
[] =
113 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
114 static const WCHAR szRemoveShortcuts
[] =
115 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
116 static const WCHAR szRMCCPSearch
[] =
117 {'R','M','C','C','P','S','e','a','r','c','h',0};
118 static const WCHAR szScheduleReboot
[] =
119 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
120 static const WCHAR szSelfUnregModules
[] =
121 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
122 static const WCHAR szSetODBCFolders
[] =
123 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
124 static const WCHAR szStartServices
[] =
125 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
126 static const WCHAR szStopServices
[] =
127 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
128 static const WCHAR szUnpublishComponents
[] =
129 {'U','n','p','u','b','l','i','s','h', 'C','o','m','p','o','n','e','n','t','s',0};
130 static const WCHAR szUnpublishFeatures
[] =
131 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
132 static const WCHAR szUnregisterComPlus
[] =
133 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
134 static const WCHAR szUnregisterTypeLibraries
[] =
135 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r','i','e','s',0};
136 static const WCHAR szValidateProductID
[] =
137 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
138 static const WCHAR szWriteEnvironmentStrings
[] =
139 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t','S','t','r','i','n','g','s',0};
141 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
143 static const WCHAR Query_t
[] =
144 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
145 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
146 'W','H','E','R','E', ' ','`','A','c','t','i','o','n','`',' ','=',
147 ' ','\'','%','s','\'',0};
150 row
= MSI_QueryGetRecord( package
->db
, Query_t
, action
);
153 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
154 msiobj_release(&row
->hdr
);
157 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
161 static const WCHAR template_s
[]=
162 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
164 static const WCHAR template_e
[]=
165 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
166 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
168 static const WCHAR format
[] =
169 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
173 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
175 sprintfW(message
,template_s
,timet
,action
);
177 sprintfW(message
,template_e
,timet
,action
,rc
);
179 row
= MSI_CreateRecord(1);
180 MSI_RecordSetStringW(row
,1,message
);
182 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
183 msiobj_release(&row
->hdr
);
193 static int parse_prop( const WCHAR
*str
, WCHAR
*value
, int *quotes
)
195 enum parse_state state
= state_quote
;
198 BOOL ignore
, in_quotes
= FALSE
;
199 int count
= 0, len
= 0;
201 for (p
= str
; *p
; p
++)
206 case state_whitespace
:
216 if (in_quotes
&& p
[1] != '\"') count
--;
232 if (in_quotes
) count
--;
236 state
= state_whitespace
;
237 if (!count
) goto done
;
242 if (!count
) in_quotes
= FALSE
;
243 else in_quotes
= TRUE
;
253 if (in_quotes
&& p
[1] != '\"') count
--;
257 state
= state_whitespace
;
258 if (!count
|| (count
> 1 && !len
)) goto done
;
264 if (!count
) in_quotes
= FALSE
;
265 else in_quotes
= TRUE
;
273 if (!ignore
) *out
++ = *p
;
277 if (!len
) *value
= 0;
284 static void remove_quotes( WCHAR
*str
)
287 int len
= strlenW( str
);
289 while ((p
= strchrW( p
, '"' )))
291 memmove( p
, p
+ 1, (len
- (p
- str
)) * sizeof(WCHAR
) );
296 UINT
msi_parse_command_line( MSIPACKAGE
*package
, LPCWSTR szCommandLine
,
306 return ERROR_SUCCESS
;
311 while (*ptr
== ' ') ptr
++;
314 ptr2
= strchrW( ptr
, '=' );
315 if (!ptr2
) return ERROR_INVALID_COMMAND_LINE
;
318 if (!len
) return ERROR_INVALID_COMMAND_LINE
;
320 while (ptr
[len
- 1] == ' ') len
--;
322 prop
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
323 memcpy( prop
, ptr
, len
* sizeof(WCHAR
) );
325 if (!preserve_case
) struprW( prop
);
328 while (*ptr2
== ' ') ptr2
++;
331 val
= msi_alloc( (strlenW( ptr2
) + 1) * sizeof(WCHAR
) );
332 len
= parse_prop( ptr2
, val
, &num_quotes
);
335 WARN("unbalanced quotes\n");
338 return ERROR_INVALID_COMMAND_LINE
;
340 remove_quotes( val
);
341 TRACE("Found commandline property %s = %s\n", debugstr_w(prop
), debugstr_w(val
));
343 r
= msi_set_property( package
->db
, prop
, val
, -1 );
344 if (r
== ERROR_SUCCESS
&& !strcmpW( prop
, szSourceDir
))
345 msi_reset_folders( package
, TRUE
);
353 return ERROR_SUCCESS
;
356 WCHAR
**msi_split_string( const WCHAR
*str
, WCHAR sep
)
359 LPWSTR p
, *ret
= NULL
;
365 /* count the number of substrings */
366 for ( pc
= str
, count
= 0; pc
; count
++ )
368 pc
= strchrW( pc
, sep
);
373 /* allocate space for an array of substring pointers and the substrings */
374 ret
= msi_alloc( (count
+1) * sizeof (LPWSTR
) +
375 (lstrlenW(str
)+1) * sizeof(WCHAR
) );
379 /* copy the string and set the pointers */
380 p
= (LPWSTR
) &ret
[count
+1];
382 for( count
= 0; (ret
[count
] = p
); count
++ )
384 p
= strchrW( p
, sep
);
392 static BOOL
ui_sequence_exists( MSIPACKAGE
*package
)
394 static const WCHAR query
[] = {
395 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
396 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e','`',' ',
397 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',' ','>',' ','0',0};
401 if (!(MSI_DatabaseOpenViewW( package
->db
, query
, &view
)))
403 MSI_IterateRecords( view
, &count
, NULL
, package
);
404 msiobj_release( &view
->hdr
);
409 UINT
msi_set_sourcedir_props(MSIPACKAGE
*package
, BOOL replace
)
411 WCHAR
*source
, *check
, *p
, *db
;
414 if (!(db
= msi_dup_property( package
->db
, szOriginalDatabase
)))
415 return ERROR_OUTOFMEMORY
;
417 if (!(p
= strrchrW( db
, '\\' )) && !(p
= strrchrW( db
, '/' )))
420 return ERROR_SUCCESS
;
423 source
= msi_alloc( len
* sizeof(WCHAR
) );
424 lstrcpynW( source
, db
, len
);
427 check
= msi_dup_property( package
->db
, szSourceDir
);
428 if (!check
|| replace
)
430 UINT r
= msi_set_property( package
->db
, szSourceDir
, source
, -1 );
431 if (r
== ERROR_SUCCESS
)
432 msi_reset_folders( package
, TRUE
);
436 check
= msi_dup_property( package
->db
, szSOURCEDIR
);
437 if (!check
|| replace
)
438 msi_set_property( package
->db
, szSOURCEDIR
, source
, -1 );
443 return ERROR_SUCCESS
;
446 static BOOL
needs_ui_sequence(MSIPACKAGE
*package
)
448 return (package
->ui_level
& INSTALLUILEVEL_MASK
) >= INSTALLUILEVEL_REDUCED
;
451 UINT
msi_set_context(MSIPACKAGE
*package
)
453 UINT r
= msi_locate_product( package
->ProductCode
, &package
->Context
);
454 if (r
!= ERROR_SUCCESS
)
456 int num
= msi_get_property_int( package
->db
, szAllUsers
, 0 );
457 if (num
== 1 || num
== 2)
458 package
->Context
= MSIINSTALLCONTEXT_MACHINE
;
460 package
->Context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
462 return ERROR_SUCCESS
;
465 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
468 LPCWSTR cond
, action
;
469 MSIPACKAGE
*package
= param
;
471 action
= MSI_RecordGetString(row
,1);
474 ERR("Error is retrieving action name\n");
475 return ERROR_FUNCTION_FAILED
;
478 /* check conditions */
479 cond
= MSI_RecordGetString(row
,2);
481 /* this is a hack to skip errors in the condition code */
482 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
484 TRACE("Skipping action: %s (condition is false)\n", debugstr_w(action
));
485 return ERROR_SUCCESS
;
488 if (needs_ui_sequence(package
))
489 rc
= ACTION_PerformUIAction(package
, action
, SCRIPT_NONE
);
491 rc
= ACTION_PerformAction(package
, action
, SCRIPT_NONE
);
493 msi_dialog_check_messages( NULL
);
495 if (package
->CurrentInstallState
!= ERROR_SUCCESS
)
496 rc
= package
->CurrentInstallState
;
498 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
501 if (rc
!= ERROR_SUCCESS
)
502 ERR("Execution halted, action %s returned %i\n", debugstr_w(action
), rc
);
504 if (package
->need_reboot_now
)
506 TRACE("action %s asked for immediate reboot, suspending installation\n",
508 rc
= ACTION_ForceReboot( package
);
513 UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR table
)
515 static const WCHAR query
[] = {
516 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','%','s','`',
517 ' ','W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',' ',
518 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
519 '`','S','e','q','u','e','n','c','e','`',0};
523 TRACE("%p %s\n", package
, debugstr_w(table
));
525 r
= MSI_OpenQuery( package
->db
, &view
, query
, table
);
526 if (r
== ERROR_SUCCESS
)
528 r
= MSI_IterateRecords( view
, NULL
, ITERATE_Actions
, package
);
529 msiobj_release(&view
->hdr
);
534 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
536 static const WCHAR query
[] = {
537 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
538 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
539 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
540 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','%','i',' ',
541 'O','R','D','E','R',' ', 'B','Y',' ','`','S','e','q','u','e','n','c','e','`',0};
542 static const WCHAR query_validate
[] = {
543 'S','E','L','E','C','T',' ','`','S','e','q','u','e','n','c','e','`',
544 ' ', 'F','R','O','M',' ','`','I','n','s','t','a','l','l',
545 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e','`',' ',
546 'W','H','E','R','E',' ','`','A','c','t','i','o','n','`',' ','=',
547 ' ','\'', 'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','\'',0};
552 if (package
->script
->ExecuteSequenceRun
)
554 TRACE("Execute Sequence already Run\n");
555 return ERROR_SUCCESS
;
558 package
->script
->ExecuteSequenceRun
= TRUE
;
560 /* get the sequence number */
563 MSIRECORD
*row
= MSI_QueryGetRecord(package
->db
, query_validate
);
564 if (!row
) return ERROR_FUNCTION_FAILED
;
565 seq
= MSI_RecordGetInteger(row
,1);
566 msiobj_release(&row
->hdr
);
568 rc
= MSI_OpenQuery(package
->db
, &view
, query
, seq
);
569 if (rc
== ERROR_SUCCESS
)
571 TRACE("Running the actions\n");
573 msi_set_property( package
->db
, szSourceDir
, NULL
, -1 );
574 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
575 msiobj_release(&view
->hdr
);
580 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
582 static const WCHAR query
[] = {
583 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
584 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e','`',' ',
585 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',' ','>',' ','0',' ',
586 'O','R','D','E','R',' ','B','Y',' ','`','S','e','q','u','e','n','c','e','`',0};
590 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
591 if (rc
== ERROR_SUCCESS
)
593 TRACE("Running the actions\n");
594 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
595 msiobj_release(&view
->hdr
);
600 /********************************************************
601 * ACTION helper functions and functions that perform the actions
602 *******************************************************/
603 static BOOL
ACTION_HandleCustomAction( MSIPACKAGE
*package
, LPCWSTR action
, UINT
*rc
, UINT script
)
608 arc
= ACTION_CustomAction( package
, action
, script
);
609 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
617 MSICOMPONENT
*msi_get_loaded_component( MSIPACKAGE
*package
, const WCHAR
*Component
)
621 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
623 if (!strcmpW( Component
, comp
->Component
)) return comp
;
628 MSIFEATURE
*msi_get_loaded_feature(MSIPACKAGE
* package
, const WCHAR
*Feature
)
632 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
634 if (!strcmpW( Feature
, feature
->Feature
)) return feature
;
639 MSIFILE
*msi_get_loaded_file( MSIPACKAGE
*package
, const WCHAR
*key
)
643 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
645 if (!strcmpW( key
, file
->File
)) return file
;
650 MSIFOLDER
*msi_get_loaded_folder( MSIPACKAGE
*package
, const WCHAR
*dir
)
654 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
656 if (!strcmpW( dir
, folder
->Directory
)) return folder
;
662 * Recursively create all directories in the path.
663 * shamelessly stolen from setupapi/queue.c
665 BOOL
msi_create_full_path( const WCHAR
*path
)
671 new_path
= msi_alloc( (strlenW( path
) + 1) * sizeof(WCHAR
) );
672 strcpyW( new_path
, path
);
674 while ((len
= strlenW( new_path
)) && new_path
[len
- 1] == '\\')
675 new_path
[len
- 1] = 0;
677 while (!CreateDirectoryW( new_path
, NULL
))
680 DWORD last_error
= GetLastError();
681 if (last_error
== ERROR_ALREADY_EXISTS
) break;
682 if (last_error
!= ERROR_PATH_NOT_FOUND
)
687 if (!(slash
= strrchrW( new_path
, '\\' )))
692 len
= slash
- new_path
;
694 if (!msi_create_full_path( new_path
))
699 new_path
[len
] = '\\';
701 msi_free( new_path
);
705 void msi_ui_progress( MSIPACKAGE
*package
, int a
, int b
, int c
, int d
)
709 row
= MSI_CreateRecord( 4 );
710 MSI_RecordSetInteger( row
, 1, a
);
711 MSI_RecordSetInteger( row
, 2, b
);
712 MSI_RecordSetInteger( row
, 3, c
);
713 MSI_RecordSetInteger( row
, 4, d
);
714 MSI_ProcessMessage( package
, INSTALLMESSAGE_PROGRESS
, row
);
715 msiobj_release( &row
->hdr
);
717 msi_dialog_check_messages( NULL
);
720 void msi_ui_actiondata( MSIPACKAGE
*package
, const WCHAR
*action
, MSIRECORD
*record
)
722 static const WCHAR query
[] =
723 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
724 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
725 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',' ','\'','%','s','\'',0};
730 if (!package
->LastAction
|| strcmpW( package
->LastAction
, action
))
732 if (!(row
= MSI_QueryGetRecord( package
->db
, query
, action
))) return;
734 if (MSI_RecordIsNull( row
, 3 ))
736 msiobj_release( &row
->hdr
);
739 /* update the cached action format */
740 msi_free( package
->ActionFormat
);
741 package
->ActionFormat
= msi_dup_record_field( row
, 3 );
742 msi_free( package
->LastAction
);
743 package
->LastAction
= strdupW( action
);
744 msiobj_release( &row
->hdr
);
747 MSI_RecordSetStringW( record
, 0, package
->ActionFormat
);
748 MSI_FormatRecordW( package
, record
, message
, &size
);
749 row
= MSI_CreateRecord( 1 );
750 MSI_RecordSetStringW( row
, 1, message
);
751 MSI_ProcessMessage( package
, INSTALLMESSAGE_ACTIONDATA
, row
);
752 msiobj_release( &row
->hdr
);
755 INSTALLSTATE
msi_get_component_action( MSIPACKAGE
*package
, MSICOMPONENT
*comp
)
759 TRACE("component is disabled: %s\n", debugstr_w(comp
->Component
));
760 return INSTALLSTATE_UNKNOWN
;
762 if (package
->need_rollback
) return comp
->Installed
;
763 if (comp
->num_clients
> 0 && comp
->ActionRequest
== INSTALLSTATE_ABSENT
)
765 TRACE("%s has %u clients left\n", debugstr_w(comp
->Component
), comp
->num_clients
);
766 return INSTALLSTATE_UNKNOWN
;
768 return comp
->ActionRequest
;
771 INSTALLSTATE
msi_get_feature_action( MSIPACKAGE
*package
, MSIFEATURE
*feature
)
773 if (package
->need_rollback
) return feature
->Installed
;
774 return feature
->ActionRequest
;
777 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
779 MSIPACKAGE
*package
= param
;
780 LPCWSTR dir
, component
, full_path
;
785 component
= MSI_RecordGetString(row
, 2);
787 return ERROR_SUCCESS
;
789 comp
= msi_get_loaded_component(package
, component
);
791 return ERROR_SUCCESS
;
793 comp
->Action
= msi_get_component_action( package
, comp
);
794 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
796 TRACE("component not scheduled for installation: %s\n", debugstr_w(component
));
797 return ERROR_SUCCESS
;
800 dir
= MSI_RecordGetString(row
,1);
803 ERR("Unable to get folder id\n");
804 return ERROR_SUCCESS
;
807 uirow
= MSI_CreateRecord(1);
808 MSI_RecordSetStringW(uirow
, 1, dir
);
809 msi_ui_actiondata(package
, szCreateFolders
, uirow
);
810 msiobj_release(&uirow
->hdr
);
812 full_path
= msi_get_target_folder( package
, dir
);
815 ERR("Unable to retrieve folder %s\n", debugstr_w(dir
));
816 return ERROR_SUCCESS
;
818 TRACE("folder is %s\n", debugstr_w(full_path
));
820 folder
= msi_get_loaded_folder( package
, dir
);
821 if (folder
->State
== FOLDER_STATE_UNINITIALIZED
) msi_create_full_path( full_path
);
822 folder
->State
= FOLDER_STATE_CREATED
;
823 return ERROR_SUCCESS
;
826 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
828 static const WCHAR query
[] = {
829 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
830 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
834 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
835 if (rc
!= ERROR_SUCCESS
)
836 return ERROR_SUCCESS
;
838 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
839 msiobj_release(&view
->hdr
);
843 static void remove_persistent_folder( MSIFOLDER
*folder
)
847 LIST_FOR_EACH_ENTRY( fl
, &folder
->children
, FolderList
, entry
)
849 remove_persistent_folder( fl
->folder
);
851 if (folder
->persistent
&& folder
->State
!= FOLDER_STATE_REMOVED
)
853 if (RemoveDirectoryW( folder
->ResolvedTarget
)) folder
->State
= FOLDER_STATE_REMOVED
;
857 static UINT
ITERATE_RemoveFolders( MSIRECORD
*row
, LPVOID param
)
859 MSIPACKAGE
*package
= param
;
860 LPCWSTR dir
, component
, full_path
;
865 component
= MSI_RecordGetString(row
, 2);
867 return ERROR_SUCCESS
;
869 comp
= msi_get_loaded_component(package
, component
);
871 return ERROR_SUCCESS
;
873 comp
->Action
= msi_get_component_action( package
, comp
);
874 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
876 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
877 return ERROR_SUCCESS
;
880 dir
= MSI_RecordGetString( row
, 1 );
883 ERR("Unable to get folder id\n");
884 return ERROR_SUCCESS
;
887 full_path
= msi_get_target_folder( package
, dir
);
890 ERR("Unable to resolve folder %s\n", debugstr_w(dir
));
891 return ERROR_SUCCESS
;
893 TRACE("folder is %s\n", debugstr_w(full_path
));
895 uirow
= MSI_CreateRecord( 1 );
896 MSI_RecordSetStringW( uirow
, 1, dir
);
897 msi_ui_actiondata( package
, szRemoveFolders
, uirow
);
898 msiobj_release( &uirow
->hdr
);
900 folder
= msi_get_loaded_folder( package
, dir
);
901 remove_persistent_folder( folder
);
902 return ERROR_SUCCESS
;
905 static UINT
ACTION_RemoveFolders( MSIPACKAGE
*package
)
907 static const WCHAR query
[] = {
908 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
909 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
913 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
914 if (rc
!= ERROR_SUCCESS
)
915 return ERROR_SUCCESS
;
917 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveFolders
, package
);
918 msiobj_release( &view
->hdr
);
922 static UINT
load_component( MSIRECORD
*row
, LPVOID param
)
924 MSIPACKAGE
*package
= param
;
927 comp
= msi_alloc_zero( sizeof(MSICOMPONENT
) );
929 return ERROR_FUNCTION_FAILED
;
931 list_add_tail( &package
->components
, &comp
->entry
);
933 /* fill in the data */
934 comp
->Component
= msi_dup_record_field( row
, 1 );
936 TRACE("Loading Component %s\n", debugstr_w(comp
->Component
));
938 comp
->ComponentId
= msi_dup_record_field( row
, 2 );
939 comp
->Directory
= msi_dup_record_field( row
, 3 );
940 comp
->Attributes
= MSI_RecordGetInteger(row
,4);
941 comp
->Condition
= msi_dup_record_field( row
, 5 );
942 comp
->KeyPath
= msi_dup_record_field( row
, 6 );
944 comp
->Installed
= INSTALLSTATE_UNKNOWN
;
945 comp
->Action
= INSTALLSTATE_UNKNOWN
;
946 comp
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
948 comp
->assembly
= msi_load_assembly( package
, comp
);
949 return ERROR_SUCCESS
;
952 UINT
msi_load_all_components( MSIPACKAGE
*package
)
954 static const WCHAR query
[] = {
955 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
956 '`','C','o','m','p','o','n','e','n','t','`',0};
960 if (!list_empty(&package
->components
))
961 return ERROR_SUCCESS
;
963 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
964 if (r
!= ERROR_SUCCESS
)
967 if (!msi_init_assembly_caches( package
))
969 ERR("can't initialize assembly caches\n");
970 msiobj_release( &view
->hdr
);
971 return ERROR_FUNCTION_FAILED
;
974 r
= MSI_IterateRecords(view
, NULL
, load_component
, package
);
975 msiobj_release(&view
->hdr
);
984 static UINT
add_feature_component( MSIFEATURE
*feature
, MSICOMPONENT
*comp
)
988 cl
= msi_alloc( sizeof (*cl
) );
990 return ERROR_NOT_ENOUGH_MEMORY
;
991 cl
->component
= comp
;
992 list_add_tail( &feature
->Components
, &cl
->entry
);
994 return ERROR_SUCCESS
;
997 static UINT
add_feature_child( MSIFEATURE
*parent
, MSIFEATURE
*child
)
1001 fl
= msi_alloc( sizeof(*fl
) );
1003 return ERROR_NOT_ENOUGH_MEMORY
;
1004 fl
->feature
= child
;
1005 list_add_tail( &parent
->Children
, &fl
->entry
);
1007 return ERROR_SUCCESS
;
1010 static UINT
iterate_load_featurecomponents(MSIRECORD
*row
, LPVOID param
)
1012 _ilfs
* ilfs
= param
;
1016 component
= MSI_RecordGetString(row
,1);
1018 /* check to see if the component is already loaded */
1019 comp
= msi_get_loaded_component( ilfs
->package
, component
);
1022 WARN("ignoring unknown component %s\n", debugstr_w(component
));
1023 return ERROR_SUCCESS
;
1025 add_feature_component( ilfs
->feature
, comp
);
1026 comp
->Enabled
= TRUE
;
1028 return ERROR_SUCCESS
;
1031 static UINT
load_feature(MSIRECORD
* row
, LPVOID param
)
1033 static const WCHAR query
[] = {
1034 'S','E','L','E','C','T',' ','`','C','o','m','p','o','n','e','n','t','_','`',
1035 ' ','F','R','O','M',' ','`','F','e','a','t','u','r','e',
1036 'C','o','m','p','o','n','e','n','t','s','`',' ','W','H','E','R','E',' ',
1037 '`','F','e', 'a','t','u','r','e','_','`',' ','=','\'','%','s','\'',0};
1038 MSIPACKAGE
*package
= param
;
1039 MSIFEATURE
*feature
;
1044 /* fill in the data */
1046 feature
= msi_alloc_zero( sizeof (MSIFEATURE
) );
1048 return ERROR_NOT_ENOUGH_MEMORY
;
1050 list_init( &feature
->Children
);
1051 list_init( &feature
->Components
);
1053 feature
->Feature
= msi_dup_record_field( row
, 1 );
1055 TRACE("Loading feature %s\n",debugstr_w(feature
->Feature
));
1057 feature
->Feature_Parent
= msi_dup_record_field( row
, 2 );
1058 feature
->Title
= msi_dup_record_field( row
, 3 );
1059 feature
->Description
= msi_dup_record_field( row
, 4 );
1061 if (!MSI_RecordIsNull(row
,5))
1062 feature
->Display
= MSI_RecordGetInteger(row
,5);
1064 feature
->Level
= MSI_RecordGetInteger(row
,6);
1065 feature
->Directory
= msi_dup_record_field( row
, 7 );
1066 feature
->Attributes
= MSI_RecordGetInteger(row
,8);
1068 feature
->Installed
= INSTALLSTATE_UNKNOWN
;
1069 feature
->Action
= INSTALLSTATE_UNKNOWN
;
1070 feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1072 list_add_tail( &package
->features
, &feature
->entry
);
1074 /* load feature components */
1076 rc
= MSI_OpenQuery( package
->db
, &view
, query
, feature
->Feature
);
1077 if (rc
!= ERROR_SUCCESS
)
1078 return ERROR_SUCCESS
;
1080 ilfs
.package
= package
;
1081 ilfs
.feature
= feature
;
1083 rc
= MSI_IterateRecords(view
, NULL
, iterate_load_featurecomponents
, &ilfs
);
1084 msiobj_release(&view
->hdr
);
1088 static UINT
find_feature_children(MSIRECORD
* row
, LPVOID param
)
1090 MSIPACKAGE
*package
= param
;
1091 MSIFEATURE
*parent
, *child
;
1093 child
= msi_get_loaded_feature( package
, MSI_RecordGetString( row
, 1 ) );
1095 return ERROR_FUNCTION_FAILED
;
1097 if (!child
->Feature_Parent
)
1098 return ERROR_SUCCESS
;
1100 parent
= msi_get_loaded_feature( package
, child
->Feature_Parent
);
1102 return ERROR_FUNCTION_FAILED
;
1104 add_feature_child( parent
, child
);
1105 return ERROR_SUCCESS
;
1108 UINT
msi_load_all_features( MSIPACKAGE
*package
)
1110 static const WCHAR query
[] = {
1111 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1112 '`','F','e','a','t','u','r','e','`',' ','O','R','D','E','R',' ','B','Y',' ',
1113 '`','D','i','s','p','l','a','y','`',0};
1117 if (!list_empty(&package
->features
))
1118 return ERROR_SUCCESS
;
1120 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1121 if (r
!= ERROR_SUCCESS
)
1124 r
= MSI_IterateRecords( view
, NULL
, load_feature
, package
);
1125 if (r
!= ERROR_SUCCESS
)
1127 msiobj_release( &view
->hdr
);
1130 r
= MSI_IterateRecords( view
, NULL
, find_feature_children
, package
);
1131 msiobj_release( &view
->hdr
);
1135 static LPWSTR
folder_split_path(LPWSTR p
, WCHAR ch
)
1146 static UINT
load_file_hash(MSIPACKAGE
*package
, MSIFILE
*file
)
1148 static const WCHAR query
[] = {
1149 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1150 '`','M','s','i','F','i','l','e','H','a','s','h','`',' ',
1151 'W','H','E','R','E',' ','`','F','i','l','e','_','`',' ','=',' ','\'','%','s','\'',0};
1152 MSIQUERY
*view
= NULL
;
1153 MSIRECORD
*row
= NULL
;
1156 TRACE("%s\n", debugstr_w(file
->File
));
1158 r
= MSI_OpenQuery(package
->db
, &view
, query
, file
->File
);
1159 if (r
!= ERROR_SUCCESS
)
1162 r
= MSI_ViewExecute(view
, NULL
);
1163 if (r
!= ERROR_SUCCESS
)
1166 r
= MSI_ViewFetch(view
, &row
);
1167 if (r
!= ERROR_SUCCESS
)
1170 file
->hash
.dwFileHashInfoSize
= sizeof(MSIFILEHASHINFO
);
1171 file
->hash
.dwData
[0] = MSI_RecordGetInteger(row
, 3);
1172 file
->hash
.dwData
[1] = MSI_RecordGetInteger(row
, 4);
1173 file
->hash
.dwData
[2] = MSI_RecordGetInteger(row
, 5);
1174 file
->hash
.dwData
[3] = MSI_RecordGetInteger(row
, 6);
1177 if (view
) msiobj_release(&view
->hdr
);
1178 if (row
) msiobj_release(&row
->hdr
);
1182 static UINT
load_file_disk_id( MSIPACKAGE
*package
, MSIFILE
*file
)
1185 static const WCHAR query
[] = {
1186 'S','E','L','E','C','T',' ','`','D','i','s','k','I','d','`',' ', 'F','R','O','M',' ',
1187 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
1188 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',' ','%','i',0};
1190 row
= MSI_QueryGetRecord( package
->db
, query
, file
->Sequence
);
1193 WARN("query failed\n");
1194 return ERROR_FUNCTION_FAILED
;
1197 file
->disk_id
= MSI_RecordGetInteger( row
, 1 );
1198 msiobj_release( &row
->hdr
);
1199 return ERROR_SUCCESS
;
1202 static UINT
load_file(MSIRECORD
*row
, LPVOID param
)
1204 MSIPACKAGE
* package
= param
;
1208 /* fill in the data */
1210 file
= msi_alloc_zero( sizeof (MSIFILE
) );
1212 return ERROR_NOT_ENOUGH_MEMORY
;
1214 file
->File
= msi_dup_record_field( row
, 1 );
1216 component
= MSI_RecordGetString( row
, 2 );
1217 file
->Component
= msi_get_loaded_component( package
, component
);
1219 if (!file
->Component
)
1221 WARN("Component not found: %s\n", debugstr_w(component
));
1222 msi_free(file
->File
);
1224 return ERROR_SUCCESS
;
1227 file
->FileName
= msi_dup_record_field( row
, 3 );
1228 msi_reduce_to_long_filename( file
->FileName
);
1230 file
->ShortName
= msi_dup_record_field( row
, 3 );
1231 file
->LongName
= strdupW( folder_split_path(file
->ShortName
, '|'));
1233 file
->FileSize
= MSI_RecordGetInteger( row
, 4 );
1234 file
->Version
= msi_dup_record_field( row
, 5 );
1235 file
->Language
= msi_dup_record_field( row
, 6 );
1236 file
->Attributes
= MSI_RecordGetInteger( row
, 7 );
1237 file
->Sequence
= MSI_RecordGetInteger( row
, 8 );
1239 file
->state
= msifs_invalid
;
1241 /* if the compressed bits are not set in the file attributes,
1242 * then read the information from the package word count property
1244 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1246 file
->IsCompressed
= FALSE
;
1248 else if (file
->Attributes
&
1249 (msidbFileAttributesCompressed
| msidbFileAttributesPatchAdded
))
1251 file
->IsCompressed
= TRUE
;
1253 else if (file
->Attributes
& msidbFileAttributesNoncompressed
)
1255 file
->IsCompressed
= FALSE
;
1259 file
->IsCompressed
= package
->WordCount
& msidbSumInfoSourceTypeCompressed
;
1262 load_file_hash(package
, file
);
1263 load_file_disk_id(package
, file
);
1265 TRACE("File Loaded (%s)\n",debugstr_w(file
->File
));
1267 list_add_tail( &package
->files
, &file
->entry
);
1269 return ERROR_SUCCESS
;
1272 static UINT
load_all_files(MSIPACKAGE
*package
)
1274 static const WCHAR query
[] = {
1275 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1276 '`','F','i','l','e','`',' ', 'O','R','D','E','R',' ','B','Y',' ',
1277 '`','S','e','q','u','e','n','c','e','`', 0};
1281 if (!list_empty(&package
->files
))
1282 return ERROR_SUCCESS
;
1284 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1285 if (rc
!= ERROR_SUCCESS
)
1286 return ERROR_SUCCESS
;
1288 rc
= MSI_IterateRecords(view
, NULL
, load_file
, package
);
1289 msiobj_release(&view
->hdr
);
1293 static UINT
load_media( MSIRECORD
*row
, LPVOID param
)
1295 MSIPACKAGE
*package
= param
;
1296 UINT disk_id
= MSI_RecordGetInteger( row
, 1 );
1297 const WCHAR
*cabinet
= MSI_RecordGetString( row
, 4 );
1299 /* FIXME: load external cabinets and directory sources too */
1300 if (!cabinet
|| cabinet
[0] != '#') return ERROR_SUCCESS
;
1301 msi_add_cabinet_stream( package
, disk_id
, package
->db
->storage
, cabinet
);
1302 return ERROR_SUCCESS
;
1305 static UINT
load_all_media( MSIPACKAGE
*package
)
1307 static const WCHAR query
[] = {
1308 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`',
1309 'M','e','d','i','a','`',' ','O','R','D','E','R',' ','B','Y',' ',
1310 '`','D','i','s','k','I','d','`',0};
1314 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1315 if (r
!= ERROR_SUCCESS
)
1316 return ERROR_SUCCESS
;
1318 r
= MSI_IterateRecords( view
, NULL
, load_media
, package
);
1319 msiobj_release( &view
->hdr
);
1323 static UINT
load_patch(MSIRECORD
*row
, LPVOID param
)
1325 MSIPACKAGE
*package
= param
;
1326 MSIFILEPATCH
*patch
;
1329 patch
= msi_alloc_zero( sizeof (MSIFILEPATCH
) );
1331 return ERROR_NOT_ENOUGH_MEMORY
;
1333 file_key
= msi_dup_record_field( row
, 1 );
1334 patch
->File
= msi_get_loaded_file( package
, file_key
);
1339 ERR("Failed to find target for patch in File table\n");
1341 return ERROR_FUNCTION_FAILED
;
1344 patch
->Sequence
= MSI_RecordGetInteger( row
, 2 );
1346 /* FIXME: The database should be properly transformed */
1347 patch
->Sequence
+= MSI_INITIAL_MEDIA_TRANSFORM_OFFSET
;
1349 patch
->PatchSize
= MSI_RecordGetInteger( row
, 3 );
1350 patch
->Attributes
= MSI_RecordGetInteger( row
, 4 );
1351 patch
->IsApplied
= FALSE
;
1354 * Header field - for patch validation.
1355 * _StreamRef - External key into MsiPatchHeaders (instead of the header field)
1358 TRACE("Patch Loaded (%s)\n", debugstr_w(patch
->File
->File
));
1360 list_add_tail( &package
->filepatches
, &patch
->entry
);
1362 return ERROR_SUCCESS
;
1365 static UINT
load_all_patches(MSIPACKAGE
*package
)
1367 static const WCHAR query
[] = {
1368 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1369 '`','P','a','t','c','h','`',' ','O','R','D','E','R',' ','B','Y',' ',
1370 '`','S','e','q','u','e','n','c','e','`',0};
1374 if (!list_empty(&package
->filepatches
))
1375 return ERROR_SUCCESS
;
1377 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1378 if (rc
!= ERROR_SUCCESS
)
1379 return ERROR_SUCCESS
;
1381 rc
= MSI_IterateRecords(view
, NULL
, load_patch
, package
);
1382 msiobj_release(&view
->hdr
);
1386 static UINT
load_folder_persistence( MSIPACKAGE
*package
, MSIFOLDER
*folder
)
1388 static const WCHAR query
[] = {
1389 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1390 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',' ','W','H','E','R','E',' ',
1391 '`','D','i','r','e','c','t','o','r','y','_','`',' ','=','\'','%','s','\'',0};
1394 folder
->persistent
= FALSE
;
1395 if (!MSI_OpenQuery( package
->db
, &view
, query
, folder
->Directory
))
1397 if (!MSI_ViewExecute( view
, NULL
))
1400 if (!MSI_ViewFetch( view
, &rec
))
1402 TRACE("directory %s is persistent\n", debugstr_w(folder
->Directory
));
1403 folder
->persistent
= TRUE
;
1404 msiobj_release( &rec
->hdr
);
1407 msiobj_release( &view
->hdr
);
1409 return ERROR_SUCCESS
;
1412 static UINT
load_folder( MSIRECORD
*row
, LPVOID param
)
1414 MSIPACKAGE
*package
= param
;
1415 static WCHAR szEmpty
[] = { 0 };
1416 LPWSTR p
, tgt_short
, tgt_long
, src_short
, src_long
;
1419 if (!(folder
= msi_alloc_zero( sizeof(*folder
) ))) return ERROR_NOT_ENOUGH_MEMORY
;
1420 list_init( &folder
->children
);
1421 folder
->Directory
= msi_dup_record_field( row
, 1 );
1422 folder
->Parent
= msi_dup_record_field( row
, 2 );
1423 p
= msi_dup_record_field(row
, 3);
1425 TRACE("%s\n", debugstr_w(folder
->Directory
));
1427 /* split src and target dir */
1429 src_short
= folder_split_path( p
, ':' );
1431 /* split the long and short paths */
1432 tgt_long
= folder_split_path( tgt_short
, '|' );
1433 src_long
= folder_split_path( src_short
, '|' );
1435 /* check for no-op dirs */
1436 if (tgt_short
&& !strcmpW( szDot
, tgt_short
))
1437 tgt_short
= szEmpty
;
1438 if (src_short
&& !strcmpW( szDot
, src_short
))
1439 src_short
= szEmpty
;
1442 tgt_long
= tgt_short
;
1445 src_short
= tgt_short
;
1446 src_long
= tgt_long
;
1450 src_long
= src_short
;
1452 /* FIXME: use the target short path too */
1453 folder
->TargetDefault
= strdupW(tgt_long
);
1454 folder
->SourceShortPath
= strdupW(src_short
);
1455 folder
->SourceLongPath
= strdupW(src_long
);
1458 TRACE("TargetDefault = %s\n",debugstr_w( folder
->TargetDefault
));
1459 TRACE("SourceLong = %s\n", debugstr_w( folder
->SourceLongPath
));
1460 TRACE("SourceShort = %s\n", debugstr_w( folder
->SourceShortPath
));
1462 load_folder_persistence( package
, folder
);
1464 list_add_tail( &package
->folders
, &folder
->entry
);
1465 return ERROR_SUCCESS
;
1468 static UINT
add_folder_child( MSIFOLDER
*parent
, MSIFOLDER
*child
)
1472 if (!(fl
= msi_alloc( sizeof(*fl
) ))) return ERROR_NOT_ENOUGH_MEMORY
;
1474 list_add_tail( &parent
->children
, &fl
->entry
);
1475 return ERROR_SUCCESS
;
1478 static UINT
find_folder_children( MSIRECORD
*row
, LPVOID param
)
1480 MSIPACKAGE
*package
= param
;
1481 MSIFOLDER
*parent
, *child
;
1483 if (!(child
= msi_get_loaded_folder( package
, MSI_RecordGetString( row
, 1 ) )))
1484 return ERROR_FUNCTION_FAILED
;
1486 if (!child
->Parent
) return ERROR_SUCCESS
;
1488 if (!(parent
= msi_get_loaded_folder( package
, child
->Parent
)))
1489 return ERROR_FUNCTION_FAILED
;
1491 return add_folder_child( parent
, child
);
1494 static UINT
load_all_folders( MSIPACKAGE
*package
)
1496 static const WCHAR query
[] = {
1497 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1498 '`','D','i','r','e','c','t','o','r','y','`',0};
1502 if (!list_empty(&package
->folders
))
1503 return ERROR_SUCCESS
;
1505 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1506 if (r
!= ERROR_SUCCESS
)
1509 r
= MSI_IterateRecords( view
, NULL
, load_folder
, package
);
1510 if (r
!= ERROR_SUCCESS
)
1512 msiobj_release( &view
->hdr
);
1515 r
= MSI_IterateRecords( view
, NULL
, find_folder_children
, package
);
1516 msiobj_release( &view
->hdr
);
1520 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1522 msi_set_property( package
->db
, szCostingComplete
, szZero
, -1 );
1523 msi_set_property( package
->db
, szRootDrive
, szCRoot
, -1 );
1525 load_all_folders( package
);
1526 msi_load_all_components( package
);
1527 msi_load_all_features( package
);
1528 load_all_files( package
);
1529 load_all_patches( package
);
1530 load_all_media( package
);
1532 return ERROR_SUCCESS
;
1535 static UINT
execute_script_action( MSIPACKAGE
*package
, UINT script
, UINT index
)
1537 const WCHAR
*action
= package
->script
->Actions
[script
][index
];
1538 ui_actionstart( package
, action
);
1539 TRACE("executing %s\n", debugstr_w(action
));
1540 return ACTION_PerformAction( package
, action
, script
);
1543 static UINT
execute_script( MSIPACKAGE
*package
, UINT script
)
1545 UINT i
, rc
= ERROR_SUCCESS
;
1547 TRACE("executing script %u\n", script
);
1549 if (!package
->script
)
1551 ERR("no script!\n");
1552 return ERROR_FUNCTION_FAILED
;
1554 if (script
== SCRIPT_ROLLBACK
)
1556 for (i
= package
->script
->ActionCount
[script
]; i
> 0; i
--)
1558 rc
= execute_script_action( package
, script
, i
- 1 );
1559 if (rc
!= ERROR_SUCCESS
) break;
1564 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
1566 rc
= execute_script_action( package
, script
, i
);
1567 if (rc
!= ERROR_SUCCESS
) break;
1570 msi_free_action_script(package
, script
);
1574 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1576 return ERROR_SUCCESS
;
1579 static void get_client_counts( MSIPACKAGE
*package
)
1584 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1586 if (!comp
->ComponentId
) continue;
1588 if (MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, szLocalSid
, &hkey
, FALSE
) &&
1589 MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, NULL
, &hkey
, FALSE
))
1591 comp
->num_clients
= 0;
1594 RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, (DWORD
*)&comp
->num_clients
,
1595 NULL
, NULL
, NULL
, NULL
);
1596 RegCloseKey( hkey
);
1600 static void ACTION_GetComponentInstallStates(MSIPACKAGE
*package
)
1605 LIST_FOR_EACH_ENTRY(comp
, &package
->components
, MSICOMPONENT
, entry
)
1607 if (!comp
->ComponentId
) continue;
1609 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1610 MSIINSTALLCONTEXT_USERMANAGED
, comp
->ComponentId
,
1612 if (r
== ERROR_SUCCESS
) continue;
1614 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1615 MSIINSTALLCONTEXT_USERUNMANAGED
, comp
->ComponentId
,
1617 if (r
== ERROR_SUCCESS
) continue;
1619 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1620 MSIINSTALLCONTEXT_MACHINE
, comp
->ComponentId
,
1622 if (r
== ERROR_SUCCESS
) continue;
1624 comp
->Installed
= INSTALLSTATE_ABSENT
;
1628 static void ACTION_GetFeatureInstallStates(MSIPACKAGE
*package
)
1630 MSIFEATURE
*feature
;
1632 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1634 INSTALLSTATE state
= MsiQueryFeatureStateW( package
->ProductCode
, feature
->Feature
);
1636 if (state
== INSTALLSTATE_UNKNOWN
|| state
== INSTALLSTATE_INVALIDARG
)
1637 feature
->Installed
= INSTALLSTATE_ABSENT
;
1639 feature
->Installed
= state
;
1643 static inline BOOL
is_feature_selected( MSIFEATURE
*feature
, INT level
)
1645 return (feature
->Level
> 0 && feature
->Level
<= level
);
1648 static BOOL
process_state_property(MSIPACKAGE
* package
, int level
,
1649 LPCWSTR property
, INSTALLSTATE state
)
1652 MSIFEATURE
*feature
;
1653 BOOL remove
= !strcmpW(property
, szRemove
);
1654 BOOL reinstall
= !strcmpW(property
, szReinstall
);
1656 override
= msi_dup_property( package
->db
, property
);
1660 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1662 if (feature
->Level
<= 0)
1666 state
= (feature
->Installed
== INSTALLSTATE_ABSENT
? INSTALLSTATE_UNKNOWN
: feature
->Installed
);
1668 state
= (feature
->Installed
== INSTALLSTATE_ABSENT
? INSTALLSTATE_UNKNOWN
: INSTALLSTATE_ABSENT
);
1670 if (!strcmpiW( override
, szAll
))
1672 feature
->Action
= state
;
1673 feature
->ActionRequest
= state
;
1677 LPWSTR ptr
= override
;
1678 LPWSTR ptr2
= strchrW(override
,',');
1682 int len
= ptr2
- ptr
;
1684 if ((ptr2
&& strlenW(feature
->Feature
) == len
&& !strncmpW(ptr
, feature
->Feature
, len
))
1685 || (!ptr2
&& !strcmpW(ptr
, feature
->Feature
)))
1687 feature
->Action
= state
;
1688 feature
->ActionRequest
= state
;
1694 ptr2
= strchrW(ptr
,',');
1705 static BOOL
process_overrides( MSIPACKAGE
*package
, int level
)
1707 static const WCHAR szAddLocal
[] =
1708 {'A','D','D','L','O','C','A','L',0};
1709 static const WCHAR szAddSource
[] =
1710 {'A','D','D','S','O','U','R','C','E',0};
1711 static const WCHAR szAdvertise
[] =
1712 {'A','D','V','E','R','T','I','S','E',0};
1715 /* all these activation/deactivation things happen in order and things
1716 * later on the list override things earlier on the list.
1718 * 0 INSTALLLEVEL processing
1731 ret
|= process_state_property( package
, level
, szAddLocal
, INSTALLSTATE_LOCAL
);
1732 ret
|= process_state_property( package
, level
, szRemove
, INSTALLSTATE_ABSENT
);
1733 ret
|= process_state_property( package
, level
, szAddSource
, INSTALLSTATE_SOURCE
);
1734 ret
|= process_state_property( package
, level
, szReinstall
, INSTALLSTATE_UNKNOWN
);
1735 ret
|= process_state_property( package
, level
, szAdvertise
, INSTALLSTATE_ADVERTISED
);
1737 if (ret
&& !package
->full_reinstall
)
1738 msi_set_property( package
->db
, szPreselected
, szOne
, -1 );
1743 UINT
MSI_SetFeatureStates(MSIPACKAGE
*package
)
1746 MSICOMPONENT
* component
;
1747 MSIFEATURE
*feature
;
1749 TRACE("Checking Install Level\n");
1751 level
= msi_get_property_int(package
->db
, szInstallLevel
, 1);
1753 if (!msi_get_property_int( package
->db
, szPreselected
, 0 ))
1755 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1757 if (!is_feature_selected( feature
, level
)) continue;
1759 if (feature
->ActionRequest
== INSTALLSTATE_UNKNOWN
)
1761 if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1763 feature
->Action
= INSTALLSTATE_SOURCE
;
1764 feature
->ActionRequest
= INSTALLSTATE_SOURCE
;
1766 else if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1768 feature
->Action
= INSTALLSTATE_ADVERTISED
;
1769 feature
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1773 feature
->Action
= INSTALLSTATE_LOCAL
;
1774 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1778 /* disable child features of unselected parent or follow parent */
1779 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1783 LIST_FOR_EACH_ENTRY( fl
, &feature
->Children
, FeatureList
, entry
)
1785 if (!is_feature_selected( feature
, level
))
1787 fl
->feature
->Action
= INSTALLSTATE_UNKNOWN
;
1788 fl
->feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1790 else if (fl
->feature
->Attributes
& msidbFeatureAttributesFollowParent
)
1792 TRACE("feature %s (level %d request %d) follows parent %s (level %d request %d)\n",
1793 debugstr_w(fl
->feature
->Feature
), fl
->feature
->Level
, fl
->feature
->ActionRequest
,
1794 debugstr_w(feature
->Feature
), feature
->Level
, feature
->ActionRequest
);
1795 fl
->feature
->Action
= feature
->Action
;
1796 fl
->feature
->ActionRequest
= feature
->ActionRequest
;
1801 else /* preselected */
1803 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1805 if (!is_feature_selected( feature
, level
)) continue;
1807 if (feature
->ActionRequest
== INSTALLSTATE_UNKNOWN
)
1809 if (feature
->Installed
== INSTALLSTATE_ABSENT
)
1811 feature
->Action
= INSTALLSTATE_UNKNOWN
;
1812 feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1816 feature
->Action
= feature
->Installed
;
1817 feature
->ActionRequest
= feature
->Installed
;
1821 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1825 if (!is_feature_selected( feature
, level
)) continue;
1827 LIST_FOR_EACH_ENTRY( fl
, &feature
->Children
, FeatureList
, entry
)
1829 if (fl
->feature
->Attributes
& msidbFeatureAttributesFollowParent
&&
1830 (!(feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)))
1832 TRACE("feature %s (level %d request %d) follows parent %s (level %d request %d)\n",
1833 debugstr_w(fl
->feature
->Feature
), fl
->feature
->Level
, fl
->feature
->ActionRequest
,
1834 debugstr_w(feature
->Feature
), feature
->Level
, feature
->ActionRequest
);
1835 fl
->feature
->Action
= feature
->Action
;
1836 fl
->feature
->ActionRequest
= feature
->ActionRequest
;
1842 /* now we want to set component state based based on feature state */
1843 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1847 TRACE("examining feature %s (level %d installed %d request %d action %d)\n",
1848 debugstr_w(feature
->Feature
), feature
->Level
, feature
->Installed
,
1849 feature
->ActionRequest
, feature
->Action
);
1851 /* features with components that have compressed files are made local */
1852 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1854 if (cl
->component
->ForceLocalState
&&
1855 feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1857 feature
->Action
= INSTALLSTATE_LOCAL
;
1858 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1863 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1865 component
= cl
->component
;
1867 switch (feature
->ActionRequest
)
1869 case INSTALLSTATE_ABSENT
:
1870 component
->anyAbsent
= 1;
1872 case INSTALLSTATE_ADVERTISED
:
1873 component
->hasAdvertisedFeature
= 1;
1875 case INSTALLSTATE_SOURCE
:
1876 component
->hasSourceFeature
= 1;
1878 case INSTALLSTATE_LOCAL
:
1879 component
->hasLocalFeature
= 1;
1881 case INSTALLSTATE_DEFAULT
:
1882 if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1883 component
->hasAdvertisedFeature
= 1;
1884 else if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1885 component
->hasSourceFeature
= 1;
1887 component
->hasLocalFeature
= 1;
1895 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1897 /* check if it's local or source */
1898 if (!(component
->Attributes
& msidbComponentAttributesOptional
) &&
1899 (component
->hasLocalFeature
|| component
->hasSourceFeature
))
1901 if ((component
->Attributes
& msidbComponentAttributesSourceOnly
) &&
1902 !component
->ForceLocalState
)
1904 component
->Action
= INSTALLSTATE_SOURCE
;
1905 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1909 component
->Action
= INSTALLSTATE_LOCAL
;
1910 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1915 /* if any feature is local, the component must be local too */
1916 if (component
->hasLocalFeature
)
1918 component
->Action
= INSTALLSTATE_LOCAL
;
1919 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1922 if (component
->hasSourceFeature
)
1924 component
->Action
= INSTALLSTATE_SOURCE
;
1925 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1928 if (component
->hasAdvertisedFeature
)
1930 component
->Action
= INSTALLSTATE_ADVERTISED
;
1931 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1934 TRACE("nobody wants component %s\n", debugstr_w(component
->Component
));
1935 if (component
->anyAbsent
&& component
->ComponentId
)
1937 component
->Action
= INSTALLSTATE_ABSENT
;
1938 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
1942 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1944 if (component
->ActionRequest
== INSTALLSTATE_DEFAULT
)
1946 TRACE("%s was default, setting to local\n", debugstr_w(component
->Component
));
1947 component
->Action
= INSTALLSTATE_LOCAL
;
1948 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1951 if (component
->ActionRequest
== INSTALLSTATE_SOURCE
&&
1952 component
->Installed
== INSTALLSTATE_SOURCE
&&
1953 component
->hasSourceFeature
)
1955 component
->Action
= INSTALLSTATE_UNKNOWN
;
1956 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1959 TRACE("component %s (installed %d request %d action %d)\n",
1960 debugstr_w(component
->Component
), component
->Installed
, component
->ActionRequest
, component
->Action
);
1962 if (component
->Action
== INSTALLSTATE_LOCAL
|| component
->Action
== INSTALLSTATE_SOURCE
)
1963 component
->num_clients
++;
1964 else if (component
->Action
== INSTALLSTATE_ABSENT
)
1965 component
->num_clients
--;
1968 return ERROR_SUCCESS
;
1971 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1973 MSIPACKAGE
*package
= param
;
1975 MSIFEATURE
*feature
;
1977 name
= MSI_RecordGetString( row
, 1 );
1979 feature
= msi_get_loaded_feature( package
, name
);
1981 ERR("FAILED to find loaded feature %s\n",debugstr_w(name
));
1985 Condition
= MSI_RecordGetString(row
,3);
1987 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
1989 int level
= MSI_RecordGetInteger(row
,2);
1990 TRACE("Resetting feature %s to level %i\n", debugstr_w(name
), level
);
1991 feature
->Level
= level
;
1994 return ERROR_SUCCESS
;
1997 VS_FIXEDFILEINFO
*msi_get_disk_file_version( LPCWSTR filename
)
1999 static const WCHAR name
[] = {'\\',0};
2000 VS_FIXEDFILEINFO
*ptr
, *ret
;
2002 DWORD versize
, handle
;
2005 versize
= GetFileVersionInfoSizeW( filename
, &handle
);
2009 version
= msi_alloc( versize
);
2013 GetFileVersionInfoW( filename
, 0, versize
, version
);
2015 if (!VerQueryValueW( version
, name
, (LPVOID
*)&ptr
, &sz
))
2017 msi_free( version
);
2021 ret
= msi_alloc( sz
);
2022 memcpy( ret
, ptr
, sz
);
2024 msi_free( version
);
2028 int msi_compare_file_versions( VS_FIXEDFILEINFO
*fi
, const WCHAR
*version
)
2032 msi_parse_version_string( version
, &ms
, &ls
);
2034 if (fi
->dwFileVersionMS
> ms
) return 1;
2035 else if (fi
->dwFileVersionMS
< ms
) return -1;
2036 else if (fi
->dwFileVersionLS
> ls
) return 1;
2037 else if (fi
->dwFileVersionLS
< ls
) return -1;
2041 int msi_compare_font_versions( const WCHAR
*ver1
, const WCHAR
*ver2
)
2045 msi_parse_version_string( ver1
, &ms1
, NULL
);
2046 msi_parse_version_string( ver2
, &ms2
, NULL
);
2048 if (ms1
> ms2
) return 1;
2049 else if (ms1
< ms2
) return -1;
2053 DWORD
msi_get_disk_file_size( LPCWSTR filename
)
2058 file
= CreateFileW( filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
2059 if (file
== INVALID_HANDLE_VALUE
)
2060 return INVALID_FILE_SIZE
;
2062 size
= GetFileSize( file
, NULL
);
2063 TRACE("size is %u\n", size
);
2064 CloseHandle( file
);
2068 BOOL
msi_file_hash_matches( MSIFILE
*file
)
2071 MSIFILEHASHINFO hash
;
2073 hash
.dwFileHashInfoSize
= sizeof(MSIFILEHASHINFO
);
2074 r
= MsiGetFileHashW( file
->TargetPath
, 0, &hash
);
2075 if (r
!= ERROR_SUCCESS
)
2078 return !memcmp( &hash
, &file
->hash
, sizeof(MSIFILEHASHINFO
) );
2081 static WCHAR
*get_temp_dir( void )
2084 WCHAR tmp
[MAX_PATH
], dir
[MAX_PATH
];
2086 GetTempPathW( MAX_PATH
, tmp
);
2089 if (!GetTempFileNameW( tmp
, szMsi
, ++id
, dir
)) return NULL
;
2090 if (CreateDirectoryW( dir
, NULL
)) break;
2092 return strdupW( dir
);
2096 * msi_build_directory_name()
2098 * This function is to save messing round with directory names
2099 * It handles adding backslashes between path segments,
2100 * and can add \ at the end of the directory name if told to.
2102 * It takes a variable number of arguments.
2103 * It always allocates a new string for the result, so make sure
2104 * to free the return value when finished with it.
2106 * The first arg is the number of path segments that follow.
2107 * The arguments following count are a list of path segments.
2108 * A path segment may be NULL.
2110 * Path segments will be added with a \ separating them.
2111 * A \ will not be added after the last segment, however if the
2112 * last segment is NULL, then the last character will be a \
2114 WCHAR
*msi_build_directory_name( DWORD count
, ... )
2120 va_start( va
, count
);
2121 for (i
= 0; i
< count
; i
++)
2123 const WCHAR
*str
= va_arg( va
, const WCHAR
* );
2124 if (str
) sz
+= strlenW( str
) + 1;
2128 dir
= msi_alloc( sz
* sizeof(WCHAR
) );
2131 va_start( va
, count
);
2132 for (i
= 0; i
< count
; i
++)
2134 const WCHAR
*str
= va_arg( va
, const WCHAR
* );
2136 strcatW( dir
, str
);
2137 if ( i
+ 1 != count
&& dir
[0] && dir
[strlenW( dir
) - 1] != '\\') strcatW( dir
, szBackSlash
);
2143 static void set_target_path( MSIPACKAGE
*package
, MSIFILE
*file
)
2145 MSIASSEMBLY
*assembly
= file
->Component
->assembly
;
2147 TRACE("file %s is named %s\n", debugstr_w(file
->File
), debugstr_w(file
->FileName
));
2149 msi_free( file
->TargetPath
);
2150 if (assembly
&& !assembly
->application
)
2152 if (!assembly
->tempdir
) assembly
->tempdir
= get_temp_dir();
2153 file
->TargetPath
= msi_build_directory_name( 2, assembly
->tempdir
, file
->FileName
);
2154 msi_track_tempfile( package
, file
->TargetPath
);
2158 const WCHAR
*dir
= msi_get_target_folder( package
, file
->Component
->Directory
);
2159 file
->TargetPath
= msi_build_directory_name( 2, dir
, file
->FileName
);
2162 TRACE("resolves to %s\n", debugstr_w(file
->TargetPath
));
2165 static UINT
calculate_file_cost( MSIPACKAGE
*package
)
2167 VS_FIXEDFILEINFO
*file_version
;
2168 WCHAR
*font_version
;
2171 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2173 MSICOMPONENT
*comp
= file
->Component
;
2176 if (!comp
->Enabled
) continue;
2178 if (file
->IsCompressed
)
2179 comp
->ForceLocalState
= TRUE
;
2181 set_target_path( package
, file
);
2183 if ((comp
->assembly
&& !comp
->assembly
->installed
) ||
2184 GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
2186 comp
->Cost
+= file
->FileSize
;
2189 file_size
= msi_get_disk_file_size( file
->TargetPath
);
2193 if ((file_version
= msi_get_disk_file_version( file
->TargetPath
)))
2195 if (msi_compare_file_versions( file_version
, file
->Version
) < 0)
2197 comp
->Cost
+= file
->FileSize
- file_size
;
2199 msi_free( file_version
);
2202 else if ((font_version
= msi_font_version_from_file( file
->TargetPath
)))
2204 if (msi_compare_font_versions( font_version
, file
->Version
) < 0)
2206 comp
->Cost
+= file
->FileSize
- file_size
;
2208 msi_free( font_version
);
2212 if (file_size
!= file
->FileSize
)
2214 comp
->Cost
+= file
->FileSize
- file_size
;
2217 return ERROR_SUCCESS
;
2220 WCHAR
*msi_normalize_path( const WCHAR
*in
)
2222 const WCHAR
*p
= in
;
2224 int n
, len
= strlenW( in
) + 2;
2226 if (!(q
= ret
= msi_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
2231 /* copy until the end of the string or a space */
2232 while (*p
!= ' ' && (*q
= *p
))
2235 /* reduce many backslashes to one */
2236 if (*p
!= '\\' || *q
!= '\\')
2240 /* quit at the end of the string */
2244 /* count the number of spaces */
2249 /* if it's leading or trailing space, skip it */
2250 if ( len
== 0 || p
[-1] == '\\' || p
[n
] == '\\' )
2252 else /* copy n spaces */
2253 while (n
&& (*q
++ = *p
++)) n
--;
2255 while (q
- ret
> 0 && q
[-1] == ' ') q
--;
2256 if (q
- ret
> 0 && q
[-1] != '\\')
2264 static WCHAR
*get_install_location( MSIPACKAGE
*package
)
2269 if (!package
->ProductCode
) return NULL
;
2270 if (MSIREG_OpenInstallProps( package
->ProductCode
, package
->Context
, NULL
, &hkey
, FALSE
)) return NULL
;
2271 if ((path
= msi_reg_get_val_str( hkey
, szInstallLocation
)) && !path
[0])
2276 RegCloseKey( hkey
);
2280 void msi_resolve_target_folder( MSIPACKAGE
*package
, const WCHAR
*name
, BOOL load_prop
)
2283 MSIFOLDER
*folder
, *parent
, *child
;
2284 WCHAR
*path
, *normalized_path
;
2286 TRACE("resolving %s\n", debugstr_w(name
));
2288 if (!(folder
= msi_get_loaded_folder( package
, name
))) return;
2290 if (!strcmpW( folder
->Directory
, szTargetDir
)) /* special resolving for target root dir */
2292 if (!(path
= get_install_location( package
)) &&
2293 (!load_prop
|| !(path
= msi_dup_property( package
->db
, szTargetDir
))))
2295 path
= msi_dup_property( package
->db
, szRootDrive
);
2298 else if (!load_prop
|| !(path
= msi_dup_property( package
->db
, folder
->Directory
)))
2300 if (folder
->Parent
&& strcmpW( folder
->Directory
, folder
->Parent
))
2302 parent
= msi_get_loaded_folder( package
, folder
->Parent
);
2303 path
= msi_build_directory_name( 3, parent
->ResolvedTarget
, folder
->TargetDefault
, NULL
);
2306 path
= msi_build_directory_name( 2, folder
->TargetDefault
, NULL
);
2308 normalized_path
= msi_normalize_path( path
);
2310 if (folder
->ResolvedTarget
&& !strcmpiW( normalized_path
, folder
->ResolvedTarget
))
2312 TRACE("%s already resolved to %s\n", debugstr_w(name
), debugstr_w(folder
->ResolvedTarget
));
2313 msi_free( normalized_path
);
2316 msi_set_property( package
->db
, folder
->Directory
, normalized_path
, -1 );
2317 msi_free( folder
->ResolvedTarget
);
2318 folder
->ResolvedTarget
= normalized_path
;
2320 LIST_FOR_EACH_ENTRY( fl
, &folder
->children
, FolderList
, entry
)
2323 msi_resolve_target_folder( package
, child
->Directory
, load_prop
);
2325 TRACE("%s resolves to %s\n", debugstr_w(name
), debugstr_w(folder
->ResolvedTarget
));
2328 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2330 static const WCHAR query
[] =
2331 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2332 '`','C','o','n','d','i','t','i','o','n','`',0};
2333 static const WCHAR szOutOfDiskSpace
[] =
2334 {'O','u','t','O','f','D','i','s','k','S','p','a','c','e',0};
2335 static const WCHAR szPrimaryFolder
[] =
2336 {'P','R','I','M','A','R','Y','F','O','L','D','E','R',0};
2337 static const WCHAR szPrimaryVolumePath
[] =
2338 {'P','r','i','m','a','r','y','V','o','l','u','m','e','P','a','t','h',0};
2339 static const WCHAR szPrimaryVolumeSpaceAvailable
[] =
2340 {'P','r','i','m','a','r','y','V','o','l','u','m','e','S','p','a','c','e',
2341 'A','v','a','i','l','a','b','l','e',0};
2342 static const WCHAR szOutOfNoRbDiskSpace
[] =
2343 {'O','u','t','O','f','N','o','R','b','D','i','s','k','S','p','a','c','e',0};
2346 WCHAR
*level
, *primary_key
, *primary_folder
;
2349 TRACE("Building directory properties\n");
2350 msi_resolve_target_folder( package
, szTargetDir
, TRUE
);
2352 TRACE("Evaluating component conditions\n");
2353 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2355 if (MSI_EvaluateConditionW( package
, comp
->Condition
) == MSICONDITION_FALSE
)
2357 TRACE("Disabling component %s\n", debugstr_w(comp
->Component
));
2358 comp
->Enabled
= FALSE
;
2361 comp
->Enabled
= TRUE
;
2363 get_client_counts( package
);
2365 /* read components states from the registry */
2366 ACTION_GetComponentInstallStates(package
);
2367 ACTION_GetFeatureInstallStates(package
);
2369 if (!process_overrides( package
, msi_get_property_int( package
->db
, szInstallLevel
, 1 ) ))
2371 TRACE("Evaluating feature conditions\n");
2373 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
2374 if (rc
== ERROR_SUCCESS
)
2376 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_CostFinalizeConditions
, package
);
2377 msiobj_release( &view
->hdr
);
2378 if (rc
!= ERROR_SUCCESS
)
2383 TRACE("Calculating file cost\n");
2384 calculate_file_cost( package
);
2386 msi_set_property( package
->db
, szCostingComplete
, szOne
, -1 );
2387 /* set default run level if not set */
2388 level
= msi_dup_property( package
->db
, szInstallLevel
);
2389 if (!level
) msi_set_property( package
->db
, szInstallLevel
, szOne
, -1 );
2392 if ((primary_key
= msi_dup_property( package
->db
, szPrimaryFolder
)))
2394 if ((primary_folder
= msi_dup_property( package
->db
, primary_key
)))
2396 if (((primary_folder
[0] >= 'A' && primary_folder
[0] <= 'Z') ||
2397 (primary_folder
[0] >= 'a' && primary_folder
[0] <= 'z')) && primary_folder
[1] == ':')
2399 ULARGE_INTEGER free
;
2401 primary_folder
[2] = 0;
2402 if (GetDiskFreeSpaceExW( primary_folder
, &free
, NULL
, NULL
))
2404 static const WCHAR fmtW
[] = {'%','l','u',0};
2407 sprintfW( buf
, fmtW
, free
.QuadPart
/ 512 );
2408 msi_set_property( package
->db
, szPrimaryVolumeSpaceAvailable
, buf
, -1 );
2410 msi_set_property( package
->db
, szPrimaryVolumePath
, primary_folder
, 2 );
2412 msi_free( primary_folder
);
2414 msi_free( primary_key
);
2417 /* FIXME: check volume disk space */
2418 msi_set_property( package
->db
, szOutOfDiskSpace
, szZero
, -1 );
2419 msi_set_property( package
->db
, szOutOfNoRbDiskSpace
, szZero
, -1 );
2421 return MSI_SetFeatureStates(package
);
2424 static BYTE
*parse_value( MSIPACKAGE
*package
, const WCHAR
*value
, DWORD len
, DWORD
*type
, DWORD
*size
)
2430 *size
= sizeof(WCHAR
);
2432 if ((data
= msi_alloc( *size
))) *(WCHAR
*)data
= 0;
2435 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
2441 LPWSTR deformated
= NULL
;
2444 deformat_string(package
, &value
[2], &deformated
);
2446 /* binary value type */
2450 *size
= (strlenW(ptr
)/2)+1;
2452 *size
= strlenW(ptr
)/2;
2454 data
= msi_alloc(*size
);
2460 /* if uneven pad with a zero in front */
2466 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2468 TRACE("Uneven byte count\n");
2476 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2479 msi_free(deformated
);
2481 TRACE("Data %i bytes(%i)\n",*size
,count
);
2488 deformat_string(package
, &value
[1], &deformated
);
2491 *size
= sizeof(DWORD
);
2492 data
= msi_alloc(*size
);
2498 if ( (*p
< '0') || (*p
> '9') )
2504 if (deformated
[0] == '-')
2507 TRACE("DWORD %i\n",*(LPDWORD
)data
);
2509 msi_free(deformated
);
2514 const WCHAR
*ptr
= value
;
2517 if (value
[0] == '#')
2520 if (value
[1] == '%')
2523 *type
= REG_EXPAND_SZ
;
2526 data
= (BYTE
*)msi_strdupW( ptr
, len
);
2527 if (len
> strlenW( (const WCHAR
*)data
)) *type
= REG_MULTI_SZ
;
2528 *size
= (len
+ 1) * sizeof(WCHAR
);
2533 static const WCHAR
*get_root_key( MSIPACKAGE
*package
, INT root
, HKEY
*root_key
)
2540 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ))
2542 *root_key
= HKEY_LOCAL_MACHINE
;
2547 *root_key
= HKEY_CURRENT_USER
;
2552 *root_key
= HKEY_CLASSES_ROOT
;
2556 *root_key
= HKEY_CURRENT_USER
;
2560 *root_key
= HKEY_LOCAL_MACHINE
;
2564 *root_key
= HKEY_USERS
;
2568 ERR("Unknown root %i\n", root
);
2575 static inline REGSAM
get_registry_view( const MSICOMPONENT
*comp
)
2578 if (is_wow64
|| is_64bit
)
2579 view
|= (comp
->Attributes
& msidbComponentAttributes64bit
) ? KEY_WOW64_64KEY
: KEY_WOW64_32KEY
;
2583 static HKEY
open_key( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
, BOOL create
)
2585 REGSAM access
= KEY_ALL_ACCESS
;
2586 WCHAR
*subkey
, *p
, *q
;
2587 HKEY hkey
, ret
= NULL
;
2590 access
|= get_registry_view( comp
);
2592 if (!(subkey
= strdupW( path
))) return NULL
;
2594 if ((q
= strchrW( p
, '\\' ))) *q
= 0;
2596 res
= RegCreateKeyExW( root
, subkey
, 0, NULL
, 0, access
, NULL
, &hkey
, NULL
);
2598 res
= RegOpenKeyExW( root
, subkey
, 0, access
, &hkey
);
2601 TRACE("failed to open key %s (%d)\n", debugstr_w(subkey
), res
);
2607 ret
= open_key( comp
, hkey
, q
+ 1, create
);
2608 RegCloseKey( hkey
);
2615 static BOOL
is_special_entry( const WCHAR
*name
)
2617 return (name
&& (name
[0] == '*' || name
[0] == '+') && !name
[1]);
2620 static WCHAR
**split_multi_string_values( const WCHAR
*str
, DWORD len
, DWORD
*count
)
2622 const WCHAR
*p
= str
;
2627 if (!str
) return NULL
;
2628 while ((p
- str
) < len
)
2630 p
+= strlenW( p
) + 1;
2633 if (!(ret
= msi_alloc( *count
* sizeof(WCHAR
*) ))) return NULL
;
2635 while ((p
- str
) < len
)
2637 if (!(ret
[i
] = strdupW( p
)))
2639 for (; i
>= 0; i
--) msi_free( ret
[i
] );
2643 p
+= strlenW( p
) + 1;
2649 static WCHAR
*flatten_multi_string_values( WCHAR
**left
, DWORD left_count
,
2650 WCHAR
**right
, DWORD right_count
, DWORD
*size
)
2655 *size
= sizeof(WCHAR
);
2656 for (i
= 0; i
< left_count
; i
++) *size
+= (strlenW( left
[i
] ) + 1) * sizeof(WCHAR
);
2657 for (i
= 0; i
< right_count
; i
++) *size
+= (strlenW( right
[i
] ) + 1) * sizeof(WCHAR
);
2659 if (!(ret
= p
= msi_alloc( *size
))) return NULL
;
2661 for (i
= 0; i
< left_count
; i
++)
2663 strcpyW( p
, left
[i
] );
2664 p
+= strlenW( p
) + 1;
2666 for (i
= 0; i
< right_count
; i
++)
2668 strcpyW( p
, right
[i
] );
2669 p
+= strlenW( p
) + 1;
2675 static DWORD
remove_duplicate_values( WCHAR
**old
, DWORD old_count
,
2676 WCHAR
**new, DWORD new_count
)
2678 DWORD ret
= old_count
;
2679 unsigned int i
, j
, k
;
2681 for (i
= 0; i
< new_count
; i
++)
2683 for (j
= 0; j
< old_count
; j
++)
2685 if (old
[j
] && !strcmpW( new[i
], old
[j
] ))
2688 for (k
= j
; k
< old_count
- 1; k
++) { old
[k
] = old
[k
+ 1]; }
2704 static WCHAR
*join_multi_string_values( enum join_op op
, WCHAR
**old
, DWORD old_count
,
2705 WCHAR
**new, DWORD new_count
, DWORD
*size
)
2709 case JOIN_OP_APPEND
:
2710 old_count
= remove_duplicate_values( old
, old_count
, new, new_count
);
2711 return flatten_multi_string_values( old
, old_count
, new, new_count
, size
);
2713 case JOIN_OP_PREPEND
:
2714 old_count
= remove_duplicate_values( old
, old_count
, new, new_count
);
2715 return flatten_multi_string_values( new, new_count
, old
, old_count
, size
);
2717 case JOIN_OP_REPLACE
:
2718 return flatten_multi_string_values( new, new_count
, NULL
, 0, size
);
2721 ERR("unhandled join op %u\n", op
);
2726 static BYTE
*build_multi_string_value( BYTE
*old_value
, DWORD old_size
,
2727 BYTE
*new_value
, DWORD new_size
, DWORD
*size
)
2729 DWORD i
, old_len
= 0, new_len
= 0, old_count
= 0, new_count
= 0;
2730 const WCHAR
*new_ptr
= NULL
, *old_ptr
= NULL
;
2731 enum join_op op
= JOIN_OP_REPLACE
;
2732 WCHAR
**old
= NULL
, **new = NULL
;
2735 if (new_size
/ sizeof(WCHAR
) - 1 > 1)
2737 new_ptr
= (const WCHAR
*)new_value
;
2738 new_len
= new_size
/ sizeof(WCHAR
) - 1;
2740 if (!new_ptr
[0] && new_ptr
[new_len
- 1])
2742 op
= JOIN_OP_APPEND
;
2746 else if (new_ptr
[0] && !new_ptr
[new_len
- 1])
2748 op
= JOIN_OP_PREPEND
;
2751 else if (new_len
> 2 && !new_ptr
[0] && !new_ptr
[new_len
- 1])
2753 op
= JOIN_OP_REPLACE
;
2757 new = split_multi_string_values( new_ptr
, new_len
, &new_count
);
2759 if (old_size
/ sizeof(WCHAR
) - 1 > 1)
2761 old_ptr
= (const WCHAR
*)old_value
;
2762 old_len
= old_size
/ sizeof(WCHAR
) - 1;
2763 old
= split_multi_string_values( old_ptr
, old_len
, &old_count
);
2765 ret
= (BYTE
*)join_multi_string_values( op
, old
, old_count
, new, new_count
, size
);
2766 for (i
= 0; i
< old_count
; i
++) msi_free( old
[i
] );
2767 for (i
= 0; i
< new_count
; i
++) msi_free( new[i
] );
2773 static BYTE
*reg_get_value( HKEY hkey
, const WCHAR
*name
, DWORD
*type
, DWORD
*size
)
2776 if (RegQueryValueExW( hkey
, name
, NULL
, NULL
, NULL
, size
)) return NULL
;
2777 if (!(ret
= msi_alloc( *size
))) return NULL
;
2778 RegQueryValueExW( hkey
, name
, NULL
, type
, ret
, size
);
2782 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
2784 MSIPACKAGE
*package
= param
;
2785 BYTE
*new_value
, *old_value
= NULL
;
2786 HKEY root_key
, hkey
;
2787 DWORD type
, old_type
, new_size
, old_size
= 0;
2788 LPWSTR deformated
, uikey
;
2789 const WCHAR
*szRoot
, *component
, *name
, *key
, *str
;
2793 BOOL check_first
= FALSE
;
2796 msi_ui_progress( package
, 2, REG_PROGRESS_VALUE
, 0, 0 );
2798 component
= MSI_RecordGetString(row
, 6);
2799 comp
= msi_get_loaded_component(package
,component
);
2801 return ERROR_SUCCESS
;
2803 comp
->Action
= msi_get_component_action( package
, comp
);
2804 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
2806 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
2807 return ERROR_SUCCESS
;
2810 name
= MSI_RecordGetString(row
, 4);
2811 if( MSI_RecordIsNull(row
,5) && name
)
2813 /* null values can have special meanings */
2814 if (name
[0]=='-' && name
[1] == 0)
2815 return ERROR_SUCCESS
;
2816 if ((name
[0] == '+' || name
[0] == '*') && !name
[1])
2820 root
= MSI_RecordGetInteger(row
,2);
2821 key
= MSI_RecordGetString(row
, 3);
2823 szRoot
= get_root_key( package
, root
, &root_key
);
2825 return ERROR_SUCCESS
;
2827 deformat_string(package
, key
, &deformated
);
2828 uikey
= msi_alloc( (strlenW(deformated
) + strlenW(szRoot
) + 1) * sizeof(WCHAR
) );
2829 strcpyW(uikey
,szRoot
);
2830 strcatW(uikey
,deformated
);
2832 if (!(hkey
= open_key( comp
, root_key
, deformated
, TRUE
)))
2834 ERR("Could not create key %s\n", debugstr_w(deformated
));
2836 msi_free(deformated
);
2837 return ERROR_FUNCTION_FAILED
;
2839 msi_free( deformated
);
2840 str
= msi_record_get_string( row
, 5, NULL
);
2841 len
= deformat_string( package
, str
, &deformated
);
2842 new_value
= parse_value( package
, deformated
, len
, &type
, &new_size
);
2844 msi_free( deformated
);
2845 deformat_string(package
, name
, &deformated
);
2847 if (!is_special_entry( name
))
2849 old_value
= reg_get_value( hkey
, deformated
, &old_type
, &old_size
);
2850 if (type
== REG_MULTI_SZ
)
2853 if (old_value
&& old_type
!= REG_MULTI_SZ
)
2855 msi_free( old_value
);
2859 new = build_multi_string_value( old_value
, old_size
, new_value
, new_size
, &new_size
);
2860 msi_free( new_value
);
2865 TRACE("setting value %s of %s type %u\n", debugstr_w(deformated
), debugstr_w(uikey
), type
);
2866 RegSetValueExW( hkey
, deformated
, 0, type
, new_value
, new_size
);
2868 else if (!old_value
)
2870 if (deformated
|| new_size
)
2872 TRACE("setting value %s of %s type %u\n", debugstr_w(deformated
), debugstr_w(uikey
), type
);
2873 RegSetValueExW( hkey
, deformated
, 0, type
, new_value
, new_size
);
2876 else TRACE("not overwriting existing value %s of %s\n", debugstr_w(deformated
), debugstr_w(uikey
));
2880 uirow
= MSI_CreateRecord(3);
2881 MSI_RecordSetStringW(uirow
,2,deformated
);
2882 MSI_RecordSetStringW(uirow
,1,uikey
);
2883 if (type
== REG_SZ
|| type
== REG_EXPAND_SZ
)
2884 MSI_RecordSetStringW(uirow
, 3, (LPWSTR
)new_value
);
2885 msi_ui_actiondata( package
, szWriteRegistryValues
, uirow
);
2886 msiobj_release( &uirow
->hdr
);
2888 msi_free(new_value
);
2889 msi_free(old_value
);
2890 msi_free(deformated
);
2893 return ERROR_SUCCESS
;
2896 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2898 static const WCHAR query
[] = {
2899 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2900 '`','R','e','g','i','s','t','r','y','`',0};
2904 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
2905 if (rc
!= ERROR_SUCCESS
)
2906 return ERROR_SUCCESS
;
2908 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2909 msiobj_release(&view
->hdr
);
2913 static void delete_key( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
)
2920 access
|= get_registry_view( comp
);
2922 if (!(subkey
= strdupW( path
))) return;
2925 if ((p
= strrchrW( subkey
, '\\' ))) *p
= 0;
2926 hkey
= open_key( comp
, root
, subkey
, FALSE
);
2929 res
= RegDeleteKeyExW( hkey
, p
+ 1, access
, 0 );
2931 res
= RegDeleteKeyExW( root
, subkey
, access
, 0 );
2934 TRACE("failed to delete key %s (%d)\n", debugstr_w(subkey
), res
);
2937 if (p
&& p
[1]) RegCloseKey( hkey
);
2943 static void delete_value( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
, const WCHAR
*value
)
2947 DWORD num_subkeys
, num_values
;
2949 if ((hkey
= open_key( comp
, root
, path
, FALSE
)))
2951 if ((res
= RegDeleteValueW( hkey
, value
)))
2952 TRACE("failed to delete value %s (%d)\n", debugstr_w(value
), res
);
2954 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, &num_subkeys
, NULL
, NULL
, &num_values
,
2955 NULL
, NULL
, NULL
, NULL
);
2956 RegCloseKey( hkey
);
2957 if (!res
&& !num_subkeys
&& !num_values
)
2959 TRACE("removing empty key %s\n", debugstr_w(path
));
2960 delete_key( comp
, root
, path
);
2965 static void delete_tree( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
)
2970 if (!(hkey
= open_key( comp
, root
, path
, FALSE
))) return;
2971 res
= SHDeleteKeyW( hkey
, NULL
);
2972 if (res
) TRACE("failed to delete subtree of %s (%d)\n", debugstr_w(path
), res
);
2973 delete_key( comp
, root
, path
);
2974 RegCloseKey( hkey
);
2977 static UINT
ITERATE_RemoveRegistryValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
2979 MSIPACKAGE
*package
= param
;
2980 LPCWSTR component
, name
, key_str
, root_key_str
;
2981 LPWSTR deformated_key
, deformated_name
, ui_key_str
;
2984 BOOL delete_key
= FALSE
;
2989 msi_ui_progress( package
, 2, REG_PROGRESS_VALUE
, 0, 0 );
2991 component
= MSI_RecordGetString( row
, 6 );
2992 comp
= msi_get_loaded_component( package
, component
);
2994 return ERROR_SUCCESS
;
2996 comp
->Action
= msi_get_component_action( package
, comp
);
2997 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
2999 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
3000 return ERROR_SUCCESS
;
3003 name
= MSI_RecordGetString( row
, 4 );
3004 if (MSI_RecordIsNull( row
, 5 ) && name
)
3006 if (name
[0] == '+' && !name
[1])
3007 return ERROR_SUCCESS
;
3008 if ((name
[0] == '-' || name
[0] == '*') && !name
[1])
3015 root
= MSI_RecordGetInteger( row
, 2 );
3016 key_str
= MSI_RecordGetString( row
, 3 );
3018 root_key_str
= get_root_key( package
, root
, &hkey_root
);
3020 return ERROR_SUCCESS
;
3022 deformat_string( package
, key_str
, &deformated_key
);
3023 size
= strlenW( deformated_key
) + strlenW( root_key_str
) + 1;
3024 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
3025 strcpyW( ui_key_str
, root_key_str
);
3026 strcatW( ui_key_str
, deformated_key
);
3028 deformat_string( package
, name
, &deformated_name
);
3030 if (delete_key
) delete_tree( comp
, hkey_root
, deformated_key
);
3031 else delete_value( comp
, hkey_root
, deformated_key
, deformated_name
);
3032 msi_free( deformated_key
);
3034 uirow
= MSI_CreateRecord( 2 );
3035 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
3036 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
3037 msi_ui_actiondata( package
, szRemoveRegistryValues
, uirow
);
3038 msiobj_release( &uirow
->hdr
);
3040 msi_free( ui_key_str
);
3041 msi_free( deformated_name
);
3042 return ERROR_SUCCESS
;
3045 static UINT
ITERATE_RemoveRegistryValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
3047 MSIPACKAGE
*package
= param
;
3048 LPCWSTR component
, name
, key_str
, root_key_str
;
3049 LPWSTR deformated_key
, deformated_name
, ui_key_str
;
3052 BOOL delete_key
= FALSE
;
3057 component
= MSI_RecordGetString( row
, 5 );
3058 comp
= msi_get_loaded_component( package
, component
);
3060 return ERROR_SUCCESS
;
3062 comp
->Action
= msi_get_component_action( package
, comp
);
3063 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
3065 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
3066 return ERROR_SUCCESS
;
3069 if ((name
= MSI_RecordGetString( row
, 4 )))
3071 if (name
[0] == '-' && !name
[1])
3078 root
= MSI_RecordGetInteger( row
, 2 );
3079 key_str
= MSI_RecordGetString( row
, 3 );
3081 root_key_str
= get_root_key( package
, root
, &hkey_root
);
3083 return ERROR_SUCCESS
;
3085 deformat_string( package
, key_str
, &deformated_key
);
3086 size
= strlenW( deformated_key
) + strlenW( root_key_str
) + 1;
3087 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
3088 strcpyW( ui_key_str
, root_key_str
);
3089 strcatW( ui_key_str
, deformated_key
);
3091 deformat_string( package
, name
, &deformated_name
);
3093 if (delete_key
) delete_tree( comp
, hkey_root
, deformated_key
);
3094 else delete_value( comp
, hkey_root
, deformated_key
, deformated_name
);
3095 msi_free( deformated_key
);
3097 uirow
= MSI_CreateRecord( 2 );
3098 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
3099 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
3100 msi_ui_actiondata( package
, szRemoveRegistryValues
, uirow
);
3101 msiobj_release( &uirow
->hdr
);
3103 msi_free( ui_key_str
);
3104 msi_free( deformated_name
);
3105 return ERROR_SUCCESS
;
3108 static UINT
ACTION_RemoveRegistryValues( MSIPACKAGE
*package
)
3110 static const WCHAR registry_query
[] = {
3111 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3112 '`','R','e','g','i','s','t','r','y','`',0};
3113 static const WCHAR remove_registry_query
[] = {
3114 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3115 '`','R','e','m','o','v','e','R','e','g','i','s','t','r','y','`',0};
3119 rc
= MSI_DatabaseOpenViewW( package
->db
, registry_query
, &view
);
3120 if (rc
== ERROR_SUCCESS
)
3122 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnUninstall
, package
);
3123 msiobj_release( &view
->hdr
);
3124 if (rc
!= ERROR_SUCCESS
)
3127 rc
= MSI_DatabaseOpenViewW( package
->db
, remove_registry_query
, &view
);
3128 if (rc
== ERROR_SUCCESS
)
3130 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnInstall
, package
);
3131 msiobj_release( &view
->hdr
);
3132 if (rc
!= ERROR_SUCCESS
)
3135 return ERROR_SUCCESS
;
3138 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
3140 return ERROR_SUCCESS
;
3144 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
3146 static const WCHAR query
[]= {
3147 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3148 '`','R','e','g','i','s','t','r','y','`',0};
3150 DWORD total
= 0, count
= 0;
3152 MSIFEATURE
*feature
;
3156 TRACE("InstallValidate\n");
3158 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
3159 if (rc
== ERROR_SUCCESS
)
3161 rc
= MSI_IterateRecords( view
, &count
, NULL
, package
);
3162 msiobj_release( &view
->hdr
);
3163 if (rc
!= ERROR_SUCCESS
)
3165 total
+= count
* REG_PROGRESS_VALUE
;
3167 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
3168 total
+= COMPONENT_PROGRESS_VALUE
;
3170 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
3171 total
+= file
->FileSize
;
3173 msi_ui_progress( package
, 0, total
, 0, 0 );
3175 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3177 TRACE("Feature: %s Installed %d Request %d Action %d\n",
3178 debugstr_w(feature
->Feature
), feature
->Installed
,
3179 feature
->ActionRequest
, feature
->Action
);
3181 return ERROR_SUCCESS
;
3184 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
3186 MSIPACKAGE
* package
= param
;
3187 LPCWSTR cond
= NULL
;
3188 LPCWSTR message
= NULL
;
3191 static const WCHAR title
[]=
3192 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3194 cond
= MSI_RecordGetString(row
,1);
3196 r
= MSI_EvaluateConditionW(package
,cond
);
3197 if (r
== MSICONDITION_FALSE
)
3199 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
3202 message
= MSI_RecordGetString(row
,2);
3203 deformat_string(package
,message
,&deformated
);
3204 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
3205 msi_free(deformated
);
3208 return ERROR_INSTALL_FAILURE
;
3211 return ERROR_SUCCESS
;
3214 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
3216 static const WCHAR query
[] = {
3217 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3218 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
3222 TRACE("Checking launch conditions\n");
3224 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
3225 if (rc
!= ERROR_SUCCESS
)
3226 return ERROR_SUCCESS
;
3228 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
3229 msiobj_release(&view
->hdr
);
3233 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, MSICOMPONENT
*cmp
)
3237 return strdupW( msi_get_target_folder( package
, cmp
->Directory
) );
3239 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
3241 static const WCHAR query
[] = {
3242 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3243 '`','R','e','g','i','s','t','r','y','`',' ','W','H','E','R','E',' ',
3244 '`','R','e','g','i','s','t','r','y','`',' ','=',' ' ,'\'','%','s','\'',0};
3245 static const WCHAR fmt
[] = {'%','0','2','i',':','\\','%','s','\\',0};
3246 static const WCHAR fmt2
[]= {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3249 LPWSTR deformated
, buffer
, deformated_name
;
3252 row
= MSI_QueryGetRecord(package
->db
, query
, cmp
->KeyPath
);
3256 root
= MSI_RecordGetInteger(row
,2);
3257 key
= MSI_RecordGetString(row
, 3);
3258 name
= MSI_RecordGetString(row
, 4);
3259 deformat_string(package
, key
, &deformated
);
3260 deformat_string(package
, name
, &deformated_name
);
3262 len
= strlenW(deformated
) + 6;
3263 if (deformated_name
)
3264 len
+=strlenW(deformated_name
);
3266 buffer
= msi_alloc( len
*sizeof(WCHAR
));
3268 if (deformated_name
)
3269 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
3271 sprintfW(buffer
,fmt
,root
,deformated
);
3273 msi_free(deformated
);
3274 msi_free(deformated_name
);
3275 msiobj_release(&row
->hdr
);
3279 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
3281 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3286 MSIFILE
*file
= msi_get_loaded_file( package
, cmp
->KeyPath
);
3289 return strdupW( file
->TargetPath
);
3294 static HKEY
openSharedDLLsKey(void)
3297 static const WCHAR path
[] =
3298 {'S','o','f','t','w','a','r','e','\\',
3299 'M','i','c','r','o','s','o','f','t','\\',
3300 'W','i','n','d','o','w','s','\\',
3301 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3302 'S','h','a','r','e','d','D','L','L','s',0};
3304 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
3308 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
3313 DWORD sz
= sizeof(count
);
3316 hkey
= openSharedDLLsKey();
3317 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
3318 if (rc
!= ERROR_SUCCESS
)
3324 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
3328 hkey
= openSharedDLLsKey();
3330 msi_reg_set_val_dword( hkey
, path
, count
);
3332 RegDeleteValueW(hkey
,path
);
3337 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, MSICOMPONENT
*comp
)
3339 MSIFEATURE
*feature
;
3343 /* only refcount DLLs */
3344 if (comp
->KeyPath
== NULL
||
3346 comp
->Attributes
& msidbComponentAttributesRegistryKeyPath
||
3347 comp
->Attributes
& msidbComponentAttributesODBCDataSource
)
3351 count
= ACTION_GetSharedDLLsCount( comp
->FullKeypath
);
3352 write
= (count
> 0);
3354 if (comp
->Attributes
& msidbComponentAttributesSharedDllRefCount
)
3358 /* increment counts */
3359 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3363 if (msi_get_feature_action( package
, feature
) != INSTALLSTATE_LOCAL
)
3366 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3368 if ( cl
->component
== comp
)
3373 /* decrement counts */
3374 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3378 if (msi_get_feature_action( package
, feature
) != INSTALLSTATE_ABSENT
)
3381 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3383 if ( cl
->component
== comp
)
3388 /* ref count all the files in the component */
3393 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
3395 if (file
->Component
== comp
)
3396 ACTION_WriteSharedDLLsCount( file
->TargetPath
, count
);
3400 /* add a count for permanent */
3401 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
3404 comp
->RefCount
= count
;
3407 ACTION_WriteSharedDLLsCount( comp
->FullKeypath
, comp
->RefCount
);
3410 static WCHAR
*build_full_keypath( MSIPACKAGE
*package
, MSICOMPONENT
*comp
)
3414 const WCHAR prefixW
[] = {'<','\\',0};
3415 DWORD len
= strlenW( prefixW
) + strlenW( comp
->assembly
->display_name
);
3416 WCHAR
*keypath
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
3420 strcpyW( keypath
, prefixW
);
3421 strcatW( keypath
, comp
->assembly
->display_name
);
3425 return resolve_keypath( package
, comp
);
3428 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
3430 WCHAR squished_pc
[GUID_SIZE
], squished_cc
[GUID_SIZE
];
3437 squash_guid(package
->ProductCode
,squished_pc
);
3438 msi_set_sourcedir_props(package
, FALSE
);
3440 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
3443 INSTALLSTATE action
;
3445 msi_ui_progress( package
, 2, COMPONENT_PROGRESS_VALUE
, 0, 0 );
3446 if (!comp
->ComponentId
)
3449 squash_guid( comp
->ComponentId
, squished_cc
);
3450 msi_free( comp
->FullKeypath
);
3451 comp
->FullKeypath
= build_full_keypath( package
, comp
);
3453 ACTION_RefCountComponent( package
, comp
);
3455 if (package
->need_rollback
) action
= comp
->Installed
;
3456 else action
= comp
->ActionRequest
;
3458 TRACE("Component %s (%s) Keypath=%s RefCount=%u Clients=%u Action=%u\n",
3459 debugstr_w(comp
->Component
), debugstr_w(squished_cc
),
3460 debugstr_w(comp
->FullKeypath
), comp
->RefCount
, comp
->num_clients
, action
);
3462 if (action
== INSTALLSTATE_LOCAL
|| action
== INSTALLSTATE_SOURCE
)
3464 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3465 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, szLocalSid
, &hkey
, TRUE
);
3467 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, NULL
, &hkey
, TRUE
);
3469 if (rc
!= ERROR_SUCCESS
)
3472 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
3474 static const WCHAR szPermKey
[] =
3475 { '0','0','0','0','0','0','0','0','0','0','0','0',
3476 '0','0','0','0','0','0','0','0','0','0','0','0',
3477 '0','0','0','0','0','0','0','0',0 };
3479 msi_reg_set_val_str(hkey
, szPermKey
, comp
->FullKeypath
);
3481 if (action
== INSTALLSTATE_LOCAL
)
3482 msi_reg_set_val_str(hkey
, squished_pc
, comp
->FullKeypath
);
3488 WCHAR source
[MAX_PATH
];
3489 WCHAR base
[MAX_PATH
];
3492 static const WCHAR fmt
[] = {'%','0','2','d','\\',0};
3493 static const WCHAR query
[] = {
3494 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3495 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3496 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
3497 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
3498 '`','D','i','s','k','I','d','`',0};
3500 if (!comp
->KeyPath
|| !(file
= msi_get_loaded_file(package
, comp
->KeyPath
)))
3503 row
= MSI_QueryGetRecord(package
->db
, query
, file
->Sequence
);
3504 sprintfW(source
, fmt
, MSI_RecordGetInteger(row
, 1));
3505 ptr2
= strrchrW(source
, '\\') + 1;
3506 msiobj_release(&row
->hdr
);
3508 lstrcpyW(base
, package
->PackagePath
);
3509 ptr
= strrchrW(base
, '\\');
3512 sourcepath
= msi_resolve_file_source(package
, file
);
3513 ptr
= sourcepath
+ lstrlenW(base
);
3514 lstrcpyW(ptr2
, ptr
);
3515 msi_free(sourcepath
);
3517 msi_reg_set_val_str(hkey
, squished_pc
, source
);
3521 else if (action
== INSTALLSTATE_ABSENT
)
3523 if (comp
->num_clients
<= 0)
3525 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3526 rc
= MSIREG_DeleteUserDataComponentKey( comp
->ComponentId
, szLocalSid
);
3528 rc
= MSIREG_DeleteUserDataComponentKey( comp
->ComponentId
, NULL
);
3530 if (rc
!= ERROR_SUCCESS
) WARN( "failed to delete component key %u\n", rc
);
3536 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3537 rc
= MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, szLocalSid
, &hkey
, FALSE
);
3539 rc
= MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, NULL
, &hkey
, FALSE
);
3541 if (rc
!= ERROR_SUCCESS
)
3543 WARN( "failed to open component key %u\n", rc
);
3546 res
= RegDeleteValueW( hkey
, squished_pc
);
3548 if (res
) WARN( "failed to delete component value %d\n", res
);
3553 uirow
= MSI_CreateRecord(3);
3554 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
3555 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
3556 MSI_RecordSetStringW(uirow
,3,comp
->FullKeypath
);
3557 msi_ui_actiondata( package
, szProcessComponents
, uirow
);
3558 msiobj_release( &uirow
->hdr
);
3560 return ERROR_SUCCESS
;
3571 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
3572 LPWSTR lpszName
, LONG_PTR lParam
)
3575 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
3576 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
3580 if (!IS_INTRESOURCE(lpszName
))
3582 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
3586 sz
= strlenW(tl_struct
->source
)+4;
3587 sz
*= sizeof(WCHAR
);
3589 if ((INT_PTR
)lpszName
== 1)
3590 tl_struct
->path
= strdupW(tl_struct
->source
);
3593 tl_struct
->path
= msi_alloc(sz
);
3594 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
3597 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
3598 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
3601 msi_free(tl_struct
->path
);
3602 tl_struct
->path
= NULL
;
3607 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
3608 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
3610 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3614 msi_free(tl_struct
->path
);
3615 tl_struct
->path
= NULL
;
3617 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3618 ITypeLib_Release(tl_struct
->ptLib
);
3623 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
3625 MSIPACKAGE
* package
= param
;
3629 typelib_struct tl_struct
;
3634 component
= MSI_RecordGetString(row
,3);
3635 comp
= msi_get_loaded_component(package
,component
);
3637 return ERROR_SUCCESS
;
3639 comp
->Action
= msi_get_component_action( package
, comp
);
3640 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
3642 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
3643 return ERROR_SUCCESS
;
3646 if (!comp
->KeyPath
|| !(file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
3648 TRACE("component has no key path\n");
3649 return ERROR_SUCCESS
;
3651 msi_ui_actiondata( package
, szRegisterTypeLibraries
, row
);
3653 module
= LoadLibraryExW( file
->TargetPath
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
3657 guid
= MSI_RecordGetString(row
,1);
3658 CLSIDFromString( guid
, &tl_struct
.clsid
);
3659 tl_struct
.source
= strdupW( file
->TargetPath
);
3660 tl_struct
.path
= NULL
;
3662 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
3663 (LONG_PTR
)&tl_struct
);
3667 LPCWSTR helpid
, help_path
= NULL
;
3670 helpid
= MSI_RecordGetString(row
,6);
3672 if (helpid
) help_path
= msi_get_target_folder( package
, helpid
);
3673 res
= RegisterTypeLib( tl_struct
.ptLib
, tl_struct
.path
, (OLECHAR
*)help_path
);
3676 ERR("Failed to register type library %s\n", debugstr_w(tl_struct
.path
));
3678 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
3680 ITypeLib_Release(tl_struct
.ptLib
);
3681 msi_free(tl_struct
.path
);
3683 else ERR("Failed to load type library %s\n", debugstr_w(tl_struct
.source
));
3685 FreeLibrary(module
);
3686 msi_free(tl_struct
.source
);
3690 hr
= LoadTypeLibEx(file
->TargetPath
, REGKIND_REGISTER
, &tlib
);
3693 ERR("Failed to load type library: %08x\n", hr
);
3694 return ERROR_INSTALL_FAILURE
;
3697 ITypeLib_Release(tlib
);
3700 return ERROR_SUCCESS
;
3703 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
3705 static const WCHAR query
[] = {
3706 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3707 '`','T','y','p','e','L','i','b','`',0};
3711 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
3712 if (rc
!= ERROR_SUCCESS
)
3713 return ERROR_SUCCESS
;
3715 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
3716 msiobj_release(&view
->hdr
);
3720 static UINT
ITERATE_UnregisterTypeLibraries( MSIRECORD
*row
, LPVOID param
)
3722 MSIPACKAGE
*package
= param
;
3723 LPCWSTR component
, guid
;
3731 component
= MSI_RecordGetString( row
, 3 );
3732 comp
= msi_get_loaded_component( package
, component
);
3734 return ERROR_SUCCESS
;
3736 comp
->Action
= msi_get_component_action( package
, comp
);
3737 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
3739 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
3740 return ERROR_SUCCESS
;
3742 msi_ui_actiondata( package
, szUnregisterTypeLibraries
, row
);
3744 guid
= MSI_RecordGetString( row
, 1 );
3745 CLSIDFromString( guid
, &libid
);
3746 version
= MSI_RecordGetInteger( row
, 4 );
3747 language
= MSI_RecordGetInteger( row
, 2 );
3750 syskind
= SYS_WIN64
;
3752 syskind
= SYS_WIN32
;
3755 hr
= UnRegisterTypeLib( &libid
, (version
>> 8) & 0xffff, version
& 0xff, language
, syskind
);
3758 WARN("Failed to unregister typelib: %08x\n", hr
);
3761 return ERROR_SUCCESS
;
3764 static UINT
ACTION_UnregisterTypeLibraries( MSIPACKAGE
*package
)
3766 static const WCHAR query
[] = {
3767 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3768 '`','T','y','p','e','L','i','b','`',0};
3772 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
3773 if (rc
!= ERROR_SUCCESS
)
3774 return ERROR_SUCCESS
;
3776 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnregisterTypeLibraries
, package
);
3777 msiobj_release( &view
->hdr
);
3781 static WCHAR
*get_link_file( MSIPACKAGE
*package
, MSIRECORD
*row
)
3783 static const WCHAR szlnk
[] = {'.','l','n','k',0};
3784 LPCWSTR directory
, extension
, link_folder
;
3785 LPWSTR link_file
, filename
;
3787 directory
= MSI_RecordGetString( row
, 2 );
3788 link_folder
= msi_get_target_folder( package
, directory
);
3791 ERR("unable to resolve folder %s\n", debugstr_w(directory
));
3794 /* may be needed because of a bug somewhere else */
3795 msi_create_full_path( link_folder
);
3797 filename
= msi_dup_record_field( row
, 3 );
3798 msi_reduce_to_long_filename( filename
);
3800 extension
= strrchrW( filename
, '.' );
3801 if (!extension
|| strcmpiW( extension
, szlnk
))
3803 int len
= strlenW( filename
);
3804 filename
= msi_realloc( filename
, len
* sizeof(WCHAR
) + sizeof(szlnk
) );
3805 memcpy( filename
+ len
, szlnk
, sizeof(szlnk
) );
3807 link_file
= msi_build_directory_name( 2, link_folder
, filename
);
3808 msi_free( filename
);
3813 WCHAR
*msi_build_icon_path( MSIPACKAGE
*package
, const WCHAR
*icon_name
)
3815 static const WCHAR szMicrosoft
[] = {'M','i','c','r','o','s','o','f','t','\\',0};
3816 static const WCHAR szInstaller
[] = {'I','n','s','t','a','l','l','e','r','\\',0};
3817 WCHAR
*folder
, *dest
, *path
;
3819 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3820 folder
= msi_dup_property( package
->db
, szWindowsFolder
);
3823 WCHAR
*appdata
= msi_dup_property( package
->db
, szAppDataFolder
);
3824 folder
= msi_build_directory_name( 2, appdata
, szMicrosoft
);
3825 msi_free( appdata
);
3827 dest
= msi_build_directory_name( 3, folder
, szInstaller
, package
->ProductCode
);
3828 msi_create_full_path( dest
);
3829 path
= msi_build_directory_name( 2, dest
, icon_name
);
3835 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
3837 MSIPACKAGE
*package
= param
;
3838 LPWSTR link_file
, deformated
, path
;
3839 LPCWSTR component
, target
;
3841 IShellLinkW
*sl
= NULL
;
3842 IPersistFile
*pf
= NULL
;
3845 component
= MSI_RecordGetString(row
, 4);
3846 comp
= msi_get_loaded_component(package
, component
);
3848 return ERROR_SUCCESS
;
3850 comp
->Action
= msi_get_component_action( package
, comp
);
3851 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
3853 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
3854 return ERROR_SUCCESS
;
3856 msi_ui_actiondata( package
, szCreateShortcuts
, row
);
3858 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3859 &IID_IShellLinkW
, (LPVOID
*) &sl
);
3863 ERR("CLSID_ShellLink not available\n");
3867 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
3870 ERR("QueryInterface(IID_IPersistFile) failed\n");
3874 target
= MSI_RecordGetString(row
, 5);
3875 if (strchrW(target
, '['))
3877 deformat_string( package
, target
, &path
);
3878 TRACE("target path is %s\n", debugstr_w(path
));
3879 IShellLinkW_SetPath( sl
, path
);
3884 FIXME("poorly handled shortcut format, advertised shortcut\n");
3885 path
= resolve_keypath( package
, comp
);
3886 IShellLinkW_SetPath( sl
, path
);
3890 if (!MSI_RecordIsNull(row
,6))
3892 LPCWSTR arguments
= MSI_RecordGetString(row
, 6);
3893 deformat_string(package
, arguments
, &deformated
);
3894 IShellLinkW_SetArguments(sl
,deformated
);
3895 msi_free(deformated
);
3898 if (!MSI_RecordIsNull(row
,7))
3900 LPCWSTR description
= MSI_RecordGetString(row
, 7);
3901 IShellLinkW_SetDescription(sl
, description
);
3904 if (!MSI_RecordIsNull(row
,8))
3905 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
3907 if (!MSI_RecordIsNull(row
,9))
3910 LPCWSTR icon
= MSI_RecordGetString(row
, 9);
3912 path
= msi_build_icon_path(package
, icon
);
3913 index
= MSI_RecordGetInteger(row
,10);
3915 /* no value means 0 */
3916 if (index
== MSI_NULL_INTEGER
)
3919 IShellLinkW_SetIconLocation(sl
, path
, index
);
3923 if (!MSI_RecordIsNull(row
,11))
3924 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
3926 if (!MSI_RecordIsNull(row
,12))
3928 LPCWSTR full_path
, wkdir
= MSI_RecordGetString( row
, 12 );
3929 full_path
= msi_get_target_folder( package
, wkdir
);
3930 if (full_path
) IShellLinkW_SetWorkingDirectory( sl
, full_path
);
3932 link_file
= get_link_file(package
, row
);
3934 TRACE("Writing shortcut to %s\n", debugstr_w(link_file
));
3935 IPersistFile_Save(pf
, link_file
, FALSE
);
3936 msi_free(link_file
);
3940 IPersistFile_Release( pf
);
3942 IShellLinkW_Release( sl
);
3944 return ERROR_SUCCESS
;
3947 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
3949 static const WCHAR query
[] = {
3950 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3951 '`','S','h','o','r','t','c','u','t','`',0};
3956 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
3957 if (rc
!= ERROR_SUCCESS
)
3958 return ERROR_SUCCESS
;
3960 res
= CoInitialize( NULL
);
3962 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
3963 msiobj_release(&view
->hdr
);
3965 if (SUCCEEDED(res
)) CoUninitialize();
3969 static UINT
ITERATE_RemoveShortcuts( MSIRECORD
*row
, LPVOID param
)
3971 MSIPACKAGE
*package
= param
;
3976 component
= MSI_RecordGetString( row
, 4 );
3977 comp
= msi_get_loaded_component( package
, component
);
3979 return ERROR_SUCCESS
;
3981 comp
->Action
= msi_get_component_action( package
, comp
);
3982 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
3984 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
3985 return ERROR_SUCCESS
;
3987 msi_ui_actiondata( package
, szRemoveShortcuts
, row
);
3989 link_file
= get_link_file( package
, row
);
3991 TRACE("Removing shortcut file %s\n", debugstr_w( link_file
));
3992 if (!DeleteFileW( link_file
))
3994 WARN("Failed to remove shortcut file %u\n", GetLastError());
3996 msi_free( link_file
);
3998 return ERROR_SUCCESS
;
4001 static UINT
ACTION_RemoveShortcuts( MSIPACKAGE
*package
)
4003 static const WCHAR query
[] = {
4004 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4005 '`','S','h','o','r','t','c','u','t','`',0};
4009 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4010 if (rc
!= ERROR_SUCCESS
)
4011 return ERROR_SUCCESS
;
4013 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveShortcuts
, package
);
4014 msiobj_release( &view
->hdr
);
4018 static UINT
ITERATE_PublishIcon(MSIRECORD
*row
, LPVOID param
)
4020 MSIPACKAGE
* package
= param
;
4028 FileName
= MSI_RecordGetString(row
,1);
4031 ERR("Unable to get FileName\n");
4032 return ERROR_SUCCESS
;
4035 FilePath
= msi_build_icon_path(package
, FileName
);
4037 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
4039 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
4040 FILE_ATTRIBUTE_NORMAL
, NULL
);
4042 if (the_file
== INVALID_HANDLE_VALUE
)
4044 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
4046 return ERROR_SUCCESS
;
4053 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
4054 if (rc
!= ERROR_SUCCESS
)
4056 ERR("Failed to get stream\n");
4057 CloseHandle(the_file
);
4058 DeleteFileW(FilePath
);
4061 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
4062 } while (sz
== 1024);
4065 CloseHandle(the_file
);
4067 return ERROR_SUCCESS
;
4070 static UINT
msi_publish_icons(MSIPACKAGE
*package
)
4072 static const WCHAR query
[]= {
4073 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4074 '`','I','c','o','n','`',0};
4078 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
4079 if (r
== ERROR_SUCCESS
)
4081 r
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishIcon
, package
);
4082 msiobj_release(&view
->hdr
);
4083 if (r
!= ERROR_SUCCESS
)
4086 return ERROR_SUCCESS
;
4089 static UINT
msi_publish_sourcelist(MSIPACKAGE
*package
, HKEY hkey
)
4095 MSISOURCELISTINFO
*info
;
4097 r
= RegCreateKeyW(hkey
, szSourceList
, &source
);
4098 if (r
!= ERROR_SUCCESS
)
4101 RegCloseKey(source
);
4103 buffer
= strrchrW(package
->PackagePath
, '\\') + 1;
4104 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4105 package
->Context
, MSICODE_PRODUCT
,
4106 INSTALLPROPERTY_PACKAGENAMEW
, buffer
);
4107 if (r
!= ERROR_SUCCESS
)
4110 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4111 package
->Context
, MSICODE_PRODUCT
,
4112 INSTALLPROPERTY_MEDIAPACKAGEPATHW
, szEmpty
);
4113 if (r
!= ERROR_SUCCESS
)
4116 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4117 package
->Context
, MSICODE_PRODUCT
,
4118 INSTALLPROPERTY_DISKPROMPTW
, szEmpty
);
4119 if (r
!= ERROR_SUCCESS
)
4122 LIST_FOR_EACH_ENTRY(info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
4124 if (!strcmpW( info
->property
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
4125 msi_set_last_used_source(package
->ProductCode
, NULL
, info
->context
,
4126 info
->options
, info
->value
);
4128 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4129 info
->context
, info
->options
,
4130 info
->property
, info
->value
);
4133 LIST_FOR_EACH_ENTRY(disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
4135 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
4136 disk
->context
, disk
->options
,
4137 disk
->disk_id
, disk
->volume_label
, disk
->disk_prompt
);
4140 return ERROR_SUCCESS
;
4143 static UINT
msi_publish_product_properties(MSIPACKAGE
*package
, HKEY hkey
)
4145 MSIHANDLE hdb
, suminfo
;
4146 WCHAR guids
[MAX_PATH
];
4147 WCHAR packcode
[SQUISH_GUID_SIZE
];
4154 static const WCHAR szARPProductIcon
[] =
4155 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
4156 static const WCHAR szAssignment
[] =
4157 {'A','s','s','i','g','n','m','e','n','t',0};
4158 static const WCHAR szAdvertiseFlags
[] =
4159 {'A','d','v','e','r','t','i','s','e','F','l','a','g','s',0};
4160 static const WCHAR szClients
[] =
4161 {'C','l','i','e','n','t','s',0};
4162 static const WCHAR szColon
[] = {':',0};
4164 buffer
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
4165 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTNAMEW
, buffer
);
4168 langid
= msi_get_property_int(package
->db
, szProductLanguage
, 0);
4169 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
4172 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
, 0);
4174 buffer
= msi_dup_property(package
->db
, szARPProductIcon
);
4177 LPWSTR path
= msi_build_icon_path(package
, buffer
);
4178 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTICONW
, path
);
4183 buffer
= msi_dup_property(package
->db
, szProductVersion
);
4186 DWORD verdword
= msi_version_str_to_dword(buffer
);
4187 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
4191 msi_reg_set_val_dword(hkey
, szAssignment
, 0);
4192 msi_reg_set_val_dword(hkey
, szAdvertiseFlags
, 0x184);
4193 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_INSTANCETYPEW
, 0);
4194 msi_reg_set_val_str(hkey
, szClients
, szColon
);
4196 hdb
= alloc_msihandle(&package
->db
->hdr
);
4198 return ERROR_NOT_ENOUGH_MEMORY
;
4200 r
= MsiGetSummaryInformationW(hdb
, NULL
, 0, &suminfo
);
4201 MsiCloseHandle(hdb
);
4202 if (r
!= ERROR_SUCCESS
)
4206 r
= MsiSummaryInfoGetPropertyW(suminfo
, PID_REVNUMBER
, NULL
, NULL
,
4207 NULL
, guids
, &size
);
4208 if (r
!= ERROR_SUCCESS
)
4211 ptr
= strchrW(guids
, ';');
4213 squash_guid(guids
, packcode
);
4214 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PACKAGECODEW
, packcode
);
4217 MsiCloseHandle(suminfo
);
4218 return ERROR_SUCCESS
;
4221 static UINT
msi_publish_upgrade_code(MSIPACKAGE
*package
)
4226 WCHAR squashed_pc
[SQUISH_GUID_SIZE
];
4228 upgrade
= msi_dup_property(package
->db
, szUpgradeCode
);
4230 return ERROR_SUCCESS
;
4232 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
4233 r
= MSIREG_OpenClassesUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
4235 r
= MSIREG_OpenUserUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
4237 if (r
!= ERROR_SUCCESS
)
4239 WARN("failed to open upgrade code key\n");
4241 return ERROR_SUCCESS
;
4243 squash_guid(package
->ProductCode
, squashed_pc
);
4244 msi_reg_set_val_str(hkey
, squashed_pc
, NULL
);
4247 return ERROR_SUCCESS
;
4250 static BOOL
msi_check_publish(MSIPACKAGE
*package
)
4252 MSIFEATURE
*feature
;
4254 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4256 feature
->Action
= msi_get_feature_action( package
, feature
);
4257 if (feature
->Action
== INSTALLSTATE_LOCAL
)
4264 static BOOL
msi_check_unpublish(MSIPACKAGE
*package
)
4266 MSIFEATURE
*feature
;
4268 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4270 feature
->Action
= msi_get_feature_action( package
, feature
);
4271 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
4278 static UINT
msi_publish_patches( MSIPACKAGE
*package
)
4280 static const WCHAR szAllPatches
[] = {'A','l','l','P','a','t','c','h','e','s',0};
4281 WCHAR patch_squashed
[GUID_SIZE
];
4282 HKEY patches_key
= NULL
, product_patches_key
= NULL
, product_key
;
4284 MSIPATCHINFO
*patch
;
4286 WCHAR
*p
, *all_patches
= NULL
;
4289 r
= MSIREG_OpenProductKey( package
->ProductCode
, NULL
, package
->Context
, &product_key
, TRUE
);
4290 if (r
!= ERROR_SUCCESS
)
4291 return ERROR_FUNCTION_FAILED
;
4293 res
= RegCreateKeyExW( product_key
, szPatches
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &patches_key
, NULL
);
4294 if (res
!= ERROR_SUCCESS
)
4296 r
= ERROR_FUNCTION_FAILED
;
4300 r
= MSIREG_OpenUserDataProductPatchesKey( package
->ProductCode
, package
->Context
, &product_patches_key
, TRUE
);
4301 if (r
!= ERROR_SUCCESS
)
4304 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
4306 squash_guid( patch
->patchcode
, patch_squashed
);
4307 len
+= strlenW( patch_squashed
) + 1;
4310 p
= all_patches
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
4314 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
4318 squash_guid( patch
->patchcode
, p
);
4319 p
+= strlenW( p
) + 1;
4321 res
= RegSetValueExW( patches_key
, patch_squashed
, 0, REG_SZ
,
4322 (const BYTE
*)patch
->transforms
,
4323 (strlenW(patch
->transforms
) + 1) * sizeof(WCHAR
) );
4324 if (res
!= ERROR_SUCCESS
)
4327 r
= MSIREG_OpenUserDataPatchKey( patch
->patchcode
, package
->Context
, &patch_key
, TRUE
);
4328 if (r
!= ERROR_SUCCESS
)
4331 res
= RegSetValueExW( patch_key
, szLocalPackage
, 0, REG_SZ
, (const BYTE
*)patch
->localfile
,
4332 (strlenW( patch
->localfile
) + 1) * sizeof(WCHAR
) );
4333 RegCloseKey( patch_key
);
4334 if (res
!= ERROR_SUCCESS
)
4337 if (patch
->filename
&& !CopyFileW( patch
->filename
, patch
->localfile
, FALSE
))
4339 res
= GetLastError();
4340 ERR("Unable to copy patch package %d\n", res
);
4343 res
= RegCreateKeyExW( product_patches_key
, patch_squashed
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &patch_key
, NULL
);
4344 if (res
!= ERROR_SUCCESS
)
4347 res
= RegSetValueExW( patch_key
, szState
, 0, REG_DWORD
, (const BYTE
*)&patch
->state
, sizeof(patch
->state
) );
4348 RegCloseKey( patch_key
);
4349 if (res
!= ERROR_SUCCESS
)
4353 all_patches
[len
] = 0;
4354 res
= RegSetValueExW( patches_key
, szPatches
, 0, REG_MULTI_SZ
,
4355 (const BYTE
*)all_patches
, (len
+ 1) * sizeof(WCHAR
) );
4356 if (res
!= ERROR_SUCCESS
)
4359 res
= RegSetValueExW( product_patches_key
, szAllPatches
, 0, REG_MULTI_SZ
,
4360 (const BYTE
*)all_patches
, (len
+ 1) * sizeof(WCHAR
) );
4361 if (res
!= ERROR_SUCCESS
)
4362 r
= ERROR_FUNCTION_FAILED
;
4365 RegCloseKey( product_patches_key
);
4366 RegCloseKey( patches_key
);
4367 RegCloseKey( product_key
);
4368 msi_free( all_patches
);
4372 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
4375 HKEY hukey
= NULL
, hudkey
= NULL
;
4378 if (!list_empty(&package
->patches
))
4380 rc
= msi_publish_patches(package
);
4381 if (rc
!= ERROR_SUCCESS
)
4385 /* FIXME: also need to publish if the product is in advertise mode */
4386 if (!msi_check_publish(package
))
4387 return ERROR_SUCCESS
;
4389 rc
= MSIREG_OpenProductKey(package
->ProductCode
, NULL
, package
->Context
,
4391 if (rc
!= ERROR_SUCCESS
)
4394 rc
= MSIREG_OpenUserDataProductKey(package
->ProductCode
, package
->Context
,
4395 NULL
, &hudkey
, TRUE
);
4396 if (rc
!= ERROR_SUCCESS
)
4399 rc
= msi_publish_upgrade_code(package
);
4400 if (rc
!= ERROR_SUCCESS
)
4403 rc
= msi_publish_product_properties(package
, hukey
);
4404 if (rc
!= ERROR_SUCCESS
)
4407 rc
= msi_publish_sourcelist(package
, hukey
);
4408 if (rc
!= ERROR_SUCCESS
)
4411 rc
= msi_publish_icons(package
);
4414 uirow
= MSI_CreateRecord( 1 );
4415 MSI_RecordSetStringW( uirow
, 1, package
->ProductCode
);
4416 msi_ui_actiondata( package
, szPublishProduct
, uirow
);
4417 msiobj_release( &uirow
->hdr
);
4420 RegCloseKey(hudkey
);
4424 static WCHAR
*get_ini_file_name( MSIPACKAGE
*package
, MSIRECORD
*row
)
4426 WCHAR
*filename
, *ptr
, *folder
, *ret
;
4427 const WCHAR
*dirprop
;
4429 filename
= msi_dup_record_field( row
, 2 );
4430 if (filename
&& (ptr
= strchrW( filename
, '|' )))
4435 dirprop
= MSI_RecordGetString( row
, 3 );
4438 folder
= strdupW( msi_get_target_folder( package
, dirprop
) );
4439 if (!folder
) folder
= msi_dup_property( package
->db
, dirprop
);
4442 folder
= msi_dup_property( package
->db
, szWindowsFolder
);
4446 ERR("Unable to resolve folder %s\n", debugstr_w(dirprop
));
4447 msi_free( filename
);
4451 ret
= msi_build_directory_name( 2, folder
, ptr
);
4453 msi_free( filename
);
4458 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
4460 MSIPACKAGE
*package
= param
;
4461 LPCWSTR component
, section
, key
, value
, identifier
;
4462 LPWSTR deformated_section
, deformated_key
, deformated_value
, fullname
;
4467 component
= MSI_RecordGetString(row
, 8);
4468 comp
= msi_get_loaded_component(package
,component
);
4470 return ERROR_SUCCESS
;
4472 comp
->Action
= msi_get_component_action( package
, comp
);
4473 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
4475 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
4476 return ERROR_SUCCESS
;
4479 identifier
= MSI_RecordGetString(row
,1);
4480 section
= MSI_RecordGetString(row
,4);
4481 key
= MSI_RecordGetString(row
,5);
4482 value
= MSI_RecordGetString(row
,6);
4483 action
= MSI_RecordGetInteger(row
,7);
4485 deformat_string(package
,section
,&deformated_section
);
4486 deformat_string(package
,key
,&deformated_key
);
4487 deformat_string(package
,value
,&deformated_value
);
4489 fullname
= get_ini_file_name(package
, row
);
4493 TRACE("Adding value %s to section %s in %s\n",
4494 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
4495 debugstr_w(fullname
));
4496 WritePrivateProfileStringW(deformated_section
, deformated_key
,
4497 deformated_value
, fullname
);
4499 else if (action
== 1)
4502 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
4503 returned
, 10, fullname
);
4504 if (returned
[0] == 0)
4506 TRACE("Adding value %s to section %s in %s\n",
4507 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
4508 debugstr_w(fullname
));
4510 WritePrivateProfileStringW(deformated_section
, deformated_key
,
4511 deformated_value
, fullname
);
4514 else if (action
== 3)
4515 FIXME("Append to existing section not yet implemented\n");
4517 uirow
= MSI_CreateRecord(4);
4518 MSI_RecordSetStringW(uirow
,1,identifier
);
4519 MSI_RecordSetStringW(uirow
,2,deformated_section
);
4520 MSI_RecordSetStringW(uirow
,3,deformated_key
);
4521 MSI_RecordSetStringW(uirow
,4,deformated_value
);
4522 msi_ui_actiondata( package
, szWriteIniValues
, uirow
);
4523 msiobj_release( &uirow
->hdr
);
4526 msi_free(deformated_key
);
4527 msi_free(deformated_value
);
4528 msi_free(deformated_section
);
4529 return ERROR_SUCCESS
;
4532 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
4534 static const WCHAR query
[] = {
4535 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4536 '`','I','n','i','F','i','l','e','`',0};
4540 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
4541 if (rc
!= ERROR_SUCCESS
)
4542 return ERROR_SUCCESS
;
4544 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
4545 msiobj_release(&view
->hdr
);
4549 static UINT
ITERATE_RemoveIniValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
4551 MSIPACKAGE
*package
= param
;
4552 LPCWSTR component
, section
, key
, value
, identifier
;
4553 LPWSTR deformated_section
, deformated_key
, deformated_value
, filename
;
4558 component
= MSI_RecordGetString( row
, 8 );
4559 comp
= msi_get_loaded_component( package
, component
);
4561 return ERROR_SUCCESS
;
4563 comp
->Action
= msi_get_component_action( package
, comp
);
4564 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
4566 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
4567 return ERROR_SUCCESS
;
4570 identifier
= MSI_RecordGetString( row
, 1 );
4571 section
= MSI_RecordGetString( row
, 4 );
4572 key
= MSI_RecordGetString( row
, 5 );
4573 value
= MSI_RecordGetString( row
, 6 );
4574 action
= MSI_RecordGetInteger( row
, 7 );
4576 deformat_string( package
, section
, &deformated_section
);
4577 deformat_string( package
, key
, &deformated_key
);
4578 deformat_string( package
, value
, &deformated_value
);
4580 if (action
== msidbIniFileActionAddLine
|| action
== msidbIniFileActionCreateLine
)
4582 filename
= get_ini_file_name( package
, row
);
4584 TRACE("Removing key %s from section %s in %s\n",
4585 debugstr_w(deformated_key
), debugstr_w(deformated_section
), debugstr_w(filename
));
4587 if (!WritePrivateProfileStringW( deformated_section
, deformated_key
, NULL
, filename
))
4589 WARN("Unable to remove key %u\n", GetLastError());
4591 msi_free( filename
);
4594 FIXME("Unsupported action %d\n", action
);
4597 uirow
= MSI_CreateRecord( 4 );
4598 MSI_RecordSetStringW( uirow
, 1, identifier
);
4599 MSI_RecordSetStringW( uirow
, 2, deformated_section
);
4600 MSI_RecordSetStringW( uirow
, 3, deformated_key
);
4601 MSI_RecordSetStringW( uirow
, 4, deformated_value
);
4602 msi_ui_actiondata( package
, szRemoveIniValues
, uirow
);
4603 msiobj_release( &uirow
->hdr
);
4605 msi_free( deformated_key
);
4606 msi_free( deformated_value
);
4607 msi_free( deformated_section
);
4608 return ERROR_SUCCESS
;
4611 static UINT
ITERATE_RemoveIniValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
4613 MSIPACKAGE
*package
= param
;
4614 LPCWSTR component
, section
, key
, value
, identifier
;
4615 LPWSTR deformated_section
, deformated_key
, deformated_value
, filename
;
4620 component
= MSI_RecordGetString( row
, 8 );
4621 comp
= msi_get_loaded_component( package
, component
);
4623 return ERROR_SUCCESS
;
4625 comp
->Action
= msi_get_component_action( package
, comp
);
4626 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
4628 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
4629 return ERROR_SUCCESS
;
4632 identifier
= MSI_RecordGetString( row
, 1 );
4633 section
= MSI_RecordGetString( row
, 4 );
4634 key
= MSI_RecordGetString( row
, 5 );
4635 value
= MSI_RecordGetString( row
, 6 );
4636 action
= MSI_RecordGetInteger( row
, 7 );
4638 deformat_string( package
, section
, &deformated_section
);
4639 deformat_string( package
, key
, &deformated_key
);
4640 deformat_string( package
, value
, &deformated_value
);
4642 if (action
== msidbIniFileActionRemoveLine
)
4644 filename
= get_ini_file_name( package
, row
);
4646 TRACE("Removing key %s from section %s in %s\n",
4647 debugstr_w(deformated_key
), debugstr_w(deformated_section
), debugstr_w(filename
));
4649 if (!WritePrivateProfileStringW( deformated_section
, deformated_key
, NULL
, filename
))
4651 WARN("Unable to remove key %u\n", GetLastError());
4653 msi_free( filename
);
4656 FIXME("Unsupported action %d\n", action
);
4658 uirow
= MSI_CreateRecord( 4 );
4659 MSI_RecordSetStringW( uirow
, 1, identifier
);
4660 MSI_RecordSetStringW( uirow
, 2, deformated_section
);
4661 MSI_RecordSetStringW( uirow
, 3, deformated_key
);
4662 MSI_RecordSetStringW( uirow
, 4, deformated_value
);
4663 msi_ui_actiondata( package
, szRemoveIniValues
, uirow
);
4664 msiobj_release( &uirow
->hdr
);
4666 msi_free( deformated_key
);
4667 msi_free( deformated_value
);
4668 msi_free( deformated_section
);
4669 return ERROR_SUCCESS
;
4672 static UINT
ACTION_RemoveIniValues( MSIPACKAGE
*package
)
4674 static const WCHAR query
[] = {
4675 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4676 '`','I','n','i','F','i','l','e','`',0};
4677 static const WCHAR remove_query
[] = {
4678 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4679 '`','R','e','m','o','v','e','I','n','i','F','i','l','e','`',0};
4683 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4684 if (rc
== ERROR_SUCCESS
)
4686 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveIniValuesOnUninstall
, package
);
4687 msiobj_release( &view
->hdr
);
4688 if (rc
!= ERROR_SUCCESS
)
4691 rc
= MSI_DatabaseOpenViewW( package
->db
, remove_query
, &view
);
4692 if (rc
== ERROR_SUCCESS
)
4694 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveIniValuesOnInstall
, package
);
4695 msiobj_release( &view
->hdr
);
4696 if (rc
!= ERROR_SUCCESS
)
4699 return ERROR_SUCCESS
;
4702 static void register_dll( const WCHAR
*dll
, BOOL unregister
)
4704 static const WCHAR regW
[] =
4705 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"','%','s','\"',0};
4706 static const WCHAR unregW
[] =
4707 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','u',' ','\"','%','s','\"',0};
4708 PROCESS_INFORMATION pi
;
4712 if (!(cmd
= msi_alloc( strlenW(dll
) * sizeof(WCHAR
) + sizeof(unregW
) ))) return;
4714 if (unregister
) sprintfW( cmd
, unregW
, dll
);
4715 else sprintfW( cmd
, regW
, dll
);
4717 memset( &si
, 0, sizeof(STARTUPINFOW
) );
4718 if (CreateProcessW( NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
4720 CloseHandle( pi
.hThread
);
4721 msi_dialog_check_messages( pi
.hProcess
);
4722 CloseHandle( pi
.hProcess
);
4727 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
4729 MSIPACKAGE
*package
= param
;
4734 filename
= MSI_RecordGetString( row
, 1 );
4735 file
= msi_get_loaded_file( package
, filename
);
4738 WARN("unable to find file %s\n", debugstr_w(filename
));
4739 return ERROR_SUCCESS
;
4741 file
->Component
->Action
= msi_get_component_action( package
, file
->Component
);
4742 if (file
->Component
->Action
!= INSTALLSTATE_LOCAL
)
4744 TRACE("component not scheduled for installation %s\n", debugstr_w(file
->Component
->Component
));
4745 return ERROR_SUCCESS
;
4748 TRACE("Registering %s\n", debugstr_w( file
->TargetPath
));
4749 register_dll( file
->TargetPath
, FALSE
);
4751 uirow
= MSI_CreateRecord( 2 );
4752 MSI_RecordSetStringW( uirow
, 1, file
->File
);
4753 MSI_RecordSetStringW( uirow
, 2, file
->Component
->Directory
);
4754 msi_ui_actiondata( package
, szSelfRegModules
, uirow
);
4755 msiobj_release( &uirow
->hdr
);
4757 return ERROR_SUCCESS
;
4760 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
4762 static const WCHAR query
[] = {
4763 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4764 '`','S','e','l','f','R','e','g','`',0};
4768 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
4769 if (rc
!= ERROR_SUCCESS
)
4770 return ERROR_SUCCESS
;
4772 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
4773 msiobj_release(&view
->hdr
);
4777 static UINT
ITERATE_SelfUnregModules( MSIRECORD
*row
, LPVOID param
)
4779 MSIPACKAGE
*package
= param
;
4784 filename
= MSI_RecordGetString( row
, 1 );
4785 file
= msi_get_loaded_file( package
, filename
);
4788 WARN("unable to find file %s\n", debugstr_w(filename
));
4789 return ERROR_SUCCESS
;
4791 file
->Component
->Action
= msi_get_component_action( package
, file
->Component
);
4792 if (file
->Component
->Action
!= INSTALLSTATE_ABSENT
)
4794 TRACE("component not scheduled for removal %s\n", debugstr_w(file
->Component
->Component
));
4795 return ERROR_SUCCESS
;
4798 TRACE("Unregistering %s\n", debugstr_w( file
->TargetPath
));
4799 register_dll( file
->TargetPath
, TRUE
);
4801 uirow
= MSI_CreateRecord( 2 );
4802 MSI_RecordSetStringW( uirow
, 1, file
->File
);
4803 MSI_RecordSetStringW( uirow
, 2, file
->Component
->Directory
);
4804 msi_ui_actiondata( package
, szSelfUnregModules
, uirow
);
4805 msiobj_release( &uirow
->hdr
);
4807 return ERROR_SUCCESS
;
4810 static UINT
ACTION_SelfUnregModules( MSIPACKAGE
*package
)
4812 static const WCHAR query
[] = {
4813 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4814 '`','S','e','l','f','R','e','g','`',0};
4818 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4819 if (rc
!= ERROR_SUCCESS
)
4820 return ERROR_SUCCESS
;
4822 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_SelfUnregModules
, package
);
4823 msiobj_release( &view
->hdr
);
4827 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
4829 MSIFEATURE
*feature
;
4831 HKEY hkey
= NULL
, userdata
= NULL
;
4833 if (!msi_check_publish(package
))
4834 return ERROR_SUCCESS
;
4836 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4838 if (rc
!= ERROR_SUCCESS
)
4841 rc
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4843 if (rc
!= ERROR_SUCCESS
)
4846 /* here the guids are base 85 encoded */
4847 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
4853 BOOL absent
= FALSE
;
4856 if (feature
->Level
<= 0) continue;
4858 if (feature
->Action
!= INSTALLSTATE_LOCAL
&&
4859 feature
->Action
!= INSTALLSTATE_SOURCE
&&
4860 feature
->Action
!= INSTALLSTATE_ADVERTISED
) absent
= TRUE
;
4863 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4867 if (feature
->Feature_Parent
)
4868 size
+= strlenW( feature
->Feature_Parent
)+2;
4870 data
= msi_alloc(size
* sizeof(WCHAR
));
4873 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4875 MSICOMPONENT
* component
= cl
->component
;
4879 if (component
->ComponentId
)
4881 TRACE("From %s\n",debugstr_w(component
->ComponentId
));
4882 CLSIDFromString(component
->ComponentId
, &clsid
);
4883 encode_base85_guid(&clsid
,buf
);
4884 TRACE("to %s\n",debugstr_w(buf
));
4889 if (feature
->Feature_Parent
)
4891 static const WCHAR sep
[] = {'\2',0};
4893 strcatW(data
,feature
->Feature_Parent
);
4896 msi_reg_set_val_str( userdata
, feature
->Feature
, data
);
4900 if (feature
->Feature_Parent
)
4901 size
= strlenW(feature
->Feature_Parent
)*sizeof(WCHAR
);
4904 size
+= sizeof(WCHAR
);
4905 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
4906 (const BYTE
*)(feature
->Feature_Parent
? feature
->Feature_Parent
: szEmpty
),size
);
4910 size
+= 2*sizeof(WCHAR
);
4911 data
= msi_alloc(size
);
4914 if (feature
->Feature_Parent
)
4915 strcpyW( &data
[1], feature
->Feature_Parent
);
4916 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
4922 uirow
= MSI_CreateRecord( 1 );
4923 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
4924 msi_ui_actiondata( package
, szPublishFeatures
, uirow
);
4925 msiobj_release( &uirow
->hdr
);
4926 /* FIXME: call msi_ui_progress? */
4931 RegCloseKey(userdata
);
4935 static UINT
msi_unpublish_feature(MSIPACKAGE
*package
, MSIFEATURE
*feature
)
4941 TRACE("unpublishing feature %s\n", debugstr_w(feature
->Feature
));
4943 r
= MSIREG_OpenFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4945 if (r
== ERROR_SUCCESS
)
4947 RegDeleteValueW(hkey
, feature
->Feature
);
4951 r
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4953 if (r
== ERROR_SUCCESS
)
4955 RegDeleteValueW(hkey
, feature
->Feature
);
4959 uirow
= MSI_CreateRecord( 1 );
4960 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
4961 msi_ui_actiondata( package
, szUnpublishFeatures
, uirow
);
4962 msiobj_release( &uirow
->hdr
);
4964 return ERROR_SUCCESS
;
4967 static UINT
ACTION_UnpublishFeatures(MSIPACKAGE
*package
)
4969 MSIFEATURE
*feature
;
4971 if (!msi_check_unpublish(package
))
4972 return ERROR_SUCCESS
;
4974 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4976 msi_unpublish_feature(package
, feature
);
4979 return ERROR_SUCCESS
;
4982 static UINT
msi_publish_install_properties(MSIPACKAGE
*package
, HKEY hkey
)
4986 WCHAR date
[9], *val
, *buffer
;
4987 const WCHAR
*prop
, *key
;
4989 static const WCHAR date_fmt
[] = {'%','i','%','0','2','i','%','0','2','i',0};
4990 static const WCHAR modpath_fmt
[] =
4991 {'M','s','i','E','x','e','c','.','e','x','e',' ',
4992 '/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
4993 static const WCHAR szModifyPath
[] =
4994 {'M','o','d','i','f','y','P','a','t','h',0};
4995 static const WCHAR szUninstallString
[] =
4996 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
4997 static const WCHAR szEstimatedSize
[] =
4998 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
4999 static const WCHAR szDisplayVersion
[] =
5000 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
5001 static const WCHAR szInstallSource
[] =
5002 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0};
5003 static const WCHAR szARPAUTHORIZEDCDFPREFIX
[] =
5004 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0};
5005 static const WCHAR szAuthorizedCDFPrefix
[] =
5006 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0};
5007 static const WCHAR szARPCONTACT
[] =
5008 {'A','R','P','C','O','N','T','A','C','T',0};
5009 static const WCHAR szContact
[] =
5010 {'C','o','n','t','a','c','t',0};
5011 static const WCHAR szARPCOMMENTS
[] =
5012 {'A','R','P','C','O','M','M','E','N','T','S',0};
5013 static const WCHAR szComments
[] =
5014 {'C','o','m','m','e','n','t','s',0};
5015 static const WCHAR szProductName
[] =
5016 {'P','r','o','d','u','c','t','N','a','m','e',0};
5017 static const WCHAR szDisplayName
[] =
5018 {'D','i','s','p','l','a','y','N','a','m','e',0};
5019 static const WCHAR szARPHELPLINK
[] =
5020 {'A','R','P','H','E','L','P','L','I','N','K',0};
5021 static const WCHAR szHelpLink
[] =
5022 {'H','e','l','p','L','i','n','k',0};
5023 static const WCHAR szARPHELPTELEPHONE
[] =
5024 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0};
5025 static const WCHAR szHelpTelephone
[] =
5026 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0};
5027 static const WCHAR szARPINSTALLLOCATION
[] =
5028 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0};
5029 static const WCHAR szManufacturer
[] =
5030 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
5031 static const WCHAR szPublisher
[] =
5032 {'P','u','b','l','i','s','h','e','r',0};
5033 static const WCHAR szARPREADME
[] =
5034 {'A','R','P','R','E','A','D','M','E',0};
5035 static const WCHAR szReadme
[] =
5036 {'R','e','a','d','M','e',0};
5037 static const WCHAR szARPSIZE
[] =
5038 {'A','R','P','S','I','Z','E',0};
5039 static const WCHAR szSize
[] =
5040 {'S','i','z','e',0};
5041 static const WCHAR szARPURLINFOABOUT
[] =
5042 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0};
5043 static const WCHAR szURLInfoAbout
[] =
5044 {'U','R','L','I','n','f','o','A','b','o','u','t',0};
5045 static const WCHAR szARPURLUPDATEINFO
[] =
5046 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0};
5047 static const WCHAR szURLUpdateInfo
[] =
5048 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0};
5049 static const WCHAR szARPSYSTEMCOMPONENT
[] =
5050 {'A','R','P','S','Y','S','T','E','M','C','O','M','P','O','N','E','N','T',0};
5051 static const WCHAR szSystemComponent
[] =
5052 {'S','y','s','t','e','m','C','o','m','p','o','n','e','n','t',0};
5054 static const WCHAR
*propval
[] = {
5055 szARPAUTHORIZEDCDFPREFIX
, szAuthorizedCDFPrefix
,
5056 szARPCONTACT
, szContact
,
5057 szARPCOMMENTS
, szComments
,
5058 szProductName
, szDisplayName
,
5059 szARPHELPLINK
, szHelpLink
,
5060 szARPHELPTELEPHONE
, szHelpTelephone
,
5061 szARPINSTALLLOCATION
, szInstallLocation
,
5062 szSourceDir
, szInstallSource
,
5063 szManufacturer
, szPublisher
,
5064 szARPREADME
, szReadme
,
5066 szARPURLINFOABOUT
, szURLInfoAbout
,
5067 szARPURLUPDATEINFO
, szURLUpdateInfo
,
5070 const WCHAR
**p
= propval
;
5076 val
= msi_dup_property(package
->db
, prop
);
5077 msi_reg_set_val_str(hkey
, key
, val
);
5081 msi_reg_set_val_dword(hkey
, szWindowsInstaller
, 1);
5082 if (msi_get_property_int( package
->db
, szARPSYSTEMCOMPONENT
, 0 ))
5084 msi_reg_set_val_dword( hkey
, szSystemComponent
, 1 );
5086 size
= deformat_string(package
, modpath_fmt
, &buffer
) * sizeof(WCHAR
);
5087 RegSetValueExW(hkey
, szModifyPath
, 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
5088 RegSetValueExW(hkey
, szUninstallString
, 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
5091 /* FIXME: Write real Estimated Size when we have it */
5092 msi_reg_set_val_dword(hkey
, szEstimatedSize
, 0);
5094 GetLocalTime(&systime
);
5095 sprintfW(date
, date_fmt
, systime
.wYear
, systime
.wMonth
, systime
.wDay
);
5096 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_INSTALLDATEW
, date
);
5098 langid
= msi_get_property_int(package
->db
, szProductLanguage
, 0);
5099 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
5101 buffer
= msi_dup_property(package
->db
, szProductVersion
);
5102 msi_reg_set_val_str(hkey
, szDisplayVersion
, buffer
);
5105 DWORD verdword
= msi_version_str_to_dword(buffer
);
5107 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
5108 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMAJORW
, verdword
>> 24);
5109 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMINORW
, (verdword
>> 16) & 0xFF);
5113 return ERROR_SUCCESS
;
5116 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
5118 WCHAR squashed_pc
[SQUISH_GUID_SIZE
];
5120 LPWSTR upgrade_code
;
5121 HKEY hkey
, props
, upgrade_key
;
5124 /* FIXME: also need to publish if the product is in advertise mode */
5125 if (!msi_check_publish(package
))
5126 return ERROR_SUCCESS
;
5128 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
, package
->platform
, &hkey
, TRUE
);
5129 if (rc
!= ERROR_SUCCESS
)
5132 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
, NULL
, &props
, TRUE
);
5133 if (rc
!= ERROR_SUCCESS
)
5136 rc
= msi_publish_install_properties(package
, hkey
);
5137 if (rc
!= ERROR_SUCCESS
)
5140 rc
= msi_publish_install_properties(package
, props
);
5141 if (rc
!= ERROR_SUCCESS
)
5144 upgrade_code
= msi_dup_property(package
->db
, szUpgradeCode
);
5147 rc
= MSIREG_OpenUpgradeCodesKey( upgrade_code
, &upgrade_key
, TRUE
);
5148 if (rc
== ERROR_SUCCESS
)
5150 squash_guid( package
->ProductCode
, squashed_pc
);
5151 msi_reg_set_val_str( upgrade_key
, squashed_pc
, NULL
);
5152 RegCloseKey( upgrade_key
);
5154 msi_free( upgrade_code
);
5156 msi_reg_set_val_str( props
, INSTALLPROPERTY_LOCALPACKAGEW
, package
->localfile
);
5157 package
->delete_on_close
= FALSE
;
5160 uirow
= MSI_CreateRecord( 1 );
5161 MSI_RecordSetStringW( uirow
, 1, package
->ProductCode
);
5162 msi_ui_actiondata( package
, szRegisterProduct
, uirow
);
5163 msiobj_release( &uirow
->hdr
);
5166 return ERROR_SUCCESS
;
5169 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
5171 return execute_script(package
, SCRIPT_INSTALL
);
5174 static UINT
ITERATE_UnpublishIcon( MSIRECORD
*row
, LPVOID param
)
5176 MSIPACKAGE
*package
= param
;
5177 const WCHAR
*icon
= MSI_RecordGetString( row
, 1 );
5178 WCHAR
*p
, *icon_path
;
5180 if (!icon
) return ERROR_SUCCESS
;
5181 if ((icon_path
= msi_build_icon_path( package
, icon
)))
5183 TRACE("removing icon file %s\n", debugstr_w(icon_path
));
5184 DeleteFileW( icon_path
);
5185 if ((p
= strrchrW( icon_path
, '\\' )))
5188 RemoveDirectoryW( icon_path
);
5190 msi_free( icon_path
);
5192 return ERROR_SUCCESS
;
5195 static UINT
msi_unpublish_icons( MSIPACKAGE
*package
)
5197 static const WCHAR query
[]= {
5198 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','I','c','o','n','`',0};
5202 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
5203 if (r
== ERROR_SUCCESS
)
5205 r
= MSI_IterateRecords( view
, NULL
, ITERATE_UnpublishIcon
, package
);
5206 msiobj_release( &view
->hdr
);
5207 if (r
!= ERROR_SUCCESS
)
5210 return ERROR_SUCCESS
;
5213 static UINT
msi_unpublish_product( MSIPACKAGE
*package
, const WCHAR
*remove
)
5215 static const WCHAR szUpgradeCode
[] = {'U','p','g','r','a','d','e','C','o','d','e',0};
5216 WCHAR
*upgrade
, **features
;
5217 BOOL full_uninstall
= TRUE
;
5218 MSIFEATURE
*feature
;
5219 MSIPATCHINFO
*patch
;
5222 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
5224 if (feature
->Action
== INSTALLSTATE_LOCAL
) full_uninstall
= FALSE
;
5226 features
= msi_split_string( remove
, ',' );
5227 for (i
= 0; features
&& features
[i
]; i
++)
5229 if (!strcmpW( features
[i
], szAll
)) full_uninstall
= TRUE
;
5233 if (!full_uninstall
)
5234 return ERROR_SUCCESS
;
5236 MSIREG_DeleteProductKey(package
->ProductCode
);
5237 MSIREG_DeleteUserDataProductKey(package
->ProductCode
);
5238 MSIREG_DeleteUninstallKey(package
->ProductCode
, package
->platform
);
5240 MSIREG_DeleteLocalClassesProductKey(package
->ProductCode
);
5241 MSIREG_DeleteLocalClassesFeaturesKey(package
->ProductCode
);
5242 MSIREG_DeleteUserProductKey(package
->ProductCode
);
5243 MSIREG_DeleteUserFeaturesKey(package
->ProductCode
);
5245 upgrade
= msi_dup_property(package
->db
, szUpgradeCode
);
5248 MSIREG_DeleteUserUpgradeCodesKey(upgrade
);
5249 MSIREG_DeleteClassesUpgradeCodesKey(upgrade
);
5253 LIST_FOR_EACH_ENTRY(patch
, &package
->patches
, MSIPATCHINFO
, entry
)
5255 MSIREG_DeleteUserDataPatchKey(patch
->patchcode
, package
->Context
);
5256 if (!strcmpW( package
->ProductCode
, patch
->products
))
5258 TRACE("removing local patch package %s\n", debugstr_w(patch
->localfile
));
5259 patch
->delete_on_close
= TRUE
;
5261 /* FIXME: remove local patch package if this is the last product */
5263 TRACE("removing local package %s\n", debugstr_w(package
->localfile
));
5264 package
->delete_on_close
= TRUE
;
5266 msi_unpublish_icons( package
);
5267 return ERROR_SUCCESS
;
5270 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
5275 /* first do the same as an InstallExecute */
5276 rc
= execute_script(package
, SCRIPT_INSTALL
);
5277 if (rc
!= ERROR_SUCCESS
)
5280 /* then handle commit actions */
5281 rc
= execute_script(package
, SCRIPT_COMMIT
);
5282 if (rc
!= ERROR_SUCCESS
)
5285 remove
= msi_dup_property(package
->db
, szRemove
);
5286 rc
= msi_unpublish_product(package
, remove
);
5291 UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
5293 static const WCHAR RunOnce
[] = {
5294 'S','o','f','t','w','a','r','e','\\',
5295 'M','i','c','r','o','s','o','f','t','\\',
5296 'W','i','n','d','o','w','s','\\',
5297 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5298 'R','u','n','O','n','c','e',0};
5299 static const WCHAR InstallRunOnce
[] = {
5300 'S','o','f','t','w','a','r','e','\\',
5301 'M','i','c','r','o','s','o','f','t','\\',
5302 'W','i','n','d','o','w','s','\\',
5303 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5304 'I','n','s','t','a','l','l','e','r','\\',
5305 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
5307 static const WCHAR msiexec_fmt
[] = {
5309 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5310 '\"','%','s','\"',0};
5311 static const WCHAR install_fmt
[] = {
5312 '/','I',' ','\"','%','s','\"',' ',
5313 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5314 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5315 WCHAR buffer
[256], sysdir
[MAX_PATH
];
5317 WCHAR squished_pc
[100];
5319 squash_guid(package
->ProductCode
,squished_pc
);
5321 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
5322 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
5323 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
5326 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
5329 TRACE("Reboot command %s\n",debugstr_w(buffer
));
5331 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
5332 sprintfW(buffer
,install_fmt
,package
->ProductCode
,squished_pc
);
5334 msi_reg_set_val_str( hkey
, squished_pc
, buffer
);
5337 return ERROR_INSTALL_SUSPEND
;
5340 WCHAR
*msi_build_error_string( MSIPACKAGE
*package
, UINT error
, DWORD count
, ... )
5342 static const WCHAR query
[] =
5343 {'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
5344 'F','R','O','M',' ','`','E','r','r','o','r','`',' ','W','H','E','R','E',' ',
5345 '`','E','r','r','o','r','`',' ','=',' ','%','i',0};
5346 MSIRECORD
*rec
, *row
;
5352 if (!(row
= MSI_QueryGetRecord( package
->db
, query
, error
))) return 0;
5354 rec
= MSI_CreateRecord( count
+ 2 );
5355 str
= MSI_RecordGetString( row
, 1 );
5356 MSI_RecordSetStringW( rec
, 0, str
);
5357 msiobj_release( &row
->hdr
);
5358 MSI_RecordSetInteger( rec
, 1, error
);
5360 va_start( va
, count
);
5361 for (i
= 0; i
< count
; i
++)
5363 str
= va_arg( va
, const WCHAR
*);
5364 MSI_RecordSetStringW( rec
, i
+ 2, str
);
5368 MSI_FormatRecordW( package
, rec
, NULL
, &size
);
5370 data
= msi_alloc( size
* sizeof(WCHAR
) );
5371 if (size
> 1) MSI_FormatRecordW( package
, rec
, data
, &size
);
5373 msiobj_release( &rec
->hdr
);
5377 static UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
5383 * We are currently doing what should be done here in the top level Install
5384 * however for Administrative and uninstalls this step will be needed
5386 if (!package
->PackagePath
)
5387 return ERROR_SUCCESS
;
5389 msi_set_sourcedir_props(package
, TRUE
);
5391 attrib
= GetFileAttributesW(package
->db
->path
);
5392 if (attrib
== INVALID_FILE_ATTRIBUTES
)
5397 rc
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
5398 package
->Context
, MSICODE_PRODUCT
,
5399 INSTALLPROPERTY_DISKPROMPTW
,NULL
,&size
);
5400 if (rc
== ERROR_MORE_DATA
)
5402 prompt
= msi_alloc(size
* sizeof(WCHAR
));
5403 MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
5404 package
->Context
, MSICODE_PRODUCT
,
5405 INSTALLPROPERTY_DISKPROMPTW
,prompt
,&size
);
5408 prompt
= strdupW(package
->db
->path
);
5410 msg
= msi_build_error_string(package
, 1302, 1, prompt
);
5412 while(attrib
== INVALID_FILE_ATTRIBUTES
)
5414 rc
= MessageBoxW(NULL
, msg
, NULL
, MB_OKCANCEL
);
5418 return ERROR_INSTALL_USEREXIT
;
5420 attrib
= GetFileAttributesW(package
->db
->path
);
5426 return ERROR_SUCCESS
;
5431 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
5434 LPWSTR buffer
, productid
= NULL
;
5435 UINT i
, rc
= ERROR_SUCCESS
;
5438 static const WCHAR szPropKeys
[][80] =
5440 {'P','r','o','d','u','c','t','I','D',0},
5441 {'U','S','E','R','N','A','M','E',0},
5442 {'C','O','M','P','A','N','Y','N','A','M','E',0},
5446 static const WCHAR szRegKeys
[][80] =
5448 {'P','r','o','d','u','c','t','I','D',0},
5449 {'R','e','g','O','w','n','e','r',0},
5450 {'R','e','g','C','o','m','p','a','n','y',0},
5454 if (msi_check_unpublish(package
))
5456 MSIREG_DeleteUserDataProductKey(package
->ProductCode
);
5460 productid
= msi_dup_property( package
->db
, INSTALLPROPERTY_PRODUCTIDW
);
5464 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
,
5466 if (rc
!= ERROR_SUCCESS
)
5469 for( i
= 0; szPropKeys
[i
][0]; i
++ )
5471 buffer
= msi_dup_property( package
->db
, szPropKeys
[i
] );
5472 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
5477 uirow
= MSI_CreateRecord( 1 );
5478 MSI_RecordSetStringW( uirow
, 1, productid
);
5479 msi_ui_actiondata( package
, szRegisterUser
, uirow
);
5480 msiobj_release( &uirow
->hdr
);
5482 msi_free(productid
);
5488 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
5492 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
5493 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
5497 WCHAR
*msi_create_component_advertise_string( MSIPACKAGE
*package
, MSICOMPONENT
*component
, const WCHAR
*feature
)
5499 static const WCHAR fmt
[] = {'%','s','%','s','%','c','%','s',0};
5500 WCHAR productid_85
[21], component_85
[21], *ret
;
5504 /* > is used if there is a component GUID and < if not. */
5506 productid_85
[0] = 0;
5507 component_85
[0] = 0;
5508 CLSIDFromString( package
->ProductCode
, &clsid
);
5510 encode_base85_guid( &clsid
, productid_85
);
5513 CLSIDFromString( component
->ComponentId
, &clsid
);
5514 encode_base85_guid( &clsid
, component_85
);
5517 TRACE("product=%s feature=%s component=%s\n", debugstr_w(productid_85
), debugstr_w(feature
),
5518 debugstr_w(component_85
));
5520 sz
= 20 + strlenW( feature
) + 20 + 3;
5521 ret
= msi_alloc_zero( sz
* sizeof(WCHAR
) );
5522 if (ret
) sprintfW( ret
, fmt
, productid_85
, feature
, component
? '>' : '<', component_85
);
5526 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
5528 MSIPACKAGE
*package
= param
;
5529 LPCWSTR compgroupid
, component
, feature
, qualifier
, text
;
5530 LPWSTR advertise
= NULL
, output
= NULL
, existing
= NULL
, p
, q
;
5539 feature
= MSI_RecordGetString(rec
, 5);
5540 feat
= msi_get_loaded_feature(package
, feature
);
5542 return ERROR_SUCCESS
;
5544 feat
->Action
= msi_get_feature_action( package
, feat
);
5545 if (feat
->Action
!= INSTALLSTATE_LOCAL
&&
5546 feat
->Action
!= INSTALLSTATE_SOURCE
&&
5547 feat
->Action
!= INSTALLSTATE_ADVERTISED
)
5549 TRACE("feature not scheduled for installation %s\n", debugstr_w(feature
));
5550 return ERROR_SUCCESS
;
5553 component
= MSI_RecordGetString(rec
, 3);
5554 comp
= msi_get_loaded_component(package
, component
);
5556 return ERROR_SUCCESS
;
5558 compgroupid
= MSI_RecordGetString(rec
,1);
5559 qualifier
= MSI_RecordGetString(rec
,2);
5561 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
5562 if (rc
!= ERROR_SUCCESS
)
5565 advertise
= msi_create_component_advertise_string( package
, comp
, feature
);
5566 text
= MSI_RecordGetString( rec
, 4 );
5569 p
= msi_alloc( (strlenW( advertise
) + strlenW( text
) + 1) * sizeof(WCHAR
) );
5570 strcpyW( p
, advertise
);
5572 msi_free( advertise
);
5575 existing
= msi_reg_get_val_str( hkey
, qualifier
);
5577 sz
= strlenW( advertise
) + 1;
5580 for (p
= existing
; *p
; p
+= len
)
5582 len
= strlenW( p
) + 1;
5583 if (strcmpW( advertise
, p
)) sz
+= len
;
5586 if (!(output
= msi_alloc( (sz
+ 1) * sizeof(WCHAR
) )))
5588 rc
= ERROR_OUTOFMEMORY
;
5594 for (p
= existing
; *p
; p
+= len
)
5596 len
= strlenW( p
) + 1;
5597 if (strcmpW( advertise
, p
))
5599 memcpy( q
, p
, len
* sizeof(WCHAR
) );
5604 strcpyW( q
, advertise
);
5605 q
[strlenW( q
) + 1] = 0;
5607 msi_reg_set_val_multi_str( hkey
, qualifier
, output
);
5612 msi_free( advertise
);
5613 msi_free( existing
);
5616 uirow
= MSI_CreateRecord( 2 );
5617 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
5618 MSI_RecordSetStringW( uirow
, 2, qualifier
);
5619 msi_ui_actiondata( package
, szPublishComponents
, uirow
);
5620 msiobj_release( &uirow
->hdr
);
5621 /* FIXME: call ui_progress? */
5627 * At present I am ignorning the advertised components part of this and only
5628 * focusing on the qualified component sets
5630 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
5632 static const WCHAR query
[] = {
5633 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5634 '`','P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','`',0};
5638 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
5639 if (rc
!= ERROR_SUCCESS
)
5640 return ERROR_SUCCESS
;
5642 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
5643 msiobj_release(&view
->hdr
);
5647 static UINT
ITERATE_UnpublishComponent( MSIRECORD
*rec
, LPVOID param
)
5649 static const WCHAR szInstallerComponents
[] = {
5650 'S','o','f','t','w','a','r','e','\\',
5651 'M','i','c','r','o','s','o','f','t','\\',
5652 'I','n','s','t','a','l','l','e','r','\\',
5653 'C','o','m','p','o','n','e','n','t','s','\\',0};
5655 MSIPACKAGE
*package
= param
;
5656 LPCWSTR compgroupid
, component
, feature
, qualifier
;
5660 WCHAR squashed
[GUID_SIZE
], keypath
[MAX_PATH
];
5663 feature
= MSI_RecordGetString( rec
, 5 );
5664 feat
= msi_get_loaded_feature( package
, feature
);
5666 return ERROR_SUCCESS
;
5668 feat
->Action
= msi_get_feature_action( package
, feat
);
5669 if (feat
->Action
!= INSTALLSTATE_ABSENT
)
5671 TRACE("feature not scheduled for removal %s\n", debugstr_w(feature
));
5672 return ERROR_SUCCESS
;
5675 component
= MSI_RecordGetString( rec
, 3 );
5676 comp
= msi_get_loaded_component( package
, component
);
5678 return ERROR_SUCCESS
;
5680 compgroupid
= MSI_RecordGetString( rec
, 1 );
5681 qualifier
= MSI_RecordGetString( rec
, 2 );
5683 squash_guid( compgroupid
, squashed
);
5684 strcpyW( keypath
, szInstallerComponents
);
5685 strcatW( keypath
, squashed
);
5687 res
= RegDeleteKeyW( HKEY_CURRENT_USER
, keypath
);
5688 if (res
!= ERROR_SUCCESS
)
5690 WARN("Unable to delete component key %d\n", res
);
5693 uirow
= MSI_CreateRecord( 2 );
5694 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
5695 MSI_RecordSetStringW( uirow
, 2, qualifier
);
5696 msi_ui_actiondata( package
, szUnpublishComponents
, uirow
);
5697 msiobj_release( &uirow
->hdr
);
5699 return ERROR_SUCCESS
;
5702 static UINT
ACTION_UnpublishComponents( MSIPACKAGE
*package
)
5704 static const WCHAR query
[] = {
5705 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5706 '`','P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','`',0};
5710 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
5711 if (rc
!= ERROR_SUCCESS
)
5712 return ERROR_SUCCESS
;
5714 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnpublishComponent
, package
);
5715 msiobj_release( &view
->hdr
);
5719 static UINT
ITERATE_InstallService(MSIRECORD
*rec
, LPVOID param
)
5721 static const WCHAR query
[] =
5722 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5723 '`','C','o','m','p','o','n','e','n','t','`',' ','W','H','E','R','E',' ',
5724 '`','C','o','m','p','o','n','e','n','t','`',' ','=','\'','%','s','\'',0};
5725 MSIPACKAGE
*package
= param
;
5726 MSICOMPONENT
*component
;
5729 SC_HANDLE hscm
= NULL
, service
= NULL
;
5731 LPWSTR name
= NULL
, disp
= NULL
, load_order
= NULL
, serv_name
= NULL
;
5732 LPWSTR depends
= NULL
, pass
= NULL
, args
= NULL
, image_path
= NULL
;
5733 DWORD serv_type
, start_type
, err_control
;
5734 SERVICE_DESCRIPTIONW sd
= {NULL
};
5735 UINT ret
= ERROR_SUCCESS
;
5737 comp
= MSI_RecordGetString( rec
, 12 );
5738 component
= msi_get_loaded_component( package
, comp
);
5741 WARN("service component not found\n");
5744 component
->Action
= msi_get_component_action( package
, component
);
5745 if (component
->Action
!= INSTALLSTATE_LOCAL
)
5747 TRACE("component not scheduled for installation %s\n", debugstr_w(comp
));
5750 hscm
= OpenSCManagerW(NULL
, SERVICES_ACTIVE_DATABASEW
, GENERIC_WRITE
);
5753 ERR("Failed to open the SC Manager!\n");
5757 start_type
= MSI_RecordGetInteger(rec
, 5);
5758 if (start_type
== SERVICE_BOOT_START
|| start_type
== SERVICE_SYSTEM_START
)
5761 deformat_string(package
, MSI_RecordGetString(rec
, 2), &name
);
5762 deformat_string(package
, MSI_RecordGetString(rec
, 3), &disp
);
5763 serv_type
= MSI_RecordGetInteger(rec
, 4);
5764 err_control
= MSI_RecordGetInteger(rec
, 6);
5765 deformat_string(package
, MSI_RecordGetString(rec
, 7), &load_order
);
5766 deformat_string(package
, MSI_RecordGetString(rec
, 8), &depends
);
5767 deformat_string(package
, MSI_RecordGetString(rec
, 9), &serv_name
);
5768 deformat_string(package
, MSI_RecordGetString(rec
, 10), &pass
);
5769 deformat_string(package
, MSI_RecordGetString(rec
, 11), &args
);
5770 deformat_string(package
, MSI_RecordGetString(rec
, 13), &sd
.lpDescription
);
5772 /* fetch the service path */
5773 row
= MSI_QueryGetRecord(package
->db
, query
, comp
);
5776 ERR("Query failed\n");
5779 if (!(key
= MSI_RecordGetString(row
, 6)))
5781 msiobj_release(&row
->hdr
);
5784 file
= msi_get_loaded_file(package
, key
);
5785 msiobj_release(&row
->hdr
);
5788 ERR("Failed to load the service file\n");
5792 if (!args
|| !args
[0]) image_path
= file
->TargetPath
;
5795 int len
= strlenW(file
->TargetPath
) + strlenW(args
) + 2;
5796 if (!(image_path
= msi_alloc(len
* sizeof(WCHAR
))))
5798 ret
= ERROR_OUTOFMEMORY
;
5802 strcpyW(image_path
, file
->TargetPath
);
5803 strcatW(image_path
, szSpace
);
5804 strcatW(image_path
, args
);
5806 service
= CreateServiceW(hscm
, name
, disp
, GENERIC_ALL
, serv_type
,
5807 start_type
, err_control
, image_path
, load_order
,
5808 NULL
, depends
, serv_name
, pass
);
5812 if (GetLastError() != ERROR_SERVICE_EXISTS
)
5813 ERR("Failed to create service %s: %d\n", debugstr_w(name
), GetLastError());
5815 else if (sd
.lpDescription
)
5817 if (!ChangeServiceConfig2W(service
, SERVICE_CONFIG_DESCRIPTION
, &sd
))
5818 WARN("failed to set service description %u\n", GetLastError());
5821 if (image_path
!= file
->TargetPath
) msi_free(image_path
);
5823 CloseServiceHandle(service
);
5824 CloseServiceHandle(hscm
);
5827 msi_free(sd
.lpDescription
);
5828 msi_free(load_order
);
5829 msi_free(serv_name
);
5837 static UINT
ACTION_InstallServices( MSIPACKAGE
*package
)
5839 static const WCHAR query
[] = {
5840 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5841 'S','e','r','v','i','c','e','I','n','s','t','a','l','l',0};
5845 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
5846 if (rc
!= ERROR_SUCCESS
)
5847 return ERROR_SUCCESS
;
5849 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallService
, package
);
5850 msiobj_release(&view
->hdr
);
5854 /* converts arg1[~]arg2[~]arg3 to a list of ptrs to the strings */
5855 static LPCWSTR
*msi_service_args_to_vector(LPWSTR args
, DWORD
*numargs
)
5857 LPCWSTR
*vector
, *temp_vector
;
5861 static const WCHAR separator
[] = {'[','~',']',0};
5864 sep_len
= sizeof(separator
) / sizeof(WCHAR
) - 1;
5869 vector
= msi_alloc(sizeof(LPWSTR
));
5877 vector
[*numargs
- 1] = p
;
5879 if ((q
= strstrW(p
, separator
)))
5883 temp_vector
= msi_realloc(vector
, (*numargs
+ 1) * sizeof(LPWSTR
));
5889 vector
= temp_vector
;
5898 static UINT
ITERATE_StartService(MSIRECORD
*rec
, LPVOID param
)
5900 MSIPACKAGE
*package
= param
;
5903 SC_HANDLE scm
= NULL
, service
= NULL
;
5904 LPCWSTR component
, *vector
= NULL
;
5905 LPWSTR name
, args
, display_name
= NULL
;
5906 DWORD event
, numargs
, len
, wait
, dummy
;
5907 UINT r
= ERROR_FUNCTION_FAILED
;
5908 SERVICE_STATUS_PROCESS status
;
5909 ULONGLONG start_time
;
5911 component
= MSI_RecordGetString(rec
, 6);
5912 comp
= msi_get_loaded_component(package
, component
);
5914 return ERROR_SUCCESS
;
5916 event
= MSI_RecordGetInteger( rec
, 3 );
5917 deformat_string( package
, MSI_RecordGetString( rec
, 2 ), &name
);
5919 comp
->Action
= msi_get_component_action( package
, comp
);
5920 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventStart
)) &&
5921 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallStart
)))
5923 TRACE("not starting %s\n", debugstr_w(name
));
5925 return ERROR_SUCCESS
;
5928 deformat_string(package
, MSI_RecordGetString(rec
, 4), &args
);
5929 wait
= MSI_RecordGetInteger(rec
, 5);
5931 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_CONNECT
);
5934 ERR("Failed to open the service control manager\n");
5939 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
5940 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
5942 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
5943 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
5946 service
= OpenServiceW(scm
, name
, SERVICE_START
|SERVICE_QUERY_STATUS
);
5949 ERR("Failed to open service %s (%u)\n", debugstr_w(name
), GetLastError());
5953 vector
= msi_service_args_to_vector(args
, &numargs
);
5955 if (!StartServiceW(service
, numargs
, vector
) &&
5956 GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
)
5958 ERR("Failed to start service %s (%u)\n", debugstr_w(name
), GetLastError());
5965 /* wait for at most 30 seconds for the service to be up and running */
5966 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
,
5967 (BYTE
*)&status
, sizeof(SERVICE_STATUS_PROCESS
), &dummy
))
5969 TRACE("failed to query service status (%u)\n", GetLastError());
5972 start_time
= GetTickCount64();
5973 while (status
.dwCurrentState
== SERVICE_START_PENDING
)
5975 if (GetTickCount64() - start_time
> 30000) break;
5977 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
,
5978 (BYTE
*)&status
, sizeof(SERVICE_STATUS_PROCESS
), &dummy
))
5980 TRACE("failed to query service status (%u)\n", GetLastError());
5984 if (status
.dwCurrentState
!= SERVICE_RUNNING
)
5986 WARN("service failed to start %u\n", status
.dwCurrentState
);
5987 r
= ERROR_FUNCTION_FAILED
;
5992 uirow
= MSI_CreateRecord( 2 );
5993 MSI_RecordSetStringW( uirow
, 1, display_name
);
5994 MSI_RecordSetStringW( uirow
, 2, name
);
5995 msi_ui_actiondata( package
, szStartServices
, uirow
);
5996 msiobj_release( &uirow
->hdr
);
5998 CloseServiceHandle(service
);
5999 CloseServiceHandle(scm
);
6004 msi_free(display_name
);
6008 static UINT
ACTION_StartServices( MSIPACKAGE
*package
)
6010 static const WCHAR query
[] = {
6011 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6012 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0};
6016 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
6017 if (rc
!= ERROR_SUCCESS
)
6018 return ERROR_SUCCESS
;
6020 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StartService
, package
);
6021 msiobj_release(&view
->hdr
);
6025 static BOOL
stop_service_dependents(SC_HANDLE scm
, SC_HANDLE service
)
6027 DWORD i
, needed
, count
;
6028 ENUM_SERVICE_STATUSW
*dependencies
;
6031 BOOL stopped
, ret
= FALSE
;
6033 if (EnumDependentServicesW(service
, SERVICE_ACTIVE
, NULL
,
6034 0, &needed
, &count
))
6037 if (GetLastError() != ERROR_MORE_DATA
)
6040 dependencies
= msi_alloc(needed
);
6044 if (!EnumDependentServicesW(service
, SERVICE_ACTIVE
, dependencies
,
6045 needed
, &needed
, &count
))
6048 for (i
= 0; i
< count
; i
++)
6050 depserv
= OpenServiceW(scm
, dependencies
[i
].lpServiceName
,
6051 SERVICE_STOP
| SERVICE_QUERY_STATUS
);
6055 stopped
= ControlService(depserv
, SERVICE_CONTROL_STOP
, &ss
);
6056 CloseServiceHandle(depserv
);
6064 msi_free(dependencies
);
6068 static UINT
stop_service( LPCWSTR name
)
6070 SC_HANDLE scm
= NULL
, service
= NULL
;
6071 SERVICE_STATUS status
;
6072 SERVICE_STATUS_PROCESS ssp
;
6075 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
6078 WARN("Failed to open the SCM: %d\n", GetLastError());
6082 service
= OpenServiceW(scm
, name
,
6084 SERVICE_QUERY_STATUS
|
6085 SERVICE_ENUMERATE_DEPENDENTS
);
6088 WARN("Failed to open service (%s): %d\n", debugstr_w(name
), GetLastError());
6092 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
, (LPBYTE
)&ssp
,
6093 sizeof(SERVICE_STATUS_PROCESS
), &needed
))
6095 WARN("Failed to query service status (%s): %d\n", debugstr_w(name
), GetLastError());
6099 if (ssp
.dwCurrentState
== SERVICE_STOPPED
)
6102 stop_service_dependents(scm
, service
);
6104 if (!ControlService(service
, SERVICE_CONTROL_STOP
, &status
))
6105 WARN("Failed to stop service (%s): %d\n", debugstr_w(name
), GetLastError());
6108 CloseServiceHandle(service
);
6109 CloseServiceHandle(scm
);
6111 return ERROR_SUCCESS
;
6114 static UINT
ITERATE_StopService( MSIRECORD
*rec
, LPVOID param
)
6116 MSIPACKAGE
*package
= param
;
6120 WCHAR
*name
, *display_name
= NULL
;
6124 component
= MSI_RecordGetString( rec
, 6 );
6125 comp
= msi_get_loaded_component( package
, component
);
6127 return ERROR_SUCCESS
;
6129 event
= MSI_RecordGetInteger( rec
, 3 );
6130 deformat_string( package
, MSI_RecordGetString( rec
, 2 ), &name
);
6132 comp
->Action
= msi_get_component_action( package
, comp
);
6133 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventStop
)) &&
6134 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallStop
)))
6136 TRACE("not stopping %s\n", debugstr_w(name
));
6138 return ERROR_SUCCESS
;
6141 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_CONNECT
);
6144 ERR("Failed to open the service control manager\n");
6149 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
6150 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
6152 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
6153 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
6155 CloseServiceHandle( scm
);
6157 stop_service( name
);
6160 uirow
= MSI_CreateRecord( 2 );
6161 MSI_RecordSetStringW( uirow
, 1, display_name
);
6162 MSI_RecordSetStringW( uirow
, 2, name
);
6163 msi_ui_actiondata( package
, szStopServices
, uirow
);
6164 msiobj_release( &uirow
->hdr
);
6167 msi_free( display_name
);
6168 return ERROR_SUCCESS
;
6171 static UINT
ACTION_StopServices( MSIPACKAGE
*package
)
6173 static const WCHAR query
[] = {
6174 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6175 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0};
6179 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
6180 if (rc
!= ERROR_SUCCESS
)
6181 return ERROR_SUCCESS
;
6183 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StopService
, package
);
6184 msiobj_release(&view
->hdr
);
6188 static UINT
ITERATE_DeleteService( MSIRECORD
*rec
, LPVOID param
)
6190 MSIPACKAGE
*package
= param
;
6193 LPWSTR name
= NULL
, display_name
= NULL
;
6195 SC_HANDLE scm
= NULL
, service
= NULL
;
6197 comp
= msi_get_loaded_component( package
, MSI_RecordGetString(rec
, 6) );
6199 return ERROR_SUCCESS
;
6201 event
= MSI_RecordGetInteger( rec
, 3 );
6202 deformat_string( package
, MSI_RecordGetString(rec
, 2), &name
);
6204 comp
->Action
= msi_get_component_action( package
, comp
);
6205 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventDelete
)) &&
6206 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallDelete
)))
6208 TRACE("service %s not scheduled for removal\n", debugstr_w(name
));
6210 return ERROR_SUCCESS
;
6212 stop_service( name
);
6214 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
6217 WARN("Failed to open the SCM: %d\n", GetLastError());
6222 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
6223 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
6225 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
6226 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
6229 service
= OpenServiceW( scm
, name
, DELETE
);
6232 WARN("Failed to open service (%s): %u\n", debugstr_w(name
), GetLastError());
6236 if (!DeleteService( service
))
6237 WARN("Failed to delete service (%s): %u\n", debugstr_w(name
), GetLastError());
6240 uirow
= MSI_CreateRecord( 2 );
6241 MSI_RecordSetStringW( uirow
, 1, display_name
);
6242 MSI_RecordSetStringW( uirow
, 2, name
);
6243 msi_ui_actiondata( package
, szDeleteServices
, uirow
);
6244 msiobj_release( &uirow
->hdr
);
6246 CloseServiceHandle( service
);
6247 CloseServiceHandle( scm
);
6249 msi_free( display_name
);
6251 return ERROR_SUCCESS
;
6254 static UINT
ACTION_DeleteServices( MSIPACKAGE
*package
)
6256 static const WCHAR query
[] = {
6257 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6258 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0};
6262 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
6263 if (rc
!= ERROR_SUCCESS
)
6264 return ERROR_SUCCESS
;
6266 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_DeleteService
, package
);
6267 msiobj_release( &view
->hdr
);
6271 static UINT
ITERATE_InstallODBCDriver( MSIRECORD
*rec
, LPVOID param
)
6273 MSIPACKAGE
*package
= param
;
6274 LPWSTR driver
, driver_path
, ptr
;
6275 WCHAR outpath
[MAX_PATH
];
6276 MSIFILE
*driver_file
= NULL
, *setup_file
= NULL
;
6279 LPCWSTR desc
, file_key
, component
;
6281 UINT r
= ERROR_SUCCESS
;
6283 static const WCHAR driver_fmt
[] = {
6284 'D','r','i','v','e','r','=','%','s',0};
6285 static const WCHAR setup_fmt
[] = {
6286 'S','e','t','u','p','=','%','s',0};
6287 static const WCHAR usage_fmt
[] = {
6288 'F','i','l','e','U','s','a','g','e','=','1',0};
6290 component
= MSI_RecordGetString( rec
, 2 );
6291 comp
= msi_get_loaded_component( package
, component
);
6293 return ERROR_SUCCESS
;
6295 comp
->Action
= msi_get_component_action( package
, comp
);
6296 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6298 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6299 return ERROR_SUCCESS
;
6301 desc
= MSI_RecordGetString(rec
, 3);
6303 file_key
= MSI_RecordGetString( rec
, 4 );
6304 if (file_key
) driver_file
= msi_get_loaded_file( package
, file_key
);
6306 file_key
= MSI_RecordGetString( rec
, 5 );
6307 if (file_key
) setup_file
= msi_get_loaded_file( package
, file_key
);
6311 ERR("ODBC Driver entry not found!\n");
6312 return ERROR_FUNCTION_FAILED
;
6315 len
= lstrlenW(desc
) + lstrlenW(driver_fmt
) + lstrlenW(driver_file
->FileName
);
6317 len
+= lstrlenW(setup_fmt
) + lstrlenW(setup_file
->FileName
);
6318 len
+= lstrlenW(usage_fmt
) + 2; /* \0\0 */
6320 driver
= msi_alloc(len
* sizeof(WCHAR
));
6322 return ERROR_OUTOFMEMORY
;
6325 lstrcpyW(ptr
, desc
);
6326 ptr
+= lstrlenW(ptr
) + 1;
6328 len
= sprintfW(ptr
, driver_fmt
, driver_file
->FileName
);
6333 len
= sprintfW(ptr
, setup_fmt
, setup_file
->FileName
);
6337 lstrcpyW(ptr
, usage_fmt
);
6338 ptr
+= lstrlenW(ptr
) + 1;
6341 if (!driver_file
->TargetPath
)
6343 const WCHAR
*dir
= msi_get_target_folder( package
, driver_file
->Component
->Directory
);
6344 driver_file
->TargetPath
= msi_build_directory_name( 2, dir
, driver_file
->FileName
);
6346 driver_path
= strdupW(driver_file
->TargetPath
);
6347 ptr
= strrchrW(driver_path
, '\\');
6348 if (ptr
) *ptr
= '\0';
6350 if (!SQLInstallDriverExW(driver
, driver_path
, outpath
, MAX_PATH
,
6351 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
6353 ERR("Failed to install SQL driver!\n");
6354 r
= ERROR_FUNCTION_FAILED
;
6357 uirow
= MSI_CreateRecord( 5 );
6358 MSI_RecordSetStringW( uirow
, 1, desc
);
6359 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6360 MSI_RecordSetStringW( uirow
, 3, driver_file
->Component
->Directory
);
6361 msi_ui_actiondata( package
, szInstallODBC
, uirow
);
6362 msiobj_release( &uirow
->hdr
);
6365 msi_free(driver_path
);
6370 static UINT
ITERATE_InstallODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
6372 MSIPACKAGE
*package
= param
;
6373 LPWSTR translator
, translator_path
, ptr
;
6374 WCHAR outpath
[MAX_PATH
];
6375 MSIFILE
*translator_file
= NULL
, *setup_file
= NULL
;
6378 LPCWSTR desc
, file_key
, component
;
6380 UINT r
= ERROR_SUCCESS
;
6382 static const WCHAR translator_fmt
[] = {
6383 'T','r','a','n','s','l','a','t','o','r','=','%','s',0};
6384 static const WCHAR setup_fmt
[] = {
6385 'S','e','t','u','p','=','%','s',0};
6387 component
= MSI_RecordGetString( rec
, 2 );
6388 comp
= msi_get_loaded_component( package
, component
);
6390 return ERROR_SUCCESS
;
6392 comp
->Action
= msi_get_component_action( package
, comp
);
6393 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6395 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6396 return ERROR_SUCCESS
;
6398 desc
= MSI_RecordGetString(rec
, 3);
6400 file_key
= MSI_RecordGetString( rec
, 4 );
6401 if (file_key
) translator_file
= msi_get_loaded_file( package
, file_key
);
6403 file_key
= MSI_RecordGetString( rec
, 5 );
6404 if (file_key
) setup_file
= msi_get_loaded_file( package
, file_key
);
6406 if (!translator_file
)
6408 ERR("ODBC Translator entry not found!\n");
6409 return ERROR_FUNCTION_FAILED
;
6412 len
= lstrlenW(desc
) + lstrlenW(translator_fmt
) + lstrlenW(translator_file
->FileName
) + 2; /* \0\0 */
6414 len
+= lstrlenW(setup_fmt
) + lstrlenW(setup_file
->FileName
);
6416 translator
= msi_alloc(len
* sizeof(WCHAR
));
6418 return ERROR_OUTOFMEMORY
;
6421 lstrcpyW(ptr
, desc
);
6422 ptr
+= lstrlenW(ptr
) + 1;
6424 len
= sprintfW(ptr
, translator_fmt
, translator_file
->FileName
);
6429 len
= sprintfW(ptr
, setup_fmt
, setup_file
->FileName
);
6434 translator_path
= strdupW(translator_file
->TargetPath
);
6435 ptr
= strrchrW(translator_path
, '\\');
6436 if (ptr
) *ptr
= '\0';
6438 if (!SQLInstallTranslatorExW(translator
, translator_path
, outpath
, MAX_PATH
,
6439 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
6441 ERR("Failed to install SQL translator!\n");
6442 r
= ERROR_FUNCTION_FAILED
;
6445 uirow
= MSI_CreateRecord( 5 );
6446 MSI_RecordSetStringW( uirow
, 1, desc
);
6447 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6448 MSI_RecordSetStringW( uirow
, 3, translator_file
->Component
->Directory
);
6449 msi_ui_actiondata( package
, szInstallODBC
, uirow
);
6450 msiobj_release( &uirow
->hdr
);
6452 msi_free(translator
);
6453 msi_free(translator_path
);
6458 static UINT
ITERATE_InstallODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
6460 MSIPACKAGE
*package
= param
;
6463 LPCWSTR desc
, driver
, component
;
6464 WORD request
= ODBC_ADD_SYS_DSN
;
6467 UINT r
= ERROR_SUCCESS
;
6470 static const WCHAR attrs_fmt
[] = {
6471 'D','S','N','=','%','s',0 };
6473 component
= MSI_RecordGetString( rec
, 2 );
6474 comp
= msi_get_loaded_component( package
, component
);
6476 return ERROR_SUCCESS
;
6478 comp
->Action
= msi_get_component_action( package
, comp
);
6479 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6481 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6482 return ERROR_SUCCESS
;
6485 desc
= MSI_RecordGetString(rec
, 3);
6486 driver
= MSI_RecordGetString(rec
, 4);
6487 registration
= MSI_RecordGetInteger(rec
, 5);
6489 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_ADD_SYS_DSN
;
6490 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_ADD_DSN
;
6492 len
= lstrlenW(attrs_fmt
) + lstrlenW(desc
) + 2; /* \0\0 */
6493 attrs
= msi_alloc(len
* sizeof(WCHAR
));
6495 return ERROR_OUTOFMEMORY
;
6497 len
= sprintfW(attrs
, attrs_fmt
, desc
);
6500 if (!SQLConfigDataSourceW(NULL
, request
, driver
, attrs
))
6502 ERR("Failed to install SQL data source!\n");
6503 r
= ERROR_FUNCTION_FAILED
;
6506 uirow
= MSI_CreateRecord( 5 );
6507 MSI_RecordSetStringW( uirow
, 1, desc
);
6508 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6509 MSI_RecordSetInteger( uirow
, 3, request
);
6510 msi_ui_actiondata( package
, szInstallODBC
, uirow
);
6511 msiobj_release( &uirow
->hdr
);
6518 static UINT
ACTION_InstallODBC( MSIPACKAGE
*package
)
6520 static const WCHAR driver_query
[] = {
6521 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6522 'O','D','B','C','D','r','i','v','e','r',0};
6523 static const WCHAR translator_query
[] = {
6524 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6525 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0};
6526 static const WCHAR source_query
[] = {
6527 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6528 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0};
6532 rc
= MSI_DatabaseOpenViewW(package
->db
, driver_query
, &view
);
6533 if (rc
== ERROR_SUCCESS
)
6535 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDriver
, package
);
6536 msiobj_release(&view
->hdr
);
6537 if (rc
!= ERROR_SUCCESS
)
6540 rc
= MSI_DatabaseOpenViewW(package
->db
, translator_query
, &view
);
6541 if (rc
== ERROR_SUCCESS
)
6543 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCTranslator
, package
);
6544 msiobj_release(&view
->hdr
);
6545 if (rc
!= ERROR_SUCCESS
)
6548 rc
= MSI_DatabaseOpenViewW(package
->db
, source_query
, &view
);
6549 if (rc
== ERROR_SUCCESS
)
6551 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDataSource
, package
);
6552 msiobj_release(&view
->hdr
);
6553 if (rc
!= ERROR_SUCCESS
)
6556 return ERROR_SUCCESS
;
6559 static UINT
ITERATE_RemoveODBCDriver( MSIRECORD
*rec
, LPVOID param
)
6561 MSIPACKAGE
*package
= param
;
6565 LPCWSTR desc
, component
;
6567 component
= MSI_RecordGetString( rec
, 2 );
6568 comp
= msi_get_loaded_component( package
, component
);
6570 return ERROR_SUCCESS
;
6572 comp
->Action
= msi_get_component_action( package
, comp
);
6573 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6575 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6576 return ERROR_SUCCESS
;
6579 desc
= MSI_RecordGetString( rec
, 3 );
6580 if (!SQLRemoveDriverW( desc
, FALSE
, &usage
))
6582 WARN("Failed to remove ODBC driver\n");
6586 FIXME("Usage count reached 0\n");
6589 uirow
= MSI_CreateRecord( 2 );
6590 MSI_RecordSetStringW( uirow
, 1, desc
);
6591 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6592 msi_ui_actiondata( package
, szRemoveODBC
, uirow
);
6593 msiobj_release( &uirow
->hdr
);
6595 return ERROR_SUCCESS
;
6598 static UINT
ITERATE_RemoveODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
6600 MSIPACKAGE
*package
= param
;
6604 LPCWSTR desc
, component
;
6606 component
= MSI_RecordGetString( rec
, 2 );
6607 comp
= msi_get_loaded_component( package
, component
);
6609 return ERROR_SUCCESS
;
6611 comp
->Action
= msi_get_component_action( package
, comp
);
6612 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6614 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6615 return ERROR_SUCCESS
;
6618 desc
= MSI_RecordGetString( rec
, 3 );
6619 if (!SQLRemoveTranslatorW( desc
, &usage
))
6621 WARN("Failed to remove ODBC translator\n");
6625 FIXME("Usage count reached 0\n");
6628 uirow
= MSI_CreateRecord( 2 );
6629 MSI_RecordSetStringW( uirow
, 1, desc
);
6630 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6631 msi_ui_actiondata( package
, szRemoveODBC
, uirow
);
6632 msiobj_release( &uirow
->hdr
);
6634 return ERROR_SUCCESS
;
6637 static UINT
ITERATE_RemoveODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
6639 MSIPACKAGE
*package
= param
;
6643 LPCWSTR desc
, driver
, component
;
6644 WORD request
= ODBC_REMOVE_SYS_DSN
;
6648 static const WCHAR attrs_fmt
[] = {
6649 'D','S','N','=','%','s',0 };
6651 component
= MSI_RecordGetString( rec
, 2 );
6652 comp
= msi_get_loaded_component( package
, component
);
6654 return ERROR_SUCCESS
;
6656 comp
->Action
= msi_get_component_action( package
, comp
);
6657 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6659 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6660 return ERROR_SUCCESS
;
6663 desc
= MSI_RecordGetString( rec
, 3 );
6664 driver
= MSI_RecordGetString( rec
, 4 );
6665 registration
= MSI_RecordGetInteger( rec
, 5 );
6667 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_REMOVE_SYS_DSN
;
6668 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_REMOVE_DSN
;
6670 len
= strlenW( attrs_fmt
) + strlenW( desc
) + 2; /* \0\0 */
6671 attrs
= msi_alloc( len
* sizeof(WCHAR
) );
6673 return ERROR_OUTOFMEMORY
;
6675 FIXME("Use ODBCSourceAttribute table\n");
6677 len
= sprintfW( attrs
, attrs_fmt
, desc
);
6680 if (!SQLConfigDataSourceW( NULL
, request
, driver
, attrs
))
6682 WARN("Failed to remove ODBC data source\n");
6686 uirow
= MSI_CreateRecord( 3 );
6687 MSI_RecordSetStringW( uirow
, 1, desc
);
6688 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6689 MSI_RecordSetInteger( uirow
, 3, request
);
6690 msi_ui_actiondata( package
, szRemoveODBC
, uirow
);
6691 msiobj_release( &uirow
->hdr
);
6693 return ERROR_SUCCESS
;
6696 static UINT
ACTION_RemoveODBC( MSIPACKAGE
*package
)
6698 static const WCHAR driver_query
[] = {
6699 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6700 'O','D','B','C','D','r','i','v','e','r',0};
6701 static const WCHAR translator_query
[] = {
6702 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6703 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0};
6704 static const WCHAR source_query
[] = {
6705 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6706 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0};
6710 rc
= MSI_DatabaseOpenViewW( package
->db
, driver_query
, &view
);
6711 if (rc
== ERROR_SUCCESS
)
6713 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDriver
, package
);
6714 msiobj_release( &view
->hdr
);
6715 if (rc
!= ERROR_SUCCESS
)
6718 rc
= MSI_DatabaseOpenViewW( package
->db
, translator_query
, &view
);
6719 if (rc
== ERROR_SUCCESS
)
6721 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCTranslator
, package
);
6722 msiobj_release( &view
->hdr
);
6723 if (rc
!= ERROR_SUCCESS
)
6726 rc
= MSI_DatabaseOpenViewW( package
->db
, source_query
, &view
);
6727 if (rc
== ERROR_SUCCESS
)
6729 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDataSource
, package
);
6730 msiobj_release( &view
->hdr
);
6731 if (rc
!= ERROR_SUCCESS
)
6734 return ERROR_SUCCESS
;
6737 #define ENV_ACT_SETALWAYS 0x1
6738 #define ENV_ACT_SETABSENT 0x2
6739 #define ENV_ACT_REMOVE 0x4
6740 #define ENV_ACT_REMOVEMATCH 0x8
6742 #define ENV_MOD_MACHINE 0x20000000
6743 #define ENV_MOD_APPEND 0x40000000
6744 #define ENV_MOD_PREFIX 0x80000000
6745 #define ENV_MOD_MASK 0xC0000000
6747 #define check_flag_combo(x, y) ((x) & ~(y)) == (y)
6749 static UINT
env_parse_flags( LPCWSTR
*name
, LPCWSTR
*value
, DWORD
*flags
)
6751 LPCWSTR cptr
= *name
;
6753 static const WCHAR prefix
[] = {'[','~',']',0};
6754 static const int prefix_len
= 3;
6760 *flags
|= ENV_ACT_SETALWAYS
;
6761 else if (*cptr
== '+')
6762 *flags
|= ENV_ACT_SETABSENT
;
6763 else if (*cptr
== '-')
6764 *flags
|= ENV_ACT_REMOVE
;
6765 else if (*cptr
== '!')
6766 *flags
|= ENV_ACT_REMOVEMATCH
;
6767 else if (*cptr
== '*')
6768 *flags
|= ENV_MOD_MACHINE
;
6778 ERR("Missing environment variable\n");
6779 return ERROR_FUNCTION_FAILED
;
6784 LPCWSTR ptr
= *value
;
6785 if (!strncmpW(ptr
, prefix
, prefix_len
))
6787 if (ptr
[prefix_len
] == szSemiColon
[0])
6789 *flags
|= ENV_MOD_APPEND
;
6790 *value
+= lstrlenW(prefix
);
6797 else if (lstrlenW(*value
) >= prefix_len
)
6799 ptr
+= lstrlenW(ptr
) - prefix_len
;
6800 if (!strcmpW( ptr
, prefix
))
6802 if ((ptr
-1) > *value
&& *(ptr
-1) == szSemiColon
[0])
6804 *flags
|= ENV_MOD_PREFIX
;
6805 /* the "[~]" will be removed by deformat_string */;
6815 if (check_flag_combo(*flags
, ENV_ACT_SETALWAYS
| ENV_ACT_SETABSENT
) ||
6816 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETABSENT
) ||
6817 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETALWAYS
) ||
6818 check_flag_combo(*flags
, ENV_ACT_SETABSENT
| ENV_MOD_MASK
))
6820 ERR("Invalid flags: %08x\n", *flags
);
6821 return ERROR_FUNCTION_FAILED
;
6825 *flags
= ENV_ACT_SETALWAYS
| ENV_ACT_REMOVE
;
6827 return ERROR_SUCCESS
;
6830 static UINT
open_env_key( DWORD flags
, HKEY
*key
)
6832 static const WCHAR user_env
[] =
6833 {'E','n','v','i','r','o','n','m','e','n','t',0};
6834 static const WCHAR machine_env
[] =
6835 {'S','y','s','t','e','m','\\',
6836 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
6837 'C','o','n','t','r','o','l','\\',
6838 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
6839 'E','n','v','i','r','o','n','m','e','n','t',0};
6844 if (flags
& ENV_MOD_MACHINE
)
6847 root
= HKEY_LOCAL_MACHINE
;
6852 root
= HKEY_CURRENT_USER
;
6855 res
= RegOpenKeyExW( root
, env
, 0, KEY_ALL_ACCESS
, key
);
6856 if (res
!= ERROR_SUCCESS
)
6858 WARN("Failed to open key %s (%d)\n", debugstr_w(env
), res
);
6859 return ERROR_FUNCTION_FAILED
;
6862 return ERROR_SUCCESS
;
6865 static UINT
ITERATE_WriteEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
6867 MSIPACKAGE
*package
= param
;
6868 LPCWSTR name
, value
, component
;
6869 LPWSTR data
= NULL
, newval
= NULL
, deformatted
= NULL
, ptr
;
6870 DWORD flags
, type
, size
;
6877 component
= MSI_RecordGetString(rec
, 4);
6878 comp
= msi_get_loaded_component(package
, component
);
6880 return ERROR_SUCCESS
;
6882 comp
->Action
= msi_get_component_action( package
, comp
);
6883 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6885 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6886 return ERROR_SUCCESS
;
6888 name
= MSI_RecordGetString(rec
, 2);
6889 value
= MSI_RecordGetString(rec
, 3);
6891 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
6893 res
= env_parse_flags(&name
, &value
, &flags
);
6894 if (res
!= ERROR_SUCCESS
|| !value
)
6897 if (value
&& !deformat_string(package
, value
, &deformatted
))
6899 res
= ERROR_OUTOFMEMORY
;
6903 value
= deformatted
;
6905 res
= open_env_key( flags
, &env
);
6906 if (res
!= ERROR_SUCCESS
)
6909 if (flags
& ENV_MOD_MACHINE
)
6910 action
|= 0x20000000;
6914 res
= RegQueryValueExW(env
, name
, NULL
, &type
, NULL
, &size
);
6915 if ((res
!= ERROR_SUCCESS
&& res
!= ERROR_FILE_NOT_FOUND
) ||
6916 (res
== ERROR_SUCCESS
&& type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
))
6919 if ((res
== ERROR_FILE_NOT_FOUND
|| !(flags
& ENV_MOD_MASK
)))
6923 /* Nothing to do. */
6926 res
= ERROR_SUCCESS
;
6930 /* If we are appending but the string was empty, strip ; */
6931 if ((flags
& ENV_MOD_APPEND
) && (value
[0] == szSemiColon
[0])) value
++;
6933 size
= (lstrlenW(value
) + 1) * sizeof(WCHAR
);
6934 newval
= strdupW(value
);
6937 res
= ERROR_OUTOFMEMORY
;
6945 /* Contrary to MSDN, +-variable to [~];path works */
6946 if (flags
& ENV_ACT_SETABSENT
&& !(flags
& ENV_MOD_MASK
))
6948 res
= ERROR_SUCCESS
;
6952 data
= msi_alloc(size
);
6955 msi_free(deformatted
);
6957 return ERROR_OUTOFMEMORY
;
6960 res
= RegQueryValueExW(env
, name
, NULL
, &type
, (LPVOID
)data
, &size
);
6961 if (res
!= ERROR_SUCCESS
)
6964 if (flags
& ENV_ACT_REMOVEMATCH
&& (!value
|| !strcmpW( data
, value
)))
6967 res
= RegDeleteValueW(env
, name
);
6968 if (res
!= ERROR_SUCCESS
)
6969 WARN("Failed to remove value %s (%d)\n", debugstr_w(name
), res
);
6973 size
= (lstrlenW(data
) + 1) * sizeof(WCHAR
);
6974 if (flags
& ENV_MOD_MASK
)
6978 if (flags
& ENV_MOD_APPEND
) multiplier
++;
6979 if (flags
& ENV_MOD_PREFIX
) multiplier
++;
6980 mod_size
= lstrlenW(value
) * multiplier
;
6981 size
+= mod_size
* sizeof(WCHAR
);
6984 newval
= msi_alloc(size
);
6988 res
= ERROR_OUTOFMEMORY
;
6992 if (flags
& ENV_MOD_PREFIX
)
6994 lstrcpyW(newval
, value
);
6995 ptr
= newval
+ lstrlenW(value
);
6996 action
|= 0x80000000;
6999 lstrcpyW(ptr
, data
);
7001 if (flags
& ENV_MOD_APPEND
)
7003 lstrcatW(newval
, value
);
7004 action
|= 0x40000000;
7007 TRACE("setting %s to %s\n", debugstr_w(name
), debugstr_w(newval
));
7008 res
= RegSetValueExW(env
, name
, 0, type
, (LPVOID
)newval
, size
);
7011 WARN("Failed to set %s to %s (%d)\n", debugstr_w(name
), debugstr_w(newval
), res
);
7015 uirow
= MSI_CreateRecord( 3 );
7016 MSI_RecordSetStringW( uirow
, 1, name
);
7017 MSI_RecordSetStringW( uirow
, 2, newval
);
7018 MSI_RecordSetInteger( uirow
, 3, action
);
7019 msi_ui_actiondata( package
, szWriteEnvironmentStrings
, uirow
);
7020 msiobj_release( &uirow
->hdr
);
7022 if (env
) RegCloseKey(env
);
7023 msi_free(deformatted
);
7029 static UINT
ACTION_WriteEnvironmentStrings( MSIPACKAGE
*package
)
7031 static const WCHAR query
[] = {
7032 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7033 '`','E','n','v','i','r','o','n','m','e','n','t','`',0};
7037 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
7038 if (rc
!= ERROR_SUCCESS
)
7039 return ERROR_SUCCESS
;
7041 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteEnvironmentString
, package
);
7042 msiobj_release(&view
->hdr
);
7046 static UINT
ITERATE_RemoveEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
7048 MSIPACKAGE
*package
= param
;
7049 LPCWSTR name
, value
, component
;
7050 LPWSTR deformatted
= NULL
;
7059 component
= MSI_RecordGetString( rec
, 4 );
7060 comp
= msi_get_loaded_component( package
, component
);
7062 return ERROR_SUCCESS
;
7064 comp
->Action
= msi_get_component_action( package
, comp
);
7065 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
7067 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
7068 return ERROR_SUCCESS
;
7070 name
= MSI_RecordGetString( rec
, 2 );
7071 value
= MSI_RecordGetString( rec
, 3 );
7073 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
7075 r
= env_parse_flags( &name
, &value
, &flags
);
7076 if (r
!= ERROR_SUCCESS
)
7079 if (!(flags
& ENV_ACT_REMOVE
))
7081 TRACE("Environment variable %s not marked for removal\n", debugstr_w(name
));
7082 return ERROR_SUCCESS
;
7085 if (value
&& !deformat_string( package
, value
, &deformatted
))
7086 return ERROR_OUTOFMEMORY
;
7088 value
= deformatted
;
7090 r
= open_env_key( flags
, &env
);
7091 if (r
!= ERROR_SUCCESS
)
7097 if (flags
& ENV_MOD_MACHINE
)
7098 action
|= 0x20000000;
7100 TRACE("Removing %s\n", debugstr_w(name
));
7102 res
= RegDeleteValueW( env
, name
);
7103 if (res
!= ERROR_SUCCESS
)
7105 WARN("Failed to delete value %s (%d)\n", debugstr_w(name
), res
);
7110 uirow
= MSI_CreateRecord( 3 );
7111 MSI_RecordSetStringW( uirow
, 1, name
);
7112 MSI_RecordSetStringW( uirow
, 2, value
);
7113 MSI_RecordSetInteger( uirow
, 3, action
);
7114 msi_ui_actiondata( package
, szRemoveEnvironmentStrings
, uirow
);
7115 msiobj_release( &uirow
->hdr
);
7117 if (env
) RegCloseKey( env
);
7118 msi_free( deformatted
);
7122 static UINT
ACTION_RemoveEnvironmentStrings( MSIPACKAGE
*package
)
7124 static const WCHAR query
[] = {
7125 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7126 '`','E','n','v','i','r','o','n','m','e','n','t','`',0};
7130 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
7131 if (rc
!= ERROR_SUCCESS
)
7132 return ERROR_SUCCESS
;
7134 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveEnvironmentString
, package
);
7135 msiobj_release( &view
->hdr
);
7139 UINT
msi_validate_product_id( MSIPACKAGE
*package
)
7141 LPWSTR key
, template, id
;
7142 UINT r
= ERROR_SUCCESS
;
7144 id
= msi_dup_property( package
->db
, szProductID
);
7148 return ERROR_SUCCESS
;
7150 template = msi_dup_property( package
->db
, szPIDTemplate
);
7151 key
= msi_dup_property( package
->db
, szPIDKEY
);
7152 if (key
&& template)
7154 FIXME( "partial stub: template %s key %s\n", debugstr_w(template), debugstr_w(key
) );
7155 r
= msi_set_property( package
->db
, szProductID
, key
, -1 );
7157 msi_free( template );
7162 static UINT
ACTION_ValidateProductID( MSIPACKAGE
*package
)
7164 return msi_validate_product_id( package
);
7167 static UINT
ACTION_ScheduleReboot( MSIPACKAGE
*package
)
7170 package
->need_reboot_at_end
= 1;
7171 return ERROR_SUCCESS
;
7174 static UINT
ACTION_AllocateRegistrySpace( MSIPACKAGE
*package
)
7176 static const WCHAR szAvailableFreeReg
[] =
7177 {'A','V','A','I','L','A','B','L','E','F','R','E','E','R','E','G',0};
7179 int space
= msi_get_property_int( package
->db
, szAvailableFreeReg
, 0 );
7181 TRACE("%p %d kilobytes\n", package
, space
);
7183 uirow
= MSI_CreateRecord( 1 );
7184 MSI_RecordSetInteger( uirow
, 1, space
);
7185 msi_ui_actiondata( package
, szAllocateRegistrySpace
, uirow
);
7186 msiobj_release( &uirow
->hdr
);
7188 return ERROR_SUCCESS
;
7191 static UINT
ACTION_DisableRollback( MSIPACKAGE
*package
)
7193 TRACE("%p\n", package
);
7195 msi_set_property( package
->db
, szRollbackDisabled
, szOne
, -1 );
7196 return ERROR_SUCCESS
;
7199 static UINT
ACTION_InstallAdminPackage( MSIPACKAGE
*package
)
7201 FIXME("%p\n", package
);
7202 return ERROR_SUCCESS
;
7205 static UINT
ACTION_SetODBCFolders( MSIPACKAGE
*package
)
7207 static const WCHAR driver_query
[] = {
7208 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7209 'O','D','B','C','D','r','i','v','e','r',0};
7210 static const WCHAR translator_query
[] = {
7211 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7212 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0};
7216 r
= MSI_DatabaseOpenViewW( package
->db
, driver_query
, &view
);
7217 if (r
== ERROR_SUCCESS
)
7220 r
= MSI_IterateRecords( view
, &count
, NULL
, package
);
7221 msiobj_release( &view
->hdr
);
7222 if (r
!= ERROR_SUCCESS
)
7224 if (count
) FIXME("ignored %u rows in ODBCDriver table\n", count
);
7226 r
= MSI_DatabaseOpenViewW( package
->db
, translator_query
, &view
);
7227 if (r
== ERROR_SUCCESS
)
7230 r
= MSI_IterateRecords( view
, &count
, NULL
, package
);
7231 msiobj_release( &view
->hdr
);
7232 if (r
!= ERROR_SUCCESS
)
7234 if (count
) FIXME("ignored %u rows in ODBCTranslator table\n", count
);
7236 return ERROR_SUCCESS
;
7239 static UINT
ITERATE_RemoveExistingProducts( MSIRECORD
*rec
, LPVOID param
)
7241 static const WCHAR fmtW
[] =
7242 {'m','s','i','e','x','e','c',' ','/','i',' ','%','s',' ','R','E','M','O','V','E','=','%','s',0};
7243 MSIPACKAGE
*package
= param
;
7244 const WCHAR
*property
= MSI_RecordGetString( rec
, 7 );
7245 int attrs
= MSI_RecordGetInteger( rec
, 5 );
7246 UINT len
= sizeof(fmtW
)/sizeof(fmtW
[0]);
7247 WCHAR
*product
, *features
, *cmd
;
7249 PROCESS_INFORMATION info
;
7252 if (attrs
& msidbUpgradeAttributesOnlyDetect
) return ERROR_SUCCESS
;
7253 if (!(product
= msi_dup_property( package
->db
, property
))) return ERROR_SUCCESS
;
7255 deformat_string( package
, MSI_RecordGetString( rec
, 6 ), &features
);
7257 len
+= strlenW( product
);
7259 len
+= strlenW( features
);
7261 len
+= sizeof(szAll
) / sizeof(szAll
[0]);
7263 if (!(cmd
= msi_alloc( len
* sizeof(WCHAR
) )))
7265 msi_free( product
);
7266 msi_free( features
);
7267 return ERROR_OUTOFMEMORY
;
7269 sprintfW( cmd
, fmtW
, product
, features
? features
: szAll
);
7270 msi_free( product
);
7271 msi_free( features
);
7273 memset( &si
, 0, sizeof(STARTUPINFOW
) );
7274 ret
= CreateProcessW( NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &info
);
7276 if (!ret
) return GetLastError();
7277 CloseHandle( info
.hThread
);
7279 WaitForSingleObject( info
.hProcess
, INFINITE
);
7280 CloseHandle( info
.hProcess
);
7281 return ERROR_SUCCESS
;
7284 static UINT
ACTION_RemoveExistingProducts( MSIPACKAGE
*package
)
7286 static const WCHAR query
[] = {
7287 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','U','p','g','r','a','d','e',0};
7291 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
7292 if (r
== ERROR_SUCCESS
)
7294 r
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveExistingProducts
, package
);
7295 msiobj_release( &view
->hdr
);
7296 if (r
!= ERROR_SUCCESS
)
7299 return ERROR_SUCCESS
;
7302 static UINT
ITERATE_MigrateFeatureStates( MSIRECORD
*rec
, LPVOID param
)
7304 MSIPACKAGE
*package
= param
;
7305 int attributes
= MSI_RecordGetInteger( rec
, 5 );
7307 if (attributes
& msidbUpgradeAttributesMigrateFeatures
)
7309 const WCHAR
*upgrade_code
= MSI_RecordGetString( rec
, 1 );
7310 const WCHAR
*version_min
= MSI_RecordGetString( rec
, 2 );
7311 const WCHAR
*version_max
= MSI_RecordGetString( rec
, 3 );
7312 const WCHAR
*language
= MSI_RecordGetString( rec
, 4 );
7316 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
7318 r
= MSIREG_OpenClassesUpgradeCodesKey( upgrade_code
, &hkey
, FALSE
);
7319 if (r
!= ERROR_SUCCESS
)
7320 return ERROR_SUCCESS
;
7324 r
= MSIREG_OpenUserUpgradeCodesKey( upgrade_code
, &hkey
, FALSE
);
7325 if (r
!= ERROR_SUCCESS
)
7326 return ERROR_SUCCESS
;
7328 RegCloseKey( hkey
);
7330 FIXME("migrate feature states from %s version min %s version max %s language %s\n",
7331 debugstr_w(upgrade_code
), debugstr_w(version_min
),
7332 debugstr_w(version_max
), debugstr_w(language
));
7334 return ERROR_SUCCESS
;
7337 static UINT
ACTION_MigrateFeatureStates( MSIPACKAGE
*package
)
7339 static const WCHAR query
[] = {
7340 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7341 'U','p','g','r','a','d','e',0};
7345 if (msi_get_property_int( package
->db
, szInstalled
, 0 ))
7347 TRACE("product is installed, skipping action\n");
7348 return ERROR_SUCCESS
;
7350 if (msi_get_property_int( package
->db
, szPreselected
, 0 ))
7352 TRACE("Preselected property is set, not migrating feature states\n");
7353 return ERROR_SUCCESS
;
7355 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
7356 if (r
== ERROR_SUCCESS
)
7358 r
= MSI_IterateRecords( view
, NULL
, ITERATE_MigrateFeatureStates
, package
);
7359 msiobj_release( &view
->hdr
);
7360 if (r
!= ERROR_SUCCESS
)
7363 return ERROR_SUCCESS
;
7366 static void bind_image( const char *filename
, const char *path
)
7368 if (!BindImageEx( 0, filename
, path
, NULL
, NULL
))
7370 WARN("failed to bind image %u\n", GetLastError());
7374 static UINT
ITERATE_BindImage( MSIRECORD
*rec
, LPVOID param
)
7378 MSIPACKAGE
*package
= param
;
7379 const WCHAR
*key
= MSI_RecordGetString( rec
, 1 );
7380 const WCHAR
*paths
= MSI_RecordGetString( rec
, 2 );
7381 char *filenameA
, *pathA
;
7382 WCHAR
*pathW
, **path_list
;
7384 if (!(file
= msi_get_loaded_file( package
, key
)))
7386 WARN("file %s not found\n", debugstr_w(key
));
7387 return ERROR_SUCCESS
;
7389 if (!(filenameA
= strdupWtoA( file
->TargetPath
))) return ERROR_SUCCESS
;
7390 path_list
= msi_split_string( paths
, ';' );
7391 if (!path_list
) bind_image( filenameA
, NULL
);
7394 for (i
= 0; path_list
[i
] && path_list
[i
][0]; i
++)
7396 deformat_string( package
, path_list
[i
], &pathW
);
7397 if ((pathA
= strdupWtoA( pathW
)))
7399 bind_image( filenameA
, pathA
);
7405 msi_free( path_list
);
7406 msi_free( filenameA
);
7407 return ERROR_SUCCESS
;
7410 static UINT
ACTION_BindImage( MSIPACKAGE
*package
)
7412 static const WCHAR query
[] = {
7413 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7414 'B','i','n','d','I','m','a','g','e',0};
7418 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
7419 if (r
== ERROR_SUCCESS
)
7421 r
= MSI_IterateRecords( view
, NULL
, ITERATE_BindImage
, package
);
7422 msiobj_release( &view
->hdr
);
7423 if (r
!= ERROR_SUCCESS
)
7426 return ERROR_SUCCESS
;
7429 static UINT
msi_unimplemented_action_stub( MSIPACKAGE
*package
, LPCSTR action
, LPCWSTR table
)
7431 static const WCHAR query
[] = {
7432 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','%','s','`',0};
7437 r
= MSI_OpenQuery( package
->db
, &view
, query
, table
);
7438 if (r
== ERROR_SUCCESS
)
7440 r
= MSI_IterateRecords(view
, &count
, NULL
, package
);
7441 msiobj_release(&view
->hdr
);
7442 if (r
!= ERROR_SUCCESS
)
7445 if (count
) FIXME("%s: ignored %u rows from %s\n", action
, count
, debugstr_w(table
));
7446 return ERROR_SUCCESS
;
7449 static UINT
ACTION_IsolateComponents( MSIPACKAGE
*package
)
7451 static const WCHAR table
[] = {
7452 'I','s','o','l','a','t','e','d','C','o','m','p','o','n','e','n','t',0 };
7453 return msi_unimplemented_action_stub( package
, "IsolateComponents", table
);
7456 static UINT
ACTION_RMCCPSearch( MSIPACKAGE
*package
)
7458 static const WCHAR table
[] = { 'C','C','P','S','e','a','r','c','h',0 };
7459 return msi_unimplemented_action_stub( package
, "RMCCPSearch", table
);
7462 static UINT
ACTION_RegisterComPlus( MSIPACKAGE
*package
)
7464 static const WCHAR table
[] = { 'C','o','m','p','l','u','s',0 };
7465 return msi_unimplemented_action_stub( package
, "RegisterComPlus", table
);
7468 static UINT
ACTION_UnregisterComPlus( MSIPACKAGE
*package
)
7470 static const WCHAR table
[] = { 'C','o','m','p','l','u','s',0 };
7471 return msi_unimplemented_action_stub( package
, "UnregisterComPlus", table
);
7474 static UINT
ACTION_InstallSFPCatalogFile( MSIPACKAGE
*package
)
7476 static const WCHAR table
[] = { 'S','F','P','C','a','t','a','l','o','g',0 };
7477 return msi_unimplemented_action_stub( package
, "InstallSFPCatalogFile", table
);
7482 const WCHAR
*action
;
7483 UINT (*handler
)(MSIPACKAGE
*);
7484 const WCHAR
*action_rollback
;
7488 { szAllocateRegistrySpace
, ACTION_AllocateRegistrySpace
, NULL
},
7489 { szAppSearch
, ACTION_AppSearch
, NULL
},
7490 { szBindImage
, ACTION_BindImage
, NULL
},
7491 { szCCPSearch
, ACTION_CCPSearch
, NULL
},
7492 { szCostFinalize
, ACTION_CostFinalize
, NULL
},
7493 { szCostInitialize
, ACTION_CostInitialize
, NULL
},
7494 { szCreateFolders
, ACTION_CreateFolders
, szRemoveFolders
},
7495 { szCreateShortcuts
, ACTION_CreateShortcuts
, szRemoveShortcuts
},
7496 { szDeleteServices
, ACTION_DeleteServices
, szInstallServices
},
7497 { szDisableRollback
, ACTION_DisableRollback
, NULL
},
7498 { szDuplicateFiles
, ACTION_DuplicateFiles
, szRemoveDuplicateFiles
},
7499 { szExecuteAction
, ACTION_ExecuteAction
, NULL
},
7500 { szFileCost
, ACTION_FileCost
, NULL
},
7501 { szFindRelatedProducts
, ACTION_FindRelatedProducts
, NULL
},
7502 { szForceReboot
, ACTION_ForceReboot
, NULL
},
7503 { szInstallAdminPackage
, ACTION_InstallAdminPackage
, NULL
},
7504 { szInstallExecute
, ACTION_InstallExecute
, NULL
},
7505 { szInstallExecuteAgain
, ACTION_InstallExecute
, NULL
},
7506 { szInstallFiles
, ACTION_InstallFiles
, szRemoveFiles
},
7507 { szInstallFinalize
, ACTION_InstallFinalize
, NULL
},
7508 { szInstallInitialize
, ACTION_InstallInitialize
, NULL
},
7509 { szInstallODBC
, ACTION_InstallODBC
, szRemoveODBC
},
7510 { szInstallServices
, ACTION_InstallServices
, szDeleteServices
},
7511 { szInstallSFPCatalogFile
, ACTION_InstallSFPCatalogFile
, NULL
},
7512 { szInstallValidate
, ACTION_InstallValidate
, NULL
},
7513 { szIsolateComponents
, ACTION_IsolateComponents
, NULL
},
7514 { szLaunchConditions
, ACTION_LaunchConditions
, NULL
},
7515 { szMigrateFeatureStates
, ACTION_MigrateFeatureStates
, NULL
},
7516 { szMoveFiles
, ACTION_MoveFiles
, NULL
},
7517 { szMsiPublishAssemblies
, ACTION_MsiPublishAssemblies
, szMsiUnpublishAssemblies
},
7518 { szMsiUnpublishAssemblies
, ACTION_MsiUnpublishAssemblies
, szMsiPublishAssemblies
},
7519 { szPatchFiles
, ACTION_PatchFiles
, NULL
},
7520 { szProcessComponents
, ACTION_ProcessComponents
, szProcessComponents
},
7521 { szPublishComponents
, ACTION_PublishComponents
, szUnpublishComponents
},
7522 { szPublishFeatures
, ACTION_PublishFeatures
, szUnpublishFeatures
},
7523 { szPublishProduct
, ACTION_PublishProduct
, NULL
},
7524 { szRegisterClassInfo
, ACTION_RegisterClassInfo
, szUnregisterClassInfo
},
7525 { szRegisterComPlus
, ACTION_RegisterComPlus
, szUnregisterComPlus
},
7526 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
, szUnregisterExtensionInfo
},
7527 { szRegisterFonts
, ACTION_RegisterFonts
, szUnregisterFonts
},
7528 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
, szUnregisterMIMEInfo
},
7529 { szRegisterProduct
, ACTION_RegisterProduct
, NULL
},
7530 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
, szUnregisterProgIdInfo
},
7531 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
, szUnregisterTypeLibraries
},
7532 { szRegisterUser
, ACTION_RegisterUser
, NULL
},
7533 { szRemoveDuplicateFiles
, ACTION_RemoveDuplicateFiles
, szDuplicateFiles
},
7534 { szRemoveEnvironmentStrings
, ACTION_RemoveEnvironmentStrings
, szWriteEnvironmentStrings
},
7535 { szRemoveExistingProducts
, ACTION_RemoveExistingProducts
, NULL
},
7536 { szRemoveFiles
, ACTION_RemoveFiles
, szInstallFiles
},
7537 { szRemoveFolders
, ACTION_RemoveFolders
, szCreateFolders
},
7538 { szRemoveIniValues
, ACTION_RemoveIniValues
, szWriteIniValues
},
7539 { szRemoveODBC
, ACTION_RemoveODBC
, szInstallODBC
},
7540 { szRemoveRegistryValues
, ACTION_RemoveRegistryValues
, szWriteRegistryValues
},
7541 { szRemoveShortcuts
, ACTION_RemoveShortcuts
, szCreateShortcuts
},
7542 { szResolveSource
, ACTION_ResolveSource
, NULL
},
7543 { szRMCCPSearch
, ACTION_RMCCPSearch
, NULL
},
7544 { szScheduleReboot
, ACTION_ScheduleReboot
, NULL
},
7545 { szSelfRegModules
, ACTION_SelfRegModules
, szSelfUnregModules
},
7546 { szSelfUnregModules
, ACTION_SelfUnregModules
, szSelfRegModules
},
7547 { szSetODBCFolders
, ACTION_SetODBCFolders
, NULL
},
7548 { szStartServices
, ACTION_StartServices
, szStopServices
},
7549 { szStopServices
, ACTION_StopServices
, szStartServices
},
7550 { szUnpublishComponents
, ACTION_UnpublishComponents
, szPublishComponents
},
7551 { szUnpublishFeatures
, ACTION_UnpublishFeatures
, szPublishFeatures
},
7552 { szUnregisterClassInfo
, ACTION_UnregisterClassInfo
, szRegisterClassInfo
},
7553 { szUnregisterComPlus
, ACTION_UnregisterComPlus
, szRegisterComPlus
},
7554 { szUnregisterExtensionInfo
, ACTION_UnregisterExtensionInfo
, szRegisterExtensionInfo
},
7555 { szUnregisterFonts
, ACTION_UnregisterFonts
, szRegisterFonts
},
7556 { szUnregisterMIMEInfo
, ACTION_UnregisterMIMEInfo
, szRegisterMIMEInfo
},
7557 { szUnregisterProgIdInfo
, ACTION_UnregisterProgIdInfo
, szRegisterProgIdInfo
},
7558 { szUnregisterTypeLibraries
, ACTION_UnregisterTypeLibraries
, szRegisterTypeLibraries
},
7559 { szValidateProductID
, ACTION_ValidateProductID
, NULL
},
7560 { szWriteEnvironmentStrings
, ACTION_WriteEnvironmentStrings
, szRemoveEnvironmentStrings
},
7561 { szWriteIniValues
, ACTION_WriteIniValues
, szRemoveIniValues
},
7562 { szWriteRegistryValues
, ACTION_WriteRegistryValues
, szRemoveRegistryValues
},
7563 { NULL
, NULL
, NULL
}
7566 static BOOL
ACTION_HandleStandardAction( MSIPACKAGE
*package
, LPCWSTR action
, UINT
*rc
)
7572 while (StandardActions
[i
].action
!= NULL
)
7574 if (!strcmpW( StandardActions
[i
].action
, action
))
7576 ui_actionstart( package
, action
);
7577 if (StandardActions
[i
].handler
)
7579 ui_actioninfo( package
, action
, TRUE
, 0 );
7580 *rc
= StandardActions
[i
].handler( package
);
7581 ui_actioninfo( package
, action
, FALSE
, *rc
);
7583 if (StandardActions
[i
].action_rollback
&& !package
->need_rollback
)
7585 TRACE("scheduling rollback action\n");
7586 msi_schedule_action( package
, SCRIPT_ROLLBACK
, StandardActions
[i
].action_rollback
);
7591 FIXME("unhandled standard action %s\n", debugstr_w(action
));
7592 *rc
= ERROR_SUCCESS
;
7602 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, UINT script
)
7604 UINT rc
= ERROR_SUCCESS
;
7607 TRACE("Performing action (%s)\n", debugstr_w(action
));
7609 handled
= ACTION_HandleStandardAction(package
, action
, &rc
);
7612 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, script
);
7616 WARN("unhandled msi action %s\n", debugstr_w(action
));
7617 rc
= ERROR_FUNCTION_NOT_CALLED
;
7623 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
, UINT script
)
7625 UINT rc
= ERROR_SUCCESS
;
7626 BOOL handled
= FALSE
;
7628 TRACE("Performing action (%s)\n", debugstr_w(action
));
7630 package
->action_progress_increment
= 0;
7631 handled
= ACTION_HandleStandardAction(package
, action
, &rc
);
7634 handled
= ACTION_HandleCustomAction(package
, action
, &rc
, script
);
7636 if( !handled
&& ACTION_DialogBox(package
, action
) == ERROR_SUCCESS
)
7641 WARN("unhandled msi action %s\n", debugstr_w(action
));
7642 rc
= ERROR_FUNCTION_NOT_CALLED
;
7648 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
)
7650 UINT rc
= ERROR_SUCCESS
;
7653 static const WCHAR query
[] =
7654 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7655 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
7656 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
7657 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
7658 static const WCHAR ui_query
[] =
7659 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7660 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
7661 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
7662 ' ', '=',' ','%','i',0};
7664 if (needs_ui_sequence(package
))
7665 row
= MSI_QueryGetRecord(package
->db
, ui_query
, seq
);
7667 row
= MSI_QueryGetRecord(package
->db
, query
, seq
);
7671 LPCWSTR action
, cond
;
7673 TRACE("Running the actions\n");
7675 /* check conditions */
7676 cond
= MSI_RecordGetString(row
, 2);
7678 /* this is a hack to skip errors in the condition code */
7679 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
7681 msiobj_release(&row
->hdr
);
7682 return ERROR_SUCCESS
;
7685 action
= MSI_RecordGetString(row
, 1);
7688 ERR("failed to fetch action\n");
7689 msiobj_release(&row
->hdr
);
7690 return ERROR_FUNCTION_FAILED
;
7693 if (needs_ui_sequence(package
))
7694 rc
= ACTION_PerformUIAction(package
, action
, SCRIPT_NONE
);
7696 rc
= ACTION_PerformAction(package
, action
, SCRIPT_NONE
);
7698 msiobj_release(&row
->hdr
);
7704 /****************************************************
7705 * TOP level entry points
7706 *****************************************************/
7708 UINT
MSI_InstallPackage( MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
7709 LPCWSTR szCommandLine
)
7711 static const WCHAR szDisableRollback
[] = {'D','I','S','A','B','L','E','R','O','L','L','B','A','C','K',0};
7712 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
7713 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
7714 WCHAR
*reinstall
, *remove
, *patch
, *productcode
;
7718 msi_set_property( package
->db
, szAction
, szInstall
, -1 );
7720 package
->script
->InWhatSequence
= SEQUENCE_INSTALL
;
7727 dir
= strdupW(szPackagePath
);
7728 p
= strrchrW(dir
, '\\');
7732 file
= szPackagePath
+ (p
- dir
);
7737 dir
= msi_alloc(MAX_PATH
* sizeof(WCHAR
));
7738 GetCurrentDirectoryW(MAX_PATH
, dir
);
7739 lstrcatW(dir
, szBackSlash
);
7740 file
= szPackagePath
;
7743 msi_free( package
->PackagePath
);
7744 package
->PackagePath
= msi_alloc((lstrlenW(dir
) + lstrlenW(file
) + 1) * sizeof(WCHAR
));
7745 if (!package
->PackagePath
)
7748 return ERROR_OUTOFMEMORY
;
7751 lstrcpyW(package
->PackagePath
, dir
);
7752 lstrcatW(package
->PackagePath
, file
);
7755 msi_set_sourcedir_props(package
, FALSE
);
7758 rc
= msi_parse_command_line( package
, szCommandLine
, FALSE
);
7759 if (rc
!= ERROR_SUCCESS
)
7762 msi_apply_transforms( package
);
7763 msi_apply_patches( package
);
7765 patch
= msi_dup_property( package
->db
, szPatch
);
7766 remove
= msi_dup_property( package
->db
, szRemove
);
7767 reinstall
= msi_dup_property( package
->db
, szReinstall
);
7768 if (msi_get_property_int( package
->db
, szInstalled
, 0 ) && !remove
&& !reinstall
&& !patch
)
7770 TRACE("setting REINSTALL property to ALL\n");
7771 msi_set_property( package
->db
, szReinstall
, szAll
, -1 );
7772 package
->full_reinstall
= 1;
7775 msi_set_original_database_property( package
->db
, szPackagePath
);
7776 msi_parse_command_line( package
, szCommandLine
, FALSE
);
7777 msi_adjust_privilege_properties( package
);
7778 msi_set_context( package
);
7780 productcode
= msi_dup_property( package
->db
, szProductCode
);
7781 if (strcmpiW( productcode
, package
->ProductCode
))
7783 TRACE( "product code changed %s -> %s\n", debugstr_w(package
->ProductCode
), debugstr_w(productcode
) );
7784 msi_free( package
->ProductCode
);
7785 package
->ProductCode
= productcode
;
7787 else msi_free( productcode
);
7789 if (msi_get_property_int( package
->db
, szDisableRollback
, 0 ))
7791 TRACE("disabling rollback\n");
7792 msi_set_property( package
->db
, szRollbackDisabled
, szOne
, -1 );
7795 if (needs_ui_sequence( package
))
7797 package
->script
->InWhatSequence
|= SEQUENCE_UI
;
7798 rc
= ACTION_ProcessUISequence(package
);
7799 ui_exists
= ui_sequence_exists(package
);
7800 if (rc
== ERROR_SUCCESS
|| !ui_exists
)
7802 package
->script
->InWhatSequence
|= SEQUENCE_EXEC
;
7803 rc
= ACTION_ProcessExecSequence(package
, ui_exists
);
7807 rc
= ACTION_ProcessExecSequence(package
, FALSE
);
7809 /* process the ending type action */
7810 if (rc
== ERROR_SUCCESS
)
7811 ACTION_PerformActionSequence(package
, -1);
7812 else if (rc
== ERROR_INSTALL_USEREXIT
)
7813 ACTION_PerformActionSequence(package
, -2);
7814 else if (rc
== ERROR_INSTALL_SUSPEND
)
7815 ACTION_PerformActionSequence(package
, -4);
7818 ACTION_PerformActionSequence(package
, -3);
7819 if (!msi_get_property_int( package
->db
, szRollbackDisabled
, 0 ))
7821 package
->need_rollback
= TRUE
;
7825 /* finish up running custom actions */
7826 ACTION_FinishCustomActions(package
);
7828 if (package
->need_rollback
&& !reinstall
)
7830 WARN("installation failed, running rollback script\n");
7831 execute_script( package
, SCRIPT_ROLLBACK
);
7833 msi_free( reinstall
);
7837 if (rc
== ERROR_SUCCESS
&& package
->need_reboot_at_end
)
7838 return ERROR_SUCCESS_REBOOT_REQUIRED
;