2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004,2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
39 #include "wine/unicode.h"
45 #define REG_PROGRESS_VALUE 13200
46 #define COMPONENT_PROGRESS_VALUE 24000
48 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
50 static const WCHAR szCreateFolders
[] =
51 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
52 static const WCHAR szCostFinalize
[] =
53 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
54 static const WCHAR szWriteRegistryValues
[] =
55 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
56 static const WCHAR szFileCost
[] =
57 {'F','i','l','e','C','o','s','t',0};
58 static const WCHAR szInstallInitialize
[] =
59 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
60 static const WCHAR szInstallValidate
[] =
61 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
62 static const WCHAR szLaunchConditions
[] =
63 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
64 static const WCHAR szProcessComponents
[] =
65 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
66 static const WCHAR szRegisterTypeLibraries
[] =
67 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r','i','e','s',0};
68 static const WCHAR szCreateShortcuts
[] =
69 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
70 static const WCHAR szPublishProduct
[] =
71 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
72 static const WCHAR szWriteIniValues
[] =
73 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
74 static const WCHAR szSelfRegModules
[] =
75 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
76 static const WCHAR szPublishFeatures
[] =
77 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
78 static const WCHAR szRegisterProduct
[] =
79 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
80 static const WCHAR szInstallExecute
[] =
81 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
82 static const WCHAR szInstallExecuteAgain
[] =
83 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e','A','g','a','i','n',0};
84 static const WCHAR szInstallFinalize
[] =
85 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
86 static const WCHAR szForceReboot
[] =
87 {'F','o','r','c','e','R','e','b','o','o','t',0};
88 static const WCHAR szResolveSource
[] =
89 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
90 static const WCHAR szAllocateRegistrySpace
[] =
91 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y','S','p','a','c','e',0};
92 static const WCHAR szBindImage
[] =
93 {'B','i','n','d','I','m','a','g','e',0};
94 static const WCHAR szDeleteServices
[] =
95 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
96 static const WCHAR szDisableRollback
[] =
97 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
98 static const WCHAR szExecuteAction
[] =
99 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
100 static const WCHAR szInstallAdminPackage
[] =
101 {'I','n','s','t','a','l','l','A','d','m','i','n','P','a','c','k','a','g','e',0};
102 static const WCHAR szInstallSFPCatalogFile
[] =
103 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g','F','i','l','e',0};
104 static const WCHAR szIsolateComponents
[] =
105 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
106 static const WCHAR szMigrateFeatureStates
[] =
107 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e','S','t','a','t','e','s',0};
108 static const WCHAR szMsiUnpublishAssemblies
[] =
109 {'M','s','i','U','n','p','u','b','l','i','s','h','A','s','s','e','m','b','l','i','e','s',0};
110 static const WCHAR szInstallODBC
[] =
111 {'I','n','s','t','a','l','l','O','D','B','C',0};
112 static const WCHAR szInstallServices
[] =
113 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
114 static const WCHAR szPublishComponents
[] =
115 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
116 static const WCHAR szRegisterComPlus
[] =
117 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
118 static const WCHAR szRegisterUser
[] =
119 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
120 static const WCHAR szRemoveEnvironmentStrings
[] =
121 {'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};
122 static const WCHAR szRemoveExistingProducts
[] =
123 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g','P','r','o','d','u','c','t','s',0};
124 static const WCHAR szRemoveFolders
[] =
125 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
126 static const WCHAR szRemoveIniValues
[] =
127 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
128 static const WCHAR szRemoveODBC
[] =
129 {'R','e','m','o','v','e','O','D','B','C',0};
130 static const WCHAR szRemoveRegistryValues
[] =
131 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
132 static const WCHAR szRemoveShortcuts
[] =
133 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
134 static const WCHAR szRMCCPSearch
[] =
135 {'R','M','C','C','P','S','e','a','r','c','h',0};
136 static const WCHAR szScheduleReboot
[] =
137 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
138 static const WCHAR szSelfUnregModules
[] =
139 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
140 static const WCHAR szSetODBCFolders
[] =
141 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
142 static const WCHAR szStartServices
[] =
143 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
144 static const WCHAR szStopServices
[] =
145 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
146 static const WCHAR szUnpublishComponents
[] =
147 {'U','n','p','u','b','l','i','s','h', 'C','o','m','p','o','n','e','n','t','s',0};
148 static const WCHAR szUnpublishFeatures
[] =
149 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
150 static const WCHAR szUnpublishProduct
[] =
151 {'U','n','p','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
152 static const WCHAR szUnregisterComPlus
[] =
153 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
154 static const WCHAR szUnregisterTypeLibraries
[] =
155 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r','i','e','s',0};
156 static const WCHAR szValidateProductID
[] =
157 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
158 static const WCHAR szWriteEnvironmentStrings
[] =
159 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t','S','t','r','i','n','g','s',0};
160 static const WCHAR szINSTALL
[] =
161 {'I','N','S','T','A','L','L',0};
170 static INT
ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
, LPCWSTR description
, LPCWSTR
template)
172 WCHAR query
[] = {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
173 '`','A','c','t','i','o','n','T','e','x','t','`',' ','W','H','E','R','E',' ',
174 '`','A','c','t','i','o','n','`',' ','=',' ','\'','%','s','\'',0};
175 MSIRECORD
*row
, *textrow
;
178 textrow
= MSI_QueryGetRecord(package
->db
, query
, action
);
181 description
= MSI_RecordGetString(textrow
, 2);
182 template = MSI_RecordGetString(textrow
, 3);
185 row
= MSI_CreateRecord(3);
187 MSI_RecordSetStringW(row
, 1, action
);
188 MSI_RecordSetStringW(row
, 2, description
);
189 MSI_RecordSetStringW(row
, 3, template);
190 rc
= MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
191 if (textrow
) msiobj_release(&textrow
->hdr
);
192 msiobj_release(&row
->hdr
);
196 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
202 template = msi_get_error_message(package
->db
, start
? MSIERR_INFO_ACTIONSTART
: MSIERR_INFO_ACTIONENDED
);
204 row
= MSI_CreateRecord(2);
210 MSI_RecordSetStringW(row
, 0, template);
211 MSI_RecordSetStringW(row
, 1, action
);
212 MSI_RecordSetInteger(row
, 2, start
? package
->LastActionResult
: rc
);
213 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
214 msiobj_release(&row
->hdr
);
216 if (!start
) package
->LastActionResult
= rc
;
226 static int parse_prop( const WCHAR
*str
, WCHAR
*value
, int *quotes
)
228 enum parse_state state
= state_quote
;
231 BOOL ignore
, in_quotes
= FALSE
;
232 int count
= 0, len
= 0;
234 for (p
= str
; *p
; p
++)
239 case state_whitespace
:
249 if (in_quotes
&& p
[1] != '\"') count
--;
265 if (in_quotes
) count
--;
269 state
= state_whitespace
;
270 if (!count
) goto done
;
275 if (count
) in_quotes
= TRUE
;
285 if (in_quotes
&& p
[1] != '\"') count
--;
289 state
= state_whitespace
;
290 if (!count
|| (count
> 1 && !len
)) goto done
;
296 if (count
) in_quotes
= TRUE
;
304 if (!ignore
) *out
++ = *p
;
305 if (!count
) in_quotes
= FALSE
;
309 if (!len
) *value
= 0;
316 static void remove_quotes( WCHAR
*str
)
319 int len
= strlenW( str
);
321 while ((p
= strchrW( p
, '"' )))
323 memmove( p
, p
+ 1, (len
- (p
- str
)) * sizeof(WCHAR
) );
328 UINT
msi_parse_command_line( MSIPACKAGE
*package
, LPCWSTR szCommandLine
,
338 return ERROR_SUCCESS
;
343 while (*ptr
== ' ') ptr
++;
346 ptr2
= strchrW( ptr
, '=' );
347 if (!ptr2
) return ERROR_INVALID_COMMAND_LINE
;
350 if (!len
) return ERROR_INVALID_COMMAND_LINE
;
352 while (ptr
[len
- 1] == ' ') len
--;
354 prop
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
355 memcpy( prop
, ptr
, len
* sizeof(WCHAR
) );
357 if (!preserve_case
) struprW( prop
);
360 while (*ptr2
== ' ') ptr2
++;
363 val
= msi_alloc( (strlenW( ptr2
) + 1) * sizeof(WCHAR
) );
364 len
= parse_prop( ptr2
, val
, &num_quotes
);
367 WARN("unbalanced quotes\n");
370 return ERROR_INVALID_COMMAND_LINE
;
372 remove_quotes( val
);
373 TRACE("Found commandline property %s = %s\n", debugstr_w(prop
), debugstr_w(val
));
375 r
= msi_set_property( package
->db
, prop
, val
, -1 );
376 if (r
== ERROR_SUCCESS
&& !strcmpW( prop
, szSourceDir
))
377 msi_reset_folders( package
, TRUE
);
385 return ERROR_SUCCESS
;
388 WCHAR
**msi_split_string( const WCHAR
*str
, WCHAR sep
)
391 LPWSTR p
, *ret
= NULL
;
397 /* count the number of substrings */
398 for ( pc
= str
, count
= 0; pc
; count
++ )
400 pc
= strchrW( pc
, sep
);
405 /* allocate space for an array of substring pointers and the substrings */
406 ret
= msi_alloc( (count
+1) * sizeof (LPWSTR
) +
407 (lstrlenW(str
)+1) * sizeof(WCHAR
) );
411 /* copy the string and set the pointers */
412 p
= (LPWSTR
) &ret
[count
+1];
414 for( count
= 0; (ret
[count
] = p
); count
++ )
416 p
= strchrW( p
, sep
);
424 static BOOL
ui_sequence_exists( MSIPACKAGE
*package
)
426 static const WCHAR query
[] = {
427 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
428 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e','`',' ',
429 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',' ','>',' ','0',0};
433 if (!(MSI_DatabaseOpenViewW( package
->db
, query
, &view
)))
435 MSI_IterateRecords( view
, &count
, NULL
, package
);
436 msiobj_release( &view
->hdr
);
441 UINT
msi_set_sourcedir_props(MSIPACKAGE
*package
, BOOL replace
)
443 WCHAR
*source
, *check
, *p
, *db
;
446 if (!(db
= msi_dup_property( package
->db
, szOriginalDatabase
)))
447 return ERROR_OUTOFMEMORY
;
449 if (!(p
= strrchrW( db
, '\\' )) && !(p
= strrchrW( db
, '/' )))
452 return ERROR_SUCCESS
;
455 source
= msi_alloc( len
* sizeof(WCHAR
) );
456 lstrcpynW( source
, db
, len
);
459 check
= msi_dup_property( package
->db
, szSourceDir
);
460 if (!check
|| replace
)
462 UINT r
= msi_set_property( package
->db
, szSourceDir
, source
, -1 );
463 if (r
== ERROR_SUCCESS
)
464 msi_reset_folders( package
, TRUE
);
468 check
= msi_dup_property( package
->db
, szSOURCEDIR
);
469 if (!check
|| replace
)
470 msi_set_property( package
->db
, szSOURCEDIR
, source
, -1 );
475 return ERROR_SUCCESS
;
478 static BOOL
needs_ui_sequence(MSIPACKAGE
*package
)
480 return (package
->ui_level
& INSTALLUILEVEL_MASK
) >= INSTALLUILEVEL_REDUCED
;
483 UINT
msi_set_context(MSIPACKAGE
*package
)
485 UINT r
= msi_locate_product( package
->ProductCode
, &package
->Context
);
486 if (r
!= ERROR_SUCCESS
)
488 int num
= msi_get_property_int( package
->db
, szAllUsers
, 0 );
489 if (num
== 1 || num
== 2)
490 package
->Context
= MSIINSTALLCONTEXT_MACHINE
;
492 package
->Context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
494 return ERROR_SUCCESS
;
497 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
500 LPCWSTR cond
, action
;
501 MSIPACKAGE
*package
= param
;
503 action
= MSI_RecordGetString(row
,1);
506 ERR("Error is retrieving action name\n");
507 return ERROR_FUNCTION_FAILED
;
510 /* check conditions */
511 cond
= MSI_RecordGetString(row
,2);
513 /* this is a hack to skip errors in the condition code */
514 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
516 TRACE("Skipping action: %s (condition is false)\n", debugstr_w(action
));
517 return ERROR_SUCCESS
;
520 rc
= ACTION_PerformAction(package
, action
, SCRIPT_NONE
);
522 msi_dialog_check_messages( NULL
);
524 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
527 if (rc
!= ERROR_SUCCESS
)
528 ERR("Execution halted, action %s returned %i\n", debugstr_w(action
), rc
);
530 if (package
->need_reboot_now
)
532 TRACE("action %s asked for immediate reboot, suspending installation\n",
534 rc
= ACTION_ForceReboot( package
);
539 UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR table
)
541 static const WCHAR query
[] = {
542 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','%','s','`',
543 ' ','W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',' ',
544 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
545 '`','S','e','q','u','e','n','c','e','`',0};
549 TRACE("%p %s\n", package
, debugstr_w(table
));
551 r
= MSI_OpenQuery( package
->db
, &view
, query
, table
);
552 if (r
== ERROR_SUCCESS
)
554 r
= MSI_IterateRecords( view
, NULL
, ITERATE_Actions
, package
);
555 msiobj_release(&view
->hdr
);
560 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
)
562 static const WCHAR query
[] = {
563 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
564 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
565 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
566 '`','S','e','q','u','e','n','c','e','`',' ', '>',' ','0',' ',
567 'O','R','D','E','R',' ', 'B','Y',' ','`','S','e','q','u','e','n','c','e','`',0};
571 if (package
->ExecuteSequenceRun
)
573 TRACE("Execute Sequence already Run\n");
574 return ERROR_SUCCESS
;
577 package
->ExecuteSequenceRun
= TRUE
;
579 rc
= MSI_OpenQuery(package
->db
, &view
, query
);
580 if (rc
== ERROR_SUCCESS
)
582 TRACE("Running the actions\n");
584 msi_set_property( package
->db
, szSourceDir
, NULL
, -1 );
585 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
586 msiobj_release(&view
->hdr
);
591 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
593 static const WCHAR query
[] = {
594 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
595 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e','`',' ',
596 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',' ','>',' ','0',' ',
597 'O','R','D','E','R',' ','B','Y',' ','`','S','e','q','u','e','n','c','e','`',0};
601 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
602 if (rc
== ERROR_SUCCESS
)
604 TRACE("Running the actions\n");
605 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
606 msiobj_release(&view
->hdr
);
611 /********************************************************
612 * ACTION helper functions and functions that perform the actions
613 *******************************************************/
614 static UINT
ACTION_HandleCustomAction(MSIPACKAGE
*package
, LPCWSTR action
, UINT script
)
619 uirc
= ui_actionstart(package
, action
, NULL
, NULL
);
620 if (uirc
== IDCANCEL
)
621 return ERROR_INSTALL_USEREXIT
;
622 ui_actioninfo(package
, action
, TRUE
, 0);
623 arc
= ACTION_CustomAction( package
, action
, script
);
626 if (arc
== ERROR_FUNCTION_NOT_CALLED
&& needs_ui_sequence(package
))
628 uirc
= ACTION_ShowDialog(package
, action
);
632 return ERROR_SUCCESS
; /* stop immediately */
633 case 0: arc
= ERROR_FUNCTION_NOT_CALLED
; break;
634 case 1: arc
= ERROR_SUCCESS
; break;
635 case 2: arc
= ERROR_INSTALL_USEREXIT
; break;
636 case 3: arc
= ERROR_INSTALL_FAILURE
; break;
637 case 4: arc
= ERROR_INSTALL_SUSPEND
; break;
638 case 5: arc
= ERROR_MORE_DATA
; break;
639 case 6: arc
= ERROR_INVALID_HANDLE_STATE
; break;
640 case 7: arc
= ERROR_INVALID_DATA
; break;
641 case 8: arc
= ERROR_INSTALL_ALREADY_RUNNING
; break;
642 case 9: arc
= ERROR_INSTALL_PACKAGE_REJECTED
; break;
643 default: arc
= ERROR_FUNCTION_FAILED
; break;
647 ui_actioninfo(package
, action
, FALSE
, uirc
);
652 MSICOMPONENT
*msi_get_loaded_component( MSIPACKAGE
*package
, const WCHAR
*Component
)
656 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
658 if (!strcmpW( Component
, comp
->Component
)) return comp
;
663 MSIFEATURE
*msi_get_loaded_feature(MSIPACKAGE
* package
, const WCHAR
*Feature
)
667 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
669 if (!strcmpW( Feature
, feature
->Feature
)) return feature
;
674 MSIFILE
*msi_get_loaded_file( MSIPACKAGE
*package
, const WCHAR
*key
)
678 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
680 if (!strcmpW( key
, file
->File
)) return file
;
685 MSIFOLDER
*msi_get_loaded_folder( MSIPACKAGE
*package
, const WCHAR
*dir
)
689 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
691 if (!strcmpW( dir
, folder
->Directory
)) return folder
;
697 * Recursively create all directories in the path.
698 * shamelessly stolen from setupapi/queue.c
700 BOOL
msi_create_full_path( const WCHAR
*path
)
706 new_path
= msi_alloc( (strlenW( path
) + 1) * sizeof(WCHAR
) );
707 strcpyW( new_path
, path
);
709 while ((len
= strlenW( new_path
)) && new_path
[len
- 1] == '\\')
710 new_path
[len
- 1] = 0;
712 while (!CreateDirectoryW( new_path
, NULL
))
715 DWORD last_error
= GetLastError();
716 if (last_error
== ERROR_ALREADY_EXISTS
) break;
717 if (last_error
!= ERROR_PATH_NOT_FOUND
)
722 if (!(slash
= strrchrW( new_path
, '\\' )))
727 len
= slash
- new_path
;
729 if (!msi_create_full_path( new_path
))
734 new_path
[len
] = '\\';
736 msi_free( new_path
);
740 void msi_ui_progress( MSIPACKAGE
*package
, int a
, int b
, int c
, int d
)
744 row
= MSI_CreateRecord( 4 );
745 MSI_RecordSetInteger( row
, 1, a
);
746 MSI_RecordSetInteger( row
, 2, b
);
747 MSI_RecordSetInteger( row
, 3, c
);
748 MSI_RecordSetInteger( row
, 4, d
);
749 MSI_ProcessMessage( package
, INSTALLMESSAGE_PROGRESS
, row
);
750 msiobj_release( &row
->hdr
);
752 msi_dialog_check_messages( NULL
);
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_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, 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_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, 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 (file %s sequence %u)\n", debugstr_w(file
->File
), file
->Sequence
);
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] != '#' || disk_id
>= MSI_INITIAL_MEDIA_TRANSFORM_DISKID
)
1301 return ERROR_SUCCESS
;
1303 return msi_add_cabinet_stream( package
, disk_id
, package
->db
->storage
, cabinet
);
1306 static UINT
load_all_media( MSIPACKAGE
*package
)
1308 static const WCHAR query
[] = {
1309 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`',
1310 'M','e','d','i','a','`',' ','O','R','D','E','R',' ','B','Y',' ',
1311 '`','D','i','s','k','I','d','`',0};
1315 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1316 if (r
!= ERROR_SUCCESS
)
1317 return ERROR_SUCCESS
;
1319 r
= MSI_IterateRecords( view
, NULL
, load_media
, package
);
1320 msiobj_release( &view
->hdr
);
1324 static UINT
load_patch_disk_id( MSIPACKAGE
*package
, MSIFILEPATCH
*patch
)
1326 static const WCHAR query
[] =
1327 {'S','E','L','E','C','T',' ','`','D','i','s','k','I','d','`',' ', 'F','R','O','M',' ',
1328 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
1329 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',' ','%','u',0};
1332 if (!(rec
= MSI_QueryGetRecord( package
->db
, query
, patch
->Sequence
)))
1334 WARN("query failed\n");
1335 return ERROR_FUNCTION_FAILED
;
1338 patch
->disk_id
= MSI_RecordGetInteger( rec
, 1 );
1339 msiobj_release( &rec
->hdr
);
1340 return ERROR_SUCCESS
;
1343 static UINT
load_patch(MSIRECORD
*row
, LPVOID param
)
1345 MSIPACKAGE
*package
= param
;
1346 MSIFILEPATCH
*patch
;
1347 const WCHAR
*file_key
;
1349 patch
= msi_alloc_zero( sizeof (MSIFILEPATCH
) );
1351 return ERROR_NOT_ENOUGH_MEMORY
;
1353 file_key
= MSI_RecordGetString( row
, 1 );
1354 patch
->File
= msi_get_loaded_file( package
, file_key
);
1357 ERR("Failed to find target for patch in File table\n");
1359 return ERROR_FUNCTION_FAILED
;
1362 patch
->Sequence
= MSI_RecordGetInteger( row
, 2 );
1363 patch
->PatchSize
= MSI_RecordGetInteger( row
, 3 );
1364 patch
->Attributes
= MSI_RecordGetInteger( row
, 4 );
1367 * Header field - for patch validation.
1368 * _StreamRef - External key into MsiPatchHeaders (instead of the header field)
1371 load_patch_disk_id( package
, patch
);
1373 TRACE("Patch loaded (file %s sequence %u)\n", debugstr_w(patch
->File
->File
), patch
->Sequence
);
1375 list_add_tail( &package
->filepatches
, &patch
->entry
);
1377 return ERROR_SUCCESS
;
1380 static UINT
load_all_patches(MSIPACKAGE
*package
)
1382 static const WCHAR query
[] = {
1383 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1384 '`','P','a','t','c','h','`',' ','O','R','D','E','R',' ','B','Y',' ',
1385 '`','S','e','q','u','e','n','c','e','`',0};
1389 if (!list_empty(&package
->filepatches
))
1390 return ERROR_SUCCESS
;
1392 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1393 if (rc
!= ERROR_SUCCESS
)
1394 return ERROR_SUCCESS
;
1396 rc
= MSI_IterateRecords(view
, NULL
, load_patch
, package
);
1397 msiobj_release(&view
->hdr
);
1401 static UINT
load_folder_persistence( MSIPACKAGE
*package
, MSIFOLDER
*folder
)
1403 static const WCHAR query
[] = {
1404 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1405 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',' ','W','H','E','R','E',' ',
1406 '`','D','i','r','e','c','t','o','r','y','_','`',' ','=','\'','%','s','\'',0};
1409 folder
->persistent
= FALSE
;
1410 if (!MSI_OpenQuery( package
->db
, &view
, query
, folder
->Directory
))
1412 if (!MSI_ViewExecute( view
, NULL
))
1415 if (!MSI_ViewFetch( view
, &rec
))
1417 TRACE("directory %s is persistent\n", debugstr_w(folder
->Directory
));
1418 folder
->persistent
= TRUE
;
1419 msiobj_release( &rec
->hdr
);
1422 msiobj_release( &view
->hdr
);
1424 return ERROR_SUCCESS
;
1427 static UINT
load_folder( MSIRECORD
*row
, LPVOID param
)
1429 MSIPACKAGE
*package
= param
;
1430 static WCHAR szEmpty
[] = { 0 };
1431 LPWSTR p
, tgt_short
, tgt_long
, src_short
, src_long
;
1434 if (!(folder
= msi_alloc_zero( sizeof(*folder
) ))) return ERROR_NOT_ENOUGH_MEMORY
;
1435 list_init( &folder
->children
);
1436 folder
->Directory
= msi_dup_record_field( row
, 1 );
1437 folder
->Parent
= msi_dup_record_field( row
, 2 );
1438 p
= msi_dup_record_field(row
, 3);
1440 TRACE("%s\n", debugstr_w(folder
->Directory
));
1442 /* split src and target dir */
1444 src_short
= folder_split_path( p
, ':' );
1446 /* split the long and short paths */
1447 tgt_long
= folder_split_path( tgt_short
, '|' );
1448 src_long
= folder_split_path( src_short
, '|' );
1450 /* check for no-op dirs */
1451 if (tgt_short
&& !strcmpW( szDot
, tgt_short
))
1452 tgt_short
= szEmpty
;
1453 if (src_short
&& !strcmpW( szDot
, src_short
))
1454 src_short
= szEmpty
;
1457 tgt_long
= tgt_short
;
1460 src_short
= tgt_short
;
1461 src_long
= tgt_long
;
1465 src_long
= src_short
;
1467 /* FIXME: use the target short path too */
1468 folder
->TargetDefault
= strdupW(tgt_long
);
1469 folder
->SourceShortPath
= strdupW(src_short
);
1470 folder
->SourceLongPath
= strdupW(src_long
);
1473 TRACE("TargetDefault = %s\n",debugstr_w( folder
->TargetDefault
));
1474 TRACE("SourceLong = %s\n", debugstr_w( folder
->SourceLongPath
));
1475 TRACE("SourceShort = %s\n", debugstr_w( folder
->SourceShortPath
));
1477 load_folder_persistence( package
, folder
);
1479 list_add_tail( &package
->folders
, &folder
->entry
);
1480 return ERROR_SUCCESS
;
1483 static UINT
add_folder_child( MSIFOLDER
*parent
, MSIFOLDER
*child
)
1487 if (!(fl
= msi_alloc( sizeof(*fl
) ))) return ERROR_NOT_ENOUGH_MEMORY
;
1489 list_add_tail( &parent
->children
, &fl
->entry
);
1490 return ERROR_SUCCESS
;
1493 static UINT
find_folder_children( MSIRECORD
*row
, LPVOID param
)
1495 MSIPACKAGE
*package
= param
;
1496 MSIFOLDER
*parent
, *child
;
1498 if (!(child
= msi_get_loaded_folder( package
, MSI_RecordGetString( row
, 1 ) )))
1499 return ERROR_FUNCTION_FAILED
;
1501 if (!child
->Parent
) return ERROR_SUCCESS
;
1503 if (!(parent
= msi_get_loaded_folder( package
, child
->Parent
)))
1504 return ERROR_FUNCTION_FAILED
;
1506 return add_folder_child( parent
, child
);
1509 static UINT
load_all_folders( MSIPACKAGE
*package
)
1511 static const WCHAR query
[] = {
1512 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1513 '`','D','i','r','e','c','t','o','r','y','`',0};
1517 if (!list_empty(&package
->folders
))
1518 return ERROR_SUCCESS
;
1520 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1521 if (r
!= ERROR_SUCCESS
)
1524 r
= MSI_IterateRecords( view
, NULL
, load_folder
, package
);
1525 if (r
!= ERROR_SUCCESS
)
1527 msiobj_release( &view
->hdr
);
1530 r
= MSI_IterateRecords( view
, NULL
, find_folder_children
, package
);
1531 msiobj_release( &view
->hdr
);
1535 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1537 msi_set_property( package
->db
, szCostingComplete
, szZero
, -1 );
1538 msi_set_property( package
->db
, szRootDrive
, szCRoot
, -1 );
1540 load_all_folders( package
);
1541 msi_load_all_components( package
);
1542 msi_load_all_features( package
);
1543 load_all_files( package
);
1544 load_all_patches( package
);
1545 load_all_media( package
);
1547 return ERROR_SUCCESS
;
1550 static UINT
execute_script( MSIPACKAGE
*package
, UINT script
)
1552 UINT i
, rc
= ERROR_SUCCESS
;
1554 TRACE("executing script %u\n", script
);
1556 if (script
== SCRIPT_ROLLBACK
)
1558 for (i
= package
->script_actions_count
[script
]; i
> 0; i
--)
1560 rc
= ACTION_PerformAction(package
, package
->script_actions
[script
][i
-1], script
);
1561 if (rc
!= ERROR_SUCCESS
)
1563 ERR("Execution of script %i halted; action %s returned %u\n",
1564 script
, debugstr_w(package
->script_actions
[script
][i
-1]), rc
);
1571 for (i
= 0; i
< package
->script_actions_count
[script
]; i
++)
1573 rc
= ACTION_PerformAction(package
, package
->script_actions
[script
][i
], script
);
1574 if (rc
!= ERROR_SUCCESS
)
1576 ERR("Execution of script %i halted; action %s returned %u\n",
1577 script
, debugstr_w(package
->script_actions
[script
][i
]), rc
);
1582 msi_free_action_script(package
, script
);
1586 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1588 return ERROR_SUCCESS
;
1591 static void get_client_counts( MSIPACKAGE
*package
)
1596 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1598 if (!comp
->ComponentId
) continue;
1600 if (MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, szLocalSid
, &hkey
, FALSE
) &&
1601 MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, NULL
, &hkey
, FALSE
))
1603 comp
->num_clients
= 0;
1606 RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, (DWORD
*)&comp
->num_clients
,
1607 NULL
, NULL
, NULL
, NULL
);
1608 RegCloseKey( hkey
);
1612 static void ACTION_GetComponentInstallStates(MSIPACKAGE
*package
)
1617 LIST_FOR_EACH_ENTRY(comp
, &package
->components
, MSICOMPONENT
, entry
)
1619 if (!comp
->ComponentId
) continue;
1621 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1622 MSIINSTALLCONTEXT_USERMANAGED
, comp
->ComponentId
,
1624 if (r
== ERROR_SUCCESS
) continue;
1626 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1627 MSIINSTALLCONTEXT_USERUNMANAGED
, comp
->ComponentId
,
1629 if (r
== ERROR_SUCCESS
) continue;
1631 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1632 MSIINSTALLCONTEXT_MACHINE
, comp
->ComponentId
,
1634 if (r
== ERROR_SUCCESS
) continue;
1636 comp
->Installed
= INSTALLSTATE_ABSENT
;
1640 static void ACTION_GetFeatureInstallStates(MSIPACKAGE
*package
)
1642 MSIFEATURE
*feature
;
1644 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1646 INSTALLSTATE state
= MsiQueryFeatureStateW( package
->ProductCode
, feature
->Feature
);
1648 if (state
== INSTALLSTATE_UNKNOWN
|| state
== INSTALLSTATE_INVALIDARG
)
1649 feature
->Installed
= INSTALLSTATE_ABSENT
;
1651 feature
->Installed
= state
;
1655 static inline BOOL
is_feature_selected( MSIFEATURE
*feature
, INT level
)
1657 return (feature
->Level
> 0 && feature
->Level
<= level
);
1660 static BOOL
process_state_property(MSIPACKAGE
* package
, int level
,
1661 LPCWSTR property
, INSTALLSTATE state
)
1664 MSIFEATURE
*feature
;
1665 BOOL remove
= !strcmpW(property
, szRemove
);
1666 BOOL reinstall
= !strcmpW(property
, szReinstall
);
1668 override
= msi_dup_property( package
->db
, property
);
1672 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1674 if (feature
->Level
<= 0)
1678 state
= (feature
->Installed
== INSTALLSTATE_ABSENT
? INSTALLSTATE_UNKNOWN
: feature
->Installed
);
1680 state
= (feature
->Installed
== INSTALLSTATE_ABSENT
? INSTALLSTATE_UNKNOWN
: INSTALLSTATE_ABSENT
);
1682 if (!strcmpiW( override
, szAll
))
1684 feature
->Action
= state
;
1685 feature
->ActionRequest
= state
;
1689 LPWSTR ptr
= override
;
1690 LPWSTR ptr2
= strchrW(override
,',');
1694 int len
= ptr2
- ptr
;
1696 if ((ptr2
&& strlenW(feature
->Feature
) == len
&& !strncmpW(ptr
, feature
->Feature
, len
))
1697 || (!ptr2
&& !strcmpW(ptr
, feature
->Feature
)))
1699 feature
->Action
= state
;
1700 feature
->ActionRequest
= state
;
1706 ptr2
= strchrW(ptr
,',');
1717 static BOOL
process_overrides( MSIPACKAGE
*package
, int level
)
1719 static const WCHAR szAddLocal
[] =
1720 {'A','D','D','L','O','C','A','L',0};
1721 static const WCHAR szAddSource
[] =
1722 {'A','D','D','S','O','U','R','C','E',0};
1723 static const WCHAR szAdvertise
[] =
1724 {'A','D','V','E','R','T','I','S','E',0};
1727 /* all these activation/deactivation things happen in order and things
1728 * later on the list override things earlier on the list.
1730 * 0 INSTALLLEVEL processing
1743 ret
|= process_state_property( package
, level
, szAddLocal
, INSTALLSTATE_LOCAL
);
1744 ret
|= process_state_property( package
, level
, szRemove
, INSTALLSTATE_ABSENT
);
1745 ret
|= process_state_property( package
, level
, szAddSource
, INSTALLSTATE_SOURCE
);
1746 ret
|= process_state_property( package
, level
, szReinstall
, INSTALLSTATE_UNKNOWN
);
1747 ret
|= process_state_property( package
, level
, szAdvertise
, INSTALLSTATE_ADVERTISED
);
1750 msi_set_property( package
->db
, szPreselected
, szOne
, -1 );
1755 static void disable_children( MSIFEATURE
*feature
, int level
)
1759 LIST_FOR_EACH_ENTRY( fl
, &feature
->Children
, FeatureList
, entry
)
1761 if (!is_feature_selected( feature
, level
))
1763 TRACE("child %s (level %d request %d) follows disabled parent %s (level %d request %d)\n",
1764 debugstr_w(fl
->feature
->Feature
), fl
->feature
->Level
, fl
->feature
->ActionRequest
,
1765 debugstr_w(feature
->Feature
), feature
->Level
, feature
->ActionRequest
);
1767 fl
->feature
->Level
= feature
->Level
;
1768 fl
->feature
->Action
= INSTALLSTATE_UNKNOWN
;
1769 fl
->feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1771 disable_children( fl
->feature
, level
);
1775 static void follow_parent( MSIFEATURE
*feature
)
1779 LIST_FOR_EACH_ENTRY( fl
, &feature
->Children
, FeatureList
, entry
)
1781 if (fl
->feature
->Attributes
& msidbFeatureAttributesFollowParent
)
1783 TRACE("child %s (level %d request %d) follows parent %s (level %d request %d)\n",
1784 debugstr_w(fl
->feature
->Feature
), fl
->feature
->Level
, fl
->feature
->ActionRequest
,
1785 debugstr_w(feature
->Feature
), feature
->Level
, feature
->ActionRequest
);
1787 fl
->feature
->Action
= feature
->Action
;
1788 fl
->feature
->ActionRequest
= feature
->ActionRequest
;
1790 follow_parent( fl
->feature
);
1794 UINT
MSI_SetFeatureStates(MSIPACKAGE
*package
)
1797 MSICOMPONENT
* component
;
1798 MSIFEATURE
*feature
;
1800 TRACE("Checking Install Level\n");
1802 level
= msi_get_property_int(package
->db
, szInstallLevel
, 1);
1804 if (msi_get_property_int( package
->db
, szPreselected
, 0 ))
1806 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1808 if (!is_feature_selected( feature
, level
)) continue;
1810 if (feature
->ActionRequest
== INSTALLSTATE_UNKNOWN
)
1812 if (feature
->Installed
== INSTALLSTATE_ABSENT
)
1814 feature
->Action
= INSTALLSTATE_UNKNOWN
;
1815 feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1819 feature
->Action
= feature
->Installed
;
1820 feature
->ActionRequest
= feature
->Installed
;
1824 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1826 if (feature
->Feature_Parent
) continue;
1827 disable_children( feature
, level
);
1828 follow_parent( feature
);
1831 else if (!msi_get_property_int( package
->db
, szInstalled
, 0 ))
1833 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1835 if (!is_feature_selected( feature
, level
)) continue;
1837 if (feature
->ActionRequest
== INSTALLSTATE_UNKNOWN
)
1839 if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1841 feature
->Action
= INSTALLSTATE_SOURCE
;
1842 feature
->ActionRequest
= INSTALLSTATE_SOURCE
;
1844 else if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1846 feature
->Action
= INSTALLSTATE_ADVERTISED
;
1847 feature
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1851 feature
->Action
= INSTALLSTATE_LOCAL
;
1852 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1856 /* disable child features of unselected parent or follow parent */
1857 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1859 if (feature
->Feature_Parent
) continue;
1860 disable_children( feature
, level
);
1861 follow_parent( feature
);
1865 /* now we want to set component state based based on feature state */
1866 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1870 TRACE("examining feature %s (level %d installed %d request %d action %d)\n",
1871 debugstr_w(feature
->Feature
), feature
->Level
, feature
->Installed
,
1872 feature
->ActionRequest
, feature
->Action
);
1874 /* features with components that have compressed files are made local */
1875 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1877 if (cl
->component
->ForceLocalState
&&
1878 feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1880 feature
->Action
= INSTALLSTATE_LOCAL
;
1881 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1886 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1888 component
= cl
->component
;
1890 switch (feature
->ActionRequest
)
1892 case INSTALLSTATE_ABSENT
:
1893 component
->anyAbsent
= 1;
1895 case INSTALLSTATE_ADVERTISED
:
1896 component
->hasAdvertisedFeature
= 1;
1898 case INSTALLSTATE_SOURCE
:
1899 component
->hasSourceFeature
= 1;
1901 case INSTALLSTATE_LOCAL
:
1902 component
->hasLocalFeature
= 1;
1904 case INSTALLSTATE_DEFAULT
:
1905 if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1906 component
->hasAdvertisedFeature
= 1;
1907 else if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1908 component
->hasSourceFeature
= 1;
1910 component
->hasLocalFeature
= 1;
1912 case INSTALLSTATE_UNKNOWN
:
1913 if (feature
->Installed
== INSTALLSTATE_ADVERTISED
)
1914 component
->hasAdvertisedFeature
= 1;
1915 if (feature
->Installed
== INSTALLSTATE_SOURCE
)
1916 component
->hasSourceFeature
= 1;
1917 if (feature
->Installed
== INSTALLSTATE_LOCAL
)
1918 component
->hasLocalFeature
= 1;
1926 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1928 /* check if it's local or source */
1929 if (!(component
->Attributes
& msidbComponentAttributesOptional
) &&
1930 (component
->hasLocalFeature
|| component
->hasSourceFeature
))
1932 if ((component
->Attributes
& msidbComponentAttributesSourceOnly
) &&
1933 !component
->ForceLocalState
)
1935 component
->Action
= INSTALLSTATE_SOURCE
;
1936 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1940 component
->Action
= INSTALLSTATE_LOCAL
;
1941 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1946 /* if any feature is local, the component must be local too */
1947 if (component
->hasLocalFeature
)
1949 component
->Action
= INSTALLSTATE_LOCAL
;
1950 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1953 if (component
->hasSourceFeature
)
1955 component
->Action
= INSTALLSTATE_SOURCE
;
1956 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1959 if (component
->hasAdvertisedFeature
)
1961 component
->Action
= INSTALLSTATE_ADVERTISED
;
1962 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1965 TRACE("nobody wants component %s\n", debugstr_w(component
->Component
));
1966 if (component
->anyAbsent
&& component
->ComponentId
)
1968 component
->Action
= INSTALLSTATE_ABSENT
;
1969 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
1973 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1975 if (component
->ActionRequest
== INSTALLSTATE_DEFAULT
)
1977 TRACE("%s was default, setting to local\n", debugstr_w(component
->Component
));
1978 component
->Action
= INSTALLSTATE_LOCAL
;
1979 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1982 if (component
->ActionRequest
== INSTALLSTATE_SOURCE
&&
1983 component
->Installed
== INSTALLSTATE_SOURCE
&&
1984 component
->hasSourceFeature
)
1986 component
->Action
= INSTALLSTATE_UNKNOWN
;
1987 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1990 TRACE("component %s (installed %d request %d action %d)\n",
1991 debugstr_w(component
->Component
), component
->Installed
, component
->ActionRequest
, component
->Action
);
1993 if (component
->Action
== INSTALLSTATE_LOCAL
|| component
->Action
== INSTALLSTATE_SOURCE
)
1994 component
->num_clients
++;
1995 else if (component
->Action
== INSTALLSTATE_ABSENT
)
1996 component
->num_clients
--;
1999 return ERROR_SUCCESS
;
2002 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
2004 MSIPACKAGE
*package
= param
;
2006 MSIFEATURE
*feature
;
2008 name
= MSI_RecordGetString( row
, 1 );
2010 feature
= msi_get_loaded_feature( package
, name
);
2012 ERR("FAILED to find loaded feature %s\n",debugstr_w(name
));
2016 Condition
= MSI_RecordGetString(row
,3);
2018 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
2020 int level
= MSI_RecordGetInteger(row
,2);
2021 TRACE("Resetting feature %s to level %i\n", debugstr_w(name
), level
);
2022 feature
->Level
= level
;
2025 return ERROR_SUCCESS
;
2028 VS_FIXEDFILEINFO
*msi_get_disk_file_version( LPCWSTR filename
)
2030 static const WCHAR name
[] = {'\\',0};
2031 VS_FIXEDFILEINFO
*ptr
, *ret
;
2033 DWORD versize
, handle
;
2036 versize
= GetFileVersionInfoSizeW( filename
, &handle
);
2040 version
= msi_alloc( versize
);
2044 GetFileVersionInfoW( filename
, 0, versize
, version
);
2046 if (!VerQueryValueW( version
, name
, (LPVOID
*)&ptr
, &sz
))
2048 msi_free( version
);
2052 ret
= msi_alloc( sz
);
2053 memcpy( ret
, ptr
, sz
);
2055 msi_free( version
);
2059 int msi_compare_file_versions( VS_FIXEDFILEINFO
*fi
, const WCHAR
*version
)
2063 msi_parse_version_string( version
, &ms
, &ls
);
2065 if (fi
->dwFileVersionMS
> ms
) return 1;
2066 else if (fi
->dwFileVersionMS
< ms
) return -1;
2067 else if (fi
->dwFileVersionLS
> ls
) return 1;
2068 else if (fi
->dwFileVersionLS
< ls
) return -1;
2072 int msi_compare_font_versions( const WCHAR
*ver1
, const WCHAR
*ver2
)
2076 msi_parse_version_string( ver1
, &ms1
, NULL
);
2077 msi_parse_version_string( ver2
, &ms2
, NULL
);
2079 if (ms1
> ms2
) return 1;
2080 else if (ms1
< ms2
) return -1;
2084 DWORD
msi_get_disk_file_size( LPCWSTR filename
)
2089 file
= CreateFileW( filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
2090 if (file
== INVALID_HANDLE_VALUE
)
2091 return INVALID_FILE_SIZE
;
2093 size
= GetFileSize( file
, NULL
);
2094 CloseHandle( file
);
2098 BOOL
msi_file_hash_matches( MSIFILE
*file
)
2101 MSIFILEHASHINFO hash
;
2103 hash
.dwFileHashInfoSize
= sizeof(MSIFILEHASHINFO
);
2104 r
= msi_get_filehash( file
->TargetPath
, &hash
);
2105 if (r
!= ERROR_SUCCESS
)
2108 return !memcmp( &hash
, &file
->hash
, sizeof(MSIFILEHASHINFO
) );
2111 static WCHAR
*create_temp_dir( MSIDATABASE
*db
)
2116 if (!db
->tempfolder
)
2118 WCHAR tmp
[MAX_PATH
];
2119 UINT len
= sizeof(tmp
)/sizeof(tmp
[0]);
2121 if (msi_get_property( db
, szTempFolder
, tmp
, &len
) ||
2122 GetFileAttributesW( tmp
) != FILE_ATTRIBUTE_DIRECTORY
)
2124 GetTempPathW( MAX_PATH
, tmp
);
2126 if (!(db
->tempfolder
= strdupW( tmp
))) return NULL
;
2129 if ((ret
= msi_alloc( (strlenW( db
->tempfolder
) + 20) * sizeof(WCHAR
) )))
2133 if (!GetTempFileNameW( db
->tempfolder
, szMsi
, ++id
, ret
))
2138 if (CreateDirectoryW( ret
, NULL
)) break;
2146 * msi_build_directory_name()
2148 * This function is to save messing round with directory names
2149 * It handles adding backslashes between path segments,
2150 * and can add \ at the end of the directory name if told to.
2152 * It takes a variable number of arguments.
2153 * It always allocates a new string for the result, so make sure
2154 * to free the return value when finished with it.
2156 * The first arg is the number of path segments that follow.
2157 * The arguments following count are a list of path segments.
2158 * A path segment may be NULL.
2160 * Path segments will be added with a \ separating them.
2161 * A \ will not be added after the last segment, however if the
2162 * last segment is NULL, then the last character will be a \
2164 WCHAR
*msi_build_directory_name( DWORD count
, ... )
2170 va_start( va
, count
);
2171 for (i
= 0; i
< count
; i
++)
2173 const WCHAR
*str
= va_arg( va
, const WCHAR
* );
2174 if (str
) sz
+= strlenW( str
) + 1;
2178 dir
= msi_alloc( sz
* sizeof(WCHAR
) );
2181 va_start( va
, count
);
2182 for (i
= 0; i
< count
; i
++)
2184 const WCHAR
*str
= va_arg( va
, const WCHAR
* );
2186 strcatW( dir
, str
);
2187 if ( i
+ 1 != count
&& dir
[0] && dir
[strlenW( dir
) - 1] != '\\') strcatW( dir
, szBackSlash
);
2193 BOOL
msi_is_global_assembly( MSICOMPONENT
*comp
)
2195 return comp
->assembly
&& !comp
->assembly
->application
;
2198 static void set_target_path( MSIPACKAGE
*package
, MSIFILE
*file
)
2200 msi_free( file
->TargetPath
);
2201 if (msi_is_global_assembly( file
->Component
))
2203 MSIASSEMBLY
*assembly
= file
->Component
->assembly
;
2205 if (!assembly
->tempdir
) assembly
->tempdir
= create_temp_dir( package
->db
);
2206 file
->TargetPath
= msi_build_directory_name( 2, assembly
->tempdir
, file
->FileName
);
2210 const WCHAR
*dir
= msi_get_target_folder( package
, file
->Component
->Directory
);
2211 file
->TargetPath
= msi_build_directory_name( 2, dir
, file
->FileName
);
2214 TRACE("file %s resolves to %s\n", debugstr_w(file
->File
), debugstr_w(file
->TargetPath
));
2217 static UINT
calculate_file_cost( MSIPACKAGE
*package
)
2219 VS_FIXEDFILEINFO
*file_version
;
2220 WCHAR
*font_version
;
2223 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2225 MSICOMPONENT
*comp
= file
->Component
;
2228 if (!comp
->Enabled
) continue;
2230 if (file
->IsCompressed
)
2231 comp
->ForceLocalState
= TRUE
;
2233 set_target_path( package
, file
);
2235 if ((comp
->assembly
&& !comp
->assembly
->installed
) ||
2236 GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
2238 comp
->Cost
+= file
->FileSize
;
2241 file_size
= msi_get_disk_file_size( file
->TargetPath
);
2242 TRACE("%s (size %u)\n", debugstr_w(file
->TargetPath
), file_size
);
2246 if ((file_version
= msi_get_disk_file_version( file
->TargetPath
)))
2248 if (msi_compare_file_versions( file_version
, file
->Version
) < 0)
2250 comp
->Cost
+= file
->FileSize
- file_size
;
2252 msi_free( file_version
);
2255 else if ((font_version
= msi_font_version_from_file( file
->TargetPath
)))
2257 if (msi_compare_font_versions( font_version
, file
->Version
) < 0)
2259 comp
->Cost
+= file
->FileSize
- file_size
;
2261 msi_free( font_version
);
2265 if (file_size
!= file
->FileSize
)
2267 comp
->Cost
+= file
->FileSize
- file_size
;
2270 return ERROR_SUCCESS
;
2273 WCHAR
*msi_normalize_path( const WCHAR
*in
)
2275 const WCHAR
*p
= in
;
2277 int n
, len
= strlenW( in
) + 2;
2279 if (!(q
= ret
= msi_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
2284 /* copy until the end of the string or a space */
2285 while (*p
!= ' ' && (*q
= *p
))
2288 /* reduce many backslashes to one */
2289 if (*p
!= '\\' || *q
!= '\\')
2293 /* quit at the end of the string */
2297 /* count the number of spaces */
2302 /* if it's leading or trailing space, skip it */
2303 if ( len
== 0 || p
[-1] == '\\' || p
[n
] == '\\' )
2305 else /* copy n spaces */
2306 while (n
&& (*q
++ = *p
++)) n
--;
2308 while (q
- ret
> 0 && q
[-1] == ' ') q
--;
2309 if (q
- ret
> 0 && q
[-1] != '\\')
2317 static WCHAR
*get_install_location( MSIPACKAGE
*package
)
2322 if (!package
->ProductCode
) return NULL
;
2323 if (MSIREG_OpenInstallProps( package
->ProductCode
, package
->Context
, NULL
, &hkey
, FALSE
)) return NULL
;
2324 if ((path
= msi_reg_get_val_str( hkey
, szInstallLocation
)) && !path
[0])
2329 RegCloseKey( hkey
);
2333 void msi_resolve_target_folder( MSIPACKAGE
*package
, const WCHAR
*name
, BOOL load_prop
)
2336 MSIFOLDER
*folder
, *parent
, *child
;
2337 WCHAR
*path
, *normalized_path
;
2339 TRACE("resolving %s\n", debugstr_w(name
));
2341 if (!(folder
= msi_get_loaded_folder( package
, name
))) return;
2343 if (!strcmpW( folder
->Directory
, szTargetDir
)) /* special resolving for target root dir */
2345 if (!(path
= get_install_location( package
)) &&
2346 (!load_prop
|| !(path
= msi_dup_property( package
->db
, szTargetDir
))))
2348 path
= msi_dup_property( package
->db
, szRootDrive
);
2351 else if (!load_prop
|| !(path
= msi_dup_property( package
->db
, folder
->Directory
)))
2353 if (folder
->Parent
&& strcmpW( folder
->Directory
, folder
->Parent
))
2355 parent
= msi_get_loaded_folder( package
, folder
->Parent
);
2356 path
= msi_build_directory_name( 3, parent
->ResolvedTarget
, folder
->TargetDefault
, NULL
);
2359 path
= msi_build_directory_name( 2, folder
->TargetDefault
, NULL
);
2361 normalized_path
= msi_normalize_path( path
);
2363 if (folder
->ResolvedTarget
&& !strcmpiW( normalized_path
, folder
->ResolvedTarget
))
2365 TRACE("%s already resolved to %s\n", debugstr_w(name
), debugstr_w(folder
->ResolvedTarget
));
2366 msi_free( normalized_path
);
2369 msi_set_property( package
->db
, folder
->Directory
, normalized_path
, -1 );
2370 msi_free( folder
->ResolvedTarget
);
2371 folder
->ResolvedTarget
= normalized_path
;
2373 LIST_FOR_EACH_ENTRY( fl
, &folder
->children
, FolderList
, entry
)
2376 msi_resolve_target_folder( package
, child
->Directory
, load_prop
);
2378 TRACE("%s resolves to %s\n", debugstr_w(name
), debugstr_w(folder
->ResolvedTarget
));
2381 static ULONGLONG
get_volume_space_required( MSIPACKAGE
*package
)
2386 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2388 if (comp
->Action
== INSTALLSTATE_LOCAL
) ret
+= comp
->Cost
;
2393 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2395 static const WCHAR query
[] =
2396 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2397 '`','C','o','n','d','i','t','i','o','n','`',0};
2398 static const WCHAR szOutOfDiskSpace
[] =
2399 {'O','u','t','O','f','D','i','s','k','S','p','a','c','e',0};
2400 static const WCHAR szPrimaryFolder
[] =
2401 {'P','R','I','M','A','R','Y','F','O','L','D','E','R',0};
2402 static const WCHAR szPrimaryVolumePath
[] =
2403 {'P','r','i','m','a','r','y','V','o','l','u','m','e','P','a','t','h',0};
2404 static const WCHAR szPrimaryVolumeSpaceAvailable
[] =
2405 {'P','r','i','m','a','r','y','V','o','l','u','m','e','S','p','a','c','e',
2406 'A','v','a','i','l','a','b','l','e',0};
2407 static const WCHAR szPrimaryVolumeSpaceRequired
[] =
2408 {'P','r','i','m','a','r','y','V','o','l','u','m','e','S','p','a','c','e',
2409 'R','e','q','u','i','r','e','d',0};
2410 static const WCHAR szPrimaryVolumeSpaceRemaining
[] =
2411 {'P','r','i','m','a','r','y','V','o','l','u','m','e','S','p','a','c','e',
2412 'R','e','m','a','i','n','i','n','g',0};
2413 static const WCHAR szOutOfNoRbDiskSpace
[] =
2414 {'O','u','t','O','f','N','o','R','b','D','i','s','k','S','p','a','c','e',0};
2417 WCHAR
*level
, *primary_key
, *primary_folder
;
2420 TRACE("Building directory properties\n");
2421 msi_resolve_target_folder( package
, szTargetDir
, TRUE
);
2423 TRACE("Evaluating component conditions\n");
2424 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2426 if (MSI_EvaluateConditionW( package
, comp
->Condition
) == MSICONDITION_FALSE
)
2428 TRACE("Disabling component %s\n", debugstr_w(comp
->Component
));
2429 comp
->Enabled
= FALSE
;
2432 comp
->Enabled
= TRUE
;
2434 get_client_counts( package
);
2436 /* read components states from the registry */
2437 ACTION_GetComponentInstallStates(package
);
2438 ACTION_GetFeatureInstallStates(package
);
2440 if (!process_overrides( package
, msi_get_property_int( package
->db
, szInstallLevel
, 1 ) ))
2442 TRACE("Evaluating feature conditions\n");
2444 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
2445 if (rc
== ERROR_SUCCESS
)
2447 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_CostFinalizeConditions
, package
);
2448 msiobj_release( &view
->hdr
);
2449 if (rc
!= ERROR_SUCCESS
)
2454 TRACE("Calculating file cost\n");
2455 calculate_file_cost( package
);
2457 msi_set_property( package
->db
, szCostingComplete
, szOne
, -1 );
2458 /* set default run level if not set */
2459 level
= msi_dup_property( package
->db
, szInstallLevel
);
2460 if (!level
) msi_set_property( package
->db
, szInstallLevel
, szOne
, -1 );
2463 if ((rc
= MSI_SetFeatureStates( package
))) return rc
;
2465 if ((primary_key
= msi_dup_property( package
->db
, szPrimaryFolder
)))
2467 if ((primary_folder
= msi_dup_property( package
->db
, primary_key
)))
2469 if (((primary_folder
[0] >= 'A' && primary_folder
[0] <= 'Z') ||
2470 (primary_folder
[0] >= 'a' && primary_folder
[0] <= 'z')) && primary_folder
[1] == ':')
2472 static const WCHAR fmtW
[] = {'%','l','u',0};
2473 ULARGE_INTEGER free
;
2477 primary_folder
[2] = 0;
2478 if (GetDiskFreeSpaceExW( primary_folder
, &free
, NULL
, NULL
))
2480 sprintfW( buf
, fmtW
, free
.QuadPart
/ 512 );
2481 msi_set_property( package
->db
, szPrimaryVolumeSpaceAvailable
, buf
, -1 );
2483 required
= get_volume_space_required( package
);
2484 sprintfW( buf
, fmtW
, required
/ 512 );
2485 msi_set_property( package
->db
, szPrimaryVolumeSpaceRequired
, buf
, -1 );
2487 sprintfW( buf
, fmtW
, (free
.QuadPart
- required
) / 512 );
2488 msi_set_property( package
->db
, szPrimaryVolumeSpaceRemaining
, buf
, -1 );
2489 msi_set_property( package
->db
, szPrimaryVolumePath
, primary_folder
, 2 );
2491 msi_free( primary_folder
);
2493 msi_free( primary_key
);
2496 /* FIXME: check volume disk space */
2497 msi_set_property( package
->db
, szOutOfDiskSpace
, szZero
, -1 );
2498 msi_set_property( package
->db
, szOutOfNoRbDiskSpace
, szZero
, -1 );
2500 return ERROR_SUCCESS
;
2503 static BYTE
*parse_value( MSIPACKAGE
*package
, const WCHAR
*value
, DWORD len
, DWORD
*type
, DWORD
*size
)
2509 *size
= sizeof(WCHAR
);
2511 if ((data
= msi_alloc( *size
))) *(WCHAR
*)data
= 0;
2514 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
2520 LPWSTR deformated
= NULL
;
2523 deformat_string(package
, &value
[2], &deformated
);
2525 /* binary value type */
2529 *size
= (strlenW(ptr
)/2)+1;
2531 *size
= strlenW(ptr
)/2;
2533 data
= msi_alloc(*size
);
2539 /* if uneven pad with a zero in front */
2545 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2547 TRACE("Uneven byte count\n");
2555 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2558 msi_free(deformated
);
2560 TRACE("Data %i bytes(%i)\n",*size
,count
);
2567 deformat_string(package
, &value
[1], &deformated
);
2570 *size
= sizeof(DWORD
);
2571 data
= msi_alloc(*size
);
2577 if ( (*p
< '0') || (*p
> '9') )
2583 if (deformated
[0] == '-')
2586 TRACE("DWORD %i\n",*(LPDWORD
)data
);
2588 msi_free(deformated
);
2593 const WCHAR
*ptr
= value
;
2596 if (value
[0] == '#')
2599 if (value
[1] == '%')
2602 *type
= REG_EXPAND_SZ
;
2605 data
= (BYTE
*)msi_strdupW( ptr
, len
);
2606 if (len
> strlenW( (const WCHAR
*)data
)) *type
= REG_MULTI_SZ
;
2607 *size
= (len
+ 1) * sizeof(WCHAR
);
2612 static const WCHAR
*get_root_key( MSIPACKAGE
*package
, INT root
, HKEY
*root_key
)
2619 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ))
2621 *root_key
= HKEY_LOCAL_MACHINE
;
2626 *root_key
= HKEY_CURRENT_USER
;
2631 *root_key
= HKEY_CLASSES_ROOT
;
2635 *root_key
= HKEY_CURRENT_USER
;
2639 *root_key
= HKEY_LOCAL_MACHINE
;
2643 *root_key
= HKEY_USERS
;
2647 ERR("Unknown root %i\n", root
);
2654 static inline REGSAM
get_registry_view( const MSICOMPONENT
*comp
)
2657 if (is_wow64
|| is_64bit
)
2658 view
|= (comp
->Attributes
& msidbComponentAttributes64bit
) ? KEY_WOW64_64KEY
: KEY_WOW64_32KEY
;
2662 static HKEY
open_key( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
, BOOL create
, REGSAM access
)
2664 WCHAR
*subkey
, *p
, *q
;
2665 HKEY hkey
, ret
= NULL
;
2668 access
|= get_registry_view( comp
);
2670 if (!(subkey
= strdupW( path
))) return NULL
;
2672 if ((q
= strchrW( p
, '\\' ))) *q
= 0;
2674 res
= RegCreateKeyExW( root
, subkey
, 0, NULL
, 0, access
, NULL
, &hkey
, NULL
);
2676 res
= RegOpenKeyExW( root
, subkey
, 0, access
, &hkey
);
2679 TRACE("failed to open key %s (%d)\n", debugstr_w(subkey
), res
);
2685 ret
= open_key( comp
, hkey
, q
+ 1, create
, access
);
2686 RegCloseKey( hkey
);
2693 static BOOL
is_special_entry( const WCHAR
*name
)
2695 return (name
&& (name
[0] == '*' || name
[0] == '+') && !name
[1]);
2698 static WCHAR
**split_multi_string_values( const WCHAR
*str
, DWORD len
, DWORD
*count
)
2700 const WCHAR
*p
= str
;
2705 if (!str
) return NULL
;
2706 while ((p
- str
) < len
)
2708 p
+= strlenW( p
) + 1;
2711 if (!(ret
= msi_alloc( *count
* sizeof(WCHAR
*) ))) return NULL
;
2713 while ((p
- str
) < len
)
2715 if (!(ret
[i
] = strdupW( p
)))
2717 for (; i
>= 0; i
--) msi_free( ret
[i
] );
2721 p
+= strlenW( p
) + 1;
2727 static WCHAR
*flatten_multi_string_values( WCHAR
**left
, DWORD left_count
,
2728 WCHAR
**right
, DWORD right_count
, DWORD
*size
)
2733 *size
= sizeof(WCHAR
);
2734 for (i
= 0; i
< left_count
; i
++) *size
+= (strlenW( left
[i
] ) + 1) * sizeof(WCHAR
);
2735 for (i
= 0; i
< right_count
; i
++) *size
+= (strlenW( right
[i
] ) + 1) * sizeof(WCHAR
);
2737 if (!(ret
= p
= msi_alloc( *size
))) return NULL
;
2739 for (i
= 0; i
< left_count
; i
++)
2741 strcpyW( p
, left
[i
] );
2742 p
+= strlenW( p
) + 1;
2744 for (i
= 0; i
< right_count
; i
++)
2746 strcpyW( p
, right
[i
] );
2747 p
+= strlenW( p
) + 1;
2753 static DWORD
remove_duplicate_values( WCHAR
**old
, DWORD old_count
,
2754 WCHAR
**new, DWORD new_count
)
2756 DWORD ret
= old_count
;
2757 unsigned int i
, j
, k
;
2759 for (i
= 0; i
< new_count
; i
++)
2761 for (j
= 0; j
< old_count
; j
++)
2763 if (old
[j
] && !strcmpW( new[i
], old
[j
] ))
2766 for (k
= j
; k
< old_count
- 1; k
++) { old
[k
] = old
[k
+ 1]; }
2782 static WCHAR
*join_multi_string_values( enum join_op op
, WCHAR
**old
, DWORD old_count
,
2783 WCHAR
**new, DWORD new_count
, DWORD
*size
)
2787 case JOIN_OP_APPEND
:
2788 old_count
= remove_duplicate_values( old
, old_count
, new, new_count
);
2789 return flatten_multi_string_values( old
, old_count
, new, new_count
, size
);
2791 case JOIN_OP_PREPEND
:
2792 old_count
= remove_duplicate_values( old
, old_count
, new, new_count
);
2793 return flatten_multi_string_values( new, new_count
, old
, old_count
, size
);
2795 case JOIN_OP_REPLACE
:
2796 return flatten_multi_string_values( new, new_count
, NULL
, 0, size
);
2799 ERR("unhandled join op %u\n", op
);
2804 static BYTE
*build_multi_string_value( BYTE
*old_value
, DWORD old_size
,
2805 BYTE
*new_value
, DWORD new_size
, DWORD
*size
)
2807 DWORD i
, old_len
= 0, new_len
= 0, old_count
= 0, new_count
= 0;
2808 const WCHAR
*new_ptr
= NULL
, *old_ptr
= NULL
;
2809 enum join_op op
= JOIN_OP_REPLACE
;
2810 WCHAR
**old
= NULL
, **new = NULL
;
2813 if (new_size
/ sizeof(WCHAR
) - 1 > 1)
2815 new_ptr
= (const WCHAR
*)new_value
;
2816 new_len
= new_size
/ sizeof(WCHAR
) - 1;
2818 if (!new_ptr
[0] && new_ptr
[new_len
- 1])
2820 op
= JOIN_OP_APPEND
;
2824 else if (new_ptr
[0] && !new_ptr
[new_len
- 1])
2826 op
= JOIN_OP_PREPEND
;
2829 else if (new_len
> 2 && !new_ptr
[0] && !new_ptr
[new_len
- 1])
2831 op
= JOIN_OP_REPLACE
;
2835 new = split_multi_string_values( new_ptr
, new_len
, &new_count
);
2837 if (old_size
/ sizeof(WCHAR
) - 1 > 1)
2839 old_ptr
= (const WCHAR
*)old_value
;
2840 old_len
= old_size
/ sizeof(WCHAR
) - 1;
2841 old
= split_multi_string_values( old_ptr
, old_len
, &old_count
);
2843 ret
= (BYTE
*)join_multi_string_values( op
, old
, old_count
, new, new_count
, size
);
2844 for (i
= 0; i
< old_count
; i
++) msi_free( old
[i
] );
2845 for (i
= 0; i
< new_count
; i
++) msi_free( new[i
] );
2851 static BYTE
*reg_get_value( HKEY hkey
, const WCHAR
*name
, DWORD
*type
, DWORD
*size
)
2854 if (RegQueryValueExW( hkey
, name
, NULL
, NULL
, NULL
, size
)) return NULL
;
2855 if (!(ret
= msi_alloc( *size
))) return NULL
;
2856 RegQueryValueExW( hkey
, name
, NULL
, type
, ret
, size
);
2860 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
2862 MSIPACKAGE
*package
= param
;
2863 BYTE
*new_value
, *old_value
= NULL
;
2864 HKEY root_key
, hkey
;
2865 DWORD type
, old_type
, new_size
, old_size
= 0;
2866 LPWSTR deformated
, uikey
;
2867 const WCHAR
*szRoot
, *component
, *name
, *key
, *str
;
2871 BOOL check_first
= FALSE
;
2874 msi_ui_progress( package
, 2, REG_PROGRESS_VALUE
, 0, 0 );
2876 component
= MSI_RecordGetString(row
, 6);
2877 comp
= msi_get_loaded_component(package
,component
);
2879 return ERROR_SUCCESS
;
2881 comp
->Action
= msi_get_component_action( package
, comp
);
2882 if (comp
->Action
!= INSTALLSTATE_LOCAL
&& comp
->Action
!= INSTALLSTATE_SOURCE
)
2884 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
2885 return ERROR_SUCCESS
;
2888 name
= MSI_RecordGetString(row
, 4);
2889 if( MSI_RecordIsNull(row
,5) && name
)
2891 /* null values can have special meanings */
2892 if (name
[0]=='-' && name
[1] == 0)
2893 return ERROR_SUCCESS
;
2894 if ((name
[0] == '+' || name
[0] == '*') && !name
[1])
2898 root
= MSI_RecordGetInteger(row
,2);
2899 key
= MSI_RecordGetString(row
, 3);
2901 szRoot
= get_root_key( package
, root
, &root_key
);
2903 return ERROR_SUCCESS
;
2905 deformat_string(package
, key
, &deformated
);
2906 uikey
= msi_alloc( (strlenW(deformated
) + strlenW(szRoot
) + 1) * sizeof(WCHAR
) );
2907 strcpyW(uikey
,szRoot
);
2908 strcatW(uikey
,deformated
);
2910 if (!(hkey
= open_key( comp
, root_key
, deformated
, TRUE
, KEY_QUERY_VALUE
| KEY_SET_VALUE
)))
2912 ERR("Could not create key %s\n", debugstr_w(deformated
));
2914 msi_free(deformated
);
2915 return ERROR_FUNCTION_FAILED
;
2917 msi_free( deformated
);
2918 str
= msi_record_get_string( row
, 5, NULL
);
2919 len
= deformat_string( package
, str
, &deformated
);
2920 new_value
= parse_value( package
, deformated
, len
, &type
, &new_size
);
2922 msi_free( deformated
);
2923 deformat_string(package
, name
, &deformated
);
2925 if (!is_special_entry( name
))
2927 old_value
= reg_get_value( hkey
, deformated
, &old_type
, &old_size
);
2928 if (type
== REG_MULTI_SZ
)
2931 if (old_value
&& old_type
!= REG_MULTI_SZ
)
2933 msi_free( old_value
);
2937 new = build_multi_string_value( old_value
, old_size
, new_value
, new_size
, &new_size
);
2938 msi_free( new_value
);
2943 TRACE("setting value %s of %s type %u\n", debugstr_w(deformated
), debugstr_w(uikey
), type
);
2944 RegSetValueExW( hkey
, deformated
, 0, type
, new_value
, new_size
);
2946 else if (!old_value
)
2948 if (deformated
|| new_size
)
2950 TRACE("setting value %s of %s type %u\n", debugstr_w(deformated
), debugstr_w(uikey
), type
);
2951 RegSetValueExW( hkey
, deformated
, 0, type
, new_value
, new_size
);
2954 else TRACE("not overwriting existing value %s of %s\n", debugstr_w(deformated
), debugstr_w(uikey
));
2958 uirow
= MSI_CreateRecord(3);
2959 MSI_RecordSetStringW(uirow
,2,deformated
);
2960 MSI_RecordSetStringW(uirow
,1,uikey
);
2961 if (type
== REG_SZ
|| type
== REG_EXPAND_SZ
)
2962 MSI_RecordSetStringW(uirow
, 3, (LPWSTR
)new_value
);
2963 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
2964 msiobj_release( &uirow
->hdr
);
2966 msi_free(new_value
);
2967 msi_free(old_value
);
2968 msi_free(deformated
);
2971 return ERROR_SUCCESS
;
2974 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2976 static const WCHAR query
[] = {
2977 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2978 '`','R','e','g','i','s','t','r','y','`',0};
2982 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
2983 if (rc
!= ERROR_SUCCESS
)
2984 return ERROR_SUCCESS
;
2986 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2987 msiobj_release(&view
->hdr
);
2991 static void delete_key( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
)
2998 access
|= get_registry_view( comp
);
3000 if (!(subkey
= strdupW( path
))) return;
3003 if ((p
= strrchrW( subkey
, '\\' )))
3006 if (!p
[1]) continue; /* trailing backslash */
3007 hkey
= open_key( comp
, root
, subkey
, FALSE
, access
| READ_CONTROL
);
3009 res
= RegDeleteKeyExW( hkey
, p
+ 1, access
, 0 );
3010 RegCloseKey( hkey
);
3013 res
= RegDeleteKeyExW( root
, subkey
, access
, 0 );
3016 TRACE("failed to delete key %s (%d)\n", debugstr_w(subkey
), res
);
3023 static void delete_value( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
, const WCHAR
*value
)
3027 DWORD num_subkeys
, num_values
;
3029 if ((hkey
= open_key( comp
, root
, path
, FALSE
, KEY_SET_VALUE
| KEY_QUERY_VALUE
)))
3031 if ((res
= RegDeleteValueW( hkey
, value
)))
3032 TRACE("failed to delete value %s (%d)\n", debugstr_w(value
), res
);
3034 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, &num_subkeys
, NULL
, NULL
, &num_values
,
3035 NULL
, NULL
, NULL
, NULL
);
3036 RegCloseKey( hkey
);
3037 if (!res
&& !num_subkeys
&& !num_values
)
3039 TRACE("removing empty key %s\n", debugstr_w(path
));
3040 delete_key( comp
, root
, path
);
3045 static void delete_tree( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
)
3050 if (!(hkey
= open_key( comp
, root
, path
, FALSE
, KEY_ALL_ACCESS
))) return;
3051 res
= RegDeleteTreeW( hkey
, NULL
);
3052 if (res
) TRACE("failed to delete subtree of %s (%d)\n", debugstr_w(path
), res
);
3053 delete_key( comp
, root
, path
);
3054 RegCloseKey( hkey
);
3057 static UINT
ITERATE_RemoveRegistryValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
3059 MSIPACKAGE
*package
= param
;
3060 LPCWSTR component
, name
, key_str
, root_key_str
;
3061 LPWSTR deformated_key
, deformated_name
, ui_key_str
;
3064 BOOL delete_key
= FALSE
;
3069 msi_ui_progress( package
, 2, REG_PROGRESS_VALUE
, 0, 0 );
3071 component
= MSI_RecordGetString( row
, 6 );
3072 comp
= msi_get_loaded_component( package
, component
);
3074 return ERROR_SUCCESS
;
3076 comp
->Action
= msi_get_component_action( package
, comp
);
3077 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
3079 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
3080 return ERROR_SUCCESS
;
3083 name
= MSI_RecordGetString( row
, 4 );
3084 if (MSI_RecordIsNull( row
, 5 ) && name
)
3086 if (name
[0] == '+' && !name
[1])
3087 return ERROR_SUCCESS
;
3088 if ((name
[0] == '-' || name
[0] == '*') && !name
[1])
3095 root
= MSI_RecordGetInteger( row
, 2 );
3096 key_str
= MSI_RecordGetString( row
, 3 );
3098 root_key_str
= get_root_key( package
, root
, &hkey_root
);
3100 return ERROR_SUCCESS
;
3102 deformat_string( package
, key_str
, &deformated_key
);
3103 size
= strlenW( deformated_key
) + strlenW( root_key_str
) + 1;
3104 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
3105 strcpyW( ui_key_str
, root_key_str
);
3106 strcatW( ui_key_str
, deformated_key
);
3108 deformat_string( package
, name
, &deformated_name
);
3110 if (delete_key
) delete_tree( comp
, hkey_root
, deformated_key
);
3111 else delete_value( comp
, hkey_root
, deformated_key
, deformated_name
);
3112 msi_free( deformated_key
);
3114 uirow
= MSI_CreateRecord( 2 );
3115 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
3116 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
3117 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
3118 msiobj_release( &uirow
->hdr
);
3120 msi_free( ui_key_str
);
3121 msi_free( deformated_name
);
3122 return ERROR_SUCCESS
;
3125 static UINT
ITERATE_RemoveRegistryValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
3127 MSIPACKAGE
*package
= param
;
3128 LPCWSTR component
, name
, key_str
, root_key_str
;
3129 LPWSTR deformated_key
, deformated_name
, ui_key_str
;
3132 BOOL delete_key
= FALSE
;
3137 component
= MSI_RecordGetString( row
, 5 );
3138 comp
= msi_get_loaded_component( package
, component
);
3140 return ERROR_SUCCESS
;
3142 comp
->Action
= msi_get_component_action( package
, comp
);
3143 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
3145 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
3146 return ERROR_SUCCESS
;
3149 if ((name
= MSI_RecordGetString( row
, 4 )))
3151 if (name
[0] == '-' && !name
[1])
3158 root
= MSI_RecordGetInteger( row
, 2 );
3159 key_str
= MSI_RecordGetString( row
, 3 );
3161 root_key_str
= get_root_key( package
, root
, &hkey_root
);
3163 return ERROR_SUCCESS
;
3165 deformat_string( package
, key_str
, &deformated_key
);
3166 size
= strlenW( deformated_key
) + strlenW( root_key_str
) + 1;
3167 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
3168 strcpyW( ui_key_str
, root_key_str
);
3169 strcatW( ui_key_str
, deformated_key
);
3171 deformat_string( package
, name
, &deformated_name
);
3173 if (delete_key
) delete_tree( comp
, hkey_root
, deformated_key
);
3174 else delete_value( comp
, hkey_root
, deformated_key
, deformated_name
);
3175 msi_free( deformated_key
);
3177 uirow
= MSI_CreateRecord( 2 );
3178 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
3179 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
3180 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
3181 msiobj_release( &uirow
->hdr
);
3183 msi_free( ui_key_str
);
3184 msi_free( deformated_name
);
3185 return ERROR_SUCCESS
;
3188 static UINT
ACTION_RemoveRegistryValues( MSIPACKAGE
*package
)
3190 static const WCHAR registry_query
[] = {
3191 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3192 '`','R','e','g','i','s','t','r','y','`',0};
3193 static const WCHAR remove_registry_query
[] = {
3194 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3195 '`','R','e','m','o','v','e','R','e','g','i','s','t','r','y','`',0};
3199 rc
= MSI_DatabaseOpenViewW( package
->db
, registry_query
, &view
);
3200 if (rc
== ERROR_SUCCESS
)
3202 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnUninstall
, package
);
3203 msiobj_release( &view
->hdr
);
3204 if (rc
!= ERROR_SUCCESS
)
3207 rc
= MSI_DatabaseOpenViewW( package
->db
, remove_registry_query
, &view
);
3208 if (rc
== ERROR_SUCCESS
)
3210 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnInstall
, package
);
3211 msiobj_release( &view
->hdr
);
3212 if (rc
!= ERROR_SUCCESS
)
3215 return ERROR_SUCCESS
;
3218 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
3220 return ERROR_SUCCESS
;
3224 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
3226 static const WCHAR query
[]= {
3227 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3228 '`','R','e','g','i','s','t','r','y','`',0};
3230 DWORD total
= 0, count
= 0;
3232 MSIFEATURE
*feature
;
3236 TRACE("InstallValidate\n");
3238 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
3239 if (rc
== ERROR_SUCCESS
)
3241 rc
= MSI_IterateRecords( view
, &count
, NULL
, package
);
3242 msiobj_release( &view
->hdr
);
3243 if (rc
!= ERROR_SUCCESS
)
3245 total
+= count
* REG_PROGRESS_VALUE
;
3247 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
3248 total
+= COMPONENT_PROGRESS_VALUE
;
3250 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
3251 total
+= file
->FileSize
;
3253 msi_ui_progress( package
, 0, total
, 0, 0 );
3255 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3257 TRACE("Feature: %s Installed %d Request %d Action %d\n",
3258 debugstr_w(feature
->Feature
), feature
->Installed
,
3259 feature
->ActionRequest
, feature
->Action
);
3261 return ERROR_SUCCESS
;
3264 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
3266 MSIPACKAGE
* package
= param
;
3267 LPCWSTR cond
= NULL
;
3268 LPCWSTR message
= NULL
;
3271 static const WCHAR title
[]=
3272 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3274 cond
= MSI_RecordGetString(row
,1);
3276 r
= MSI_EvaluateConditionW(package
,cond
);
3277 if (r
== MSICONDITION_FALSE
)
3279 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
3282 message
= MSI_RecordGetString(row
,2);
3283 deformat_string(package
,message
,&deformated
);
3284 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
3285 msi_free(deformated
);
3288 return ERROR_INSTALL_FAILURE
;
3291 return ERROR_SUCCESS
;
3294 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
3296 static const WCHAR query
[] = {
3297 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3298 '`','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','`',0};
3302 TRACE("Checking launch conditions\n");
3304 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
3305 if (rc
!= ERROR_SUCCESS
)
3306 return ERROR_SUCCESS
;
3308 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
3309 msiobj_release(&view
->hdr
);
3313 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, MSICOMPONENT
*cmp
)
3317 return strdupW( msi_get_target_folder( package
, cmp
->Directory
) );
3319 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
3321 static const WCHAR query
[] = {
3322 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3323 '`','R','e','g','i','s','t','r','y','`',' ','W','H','E','R','E',' ',
3324 '`','R','e','g','i','s','t','r','y','`',' ','=',' ' ,'\'','%','s','\'',0};
3325 static const WCHAR fmt
[] = {'%','0','2','i',':','\\','%','s','\\',0};
3326 static const WCHAR fmt2
[]= {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3329 LPWSTR deformated
, buffer
, deformated_name
;
3332 row
= MSI_QueryGetRecord(package
->db
, query
, cmp
->KeyPath
);
3336 root
= MSI_RecordGetInteger(row
,2);
3337 key
= MSI_RecordGetString(row
, 3);
3338 name
= MSI_RecordGetString(row
, 4);
3339 deformat_string(package
, key
, &deformated
);
3340 deformat_string(package
, name
, &deformated_name
);
3342 len
= strlenW(deformated
) + 6;
3343 if (deformated_name
)
3344 len
+=strlenW(deformated_name
);
3346 buffer
= msi_alloc( len
*sizeof(WCHAR
));
3348 if (deformated_name
)
3349 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
3351 sprintfW(buffer
,fmt
,root
,deformated
);
3353 msi_free(deformated
);
3354 msi_free(deformated_name
);
3355 msiobj_release(&row
->hdr
);
3359 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
3361 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3366 MSIFILE
*file
= msi_get_loaded_file( package
, cmp
->KeyPath
);
3369 return strdupW( file
->TargetPath
);
3374 static HKEY
openSharedDLLsKey(void)
3377 static const WCHAR path
[] =
3378 {'S','o','f','t','w','a','r','e','\\',
3379 'M','i','c','r','o','s','o','f','t','\\',
3380 'W','i','n','d','o','w','s','\\',
3381 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3382 'S','h','a','r','e','d','D','L','L','s',0};
3384 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
3388 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
3393 DWORD sz
= sizeof(count
);
3396 hkey
= openSharedDLLsKey();
3397 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
3398 if (rc
!= ERROR_SUCCESS
)
3404 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
3408 hkey
= openSharedDLLsKey();
3410 msi_reg_set_val_dword( hkey
, path
, count
);
3412 RegDeleteValueW(hkey
,path
);
3417 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, MSICOMPONENT
*comp
)
3419 MSIFEATURE
*feature
;
3423 /* only refcount DLLs */
3424 if (comp
->KeyPath
== NULL
||
3426 comp
->Attributes
& msidbComponentAttributesRegistryKeyPath
||
3427 comp
->Attributes
& msidbComponentAttributesODBCDataSource
)
3431 count
= ACTION_GetSharedDLLsCount( comp
->FullKeypath
);
3432 write
= (count
> 0);
3434 if (comp
->Attributes
& msidbComponentAttributesSharedDllRefCount
)
3438 /* increment counts */
3439 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3443 if (msi_get_feature_action( package
, feature
) != INSTALLSTATE_LOCAL
)
3446 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3448 if ( cl
->component
== comp
)
3453 /* decrement counts */
3454 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3458 if (msi_get_feature_action( package
, feature
) != INSTALLSTATE_ABSENT
)
3461 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3463 if ( cl
->component
== comp
)
3468 /* ref count all the files in the component */
3473 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
3475 if (file
->Component
== comp
)
3476 ACTION_WriteSharedDLLsCount( file
->TargetPath
, count
);
3480 /* add a count for permanent */
3481 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
3484 comp
->RefCount
= count
;
3487 ACTION_WriteSharedDLLsCount( comp
->FullKeypath
, comp
->RefCount
);
3490 static WCHAR
*build_full_keypath( MSIPACKAGE
*package
, MSICOMPONENT
*comp
)
3494 const WCHAR prefixW
[] = {'<','\\',0};
3495 DWORD len
= strlenW( prefixW
) + strlenW( comp
->assembly
->display_name
);
3496 WCHAR
*keypath
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
3500 strcpyW( keypath
, prefixW
);
3501 strcatW( keypath
, comp
->assembly
->display_name
);
3505 return resolve_keypath( package
, comp
);
3508 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
3510 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
], squashed_cc
[SQUASHED_GUID_SIZE
];
3517 squash_guid( package
->ProductCode
, squashed_pc
);
3518 msi_set_sourcedir_props(package
, FALSE
);
3520 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
3523 INSTALLSTATE action
;
3525 msi_ui_progress( package
, 2, COMPONENT_PROGRESS_VALUE
, 0, 0 );
3526 if (!comp
->ComponentId
)
3529 squash_guid( comp
->ComponentId
, squashed_cc
);
3530 msi_free( comp
->FullKeypath
);
3531 comp
->FullKeypath
= build_full_keypath( package
, comp
);
3533 ACTION_RefCountComponent( package
, comp
);
3535 if (package
->need_rollback
) action
= comp
->Installed
;
3536 else action
= comp
->ActionRequest
;
3538 TRACE("Component %s (%s) Keypath=%s RefCount=%u Clients=%u Action=%u\n",
3539 debugstr_w(comp
->Component
), debugstr_w(squashed_cc
),
3540 debugstr_w(comp
->FullKeypath
), comp
->RefCount
, comp
->num_clients
, action
);
3542 if (action
== INSTALLSTATE_LOCAL
|| action
== INSTALLSTATE_SOURCE
)
3544 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3545 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, szLocalSid
, &hkey
, TRUE
);
3547 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, NULL
, &hkey
, TRUE
);
3549 if (rc
!= ERROR_SUCCESS
)
3552 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
3554 static const WCHAR szPermKey
[] =
3555 { '0','0','0','0','0','0','0','0','0','0','0','0',
3556 '0','0','0','0','0','0','0','0','0','0','0','0',
3557 '0','0','0','0','0','0','0','0',0 };
3559 msi_reg_set_val_str(hkey
, szPermKey
, comp
->FullKeypath
);
3561 if (action
== INSTALLSTATE_LOCAL
)
3562 msi_reg_set_val_str( hkey
, squashed_pc
, comp
->FullKeypath
);
3568 WCHAR source
[MAX_PATH
];
3569 WCHAR base
[MAX_PATH
];
3572 static const WCHAR fmt
[] = {'%','0','2','d','\\',0};
3573 static const WCHAR query
[] = {
3574 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3575 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
3576 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
3577 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
3578 '`','D','i','s','k','I','d','`',0};
3580 if (!comp
->KeyPath
|| !(file
= msi_get_loaded_file(package
, comp
->KeyPath
)))
3583 if (!(row
= MSI_QueryGetRecord(package
->db
, query
, file
->Sequence
)))
3584 return ERROR_FUNCTION_FAILED
;
3586 sprintfW(source
, fmt
, MSI_RecordGetInteger(row
, 1));
3587 ptr2
= strrchrW(source
, '\\') + 1;
3588 msiobj_release(&row
->hdr
);
3590 lstrcpyW(base
, package
->PackagePath
);
3591 ptr
= strrchrW(base
, '\\');
3594 sourcepath
= msi_resolve_file_source(package
, file
);
3595 ptr
= sourcepath
+ lstrlenW(base
);
3596 lstrcpyW(ptr2
, ptr
);
3597 msi_free(sourcepath
);
3599 msi_reg_set_val_str( hkey
, squashed_pc
, source
);
3603 else if (action
== INSTALLSTATE_ABSENT
)
3605 if (comp
->num_clients
<= 0)
3607 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3608 rc
= MSIREG_DeleteUserDataComponentKey( comp
->ComponentId
, szLocalSid
);
3610 rc
= MSIREG_DeleteUserDataComponentKey( comp
->ComponentId
, NULL
);
3612 if (rc
!= ERROR_SUCCESS
) WARN( "failed to delete component key %u\n", rc
);
3618 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3619 rc
= MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, szLocalSid
, &hkey
, FALSE
);
3621 rc
= MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, NULL
, &hkey
, FALSE
);
3623 if (rc
!= ERROR_SUCCESS
)
3625 WARN( "failed to open component key %u\n", rc
);
3628 res
= RegDeleteValueW( hkey
, squashed_pc
);
3630 if (res
) WARN( "failed to delete component value %d\n", res
);
3635 uirow
= MSI_CreateRecord(3);
3636 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
3637 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
3638 MSI_RecordSetStringW(uirow
,3,comp
->FullKeypath
);
3639 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
3640 msiobj_release( &uirow
->hdr
);
3642 return ERROR_SUCCESS
;
3653 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
3654 LPWSTR lpszName
, LONG_PTR lParam
)
3657 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
3658 static const WCHAR fmt
[] = {'%','s','\\','%','i',0};
3662 if (!IS_INTRESOURCE(lpszName
))
3664 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
3668 sz
= strlenW(tl_struct
->source
)+4;
3669 sz
*= sizeof(WCHAR
);
3671 if ((INT_PTR
)lpszName
== 1)
3672 tl_struct
->path
= strdupW(tl_struct
->source
);
3675 tl_struct
->path
= msi_alloc(sz
);
3676 sprintfW(tl_struct
->path
,fmt
,tl_struct
->source
, lpszName
);
3679 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
3680 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
3683 msi_free(tl_struct
->path
);
3684 tl_struct
->path
= NULL
;
3689 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
3690 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
3692 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3696 msi_free(tl_struct
->path
);
3697 tl_struct
->path
= NULL
;
3699 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3700 ITypeLib_Release(tl_struct
->ptLib
);
3705 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
3707 MSIPACKAGE
* package
= param
;
3711 typelib_struct tl_struct
;
3716 component
= MSI_RecordGetString(row
,3);
3717 comp
= msi_get_loaded_component(package
,component
);
3719 return ERROR_SUCCESS
;
3721 comp
->Action
= msi_get_component_action( package
, comp
);
3722 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
3724 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
3725 return ERROR_SUCCESS
;
3728 if (!comp
->KeyPath
|| !(file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
3730 TRACE("component has no key path\n");
3731 return ERROR_SUCCESS
;
3733 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
3735 module
= LoadLibraryExW( file
->TargetPath
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
3739 guid
= MSI_RecordGetString(row
,1);
3740 CLSIDFromString( guid
, &tl_struct
.clsid
);
3741 tl_struct
.source
= strdupW( file
->TargetPath
);
3742 tl_struct
.path
= NULL
;
3744 EnumResourceNamesW(module
, szTYPELIB
, Typelib_EnumResNameProc
,
3745 (LONG_PTR
)&tl_struct
);
3749 LPCWSTR helpid
, help_path
= NULL
;
3752 helpid
= MSI_RecordGetString(row
,6);
3754 if (helpid
) help_path
= msi_get_target_folder( package
, helpid
);
3755 res
= RegisterTypeLib( tl_struct
.ptLib
, tl_struct
.path
, (OLECHAR
*)help_path
);
3758 ERR("Failed to register type library %s\n", debugstr_w(tl_struct
.path
));
3760 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
3762 ITypeLib_Release(tl_struct
.ptLib
);
3763 msi_free(tl_struct
.path
);
3765 else ERR("Failed to load type library %s\n", debugstr_w(tl_struct
.source
));
3767 FreeLibrary(module
);
3768 msi_free(tl_struct
.source
);
3772 hr
= LoadTypeLibEx(file
->TargetPath
, REGKIND_REGISTER
, &tlib
);
3775 ERR("Failed to load type library: %08x\n", hr
);
3776 return ERROR_INSTALL_FAILURE
;
3779 ITypeLib_Release(tlib
);
3782 return ERROR_SUCCESS
;
3785 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
3787 static const WCHAR query
[] = {
3788 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3789 '`','T','y','p','e','L','i','b','`',0};
3793 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
3794 if (rc
!= ERROR_SUCCESS
)
3795 return ERROR_SUCCESS
;
3797 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
3798 msiobj_release(&view
->hdr
);
3802 static UINT
ITERATE_UnregisterTypeLibraries( MSIRECORD
*row
, LPVOID param
)
3804 MSIPACKAGE
*package
= param
;
3805 LPCWSTR component
, guid
;
3813 component
= MSI_RecordGetString( row
, 3 );
3814 comp
= msi_get_loaded_component( package
, component
);
3816 return ERROR_SUCCESS
;
3818 comp
->Action
= msi_get_component_action( package
, comp
);
3819 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
3821 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
3822 return ERROR_SUCCESS
;
3824 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
3826 guid
= MSI_RecordGetString( row
, 1 );
3827 CLSIDFromString( guid
, &libid
);
3828 version
= MSI_RecordGetInteger( row
, 4 );
3829 language
= MSI_RecordGetInteger( row
, 2 );
3832 syskind
= SYS_WIN64
;
3834 syskind
= SYS_WIN32
;
3837 hr
= UnRegisterTypeLib( &libid
, (version
>> 8) & 0xffff, version
& 0xff, language
, syskind
);
3840 WARN("Failed to unregister typelib: %08x\n", hr
);
3843 return ERROR_SUCCESS
;
3846 static UINT
ACTION_UnregisterTypeLibraries( MSIPACKAGE
*package
)
3848 static const WCHAR query
[] = {
3849 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3850 '`','T','y','p','e','L','i','b','`',0};
3854 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
3855 if (rc
!= ERROR_SUCCESS
)
3856 return ERROR_SUCCESS
;
3858 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnregisterTypeLibraries
, package
);
3859 msiobj_release( &view
->hdr
);
3863 static WCHAR
*get_link_file( MSIPACKAGE
*package
, MSIRECORD
*row
)
3865 static const WCHAR szlnk
[] = {'.','l','n','k',0};
3866 LPCWSTR directory
, extension
, link_folder
;
3867 LPWSTR link_file
, filename
;
3869 directory
= MSI_RecordGetString( row
, 2 );
3870 link_folder
= msi_get_target_folder( package
, directory
);
3873 ERR("unable to resolve folder %s\n", debugstr_w(directory
));
3876 /* may be needed because of a bug somewhere else */
3877 msi_create_full_path( link_folder
);
3879 filename
= msi_dup_record_field( row
, 3 );
3880 msi_reduce_to_long_filename( filename
);
3882 extension
= strrchrW( filename
, '.' );
3883 if (!extension
|| strcmpiW( extension
, szlnk
))
3885 int len
= strlenW( filename
);
3886 filename
= msi_realloc( filename
, len
* sizeof(WCHAR
) + sizeof(szlnk
) );
3887 memcpy( filename
+ len
, szlnk
, sizeof(szlnk
) );
3889 link_file
= msi_build_directory_name( 2, link_folder
, filename
);
3890 msi_free( filename
);
3895 WCHAR
*msi_build_icon_path( MSIPACKAGE
*package
, const WCHAR
*icon_name
)
3897 static const WCHAR szMicrosoft
[] = {'M','i','c','r','o','s','o','f','t','\\',0};
3898 static const WCHAR szInstaller
[] = {'I','n','s','t','a','l','l','e','r','\\',0};
3899 WCHAR
*folder
, *dest
, *path
;
3901 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3902 folder
= msi_dup_property( package
->db
, szWindowsFolder
);
3905 WCHAR
*appdata
= msi_dup_property( package
->db
, szAppDataFolder
);
3906 folder
= msi_build_directory_name( 2, appdata
, szMicrosoft
);
3907 msi_free( appdata
);
3909 dest
= msi_build_directory_name( 3, folder
, szInstaller
, package
->ProductCode
);
3910 msi_create_full_path( dest
);
3911 path
= msi_build_directory_name( 2, dest
, icon_name
);
3917 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
3919 MSIPACKAGE
*package
= param
;
3920 LPWSTR link_file
, deformated
, path
;
3921 LPCWSTR component
, target
;
3923 IShellLinkW
*sl
= NULL
;
3924 IPersistFile
*pf
= NULL
;
3927 component
= MSI_RecordGetString(row
, 4);
3928 comp
= msi_get_loaded_component(package
, component
);
3930 return ERROR_SUCCESS
;
3932 comp
->Action
= msi_get_component_action( package
, comp
);
3933 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
3935 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
3936 return ERROR_SUCCESS
;
3938 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
3940 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3941 &IID_IShellLinkW
, (LPVOID
*) &sl
);
3945 ERR("CLSID_ShellLink not available\n");
3949 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
3952 ERR("QueryInterface(IID_IPersistFile) failed\n");
3956 target
= MSI_RecordGetString(row
, 5);
3957 if (strchrW(target
, '['))
3959 deformat_string( package
, target
, &path
);
3960 TRACE("target path is %s\n", debugstr_w(path
));
3961 IShellLinkW_SetPath( sl
, path
);
3966 FIXME("poorly handled shortcut format, advertised shortcut\n");
3967 path
= resolve_keypath( package
, comp
);
3968 IShellLinkW_SetPath( sl
, path
);
3972 if (!MSI_RecordIsNull(row
,6))
3974 LPCWSTR arguments
= MSI_RecordGetString(row
, 6);
3975 deformat_string(package
, arguments
, &deformated
);
3976 IShellLinkW_SetArguments(sl
,deformated
);
3977 msi_free(deformated
);
3980 if (!MSI_RecordIsNull(row
,7))
3982 LPCWSTR description
= MSI_RecordGetString(row
, 7);
3983 IShellLinkW_SetDescription(sl
, description
);
3986 if (!MSI_RecordIsNull(row
,8))
3987 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
3989 if (!MSI_RecordIsNull(row
,9))
3992 LPCWSTR icon
= MSI_RecordGetString(row
, 9);
3994 path
= msi_build_icon_path(package
, icon
);
3995 index
= MSI_RecordGetInteger(row
,10);
3997 /* no value means 0 */
3998 if (index
== MSI_NULL_INTEGER
)
4001 IShellLinkW_SetIconLocation(sl
, path
, index
);
4005 if (!MSI_RecordIsNull(row
,11))
4006 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
4008 if (!MSI_RecordIsNull(row
,12))
4010 LPCWSTR full_path
, wkdir
= MSI_RecordGetString( row
, 12 );
4011 full_path
= msi_get_target_folder( package
, wkdir
);
4012 if (full_path
) IShellLinkW_SetWorkingDirectory( sl
, full_path
);
4014 link_file
= get_link_file(package
, row
);
4016 TRACE("Writing shortcut to %s\n", debugstr_w(link_file
));
4017 IPersistFile_Save(pf
, link_file
, FALSE
);
4018 msi_free(link_file
);
4022 IPersistFile_Release( pf
);
4024 IShellLinkW_Release( sl
);
4026 return ERROR_SUCCESS
;
4029 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
4031 static const WCHAR query
[] = {
4032 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4033 '`','S','h','o','r','t','c','u','t','`',0};
4038 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
4039 if (rc
!= ERROR_SUCCESS
)
4040 return ERROR_SUCCESS
;
4042 res
= CoInitialize( NULL
);
4044 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
4045 msiobj_release(&view
->hdr
);
4047 if (SUCCEEDED(res
)) CoUninitialize();
4051 static UINT
ITERATE_RemoveShortcuts( MSIRECORD
*row
, LPVOID param
)
4053 MSIPACKAGE
*package
= param
;
4058 component
= MSI_RecordGetString( row
, 4 );
4059 comp
= msi_get_loaded_component( package
, component
);
4061 return ERROR_SUCCESS
;
4063 comp
->Action
= msi_get_component_action( package
, comp
);
4064 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
4066 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
4067 return ERROR_SUCCESS
;
4069 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
4071 link_file
= get_link_file( package
, row
);
4073 TRACE("Removing shortcut file %s\n", debugstr_w( link_file
));
4074 if (!DeleteFileW( link_file
))
4076 WARN("Failed to remove shortcut file %u\n", GetLastError());
4078 msi_free( link_file
);
4080 return ERROR_SUCCESS
;
4083 static UINT
ACTION_RemoveShortcuts( MSIPACKAGE
*package
)
4085 static const WCHAR query
[] = {
4086 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4087 '`','S','h','o','r','t','c','u','t','`',0};
4091 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4092 if (rc
!= ERROR_SUCCESS
)
4093 return ERROR_SUCCESS
;
4095 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveShortcuts
, package
);
4096 msiobj_release( &view
->hdr
);
4100 static UINT
ITERATE_PublishIcon(MSIRECORD
*row
, LPVOID param
)
4102 MSIPACKAGE
* package
= param
;
4110 FileName
= MSI_RecordGetString(row
,1);
4113 ERR("Unable to get FileName\n");
4114 return ERROR_SUCCESS
;
4117 FilePath
= msi_build_icon_path(package
, FileName
);
4119 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
4121 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
4122 FILE_ATTRIBUTE_NORMAL
, NULL
);
4124 if (the_file
== INVALID_HANDLE_VALUE
)
4126 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
4128 return ERROR_SUCCESS
;
4135 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
4136 if (rc
!= ERROR_SUCCESS
)
4138 ERR("Failed to get stream\n");
4139 DeleteFileW(FilePath
);
4142 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
4143 } while (sz
== 1024);
4146 CloseHandle(the_file
);
4148 return ERROR_SUCCESS
;
4151 static UINT
msi_publish_icons(MSIPACKAGE
*package
)
4153 static const WCHAR query
[]= {
4154 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4155 '`','I','c','o','n','`',0};
4159 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
4160 if (r
== ERROR_SUCCESS
)
4162 r
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishIcon
, package
);
4163 msiobj_release(&view
->hdr
);
4164 if (r
!= ERROR_SUCCESS
)
4167 return ERROR_SUCCESS
;
4170 static UINT
msi_publish_sourcelist(MSIPACKAGE
*package
, HKEY hkey
)
4176 MSISOURCELISTINFO
*info
;
4178 r
= RegCreateKeyW(hkey
, szSourceList
, &source
);
4179 if (r
!= ERROR_SUCCESS
)
4182 RegCloseKey(source
);
4184 buffer
= strrchrW(package
->PackagePath
, '\\') + 1;
4185 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4186 package
->Context
, MSICODE_PRODUCT
,
4187 INSTALLPROPERTY_PACKAGENAMEW
, buffer
);
4188 if (r
!= ERROR_SUCCESS
)
4191 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4192 package
->Context
, MSICODE_PRODUCT
,
4193 INSTALLPROPERTY_MEDIAPACKAGEPATHW
, szEmpty
);
4194 if (r
!= ERROR_SUCCESS
)
4197 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4198 package
->Context
, MSICODE_PRODUCT
,
4199 INSTALLPROPERTY_DISKPROMPTW
, szEmpty
);
4200 if (r
!= ERROR_SUCCESS
)
4203 LIST_FOR_EACH_ENTRY(info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
4205 if (!strcmpW( info
->property
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
4206 msi_set_last_used_source(package
->ProductCode
, NULL
, info
->context
,
4207 info
->options
, info
->value
);
4209 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4210 info
->context
, info
->options
,
4211 info
->property
, info
->value
);
4214 LIST_FOR_EACH_ENTRY(disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
4216 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
4217 disk
->context
, disk
->options
,
4218 disk
->disk_id
, disk
->volume_label
, disk
->disk_prompt
);
4221 return ERROR_SUCCESS
;
4224 static UINT
msi_publish_product_properties(MSIPACKAGE
*package
, HKEY hkey
)
4226 static const WCHAR szARPProductIcon
[] =
4227 {'A','R','P','P','R','O','D','U','C','T','I','C','O','N',0};
4228 static const WCHAR szAssignment
[] =
4229 {'A','s','s','i','g','n','m','e','n','t',0};
4230 static const WCHAR szAdvertiseFlags
[] =
4231 {'A','d','v','e','r','t','i','s','e','F','l','a','g','s',0};
4232 static const WCHAR szClients
[] =
4233 {'C','l','i','e','n','t','s',0};
4234 static const WCHAR szColon
[] = {':',0};
4235 MSIHANDLE hdb
, suminfo
;
4236 WCHAR
*buffer
, *ptr
, guids
[MAX_PATH
], packcode
[SQUASHED_GUID_SIZE
];
4240 buffer
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
4241 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTNAMEW
, buffer
);
4244 langid
= msi_get_property_int(package
->db
, szProductLanguage
, 0);
4245 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
4248 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
, 0);
4250 buffer
= msi_dup_property(package
->db
, szARPProductIcon
);
4253 LPWSTR path
= msi_build_icon_path(package
, buffer
);
4254 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTICONW
, path
);
4259 buffer
= msi_dup_property(package
->db
, szProductVersion
);
4262 DWORD verdword
= msi_version_str_to_dword(buffer
);
4263 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
4267 msi_reg_set_val_dword(hkey
, szAssignment
, 0);
4268 msi_reg_set_val_dword(hkey
, szAdvertiseFlags
, 0x184);
4269 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_INSTANCETYPEW
, 0);
4270 msi_reg_set_val_str(hkey
, szClients
, szColon
);
4272 hdb
= alloc_msihandle(&package
->db
->hdr
);
4274 return ERROR_NOT_ENOUGH_MEMORY
;
4276 r
= MsiGetSummaryInformationW(hdb
, NULL
, 0, &suminfo
);
4277 MsiCloseHandle(hdb
);
4278 if (r
!= ERROR_SUCCESS
)
4282 r
= MsiSummaryInfoGetPropertyW(suminfo
, PID_REVNUMBER
, NULL
, NULL
,
4283 NULL
, guids
, &size
);
4284 if (r
!= ERROR_SUCCESS
)
4287 ptr
= strchrW(guids
, ';');
4289 squash_guid(guids
, packcode
);
4290 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PACKAGECODEW
, packcode
);
4293 MsiCloseHandle(suminfo
);
4294 return ERROR_SUCCESS
;
4297 static UINT
msi_publish_upgrade_code(MSIPACKAGE
*package
)
4301 WCHAR
*upgrade
, squashed_pc
[SQUASHED_GUID_SIZE
];
4303 upgrade
= msi_dup_property(package
->db
, szUpgradeCode
);
4305 return ERROR_SUCCESS
;
4307 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
4308 r
= MSIREG_OpenClassesUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
4310 r
= MSIREG_OpenUserUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
4312 if (r
!= ERROR_SUCCESS
)
4314 WARN("failed to open upgrade code key\n");
4316 return ERROR_SUCCESS
;
4318 squash_guid(package
->ProductCode
, squashed_pc
);
4319 msi_reg_set_val_str(hkey
, squashed_pc
, NULL
);
4322 return ERROR_SUCCESS
;
4325 static BOOL
msi_check_publish(MSIPACKAGE
*package
)
4327 MSIFEATURE
*feature
;
4329 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4331 feature
->Action
= msi_get_feature_action( package
, feature
);
4332 if (feature
->Action
== INSTALLSTATE_LOCAL
|| feature
->Action
== INSTALLSTATE_SOURCE
)
4339 static BOOL
msi_check_unpublish(MSIPACKAGE
*package
)
4341 MSIFEATURE
*feature
;
4343 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4345 feature
->Action
= msi_get_feature_action( package
, feature
);
4346 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
4353 static UINT
msi_publish_patches( MSIPACKAGE
*package
)
4355 static const WCHAR szAllPatches
[] = {'A','l','l','P','a','t','c','h','e','s',0};
4356 WCHAR patch_squashed
[GUID_SIZE
];
4357 HKEY patches_key
= NULL
, product_patches_key
= NULL
, product_key
;
4359 MSIPATCHINFO
*patch
;
4361 WCHAR
*p
, *all_patches
= NULL
;
4364 r
= MSIREG_OpenProductKey( package
->ProductCode
, NULL
, package
->Context
, &product_key
, TRUE
);
4365 if (r
!= ERROR_SUCCESS
)
4366 return ERROR_FUNCTION_FAILED
;
4368 res
= RegCreateKeyExW( product_key
, szPatches
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &patches_key
, NULL
);
4369 if (res
!= ERROR_SUCCESS
)
4371 r
= ERROR_FUNCTION_FAILED
;
4375 r
= MSIREG_OpenUserDataProductPatchesKey( package
->ProductCode
, package
->Context
, &product_patches_key
, TRUE
);
4376 if (r
!= ERROR_SUCCESS
)
4379 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
4381 squash_guid( patch
->patchcode
, patch_squashed
);
4382 len
+= strlenW( patch_squashed
) + 1;
4385 p
= all_patches
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
4389 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
4393 squash_guid( patch
->patchcode
, p
);
4394 p
+= strlenW( p
) + 1;
4396 res
= RegSetValueExW( patches_key
, patch_squashed
, 0, REG_SZ
,
4397 (const BYTE
*)patch
->transforms
,
4398 (strlenW(patch
->transforms
) + 1) * sizeof(WCHAR
) );
4399 if (res
!= ERROR_SUCCESS
)
4402 r
= MSIREG_OpenUserDataPatchKey( patch
->patchcode
, package
->Context
, &patch_key
, TRUE
);
4403 if (r
!= ERROR_SUCCESS
)
4406 res
= RegSetValueExW( patch_key
, szLocalPackage
, 0, REG_SZ
, (const BYTE
*)patch
->localfile
,
4407 (strlenW( patch
->localfile
) + 1) * sizeof(WCHAR
) );
4408 RegCloseKey( patch_key
);
4409 if (res
!= ERROR_SUCCESS
)
4412 if (patch
->filename
&& !CopyFileW( patch
->filename
, patch
->localfile
, FALSE
))
4414 res
= GetLastError();
4415 ERR("Unable to copy patch package %d\n", res
);
4418 res
= RegCreateKeyExW( product_patches_key
, patch_squashed
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &patch_key
, NULL
);
4419 if (res
!= ERROR_SUCCESS
)
4422 res
= RegSetValueExW( patch_key
, szState
, 0, REG_DWORD
, (const BYTE
*)&patch
->state
,
4423 sizeof(patch
->state
) );
4424 if (res
!= ERROR_SUCCESS
)
4426 RegCloseKey( patch_key
);
4430 res
= RegSetValueExW( patch_key
, szUninstallable
, 0, REG_DWORD
, (const BYTE
*)&patch
->uninstallable
,
4431 sizeof(patch
->uninstallable
) );
4432 RegCloseKey( patch_key
);
4433 if (res
!= ERROR_SUCCESS
)
4437 all_patches
[len
] = 0;
4438 res
= RegSetValueExW( patches_key
, szPatches
, 0, REG_MULTI_SZ
,
4439 (const BYTE
*)all_patches
, (len
+ 1) * sizeof(WCHAR
) );
4440 if (res
!= ERROR_SUCCESS
)
4443 res
= RegSetValueExW( product_patches_key
, szAllPatches
, 0, REG_MULTI_SZ
,
4444 (const BYTE
*)all_patches
, (len
+ 1) * sizeof(WCHAR
) );
4445 if (res
!= ERROR_SUCCESS
)
4446 r
= ERROR_FUNCTION_FAILED
;
4449 RegCloseKey( product_patches_key
);
4450 RegCloseKey( patches_key
);
4451 RegCloseKey( product_key
);
4452 msi_free( all_patches
);
4456 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
4459 HKEY hukey
= NULL
, hudkey
= NULL
;
4462 if (!list_empty(&package
->patches
))
4464 rc
= msi_publish_patches(package
);
4465 if (rc
!= ERROR_SUCCESS
)
4469 /* FIXME: also need to publish if the product is in advertise mode */
4470 if (!msi_check_publish(package
))
4471 return ERROR_SUCCESS
;
4473 rc
= MSIREG_OpenProductKey(package
->ProductCode
, NULL
, package
->Context
,
4475 if (rc
!= ERROR_SUCCESS
)
4478 rc
= MSIREG_OpenUserDataProductKey(package
->ProductCode
, package
->Context
,
4479 NULL
, &hudkey
, TRUE
);
4480 if (rc
!= ERROR_SUCCESS
)
4483 rc
= msi_publish_upgrade_code(package
);
4484 if (rc
!= ERROR_SUCCESS
)
4487 rc
= msi_publish_product_properties(package
, hukey
);
4488 if (rc
!= ERROR_SUCCESS
)
4491 rc
= msi_publish_sourcelist(package
, hukey
);
4492 if (rc
!= ERROR_SUCCESS
)
4495 rc
= msi_publish_icons(package
);
4498 uirow
= MSI_CreateRecord( 1 );
4499 MSI_RecordSetStringW( uirow
, 1, package
->ProductCode
);
4500 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4501 msiobj_release( &uirow
->hdr
);
4504 RegCloseKey(hudkey
);
4508 static WCHAR
*get_ini_file_name( MSIPACKAGE
*package
, MSIRECORD
*row
)
4510 WCHAR
*filename
, *ptr
, *folder
, *ret
;
4511 const WCHAR
*dirprop
;
4513 filename
= msi_dup_record_field( row
, 2 );
4514 if (filename
&& (ptr
= strchrW( filename
, '|' )))
4519 dirprop
= MSI_RecordGetString( row
, 3 );
4522 folder
= strdupW( msi_get_target_folder( package
, dirprop
) );
4523 if (!folder
) folder
= msi_dup_property( package
->db
, dirprop
);
4526 folder
= msi_dup_property( package
->db
, szWindowsFolder
);
4530 ERR("Unable to resolve folder %s\n", debugstr_w(dirprop
));
4531 msi_free( filename
);
4535 ret
= msi_build_directory_name( 2, folder
, ptr
);
4537 msi_free( filename
);
4542 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
4544 MSIPACKAGE
*package
= param
;
4545 LPCWSTR component
, section
, key
, value
, identifier
;
4546 LPWSTR deformated_section
, deformated_key
, deformated_value
, fullname
;
4551 component
= MSI_RecordGetString(row
, 8);
4552 comp
= msi_get_loaded_component(package
,component
);
4554 return ERROR_SUCCESS
;
4556 comp
->Action
= msi_get_component_action( package
, comp
);
4557 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
4559 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
4560 return ERROR_SUCCESS
;
4563 identifier
= MSI_RecordGetString(row
,1);
4564 section
= MSI_RecordGetString(row
,4);
4565 key
= MSI_RecordGetString(row
,5);
4566 value
= MSI_RecordGetString(row
,6);
4567 action
= MSI_RecordGetInteger(row
,7);
4569 deformat_string(package
,section
,&deformated_section
);
4570 deformat_string(package
,key
,&deformated_key
);
4571 deformat_string(package
,value
,&deformated_value
);
4573 fullname
= get_ini_file_name(package
, row
);
4577 TRACE("Adding value %s to section %s in %s\n",
4578 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
4579 debugstr_w(fullname
));
4580 WritePrivateProfileStringW(deformated_section
, deformated_key
,
4581 deformated_value
, fullname
);
4583 else if (action
== 1)
4586 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
4587 returned
, 10, fullname
);
4588 if (returned
[0] == 0)
4590 TRACE("Adding value %s to section %s in %s\n",
4591 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
4592 debugstr_w(fullname
));
4594 WritePrivateProfileStringW(deformated_section
, deformated_key
,
4595 deformated_value
, fullname
);
4598 else if (action
== 3)
4599 FIXME("Append to existing section not yet implemented\n");
4601 uirow
= MSI_CreateRecord(4);
4602 MSI_RecordSetStringW(uirow
,1,identifier
);
4603 MSI_RecordSetStringW(uirow
,2,deformated_section
);
4604 MSI_RecordSetStringW(uirow
,3,deformated_key
);
4605 MSI_RecordSetStringW(uirow
,4,deformated_value
);
4606 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4607 msiobj_release( &uirow
->hdr
);
4610 msi_free(deformated_key
);
4611 msi_free(deformated_value
);
4612 msi_free(deformated_section
);
4613 return ERROR_SUCCESS
;
4616 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
4618 static const WCHAR query
[] = {
4619 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4620 '`','I','n','i','F','i','l','e','`',0};
4624 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
4625 if (rc
!= ERROR_SUCCESS
)
4626 return ERROR_SUCCESS
;
4628 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
4629 msiobj_release(&view
->hdr
);
4633 static UINT
ITERATE_RemoveIniValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
4635 MSIPACKAGE
*package
= param
;
4636 LPCWSTR component
, section
, key
, value
, identifier
;
4637 LPWSTR deformated_section
, deformated_key
, deformated_value
, filename
;
4642 component
= MSI_RecordGetString( row
, 8 );
4643 comp
= msi_get_loaded_component( package
, component
);
4645 return ERROR_SUCCESS
;
4647 comp
->Action
= msi_get_component_action( package
, comp
);
4648 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
4650 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
4651 return ERROR_SUCCESS
;
4654 identifier
= MSI_RecordGetString( row
, 1 );
4655 section
= MSI_RecordGetString( row
, 4 );
4656 key
= MSI_RecordGetString( row
, 5 );
4657 value
= MSI_RecordGetString( row
, 6 );
4658 action
= MSI_RecordGetInteger( row
, 7 );
4660 deformat_string( package
, section
, &deformated_section
);
4661 deformat_string( package
, key
, &deformated_key
);
4662 deformat_string( package
, value
, &deformated_value
);
4664 if (action
== msidbIniFileActionAddLine
|| action
== msidbIniFileActionCreateLine
)
4666 filename
= get_ini_file_name( package
, row
);
4668 TRACE("Removing key %s from section %s in %s\n",
4669 debugstr_w(deformated_key
), debugstr_w(deformated_section
), debugstr_w(filename
));
4671 if (!WritePrivateProfileStringW( deformated_section
, deformated_key
, NULL
, filename
))
4673 WARN("Unable to remove key %u\n", GetLastError());
4675 msi_free( filename
);
4678 FIXME("Unsupported action %d\n", action
);
4681 uirow
= MSI_CreateRecord( 4 );
4682 MSI_RecordSetStringW( uirow
, 1, identifier
);
4683 MSI_RecordSetStringW( uirow
, 2, deformated_section
);
4684 MSI_RecordSetStringW( uirow
, 3, deformated_key
);
4685 MSI_RecordSetStringW( uirow
, 4, deformated_value
);
4686 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4687 msiobj_release( &uirow
->hdr
);
4689 msi_free( deformated_key
);
4690 msi_free( deformated_value
);
4691 msi_free( deformated_section
);
4692 return ERROR_SUCCESS
;
4695 static UINT
ITERATE_RemoveIniValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
4697 MSIPACKAGE
*package
= param
;
4698 LPCWSTR component
, section
, key
, value
, identifier
;
4699 LPWSTR deformated_section
, deformated_key
, deformated_value
, filename
;
4704 component
= MSI_RecordGetString( row
, 8 );
4705 comp
= msi_get_loaded_component( package
, component
);
4707 return ERROR_SUCCESS
;
4709 comp
->Action
= msi_get_component_action( package
, comp
);
4710 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
4712 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
4713 return ERROR_SUCCESS
;
4716 identifier
= MSI_RecordGetString( row
, 1 );
4717 section
= MSI_RecordGetString( row
, 4 );
4718 key
= MSI_RecordGetString( row
, 5 );
4719 value
= MSI_RecordGetString( row
, 6 );
4720 action
= MSI_RecordGetInteger( row
, 7 );
4722 deformat_string( package
, section
, &deformated_section
);
4723 deformat_string( package
, key
, &deformated_key
);
4724 deformat_string( package
, value
, &deformated_value
);
4726 if (action
== msidbIniFileActionRemoveLine
)
4728 filename
= get_ini_file_name( package
, row
);
4730 TRACE("Removing key %s from section %s in %s\n",
4731 debugstr_w(deformated_key
), debugstr_w(deformated_section
), debugstr_w(filename
));
4733 if (!WritePrivateProfileStringW( deformated_section
, deformated_key
, NULL
, filename
))
4735 WARN("Unable to remove key %u\n", GetLastError());
4737 msi_free( filename
);
4740 FIXME("Unsupported action %d\n", action
);
4742 uirow
= MSI_CreateRecord( 4 );
4743 MSI_RecordSetStringW( uirow
, 1, identifier
);
4744 MSI_RecordSetStringW( uirow
, 2, deformated_section
);
4745 MSI_RecordSetStringW( uirow
, 3, deformated_key
);
4746 MSI_RecordSetStringW( uirow
, 4, deformated_value
);
4747 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4748 msiobj_release( &uirow
->hdr
);
4750 msi_free( deformated_key
);
4751 msi_free( deformated_value
);
4752 msi_free( deformated_section
);
4753 return ERROR_SUCCESS
;
4756 static UINT
ACTION_RemoveIniValues( MSIPACKAGE
*package
)
4758 static const WCHAR query
[] = {
4759 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4760 '`','I','n','i','F','i','l','e','`',0};
4761 static const WCHAR remove_query
[] = {
4762 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4763 '`','R','e','m','o','v','e','I','n','i','F','i','l','e','`',0};
4767 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4768 if (rc
== ERROR_SUCCESS
)
4770 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveIniValuesOnUninstall
, package
);
4771 msiobj_release( &view
->hdr
);
4772 if (rc
!= ERROR_SUCCESS
)
4775 rc
= MSI_DatabaseOpenViewW( package
->db
, remove_query
, &view
);
4776 if (rc
== ERROR_SUCCESS
)
4778 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveIniValuesOnInstall
, package
);
4779 msiobj_release( &view
->hdr
);
4780 if (rc
!= ERROR_SUCCESS
)
4783 return ERROR_SUCCESS
;
4786 static void register_dll( const WCHAR
*dll
, BOOL unregister
)
4789 static const WCHAR regW
[] =
4790 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ','\"','%','s','\"',0};
4791 static const WCHAR unregW
[] =
4792 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ','/','u',' ','\"','%','s','\"',0};
4793 #else /* __REACTOS__ */
4794 static const WCHAR regW
[] =
4795 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','\"','%','s','\"',0};
4796 static const WCHAR unregW
[] =
4797 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','u',' ','\"','%','s','\"',0};
4798 #endif /* __REACTOS__ */
4799 PROCESS_INFORMATION pi
;
4803 if (!(cmd
= msi_alloc( strlenW(dll
) * sizeof(WCHAR
) + sizeof(unregW
) ))) return;
4805 if (unregister
) sprintfW( cmd
, unregW
, dll
);
4806 else sprintfW( cmd
, regW
, dll
);
4808 memset( &si
, 0, sizeof(STARTUPINFOW
) );
4809 if (CreateProcessW( NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
4811 CloseHandle( pi
.hThread
);
4812 msi_dialog_check_messages( pi
.hProcess
);
4813 CloseHandle( pi
.hProcess
);
4818 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
4820 MSIPACKAGE
*package
= param
;
4825 filename
= MSI_RecordGetString( row
, 1 );
4826 file
= msi_get_loaded_file( package
, filename
);
4829 WARN("unable to find file %s\n", debugstr_w(filename
));
4830 return ERROR_SUCCESS
;
4832 file
->Component
->Action
= msi_get_component_action( package
, file
->Component
);
4833 if (file
->Component
->Action
!= INSTALLSTATE_LOCAL
)
4835 TRACE("component not scheduled for installation %s\n", debugstr_w(file
->Component
->Component
));
4836 return ERROR_SUCCESS
;
4839 TRACE("Registering %s\n", debugstr_w( file
->TargetPath
));
4840 register_dll( file
->TargetPath
, FALSE
);
4842 uirow
= MSI_CreateRecord( 2 );
4843 MSI_RecordSetStringW( uirow
, 1, file
->File
);
4844 MSI_RecordSetStringW( uirow
, 2, file
->Component
->Directory
);
4845 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4846 msiobj_release( &uirow
->hdr
);
4848 return ERROR_SUCCESS
;
4851 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
4853 static const WCHAR query
[] = {
4854 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4855 '`','S','e','l','f','R','e','g','`',0};
4859 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
4860 if (rc
!= ERROR_SUCCESS
)
4861 return ERROR_SUCCESS
;
4863 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
4864 msiobj_release(&view
->hdr
);
4868 static UINT
ITERATE_SelfUnregModules( MSIRECORD
*row
, LPVOID param
)
4870 MSIPACKAGE
*package
= param
;
4875 filename
= MSI_RecordGetString( row
, 1 );
4876 file
= msi_get_loaded_file( package
, filename
);
4879 WARN("unable to find file %s\n", debugstr_w(filename
));
4880 return ERROR_SUCCESS
;
4882 file
->Component
->Action
= msi_get_component_action( package
, file
->Component
);
4883 if (file
->Component
->Action
!= INSTALLSTATE_ABSENT
)
4885 TRACE("component not scheduled for removal %s\n", debugstr_w(file
->Component
->Component
));
4886 return ERROR_SUCCESS
;
4889 TRACE("Unregistering %s\n", debugstr_w( file
->TargetPath
));
4890 register_dll( file
->TargetPath
, TRUE
);
4892 uirow
= MSI_CreateRecord( 2 );
4893 MSI_RecordSetStringW( uirow
, 1, file
->File
);
4894 MSI_RecordSetStringW( uirow
, 2, file
->Component
->Directory
);
4895 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4896 msiobj_release( &uirow
->hdr
);
4898 return ERROR_SUCCESS
;
4901 static UINT
ACTION_SelfUnregModules( MSIPACKAGE
*package
)
4903 static const WCHAR query
[] = {
4904 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4905 '`','S','e','l','f','R','e','g','`',0};
4909 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
4910 if (rc
!= ERROR_SUCCESS
)
4911 return ERROR_SUCCESS
;
4913 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_SelfUnregModules
, package
);
4914 msiobj_release( &view
->hdr
);
4918 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
4920 MSIFEATURE
*feature
;
4922 HKEY hkey
= NULL
, userdata
= NULL
;
4924 if (!msi_check_publish(package
))
4925 return ERROR_SUCCESS
;
4927 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4929 if (rc
!= ERROR_SUCCESS
)
4932 rc
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4934 if (rc
!= ERROR_SUCCESS
)
4937 /* here the guids are base 85 encoded */
4938 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
4944 BOOL absent
= FALSE
;
4947 if (feature
->Level
<= 0) continue;
4949 if (feature
->Action
!= INSTALLSTATE_LOCAL
&&
4950 feature
->Action
!= INSTALLSTATE_SOURCE
&&
4951 feature
->Action
!= INSTALLSTATE_ADVERTISED
) absent
= TRUE
;
4954 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4958 if (feature
->Feature_Parent
)
4959 size
+= strlenW( feature
->Feature_Parent
)+2;
4961 data
= msi_alloc(size
* sizeof(WCHAR
));
4964 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4966 MSICOMPONENT
* component
= cl
->component
;
4970 if (component
->ComponentId
)
4972 TRACE("From %s\n",debugstr_w(component
->ComponentId
));
4973 CLSIDFromString(component
->ComponentId
, &clsid
);
4974 encode_base85_guid(&clsid
,buf
);
4975 TRACE("to %s\n",debugstr_w(buf
));
4980 if (feature
->Feature_Parent
)
4982 static const WCHAR sep
[] = {'\2',0};
4984 strcatW(data
,feature
->Feature_Parent
);
4987 msi_reg_set_val_str( userdata
, feature
->Feature
, data
);
4991 if (feature
->Feature_Parent
)
4992 size
= strlenW(feature
->Feature_Parent
)*sizeof(WCHAR
);
4995 size
+= sizeof(WCHAR
);
4996 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
4997 (const BYTE
*)(feature
->Feature_Parent
? feature
->Feature_Parent
: szEmpty
),size
);
5001 size
+= 2*sizeof(WCHAR
);
5002 data
= msi_alloc(size
);
5005 if (feature
->Feature_Parent
)
5006 strcpyW( &data
[1], feature
->Feature_Parent
);
5007 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
5013 uirow
= MSI_CreateRecord( 1 );
5014 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
5015 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5016 msiobj_release( &uirow
->hdr
);
5017 /* FIXME: call msi_ui_progress? */
5022 RegCloseKey(userdata
);
5026 static UINT
msi_unpublish_feature(MSIPACKAGE
*package
, MSIFEATURE
*feature
)
5032 TRACE("unpublishing feature %s\n", debugstr_w(feature
->Feature
));
5034 r
= MSIREG_OpenFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
5036 if (r
== ERROR_SUCCESS
)
5038 RegDeleteValueW(hkey
, feature
->Feature
);
5042 r
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
5044 if (r
== ERROR_SUCCESS
)
5046 RegDeleteValueW(hkey
, feature
->Feature
);
5050 uirow
= MSI_CreateRecord( 1 );
5051 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
5052 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5053 msiobj_release( &uirow
->hdr
);
5055 return ERROR_SUCCESS
;
5058 static UINT
ACTION_UnpublishFeatures(MSIPACKAGE
*package
)
5060 MSIFEATURE
*feature
;
5062 if (!msi_check_unpublish(package
))
5063 return ERROR_SUCCESS
;
5065 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
5067 msi_unpublish_feature(package
, feature
);
5070 return ERROR_SUCCESS
;
5073 static UINT
msi_publish_install_properties(MSIPACKAGE
*package
, HKEY hkey
)
5077 WCHAR date
[9], *val
, *buffer
;
5078 const WCHAR
*prop
, *key
;
5080 static const WCHAR date_fmt
[] = {'%','i','%','0','2','i','%','0','2','i',0};
5081 static const WCHAR modpath_fmt
[] =
5082 {'M','s','i','E','x','e','c','.','e','x','e',' ',
5083 '/','I','[','P','r','o','d','u','c','t','C','o','d','e',']',0};
5084 static const WCHAR szModifyPath
[] =
5085 {'M','o','d','i','f','y','P','a','t','h',0};
5086 static const WCHAR szUninstallString
[] =
5087 {'U','n','i','n','s','t','a','l','l','S','t','r','i','n','g',0};
5088 static const WCHAR szEstimatedSize
[] =
5089 {'E','s','t','i','m','a','t','e','d','S','i','z','e',0};
5090 static const WCHAR szDisplayVersion
[] =
5091 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
5092 static const WCHAR szInstallSource
[] =
5093 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0};
5094 static const WCHAR szARPAUTHORIZEDCDFPREFIX
[] =
5095 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0};
5096 static const WCHAR szAuthorizedCDFPrefix
[] =
5097 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0};
5098 static const WCHAR szARPCONTACT
[] =
5099 {'A','R','P','C','O','N','T','A','C','T',0};
5100 static const WCHAR szContact
[] =
5101 {'C','o','n','t','a','c','t',0};
5102 static const WCHAR szARPCOMMENTS
[] =
5103 {'A','R','P','C','O','M','M','E','N','T','S',0};
5104 static const WCHAR szComments
[] =
5105 {'C','o','m','m','e','n','t','s',0};
5106 static const WCHAR szProductName
[] =
5107 {'P','r','o','d','u','c','t','N','a','m','e',0};
5108 static const WCHAR szDisplayName
[] =
5109 {'D','i','s','p','l','a','y','N','a','m','e',0};
5110 static const WCHAR szARPHELPLINK
[] =
5111 {'A','R','P','H','E','L','P','L','I','N','K',0};
5112 static const WCHAR szHelpLink
[] =
5113 {'H','e','l','p','L','i','n','k',0};
5114 static const WCHAR szARPHELPTELEPHONE
[] =
5115 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0};
5116 static const WCHAR szHelpTelephone
[] =
5117 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0};
5118 static const WCHAR szARPINSTALLLOCATION
[] =
5119 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0};
5120 static const WCHAR szManufacturer
[] =
5121 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
5122 static const WCHAR szPublisher
[] =
5123 {'P','u','b','l','i','s','h','e','r',0};
5124 static const WCHAR szARPREADME
[] =
5125 {'A','R','P','R','E','A','D','M','E',0};
5126 static const WCHAR szReadme
[] =
5127 {'R','e','a','d','M','e',0};
5128 static const WCHAR szARPSIZE
[] =
5129 {'A','R','P','S','I','Z','E',0};
5130 static const WCHAR szSize
[] =
5131 {'S','i','z','e',0};
5132 static const WCHAR szARPURLINFOABOUT
[] =
5133 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0};
5134 static const WCHAR szURLInfoAbout
[] =
5135 {'U','R','L','I','n','f','o','A','b','o','u','t',0};
5136 static const WCHAR szARPURLUPDATEINFO
[] =
5137 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0};
5138 static const WCHAR szURLUpdateInfo
[] =
5139 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0};
5140 static const WCHAR szARPSYSTEMCOMPONENT
[] =
5141 {'A','R','P','S','Y','S','T','E','M','C','O','M','P','O','N','E','N','T',0};
5142 static const WCHAR szSystemComponent
[] =
5143 {'S','y','s','t','e','m','C','o','m','p','o','n','e','n','t',0};
5145 static const WCHAR
*propval
[] = {
5146 szARPAUTHORIZEDCDFPREFIX
, szAuthorizedCDFPrefix
,
5147 szARPCONTACT
, szContact
,
5148 szARPCOMMENTS
, szComments
,
5149 szProductName
, szDisplayName
,
5150 szARPHELPLINK
, szHelpLink
,
5151 szARPHELPTELEPHONE
, szHelpTelephone
,
5152 szARPINSTALLLOCATION
, szInstallLocation
,
5153 szSourceDir
, szInstallSource
,
5154 szManufacturer
, szPublisher
,
5155 szARPREADME
, szReadme
,
5157 szARPURLINFOABOUT
, szURLInfoAbout
,
5158 szARPURLUPDATEINFO
, szURLUpdateInfo
,
5161 const WCHAR
**p
= propval
;
5167 val
= msi_dup_property(package
->db
, prop
);
5168 msi_reg_set_val_str(hkey
, key
, val
);
5172 msi_reg_set_val_dword(hkey
, szWindowsInstaller
, 1);
5173 if (msi_get_property_int( package
->db
, szARPSYSTEMCOMPONENT
, 0 ))
5175 msi_reg_set_val_dword( hkey
, szSystemComponent
, 1 );
5177 size
= deformat_string(package
, modpath_fmt
, &buffer
) * sizeof(WCHAR
);
5178 RegSetValueExW(hkey
, szModifyPath
, 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
5179 RegSetValueExW(hkey
, szUninstallString
, 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
5182 /* FIXME: Write real Estimated Size when we have it */
5183 msi_reg_set_val_dword(hkey
, szEstimatedSize
, 0);
5185 GetLocalTime(&systime
);
5186 sprintfW(date
, date_fmt
, systime
.wYear
, systime
.wMonth
, systime
.wDay
);
5187 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_INSTALLDATEW
, date
);
5189 langid
= msi_get_property_int(package
->db
, szProductLanguage
, 0);
5190 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
5192 buffer
= msi_dup_property(package
->db
, szProductVersion
);
5193 msi_reg_set_val_str(hkey
, szDisplayVersion
, buffer
);
5196 DWORD verdword
= msi_version_str_to_dword(buffer
);
5198 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
5199 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMAJORW
, verdword
>> 24);
5200 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMINORW
, (verdword
>> 16) & 0xFF);
5204 return ERROR_SUCCESS
;
5207 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
5209 WCHAR
*upgrade_code
, squashed_pc
[SQUASHED_GUID_SIZE
];
5211 HKEY hkey
, props
, upgrade_key
;
5214 /* FIXME: also need to publish if the product is in advertise mode */
5215 if (!msi_check_publish(package
))
5216 return ERROR_SUCCESS
;
5218 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
, package
->platform
, &hkey
, TRUE
);
5219 if (rc
!= ERROR_SUCCESS
)
5222 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
, NULL
, &props
, TRUE
);
5223 if (rc
!= ERROR_SUCCESS
)
5226 rc
= msi_publish_install_properties(package
, hkey
);
5227 if (rc
!= ERROR_SUCCESS
)
5230 rc
= msi_publish_install_properties(package
, props
);
5231 if (rc
!= ERROR_SUCCESS
)
5234 upgrade_code
= msi_dup_property(package
->db
, szUpgradeCode
);
5237 rc
= MSIREG_OpenUpgradeCodesKey( upgrade_code
, &upgrade_key
, TRUE
);
5238 if (rc
== ERROR_SUCCESS
)
5240 squash_guid( package
->ProductCode
, squashed_pc
);
5241 msi_reg_set_val_str( upgrade_key
, squashed_pc
, NULL
);
5242 RegCloseKey( upgrade_key
);
5244 msi_free( upgrade_code
);
5246 msi_reg_set_val_str( props
, INSTALLPROPERTY_LOCALPACKAGEW
, package
->localfile
);
5247 package
->delete_on_close
= FALSE
;
5250 uirow
= MSI_CreateRecord( 1 );
5251 MSI_RecordSetStringW( uirow
, 1, package
->ProductCode
);
5252 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5253 msiobj_release( &uirow
->hdr
);
5256 return ERROR_SUCCESS
;
5259 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
5261 return execute_script(package
, SCRIPT_INSTALL
);
5264 static UINT
ITERATE_UnpublishIcon( MSIRECORD
*row
, LPVOID param
)
5266 MSIPACKAGE
*package
= param
;
5267 const WCHAR
*icon
= MSI_RecordGetString( row
, 1 );
5268 WCHAR
*p
, *icon_path
;
5270 if (!icon
) return ERROR_SUCCESS
;
5271 if ((icon_path
= msi_build_icon_path( package
, icon
)))
5273 TRACE("removing icon file %s\n", debugstr_w(icon_path
));
5274 DeleteFileW( icon_path
);
5275 if ((p
= strrchrW( icon_path
, '\\' )))
5278 RemoveDirectoryW( icon_path
);
5280 msi_free( icon_path
);
5282 return ERROR_SUCCESS
;
5285 static UINT
msi_unpublish_icons( MSIPACKAGE
*package
)
5287 static const WCHAR query
[]= {
5288 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','I','c','o','n','`',0};
5292 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
5293 if (r
== ERROR_SUCCESS
)
5295 r
= MSI_IterateRecords( view
, NULL
, ITERATE_UnpublishIcon
, package
);
5296 msiobj_release( &view
->hdr
);
5297 if (r
!= ERROR_SUCCESS
)
5300 return ERROR_SUCCESS
;
5303 static void remove_product_upgrade_code( MSIPACKAGE
*package
)
5305 WCHAR
*code
, product
[SQUASHED_GUID_SIZE
];
5310 squash_guid( package
->ProductCode
, product
);
5311 if (!(code
= msi_dup_property( package
->db
, szUpgradeCode
)))
5313 WARN( "upgrade code not found\n" );
5316 if (!MSIREG_OpenUpgradeCodesKey( code
, &hkey
, FALSE
))
5318 RegDeleteValueW( hkey
, product
);
5319 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, &count
, NULL
, NULL
, NULL
, NULL
, NULL
);
5320 RegCloseKey( hkey
);
5321 if (!res
&& !count
) MSIREG_DeleteUpgradeCodesKey( code
);
5323 if (!MSIREG_OpenUserUpgradeCodesKey( code
, &hkey
, FALSE
))
5325 RegDeleteValueW( hkey
, product
);
5326 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, &count
, NULL
, NULL
, NULL
, NULL
, NULL
);
5327 RegCloseKey( hkey
);
5328 if (!res
&& !count
) MSIREG_DeleteUserUpgradeCodesKey( code
);
5330 if (!MSIREG_OpenClassesUpgradeCodesKey( code
, &hkey
, FALSE
))
5332 RegDeleteValueW( hkey
, product
);
5333 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, &count
, NULL
, NULL
, NULL
, NULL
, NULL
);
5334 RegCloseKey( hkey
);
5335 if (!res
&& !count
) MSIREG_DeleteClassesUpgradeCodesKey( code
);
5341 static UINT
ACTION_UnpublishProduct(MSIPACKAGE
*package
)
5343 MSIPATCHINFO
*patch
;
5345 MSIREG_DeleteProductKey(package
->ProductCode
);
5346 MSIREG_DeleteUserDataProductKey(package
->ProductCode
, package
->Context
);
5347 MSIREG_DeleteUninstallKey(package
->ProductCode
, package
->platform
);
5349 MSIREG_DeleteLocalClassesProductKey(package
->ProductCode
);
5350 MSIREG_DeleteLocalClassesFeaturesKey(package
->ProductCode
);
5351 MSIREG_DeleteUserProductKey(package
->ProductCode
);
5352 MSIREG_DeleteUserFeaturesKey(package
->ProductCode
);
5354 remove_product_upgrade_code( package
);
5356 LIST_FOR_EACH_ENTRY(patch
, &package
->patches
, MSIPATCHINFO
, entry
)
5358 MSIREG_DeleteUserDataPatchKey(patch
->patchcode
, package
->Context
);
5359 if (!strcmpW( package
->ProductCode
, patch
->products
))
5361 TRACE("removing local patch package %s\n", debugstr_w(patch
->localfile
));
5362 patch
->delete_on_close
= TRUE
;
5364 /* FIXME: remove local patch package if this is the last product */
5366 TRACE("removing local package %s\n", debugstr_w(package
->localfile
));
5367 package
->delete_on_close
= TRUE
;
5369 msi_unpublish_icons( package
);
5370 return ERROR_SUCCESS
;
5373 static BOOL
is_full_uninstall( MSIPACKAGE
*package
)
5375 MSIFEATURE
*feature
;
5377 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
5379 if (feature
->Action
!= INSTALLSTATE_ABSENT
&&
5380 (feature
->Installed
!= INSTALLSTATE_ABSENT
|| feature
->Action
!= INSTALLSTATE_UNKNOWN
))
5387 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
5391 /* first do the same as an InstallExecute */
5392 rc
= execute_script(package
, SCRIPT_INSTALL
);
5393 if (rc
!= ERROR_SUCCESS
)
5396 /* then handle commit actions */
5397 rc
= execute_script(package
, SCRIPT_COMMIT
);
5398 if (rc
!= ERROR_SUCCESS
)
5401 if (is_full_uninstall(package
))
5402 rc
= ACTION_UnpublishProduct(package
);
5407 UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
5409 static const WCHAR RunOnce
[] = {
5410 'S','o','f','t','w','a','r','e','\\',
5411 'M','i','c','r','o','s','o','f','t','\\',
5412 'W','i','n','d','o','w','s','\\',
5413 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5414 'R','u','n','O','n','c','e',0};
5415 static const WCHAR InstallRunOnce
[] = {
5416 'S','o','f','t','w','a','r','e','\\',
5417 'M','i','c','r','o','s','o','f','t','\\',
5418 'W','i','n','d','o','w','s','\\',
5419 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5420 'I','n','s','t','a','l','l','e','r','\\',
5421 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
5423 static const WCHAR msiexec_fmt
[] = {
5425 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5426 '\"','%','s','\"',0};
5427 static const WCHAR install_fmt
[] = {
5428 '/','I',' ','\"','%','s','\"',' ',
5429 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5430 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5431 WCHAR buffer
[256], sysdir
[MAX_PATH
], squashed_pc
[SQUASHED_GUID_SIZE
];
5434 squash_guid( package
->ProductCode
, squashed_pc
);
5436 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
5437 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
5438 snprintfW( buffer
, sizeof(buffer
)/sizeof(buffer
[0]), msiexec_fmt
, sysdir
, squashed_pc
);
5440 msi_reg_set_val_str( hkey
, squashed_pc
, buffer
);
5443 TRACE("Reboot command %s\n",debugstr_w(buffer
));
5445 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
5446 sprintfW( buffer
, install_fmt
, package
->ProductCode
, squashed_pc
);
5448 msi_reg_set_val_str( hkey
, squashed_pc
, buffer
);
5451 return ERROR_INSTALL_SUSPEND
;
5454 static UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
5460 * We are currently doing what should be done here in the top level Install
5461 * however for Administrative and uninstalls this step will be needed
5463 if (!package
->PackagePath
)
5464 return ERROR_SUCCESS
;
5466 msi_set_sourcedir_props(package
, TRUE
);
5468 attrib
= GetFileAttributesW(package
->db
->path
);
5469 if (attrib
== INVALID_FILE_ATTRIBUTES
)
5475 rc
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
5476 package
->Context
, MSICODE_PRODUCT
,
5477 INSTALLPROPERTY_DISKPROMPTW
,NULL
,&size
);
5478 if (rc
== ERROR_MORE_DATA
)
5480 prompt
= msi_alloc(size
* sizeof(WCHAR
));
5481 MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
5482 package
->Context
, MSICODE_PRODUCT
,
5483 INSTALLPROPERTY_DISKPROMPTW
,prompt
,&size
);
5486 prompt
= strdupW(package
->db
->path
);
5488 record
= MSI_CreateRecord(2);
5489 MSI_RecordSetInteger(record
, 1, MSIERR_INSERTDISK
);
5490 MSI_RecordSetStringW(record
, 2, prompt
);
5492 while(attrib
== INVALID_FILE_ATTRIBUTES
)
5494 MSI_RecordSetStringW(record
, 0, NULL
);
5495 rc
= MSI_ProcessMessage(package
, INSTALLMESSAGE_ERROR
, record
);
5497 return ERROR_INSTALL_USEREXIT
;
5498 attrib
= GetFileAttributesW(package
->db
->path
);
5503 return ERROR_SUCCESS
;
5508 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
5511 LPWSTR buffer
, productid
= NULL
;
5512 UINT i
, rc
= ERROR_SUCCESS
;
5515 static const WCHAR szPropKeys
[][80] =
5517 {'P','r','o','d','u','c','t','I','D',0},
5518 {'U','S','E','R','N','A','M','E',0},
5519 {'C','O','M','P','A','N','Y','N','A','M','E',0},
5523 static const WCHAR szRegKeys
[][80] =
5525 {'P','r','o','d','u','c','t','I','D',0},
5526 {'R','e','g','O','w','n','e','r',0},
5527 {'R','e','g','C','o','m','p','a','n','y',0},
5531 if (msi_check_unpublish(package
))
5533 MSIREG_DeleteUserDataProductKey(package
->ProductCode
, package
->Context
);
5537 productid
= msi_dup_property( package
->db
, INSTALLPROPERTY_PRODUCTIDW
);
5541 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
,
5543 if (rc
!= ERROR_SUCCESS
)
5546 for( i
= 0; szPropKeys
[i
][0]; i
++ )
5548 buffer
= msi_dup_property( package
->db
, szPropKeys
[i
] );
5549 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
5554 uirow
= MSI_CreateRecord( 1 );
5555 MSI_RecordSetStringW( uirow
, 1, productid
);
5556 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5557 msiobj_release( &uirow
->hdr
);
5559 msi_free(productid
);
5564 static UINT
iterate_properties(MSIRECORD
*record
, void *param
)
5566 static const WCHAR prop_template
[] =
5567 {'P','r','o','p','e','r','t','y','(','S',')',':',' ','[','1',']',' ','=',' ','[','2',']',0};
5570 uirow
= MSI_CloneRecord(record
);
5571 if (!uirow
) return ERROR_OUTOFMEMORY
;
5572 MSI_RecordSetStringW(uirow
, 0, prop_template
);
5573 MSI_ProcessMessage(param
, INSTALLMESSAGE_INFO
|MB_ICONHAND
, uirow
);
5574 msiobj_release(&uirow
->hdr
);
5576 return ERROR_SUCCESS
;
5580 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
5582 static const WCHAR prop_query
[] =
5583 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','_','P','r','o','p','e','r','t','y','`',0};
5586 WCHAR
*info_template
;
5588 MSIRECORD
*uirow
, *uirow_info
;
5591 /* Send COMMONDATA and INFO messages. */
5592 /* FIXME: when should these messages be sent? [see also MsiOpenPackage()] */
5593 uirow
= MSI_CreateRecord(3);
5594 if (!uirow
) return ERROR_OUTOFMEMORY
;
5595 MSI_RecordSetStringW(uirow
, 0, NULL
);
5596 MSI_RecordSetInteger(uirow
, 1, 0);
5597 MSI_RecordSetInteger(uirow
, 2, package
->num_langids
? package
->langids
[0] : 0);
5598 MSI_RecordSetInteger(uirow
, 3, msi_get_string_table_codepage(package
->db
->strings
));
5599 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5600 /* FIXME: send INSTALLMESSAGE_PROGRESS */
5601 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5603 if (!(needs_ui_sequence(package
) && ui_sequence_exists(package
)))
5605 uirow_info
= MSI_CreateRecord(0);
5608 msiobj_release(&uirow
->hdr
);
5609 return ERROR_OUTOFMEMORY
;
5611 info_template
= msi_get_error_message(package
->db
, MSIERR_INFO_LOGGINGSTART
);
5612 MSI_RecordSetStringW(uirow_info
, 0, info_template
);
5613 msi_free(info_template
);
5614 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
|MB_ICONHAND
, uirow_info
);
5615 msiobj_release(&uirow_info
->hdr
);
5618 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5620 productname
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
5621 MSI_RecordSetInteger(uirow
, 1, 1);
5622 MSI_RecordSetStringW(uirow
, 2, productname
);
5623 MSI_RecordSetStringW(uirow
, 3, NULL
);
5624 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5625 msiobj_release(&uirow
->hdr
);
5627 package
->LastActionResult
= MSI_NULL_INTEGER
;
5629 action
= msi_dup_property(package
->db
, szEXECUTEACTION
);
5630 if (!action
) action
= msi_strdupW(szINSTALL
, strlenW(szINSTALL
));
5632 /* Perform the action. Top-level actions trigger a sequence. */
5633 if (!strcmpW(action
, szINSTALL
))
5635 /* Send ACTIONSTART/INFO and INSTALLSTART. */
5636 ui_actionstart(package
, szINSTALL
, NULL
, NULL
);
5637 ui_actioninfo(package
, szINSTALL
, TRUE
, 0);
5638 uirow
= MSI_CreateRecord(2);
5641 rc
= ERROR_OUTOFMEMORY
;
5644 MSI_RecordSetStringW(uirow
, 0, NULL
);
5645 MSI_RecordSetStringW(uirow
, 1, productname
);
5646 MSI_RecordSetStringW(uirow
, 2, package
->ProductCode
);
5647 MSI_ProcessMessage(package
, INSTALLMESSAGE_INSTALLSTART
, uirow
);
5648 msiobj_release(&uirow
->hdr
);
5650 /* Perform the installation. Always use the ExecuteSequence. */
5651 package
->InWhatSequence
|= SEQUENCE_EXEC
;
5652 rc
= ACTION_ProcessExecSequence(package
);
5654 /* Send return value and INSTALLEND. */
5655 ui_actioninfo(package
, szINSTALL
, FALSE
, !rc
);
5656 uirow
= MSI_CreateRecord(3);
5659 rc
= ERROR_OUTOFMEMORY
;
5662 MSI_RecordSetStringW(uirow
, 0, NULL
);
5663 MSI_RecordSetStringW(uirow
, 1, productname
);
5664 MSI_RecordSetStringW(uirow
, 2, package
->ProductCode
);
5665 MSI_RecordSetInteger(uirow
, 3, !rc
);
5666 MSI_ProcessMessage(package
, INSTALLMESSAGE_INSTALLEND
, uirow
);
5667 msiobj_release(&uirow
->hdr
);
5670 rc
= ACTION_PerformAction(package
, action
, SCRIPT_NONE
);
5672 /* Send all set properties. */
5673 if (!MSI_OpenQuery(package
->db
, &view
, prop_query
))
5675 MSI_IterateRecords(view
, NULL
, iterate_properties
, package
);
5676 msiobj_release(&view
->hdr
);
5679 /* And finally, toggle the cancel off and on. */
5680 uirow
= MSI_CreateRecord(2);
5683 rc
= ERROR_OUTOFMEMORY
;
5686 MSI_RecordSetStringW(uirow
, 0, NULL
);
5687 MSI_RecordSetInteger(uirow
, 1, 2);
5688 MSI_RecordSetInteger(uirow
, 2, 0);
5689 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5690 MSI_RecordSetInteger(uirow
, 2, 1);
5691 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5692 msiobj_release(&uirow
->hdr
);
5695 msi_free(productname
);
5700 static UINT
ACTION_INSTALL(MSIPACKAGE
*package
)
5702 msi_set_property(package
->db
, szEXECUTEACTION
, szINSTALL
, -1);
5703 if (needs_ui_sequence(package
) && ui_sequence_exists(package
))
5705 package
->InWhatSequence
|= SEQUENCE_UI
;
5706 return ACTION_ProcessUISequence(package
);
5709 return ACTION_ExecuteAction(package
);
5712 WCHAR
*msi_create_component_advertise_string( MSIPACKAGE
*package
, MSICOMPONENT
*component
, const WCHAR
*feature
)
5714 static const WCHAR fmt
[] = {'%','s','%','s','%','c','%','s',0};
5715 WCHAR productid_85
[21], component_85
[21], *ret
;
5719 /* > is used if there is a component GUID and < if not. */
5721 productid_85
[0] = 0;
5722 component_85
[0] = 0;
5723 CLSIDFromString( package
->ProductCode
, &clsid
);
5725 encode_base85_guid( &clsid
, productid_85
);
5728 CLSIDFromString( component
->ComponentId
, &clsid
);
5729 encode_base85_guid( &clsid
, component_85
);
5732 TRACE("product=%s feature=%s component=%s\n", debugstr_w(productid_85
), debugstr_w(feature
),
5733 debugstr_w(component_85
));
5735 sz
= 20 + strlenW( feature
) + 20 + 3;
5736 ret
= msi_alloc_zero( sz
* sizeof(WCHAR
) );
5737 if (ret
) sprintfW( ret
, fmt
, productid_85
, feature
, component
? '>' : '<', component_85
);
5741 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
5743 MSIPACKAGE
*package
= param
;
5744 LPCWSTR compgroupid
, component
, feature
, qualifier
, text
;
5745 LPWSTR advertise
= NULL
, output
= NULL
, existing
= NULL
, p
, q
;
5754 feature
= MSI_RecordGetString(rec
, 5);
5755 feat
= msi_get_loaded_feature(package
, feature
);
5757 return ERROR_SUCCESS
;
5759 feat
->Action
= msi_get_feature_action( package
, feat
);
5760 if (feat
->Action
!= INSTALLSTATE_LOCAL
&&
5761 feat
->Action
!= INSTALLSTATE_SOURCE
&&
5762 feat
->Action
!= INSTALLSTATE_ADVERTISED
)
5764 TRACE("feature not scheduled for installation %s\n", debugstr_w(feature
));
5765 return ERROR_SUCCESS
;
5768 component
= MSI_RecordGetString(rec
, 3);
5769 comp
= msi_get_loaded_component(package
, component
);
5771 return ERROR_SUCCESS
;
5773 compgroupid
= MSI_RecordGetString(rec
,1);
5774 qualifier
= MSI_RecordGetString(rec
,2);
5776 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
5777 if (rc
!= ERROR_SUCCESS
)
5780 advertise
= msi_create_component_advertise_string( package
, comp
, feature
);
5781 text
= MSI_RecordGetString( rec
, 4 );
5784 p
= msi_alloc( (strlenW( advertise
) + strlenW( text
) + 1) * sizeof(WCHAR
) );
5785 strcpyW( p
, advertise
);
5787 msi_free( advertise
);
5790 existing
= msi_reg_get_val_str( hkey
, qualifier
);
5792 sz
= strlenW( advertise
) + 1;
5795 for (p
= existing
; *p
; p
+= len
)
5797 len
= strlenW( p
) + 1;
5798 if (strcmpW( advertise
, p
)) sz
+= len
;
5801 if (!(output
= msi_alloc( (sz
+ 1) * sizeof(WCHAR
) )))
5803 rc
= ERROR_OUTOFMEMORY
;
5809 for (p
= existing
; *p
; p
+= len
)
5811 len
= strlenW( p
) + 1;
5812 if (strcmpW( advertise
, p
))
5814 memcpy( q
, p
, len
* sizeof(WCHAR
) );
5819 strcpyW( q
, advertise
);
5820 q
[strlenW( q
) + 1] = 0;
5822 msi_reg_set_val_multi_str( hkey
, qualifier
, output
);
5827 msi_free( advertise
);
5828 msi_free( existing
);
5831 uirow
= MSI_CreateRecord( 2 );
5832 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
5833 MSI_RecordSetStringW( uirow
, 2, qualifier
);
5834 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5835 msiobj_release( &uirow
->hdr
);
5836 /* FIXME: call ui_progress? */
5842 * At present I am ignorning the advertised components part of this and only
5843 * focusing on the qualified component sets
5845 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
5847 static const WCHAR query
[] = {
5848 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5849 '`','P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','`',0};
5853 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
5854 if (rc
!= ERROR_SUCCESS
)
5855 return ERROR_SUCCESS
;
5857 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
5858 msiobj_release(&view
->hdr
);
5862 static UINT
ITERATE_UnpublishComponent( MSIRECORD
*rec
, LPVOID param
)
5864 static const WCHAR szInstallerComponents
[] = {
5865 'S','o','f','t','w','a','r','e','\\',
5866 'M','i','c','r','o','s','o','f','t','\\',
5867 'I','n','s','t','a','l','l','e','r','\\',
5868 'C','o','m','p','o','n','e','n','t','s','\\',0};
5870 MSIPACKAGE
*package
= param
;
5871 LPCWSTR compgroupid
, component
, feature
, qualifier
;
5875 WCHAR squashed
[GUID_SIZE
], keypath
[MAX_PATH
];
5878 feature
= MSI_RecordGetString( rec
, 5 );
5879 feat
= msi_get_loaded_feature( package
, feature
);
5881 return ERROR_SUCCESS
;
5883 feat
->Action
= msi_get_feature_action( package
, feat
);
5884 if (feat
->Action
!= INSTALLSTATE_ABSENT
)
5886 TRACE("feature not scheduled for removal %s\n", debugstr_w(feature
));
5887 return ERROR_SUCCESS
;
5890 component
= MSI_RecordGetString( rec
, 3 );
5891 comp
= msi_get_loaded_component( package
, component
);
5893 return ERROR_SUCCESS
;
5895 compgroupid
= MSI_RecordGetString( rec
, 1 );
5896 qualifier
= MSI_RecordGetString( rec
, 2 );
5898 squash_guid( compgroupid
, squashed
);
5899 strcpyW( keypath
, szInstallerComponents
);
5900 strcatW( keypath
, squashed
);
5902 res
= RegDeleteKeyW( HKEY_CURRENT_USER
, keypath
);
5903 if (res
!= ERROR_SUCCESS
)
5905 WARN("Unable to delete component key %d\n", res
);
5908 uirow
= MSI_CreateRecord( 2 );
5909 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
5910 MSI_RecordSetStringW( uirow
, 2, qualifier
);
5911 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5912 msiobj_release( &uirow
->hdr
);
5914 return ERROR_SUCCESS
;
5917 static UINT
ACTION_UnpublishComponents( MSIPACKAGE
*package
)
5919 static const WCHAR query
[] = {
5920 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5921 '`','P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','`',0};
5925 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
5926 if (rc
!= ERROR_SUCCESS
)
5927 return ERROR_SUCCESS
;
5929 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnpublishComponent
, package
);
5930 msiobj_release( &view
->hdr
);
5934 static UINT
ITERATE_InstallService(MSIRECORD
*rec
, LPVOID param
)
5936 static const WCHAR query
[] =
5937 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5938 '`','C','o','m','p','o','n','e','n','t','`',' ','W','H','E','R','E',' ',
5939 '`','C','o','m','p','o','n','e','n','t','`',' ','=','\'','%','s','\'',0};
5940 MSIPACKAGE
*package
= param
;
5941 MSICOMPONENT
*component
;
5944 SC_HANDLE hscm
= NULL
, service
= NULL
;
5946 LPWSTR name
= NULL
, disp
= NULL
, load_order
= NULL
, serv_name
= NULL
;
5947 LPWSTR depends
= NULL
, pass
= NULL
, args
= NULL
, image_path
= NULL
;
5948 DWORD serv_type
, start_type
, err_control
;
5950 SERVICE_DESCRIPTIONW sd
= {NULL
};
5951 UINT ret
= ERROR_SUCCESS
;
5953 comp
= MSI_RecordGetString( rec
, 12 );
5954 component
= msi_get_loaded_component( package
, comp
);
5957 WARN("service component not found\n");
5960 component
->Action
= msi_get_component_action( package
, component
);
5961 if (component
->Action
!= INSTALLSTATE_LOCAL
)
5963 TRACE("component not scheduled for installation %s\n", debugstr_w(comp
));
5966 hscm
= OpenSCManagerW(NULL
, SERVICES_ACTIVE_DATABASEW
, GENERIC_WRITE
);
5969 ERR("Failed to open the SC Manager!\n");
5973 start_type
= MSI_RecordGetInteger(rec
, 5);
5974 if (start_type
== SERVICE_BOOT_START
|| start_type
== SERVICE_SYSTEM_START
)
5977 deformat_string(package
, MSI_RecordGetString(rec
, 2), &name
);
5978 deformat_string(package
, MSI_RecordGetString(rec
, 3), &disp
);
5979 serv_type
= MSI_RecordGetInteger(rec
, 4);
5980 err_control
= MSI_RecordGetInteger(rec
, 6);
5981 deformat_string(package
, MSI_RecordGetString(rec
, 7), &load_order
);
5982 deformat_string(package
, MSI_RecordGetString(rec
, 8), &depends
);
5983 deformat_string(package
, MSI_RecordGetString(rec
, 9), &serv_name
);
5984 deformat_string(package
, MSI_RecordGetString(rec
, 10), &pass
);
5985 deformat_string(package
, MSI_RecordGetString(rec
, 11), &args
);
5986 deformat_string(package
, MSI_RecordGetString(rec
, 13), &sd
.lpDescription
);
5988 /* Should the complete install fail if CreateService fails? */
5989 is_vital
= (err_control
& msidbServiceInstallErrorControlVital
);
5991 /* Remove the msidbServiceInstallErrorControlVital-flag from err_control.
5992 CreateService (under Windows) would fail if not. */
5993 err_control
&= ~msidbServiceInstallErrorControlVital
;
5995 /* fetch the service path */
5996 row
= MSI_QueryGetRecord(package
->db
, query
, comp
);
5999 ERR("Query failed\n");
6002 if (!(key
= MSI_RecordGetString(row
, 6)))
6004 msiobj_release(&row
->hdr
);
6007 file
= msi_get_loaded_file(package
, key
);
6008 msiobj_release(&row
->hdr
);
6011 ERR("Failed to load the service file\n");
6015 if (!args
|| !args
[0]) image_path
= file
->TargetPath
;
6018 int len
= strlenW(file
->TargetPath
) + strlenW(args
) + 2;
6019 if (!(image_path
= msi_alloc(len
* sizeof(WCHAR
))))
6021 ret
= ERROR_OUTOFMEMORY
;
6025 strcpyW(image_path
, file
->TargetPath
);
6026 strcatW(image_path
, szSpace
);
6027 strcatW(image_path
, args
);
6029 service
= CreateServiceW(hscm
, name
, disp
, GENERIC_ALL
, serv_type
,
6030 start_type
, err_control
, image_path
, load_order
,
6031 NULL
, depends
, serv_name
, pass
);
6035 if (GetLastError() != ERROR_SERVICE_EXISTS
)
6037 WARN("Failed to create service %s: %d\n", debugstr_w(name
), GetLastError());
6039 ret
= ERROR_INSTALL_FAILURE
;
6043 else if (sd
.lpDescription
)
6045 if (!ChangeServiceConfig2W(service
, SERVICE_CONFIG_DESCRIPTION
, &sd
))
6046 WARN("failed to set service description %u\n", GetLastError());
6049 if (image_path
!= file
->TargetPath
) msi_free(image_path
);
6051 if (service
) CloseServiceHandle(service
);
6052 if (hscm
) CloseServiceHandle(hscm
);
6055 msi_free(sd
.lpDescription
);
6056 msi_free(load_order
);
6057 msi_free(serv_name
);
6065 static UINT
ACTION_InstallServices( MSIPACKAGE
*package
)
6067 static const WCHAR query
[] = {
6068 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6069 'S','e','r','v','i','c','e','I','n','s','t','a','l','l',0};
6073 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
6074 if (rc
!= ERROR_SUCCESS
)
6075 return ERROR_SUCCESS
;
6077 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallService
, package
);
6078 msiobj_release(&view
->hdr
);
6082 /* converts arg1[~]arg2[~]arg3 to a list of ptrs to the strings */
6083 static LPCWSTR
*msi_service_args_to_vector(LPWSTR args
, DWORD
*numargs
)
6085 LPCWSTR
*vector
, *temp_vector
;
6089 static const WCHAR separator
[] = {'[','~',']',0};
6092 sep_len
= sizeof(separator
) / sizeof(WCHAR
) - 1;
6097 vector
= msi_alloc(sizeof(LPWSTR
));
6105 vector
[*numargs
- 1] = p
;
6107 if ((q
= strstrW(p
, separator
)))
6111 temp_vector
= msi_realloc(vector
, (*numargs
+ 1) * sizeof(LPWSTR
));
6117 vector
= temp_vector
;
6126 static UINT
ITERATE_StartService(MSIRECORD
*rec
, LPVOID param
)
6128 MSIPACKAGE
*package
= param
;
6131 SC_HANDLE scm
= NULL
, service
= NULL
;
6132 LPCWSTR component
, *vector
= NULL
;
6133 LPWSTR name
, args
, display_name
= NULL
;
6134 DWORD event
, numargs
, len
, wait
, dummy
;
6135 UINT r
= ERROR_FUNCTION_FAILED
;
6136 SERVICE_STATUS_PROCESS status
;
6137 ULONGLONG start_time
;
6139 component
= MSI_RecordGetString(rec
, 6);
6140 comp
= msi_get_loaded_component(package
, component
);
6142 return ERROR_SUCCESS
;
6144 event
= MSI_RecordGetInteger( rec
, 3 );
6145 deformat_string( package
, MSI_RecordGetString( rec
, 2 ), &name
);
6147 comp
->Action
= msi_get_component_action( package
, comp
);
6148 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventStart
)) &&
6149 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallStart
)))
6151 TRACE("not starting %s\n", debugstr_w(name
));
6153 return ERROR_SUCCESS
;
6156 deformat_string(package
, MSI_RecordGetString(rec
, 4), &args
);
6157 wait
= MSI_RecordGetInteger(rec
, 5);
6159 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_CONNECT
);
6162 ERR("Failed to open the service control manager\n");
6167 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
6168 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
6170 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
6171 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
6174 service
= OpenServiceW(scm
, name
, SERVICE_START
|SERVICE_QUERY_STATUS
);
6177 ERR("Failed to open service %s (%u)\n", debugstr_w(name
), GetLastError());
6181 vector
= msi_service_args_to_vector(args
, &numargs
);
6183 if (!StartServiceW(service
, numargs
, vector
) &&
6184 GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
)
6186 ERR("Failed to start service %s (%u)\n", debugstr_w(name
), GetLastError());
6193 /* wait for at most 30 seconds for the service to be up and running */
6194 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
,
6195 (BYTE
*)&status
, sizeof(SERVICE_STATUS_PROCESS
), &dummy
))
6197 TRACE("failed to query service status (%u)\n", GetLastError());
6200 start_time
= GetTickCount64();
6201 while (status
.dwCurrentState
== SERVICE_START_PENDING
)
6203 if (GetTickCount64() - start_time
> 30000) break;
6205 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
,
6206 (BYTE
*)&status
, sizeof(SERVICE_STATUS_PROCESS
), &dummy
))
6208 TRACE("failed to query service status (%u)\n", GetLastError());
6212 if (status
.dwCurrentState
!= SERVICE_RUNNING
)
6214 WARN("service failed to start %u\n", status
.dwCurrentState
);
6215 r
= ERROR_FUNCTION_FAILED
;
6220 uirow
= MSI_CreateRecord( 2 );
6221 MSI_RecordSetStringW( uirow
, 1, display_name
);
6222 MSI_RecordSetStringW( uirow
, 2, name
);
6223 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6224 msiobj_release( &uirow
->hdr
);
6226 if (service
) CloseServiceHandle(service
);
6227 if (scm
) CloseServiceHandle(scm
);
6232 msi_free(display_name
);
6236 static UINT
ACTION_StartServices( MSIPACKAGE
*package
)
6238 static const WCHAR query
[] = {
6239 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6240 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0};
6244 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
6245 if (rc
!= ERROR_SUCCESS
)
6246 return ERROR_SUCCESS
;
6248 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StartService
, package
);
6249 msiobj_release(&view
->hdr
);
6253 static BOOL
stop_service_dependents(SC_HANDLE scm
, SC_HANDLE service
)
6255 DWORD i
, needed
, count
;
6256 ENUM_SERVICE_STATUSW
*dependencies
;
6259 BOOL stopped
, ret
= FALSE
;
6261 if (EnumDependentServicesW(service
, SERVICE_ACTIVE
, NULL
,
6262 0, &needed
, &count
))
6265 if (GetLastError() != ERROR_MORE_DATA
)
6268 dependencies
= msi_alloc(needed
);
6272 if (!EnumDependentServicesW(service
, SERVICE_ACTIVE
, dependencies
,
6273 needed
, &needed
, &count
))
6276 for (i
= 0; i
< count
; i
++)
6278 depserv
= OpenServiceW(scm
, dependencies
[i
].lpServiceName
,
6279 SERVICE_STOP
| SERVICE_QUERY_STATUS
);
6283 stopped
= ControlService(depserv
, SERVICE_CONTROL_STOP
, &ss
);
6284 CloseServiceHandle(depserv
);
6292 msi_free(dependencies
);
6296 static UINT
stop_service( LPCWSTR name
)
6298 SC_HANDLE scm
= NULL
, service
= NULL
;
6299 SERVICE_STATUS status
;
6300 SERVICE_STATUS_PROCESS ssp
;
6303 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
6306 WARN("Failed to open the SCM: %d\n", GetLastError());
6310 service
= OpenServiceW(scm
, name
,
6312 SERVICE_QUERY_STATUS
|
6313 SERVICE_ENUMERATE_DEPENDENTS
);
6316 WARN("Failed to open service (%s): %d\n", debugstr_w(name
), GetLastError());
6320 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
, (LPBYTE
)&ssp
,
6321 sizeof(SERVICE_STATUS_PROCESS
), &needed
))
6323 WARN("Failed to query service status (%s): %d\n", debugstr_w(name
), GetLastError());
6327 if (ssp
.dwCurrentState
== SERVICE_STOPPED
)
6330 stop_service_dependents(scm
, service
);
6332 if (!ControlService(service
, SERVICE_CONTROL_STOP
, &status
))
6333 WARN("Failed to stop service (%s): %d\n", debugstr_w(name
), GetLastError());
6336 if (service
) CloseServiceHandle(service
);
6337 if (scm
) CloseServiceHandle(scm
);
6339 return ERROR_SUCCESS
;
6342 static UINT
ITERATE_StopService( MSIRECORD
*rec
, LPVOID param
)
6344 MSIPACKAGE
*package
= param
;
6348 WCHAR
*name
, *display_name
= NULL
;
6352 component
= MSI_RecordGetString( rec
, 6 );
6353 comp
= msi_get_loaded_component( package
, component
);
6355 return ERROR_SUCCESS
;
6357 event
= MSI_RecordGetInteger( rec
, 3 );
6358 deformat_string( package
, MSI_RecordGetString( rec
, 2 ), &name
);
6360 comp
->Action
= msi_get_component_action( package
, comp
);
6361 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventStop
)) &&
6362 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallStop
)))
6364 TRACE("not stopping %s\n", debugstr_w(name
));
6366 return ERROR_SUCCESS
;
6369 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_CONNECT
);
6372 ERR("Failed to open the service control manager\n");
6377 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
6378 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
6380 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
6381 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
6383 CloseServiceHandle( scm
);
6385 stop_service( name
);
6388 uirow
= MSI_CreateRecord( 2 );
6389 MSI_RecordSetStringW( uirow
, 1, display_name
);
6390 MSI_RecordSetStringW( uirow
, 2, name
);
6391 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6392 msiobj_release( &uirow
->hdr
);
6395 msi_free( display_name
);
6396 return ERROR_SUCCESS
;
6399 static UINT
ACTION_StopServices( MSIPACKAGE
*package
)
6401 static const WCHAR query
[] = {
6402 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6403 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0};
6407 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
6408 if (rc
!= ERROR_SUCCESS
)
6409 return ERROR_SUCCESS
;
6411 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StopService
, package
);
6412 msiobj_release(&view
->hdr
);
6416 static UINT
ITERATE_DeleteService( MSIRECORD
*rec
, LPVOID param
)
6418 MSIPACKAGE
*package
= param
;
6421 LPWSTR name
= NULL
, display_name
= NULL
;
6423 SC_HANDLE scm
= NULL
, service
= NULL
;
6425 comp
= msi_get_loaded_component( package
, MSI_RecordGetString(rec
, 6) );
6427 return ERROR_SUCCESS
;
6429 event
= MSI_RecordGetInteger( rec
, 3 );
6430 deformat_string( package
, MSI_RecordGetString(rec
, 2), &name
);
6432 comp
->Action
= msi_get_component_action( package
, comp
);
6433 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventDelete
)) &&
6434 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallDelete
)))
6436 TRACE("service %s not scheduled for removal\n", debugstr_w(name
));
6438 return ERROR_SUCCESS
;
6440 stop_service( name
);
6442 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
6445 WARN("Failed to open the SCM: %d\n", GetLastError());
6450 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
6451 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
6453 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
6454 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
6457 service
= OpenServiceW( scm
, name
, DELETE
);
6460 WARN("Failed to open service (%s): %u\n", debugstr_w(name
), GetLastError());
6464 if (!DeleteService( service
))
6465 WARN("Failed to delete service (%s): %u\n", debugstr_w(name
), GetLastError());
6468 uirow
= MSI_CreateRecord( 2 );
6469 MSI_RecordSetStringW( uirow
, 1, display_name
);
6470 MSI_RecordSetStringW( uirow
, 2, name
);
6471 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6472 msiobj_release( &uirow
->hdr
);
6474 if (service
) CloseServiceHandle( service
);
6475 if (scm
) CloseServiceHandle( scm
);
6477 msi_free( display_name
);
6479 return ERROR_SUCCESS
;
6482 static UINT
ACTION_DeleteServices( MSIPACKAGE
*package
)
6484 static const WCHAR query
[] = {
6485 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6486 'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0};
6490 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
6491 if (rc
!= ERROR_SUCCESS
)
6492 return ERROR_SUCCESS
;
6494 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_DeleteService
, package
);
6495 msiobj_release( &view
->hdr
);
6499 static UINT
ITERATE_InstallODBCDriver( MSIRECORD
*rec
, LPVOID param
)
6501 MSIPACKAGE
*package
= param
;
6502 LPWSTR driver
, driver_path
, ptr
;
6503 WCHAR outpath
[MAX_PATH
];
6504 MSIFILE
*driver_file
= NULL
, *setup_file
= NULL
;
6507 LPCWSTR desc
, file_key
, component
;
6509 UINT r
= ERROR_SUCCESS
;
6511 static const WCHAR driver_fmt
[] = {
6512 'D','r','i','v','e','r','=','%','s',0};
6513 static const WCHAR setup_fmt
[] = {
6514 'S','e','t','u','p','=','%','s',0};
6515 static const WCHAR usage_fmt
[] = {
6516 'F','i','l','e','U','s','a','g','e','=','1',0};
6518 component
= MSI_RecordGetString( rec
, 2 );
6519 comp
= msi_get_loaded_component( package
, component
);
6521 return ERROR_SUCCESS
;
6523 comp
->Action
= msi_get_component_action( package
, comp
);
6524 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6526 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6527 return ERROR_SUCCESS
;
6529 desc
= MSI_RecordGetString(rec
, 3);
6531 file_key
= MSI_RecordGetString( rec
, 4 );
6532 if (file_key
) driver_file
= msi_get_loaded_file( package
, file_key
);
6534 file_key
= MSI_RecordGetString( rec
, 5 );
6535 if (file_key
) setup_file
= msi_get_loaded_file( package
, file_key
);
6539 ERR("ODBC Driver entry not found!\n");
6540 return ERROR_FUNCTION_FAILED
;
6543 len
= lstrlenW(desc
) + lstrlenW(driver_fmt
) + lstrlenW(driver_file
->FileName
);
6545 len
+= lstrlenW(setup_fmt
) + lstrlenW(setup_file
->FileName
);
6546 len
+= lstrlenW(usage_fmt
) + 2; /* \0\0 */
6548 driver
= msi_alloc(len
* sizeof(WCHAR
));
6550 return ERROR_OUTOFMEMORY
;
6553 lstrcpyW(ptr
, desc
);
6554 ptr
+= lstrlenW(ptr
) + 1;
6556 len
= sprintfW(ptr
, driver_fmt
, driver_file
->FileName
);
6561 len
= sprintfW(ptr
, setup_fmt
, setup_file
->FileName
);
6565 lstrcpyW(ptr
, usage_fmt
);
6566 ptr
+= lstrlenW(ptr
) + 1;
6569 if (!driver_file
->TargetPath
)
6571 const WCHAR
*dir
= msi_get_target_folder( package
, driver_file
->Component
->Directory
);
6572 driver_file
->TargetPath
= msi_build_directory_name( 2, dir
, driver_file
->FileName
);
6574 driver_path
= strdupW(driver_file
->TargetPath
);
6575 ptr
= strrchrW(driver_path
, '\\');
6576 if (ptr
) *ptr
= '\0';
6578 if (!SQLInstallDriverExW(driver
, driver_path
, outpath
, MAX_PATH
,
6579 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
6581 ERR("Failed to install SQL driver!\n");
6582 r
= ERROR_FUNCTION_FAILED
;
6585 uirow
= MSI_CreateRecord( 5 );
6586 MSI_RecordSetStringW( uirow
, 1, desc
);
6587 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6588 MSI_RecordSetStringW( uirow
, 3, driver_file
->Component
->Directory
);
6589 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6590 msiobj_release( &uirow
->hdr
);
6593 msi_free(driver_path
);
6598 static UINT
ITERATE_InstallODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
6600 MSIPACKAGE
*package
= param
;
6601 LPWSTR translator
, translator_path
, ptr
;
6602 WCHAR outpath
[MAX_PATH
];
6603 MSIFILE
*translator_file
= NULL
, *setup_file
= NULL
;
6606 LPCWSTR desc
, file_key
, component
;
6608 UINT r
= ERROR_SUCCESS
;
6610 static const WCHAR translator_fmt
[] = {
6611 'T','r','a','n','s','l','a','t','o','r','=','%','s',0};
6612 static const WCHAR setup_fmt
[] = {
6613 'S','e','t','u','p','=','%','s',0};
6615 component
= MSI_RecordGetString( rec
, 2 );
6616 comp
= msi_get_loaded_component( package
, component
);
6618 return ERROR_SUCCESS
;
6620 comp
->Action
= msi_get_component_action( package
, comp
);
6621 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6623 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6624 return ERROR_SUCCESS
;
6626 desc
= MSI_RecordGetString(rec
, 3);
6628 file_key
= MSI_RecordGetString( rec
, 4 );
6629 if (file_key
) translator_file
= msi_get_loaded_file( package
, file_key
);
6631 file_key
= MSI_RecordGetString( rec
, 5 );
6632 if (file_key
) setup_file
= msi_get_loaded_file( package
, file_key
);
6634 if (!translator_file
)
6636 ERR("ODBC Translator entry not found!\n");
6637 return ERROR_FUNCTION_FAILED
;
6640 len
= lstrlenW(desc
) + lstrlenW(translator_fmt
) + lstrlenW(translator_file
->FileName
) + 2; /* \0\0 */
6642 len
+= lstrlenW(setup_fmt
) + lstrlenW(setup_file
->FileName
);
6644 translator
= msi_alloc(len
* sizeof(WCHAR
));
6646 return ERROR_OUTOFMEMORY
;
6649 lstrcpyW(ptr
, desc
);
6650 ptr
+= lstrlenW(ptr
) + 1;
6652 len
= sprintfW(ptr
, translator_fmt
, translator_file
->FileName
);
6657 len
= sprintfW(ptr
, setup_fmt
, setup_file
->FileName
);
6662 translator_path
= strdupW(translator_file
->TargetPath
);
6663 ptr
= strrchrW(translator_path
, '\\');
6664 if (ptr
) *ptr
= '\0';
6666 if (!SQLInstallTranslatorExW(translator
, translator_path
, outpath
, MAX_PATH
,
6667 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
6669 ERR("Failed to install SQL translator!\n");
6670 r
= ERROR_FUNCTION_FAILED
;
6673 uirow
= MSI_CreateRecord( 5 );
6674 MSI_RecordSetStringW( uirow
, 1, desc
);
6675 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6676 MSI_RecordSetStringW( uirow
, 3, translator_file
->Component
->Directory
);
6677 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6678 msiobj_release( &uirow
->hdr
);
6680 msi_free(translator
);
6681 msi_free(translator_path
);
6686 static UINT
ITERATE_InstallODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
6688 MSIPACKAGE
*package
= param
;
6691 LPCWSTR desc
, driver
, component
;
6692 WORD request
= ODBC_ADD_SYS_DSN
;
6695 UINT r
= ERROR_SUCCESS
;
6698 static const WCHAR attrs_fmt
[] = {
6699 'D','S','N','=','%','s',0 };
6701 component
= MSI_RecordGetString( rec
, 2 );
6702 comp
= msi_get_loaded_component( package
, component
);
6704 return ERROR_SUCCESS
;
6706 comp
->Action
= msi_get_component_action( package
, comp
);
6707 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6709 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6710 return ERROR_SUCCESS
;
6713 desc
= MSI_RecordGetString(rec
, 3);
6714 driver
= MSI_RecordGetString(rec
, 4);
6715 registration
= MSI_RecordGetInteger(rec
, 5);
6717 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_ADD_SYS_DSN
;
6718 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_ADD_DSN
;
6720 len
= lstrlenW(attrs_fmt
) + lstrlenW(desc
) + 2; /* \0\0 */
6721 attrs
= msi_alloc(len
* sizeof(WCHAR
));
6723 return ERROR_OUTOFMEMORY
;
6725 len
= sprintfW(attrs
, attrs_fmt
, desc
);
6728 if (!SQLConfigDataSourceW(NULL
, request
, driver
, attrs
))
6730 ERR("Failed to install SQL data source!\n");
6731 r
= ERROR_FUNCTION_FAILED
;
6734 uirow
= MSI_CreateRecord( 5 );
6735 MSI_RecordSetStringW( uirow
, 1, desc
);
6736 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6737 MSI_RecordSetInteger( uirow
, 3, request
);
6738 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6739 msiobj_release( &uirow
->hdr
);
6746 static UINT
ACTION_InstallODBC( MSIPACKAGE
*package
)
6748 static const WCHAR driver_query
[] = {
6749 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6750 'O','D','B','C','D','r','i','v','e','r',0};
6751 static const WCHAR translator_query
[] = {
6752 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6753 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0};
6754 static const WCHAR source_query
[] = {
6755 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6756 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0};
6760 rc
= MSI_DatabaseOpenViewW(package
->db
, driver_query
, &view
);
6761 if (rc
== ERROR_SUCCESS
)
6763 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDriver
, package
);
6764 msiobj_release(&view
->hdr
);
6765 if (rc
!= ERROR_SUCCESS
)
6768 rc
= MSI_DatabaseOpenViewW(package
->db
, translator_query
, &view
);
6769 if (rc
== ERROR_SUCCESS
)
6771 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCTranslator
, package
);
6772 msiobj_release(&view
->hdr
);
6773 if (rc
!= ERROR_SUCCESS
)
6776 rc
= MSI_DatabaseOpenViewW(package
->db
, source_query
, &view
);
6777 if (rc
== ERROR_SUCCESS
)
6779 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDataSource
, package
);
6780 msiobj_release(&view
->hdr
);
6781 if (rc
!= ERROR_SUCCESS
)
6784 return ERROR_SUCCESS
;
6787 static UINT
ITERATE_RemoveODBCDriver( MSIRECORD
*rec
, LPVOID param
)
6789 MSIPACKAGE
*package
= param
;
6793 LPCWSTR desc
, component
;
6795 component
= MSI_RecordGetString( rec
, 2 );
6796 comp
= msi_get_loaded_component( package
, component
);
6798 return ERROR_SUCCESS
;
6800 comp
->Action
= msi_get_component_action( package
, comp
);
6801 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6803 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6804 return ERROR_SUCCESS
;
6807 desc
= MSI_RecordGetString( rec
, 3 );
6808 if (!SQLRemoveDriverW( desc
, FALSE
, &usage
))
6810 WARN("Failed to remove ODBC driver\n");
6814 FIXME("Usage count reached 0\n");
6817 uirow
= MSI_CreateRecord( 2 );
6818 MSI_RecordSetStringW( uirow
, 1, desc
);
6819 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6820 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6821 msiobj_release( &uirow
->hdr
);
6823 return ERROR_SUCCESS
;
6826 static UINT
ITERATE_RemoveODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
6828 MSIPACKAGE
*package
= param
;
6832 LPCWSTR desc
, component
;
6834 component
= MSI_RecordGetString( rec
, 2 );
6835 comp
= msi_get_loaded_component( package
, component
);
6837 return ERROR_SUCCESS
;
6839 comp
->Action
= msi_get_component_action( package
, comp
);
6840 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6842 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6843 return ERROR_SUCCESS
;
6846 desc
= MSI_RecordGetString( rec
, 3 );
6847 if (!SQLRemoveTranslatorW( desc
, &usage
))
6849 WARN("Failed to remove ODBC translator\n");
6853 FIXME("Usage count reached 0\n");
6856 uirow
= MSI_CreateRecord( 2 );
6857 MSI_RecordSetStringW( uirow
, 1, desc
);
6858 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6859 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6860 msiobj_release( &uirow
->hdr
);
6862 return ERROR_SUCCESS
;
6865 static UINT
ITERATE_RemoveODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
6867 MSIPACKAGE
*package
= param
;
6871 LPCWSTR desc
, driver
, component
;
6872 WORD request
= ODBC_REMOVE_SYS_DSN
;
6876 static const WCHAR attrs_fmt
[] = {
6877 'D','S','N','=','%','s',0 };
6879 component
= MSI_RecordGetString( rec
, 2 );
6880 comp
= msi_get_loaded_component( package
, component
);
6882 return ERROR_SUCCESS
;
6884 comp
->Action
= msi_get_component_action( package
, comp
);
6885 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6887 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6888 return ERROR_SUCCESS
;
6891 desc
= MSI_RecordGetString( rec
, 3 );
6892 driver
= MSI_RecordGetString( rec
, 4 );
6893 registration
= MSI_RecordGetInteger( rec
, 5 );
6895 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_REMOVE_SYS_DSN
;
6896 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_REMOVE_DSN
;
6898 len
= strlenW( attrs_fmt
) + strlenW( desc
) + 2; /* \0\0 */
6899 attrs
= msi_alloc( len
* sizeof(WCHAR
) );
6901 return ERROR_OUTOFMEMORY
;
6903 FIXME("Use ODBCSourceAttribute table\n");
6905 len
= sprintfW( attrs
, attrs_fmt
, desc
);
6908 if (!SQLConfigDataSourceW( NULL
, request
, driver
, attrs
))
6910 WARN("Failed to remove ODBC data source\n");
6914 uirow
= MSI_CreateRecord( 3 );
6915 MSI_RecordSetStringW( uirow
, 1, desc
);
6916 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6917 MSI_RecordSetInteger( uirow
, 3, request
);
6918 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6919 msiobj_release( &uirow
->hdr
);
6921 return ERROR_SUCCESS
;
6924 static UINT
ACTION_RemoveODBC( MSIPACKAGE
*package
)
6926 static const WCHAR driver_query
[] = {
6927 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6928 'O','D','B','C','D','r','i','v','e','r',0};
6929 static const WCHAR translator_query
[] = {
6930 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6931 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0};
6932 static const WCHAR source_query
[] = {
6933 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6934 'O','D','B','C','D','a','t','a','S','o','u','r','c','e',0};
6938 rc
= MSI_DatabaseOpenViewW( package
->db
, driver_query
, &view
);
6939 if (rc
== ERROR_SUCCESS
)
6941 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDriver
, package
);
6942 msiobj_release( &view
->hdr
);
6943 if (rc
!= ERROR_SUCCESS
)
6946 rc
= MSI_DatabaseOpenViewW( package
->db
, translator_query
, &view
);
6947 if (rc
== ERROR_SUCCESS
)
6949 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCTranslator
, package
);
6950 msiobj_release( &view
->hdr
);
6951 if (rc
!= ERROR_SUCCESS
)
6954 rc
= MSI_DatabaseOpenViewW( package
->db
, source_query
, &view
);
6955 if (rc
== ERROR_SUCCESS
)
6957 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDataSource
, package
);
6958 msiobj_release( &view
->hdr
);
6959 if (rc
!= ERROR_SUCCESS
)
6962 return ERROR_SUCCESS
;
6965 #define ENV_ACT_SETALWAYS 0x1
6966 #define ENV_ACT_SETABSENT 0x2
6967 #define ENV_ACT_REMOVE 0x4
6968 #define ENV_ACT_REMOVEMATCH 0x8
6970 #define ENV_MOD_MACHINE 0x20000000
6971 #define ENV_MOD_APPEND 0x40000000
6972 #define ENV_MOD_PREFIX 0x80000000
6973 #define ENV_MOD_MASK 0xC0000000
6975 #define check_flag_combo(x, y) ((x) & ~(y)) == (y)
6977 static UINT
env_parse_flags( LPCWSTR
*name
, LPCWSTR
*value
, DWORD
*flags
)
6979 LPCWSTR cptr
= *name
;
6981 static const WCHAR prefix
[] = {'[','~',']',0};
6982 static const int prefix_len
= 3;
6988 *flags
|= ENV_ACT_SETALWAYS
;
6989 else if (*cptr
== '+')
6990 *flags
|= ENV_ACT_SETABSENT
;
6991 else if (*cptr
== '-')
6992 *flags
|= ENV_ACT_REMOVE
;
6993 else if (*cptr
== '!')
6994 *flags
|= ENV_ACT_REMOVEMATCH
;
6995 else if (*cptr
== '*')
6996 *flags
|= ENV_MOD_MACHINE
;
7006 ERR("Missing environment variable\n");
7007 return ERROR_FUNCTION_FAILED
;
7012 LPCWSTR ptr
= *value
;
7013 if (!strncmpW(ptr
, prefix
, prefix_len
))
7015 if (ptr
[prefix_len
] == szSemiColon
[0])
7017 *flags
|= ENV_MOD_APPEND
;
7018 *value
+= lstrlenW(prefix
);
7025 else if (lstrlenW(*value
) >= prefix_len
)
7027 ptr
+= lstrlenW(ptr
) - prefix_len
;
7028 if (!strcmpW( ptr
, prefix
))
7030 if ((ptr
-1) > *value
&& *(ptr
-1) == szSemiColon
[0])
7032 *flags
|= ENV_MOD_PREFIX
;
7033 /* the "[~]" will be removed by deformat_string */;
7043 if (check_flag_combo(*flags
, ENV_ACT_SETALWAYS
| ENV_ACT_SETABSENT
) ||
7044 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETABSENT
) ||
7045 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETALWAYS
) ||
7046 check_flag_combo(*flags
, ENV_ACT_SETABSENT
| ENV_MOD_MASK
))
7048 ERR("Invalid flags: %08x\n", *flags
);
7049 return ERROR_FUNCTION_FAILED
;
7053 *flags
= ENV_ACT_SETALWAYS
| ENV_ACT_REMOVE
;
7055 return ERROR_SUCCESS
;
7058 static UINT
open_env_key( DWORD flags
, HKEY
*key
)
7060 static const WCHAR user_env
[] =
7061 {'E','n','v','i','r','o','n','m','e','n','t',0};
7062 static const WCHAR machine_env
[] =
7063 {'S','y','s','t','e','m','\\',
7064 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
7065 'C','o','n','t','r','o','l','\\',
7066 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
7067 'E','n','v','i','r','o','n','m','e','n','t',0};
7072 if (flags
& ENV_MOD_MACHINE
)
7075 root
= HKEY_LOCAL_MACHINE
;
7080 root
= HKEY_CURRENT_USER
;
7083 res
= RegOpenKeyExW( root
, env
, 0, KEY_ALL_ACCESS
, key
);
7084 if (res
!= ERROR_SUCCESS
)
7086 WARN("Failed to open key %s (%d)\n", debugstr_w(env
), res
);
7087 return ERROR_FUNCTION_FAILED
;
7090 return ERROR_SUCCESS
;
7093 static UINT
ITERATE_WriteEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
7095 MSIPACKAGE
*package
= param
;
7096 LPCWSTR name
, value
, component
;
7097 WCHAR
*data
= NULL
, *newval
= NULL
, *deformatted
= NULL
, *p
, *q
;
7098 DWORD flags
, type
, size
, len
, len_value
= 0;
7103 int action
= 0, found
= 0;
7105 component
= MSI_RecordGetString(rec
, 4);
7106 comp
= msi_get_loaded_component(package
, component
);
7108 return ERROR_SUCCESS
;
7110 comp
->Action
= msi_get_component_action( package
, comp
);
7111 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
7113 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
7114 return ERROR_SUCCESS
;
7116 name
= MSI_RecordGetString(rec
, 2);
7117 value
= MSI_RecordGetString(rec
, 3);
7119 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
7121 res
= env_parse_flags(&name
, &value
, &flags
);
7122 if (res
!= ERROR_SUCCESS
|| !value
)
7125 if (value
&& !deformat_string(package
, value
, &deformatted
))
7127 res
= ERROR_OUTOFMEMORY
;
7131 if ((value
= deformatted
))
7133 if (flags
& ENV_MOD_PREFIX
)
7135 p
= strrchrW( value
, ';' );
7136 len_value
= p
- value
;
7138 else if (flags
& ENV_MOD_APPEND
)
7140 value
= strchrW( value
, ';' ) + 1;
7141 len_value
= strlenW( value
);
7143 else len_value
= strlenW( value
);
7146 res
= open_env_key( flags
, &env
);
7147 if (res
!= ERROR_SUCCESS
)
7150 if (flags
& ENV_MOD_MACHINE
)
7151 action
|= 0x20000000;
7155 res
= RegQueryValueExW(env
, name
, NULL
, &type
, NULL
, &size
);
7156 if ((res
!= ERROR_SUCCESS
&& res
!= ERROR_FILE_NOT_FOUND
) ||
7157 (res
== ERROR_SUCCESS
&& type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
))
7160 if ((res
== ERROR_FILE_NOT_FOUND
|| !(flags
& ENV_MOD_MASK
)))
7164 /* Nothing to do. */
7167 res
= ERROR_SUCCESS
;
7170 size
= (lstrlenW(value
) + 1) * sizeof(WCHAR
);
7171 newval
= strdupW(value
);
7174 res
= ERROR_OUTOFMEMORY
;
7182 /* Contrary to MSDN, +-variable to [~];path works */
7183 if (flags
& ENV_ACT_SETABSENT
&& !(flags
& ENV_MOD_MASK
))
7185 res
= ERROR_SUCCESS
;
7189 if (!(p
= q
= data
= msi_alloc( size
)))
7191 msi_free(deformatted
);
7193 return ERROR_OUTOFMEMORY
;
7196 res
= RegQueryValueExW( env
, name
, NULL
, &type
, (BYTE
*)data
, &size
);
7197 if (res
!= ERROR_SUCCESS
)
7200 if (flags
& ENV_ACT_REMOVEMATCH
&& (!value
|| !strcmpW( data
, value
)))
7203 res
= RegDeleteValueW(env
, name
);
7204 if (res
!= ERROR_SUCCESS
)
7205 WARN("Failed to remove value %s (%d)\n", debugstr_w(name
), res
);
7211 while (*q
&& *q
!= ';') q
++;
7213 if (value
&& len
== len_value
&& !memcmp( value
, p
, len
* sizeof(WCHAR
) ) &&
7214 (!p
[len
] || p
[len
] == ';'))
7225 TRACE("string already set\n");
7229 size
= (len_value
+ 1 + strlenW( data
) + 1) * sizeof(WCHAR
);
7230 if (!(p
= newval
= msi_alloc( size
)))
7232 res
= ERROR_OUTOFMEMORY
;
7236 if (flags
& ENV_MOD_PREFIX
)
7238 memcpy( newval
, value
, len_value
* sizeof(WCHAR
) );
7239 newval
[len_value
] = ';';
7240 p
= newval
+ len_value
+ 1;
7241 action
|= 0x80000000;
7246 if (flags
& ENV_MOD_APPEND
)
7248 p
+= strlenW( data
);
7250 memcpy( p
, value
, (len_value
+ 1) * sizeof(WCHAR
) );
7251 action
|= 0x40000000;
7254 TRACE("setting %s to %s\n", debugstr_w(name
), debugstr_w(newval
));
7255 res
= RegSetValueExW( env
, name
, 0, type
, (BYTE
*)newval
, size
);
7258 WARN("Failed to set %s to %s (%d)\n", debugstr_w(name
), debugstr_w(newval
), res
);
7262 uirow
= MSI_CreateRecord( 3 );
7263 MSI_RecordSetStringW( uirow
, 1, name
);
7264 MSI_RecordSetStringW( uirow
, 2, newval
);
7265 MSI_RecordSetInteger( uirow
, 3, action
);
7266 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
7267 msiobj_release( &uirow
->hdr
);
7269 if (env
) RegCloseKey(env
);
7270 msi_free(deformatted
);
7276 static UINT
ACTION_WriteEnvironmentStrings( MSIPACKAGE
*package
)
7278 static const WCHAR query
[] = {
7279 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7280 '`','E','n','v','i','r','o','n','m','e','n','t','`',0};
7284 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
7285 if (rc
!= ERROR_SUCCESS
)
7286 return ERROR_SUCCESS
;
7288 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteEnvironmentString
, package
);
7289 msiobj_release(&view
->hdr
);
7293 static UINT
ITERATE_RemoveEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
7295 MSIPACKAGE
*package
= param
;
7296 LPCWSTR name
, value
, component
;
7297 WCHAR
*p
, *q
, *deformatted
= NULL
, *new_value
= NULL
;
7298 DWORD flags
, type
, size
, len
, len_value
= 0, len_new_value
;
7306 component
= MSI_RecordGetString( rec
, 4 );
7307 comp
= msi_get_loaded_component( package
, component
);
7309 return ERROR_SUCCESS
;
7311 comp
->Action
= msi_get_component_action( package
, comp
);
7312 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
7314 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
7315 return ERROR_SUCCESS
;
7317 name
= MSI_RecordGetString( rec
, 2 );
7318 value
= MSI_RecordGetString( rec
, 3 );
7320 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
7322 r
= env_parse_flags( &name
, &value
, &flags
);
7323 if (r
!= ERROR_SUCCESS
)
7326 if (!(flags
& ENV_ACT_REMOVE
))
7328 TRACE("Environment variable %s not marked for removal\n", debugstr_w(name
));
7329 return ERROR_SUCCESS
;
7332 if (value
&& !deformat_string( package
, value
, &deformatted
))
7333 return ERROR_OUTOFMEMORY
;
7335 if ((value
= deformatted
))
7337 if (flags
& ENV_MOD_PREFIX
)
7339 p
= strchrW( value
, ';' );
7340 len_value
= p
- value
;
7342 else if (flags
& ENV_MOD_APPEND
)
7344 value
= strchrW( value
, ';' ) + 1;
7345 len_value
= strlenW( value
);
7347 else len_value
= strlenW( value
);
7350 r
= open_env_key( flags
, &env
);
7351 if (r
!= ERROR_SUCCESS
)
7357 if (flags
& ENV_MOD_MACHINE
)
7358 action
|= 0x20000000;
7362 res
= RegQueryValueExW( env
, name
, NULL
, &type
, NULL
, &size
);
7363 if (res
!= ERROR_SUCCESS
|| (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
))
7366 if (!(new_value
= msi_alloc( size
))) goto done
;
7368 res
= RegQueryValueExW( env
, name
, NULL
, &type
, (BYTE
*)new_value
, &size
);
7369 if (res
!= ERROR_SUCCESS
)
7372 len_new_value
= size
/ sizeof(WCHAR
) - 1;
7376 while (*q
&& *q
!= ';') q
++;
7378 if (value
&& len
== len_value
&& !memcmp( value
, p
, len
* sizeof(WCHAR
) ))
7381 memmove( p
, q
, (len_new_value
- (q
- new_value
) + 1) * sizeof(WCHAR
) );
7388 if (!new_value
[0] || !value
)
7390 TRACE("removing %s\n", debugstr_w(name
));
7391 res
= RegDeleteValueW( env
, name
);
7392 if (res
!= ERROR_SUCCESS
)
7393 WARN("failed to delete value %s (%d)\n", debugstr_w(name
), res
);
7397 TRACE("setting %s to %s\n", debugstr_w(name
), debugstr_w(new_value
));
7398 size
= (strlenW( new_value
) + 1) * sizeof(WCHAR
);
7399 res
= RegSetValueExW( env
, name
, 0, type
, (BYTE
*)new_value
, size
);
7400 if (res
!= ERROR_SUCCESS
)
7401 WARN("failed to set %s to %s (%d)\n", debugstr_w(name
), debugstr_w(new_value
), res
);
7405 uirow
= MSI_CreateRecord( 3 );
7406 MSI_RecordSetStringW( uirow
, 1, name
);
7407 MSI_RecordSetStringW( uirow
, 2, value
);
7408 MSI_RecordSetInteger( uirow
, 3, action
);
7409 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
7410 msiobj_release( &uirow
->hdr
);
7412 if (env
) RegCloseKey( env
);
7413 msi_free( deformatted
);
7414 msi_free( new_value
);
7418 static UINT
ACTION_RemoveEnvironmentStrings( MSIPACKAGE
*package
)
7420 static const WCHAR query
[] = {
7421 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7422 '`','E','n','v','i','r','o','n','m','e','n','t','`',0};
7426 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
7427 if (rc
!= ERROR_SUCCESS
)
7428 return ERROR_SUCCESS
;
7430 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveEnvironmentString
, package
);
7431 msiobj_release( &view
->hdr
);
7435 UINT
msi_validate_product_id( MSIPACKAGE
*package
)
7437 LPWSTR key
, template, id
;
7438 UINT r
= ERROR_SUCCESS
;
7440 id
= msi_dup_property( package
->db
, szProductID
);
7444 return ERROR_SUCCESS
;
7446 template = msi_dup_property( package
->db
, szPIDTemplate
);
7447 key
= msi_dup_property( package
->db
, szPIDKEY
);
7448 if (key
&& template)
7450 FIXME( "partial stub: template %s key %s\n", debugstr_w(template), debugstr_w(key
) );
7452 WARN("Product key validation HACK, see CORE-14710\n");
7454 r
= msi_set_property( package
->db
, szProductID
, key
, -1 );
7457 msi_free( template );
7462 static UINT
ACTION_ValidateProductID( MSIPACKAGE
*package
)
7464 return msi_validate_product_id( package
);
7467 static UINT
ACTION_ScheduleReboot( MSIPACKAGE
*package
)
7470 package
->need_reboot_at_end
= 1;
7471 return ERROR_SUCCESS
;
7474 static UINT
ACTION_AllocateRegistrySpace( MSIPACKAGE
*package
)
7476 static const WCHAR szAvailableFreeReg
[] =
7477 {'A','V','A','I','L','A','B','L','E','F','R','E','E','R','E','G',0};
7479 int space
= msi_get_property_int( package
->db
, szAvailableFreeReg
, 0 );
7481 TRACE("%p %d kilobytes\n", package
, space
);
7483 uirow
= MSI_CreateRecord( 1 );
7484 MSI_RecordSetInteger( uirow
, 1, space
);
7485 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
7486 msiobj_release( &uirow
->hdr
);
7488 return ERROR_SUCCESS
;
7491 static UINT
ACTION_DisableRollback( MSIPACKAGE
*package
)
7493 TRACE("%p\n", package
);
7495 msi_set_property( package
->db
, szRollbackDisabled
, szOne
, -1 );
7496 return ERROR_SUCCESS
;
7499 static UINT
ACTION_InstallAdminPackage( MSIPACKAGE
*package
)
7501 FIXME("%p\n", package
);
7502 return ERROR_SUCCESS
;
7505 static UINT
ACTION_SetODBCFolders( MSIPACKAGE
*package
)
7507 static const WCHAR driver_query
[] = {
7508 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7509 'O','D','B','C','D','r','i','v','e','r',0};
7510 static const WCHAR translator_query
[] = {
7511 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7512 'O','D','B','C','T','r','a','n','s','l','a','t','o','r',0};
7516 r
= MSI_DatabaseOpenViewW( package
->db
, driver_query
, &view
);
7517 if (r
== ERROR_SUCCESS
)
7520 r
= MSI_IterateRecords( view
, &count
, NULL
, package
);
7521 msiobj_release( &view
->hdr
);
7522 if (r
!= ERROR_SUCCESS
)
7524 if (count
) FIXME("ignored %u rows in ODBCDriver table\n", count
);
7526 r
= MSI_DatabaseOpenViewW( package
->db
, translator_query
, &view
);
7527 if (r
== ERROR_SUCCESS
)
7530 r
= MSI_IterateRecords( view
, &count
, NULL
, package
);
7531 msiobj_release( &view
->hdr
);
7532 if (r
!= ERROR_SUCCESS
)
7534 if (count
) FIXME("ignored %u rows in ODBCTranslator table\n", count
);
7536 return ERROR_SUCCESS
;
7539 static UINT
ITERATE_RemoveExistingProducts( MSIRECORD
*rec
, LPVOID param
)
7541 static const WCHAR fmtW
[] =
7542 {'m','s','i','e','x','e','c',' ','/','q','n',' ','/','i',' ','%','s',' ',
7543 'R','E','M','O','V','E','=','%','s',0};
7544 MSIPACKAGE
*package
= param
;
7545 const WCHAR
*property
= MSI_RecordGetString( rec
, 7 );
7546 int attrs
= MSI_RecordGetInteger( rec
, 5 );
7547 UINT len
= sizeof(fmtW
)/sizeof(fmtW
[0]);
7548 WCHAR
*product
, *features
, *cmd
;
7550 PROCESS_INFORMATION info
;
7553 if (attrs
& msidbUpgradeAttributesOnlyDetect
) return ERROR_SUCCESS
;
7554 if (!(product
= msi_dup_property( package
->db
, property
))) return ERROR_SUCCESS
;
7556 deformat_string( package
, MSI_RecordGetString( rec
, 6 ), &features
);
7558 len
+= strlenW( product
);
7560 len
+= strlenW( features
);
7562 len
+= sizeof(szAll
) / sizeof(szAll
[0]);
7564 if (!(cmd
= msi_alloc( len
* sizeof(WCHAR
) )))
7566 msi_free( product
);
7567 msi_free( features
);
7568 return ERROR_OUTOFMEMORY
;
7570 sprintfW( cmd
, fmtW
, product
, features
? features
: szAll
);
7571 msi_free( product
);
7572 msi_free( features
);
7574 memset( &si
, 0, sizeof(STARTUPINFOW
) );
7575 ret
= CreateProcessW( NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &info
);
7577 if (!ret
) return GetLastError();
7578 CloseHandle( info
.hThread
);
7580 WaitForSingleObject( info
.hProcess
, INFINITE
);
7581 CloseHandle( info
.hProcess
);
7582 return ERROR_SUCCESS
;
7585 static UINT
ACTION_RemoveExistingProducts( MSIPACKAGE
*package
)
7587 static const WCHAR query
[] = {
7588 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','U','p','g','r','a','d','e',0};
7592 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
7593 if (r
== ERROR_SUCCESS
)
7595 r
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveExistingProducts
, package
);
7596 msiobj_release( &view
->hdr
);
7597 if (r
!= ERROR_SUCCESS
)
7600 return ERROR_SUCCESS
;
7603 static UINT
ITERATE_MigrateFeatureStates( MSIRECORD
*rec
, LPVOID param
)
7605 MSIPACKAGE
*package
= param
;
7606 int attributes
= MSI_RecordGetInteger( rec
, 5 );
7608 if (attributes
& msidbUpgradeAttributesMigrateFeatures
)
7610 const WCHAR
*upgrade_code
= MSI_RecordGetString( rec
, 1 );
7611 const WCHAR
*version_min
= MSI_RecordGetString( rec
, 2 );
7612 const WCHAR
*version_max
= MSI_RecordGetString( rec
, 3 );
7613 const WCHAR
*language
= MSI_RecordGetString( rec
, 4 );
7617 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
7619 r
= MSIREG_OpenClassesUpgradeCodesKey( upgrade_code
, &hkey
, FALSE
);
7620 if (r
!= ERROR_SUCCESS
)
7621 return ERROR_SUCCESS
;
7625 r
= MSIREG_OpenUserUpgradeCodesKey( upgrade_code
, &hkey
, FALSE
);
7626 if (r
!= ERROR_SUCCESS
)
7627 return ERROR_SUCCESS
;
7629 RegCloseKey( hkey
);
7631 FIXME("migrate feature states from %s version min %s version max %s language %s\n",
7632 debugstr_w(upgrade_code
), debugstr_w(version_min
),
7633 debugstr_w(version_max
), debugstr_w(language
));
7635 return ERROR_SUCCESS
;
7638 static UINT
ACTION_MigrateFeatureStates( MSIPACKAGE
*package
)
7640 static const WCHAR query
[] = {
7641 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7642 'U','p','g','r','a','d','e',0};
7646 if (msi_get_property_int( package
->db
, szInstalled
, 0 ))
7648 TRACE("product is installed, skipping action\n");
7649 return ERROR_SUCCESS
;
7651 if (msi_get_property_int( package
->db
, szPreselected
, 0 ))
7653 TRACE("Preselected property is set, not migrating feature states\n");
7654 return ERROR_SUCCESS
;
7656 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
7657 if (r
== ERROR_SUCCESS
)
7659 r
= MSI_IterateRecords( view
, NULL
, ITERATE_MigrateFeatureStates
, package
);
7660 msiobj_release( &view
->hdr
);
7661 if (r
!= ERROR_SUCCESS
)
7664 return ERROR_SUCCESS
;
7667 static void bind_image( const char *filename
, const char *path
)
7669 if (!BindImageEx( 0, filename
, path
, NULL
, NULL
))
7671 WARN("failed to bind image %u\n", GetLastError());
7675 static UINT
ITERATE_BindImage( MSIRECORD
*rec
, LPVOID param
)
7679 MSIPACKAGE
*package
= param
;
7680 const WCHAR
*key
= MSI_RecordGetString( rec
, 1 );
7681 const WCHAR
*paths
= MSI_RecordGetString( rec
, 2 );
7682 char *filenameA
, *pathA
;
7683 WCHAR
*pathW
, **path_list
;
7685 if (!(file
= msi_get_loaded_file( package
, key
)))
7687 WARN("file %s not found\n", debugstr_w(key
));
7688 return ERROR_SUCCESS
;
7690 if (!(filenameA
= strdupWtoA( file
->TargetPath
))) return ERROR_SUCCESS
;
7691 path_list
= msi_split_string( paths
, ';' );
7692 if (!path_list
) bind_image( filenameA
, NULL
);
7695 for (i
= 0; path_list
[i
] && path_list
[i
][0]; i
++)
7697 deformat_string( package
, path_list
[i
], &pathW
);
7698 if ((pathA
= strdupWtoA( pathW
)))
7700 bind_image( filenameA
, pathA
);
7706 msi_free( path_list
);
7707 msi_free( filenameA
);
7708 return ERROR_SUCCESS
;
7711 static UINT
ACTION_BindImage( MSIPACKAGE
*package
)
7713 static const WCHAR query
[] = {
7714 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7715 'B','i','n','d','I','m','a','g','e',0};
7719 r
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
7720 if (r
== ERROR_SUCCESS
)
7722 r
= MSI_IterateRecords( view
, NULL
, ITERATE_BindImage
, package
);
7723 msiobj_release( &view
->hdr
);
7724 if (r
!= ERROR_SUCCESS
)
7727 return ERROR_SUCCESS
;
7730 static UINT
msi_unimplemented_action_stub( MSIPACKAGE
*package
, LPCSTR action
, LPCWSTR table
)
7732 static const WCHAR query
[] = {
7733 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','%','s','`',0};
7738 r
= MSI_OpenQuery( package
->db
, &view
, query
, table
);
7739 if (r
== ERROR_SUCCESS
)
7741 r
= MSI_IterateRecords(view
, &count
, NULL
, package
);
7742 msiobj_release(&view
->hdr
);
7743 if (r
!= ERROR_SUCCESS
)
7746 if (count
) FIXME("%s: ignored %u rows from %s\n", action
, count
, debugstr_w(table
));
7747 return ERROR_SUCCESS
;
7750 static UINT
ACTION_IsolateComponents( MSIPACKAGE
*package
)
7752 static const WCHAR table
[] = {
7753 'I','s','o','l','a','t','e','d','C','o','m','p','o','n','e','n','t',0 };
7754 return msi_unimplemented_action_stub( package
, "IsolateComponents", table
);
7757 static UINT
ACTION_RMCCPSearch( MSIPACKAGE
*package
)
7759 static const WCHAR table
[] = { 'C','C','P','S','e','a','r','c','h',0 };
7760 return msi_unimplemented_action_stub( package
, "RMCCPSearch", table
);
7763 static UINT
ACTION_RegisterComPlus( MSIPACKAGE
*package
)
7765 static const WCHAR table
[] = { 'C','o','m','p','l','u','s',0 };
7766 return msi_unimplemented_action_stub( package
, "RegisterComPlus", table
);
7769 static UINT
ACTION_UnregisterComPlus( MSIPACKAGE
*package
)
7771 static const WCHAR table
[] = { 'C','o','m','p','l','u','s',0 };
7772 return msi_unimplemented_action_stub( package
, "UnregisterComPlus", table
);
7775 static UINT
ACTION_InstallSFPCatalogFile( MSIPACKAGE
*package
)
7777 static const WCHAR table
[] = { 'S','F','P','C','a','t','a','l','o','g',0 };
7778 return msi_unimplemented_action_stub( package
, "InstallSFPCatalogFile", table
);
7783 const WCHAR
*action
;
7784 const UINT description
;
7785 const UINT
template;
7786 UINT (*handler
)(MSIPACKAGE
*);
7787 const WCHAR
*action_rollback
;
7791 { szAllocateRegistrySpace
, IDS_DESC_ALLOCATEREGISTRYSPACE
, IDS_TEMP_ALLOCATEREGISTRYSPACE
, ACTION_AllocateRegistrySpace
, NULL
},
7792 { szAppSearch
, IDS_DESC_APPSEARCH
, IDS_TEMP_APPSEARCH
, ACTION_AppSearch
, NULL
},
7793 { szBindImage
, IDS_DESC_BINDIMAGE
, IDS_TEMP_BINDIMAGE
, ACTION_BindImage
, NULL
},
7794 { szCCPSearch
, IDS_DESC_CCPSEARCH
, 0, ACTION_CCPSearch
, NULL
},
7795 { szCostFinalize
, IDS_DESC_COSTFINALIZE
, 0, ACTION_CostFinalize
, NULL
},
7796 { szCostInitialize
, IDS_DESC_COSTINITIALIZE
, 0, ACTION_CostInitialize
, NULL
},
7797 { szCreateFolders
, IDS_DESC_CREATEFOLDERS
, IDS_TEMP_CREATEFOLDERS
, ACTION_CreateFolders
, szRemoveFolders
},
7798 { szCreateShortcuts
, IDS_DESC_CREATESHORTCUTS
, IDS_TEMP_CREATESHORTCUTS
, ACTION_CreateShortcuts
, szRemoveShortcuts
},
7799 { szDeleteServices
, IDS_DESC_DELETESERVICES
, IDS_TEMP_DELETESERVICES
, ACTION_DeleteServices
, szInstallServices
},
7800 { szDisableRollback
, 0, 0, ACTION_DisableRollback
, NULL
},
7801 { szDuplicateFiles
, IDS_DESC_DUPLICATEFILES
, IDS_TEMP_DUPLICATEFILES
, ACTION_DuplicateFiles
, szRemoveDuplicateFiles
},
7802 { szExecuteAction
, 0, 0, ACTION_ExecuteAction
, NULL
},
7803 { szFileCost
, IDS_DESC_FILECOST
, 0, ACTION_FileCost
, NULL
},
7804 { szFindRelatedProducts
, IDS_DESC_FINDRELATEDPRODUCTS
, IDS_TEMP_FINDRELATEDPRODUCTS
, ACTION_FindRelatedProducts
, NULL
},
7805 { szForceReboot
, 0, 0, ACTION_ForceReboot
, NULL
},
7806 { szInstallAdminPackage
, IDS_DESC_INSTALLADMINPACKAGE
, IDS_TEMP_INSTALLADMINPACKAGE
, ACTION_InstallAdminPackage
, NULL
},
7807 { szInstallExecute
, 0, 0, ACTION_InstallExecute
, NULL
},
7808 { szInstallExecuteAgain
, 0, 0, ACTION_InstallExecute
, NULL
},
7809 { szInstallFiles
, IDS_DESC_INSTALLFILES
, IDS_TEMP_INSTALLFILES
, ACTION_InstallFiles
, szRemoveFiles
},
7810 { szInstallFinalize
, 0, 0, ACTION_InstallFinalize
, NULL
},
7811 { szInstallInitialize
, 0, 0, ACTION_InstallInitialize
, NULL
},
7812 { szInstallODBC
, IDS_DESC_INSTALLODBC
, 0, ACTION_InstallODBC
, szRemoveODBC
},
7813 { szInstallServices
, IDS_DESC_INSTALLSERVICES
, IDS_TEMP_INSTALLSERVICES
, ACTION_InstallServices
, szDeleteServices
},
7814 { szInstallSFPCatalogFile
, IDS_DESC_INSTALLSFPCATALOGFILE
, IDS_TEMP_INSTALLSFPCATALOGFILE
, ACTION_InstallSFPCatalogFile
, NULL
},
7815 { szInstallValidate
, IDS_DESC_INSTALLVALIDATE
, 0, ACTION_InstallValidate
, NULL
},
7816 { szIsolateComponents
, 0, 0, ACTION_IsolateComponents
, NULL
},
7817 { szLaunchConditions
, IDS_DESC_LAUNCHCONDITIONS
, 0, ACTION_LaunchConditions
, NULL
},
7818 { szMigrateFeatureStates
, IDS_DESC_MIGRATEFEATURESTATES
, IDS_TEMP_MIGRATEFEATURESTATES
, ACTION_MigrateFeatureStates
, NULL
},
7819 { szMoveFiles
, IDS_DESC_MOVEFILES
, IDS_TEMP_MOVEFILES
, ACTION_MoveFiles
, NULL
},
7820 { szMsiPublishAssemblies
, IDS_DESC_MSIPUBLISHASSEMBLIES
, IDS_TEMP_MSIPUBLISHASSEMBLIES
, ACTION_MsiPublishAssemblies
, szMsiUnpublishAssemblies
},
7821 { szMsiUnpublishAssemblies
, IDS_DESC_MSIUNPUBLISHASSEMBLIES
, IDS_TEMP_MSIUNPUBLISHASSEMBLIES
, ACTION_MsiUnpublishAssemblies
, szMsiPublishAssemblies
},
7822 { szPatchFiles
, IDS_DESC_PATCHFILES
, IDS_TEMP_PATCHFILES
, ACTION_PatchFiles
, NULL
},
7823 { szProcessComponents
, IDS_DESC_PROCESSCOMPONENTS
, 0, ACTION_ProcessComponents
, szProcessComponents
},
7824 { szPublishComponents
, IDS_DESC_PUBLISHCOMPONENTS
, IDS_TEMP_PUBLISHCOMPONENTS
, ACTION_PublishComponents
, szUnpublishComponents
},
7825 { szPublishFeatures
, IDS_DESC_PUBLISHFEATURES
, IDS_TEMP_PUBLISHFEATURES
, ACTION_PublishFeatures
, szUnpublishFeatures
},
7826 { szPublishProduct
, IDS_DESC_PUBLISHPRODUCT
, 0, ACTION_PublishProduct
, szUnpublishProduct
},
7827 { szRegisterClassInfo
, IDS_DESC_REGISTERCLASSINFO
, IDS_TEMP_REGISTERCLASSINFO
, ACTION_RegisterClassInfo
, szUnregisterClassInfo
},
7828 { szRegisterComPlus
, IDS_DESC_REGISTERCOMPLUS
, IDS_TEMP_REGISTERCOMPLUS
, ACTION_RegisterComPlus
, szUnregisterComPlus
},
7829 { szRegisterExtensionInfo
, IDS_DESC_REGISTEREXTENSIONINFO
, 0, ACTION_RegisterExtensionInfo
, szUnregisterExtensionInfo
},
7830 { szRegisterFonts
, IDS_DESC_REGISTERFONTS
, IDS_TEMP_REGISTERFONTS
, ACTION_RegisterFonts
, szUnregisterFonts
},
7831 { szRegisterMIMEInfo
, IDS_DESC_REGISTERMIMEINFO
, IDS_TEMP_REGISTERMIMEINFO
, ACTION_RegisterMIMEInfo
, szUnregisterMIMEInfo
},
7832 { szRegisterProduct
, IDS_DESC_REGISTERPRODUCT
, 0, ACTION_RegisterProduct
, NULL
},
7833 { szRegisterProgIdInfo
, IDS_DESC_REGISTERPROGIDINFO
, IDS_TEMP_REGISTERPROGIDINFO
, ACTION_RegisterProgIdInfo
, szUnregisterProgIdInfo
},
7834 { szRegisterTypeLibraries
, IDS_DESC_REGISTERTYPELIBRARIES
, IDS_TEMP_REGISTERTYPELIBRARIES
, ACTION_RegisterTypeLibraries
, szUnregisterTypeLibraries
},
7835 { szRegisterUser
, IDS_DESC_REGISTERUSER
, 0, ACTION_RegisterUser
, NULL
},
7836 { szRemoveDuplicateFiles
, IDS_DESC_REMOVEDUPLICATEFILES
, IDS_TEMP_REMOVEDUPLICATEFILES
, ACTION_RemoveDuplicateFiles
, szDuplicateFiles
},
7837 { szRemoveEnvironmentStrings
, IDS_DESC_REMOVEENVIRONMENTSTRINGS
, IDS_TEMP_REMOVEENVIRONMENTSTRINGS
, ACTION_RemoveEnvironmentStrings
, szWriteEnvironmentStrings
},
7838 { szRemoveExistingProducts
, IDS_DESC_REMOVEEXISTINGPRODUCTS
, IDS_TEMP_REMOVEEXISTINGPRODUCTS
, ACTION_RemoveExistingProducts
, NULL
},
7839 { szRemoveFiles
, IDS_DESC_REMOVEFILES
, IDS_TEMP_REMOVEFILES
, ACTION_RemoveFiles
, szInstallFiles
},
7840 { szRemoveFolders
, IDS_DESC_REMOVEFOLDERS
, IDS_TEMP_REMOVEFOLDERS
, ACTION_RemoveFolders
, szCreateFolders
},
7841 { szRemoveIniValues
, IDS_DESC_REMOVEINIVALUES
, IDS_TEMP_REMOVEINIVALUES
, ACTION_RemoveIniValues
, szWriteIniValues
},
7842 { szRemoveODBC
, IDS_DESC_REMOVEODBC
, 0, ACTION_RemoveODBC
, szInstallODBC
},
7843 { szRemoveRegistryValues
, IDS_DESC_REMOVEREGISTRYVALUES
, IDS_TEMP_REMOVEREGISTRYVALUES
, ACTION_RemoveRegistryValues
, szWriteRegistryValues
},
7844 { szRemoveShortcuts
, IDS_DESC_REMOVESHORTCUTS
, IDS_TEMP_REMOVESHORTCUTS
, ACTION_RemoveShortcuts
, szCreateShortcuts
},
7845 { szResolveSource
, 0, 0, ACTION_ResolveSource
, NULL
},
7846 { szRMCCPSearch
, IDS_DESC_RMCCPSEARCH
, 0, ACTION_RMCCPSearch
, NULL
},
7847 { szScheduleReboot
, 0, 0, ACTION_ScheduleReboot
, NULL
},
7848 { szSelfRegModules
, IDS_DESC_SELFREGMODULES
, IDS_TEMP_SELFREGMODULES
, ACTION_SelfRegModules
, szSelfUnregModules
},
7849 { szSelfUnregModules
, IDS_DESC_SELFUNREGMODULES
, IDS_TEMP_SELFUNREGMODULES
, ACTION_SelfUnregModules
, szSelfRegModules
},
7850 { szSetODBCFolders
, IDS_DESC_SETODBCFOLDERS
, 0, ACTION_SetODBCFolders
, NULL
},
7851 { szStartServices
, IDS_DESC_STARTSERVICES
, IDS_TEMP_STARTSERVICES
, ACTION_StartServices
, szStopServices
},
7852 { szStopServices
, IDS_DESC_STOPSERVICES
, IDS_TEMP_STOPSERVICES
, ACTION_StopServices
, szStartServices
},
7853 { szUnpublishComponents
, IDS_DESC_UNPUBLISHCOMPONENTS
, IDS_TEMP_UNPUBLISHCOMPONENTS
, ACTION_UnpublishComponents
, szPublishComponents
},
7854 { szUnpublishFeatures
, IDS_DESC_UNPUBLISHFEATURES
, IDS_TEMP_UNPUBLISHFEATURES
, ACTION_UnpublishFeatures
, szPublishFeatures
},
7855 { szUnpublishProduct
, IDS_DESC_UNPUBLISHPRODUCT
, 0, ACTION_UnpublishProduct
, NULL
}, /* for rollback only */
7856 { szUnregisterClassInfo
, IDS_DESC_UNREGISTERCLASSINFO
, IDS_TEMP_UNREGISTERCLASSINFO
, ACTION_UnregisterClassInfo
, szRegisterClassInfo
},
7857 { szUnregisterComPlus
, IDS_DESC_UNREGISTERCOMPLUS
, IDS_TEMP_UNREGISTERCOMPLUS
, ACTION_UnregisterComPlus
, szRegisterComPlus
},
7858 { szUnregisterExtensionInfo
, IDS_DESC_UNREGISTEREXTENSIONINFO
, IDS_TEMP_UNREGISTEREXTENSIONINFO
, ACTION_UnregisterExtensionInfo
, szRegisterExtensionInfo
},
7859 { szUnregisterFonts
, IDS_DESC_UNREGISTERFONTS
, IDS_TEMP_UNREGISTERFONTS
, ACTION_UnregisterFonts
, szRegisterFonts
},
7860 { szUnregisterMIMEInfo
, IDS_DESC_UNREGISTERMIMEINFO
, IDS_TEMP_UNREGISTERMIMEINFO
, ACTION_UnregisterMIMEInfo
, szRegisterMIMEInfo
},
7861 { szUnregisterProgIdInfo
, IDS_DESC_UNREGISTERPROGIDINFO
, IDS_TEMP_UNREGISTERPROGIDINFO
, ACTION_UnregisterProgIdInfo
, szRegisterProgIdInfo
},
7862 { szUnregisterTypeLibraries
, IDS_DESC_UNREGISTERTYPELIBRARIES
, IDS_TEMP_UNREGISTERTYPELIBRARIES
, ACTION_UnregisterTypeLibraries
, szRegisterTypeLibraries
},
7863 { szValidateProductID
, 0, 0, ACTION_ValidateProductID
, NULL
},
7864 { szWriteEnvironmentStrings
, IDS_DESC_WRITEENVIRONMENTSTRINGS
, IDS_TEMP_WRITEENVIRONMENTSTRINGS
, ACTION_WriteEnvironmentStrings
, szRemoveEnvironmentStrings
},
7865 { szWriteIniValues
, IDS_DESC_WRITEINIVALUES
, IDS_TEMP_WRITEINIVALUES
, ACTION_WriteIniValues
, szRemoveIniValues
},
7866 { szWriteRegistryValues
, IDS_DESC_WRITEREGISTRYVALUES
, IDS_TEMP_WRITEREGISTRYVALUES
, ACTION_WriteRegistryValues
, szRemoveRegistryValues
},
7867 { szINSTALL
, 0, 0, ACTION_INSTALL
, NULL
},
7871 static UINT
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
)
7873 UINT rc
= ERROR_FUNCTION_NOT_CALLED
;
7877 while (StandardActions
[i
].action
!= NULL
)
7879 if (!strcmpW( StandardActions
[i
].action
, action
))
7881 WCHAR description
[100] = {0}, template[100] = {0};
7883 if (StandardActions
[i
].description
!= 0)
7884 LoadStringW(msi_hInstance
, StandardActions
[i
].description
, (LPWSTR
)&description
, 100);
7885 if (StandardActions
[i
].template != 0)
7886 LoadStringW(msi_hInstance
, StandardActions
[i
].template, (LPWSTR
)&template, 100);
7888 ui_actionstart(package
, action
, description
, template);
7889 if (StandardActions
[i
].handler
)
7891 ui_actioninfo( package
, action
, TRUE
, 0 );
7892 rc
= StandardActions
[i
].handler( package
);
7893 ui_actioninfo( package
, action
, FALSE
, !rc
);
7895 if (StandardActions
[i
].action_rollback
&& !package
->need_rollback
)
7897 TRACE("scheduling rollback action\n");
7898 msi_schedule_action( package
, SCRIPT_ROLLBACK
, StandardActions
[i
].action_rollback
);
7903 FIXME("unhandled standard action %s\n", debugstr_w(action
));
7913 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
, UINT script
)
7917 TRACE("Performing action (%s)\n", debugstr_w(action
));
7919 package
->action_progress_increment
= 0;
7920 rc
= ACTION_HandleStandardAction(package
, action
);
7922 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
7923 rc
= ACTION_HandleCustomAction(package
, action
, script
);
7925 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
7926 WARN("unhandled msi action %s\n", debugstr_w(action
));
7931 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
)
7933 UINT rc
= ERROR_SUCCESS
;
7936 static const WCHAR query
[] =
7937 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7938 '`','I','n','s','t','a','l','l','E','x','e','c','u','t','e',
7939 'S','e','q','u','e','n','c','e','`',' ', 'W','H','E','R','E',' ',
7940 '`','S','e','q','u','e','n','c','e','`',' ', '=',' ','%','i',0};
7941 static const WCHAR ui_query
[] =
7942 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
7943 '`','I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
7944 '`', ' ', 'W','H','E','R','E',' ','`','S','e','q','u','e','n','c','e','`',
7945 ' ', '=',' ','%','i',0};
7947 if (needs_ui_sequence(package
))
7948 row
= MSI_QueryGetRecord(package
->db
, ui_query
, seq
);
7950 row
= MSI_QueryGetRecord(package
->db
, query
, seq
);
7954 LPCWSTR action
, cond
;
7956 TRACE("Running the actions\n");
7958 /* check conditions */
7959 cond
= MSI_RecordGetString(row
, 2);
7961 /* this is a hack to skip errors in the condition code */
7962 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
7964 msiobj_release(&row
->hdr
);
7965 return ERROR_SUCCESS
;
7968 action
= MSI_RecordGetString(row
, 1);
7971 ERR("failed to fetch action\n");
7972 msiobj_release(&row
->hdr
);
7973 return ERROR_FUNCTION_FAILED
;
7976 rc
= ACTION_PerformAction(package
, action
, SCRIPT_NONE
);
7978 msiobj_release(&row
->hdr
);
7984 DWORD WINAPI
dummy_thread_proc(void *arg
)
7986 struct dummy_thread
*info
= arg
;
7989 hr
= CoInitializeEx(0, COINIT_MULTITHREADED
);
7990 if (FAILED(hr
)) ERR("CoInitializeEx failed %08x\n", hr
);
7992 SetEvent(info
->started
);
7993 WaitForSingleObject(info
->stopped
, INFINITE
);
7999 static void start_dummy_thread(struct dummy_thread
*info
)
8001 if (!(info
->started
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
))) return;
8002 if (!(info
->stopped
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
))) return;
8003 if (!(info
->thread
= CreateThread(NULL
, 0, dummy_thread_proc
, info
, 0, NULL
))) return;
8005 WaitForSingleObject(info
->started
, INFINITE
);
8008 static void stop_dummy_thread(struct dummy_thread
*info
)
8012 SetEvent(info
->stopped
);
8013 WaitForSingleObject(info
->thread
, INFINITE
);
8014 CloseHandle(info
->thread
);
8016 if (info
->started
) CloseHandle(info
->started
);
8017 if (info
->stopped
) CloseHandle(info
->stopped
);
8020 /****************************************************
8021 * TOP level entry points
8022 *****************************************************/
8024 UINT
MSI_InstallPackage( MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
8025 LPCWSTR szCommandLine
)
8027 static const WCHAR szDisableRollback
[] = {'D','I','S','A','B','L','E','R','O','L','L','B','A','C','K',0};
8028 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
8029 WCHAR
*reinstall
= NULL
, *productcode
, *action
;
8030 struct dummy_thread thread_info
= {NULL
, NULL
, NULL
};
8039 dir
= strdupW(szPackagePath
);
8040 p
= strrchrW(dir
, '\\');
8044 file
= szPackagePath
+ (p
- dir
);
8049 dir
= msi_alloc(MAX_PATH
* sizeof(WCHAR
));
8050 GetCurrentDirectoryW(MAX_PATH
, dir
);
8051 lstrcatW(dir
, szBackSlash
);
8052 file
= szPackagePath
;
8055 msi_free( package
->PackagePath
);
8056 package
->PackagePath
= msi_alloc((lstrlenW(dir
) + lstrlenW(file
) + 1) * sizeof(WCHAR
));
8057 if (!package
->PackagePath
)
8060 return ERROR_OUTOFMEMORY
;
8063 lstrcpyW(package
->PackagePath
, dir
);
8064 lstrcatW(package
->PackagePath
, file
);
8067 msi_set_sourcedir_props(package
, FALSE
);
8070 rc
= msi_parse_command_line( package
, szCommandLine
, FALSE
);
8071 if (rc
!= ERROR_SUCCESS
)
8074 msi_apply_transforms( package
);
8075 msi_apply_patches( package
);
8077 if (msi_get_property( package
->db
, szAction
, NULL
, &len
))
8078 msi_set_property( package
->db
, szAction
, szINSTALL
, -1 );
8079 action
= msi_dup_property( package
->db
, szAction
);
8082 msi_set_original_database_property( package
->db
, szPackagePath
);
8083 msi_parse_command_line( package
, szCommandLine
, FALSE
);
8084 msi_adjust_privilege_properties( package
);
8085 msi_set_context( package
);
8087 start_dummy_thread(&thread_info
);
8089 productcode
= msi_dup_property( package
->db
, szProductCode
);
8090 if (strcmpiW( productcode
, package
->ProductCode
))
8092 TRACE( "product code changed %s -> %s\n", debugstr_w(package
->ProductCode
), debugstr_w(productcode
) );
8093 msi_free( package
->ProductCode
);
8094 package
->ProductCode
= productcode
;
8096 else msi_free( productcode
);
8098 if (msi_get_property_int( package
->db
, szDisableRollback
, 0 ))
8100 TRACE("disabling rollback\n");
8101 msi_set_property( package
->db
, szRollbackDisabled
, szOne
, -1 );
8104 rc
= ACTION_PerformAction(package
, action
, SCRIPT_NONE
);
8106 /* process the ending type action */
8107 if (rc
== ERROR_SUCCESS
)
8108 ACTION_PerformActionSequence(package
, -1);
8109 else if (rc
== ERROR_INSTALL_USEREXIT
)
8110 ACTION_PerformActionSequence(package
, -2);
8111 else if (rc
== ERROR_INSTALL_SUSPEND
)
8112 ACTION_PerformActionSequence(package
, -4);
8115 ACTION_PerformActionSequence(package
, -3);
8116 if (!msi_get_property_int( package
->db
, szRollbackDisabled
, 0 ))
8118 package
->need_rollback
= TRUE
;
8122 /* finish up running custom actions */
8123 ACTION_FinishCustomActions(package
);
8125 stop_dummy_thread(&thread_info
);
8127 if (package
->need_rollback
&& !(reinstall
= msi_dup_property( package
->db
, szReinstall
)))
8129 WARN("installation failed, running rollback script\n");
8130 execute_script( package
, SCRIPT_ROLLBACK
);
8132 msi_free( reinstall
);
8135 if (rc
== ERROR_SUCCESS
&& package
->need_reboot_at_end
)
8136 return ERROR_SUCCESS_REBOOT_REQUIRED
;