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"
44 #define REG_PROGRESS_VALUE 13200
45 #define COMPONENT_PROGRESS_VALUE 24000
47 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
56 static INT
ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
, LPCWSTR description
, LPCWSTR
template)
58 MSIRECORD
*row
, *textrow
;
61 textrow
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `ActionText` WHERE `Action` = '%s'", action
);
64 description
= MSI_RecordGetString(textrow
, 2);
65 template = MSI_RecordGetString(textrow
, 3);
68 row
= MSI_CreateRecord(3);
70 MSI_RecordSetStringW(row
, 1, action
);
71 MSI_RecordSetStringW(row
, 2, description
);
72 MSI_RecordSetStringW(row
, 3, template);
73 rc
= MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
74 if (textrow
) msiobj_release(&textrow
->hdr
);
75 msiobj_release(&row
->hdr
);
79 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
85 template = msi_get_error_message(package
->db
, start
? MSIERR_INFO_ACTIONSTART
: MSIERR_INFO_ACTIONENDED
);
87 row
= MSI_CreateRecord(2);
93 MSI_RecordSetStringW(row
, 0, template);
94 MSI_RecordSetStringW(row
, 1, action
);
95 MSI_RecordSetInteger(row
, 2, start
? package
->LastActionResult
: rc
);
96 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
97 msiobj_release(&row
->hdr
);
99 if (!start
) package
->LastActionResult
= rc
;
109 static int parse_prop( const WCHAR
*str
, WCHAR
*value
, int *quotes
)
111 enum parse_state state
= state_quote
;
114 BOOL ignore
, in_quotes
= FALSE
;
115 int count
= 0, len
= 0;
117 for (p
= str
; *p
; p
++)
122 case state_whitespace
:
132 if (in_quotes
&& p
[1] != '\"') count
--;
148 if (in_quotes
) count
--;
152 state
= state_whitespace
;
153 if (!count
) goto done
;
158 if (count
) in_quotes
= TRUE
;
168 if (in_quotes
&& p
[1] != '\"') count
--;
172 state
= state_whitespace
;
173 if (!count
|| (count
> 1 && !len
)) goto done
;
179 if (count
) in_quotes
= TRUE
;
187 if (!ignore
&& value
) *out
++ = *p
;
188 if (!count
) in_quotes
= FALSE
;
194 if (!len
) *value
= 0;
198 if(quotes
) *quotes
= count
;
202 static void remove_quotes( WCHAR
*str
)
205 int len
= lstrlenW( str
);
207 while ((p
= wcschr( p
, '"' )))
209 memmove( p
, p
+ 1, (len
- (p
- str
)) * sizeof(WCHAR
) );
214 UINT
msi_parse_command_line( MSIPACKAGE
*package
, LPCWSTR szCommandLine
,
224 return ERROR_SUCCESS
;
229 while (*ptr
== ' ') ptr
++;
232 ptr2
= wcschr( ptr
, '=' );
233 if (!ptr2
) return ERROR_INVALID_COMMAND_LINE
;
236 if (!len
) return ERROR_INVALID_COMMAND_LINE
;
238 while (ptr
[len
- 1] == ' ') len
--;
240 prop
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
241 memcpy( prop
, ptr
, len
* sizeof(WCHAR
) );
243 if (!preserve_case
) wcsupr( prop
);
246 while (*ptr2
== ' ') ptr2
++;
249 val
= msi_alloc( (lstrlenW( ptr2
) + 1) * sizeof(WCHAR
) );
250 len
= parse_prop( ptr2
, val
, &num_quotes
);
253 WARN("unbalanced quotes\n");
256 return ERROR_INVALID_COMMAND_LINE
;
258 remove_quotes( val
);
259 TRACE("Found commandline property %s = %s\n", debugstr_w(prop
), debugstr_w(val
));
261 r
= msi_set_property( package
->db
, prop
, val
, -1 );
262 if (r
== ERROR_SUCCESS
&& !wcscmp( prop
, L
"SourceDir" ))
263 msi_reset_source_folders( package
);
271 return ERROR_SUCCESS
;
274 const WCHAR
*msi_get_command_line_option(const WCHAR
*cmd
, const WCHAR
*option
, UINT
*len
)
276 DWORD opt_len
= lstrlenW(option
);
285 while (*cmd
== ' ') cmd
++;
288 if(!wcsnicmp(cmd
, option
, opt_len
))
291 cmd
= wcschr( cmd
, '=' );
294 while (*cmd
== ' ') cmd
++;
297 *len
= parse_prop( cmd
, NULL
, NULL
);
298 if (found
) return cmd
;
305 WCHAR
**msi_split_string( const WCHAR
*str
, WCHAR sep
)
308 LPWSTR p
, *ret
= NULL
;
314 /* count the number of substrings */
315 for ( pc
= str
, count
= 0; pc
; count
++ )
317 pc
= wcschr( pc
, sep
);
322 /* allocate space for an array of substring pointers and the substrings */
323 ret
= msi_alloc( (count
+1) * sizeof (LPWSTR
) +
324 (lstrlenW(str
)+1) * sizeof(WCHAR
) );
328 /* copy the string and set the pointers */
329 p
= (LPWSTR
) &ret
[count
+1];
331 for( count
= 0; (ret
[count
] = p
); count
++ )
333 p
= wcschr( p
, sep
);
341 static BOOL
ui_sequence_exists( MSIPACKAGE
*package
)
346 if (!(MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `InstallUISequence` WHERE `Sequence` > 0", &view
)))
348 MSI_IterateRecords( view
, &count
, NULL
, package
);
349 msiobj_release( &view
->hdr
);
354 UINT
msi_set_sourcedir_props(MSIPACKAGE
*package
, BOOL replace
)
356 WCHAR
*source
, *check
, *p
, *db
;
359 if (!(db
= msi_dup_property( package
->db
, L
"OriginalDatabase" )))
360 return ERROR_OUTOFMEMORY
;
362 if (!(p
= wcsrchr( db
, '\\' )) && !(p
= wcsrchr( db
, '/' )))
365 return ERROR_SUCCESS
;
368 source
= msi_alloc( len
* sizeof(WCHAR
) );
369 lstrcpynW( source
, db
, len
);
372 check
= msi_dup_property( package
->db
, L
"SourceDir" );
373 if (!check
|| replace
)
375 UINT r
= msi_set_property( package
->db
, L
"SourceDir", source
, -1 );
376 if (r
== ERROR_SUCCESS
)
377 msi_reset_source_folders( package
);
381 check
= msi_dup_property( package
->db
, L
"SOURCEDIR" );
382 if (!check
|| replace
)
383 msi_set_property( package
->db
, L
"SOURCEDIR", source
, -1 );
388 return ERROR_SUCCESS
;
391 static BOOL
needs_ui_sequence(MSIPACKAGE
*package
)
393 return (package
->ui_level
& INSTALLUILEVEL_MASK
) >= INSTALLUILEVEL_REDUCED
;
396 UINT
msi_set_context(MSIPACKAGE
*package
)
398 UINT r
= msi_locate_product( package
->ProductCode
, &package
->Context
);
399 if (r
!= ERROR_SUCCESS
)
401 int num
= msi_get_property_int( package
->db
, L
"ALLUSERS", 0 );
402 if (num
== 1 || num
== 2)
403 package
->Context
= MSIINSTALLCONTEXT_MACHINE
;
405 package
->Context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
407 return ERROR_SUCCESS
;
410 static UINT
ITERATE_Actions(MSIRECORD
*row
, LPVOID param
)
413 LPCWSTR cond
, action
;
414 MSIPACKAGE
*package
= param
;
416 action
= MSI_RecordGetString(row
,1);
419 ERR("Error is retrieving action name\n");
420 return ERROR_FUNCTION_FAILED
;
423 /* check conditions */
424 cond
= MSI_RecordGetString(row
,2);
426 /* this is a hack to skip errors in the condition code */
427 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
429 TRACE("Skipping action: %s (condition is false)\n", debugstr_w(action
));
430 return ERROR_SUCCESS
;
433 rc
= ACTION_PerformAction(package
, action
);
435 msi_dialog_check_messages( NULL
);
437 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
440 if (rc
!= ERROR_SUCCESS
)
441 ERR("Execution halted, action %s returned %i\n", debugstr_w(action
), rc
);
443 if (package
->need_reboot_now
)
445 TRACE("action %s asked for immediate reboot, suspending installation\n",
447 rc
= ACTION_ForceReboot( package
);
452 UINT
MSI_Sequence( MSIPACKAGE
*package
, LPCWSTR table
)
457 TRACE("%p %s\n", package
, debugstr_w(table
));
459 r
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `%s` WHERE `Sequence` > 0 ORDER BY `Sequence`", table
);
460 if (r
== ERROR_SUCCESS
)
462 r
= MSI_IterateRecords( view
, NULL
, ITERATE_Actions
, package
);
463 msiobj_release(&view
->hdr
);
468 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
)
473 if (package
->ExecuteSequenceRun
)
475 TRACE("Execute Sequence already Run\n");
476 return ERROR_SUCCESS
;
479 package
->ExecuteSequenceRun
= TRUE
;
481 rc
= MSI_OpenQuery(package
->db
, &view
,
482 L
"SELECT * FROM `InstallExecuteSequence` WHERE `Sequence` > 0 ORDER BY `Sequence`");
483 if (rc
== ERROR_SUCCESS
)
485 TRACE("Running the actions\n");
487 msi_set_property( package
->db
, L
"SourceDir", NULL
, -1 );
488 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
489 msiobj_release(&view
->hdr
);
494 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
499 rc
= MSI_DatabaseOpenViewW(package
->db
,
500 L
"SELECT * FROM `InstallUISequence` WHERE `Sequence` > 0 ORDER BY `Sequence`",
502 if (rc
== ERROR_SUCCESS
)
504 TRACE("Running the actions\n");
505 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_Actions
, package
);
506 msiobj_release(&view
->hdr
);
511 /********************************************************
512 * ACTION helper functions and functions that perform the actions
513 *******************************************************/
514 static UINT
ACTION_HandleCustomAction(MSIPACKAGE
*package
, LPCWSTR action
)
519 uirc
= ui_actionstart(package
, action
, NULL
, NULL
);
520 if (uirc
== IDCANCEL
)
521 return ERROR_INSTALL_USEREXIT
;
522 ui_actioninfo(package
, action
, TRUE
, 0);
523 arc
= ACTION_CustomAction(package
, action
);
526 if (arc
== ERROR_FUNCTION_NOT_CALLED
&& needs_ui_sequence(package
))
528 uirc
= ACTION_ShowDialog(package
, action
);
532 return ERROR_SUCCESS
; /* stop immediately */
533 case 0: arc
= ERROR_FUNCTION_NOT_CALLED
; break;
534 case 1: arc
= ERROR_SUCCESS
; break;
535 case 2: arc
= ERROR_INSTALL_USEREXIT
; break;
536 case 3: arc
= ERROR_INSTALL_FAILURE
; break;
537 case 4: arc
= ERROR_INSTALL_SUSPEND
; break;
538 case 5: arc
= ERROR_MORE_DATA
; break;
539 case 6: arc
= ERROR_INVALID_HANDLE_STATE
; break;
540 case 7: arc
= ERROR_INVALID_DATA
; break;
541 case 8: arc
= ERROR_INSTALL_ALREADY_RUNNING
; break;
542 case 9: arc
= ERROR_INSTALL_PACKAGE_REJECTED
; break;
543 default: arc
= ERROR_FUNCTION_FAILED
; break;
547 ui_actioninfo(package
, action
, FALSE
, uirc
);
552 MSICOMPONENT
*msi_get_loaded_component( MSIPACKAGE
*package
, const WCHAR
*Component
)
556 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
558 if (!wcscmp( Component
, comp
->Component
)) return comp
;
563 MSIFEATURE
*msi_get_loaded_feature(MSIPACKAGE
* package
, const WCHAR
*Feature
)
567 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
569 if (!wcscmp( Feature
, feature
->Feature
)) return feature
;
574 MSIFILE
*msi_get_loaded_file( MSIPACKAGE
*package
, const WCHAR
*key
)
578 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
580 if (!wcscmp( key
, file
->File
)) return file
;
585 MSIFOLDER
*msi_get_loaded_folder( MSIPACKAGE
*package
, const WCHAR
*dir
)
589 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
591 if (!wcscmp( dir
, folder
->Directory
)) return folder
;
596 void msi_ui_progress( MSIPACKAGE
*package
, int a
, int b
, int c
, int d
)
600 row
= MSI_CreateRecord( 4 );
601 MSI_RecordSetInteger( row
, 1, a
);
602 MSI_RecordSetInteger( row
, 2, b
);
603 MSI_RecordSetInteger( row
, 3, c
);
604 MSI_RecordSetInteger( row
, 4, d
);
605 MSI_ProcessMessage( package
, INSTALLMESSAGE_PROGRESS
, row
);
606 msiobj_release( &row
->hdr
);
608 msi_dialog_check_messages( NULL
);
611 INSTALLSTATE
msi_get_component_action( MSIPACKAGE
*package
, MSICOMPONENT
*comp
)
615 TRACE("component is disabled: %s\n", debugstr_w(comp
->Component
));
616 return INSTALLSTATE_UNKNOWN
;
618 if (package
->need_rollback
) return comp
->Installed
;
619 if (comp
->num_clients
> 0 && comp
->ActionRequest
== INSTALLSTATE_ABSENT
)
621 TRACE("%s has %u clients left\n", debugstr_w(comp
->Component
), comp
->num_clients
);
622 return INSTALLSTATE_UNKNOWN
;
624 return comp
->ActionRequest
;
627 INSTALLSTATE
msi_get_feature_action( MSIPACKAGE
*package
, MSIFEATURE
*feature
)
629 if (package
->need_rollback
) return feature
->Installed
;
630 return feature
->ActionRequest
;
633 static UINT
ITERATE_CreateFolders(MSIRECORD
*row
, LPVOID param
)
635 MSIPACKAGE
*package
= param
;
636 LPCWSTR dir
, component
, full_path
;
641 component
= MSI_RecordGetString(row
, 2);
643 return ERROR_SUCCESS
;
645 comp
= msi_get_loaded_component(package
, component
);
647 return ERROR_SUCCESS
;
649 comp
->Action
= msi_get_component_action( package
, comp
);
650 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
652 TRACE("component not scheduled for installation: %s\n", debugstr_w(component
));
653 return ERROR_SUCCESS
;
656 dir
= MSI_RecordGetString(row
,1);
659 ERR("Unable to get folder id\n");
660 return ERROR_SUCCESS
;
663 uirow
= MSI_CreateRecord(1);
664 MSI_RecordSetStringW(uirow
, 1, dir
);
665 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
666 msiobj_release(&uirow
->hdr
);
668 full_path
= msi_get_target_folder( package
, dir
);
671 ERR("Unable to retrieve folder %s\n", debugstr_w(dir
));
672 return ERROR_SUCCESS
;
674 TRACE("folder is %s\n", debugstr_w(full_path
));
676 folder
= msi_get_loaded_folder( package
, dir
);
677 if (folder
->State
== FOLDER_STATE_UNINITIALIZED
) msi_create_full_path( package
, full_path
);
678 folder
->State
= FOLDER_STATE_CREATED
;
680 return ERROR_SUCCESS
;
683 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
688 if (package
->script
== SCRIPT_NONE
)
689 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"CreateFolders");
691 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `CreateFolder`", &view
);
692 if (rc
!= ERROR_SUCCESS
)
693 return ERROR_SUCCESS
;
695 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateFolders
, package
);
696 msiobj_release(&view
->hdr
);
700 static void remove_persistent_folder( MSIFOLDER
*folder
)
704 LIST_FOR_EACH_ENTRY( fl
, &folder
->children
, FolderList
, entry
)
706 remove_persistent_folder( fl
->folder
);
708 if (folder
->persistent
&& folder
->State
!= FOLDER_STATE_REMOVED
)
710 if (RemoveDirectoryW( folder
->ResolvedTarget
)) folder
->State
= FOLDER_STATE_REMOVED
;
714 static UINT
ITERATE_RemoveFolders( MSIRECORD
*row
, LPVOID param
)
716 MSIPACKAGE
*package
= param
;
717 LPCWSTR dir
, component
, full_path
;
722 component
= MSI_RecordGetString(row
, 2);
724 return ERROR_SUCCESS
;
726 comp
= msi_get_loaded_component(package
, component
);
728 return ERROR_SUCCESS
;
730 comp
->Action
= msi_get_component_action( package
, comp
);
731 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
733 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
734 return ERROR_SUCCESS
;
737 dir
= MSI_RecordGetString( row
, 1 );
740 ERR("Unable to get folder id\n");
741 return ERROR_SUCCESS
;
744 full_path
= msi_get_target_folder( package
, dir
);
747 ERR("Unable to resolve folder %s\n", debugstr_w(dir
));
748 return ERROR_SUCCESS
;
750 TRACE("folder is %s\n", debugstr_w(full_path
));
752 uirow
= MSI_CreateRecord( 1 );
753 MSI_RecordSetStringW( uirow
, 1, dir
);
754 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
755 msiobj_release( &uirow
->hdr
);
757 folder
= msi_get_loaded_folder( package
, dir
);
758 remove_persistent_folder( folder
);
759 return ERROR_SUCCESS
;
762 static UINT
ACTION_RemoveFolders( MSIPACKAGE
*package
)
767 if (package
->script
== SCRIPT_NONE
)
768 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RemoveFolders");
770 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `CreateFolder`", &view
);
771 if (rc
!= ERROR_SUCCESS
)
772 return ERROR_SUCCESS
;
774 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveFolders
, package
);
775 msiobj_release( &view
->hdr
);
779 static UINT
load_component( MSIRECORD
*row
, LPVOID param
)
781 MSIPACKAGE
*package
= param
;
784 comp
= msi_alloc_zero( sizeof(MSICOMPONENT
) );
786 return ERROR_FUNCTION_FAILED
;
788 list_add_tail( &package
->components
, &comp
->entry
);
790 /* fill in the data */
791 comp
->Component
= msi_dup_record_field( row
, 1 );
793 TRACE("Loading Component %s\n", debugstr_w(comp
->Component
));
795 comp
->ComponentId
= msi_dup_record_field( row
, 2 );
796 comp
->Directory
= msi_dup_record_field( row
, 3 );
797 comp
->Attributes
= MSI_RecordGetInteger(row
,4);
798 comp
->Condition
= msi_dup_record_field( row
, 5 );
799 comp
->KeyPath
= msi_dup_record_field( row
, 6 );
801 comp
->Installed
= INSTALLSTATE_UNKNOWN
;
802 comp
->Action
= INSTALLSTATE_UNKNOWN
;
803 comp
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
805 comp
->assembly
= msi_load_assembly( package
, comp
);
806 return ERROR_SUCCESS
;
809 UINT
msi_load_all_components( MSIPACKAGE
*package
)
814 if (!list_empty(&package
->components
))
815 return ERROR_SUCCESS
;
817 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Component`", &view
);
818 if (r
!= ERROR_SUCCESS
)
821 r
= MSI_IterateRecords(view
, NULL
, load_component
, package
);
822 msiobj_release(&view
->hdr
);
831 static UINT
add_feature_component( MSIFEATURE
*feature
, MSICOMPONENT
*comp
)
835 cl
= msi_alloc( sizeof (*cl
) );
837 return ERROR_NOT_ENOUGH_MEMORY
;
838 cl
->component
= comp
;
839 list_add_tail( &feature
->Components
, &cl
->entry
);
841 return ERROR_SUCCESS
;
844 static UINT
add_feature_child( MSIFEATURE
*parent
, MSIFEATURE
*child
)
848 fl
= msi_alloc( sizeof(*fl
) );
850 return ERROR_NOT_ENOUGH_MEMORY
;
852 list_add_tail( &parent
->Children
, &fl
->entry
);
854 return ERROR_SUCCESS
;
857 static UINT
iterate_load_featurecomponents(MSIRECORD
*row
, LPVOID param
)
863 component
= MSI_RecordGetString(row
,1);
865 /* check to see if the component is already loaded */
866 comp
= msi_get_loaded_component( ilfs
->package
, component
);
869 WARN("ignoring unknown component %s\n", debugstr_w(component
));
870 return ERROR_SUCCESS
;
872 add_feature_component( ilfs
->feature
, comp
);
873 comp
->Enabled
= TRUE
;
875 return ERROR_SUCCESS
;
878 static UINT
load_feature(MSIRECORD
*row
, LPVOID param
)
880 MSIPACKAGE
*package
= param
;
886 /* fill in the data */
888 feature
= msi_alloc_zero( sizeof (MSIFEATURE
) );
890 return ERROR_NOT_ENOUGH_MEMORY
;
892 list_init( &feature
->Children
);
893 list_init( &feature
->Components
);
895 feature
->Feature
= msi_dup_record_field( row
, 1 );
897 TRACE("Loading feature %s\n",debugstr_w(feature
->Feature
));
899 feature
->Feature_Parent
= msi_dup_record_field( row
, 2 );
900 feature
->Title
= msi_dup_record_field( row
, 3 );
901 feature
->Description
= msi_dup_record_field( row
, 4 );
903 if (!MSI_RecordIsNull(row
,5))
904 feature
->Display
= MSI_RecordGetInteger(row
,5);
906 feature
->Level
= MSI_RecordGetInteger(row
,6);
907 feature
->Directory
= msi_dup_record_field( row
, 7 );
908 feature
->Attributes
= MSI_RecordGetInteger(row
,8);
910 feature
->Installed
= INSTALLSTATE_UNKNOWN
;
911 feature
->Action
= INSTALLSTATE_UNKNOWN
;
912 feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
914 list_add_tail( &package
->features
, &feature
->entry
);
916 /* load feature components */
918 rc
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT `Component_` FROM `FeatureComponents` WHERE `Feature_` = '%s'",
920 if (rc
!= ERROR_SUCCESS
)
921 return ERROR_SUCCESS
;
923 ilfs
.package
= package
;
924 ilfs
.feature
= feature
;
926 rc
= MSI_IterateRecords(view
, NULL
, iterate_load_featurecomponents
, &ilfs
);
927 msiobj_release(&view
->hdr
);
931 static UINT
find_feature_children(MSIRECORD
* row
, LPVOID param
)
933 MSIPACKAGE
*package
= param
;
934 MSIFEATURE
*parent
, *child
;
936 child
= msi_get_loaded_feature( package
, MSI_RecordGetString( row
, 1 ) );
938 return ERROR_FUNCTION_FAILED
;
940 if (!child
->Feature_Parent
)
941 return ERROR_SUCCESS
;
943 parent
= msi_get_loaded_feature( package
, child
->Feature_Parent
);
945 return ERROR_FUNCTION_FAILED
;
947 add_feature_child( parent
, child
);
948 return ERROR_SUCCESS
;
951 UINT
msi_load_all_features( MSIPACKAGE
*package
)
956 if (!list_empty(&package
->features
))
957 return ERROR_SUCCESS
;
959 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Feature` ORDER BY `Display`", &view
);
960 if (r
!= ERROR_SUCCESS
)
963 r
= MSI_IterateRecords( view
, NULL
, load_feature
, package
);
964 if (r
!= ERROR_SUCCESS
)
966 msiobj_release( &view
->hdr
);
969 r
= MSI_IterateRecords( view
, NULL
, find_feature_children
, package
);
970 msiobj_release( &view
->hdr
);
974 static LPWSTR
folder_split_path(LPWSTR p
, WCHAR ch
)
985 static UINT
load_file_hash(MSIPACKAGE
*package
, MSIFILE
*file
)
987 MSIQUERY
*view
= NULL
;
988 MSIRECORD
*row
= NULL
;
991 TRACE("%s\n", debugstr_w(file
->File
));
993 r
= MSI_OpenQuery(package
->db
, &view
, L
"SELECT * FROM `MsiFileHash` WHERE `File_` = '%s'", file
->File
);
994 if (r
!= ERROR_SUCCESS
)
997 r
= MSI_ViewExecute(view
, NULL
);
998 if (r
!= ERROR_SUCCESS
)
1001 r
= MSI_ViewFetch(view
, &row
);
1002 if (r
!= ERROR_SUCCESS
)
1005 file
->hash
.dwFileHashInfoSize
= sizeof(MSIFILEHASHINFO
);
1006 file
->hash
.dwData
[0] = MSI_RecordGetInteger(row
, 3);
1007 file
->hash
.dwData
[1] = MSI_RecordGetInteger(row
, 4);
1008 file
->hash
.dwData
[2] = MSI_RecordGetInteger(row
, 5);
1009 file
->hash
.dwData
[3] = MSI_RecordGetInteger(row
, 6);
1012 if (view
) msiobj_release(&view
->hdr
);
1013 if (row
) msiobj_release(&row
->hdr
);
1017 static UINT
load_file_disk_id( MSIPACKAGE
*package
, MSIFILE
*file
)
1019 MSIRECORD
*row
= MSI_QueryGetRecord( package
->db
, L
"SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= %d",
1023 WARN("query failed\n");
1024 return ERROR_FUNCTION_FAILED
;
1027 file
->disk_id
= MSI_RecordGetInteger( row
, 1 );
1028 msiobj_release( &row
->hdr
);
1029 return ERROR_SUCCESS
;
1032 static UINT
load_file(MSIRECORD
*row
, LPVOID param
)
1034 MSIPACKAGE
* package
= param
;
1038 /* fill in the data */
1040 file
= msi_alloc_zero( sizeof (MSIFILE
) );
1042 return ERROR_NOT_ENOUGH_MEMORY
;
1044 file
->File
= msi_dup_record_field( row
, 1 );
1046 component
= MSI_RecordGetString( row
, 2 );
1047 file
->Component
= msi_get_loaded_component( package
, component
);
1049 if (!file
->Component
)
1051 WARN("Component not found: %s\n", debugstr_w(component
));
1052 msi_free(file
->File
);
1054 return ERROR_SUCCESS
;
1057 file
->FileName
= msi_dup_record_field( row
, 3 );
1058 msi_reduce_to_long_filename( file
->FileName
);
1060 file
->ShortName
= msi_dup_record_field( row
, 3 );
1061 file
->LongName
= strdupW( folder_split_path(file
->ShortName
, '|'));
1063 file
->FileSize
= MSI_RecordGetInteger( row
, 4 );
1064 file
->Version
= msi_dup_record_field( row
, 5 );
1065 file
->Language
= msi_dup_record_field( row
, 6 );
1066 file
->Attributes
= MSI_RecordGetInteger( row
, 7 );
1067 file
->Sequence
= MSI_RecordGetInteger( row
, 8 );
1069 file
->state
= msifs_invalid
;
1071 /* if the compressed bits are not set in the file attributes,
1072 * then read the information from the package word count property
1074 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1076 file
->IsCompressed
= package
->WordCount
& msidbSumInfoSourceTypeCompressed
;
1078 else if (file
->Attributes
& (msidbFileAttributesCompressed
| msidbFileAttributesPatchAdded
))
1080 file
->IsCompressed
= TRUE
;
1082 else if (file
->Attributes
& msidbFileAttributesNoncompressed
)
1084 file
->IsCompressed
= FALSE
;
1086 else file
->IsCompressed
= package
->WordCount
& msidbSumInfoSourceTypeCompressed
;
1088 load_file_hash(package
, file
);
1089 load_file_disk_id(package
, file
);
1091 TRACE("File loaded (file %s sequence %u)\n", debugstr_w(file
->File
), file
->Sequence
);
1093 list_add_tail( &package
->files
, &file
->entry
);
1094 return ERROR_SUCCESS
;
1097 static UINT
load_all_files(MSIPACKAGE
*package
)
1102 if (!list_empty(&package
->files
))
1103 return ERROR_SUCCESS
;
1105 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `File` ORDER BY `Sequence`", &view
);
1106 if (rc
!= ERROR_SUCCESS
)
1107 return ERROR_SUCCESS
;
1109 rc
= MSI_IterateRecords(view
, NULL
, load_file
, package
);
1110 msiobj_release(&view
->hdr
);
1114 static UINT
load_media( MSIRECORD
*row
, LPVOID param
)
1116 MSIPACKAGE
*package
= param
;
1117 UINT disk_id
= MSI_RecordGetInteger( row
, 1 );
1118 const WCHAR
*cabinet
= MSI_RecordGetString( row
, 4 );
1120 /* FIXME: load external cabinets and directory sources too */
1121 if (!cabinet
|| cabinet
[0] != '#' || disk_id
>= MSI_INITIAL_MEDIA_TRANSFORM_DISKID
)
1122 return ERROR_SUCCESS
;
1124 return msi_add_cabinet_stream( package
, disk_id
, package
->db
->storage
, cabinet
);
1127 static UINT
load_all_media( MSIPACKAGE
*package
)
1132 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Media` ORDER BY `DiskId`", &view
);
1133 if (r
!= ERROR_SUCCESS
)
1134 return ERROR_SUCCESS
;
1136 r
= MSI_IterateRecords( view
, NULL
, load_media
, package
);
1137 msiobj_release( &view
->hdr
);
1141 static UINT
load_patch_disk_id( MSIPACKAGE
*package
, MSIFILEPATCH
*patch
)
1143 MSIRECORD
*rec
= MSI_QueryGetRecord( package
->db
, L
"SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= %u",
1147 WARN("query failed\n");
1148 return ERROR_FUNCTION_FAILED
;
1151 patch
->disk_id
= MSI_RecordGetInteger( rec
, 1 );
1152 msiobj_release( &rec
->hdr
);
1153 return ERROR_SUCCESS
;
1156 static UINT
load_patch(MSIRECORD
*row
, LPVOID param
)
1158 MSIPACKAGE
*package
= param
;
1159 MSIFILEPATCH
*patch
;
1160 const WCHAR
*file_key
;
1162 patch
= msi_alloc_zero( sizeof (MSIFILEPATCH
) );
1164 return ERROR_NOT_ENOUGH_MEMORY
;
1166 file_key
= MSI_RecordGetString( row
, 1 );
1167 patch
->File
= msi_get_loaded_file( package
, file_key
);
1170 ERR("Failed to find target for patch in File table\n");
1172 return ERROR_FUNCTION_FAILED
;
1175 patch
->Sequence
= MSI_RecordGetInteger( row
, 2 );
1176 patch
->PatchSize
= MSI_RecordGetInteger( row
, 3 );
1177 patch
->Attributes
= MSI_RecordGetInteger( row
, 4 );
1180 * Header field - for patch validation.
1181 * _StreamRef - External key into MsiPatchHeaders (instead of the header field)
1184 load_patch_disk_id( package
, patch
);
1186 TRACE("Patch loaded (file %s sequence %u)\n", debugstr_w(patch
->File
->File
), patch
->Sequence
);
1188 list_add_tail( &package
->filepatches
, &patch
->entry
);
1190 return ERROR_SUCCESS
;
1193 static UINT
load_all_patches(MSIPACKAGE
*package
)
1198 if (!list_empty(&package
->filepatches
))
1199 return ERROR_SUCCESS
;
1201 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `Patch` ORDER BY `Sequence`", &view
);
1202 if (rc
!= ERROR_SUCCESS
)
1203 return ERROR_SUCCESS
;
1205 rc
= MSI_IterateRecords(view
, NULL
, load_patch
, package
);
1206 msiobj_release(&view
->hdr
);
1210 static UINT
iterate_patched_component( MSIRECORD
*row
, LPVOID param
)
1212 MSIPACKAGE
*package
= param
;
1216 name
= MSI_RecordGetString( row
, 1 );
1217 TRACE( "found patched component: %s\n", wine_dbgstr_w(name
) );
1218 c
= msi_get_loaded_component( package
, name
);
1220 return ERROR_SUCCESS
;
1223 if (!wcscmp( MSI_RecordGetString( row
, 2 ), L
"INSERT" ))
1225 return ERROR_SUCCESS
;
1228 static void mark_patched_components( MSIPACKAGE
*package
)
1230 static const WCHAR select
[] = L
"SELECT `Row`, `Column` FROM `_TransformView` WHERE `Table`='Component'";
1234 r
= MSI_OpenQuery( package
->db
, &q
, select
);
1235 if (r
!= ERROR_SUCCESS
)
1238 MSI_IterateRecords( q
, NULL
, iterate_patched_component
, package
);
1239 msiobj_release( &q
->hdr
);
1243 r
= MSI_OpenQuery( package
->db
, &q
, L
"ALTER TABLE `_TransformView` FREE" );
1244 if (r
!= ERROR_SUCCESS
)
1246 r
= MSI_ViewExecute( q
, NULL
);
1247 msiobj_release( &q
->hdr
);
1248 if (r
!= ERROR_SUCCESS
)
1253 static UINT
load_folder_persistence( MSIPACKAGE
*package
, MSIFOLDER
*folder
)
1257 folder
->persistent
= FALSE
;
1258 if (!MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `CreateFolder` WHERE `Directory_` = '%s'",
1259 folder
->Directory
))
1261 if (!MSI_ViewExecute( view
, NULL
))
1264 if (!MSI_ViewFetch( view
, &rec
))
1266 TRACE("directory %s is persistent\n", debugstr_w(folder
->Directory
));
1267 folder
->persistent
= TRUE
;
1268 msiobj_release( &rec
->hdr
);
1271 msiobj_release( &view
->hdr
);
1273 return ERROR_SUCCESS
;
1276 static UINT
load_folder( MSIRECORD
*row
, LPVOID param
)
1278 MSIPACKAGE
*package
= param
;
1279 static WCHAR szEmpty
[] = L
"";
1280 LPWSTR p
, tgt_short
, tgt_long
, src_short
, src_long
;
1283 if (!(folder
= msi_alloc_zero( sizeof(*folder
) ))) return ERROR_NOT_ENOUGH_MEMORY
;
1284 list_init( &folder
->children
);
1285 folder
->Directory
= msi_dup_record_field( row
, 1 );
1286 folder
->Parent
= msi_dup_record_field( row
, 2 );
1287 p
= msi_dup_record_field(row
, 3);
1289 TRACE("%s\n", debugstr_w(folder
->Directory
));
1291 /* split src and target dir */
1293 src_short
= folder_split_path( p
, ':' );
1295 /* split the long and short paths */
1296 tgt_long
= folder_split_path( tgt_short
, '|' );
1297 src_long
= folder_split_path( src_short
, '|' );
1299 /* check for no-op dirs */
1300 if (tgt_short
&& !wcscmp( L
".", tgt_short
))
1301 tgt_short
= szEmpty
;
1302 if (src_short
&& !wcscmp( L
".", src_short
))
1303 src_short
= szEmpty
;
1306 tgt_long
= tgt_short
;
1309 src_short
= tgt_short
;
1310 src_long
= tgt_long
;
1314 src_long
= src_short
;
1316 /* FIXME: use the target short path too */
1317 folder
->TargetDefault
= strdupW(tgt_long
);
1318 folder
->SourceShortPath
= strdupW(src_short
);
1319 folder
->SourceLongPath
= strdupW(src_long
);
1322 TRACE("TargetDefault = %s\n",debugstr_w( folder
->TargetDefault
));
1323 TRACE("SourceLong = %s\n", debugstr_w( folder
->SourceLongPath
));
1324 TRACE("SourceShort = %s\n", debugstr_w( folder
->SourceShortPath
));
1326 load_folder_persistence( package
, folder
);
1328 list_add_tail( &package
->folders
, &folder
->entry
);
1329 return ERROR_SUCCESS
;
1332 static UINT
add_folder_child( MSIFOLDER
*parent
, MSIFOLDER
*child
)
1336 if (!(fl
= msi_alloc( sizeof(*fl
) ))) return ERROR_NOT_ENOUGH_MEMORY
;
1338 list_add_tail( &parent
->children
, &fl
->entry
);
1339 return ERROR_SUCCESS
;
1342 static UINT
find_folder_children( MSIRECORD
*row
, LPVOID param
)
1344 MSIPACKAGE
*package
= param
;
1345 MSIFOLDER
*parent
, *child
;
1347 if (!(child
= msi_get_loaded_folder( package
, MSI_RecordGetString( row
, 1 ) )))
1348 return ERROR_FUNCTION_FAILED
;
1350 if (!child
->Parent
) return ERROR_SUCCESS
;
1352 if (!(parent
= msi_get_loaded_folder( package
, child
->Parent
)))
1353 return ERROR_FUNCTION_FAILED
;
1355 return add_folder_child( parent
, child
);
1358 static UINT
load_all_folders( MSIPACKAGE
*package
)
1363 if (!list_empty(&package
->folders
))
1364 return ERROR_SUCCESS
;
1366 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Directory`", &view
);
1367 if (r
!= ERROR_SUCCESS
)
1370 r
= MSI_IterateRecords( view
, NULL
, load_folder
, package
);
1371 if (r
!= ERROR_SUCCESS
)
1373 msiobj_release( &view
->hdr
);
1376 r
= MSI_IterateRecords( view
, NULL
, find_folder_children
, package
);
1377 msiobj_release( &view
->hdr
);
1381 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1383 msi_set_property( package
->db
, L
"CostingComplete", L
"0", -1 );
1384 msi_set_property( package
->db
, L
"ROOTDRIVE", L
"C:\\", -1 );
1386 load_all_folders( package
);
1387 msi_load_all_components( package
);
1388 msi_load_all_features( package
);
1389 load_all_files( package
);
1390 load_all_patches( package
);
1391 mark_patched_components( package
);
1392 load_all_media( package
);
1394 return ERROR_SUCCESS
;
1397 static UINT
execute_script( MSIPACKAGE
*package
, UINT script
)
1399 UINT i
, rc
= ERROR_SUCCESS
;
1401 TRACE("executing script %u\n", script
);
1403 package
->script
= script
;
1405 if (script
== SCRIPT_ROLLBACK
)
1407 for (i
= package
->script_actions_count
[script
]; i
> 0; i
--)
1409 rc
= ACTION_PerformAction(package
, package
->script_actions
[script
][i
-1]);
1410 if (rc
!= ERROR_SUCCESS
)
1412 ERR("Execution of script %i halted; action %s returned %u\n",
1413 script
, debugstr_w(package
->script_actions
[script
][i
-1]), rc
);
1420 for (i
= 0; i
< package
->script_actions_count
[script
]; i
++)
1422 rc
= ACTION_PerformAction(package
, package
->script_actions
[script
][i
]);
1423 if (rc
!= ERROR_SUCCESS
)
1425 ERR("Execution of script %i halted; action %s returned %u\n",
1426 script
, debugstr_w(package
->script_actions
[script
][i
]), rc
);
1432 package
->script
= SCRIPT_NONE
;
1434 msi_free_action_script(package
, script
);
1438 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1440 return ERROR_SUCCESS
;
1443 static void get_client_counts( MSIPACKAGE
*package
)
1448 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1450 if (!comp
->ComponentId
) continue;
1452 if (MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, L
"S-1-5-18", &hkey
, FALSE
) &&
1453 MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, NULL
, &hkey
, FALSE
))
1455 comp
->num_clients
= 0;
1458 RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, (DWORD
*)&comp
->num_clients
,
1459 NULL
, NULL
, NULL
, NULL
);
1460 RegCloseKey( hkey
);
1464 static void ACTION_GetComponentInstallStates(MSIPACKAGE
*package
)
1469 LIST_FOR_EACH_ENTRY(comp
, &package
->components
, MSICOMPONENT
, entry
)
1471 if (!comp
->ComponentId
) continue;
1473 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1474 MSIINSTALLCONTEXT_USERMANAGED
, comp
->ComponentId
,
1476 if (r
== ERROR_SUCCESS
) continue;
1478 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1479 MSIINSTALLCONTEXT_USERUNMANAGED
, comp
->ComponentId
,
1481 if (r
== ERROR_SUCCESS
) continue;
1483 r
= MsiQueryComponentStateW( package
->ProductCode
, NULL
,
1484 MSIINSTALLCONTEXT_MACHINE
, comp
->ComponentId
,
1486 if (r
== ERROR_SUCCESS
) continue;
1488 comp
->Installed
= INSTALLSTATE_ABSENT
;
1492 static void ACTION_GetFeatureInstallStates(MSIPACKAGE
*package
)
1494 MSIFEATURE
*feature
;
1496 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1498 INSTALLSTATE state
= MsiQueryFeatureStateW( package
->ProductCode
, feature
->Feature
);
1500 if (state
== INSTALLSTATE_UNKNOWN
|| state
== INSTALLSTATE_INVALIDARG
)
1501 feature
->Installed
= INSTALLSTATE_ABSENT
;
1503 feature
->Installed
= state
;
1507 static inline BOOL
is_feature_selected( MSIFEATURE
*feature
, INT level
)
1509 return (feature
->Level
> 0 && feature
->Level
<= level
);
1512 static BOOL
process_state_property(MSIPACKAGE
* package
, int level
,
1513 LPCWSTR property
, INSTALLSTATE state
)
1516 MSIFEATURE
*feature
;
1517 BOOL remove
= !wcscmp(property
, L
"REMOVE");
1518 BOOL reinstall
= !wcscmp(property
, L
"REINSTALL");
1520 override
= msi_dup_property( package
->db
, property
);
1524 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1526 if (feature
->Level
<= 0)
1530 state
= (feature
->Installed
== INSTALLSTATE_ABSENT
? INSTALLSTATE_UNKNOWN
: feature
->Installed
);
1532 state
= (feature
->Installed
== INSTALLSTATE_ABSENT
? INSTALLSTATE_UNKNOWN
: INSTALLSTATE_ABSENT
);
1534 if (!wcsicmp( override
, L
"ALL" ))
1536 feature
->Action
= state
;
1537 feature
->ActionRequest
= state
;
1541 LPWSTR ptr
= override
;
1542 LPWSTR ptr2
= wcschr(override
,',');
1546 int len
= ptr2
- ptr
;
1548 if ((ptr2
&& lstrlenW(feature
->Feature
) == len
&& !wcsncmp(ptr
, feature
->Feature
, len
))
1549 || (!ptr2
&& !wcscmp(ptr
, feature
->Feature
)))
1551 feature
->Action
= state
;
1552 feature
->ActionRequest
= state
;
1558 ptr2
= wcschr(ptr
,',');
1569 static BOOL
process_overrides( MSIPACKAGE
*package
, int level
)
1573 /* all these activation/deactivation things happen in order and things
1574 * later on the list override things earlier on the list.
1576 * 0 INSTALLLEVEL processing
1589 ret
|= process_state_property( package
, level
, L
"ADDLOCAL", INSTALLSTATE_LOCAL
);
1590 ret
|= process_state_property( package
, level
, L
"REMOVE", INSTALLSTATE_ABSENT
);
1591 ret
|= process_state_property( package
, level
, L
"ADDSOURCE", INSTALLSTATE_SOURCE
);
1592 ret
|= process_state_property( package
, level
, L
"REINSTALL", INSTALLSTATE_UNKNOWN
);
1593 ret
|= process_state_property( package
, level
, L
"ADVERTISE", INSTALLSTATE_ADVERTISED
);
1596 msi_set_property( package
->db
, L
"Preselected", L
"1", -1 );
1601 static void disable_children( MSIFEATURE
*feature
, int level
)
1605 LIST_FOR_EACH_ENTRY( fl
, &feature
->Children
, FeatureList
, entry
)
1607 if (!is_feature_selected( feature
, level
))
1609 TRACE("child %s (level %d request %d) follows disabled parent %s (level %d request %d)\n",
1610 debugstr_w(fl
->feature
->Feature
), fl
->feature
->Level
, fl
->feature
->ActionRequest
,
1611 debugstr_w(feature
->Feature
), feature
->Level
, feature
->ActionRequest
);
1613 fl
->feature
->Level
= feature
->Level
;
1614 fl
->feature
->Action
= INSTALLSTATE_UNKNOWN
;
1615 fl
->feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1617 disable_children( fl
->feature
, level
);
1621 static void follow_parent( MSIFEATURE
*feature
)
1625 LIST_FOR_EACH_ENTRY( fl
, &feature
->Children
, FeatureList
, entry
)
1627 if (fl
->feature
->Attributes
& msidbFeatureAttributesFollowParent
)
1629 TRACE("child %s (level %d request %d) follows parent %s (level %d request %d)\n",
1630 debugstr_w(fl
->feature
->Feature
), fl
->feature
->Level
, fl
->feature
->ActionRequest
,
1631 debugstr_w(feature
->Feature
), feature
->Level
, feature
->ActionRequest
);
1633 fl
->feature
->Action
= feature
->Action
;
1634 fl
->feature
->ActionRequest
= feature
->ActionRequest
;
1636 follow_parent( fl
->feature
);
1640 UINT
MSI_SetFeatureStates(MSIPACKAGE
*package
)
1643 MSICOMPONENT
* component
;
1644 MSIFEATURE
*feature
;
1646 TRACE("Checking Install Level\n");
1648 level
= msi_get_property_int(package
->db
, L
"INSTALLLEVEL", 1);
1650 if (msi_get_property_int( package
->db
, L
"Preselected", 0 ))
1652 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1654 if (!is_feature_selected( feature
, level
)) continue;
1656 if (feature
->ActionRequest
== INSTALLSTATE_UNKNOWN
)
1658 if (feature
->Installed
== INSTALLSTATE_ABSENT
)
1660 feature
->Action
= INSTALLSTATE_UNKNOWN
;
1661 feature
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1665 feature
->Action
= feature
->Installed
;
1666 feature
->ActionRequest
= feature
->Installed
;
1671 else if (!msi_get_property_int( package
->db
, L
"Installed", 0 ))
1673 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1675 if (!is_feature_selected( feature
, level
)) continue;
1677 if (feature
->ActionRequest
== INSTALLSTATE_UNKNOWN
)
1679 if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1681 feature
->Action
= INSTALLSTATE_SOURCE
;
1682 feature
->ActionRequest
= INSTALLSTATE_SOURCE
;
1684 else if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1686 feature
->Action
= INSTALLSTATE_ADVERTISED
;
1687 feature
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1691 feature
->Action
= INSTALLSTATE_LOCAL
;
1692 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1699 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1704 if (!is_feature_selected( feature
, level
)) continue;
1705 if (feature
->ActionRequest
!= INSTALLSTATE_UNKNOWN
) continue;
1707 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1709 if (!cl
->component
->updated
&& !cl
->component
->added
)
1715 if (cur
->ActionRequest
!= INSTALLSTATE_UNKNOWN
)
1718 if (cur
->Installed
!= INSTALLSTATE_ABSENT
)
1720 cur
->Action
= cur
->Installed
;
1721 cur
->ActionRequest
= cur
->Installed
;
1723 else if (!cl
->component
->added
)
1727 else if (cur
->Attributes
& msidbFeatureAttributesFavorSource
)
1729 cur
->Action
= INSTALLSTATE_SOURCE
;
1730 cur
->ActionRequest
= INSTALLSTATE_SOURCE
;
1732 else if (cur
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1734 cur
->Action
= INSTALLSTATE_ADVERTISED
;
1735 cur
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1739 cur
->Action
= INSTALLSTATE_LOCAL
;
1740 cur
->ActionRequest
= INSTALLSTATE_LOCAL
;
1743 if (!cur
->Feature_Parent
)
1745 cur
= msi_get_loaded_feature(package
, cur
->Feature_Parent
);
1751 /* disable child features of unselected parent or follow parent */
1752 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1754 if (feature
->Feature_Parent
) continue;
1755 disable_children( feature
, level
);
1756 follow_parent( feature
);
1759 /* now we want to set component state based based on feature state */
1760 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
1764 TRACE("examining feature %s (level %d installed %d request %d action %d)\n",
1765 debugstr_w(feature
->Feature
), feature
->Level
, feature
->Installed
,
1766 feature
->ActionRequest
, feature
->Action
);
1768 /* features with components that have compressed files are made local */
1769 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1771 if (cl
->component
->ForceLocalState
&&
1772 feature
->ActionRequest
== INSTALLSTATE_SOURCE
)
1774 feature
->Action
= INSTALLSTATE_LOCAL
;
1775 feature
->ActionRequest
= INSTALLSTATE_LOCAL
;
1780 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
1782 component
= cl
->component
;
1784 switch (feature
->ActionRequest
)
1786 case INSTALLSTATE_ABSENT
:
1787 component
->anyAbsent
= 1;
1789 case INSTALLSTATE_ADVERTISED
:
1790 component
->hasAdvertisedFeature
= 1;
1792 case INSTALLSTATE_SOURCE
:
1793 component
->hasSourceFeature
= 1;
1795 case INSTALLSTATE_LOCAL
:
1796 component
->hasLocalFeature
= 1;
1798 case INSTALLSTATE_DEFAULT
:
1799 if (feature
->Attributes
& msidbFeatureAttributesFavorAdvertise
)
1800 component
->hasAdvertisedFeature
= 1;
1801 else if (feature
->Attributes
& msidbFeatureAttributesFavorSource
)
1802 component
->hasSourceFeature
= 1;
1804 component
->hasLocalFeature
= 1;
1806 case INSTALLSTATE_UNKNOWN
:
1807 if (feature
->Installed
== INSTALLSTATE_ADVERTISED
)
1808 component
->hasAdvertisedFeature
= 1;
1809 if (feature
->Installed
== INSTALLSTATE_SOURCE
)
1810 component
->hasSourceFeature
= 1;
1811 if (feature
->Installed
== INSTALLSTATE_LOCAL
)
1812 component
->hasLocalFeature
= 1;
1820 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1822 /* check if it's local or source */
1823 if (!(component
->Attributes
& msidbComponentAttributesOptional
) &&
1824 (component
->hasLocalFeature
|| component
->hasSourceFeature
))
1826 if ((component
->Attributes
& msidbComponentAttributesSourceOnly
) &&
1827 !component
->ForceLocalState
)
1829 component
->Action
= INSTALLSTATE_SOURCE
;
1830 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1834 component
->Action
= INSTALLSTATE_LOCAL
;
1835 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1840 /* if any feature is local, the component must be local too */
1841 if (component
->hasLocalFeature
)
1843 component
->Action
= INSTALLSTATE_LOCAL
;
1844 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1847 if (component
->hasSourceFeature
)
1849 component
->Action
= INSTALLSTATE_SOURCE
;
1850 component
->ActionRequest
= INSTALLSTATE_SOURCE
;
1853 if (component
->hasAdvertisedFeature
)
1855 component
->Action
= INSTALLSTATE_ADVERTISED
;
1856 component
->ActionRequest
= INSTALLSTATE_ADVERTISED
;
1859 TRACE("nobody wants component %s\n", debugstr_w(component
->Component
));
1860 if (component
->anyAbsent
&& component
->ComponentId
)
1862 component
->Action
= INSTALLSTATE_ABSENT
;
1863 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
1867 LIST_FOR_EACH_ENTRY( component
, &package
->components
, MSICOMPONENT
, entry
)
1869 if (component
->ActionRequest
== INSTALLSTATE_DEFAULT
)
1871 TRACE("%s was default, setting to local\n", debugstr_w(component
->Component
));
1872 component
->Action
= INSTALLSTATE_LOCAL
;
1873 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
1876 if (component
->ActionRequest
== INSTALLSTATE_SOURCE
&&
1877 component
->Installed
== INSTALLSTATE_SOURCE
&&
1878 component
->hasSourceFeature
)
1880 component
->Action
= INSTALLSTATE_UNKNOWN
;
1881 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
1884 if (component
->Action
== INSTALLSTATE_LOCAL
|| component
->Action
== INSTALLSTATE_SOURCE
)
1885 component
->num_clients
++;
1886 else if (component
->Action
== INSTALLSTATE_ABSENT
)
1888 component
->num_clients
--;
1890 if (component
->num_clients
> 0)
1892 TRACE("multiple clients uses %s - disallowing uninstallation\n", debugstr_w(component
->Component
));
1893 component
->Action
= INSTALLSTATE_UNKNOWN
;
1897 TRACE("component %s (installed %d request %d action %d)\n",
1898 debugstr_w(component
->Component
), component
->Installed
, component
->ActionRequest
, component
->Action
);
1901 return ERROR_SUCCESS
;
1904 static UINT
ITERATE_CostFinalizeConditions(MSIRECORD
*row
, LPVOID param
)
1906 MSIPACKAGE
*package
= param
;
1908 MSIFEATURE
*feature
;
1910 name
= MSI_RecordGetString( row
, 1 );
1912 feature
= msi_get_loaded_feature( package
, name
);
1914 ERR("FAILED to find loaded feature %s\n",debugstr_w(name
));
1918 Condition
= MSI_RecordGetString(row
,3);
1920 if (MSI_EvaluateConditionW(package
,Condition
) == MSICONDITION_TRUE
)
1922 int level
= MSI_RecordGetInteger(row
,2);
1923 TRACE("Resetting feature %s to level %i\n", debugstr_w(name
), level
);
1924 feature
->Level
= level
;
1927 return ERROR_SUCCESS
;
1930 int msi_compare_file_versions( VS_FIXEDFILEINFO
*fi
, const WCHAR
*version
)
1934 msi_parse_version_string( version
, &ms
, &ls
);
1936 if (fi
->dwFileVersionMS
> ms
) return 1;
1937 else if (fi
->dwFileVersionMS
< ms
) return -1;
1938 else if (fi
->dwFileVersionLS
> ls
) return 1;
1939 else if (fi
->dwFileVersionLS
< ls
) return -1;
1943 int msi_compare_font_versions( const WCHAR
*ver1
, const WCHAR
*ver2
)
1947 msi_parse_version_string( ver1
, &ms1
, NULL
);
1948 msi_parse_version_string( ver2
, &ms2
, NULL
);
1950 if (ms1
> ms2
) return 1;
1951 else if (ms1
< ms2
) return -1;
1955 static WCHAR
*create_temp_dir( MSIDATABASE
*db
)
1960 if (!db
->tempfolder
)
1962 WCHAR tmp
[MAX_PATH
];
1963 DWORD len
= ARRAY_SIZE( tmp
);
1965 if (msi_get_property( db
, L
"TempFolder", tmp
, &len
) ||
1966 GetFileAttributesW( tmp
) != FILE_ATTRIBUTE_DIRECTORY
)
1968 GetTempPathW( MAX_PATH
, tmp
);
1970 if (!(db
->tempfolder
= strdupW( tmp
))) return NULL
;
1973 if ((ret
= msi_alloc( (lstrlenW( db
->tempfolder
) + 20) * sizeof(WCHAR
) )))
1977 if (!GetTempFileNameW( db
->tempfolder
, L
"msi", ++id
, ret
))
1982 if (CreateDirectoryW( ret
, NULL
)) break;
1990 * msi_build_directory_name()
1992 * This function is to save messing round with directory names
1993 * It handles adding backslashes between path segments,
1994 * and can add \ at the end of the directory name if told to.
1996 * It takes a variable number of arguments.
1997 * It always allocates a new string for the result, so make sure
1998 * to free the return value when finished with it.
2000 * The first arg is the number of path segments that follow.
2001 * The arguments following count are a list of path segments.
2002 * A path segment may be NULL.
2004 * Path segments will be added with a \ separating them.
2005 * A \ will not be added after the last segment, however if the
2006 * last segment is NULL, then the last character will be a \
2008 WCHAR
* WINAPIV
msi_build_directory_name( DWORD count
, ... )
2014 va_start( va
, count
);
2015 for (i
= 0; i
< count
; i
++)
2017 const WCHAR
*str
= va_arg( va
, const WCHAR
* );
2018 if (str
) sz
+= lstrlenW( str
) + 1;
2022 dir
= msi_alloc( sz
* sizeof(WCHAR
) );
2025 va_start( va
, count
);
2026 for (i
= 0; i
< count
; i
++)
2028 const WCHAR
*str
= va_arg( va
, const WCHAR
* );
2030 lstrcatW( dir
, str
);
2031 if ( i
+ 1 != count
&& dir
[0] && dir
[lstrlenW( dir
) - 1] != '\\') lstrcatW( dir
, L
"\\" );
2037 BOOL
msi_is_global_assembly( MSICOMPONENT
*comp
)
2039 return comp
->assembly
&& !comp
->assembly
->application
;
2042 static void set_target_path( MSIPACKAGE
*package
, MSIFILE
*file
)
2044 msi_free( file
->TargetPath
);
2045 if (msi_is_global_assembly( file
->Component
))
2047 MSIASSEMBLY
*assembly
= file
->Component
->assembly
;
2049 if (!assembly
->tempdir
) assembly
->tempdir
= create_temp_dir( package
->db
);
2050 file
->TargetPath
= msi_build_directory_name( 2, assembly
->tempdir
, file
->FileName
);
2054 const WCHAR
*dir
= msi_get_target_folder( package
, file
->Component
->Directory
);
2055 file
->TargetPath
= msi_build_directory_name( 2, dir
, file
->FileName
);
2058 TRACE("file %s resolves to %s\n", debugstr_w(file
->File
), debugstr_w(file
->TargetPath
));
2061 static UINT
calculate_file_cost( MSIPACKAGE
*package
)
2063 VS_FIXEDFILEINFO
*file_version
;
2064 WCHAR
*font_version
;
2067 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
2069 MSICOMPONENT
*comp
= file
->Component
;
2072 if (!comp
->Enabled
) continue;
2074 if (file
->IsCompressed
)
2075 comp
->ForceLocalState
= TRUE
;
2077 set_target_path( package
, file
);
2079 if ((comp
->assembly
&& !comp
->assembly
->installed
) ||
2080 msi_get_file_attributes( package
, file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
2082 comp
->Cost
+= file
->FileSize
;
2085 file_size
= msi_get_disk_file_size( package
, file
->TargetPath
);
2086 TRACE("%s (size %lu)\n", debugstr_w(file
->TargetPath
), file_size
);
2090 if ((file_version
= msi_get_disk_file_version( package
, file
->TargetPath
)))
2092 if (msi_compare_file_versions( file_version
, file
->Version
) < 0)
2094 comp
->Cost
+= file
->FileSize
- file_size
;
2096 msi_free( file_version
);
2099 else if ((font_version
= msi_get_font_file_version( package
, file
->TargetPath
)))
2101 if (msi_compare_font_versions( font_version
, file
->Version
) < 0)
2103 comp
->Cost
+= file
->FileSize
- file_size
;
2105 msi_free( font_version
);
2109 if (file_size
!= file
->FileSize
)
2111 comp
->Cost
+= file
->FileSize
- file_size
;
2115 return ERROR_SUCCESS
;
2118 WCHAR
*msi_normalize_path( const WCHAR
*in
)
2120 const WCHAR
*p
= in
;
2122 int n
, len
= lstrlenW( in
) + 2;
2124 if (!(q
= ret
= msi_alloc( len
* sizeof(WCHAR
) ))) return NULL
;
2129 /* copy until the end of the string or a space */
2130 while (*p
!= ' ' && (*q
= *p
))
2133 /* reduce many backslashes to one */
2134 if (*p
!= '\\' || *q
!= '\\')
2138 /* quit at the end of the string */
2142 /* count the number of spaces */
2147 /* if it's leading or trailing space, skip it */
2148 if ( len
== 0 || p
[-1] == '\\' || p
[n
] == '\\' )
2150 else /* copy n spaces */
2151 while (n
&& (*q
++ = *p
++)) n
--;
2153 while (q
- ret
> 0 && q
[-1] == ' ') q
--;
2154 if (q
- ret
> 0 && q
[-1] != '\\')
2162 static WCHAR
*get_install_location( MSIPACKAGE
*package
)
2167 if (!package
->ProductCode
) return NULL
;
2168 if (MSIREG_OpenInstallProps( package
->ProductCode
, package
->Context
, NULL
, &hkey
, FALSE
)) return NULL
;
2169 if ((path
= msi_reg_get_val_str( hkey
, L
"InstallLocation" )) && !path
[0])
2174 RegCloseKey( hkey
);
2178 void msi_resolve_target_folder( MSIPACKAGE
*package
, const WCHAR
*name
, BOOL load_prop
)
2181 MSIFOLDER
*folder
, *parent
, *child
;
2182 WCHAR
*path
, *normalized_path
;
2184 TRACE("resolving %s\n", debugstr_w(name
));
2186 if (!(folder
= msi_get_loaded_folder( package
, name
))) return;
2188 if (!wcscmp( folder
->Directory
, L
"TARGETDIR" )) /* special resolving for target root dir */
2190 if (!(path
= get_install_location( package
)) &&
2191 (!load_prop
|| !(path
= msi_dup_property( package
->db
, L
"TARGETDIR" ))))
2193 path
= msi_dup_property( package
->db
, L
"ROOTDRIVE" );
2196 else if (!load_prop
|| !(path
= msi_dup_property( package
->db
, folder
->Directory
)))
2198 if (folder
->Parent
&& wcscmp( folder
->Directory
, folder
->Parent
))
2200 parent
= msi_get_loaded_folder( package
, folder
->Parent
);
2201 path
= msi_build_directory_name( 3, parent
->ResolvedTarget
, folder
->TargetDefault
, NULL
);
2204 path
= msi_build_directory_name( 2, folder
->TargetDefault
, NULL
);
2207 normalized_path
= msi_normalize_path( path
);
2208 msi_set_property( package
->db
, folder
->Directory
, normalized_path
, -1 );
2211 msi_free( folder
->ResolvedTarget
);
2212 folder
->ResolvedTarget
= normalized_path
;
2214 LIST_FOR_EACH_ENTRY( fl
, &folder
->children
, FolderList
, entry
)
2217 msi_resolve_target_folder( package
, child
->Directory
, load_prop
);
2219 TRACE("%s resolves to %s\n", debugstr_w(name
), debugstr_w(folder
->ResolvedTarget
));
2222 static ULONGLONG
get_volume_space_required( MSIPACKAGE
*package
)
2227 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2229 if (comp
->Action
== INSTALLSTATE_LOCAL
) ret
+= comp
->Cost
;
2234 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2238 WCHAR
*level
, *primary_key
, *primary_folder
;
2241 TRACE("Building directory properties\n");
2242 msi_resolve_target_folder( package
, L
"TARGETDIR", TRUE
);
2244 TRACE("Evaluating component conditions\n");
2245 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
2247 if (MSI_EvaluateConditionW( package
, comp
->Condition
) == MSICONDITION_FALSE
)
2249 TRACE("Disabling component %s\n", debugstr_w(comp
->Component
));
2250 comp
->Enabled
= FALSE
;
2253 comp
->Enabled
= TRUE
;
2255 get_client_counts( package
);
2257 /* read components states from the registry */
2258 ACTION_GetComponentInstallStates(package
);
2259 ACTION_GetFeatureInstallStates(package
);
2261 if (!process_overrides( package
, msi_get_property_int( package
->db
, L
"INSTALLLEVEL", 1 ) ))
2263 TRACE("Evaluating feature conditions\n");
2265 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Condition`", &view
);
2266 if (rc
== ERROR_SUCCESS
)
2268 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_CostFinalizeConditions
, package
);
2269 msiobj_release( &view
->hdr
);
2270 if (rc
!= ERROR_SUCCESS
)
2275 TRACE("Calculating file cost\n");
2276 calculate_file_cost( package
);
2278 msi_set_property( package
->db
, L
"CostingComplete", L
"1", -1 );
2279 /* set default run level if not set */
2280 level
= msi_dup_property( package
->db
, L
"INSTALLLEVEL" );
2281 if (!level
) msi_set_property( package
->db
, L
"INSTALLLEVEL", L
"1", -1 );
2284 if ((rc
= MSI_SetFeatureStates( package
))) return rc
;
2286 if ((primary_key
= msi_dup_property( package
->db
, L
"PRIMARYFOLDER" )))
2288 if ((primary_folder
= msi_dup_property( package
->db
, primary_key
)))
2290 if (((primary_folder
[0] >= 'A' && primary_folder
[0] <= 'Z') ||
2291 (primary_folder
[0] >= 'a' && primary_folder
[0] <= 'z')) && primary_folder
[1] == ':')
2293 ULARGE_INTEGER free
;
2297 primary_folder
[2] = 0;
2298 if (GetDiskFreeSpaceExW( primary_folder
, &free
, NULL
, NULL
))
2301 swprintf(buf
, ARRAY_SIZE(buf
), L
"%I64u", free
.QuadPart
/ 512);
2303 swprintf( buf
, ARRAY_SIZE(buf
), L
"%lu", free
.QuadPart
/ 512 );
2305 msi_set_property( package
->db
, L
"PrimaryVolumeSpaceAvailable", buf
, -1 );
2307 required
= get_volume_space_required( package
);
2309 swprintf( buf
, ARRAY_SIZE(buf
), L
"%I64u", required
/ 512 );
2311 swprintf( buf
, ARRAY_SIZE(buf
), L
"%lu", required
/ 512 );
2313 msi_set_property( package
->db
, L
"PrimaryVolumeSpaceRequired", buf
, -1 );
2316 swprintf( buf
, ARRAY_SIZE(buf
), L
"%I64u", (free
.QuadPart
- required
) / 512 );
2318 swprintf( buf
, ARRAY_SIZE(buf
), L
"%lu", (free
.QuadPart
- required
) / 512 );
2320 msi_set_property( package
->db
, L
"PrimaryVolumeSpaceRemaining", buf
, -1 );
2321 msi_set_property( package
->db
, L
"PrimaryVolumePath", primary_folder
, 2 );
2323 msi_free( primary_folder
);
2325 msi_free( primary_key
);
2328 /* FIXME: check volume disk space */
2329 msi_set_property( package
->db
, L
"OutOfDiskSpace", L
"0", -1 );
2330 msi_set_property( package
->db
, L
"OutOfNoRbDiskSpace", L
"0", -1 );
2332 return ERROR_SUCCESS
;
2335 static BYTE
*parse_value( MSIPACKAGE
*package
, const WCHAR
*value
, DWORD len
, DWORD
*type
, DWORD
*size
)
2341 *size
= sizeof(WCHAR
);
2343 if ((data
= msi_alloc( *size
))) *(WCHAR
*)data
= 0;
2346 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
2352 LPWSTR deformated
= NULL
;
2355 deformat_string(package
, &value
[2], &deformated
);
2357 /* binary value type */
2360 if (lstrlenW(ptr
)%2)
2361 *size
= (lstrlenW(ptr
)/2)+1;
2363 *size
= lstrlenW(ptr
)/2;
2365 data
= msi_alloc(*size
);
2371 /* if uneven pad with a zero in front */
2372 if (lstrlenW(ptr
)%2)
2377 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2379 TRACE("Uneven byte count\n");
2387 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2390 msi_free(deformated
);
2392 TRACE( "data %lu bytes(%u)\n", *size
, count
);
2399 deformat_string(package
, &value
[1], &deformated
);
2402 *size
= sizeof(DWORD
);
2403 data
= msi_alloc(*size
);
2409 if ( (*p
< '0') || (*p
> '9') )
2415 if (deformated
[0] == '-')
2418 TRACE( "DWORD %lu\n", *(DWORD
*)data
);
2420 msi_free(deformated
);
2425 const WCHAR
*ptr
= value
;
2428 if (value
[0] == '#')
2431 if (value
[1] == '%')
2434 *type
= REG_EXPAND_SZ
;
2437 data
= (BYTE
*)msi_strdupW( ptr
, len
);
2438 if (len
> lstrlenW( (const WCHAR
*)data
)) *type
= REG_MULTI_SZ
;
2439 *size
= (len
+ 1) * sizeof(WCHAR
);
2444 static const WCHAR
*get_root_key( MSIPACKAGE
*package
, INT root
, HKEY
*root_key
)
2451 if (msi_get_property_int( package
->db
, L
"ALLUSERS", 0 ))
2453 *root_key
= HKEY_LOCAL_MACHINE
;
2454 ret
= L
"HKEY_LOCAL_MACHINE\\";
2458 *root_key
= HKEY_CURRENT_USER
;
2459 ret
= L
"HKEY_CURRENT_USER\\";
2463 *root_key
= HKEY_CLASSES_ROOT
;
2464 ret
= L
"HKEY_CLASSES_ROOT\\";
2467 *root_key
= HKEY_CURRENT_USER
;
2468 ret
= L
"HKEY_CURRENT_USER\\";
2471 *root_key
= HKEY_LOCAL_MACHINE
;
2472 ret
= L
"HKEY_LOCAL_MACHINE\\";
2475 *root_key
= HKEY_USERS
;
2476 ret
= L
"HKEY_USERS\\";
2479 ERR("Unknown root %i\n", root
);
2486 static inline REGSAM
get_registry_view( const MSICOMPONENT
*comp
)
2489 if (is_wow64
|| is_64bit
)
2490 view
|= (comp
->Attributes
& msidbComponentAttributes64bit
) ? KEY_WOW64_64KEY
: KEY_WOW64_32KEY
;
2494 static HKEY
open_key( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
, BOOL create
, REGSAM access
)
2496 WCHAR
*subkey
, *p
, *q
;
2497 HKEY hkey
, ret
= NULL
;
2500 access
|= get_registry_view( comp
);
2502 if (!(subkey
= strdupW( path
))) return NULL
;
2504 if ((q
= wcschr( p
, '\\' ))) *q
= 0;
2506 res
= RegCreateKeyExW( root
, subkey
, 0, NULL
, 0, access
, NULL
, &hkey
, NULL
);
2508 res
= RegOpenKeyExW( root
, subkey
, 0, access
, &hkey
);
2511 TRACE( "failed to open key %s (%ld)\n", debugstr_w(subkey
), res
);
2517 ret
= open_key( comp
, hkey
, q
+ 1, create
, access
);
2518 RegCloseKey( hkey
);
2525 static BOOL
is_special_entry( const WCHAR
*name
)
2527 return (name
&& (name
[0] == '*' || name
[0] == '+') && !name
[1]);
2530 static WCHAR
**split_multi_string_values( const WCHAR
*str
, DWORD len
, DWORD
*count
)
2532 const WCHAR
*p
= str
;
2537 if (!str
) return NULL
;
2538 while ((p
- str
) < len
)
2540 p
+= lstrlenW( p
) + 1;
2543 if (!(ret
= msi_alloc( *count
* sizeof(WCHAR
*) ))) return NULL
;
2545 while ((p
- str
) < len
)
2547 if (!(ret
[i
] = strdupW( p
)))
2549 for (; i
>= 0; i
--) msi_free( ret
[i
] );
2553 p
+= lstrlenW( p
) + 1;
2559 static WCHAR
*flatten_multi_string_values( WCHAR
**left
, DWORD left_count
,
2560 WCHAR
**right
, DWORD right_count
, DWORD
*size
)
2565 *size
= sizeof(WCHAR
);
2566 for (i
= 0; i
< left_count
; i
++) *size
+= (lstrlenW( left
[i
] ) + 1) * sizeof(WCHAR
);
2567 for (i
= 0; i
< right_count
; i
++) *size
+= (lstrlenW( right
[i
] ) + 1) * sizeof(WCHAR
);
2569 if (!(ret
= p
= msi_alloc( *size
))) return NULL
;
2571 for (i
= 0; i
< left_count
; i
++)
2573 lstrcpyW( p
, left
[i
] );
2574 p
+= lstrlenW( p
) + 1;
2576 for (i
= 0; i
< right_count
; i
++)
2578 lstrcpyW( p
, right
[i
] );
2579 p
+= lstrlenW( p
) + 1;
2585 static DWORD
remove_duplicate_values( WCHAR
**old
, DWORD old_count
,
2586 WCHAR
**new, DWORD new_count
)
2588 DWORD ret
= old_count
;
2589 unsigned int i
, j
, k
;
2591 for (i
= 0; i
< new_count
; i
++)
2593 for (j
= 0; j
< old_count
; j
++)
2595 if (old
[j
] && !wcscmp( new[i
], old
[j
] ))
2598 for (k
= j
; k
< old_count
- 1; k
++) { old
[k
] = old
[k
+ 1]; }
2614 static WCHAR
*join_multi_string_values( enum join_op op
, WCHAR
**old
, DWORD old_count
,
2615 WCHAR
**new, DWORD new_count
, DWORD
*size
)
2619 case JOIN_OP_APPEND
:
2620 old_count
= remove_duplicate_values( old
, old_count
, new, new_count
);
2621 return flatten_multi_string_values( old
, old_count
, new, new_count
, size
);
2623 case JOIN_OP_PREPEND
:
2624 old_count
= remove_duplicate_values( old
, old_count
, new, new_count
);
2625 return flatten_multi_string_values( new, new_count
, old
, old_count
, size
);
2627 case JOIN_OP_REPLACE
:
2628 return flatten_multi_string_values( new, new_count
, NULL
, 0, size
);
2631 ERR("unhandled join op %u\n", op
);
2636 static BYTE
*build_multi_string_value( BYTE
*old_value
, DWORD old_size
,
2637 BYTE
*new_value
, DWORD new_size
, DWORD
*size
)
2639 DWORD i
, old_len
= 0, new_len
= 0, old_count
= 0, new_count
= 0;
2640 const WCHAR
*new_ptr
= NULL
, *old_ptr
= NULL
;
2641 enum join_op op
= JOIN_OP_REPLACE
;
2642 WCHAR
**old
= NULL
, **new = NULL
;
2645 if (new_size
/ sizeof(WCHAR
) - 1 > 1)
2647 new_ptr
= (const WCHAR
*)new_value
;
2648 new_len
= new_size
/ sizeof(WCHAR
) - 1;
2650 if (!new_ptr
[0] && new_ptr
[new_len
- 1])
2652 op
= JOIN_OP_APPEND
;
2656 else if (new_ptr
[0] && !new_ptr
[new_len
- 1])
2658 op
= JOIN_OP_PREPEND
;
2661 else if (new_len
> 2 && !new_ptr
[0] && !new_ptr
[new_len
- 1])
2663 op
= JOIN_OP_REPLACE
;
2667 new = split_multi_string_values( new_ptr
, new_len
, &new_count
);
2669 if (old_size
/ sizeof(WCHAR
) - 1 > 1)
2671 old_ptr
= (const WCHAR
*)old_value
;
2672 old_len
= old_size
/ sizeof(WCHAR
) - 1;
2673 old
= split_multi_string_values( old_ptr
, old_len
, &old_count
);
2675 ret
= (BYTE
*)join_multi_string_values( op
, old
, old_count
, new, new_count
, size
);
2676 for (i
= 0; i
< old_count
; i
++) msi_free( old
[i
] );
2677 for (i
= 0; i
< new_count
; i
++) msi_free( new[i
] );
2683 static BYTE
*reg_get_value( HKEY hkey
, const WCHAR
*name
, DWORD
*type
, DWORD
*size
)
2686 if (RegQueryValueExW( hkey
, name
, NULL
, NULL
, NULL
, size
)) return NULL
;
2687 if (!(ret
= msi_alloc( *size
))) return NULL
;
2688 RegQueryValueExW( hkey
, name
, NULL
, type
, ret
, size
);
2692 static UINT
ITERATE_WriteRegistryValues(MSIRECORD
*row
, LPVOID param
)
2694 MSIPACKAGE
*package
= param
;
2695 BYTE
*new_value
, *old_value
= NULL
;
2696 HKEY root_key
, hkey
;
2697 DWORD type
, old_type
, new_size
, old_size
= 0;
2698 LPWSTR deformated
, uikey
;
2699 const WCHAR
*szRoot
, *component
, *name
, *key
, *str
;
2703 BOOL check_first
= FALSE
;
2706 msi_ui_progress( package
, 2, REG_PROGRESS_VALUE
, 0, 0 );
2708 component
= MSI_RecordGetString(row
, 6);
2709 comp
= msi_get_loaded_component(package
,component
);
2711 return ERROR_SUCCESS
;
2713 comp
->Action
= msi_get_component_action( package
, comp
);
2714 if (comp
->Action
!= INSTALLSTATE_LOCAL
&& comp
->Action
!= INSTALLSTATE_SOURCE
)
2716 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
2717 return ERROR_SUCCESS
;
2720 name
= MSI_RecordGetString(row
, 4);
2721 if( MSI_RecordIsNull(row
,5) && name
)
2723 /* null values can have special meanings */
2724 if (name
[0]=='-' && name
[1] == 0)
2725 return ERROR_SUCCESS
;
2726 if ((name
[0] == '+' || name
[0] == '*') && !name
[1])
2730 root
= MSI_RecordGetInteger(row
,2);
2731 key
= MSI_RecordGetString(row
, 3);
2733 szRoot
= get_root_key( package
, root
, &root_key
);
2735 return ERROR_SUCCESS
;
2737 deformat_string(package
, key
, &deformated
);
2738 uikey
= msi_alloc( (lstrlenW(deformated
) + lstrlenW(szRoot
) + 1) * sizeof(WCHAR
) );
2739 lstrcpyW(uikey
,szRoot
);
2740 lstrcatW(uikey
,deformated
);
2742 if (!(hkey
= open_key( comp
, root_key
, deformated
, TRUE
, KEY_QUERY_VALUE
| KEY_SET_VALUE
)))
2744 ERR("Could not create key %s\n", debugstr_w(deformated
));
2746 msi_free(deformated
);
2747 return ERROR_FUNCTION_FAILED
;
2749 msi_free( deformated
);
2750 str
= msi_record_get_string( row
, 5, NULL
);
2751 len
= deformat_string( package
, str
, &deformated
);
2752 new_value
= parse_value( package
, deformated
, len
, &type
, &new_size
);
2754 msi_free( deformated
);
2755 deformat_string(package
, name
, &deformated
);
2757 if (!is_special_entry( name
))
2759 old_value
= reg_get_value( hkey
, deformated
, &old_type
, &old_size
);
2760 if (type
== REG_MULTI_SZ
)
2763 if (old_value
&& old_type
!= REG_MULTI_SZ
)
2765 msi_free( old_value
);
2769 new = build_multi_string_value( old_value
, old_size
, new_value
, new_size
, &new_size
);
2770 msi_free( new_value
);
2775 TRACE( "setting value %s of %s type %lu\n", debugstr_w(deformated
), debugstr_w(uikey
), type
);
2776 RegSetValueExW( hkey
, deformated
, 0, type
, new_value
, new_size
);
2778 else if (!old_value
)
2780 if (deformated
|| new_size
)
2782 TRACE( "setting value %s of %s type %lu\n", debugstr_w(deformated
), debugstr_w(uikey
), type
);
2783 RegSetValueExW( hkey
, deformated
, 0, type
, new_value
, new_size
);
2786 else TRACE("not overwriting existing value %s of %s\n", debugstr_w(deformated
), debugstr_w(uikey
));
2790 uirow
= MSI_CreateRecord(3);
2791 MSI_RecordSetStringW(uirow
,2,deformated
);
2792 MSI_RecordSetStringW(uirow
,1,uikey
);
2793 if (type
== REG_SZ
|| type
== REG_EXPAND_SZ
)
2794 MSI_RecordSetStringW(uirow
, 3, (LPWSTR
)new_value
);
2795 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
2796 msiobj_release( &uirow
->hdr
);
2798 msi_free(new_value
);
2799 msi_free(old_value
);
2800 msi_free(deformated
);
2803 return ERROR_SUCCESS
;
2806 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2811 if (package
->script
== SCRIPT_NONE
)
2812 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"WriteRegistryValues");
2814 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `Registry`", &view
);
2815 if (rc
!= ERROR_SUCCESS
)
2816 return ERROR_SUCCESS
;
2818 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteRegistryValues
, package
);
2819 msiobj_release(&view
->hdr
);
2823 static int is_key_empty(const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
)
2825 DWORD subkeys
, values
;
2829 key
= open_key(comp
, root
, path
, FALSE
, KEY_READ
);
2832 res
= RegQueryInfoKeyW(key
, 0, 0, 0, &subkeys
, 0, 0, &values
, 0, 0, 0, 0);
2835 return !res
&& !subkeys
&& !values
;
2838 static void delete_key( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
)
2840 LONG res
= ERROR_SUCCESS
;
2841 REGSAM access
= get_registry_view( comp
);
2845 if (!(subkey
= strdupW( path
))) return;
2848 if ((p
= wcsrchr( subkey
, '\\' )))
2851 if (!p
[1]) continue; /* trailing backslash */
2852 hkey
= open_key( comp
, root
, subkey
, FALSE
, READ_CONTROL
);
2854 if (!is_key_empty(comp
, hkey
, p
+ 1))
2859 res
= RegDeleteKeyExW( hkey
, p
+ 1, access
, 0 );
2860 RegCloseKey( hkey
);
2862 else if (is_key_empty(comp
, root
, subkey
))
2863 res
= RegDeleteKeyExW( root
, subkey
, access
, 0 );
2866 TRACE( "failed to delete key %s (%ld)\n", debugstr_w(subkey
), res
);
2873 static void delete_value( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
, const WCHAR
*value
)
2878 if ((hkey
= open_key( comp
, root
, path
, FALSE
, KEY_SET_VALUE
| KEY_QUERY_VALUE
)))
2880 if ((res
= RegDeleteValueW( hkey
, value
)))
2881 TRACE( "failed to delete value %s (%ld)\n", debugstr_w(value
), res
);
2883 RegCloseKey( hkey
);
2884 if (is_key_empty(comp
, root
, path
))
2886 TRACE("removing empty key %s\n", debugstr_w(path
));
2887 delete_key( comp
, root
, path
);
2892 static void delete_tree( const MSICOMPONENT
*comp
, HKEY root
, const WCHAR
*path
)
2897 if (!(hkey
= open_key( comp
, root
, path
, FALSE
, KEY_ALL_ACCESS
))) return;
2898 res
= RegDeleteTreeW( hkey
, NULL
);
2899 if (res
) TRACE( "failed to delete subtree of %s (%ld)\n", debugstr_w(path
), res
);
2900 delete_key( comp
, root
, path
);
2901 RegCloseKey( hkey
);
2904 static UINT
ITERATE_RemoveRegistryValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
2906 MSIPACKAGE
*package
= param
;
2907 LPCWSTR component
, name
, key_str
, root_key_str
;
2908 LPWSTR deformated_key
, deformated_name
, ui_key_str
;
2911 BOOL delete_key
= FALSE
;
2916 msi_ui_progress( package
, 2, REG_PROGRESS_VALUE
, 0, 0 );
2918 component
= MSI_RecordGetString( row
, 6 );
2919 comp
= msi_get_loaded_component( package
, component
);
2921 return ERROR_SUCCESS
;
2923 comp
->Action
= msi_get_component_action( package
, comp
);
2924 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
2926 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
2927 return ERROR_SUCCESS
;
2930 name
= MSI_RecordGetString( row
, 4 );
2931 if (MSI_RecordIsNull( row
, 5 ) && name
)
2933 if (name
[0] == '+' && !name
[1])
2934 return ERROR_SUCCESS
;
2935 if ((name
[0] == '-' || name
[0] == '*') && !name
[1])
2942 root
= MSI_RecordGetInteger( row
, 2 );
2943 key_str
= MSI_RecordGetString( row
, 3 );
2945 root_key_str
= get_root_key( package
, root
, &hkey_root
);
2947 return ERROR_SUCCESS
;
2949 deformat_string( package
, key_str
, &deformated_key
);
2950 size
= lstrlenW( deformated_key
) + lstrlenW( root_key_str
) + 1;
2951 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
2952 lstrcpyW( ui_key_str
, root_key_str
);
2953 lstrcatW( ui_key_str
, deformated_key
);
2955 deformat_string( package
, name
, &deformated_name
);
2957 if (delete_key
) delete_tree( comp
, hkey_root
, deformated_key
);
2958 else delete_value( comp
, hkey_root
, deformated_key
, deformated_name
);
2959 msi_free( deformated_key
);
2961 uirow
= MSI_CreateRecord( 2 );
2962 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
2963 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
2964 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
2965 msiobj_release( &uirow
->hdr
);
2967 msi_free( ui_key_str
);
2968 msi_free( deformated_name
);
2969 return ERROR_SUCCESS
;
2972 static UINT
ITERATE_RemoveRegistryValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
2974 MSIPACKAGE
*package
= param
;
2975 LPCWSTR component
, name
, key_str
, root_key_str
;
2976 LPWSTR deformated_key
, deformated_name
, ui_key_str
;
2979 BOOL delete_key
= FALSE
;
2984 component
= MSI_RecordGetString( row
, 5 );
2985 comp
= msi_get_loaded_component( package
, component
);
2987 return ERROR_SUCCESS
;
2989 comp
->Action
= msi_get_component_action( package
, comp
);
2990 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
2992 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
2993 return ERROR_SUCCESS
;
2996 if ((name
= MSI_RecordGetString( row
, 4 )))
2998 if (name
[0] == '-' && !name
[1])
3005 root
= MSI_RecordGetInteger( row
, 2 );
3006 key_str
= MSI_RecordGetString( row
, 3 );
3008 root_key_str
= get_root_key( package
, root
, &hkey_root
);
3010 return ERROR_SUCCESS
;
3012 deformat_string( package
, key_str
, &deformated_key
);
3013 size
= lstrlenW( deformated_key
) + lstrlenW( root_key_str
) + 1;
3014 ui_key_str
= msi_alloc( size
* sizeof(WCHAR
) );
3015 lstrcpyW( ui_key_str
, root_key_str
);
3016 lstrcatW( ui_key_str
, deformated_key
);
3018 deformat_string( package
, name
, &deformated_name
);
3020 if (delete_key
) delete_tree( comp
, hkey_root
, deformated_key
);
3021 else delete_value( comp
, hkey_root
, deformated_key
, deformated_name
);
3022 msi_free( deformated_key
);
3024 uirow
= MSI_CreateRecord( 2 );
3025 MSI_RecordSetStringW( uirow
, 1, ui_key_str
);
3026 MSI_RecordSetStringW( uirow
, 2, deformated_name
);
3027 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
3028 msiobj_release( &uirow
->hdr
);
3030 msi_free( ui_key_str
);
3031 msi_free( deformated_name
);
3032 return ERROR_SUCCESS
;
3035 static UINT
ACTION_RemoveRegistryValues( MSIPACKAGE
*package
)
3040 if (package
->script
== SCRIPT_NONE
)
3041 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RemoveRegistryValues");
3043 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Registry`", &view
);
3044 if (rc
== ERROR_SUCCESS
)
3046 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnUninstall
, package
);
3047 msiobj_release( &view
->hdr
);
3048 if (rc
!= ERROR_SUCCESS
)
3051 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `RemoveRegistry`", &view
);
3052 if (rc
== ERROR_SUCCESS
)
3054 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveRegistryValuesOnInstall
, package
);
3055 msiobj_release( &view
->hdr
);
3056 if (rc
!= ERROR_SUCCESS
)
3059 return ERROR_SUCCESS
;
3062 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
3064 return ERROR_SUCCESS
;
3068 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
3071 DWORD total
= 0, count
= 0;
3073 MSIFEATURE
*feature
;
3077 TRACE("InstallValidate\n");
3079 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Registry`", &view
);
3080 if (rc
== ERROR_SUCCESS
)
3082 rc
= MSI_IterateRecords( view
, &count
, NULL
, package
);
3083 msiobj_release( &view
->hdr
);
3084 if (rc
!= ERROR_SUCCESS
)
3086 total
+= count
* REG_PROGRESS_VALUE
;
3088 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
3089 total
+= COMPONENT_PROGRESS_VALUE
;
3091 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
3092 total
+= file
->FileSize
;
3094 msi_ui_progress( package
, 0, total
, 0, 0 );
3096 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3098 TRACE("Feature: %s Installed %d Request %d Action %d\n",
3099 debugstr_w(feature
->Feature
), feature
->Installed
,
3100 feature
->ActionRequest
, feature
->Action
);
3102 return ERROR_SUCCESS
;
3105 static UINT
ITERATE_LaunchConditions(MSIRECORD
*row
, LPVOID param
)
3107 MSIPACKAGE
* package
= param
;
3108 const WCHAR
*cond
, *message
;
3111 cond
= MSI_RecordGetString(row
, 1);
3112 r
= MSI_EvaluateConditionW(package
, cond
);
3113 if (r
== MSICONDITION_FALSE
)
3115 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
3118 message
= MSI_RecordGetString(row
, 2);
3119 deformat_string(package
, message
, &deformated
);
3120 MessageBoxW(NULL
, deformated
, L
"Install Failed", MB_OK
);
3121 msi_free(deformated
);
3124 return ERROR_INSTALL_FAILURE
;
3127 return ERROR_SUCCESS
;
3130 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
3135 TRACE("Checking launch conditions\n");
3137 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `LaunchCondition`", &view
);
3138 if (rc
!= ERROR_SUCCESS
)
3139 return ERROR_SUCCESS
;
3141 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_LaunchConditions
, package
);
3142 msiobj_release(&view
->hdr
);
3146 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, MSICOMPONENT
*cmp
)
3150 return strdupW( msi_get_target_folder( package
, cmp
->Directory
) );
3152 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
3156 LPWSTR deformated
, buffer
, deformated_name
;
3159 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `Registry` WHERE `Registry` = '%s'", cmp
->KeyPath
);
3163 root
= MSI_RecordGetInteger(row
,2);
3164 key
= MSI_RecordGetString(row
, 3);
3165 name
= MSI_RecordGetString(row
, 4);
3166 deformat_string(package
, key
, &deformated
);
3167 deformat_string(package
, name
, &deformated_name
);
3169 len
= lstrlenW(deformated
) + 6;
3170 if (deformated_name
)
3171 len
+=lstrlenW(deformated_name
);
3173 buffer
= msi_alloc( len
*sizeof(WCHAR
));
3175 if (deformated_name
)
3176 swprintf(buffer
, len
, L
"%02d:\\%s\\%s", root
, deformated
, deformated_name
);
3178 swprintf(buffer
, len
, L
"%02d:\\%s\\", root
, deformated
);
3180 msi_free(deformated
);
3181 msi_free(deformated_name
);
3182 msiobj_release(&row
->hdr
);
3186 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
3188 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3193 MSIFILE
*file
= msi_get_loaded_file( package
, cmp
->KeyPath
);
3196 return strdupW( file
->TargetPath
);
3201 static HKEY
open_shared_dlls_key( MSICOMPONENT
*comp
, BOOL create
, REGSAM access
)
3203 return open_key( comp
, HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\SharedDLLs",
3207 static UINT
get_shared_dlls_count( MSICOMPONENT
*comp
)
3209 DWORD count
, type
, sz
= sizeof(count
);
3210 HKEY hkey
= open_shared_dlls_key( comp
, FALSE
, KEY_READ
);
3211 if (RegQueryValueExW( hkey
, comp
->FullKeypath
, NULL
, &type
, (BYTE
*)&count
, &sz
)) count
= 0;
3212 RegCloseKey( hkey
);
3216 static void write_shared_dlls_count( MSICOMPONENT
*comp
, const WCHAR
*path
, INT count
)
3218 HKEY hkey
= open_shared_dlls_key( comp
, TRUE
, KEY_SET_VALUE
);
3220 msi_reg_set_val_dword( hkey
, path
, count
);
3222 RegDeleteValueW( hkey
, path
);
3226 static void refcount_component( MSIPACKAGE
*package
, MSICOMPONENT
*comp
)
3228 MSIFEATURE
*feature
;
3232 /* only refcount DLLs */
3233 if (!comp
->KeyPath
|| comp
->assembly
|| comp
->Attributes
& msidbComponentAttributesRegistryKeyPath
||
3234 comp
->Attributes
& msidbComponentAttributesODBCDataSource
)
3238 count
= get_shared_dlls_count( comp
);
3239 write
= (count
> 0);
3240 if (comp
->Attributes
& msidbComponentAttributesSharedDllRefCount
)
3244 /* increment counts */
3245 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3249 if (msi_get_feature_action( package
, feature
) != INSTALLSTATE_LOCAL
)
3252 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3254 if ( cl
->component
== comp
)
3259 /* decrement counts */
3260 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
3264 if (msi_get_feature_action( package
, feature
) != INSTALLSTATE_ABSENT
)
3267 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
3269 if ( cl
->component
== comp
)
3274 /* ref count all the files in the component */
3279 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
3281 if (file
->Component
== comp
)
3282 write_shared_dlls_count( comp
, file
->TargetPath
, count
);
3286 /* add a count for permanent */
3287 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
3290 comp
->RefCount
= count
;
3293 write_shared_dlls_count( comp
, comp
->FullKeypath
, comp
->RefCount
);
3296 static WCHAR
*build_full_keypath( MSIPACKAGE
*package
, MSICOMPONENT
*comp
)
3300 DWORD len
= lstrlenW( L
"<\\" ) + lstrlenW( comp
->assembly
->display_name
);
3301 WCHAR
*keypath
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
3305 lstrcpyW( keypath
, L
"<\\" );
3306 lstrcatW( keypath
, comp
->assembly
->display_name
);
3310 return resolve_keypath( package
, comp
);
3313 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
3315 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
], squashed_cc
[SQUASHED_GUID_SIZE
];
3322 msi_set_sourcedir_props(package
, FALSE
);
3324 if (package
->script
== SCRIPT_NONE
)
3325 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"ProcessComponents");
3327 squash_guid( package
->ProductCode
, squashed_pc
);
3329 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
3332 INSTALLSTATE action
;
3334 msi_ui_progress( package
, 2, COMPONENT_PROGRESS_VALUE
, 0, 0 );
3335 if (!comp
->ComponentId
)
3338 squash_guid( comp
->ComponentId
, squashed_cc
);
3339 msi_free( comp
->FullKeypath
);
3340 comp
->FullKeypath
= build_full_keypath( package
, comp
);
3342 refcount_component( package
, comp
);
3344 if (package
->need_rollback
) action
= comp
->Installed
;
3345 else action
= comp
->ActionRequest
;
3347 TRACE("Component %s (%s) Keypath=%s RefCount=%u Clients=%u Action=%u\n",
3348 debugstr_w(comp
->Component
), debugstr_w(squashed_cc
),
3349 debugstr_w(comp
->FullKeypath
), comp
->RefCount
, comp
->num_clients
, action
);
3351 if (action
== INSTALLSTATE_LOCAL
|| action
== INSTALLSTATE_SOURCE
)
3353 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3354 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, L
"S-1-5-18", &hkey
, TRUE
);
3356 rc
= MSIREG_OpenUserDataComponentKey(comp
->ComponentId
, NULL
, &hkey
, TRUE
);
3358 if (rc
!= ERROR_SUCCESS
)
3361 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
3363 msi_reg_set_val_str(hkey
, L
"00000000000000000000000000000000", comp
->FullKeypath
);
3365 if (action
== INSTALLSTATE_LOCAL
)
3366 msi_reg_set_val_str( hkey
, squashed_pc
, comp
->FullKeypath
);
3372 WCHAR source
[MAX_PATH
];
3373 WCHAR base
[MAX_PATH
];
3376 if (!comp
->KeyPath
|| !(file
= msi_get_loaded_file(package
, comp
->KeyPath
)))
3379 if (!(row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `Media` WHERE `LastSequence` >= %d "
3380 L
"ORDER BY `DiskId`", file
->Sequence
)))
3381 return ERROR_FUNCTION_FAILED
;
3383 swprintf(source
, ARRAY_SIZE(source
), L
"%02d\\", MSI_RecordGetInteger(row
, 1));
3384 ptr2
= wcsrchr(source
, '\\') + 1;
3385 msiobj_release(&row
->hdr
);
3387 lstrcpyW(base
, package
->PackagePath
);
3388 ptr
= wcsrchr(base
, '\\');
3391 sourcepath
= msi_resolve_file_source(package
, file
);
3392 ptr
= sourcepath
+ lstrlenW(base
);
3393 lstrcpyW(ptr2
, ptr
);
3394 msi_free(sourcepath
);
3396 msi_reg_set_val_str( hkey
, squashed_pc
, source
);
3400 else if (action
== INSTALLSTATE_ABSENT
)
3402 if (comp
->num_clients
<= 0)
3404 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3405 rc
= MSIREG_DeleteUserDataComponentKey( comp
->ComponentId
, L
"S-1-5-18" );
3407 rc
= MSIREG_DeleteUserDataComponentKey( comp
->ComponentId
, NULL
);
3409 if (rc
!= ERROR_SUCCESS
) WARN( "failed to delete component key %u\n", rc
);
3415 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3416 rc
= MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, L
"S-1-5-18", &hkey
, FALSE
);
3418 rc
= MSIREG_OpenUserDataComponentKey( comp
->ComponentId
, NULL
, &hkey
, FALSE
);
3420 if (rc
!= ERROR_SUCCESS
)
3422 WARN( "failed to open component key %u\n", rc
);
3425 res
= RegDeleteValueW( hkey
, squashed_pc
);
3427 if (res
) WARN( "failed to delete component value %ld\n", res
);
3432 uirow
= MSI_CreateRecord(3);
3433 MSI_RecordSetStringW(uirow
,1,package
->ProductCode
);
3434 MSI_RecordSetStringW(uirow
,2,comp
->ComponentId
);
3435 MSI_RecordSetStringW(uirow
,3,comp
->FullKeypath
);
3436 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
3437 msiobj_release( &uirow
->hdr
);
3439 return ERROR_SUCCESS
;
3450 static BOOL CALLBACK
Typelib_EnumResNameProc( HMODULE hModule
, LPCWSTR lpszType
,
3451 LPWSTR lpszName
, LONG_PTR lParam
)
3454 typelib_struct
*tl_struct
= (typelib_struct
*) lParam
;
3458 if (!IS_INTRESOURCE(lpszName
))
3460 ERR("Not Int Resource Name %s\n",debugstr_w(lpszName
));
3464 sz
= lstrlenW(tl_struct
->source
)+4;
3466 if ((INT_PTR
)lpszName
== 1)
3467 tl_struct
->path
= strdupW(tl_struct
->source
);
3470 tl_struct
->path
= msi_alloc(sz
* sizeof(WCHAR
));
3472 swprintf(tl_struct
->path
, sz
, L
"%s\\%d", tl_struct
->source
, (WORD
)(INT_PTR
)lpszName
);
3474 swprintf(tl_struct
->path
, sz
, L
"%s\\%d", tl_struct
->source
, lpszName
);
3478 TRACE("trying %s\n", debugstr_w(tl_struct
->path
));
3479 res
= LoadTypeLib(tl_struct
->path
,&tl_struct
->ptLib
);
3482 msi_free(tl_struct
->path
);
3483 tl_struct
->path
= NULL
;
3488 ITypeLib_GetLibAttr(tl_struct
->ptLib
, &attr
);
3489 if (IsEqualGUID(&(tl_struct
->clsid
),&(attr
->guid
)))
3491 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3495 msi_free(tl_struct
->path
);
3496 tl_struct
->path
= NULL
;
3498 ITypeLib_ReleaseTLibAttr(tl_struct
->ptLib
, attr
);
3499 ITypeLib_Release(tl_struct
->ptLib
);
3504 static HMODULE
msi_load_library( MSIPACKAGE
*package
, const WCHAR
*filename
, DWORD flags
)
3507 msi_disable_fs_redirection( package
);
3508 module
= LoadLibraryExW( filename
, NULL
, flags
);
3509 msi_revert_fs_redirection( package
);
3513 static HRESULT
msi_load_typelib( MSIPACKAGE
*package
, const WCHAR
*filename
, REGKIND kind
, ITypeLib
**lib
)
3516 msi_disable_fs_redirection( package
);
3517 hr
= LoadTypeLibEx( filename
, kind
, lib
);
3518 msi_revert_fs_redirection( package
);
3522 static UINT
ITERATE_RegisterTypeLibraries(MSIRECORD
*row
, LPVOID param
)
3524 MSIPACKAGE
* package
= param
;
3528 typelib_struct tl_struct
;
3533 component
= MSI_RecordGetString(row
,3);
3534 comp
= msi_get_loaded_component(package
,component
);
3536 return ERROR_SUCCESS
;
3538 comp
->Action
= msi_get_component_action( package
, comp
);
3539 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
3541 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
3542 return ERROR_SUCCESS
;
3545 if (!comp
->KeyPath
|| !(file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
3547 TRACE("component has no key path\n");
3548 return ERROR_SUCCESS
;
3550 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
3552 module
= msi_load_library( package
, file
->TargetPath
, LOAD_LIBRARY_AS_DATAFILE
);
3556 guid
= MSI_RecordGetString(row
,1);
3557 CLSIDFromString( guid
, &tl_struct
.clsid
);
3558 tl_struct
.source
= strdupW( file
->TargetPath
);
3559 tl_struct
.path
= NULL
;
3561 EnumResourceNamesW(module
, L
"TYPELIB", Typelib_EnumResNameProc
,
3562 (LONG_PTR
)&tl_struct
);
3566 LPCWSTR helpid
, help_path
= NULL
;
3569 helpid
= MSI_RecordGetString(row
,6);
3571 if (helpid
) help_path
= msi_get_target_folder( package
, helpid
);
3572 res
= RegisterTypeLib( tl_struct
.ptLib
, tl_struct
.path
, (OLECHAR
*)help_path
);
3575 ERR("Failed to register type library %s\n", debugstr_w(tl_struct
.path
));
3577 TRACE("Registered %s\n", debugstr_w(tl_struct
.path
));
3579 ITypeLib_Release(tl_struct
.ptLib
);
3580 msi_free(tl_struct
.path
);
3582 else ERR("Failed to load type library %s\n", debugstr_w(tl_struct
.source
));
3584 FreeLibrary(module
);
3585 msi_free(tl_struct
.source
);
3589 hr
= msi_load_typelib( package
, file
->TargetPath
, REGKIND_REGISTER
, &tlib
);
3592 ERR( "failed to load type library: %#lx\n", hr
);
3593 return ERROR_INSTALL_FAILURE
;
3596 ITypeLib_Release(tlib
);
3599 return ERROR_SUCCESS
;
3602 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
3607 if (package
->script
== SCRIPT_NONE
)
3608 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RegisterTypeLibraries");
3610 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `TypeLib`", &view
);
3611 if (rc
!= ERROR_SUCCESS
)
3612 return ERROR_SUCCESS
;
3614 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_RegisterTypeLibraries
, package
);
3615 msiobj_release(&view
->hdr
);
3619 static UINT
ITERATE_UnregisterTypeLibraries( MSIRECORD
*row
, LPVOID param
)
3621 MSIPACKAGE
*package
= param
;
3622 LPCWSTR component
, guid
;
3630 component
= MSI_RecordGetString( row
, 3 );
3631 comp
= msi_get_loaded_component( package
, component
);
3633 return ERROR_SUCCESS
;
3635 comp
->Action
= msi_get_component_action( package
, comp
);
3636 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
3638 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
3639 return ERROR_SUCCESS
;
3641 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
3643 guid
= MSI_RecordGetString( row
, 1 );
3644 CLSIDFromString( guid
, &libid
);
3645 version
= MSI_RecordGetInteger( row
, 4 );
3646 language
= MSI_RecordGetInteger( row
, 2 );
3649 syskind
= SYS_WIN64
;
3651 syskind
= SYS_WIN32
;
3654 hr
= UnRegisterTypeLib( &libid
, (version
>> 8) & 0xffff, version
& 0xff, language
, syskind
);
3657 WARN( "failed to unregister typelib: %#lx\n", hr
);
3660 return ERROR_SUCCESS
;
3663 static UINT
ACTION_UnregisterTypeLibraries( MSIPACKAGE
*package
)
3668 if (package
->script
== SCRIPT_NONE
)
3669 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"UnregisterTypeLibraries");
3671 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `TypeLib`", &view
);
3672 if (rc
!= ERROR_SUCCESS
)
3673 return ERROR_SUCCESS
;
3675 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnregisterTypeLibraries
, package
);
3676 msiobj_release( &view
->hdr
);
3680 static WCHAR
*get_link_file( MSIPACKAGE
*package
, MSIRECORD
*row
)
3682 LPCWSTR directory
, extension
, link_folder
;
3683 LPWSTR link_file
, filename
;
3685 directory
= MSI_RecordGetString( row
, 2 );
3686 link_folder
= msi_get_target_folder( package
, directory
);
3689 ERR("unable to resolve folder %s\n", debugstr_w(directory
));
3692 /* may be needed because of a bug somewhere else */
3693 msi_create_full_path( package
, link_folder
);
3695 filename
= msi_dup_record_field( row
, 3 );
3696 msi_reduce_to_long_filename( filename
);
3698 extension
= wcsrchr( filename
, '.' );
3699 if (!extension
|| wcsicmp( extension
, L
".lnk" ))
3701 int len
= lstrlenW( filename
);
3702 filename
= msi_realloc( filename
, len
* sizeof(WCHAR
) + sizeof(L
".lnk") );
3703 memcpy( filename
+ len
, L
".lnk", sizeof(L
".lnk") );
3705 link_file
= msi_build_directory_name( 2, link_folder
, filename
);
3706 msi_free( filename
);
3711 WCHAR
*msi_build_icon_path( MSIPACKAGE
*package
, const WCHAR
*icon_name
)
3713 WCHAR
*folder
, *dest
, *path
;
3715 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
3716 folder
= msi_dup_property( package
->db
, L
"WindowsFolder" );
3719 WCHAR
*appdata
= msi_dup_property( package
->db
, L
"AppDataFolder" );
3720 folder
= msi_build_directory_name( 2, appdata
, L
"Microsoft\\" );
3721 msi_free( appdata
);
3723 dest
= msi_build_directory_name( 3, folder
, L
"Installer\\", package
->ProductCode
);
3724 msi_create_full_path( package
, dest
);
3725 path
= msi_build_directory_name( 2, dest
, icon_name
);
3731 static UINT
ITERATE_CreateShortcuts(MSIRECORD
*row
, LPVOID param
)
3733 MSIPACKAGE
*package
= param
;
3734 LPWSTR link_file
, deformated
, path
;
3735 LPCWSTR component
, target
;
3737 IShellLinkW
*sl
= NULL
;
3738 IPersistFile
*pf
= NULL
;
3741 component
= MSI_RecordGetString(row
, 4);
3742 comp
= msi_get_loaded_component(package
, component
);
3744 return ERROR_SUCCESS
;
3746 comp
->Action
= msi_get_component_action( package
, comp
);
3747 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
3749 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
3750 return ERROR_SUCCESS
;
3752 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
3754 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3755 &IID_IShellLinkW
, (LPVOID
*) &sl
);
3759 ERR("CLSID_ShellLink not available\n");
3763 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
3766 ERR("QueryInterface(IID_IPersistFile) failed\n");
3770 target
= MSI_RecordGetString(row
, 5);
3771 if (wcschr(target
, '['))
3773 deformat_string( package
, target
, &path
);
3774 TRACE("target path is %s\n", debugstr_w(path
));
3775 IShellLinkW_SetPath( sl
, path
);
3780 FIXME("poorly handled shortcut format, advertised shortcut\n");
3781 path
= resolve_keypath( package
, comp
);
3782 IShellLinkW_SetPath( sl
, path
);
3786 if (!MSI_RecordIsNull(row
,6))
3788 LPCWSTR arguments
= MSI_RecordGetString(row
, 6);
3789 deformat_string(package
, arguments
, &deformated
);
3790 IShellLinkW_SetArguments(sl
,deformated
);
3791 msi_free(deformated
);
3794 if (!MSI_RecordIsNull(row
,7))
3796 LPCWSTR description
= MSI_RecordGetString(row
, 7);
3797 IShellLinkW_SetDescription(sl
, description
);
3800 if (!MSI_RecordIsNull(row
,8))
3801 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
3803 if (!MSI_RecordIsNull(row
,9))
3806 LPCWSTR icon
= MSI_RecordGetString(row
, 9);
3808 path
= msi_build_icon_path(package
, icon
);
3809 index
= MSI_RecordGetInteger(row
,10);
3811 /* no value means 0 */
3812 if (index
== MSI_NULL_INTEGER
)
3815 IShellLinkW_SetIconLocation(sl
, path
, index
);
3819 if (!MSI_RecordIsNull(row
,11))
3820 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
3822 if (!MSI_RecordIsNull(row
,12))
3824 LPCWSTR full_path
, wkdir
= MSI_RecordGetString( row
, 12 );
3825 full_path
= msi_get_target_folder( package
, wkdir
);
3826 if (full_path
) IShellLinkW_SetWorkingDirectory( sl
, full_path
);
3829 link_file
= get_link_file(package
, row
);
3830 TRACE("Writing shortcut to %s\n", debugstr_w(link_file
));
3832 msi_disable_fs_redirection( package
);
3833 IPersistFile_Save(pf
, link_file
, FALSE
);
3834 msi_revert_fs_redirection( package
);
3836 msi_free(link_file
);
3840 IPersistFile_Release( pf
);
3842 IShellLinkW_Release( sl
);
3844 return ERROR_SUCCESS
;
3847 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
3853 if (package
->script
== SCRIPT_NONE
)
3854 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"CreateShortcuts");
3856 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `Shortcut`", &view
);
3857 if (rc
!= ERROR_SUCCESS
)
3858 return ERROR_SUCCESS
;
3860 res
= CoInitialize( NULL
);
3862 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_CreateShortcuts
, package
);
3863 msiobj_release(&view
->hdr
);
3865 if (SUCCEEDED(res
)) CoUninitialize();
3869 static UINT
ITERATE_RemoveShortcuts( MSIRECORD
*row
, LPVOID param
)
3871 MSIPACKAGE
*package
= param
;
3876 component
= MSI_RecordGetString( row
, 4 );
3877 comp
= msi_get_loaded_component( package
, component
);
3879 return ERROR_SUCCESS
;
3881 comp
->Action
= msi_get_component_action( package
, comp
);
3882 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
3884 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
3885 return ERROR_SUCCESS
;
3887 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
3889 link_file
= get_link_file( package
, row
);
3890 TRACE("Removing shortcut file %s\n", debugstr_w( link_file
));
3891 if (!msi_delete_file( package
, link_file
)) WARN( "failed to remove shortcut file %lu\n", GetLastError() );
3892 msi_free( link_file
);
3894 return ERROR_SUCCESS
;
3897 static UINT
ACTION_RemoveShortcuts( MSIPACKAGE
*package
)
3902 if (package
->script
== SCRIPT_NONE
)
3903 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RemoveShortcuts");
3905 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Shortcut`", &view
);
3906 if (rc
!= ERROR_SUCCESS
)
3907 return ERROR_SUCCESS
;
3909 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveShortcuts
, package
);
3910 msiobj_release( &view
->hdr
);
3914 static UINT
ITERATE_PublishIcon(MSIRECORD
*row
, LPVOID param
)
3916 MSIPACKAGE
*package
= param
;
3919 const WCHAR
*filename
;
3924 filename
= MSI_RecordGetString( row
, 1 );
3927 ERR("Unable to get filename\n");
3928 return ERROR_SUCCESS
;
3931 icon_path
= msi_build_icon_path( package
, filename
);
3933 TRACE("Creating icon file at %s\n", debugstr_w(icon_path
));
3935 handle
= msi_create_file( package
, icon_path
, GENERIC_WRITE
, 0, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
);
3936 if (handle
== INVALID_HANDLE_VALUE
)
3938 ERR("Unable to create file %s\n", debugstr_w(icon_path
));
3939 msi_free( icon_path
);
3940 return ERROR_SUCCESS
;
3947 rc
= MSI_RecordReadStream( row
, 2, buffer
, &sz
);
3948 if (rc
!= ERROR_SUCCESS
)
3950 ERR("Failed to get stream\n");
3951 msi_delete_file( package
, icon_path
);
3954 WriteFile( handle
, buffer
, sz
, &count
, NULL
);
3955 } while (sz
== 1024);
3957 msi_free( icon_path
);
3958 CloseHandle( handle
);
3960 return ERROR_SUCCESS
;
3963 static UINT
msi_publish_icons(MSIPACKAGE
*package
)
3968 r
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `Icon`", &view
);
3969 if (r
== ERROR_SUCCESS
)
3971 r
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishIcon
, package
);
3972 msiobj_release(&view
->hdr
);
3973 if (r
!= ERROR_SUCCESS
)
3976 return ERROR_SUCCESS
;
3979 static UINT
msi_publish_sourcelist(MSIPACKAGE
*package
, HKEY hkey
)
3985 MSISOURCELISTINFO
*info
;
3987 r
= RegCreateKeyW(hkey
, L
"SourceList", &source
);
3988 if (r
!= ERROR_SUCCESS
)
3991 RegCloseKey(source
);
3993 buffer
= wcsrchr(package
->PackagePath
, '\\') + 1;
3994 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
3995 package
->Context
, MSICODE_PRODUCT
,
3996 INSTALLPROPERTY_PACKAGENAMEW
, buffer
);
3997 if (r
!= ERROR_SUCCESS
)
4000 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4001 package
->Context
, MSICODE_PRODUCT
,
4002 INSTALLPROPERTY_MEDIAPACKAGEPATHW
, L
"");
4003 if (r
!= ERROR_SUCCESS
)
4006 r
= MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4007 package
->Context
, MSICODE_PRODUCT
,
4008 INSTALLPROPERTY_DISKPROMPTW
, L
"");
4009 if (r
!= ERROR_SUCCESS
)
4012 LIST_FOR_EACH_ENTRY(info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
4014 if (!wcscmp( info
->property
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
4015 msi_set_last_used_source(package
->ProductCode
, NULL
, info
->context
,
4016 info
->options
, info
->value
);
4018 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
4019 info
->context
, info
->options
,
4020 info
->property
, info
->value
);
4023 LIST_FOR_EACH_ENTRY(disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
4025 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
4026 disk
->context
, disk
->options
,
4027 disk
->disk_id
, disk
->volume_label
, disk
->disk_prompt
);
4030 return ERROR_SUCCESS
;
4033 static UINT
msi_publish_product_properties(MSIPACKAGE
*package
, HKEY hkey
)
4035 WCHAR
*buffer
, *ptr
, *guids
, packcode
[SQUASHED_GUID_SIZE
];
4038 buffer
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
4039 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTNAMEW
, buffer
);
4042 langid
= msi_get_property_int(package
->db
, L
"ProductLanguage", 0);
4043 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
4046 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
, 0);
4048 buffer
= msi_dup_property(package
->db
, L
"ARPPRODUCTICON");
4051 LPWSTR path
= msi_build_icon_path(package
, buffer
);
4052 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PRODUCTICONW
, path
);
4057 buffer
= msi_dup_property(package
->db
, L
"ProductVersion");
4060 DWORD verdword
= msi_version_str_to_dword(buffer
);
4061 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
4065 msi_reg_set_val_dword(hkey
, L
"Assignment", 0);
4066 msi_reg_set_val_dword(hkey
, L
"AdvertiseFlags", 0x184);
4067 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_INSTANCETYPEW
, 0);
4068 msi_reg_set_val_multi_str(hkey
, L
"Clients", L
":\0");
4070 if (!(guids
= msi_get_package_code(package
->db
))) return ERROR_OUTOFMEMORY
;
4071 if ((ptr
= wcschr(guids
, ';'))) *ptr
= 0;
4072 squash_guid(guids
, packcode
);
4074 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_PACKAGECODEW
, packcode
);
4076 return ERROR_SUCCESS
;
4079 static UINT
msi_publish_upgrade_code(MSIPACKAGE
*package
)
4083 WCHAR
*upgrade
, squashed_pc
[SQUASHED_GUID_SIZE
];
4085 upgrade
= msi_dup_property(package
->db
, L
"UpgradeCode");
4087 return ERROR_SUCCESS
;
4089 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
4090 r
= MSIREG_OpenClassesUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
4092 r
= MSIREG_OpenUserUpgradeCodesKey(upgrade
, &hkey
, TRUE
);
4094 if (r
!= ERROR_SUCCESS
)
4096 WARN("failed to open upgrade code key\n");
4098 return ERROR_SUCCESS
;
4100 squash_guid(package
->ProductCode
, squashed_pc
);
4101 msi_reg_set_val_str(hkey
, squashed_pc
, NULL
);
4104 return ERROR_SUCCESS
;
4107 static BOOL
msi_check_publish(MSIPACKAGE
*package
)
4109 MSIFEATURE
*feature
;
4111 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4113 feature
->Action
= msi_get_feature_action( package
, feature
);
4114 if (feature
->Action
== INSTALLSTATE_LOCAL
|| feature
->Action
== INSTALLSTATE_SOURCE
)
4121 static BOOL
msi_check_unpublish(MSIPACKAGE
*package
)
4123 MSIFEATURE
*feature
;
4125 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4127 feature
->Action
= msi_get_feature_action( package
, feature
);
4128 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
4135 static UINT
msi_publish_patches( MSIPACKAGE
*package
)
4137 WCHAR patch_squashed
[GUID_SIZE
];
4138 HKEY patches_key
= NULL
, product_patches_key
= NULL
, product_key
;
4140 MSIPATCHINFO
*patch
;
4142 WCHAR
*p
, *all_patches
= NULL
;
4145 r
= MSIREG_OpenProductKey( package
->ProductCode
, NULL
, package
->Context
, &product_key
, TRUE
);
4146 if (r
!= ERROR_SUCCESS
)
4147 return ERROR_FUNCTION_FAILED
;
4149 res
= RegCreateKeyExW( product_key
, L
"Patches", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &patches_key
, NULL
);
4150 if (res
!= ERROR_SUCCESS
)
4152 r
= ERROR_FUNCTION_FAILED
;
4156 r
= MSIREG_OpenUserDataProductPatchesKey( package
->ProductCode
, package
->Context
, &product_patches_key
, TRUE
);
4157 if (r
!= ERROR_SUCCESS
)
4160 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
4162 squash_guid( patch
->patchcode
, patch_squashed
);
4163 len
+= lstrlenW( patch_squashed
) + 1;
4166 p
= all_patches
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) );
4170 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
4174 squash_guid( patch
->patchcode
, p
);
4175 p
+= lstrlenW( p
) + 1;
4177 res
= RegSetValueExW( patches_key
, patch_squashed
, 0, REG_SZ
,
4178 (const BYTE
*)patch
->transforms
,
4179 (lstrlenW(patch
->transforms
) + 1) * sizeof(WCHAR
) );
4180 if (res
!= ERROR_SUCCESS
)
4183 r
= MSIREG_OpenUserDataPatchKey( patch
->patchcode
, package
->Context
, &patch_key
, TRUE
);
4184 if (r
!= ERROR_SUCCESS
)
4187 res
= RegSetValueExW( patch_key
, L
"LocalPackage", 0, REG_SZ
, (const BYTE
*)patch
->localfile
,
4188 (lstrlenW( patch
->localfile
) + 1) * sizeof(WCHAR
) );
4189 RegCloseKey( patch_key
);
4190 if (res
!= ERROR_SUCCESS
)
4193 if (patch
->filename
&& !CopyFileW( patch
->filename
, patch
->localfile
, FALSE
))
4195 res
= GetLastError();
4196 ERR( "unable to copy patch package %lu\n", res
);
4199 res
= RegCreateKeyExW( product_patches_key
, patch_squashed
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &patch_key
, NULL
);
4200 if (res
!= ERROR_SUCCESS
)
4203 res
= RegSetValueExW( patch_key
, L
"State", 0, REG_DWORD
, (const BYTE
*)&patch
->state
,
4204 sizeof(patch
->state
) );
4205 if (res
!= ERROR_SUCCESS
)
4207 RegCloseKey( patch_key
);
4211 res
= RegSetValueExW( patch_key
, L
"Uninstallable", 0, REG_DWORD
, (const BYTE
*)&patch
->uninstallable
,
4212 sizeof(patch
->uninstallable
) );
4213 RegCloseKey( patch_key
);
4214 if (res
!= ERROR_SUCCESS
)
4218 all_patches
[len
] = 0;
4219 res
= RegSetValueExW( patches_key
, L
"Patches", 0, REG_MULTI_SZ
,
4220 (const BYTE
*)all_patches
, (len
+ 1) * sizeof(WCHAR
) );
4221 if (res
!= ERROR_SUCCESS
)
4224 res
= RegSetValueExW( product_patches_key
, L
"AllPatches", 0, REG_MULTI_SZ
,
4225 (const BYTE
*)all_patches
, (len
+ 1) * sizeof(WCHAR
) );
4226 if (res
!= ERROR_SUCCESS
)
4227 r
= ERROR_FUNCTION_FAILED
;
4230 RegCloseKey( product_patches_key
);
4231 RegCloseKey( patches_key
);
4232 RegCloseKey( product_key
);
4233 msi_free( all_patches
);
4237 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
4240 HKEY hukey
= NULL
, hudkey
= NULL
;
4242 BOOL republish
= FALSE
;
4244 if (package
->script
== SCRIPT_NONE
)
4245 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"PublishProduct");
4247 if (!list_empty(&package
->patches
))
4249 rc
= msi_publish_patches(package
);
4250 if (rc
!= ERROR_SUCCESS
)
4254 rc
= MSIREG_OpenProductKey(package
->ProductCode
, NULL
, package
->Context
,
4256 if (rc
== ERROR_SUCCESS
)
4258 WCHAR
*package_code
;
4260 package_code
= msi_reg_get_val_str(hukey
, INSTALLPROPERTY_PACKAGECODEW
);
4265 guid
= msi_get_package_code(package
->db
);
4268 WCHAR packed
[SQUASHED_GUID_SIZE
];
4270 squash_guid(guid
, packed
);
4272 if (!wcscmp(packed
, package_code
))
4274 TRACE("re-publishing product - new package\n");
4278 msi_free(package_code
);
4282 /* FIXME: also need to publish if the product is in advertise mode */
4283 if (!republish
&& !msi_check_publish(package
))
4287 return ERROR_SUCCESS
;
4292 rc
= MSIREG_OpenProductKey(package
->ProductCode
, NULL
, package
->Context
,
4294 if (rc
!= ERROR_SUCCESS
)
4298 rc
= MSIREG_OpenUserDataProductKey(package
->ProductCode
, package
->Context
,
4299 NULL
, &hudkey
, TRUE
);
4300 if (rc
!= ERROR_SUCCESS
)
4303 rc
= msi_publish_upgrade_code(package
);
4304 if (rc
!= ERROR_SUCCESS
)
4307 rc
= msi_publish_product_properties(package
, hukey
);
4308 if (rc
!= ERROR_SUCCESS
)
4311 rc
= msi_publish_sourcelist(package
, hukey
);
4312 if (rc
!= ERROR_SUCCESS
)
4315 rc
= msi_publish_icons(package
);
4318 uirow
= MSI_CreateRecord( 1 );
4319 MSI_RecordSetStringW( uirow
, 1, package
->ProductCode
);
4320 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4321 msiobj_release( &uirow
->hdr
);
4324 RegCloseKey(hudkey
);
4328 static WCHAR
*get_ini_file_name( MSIPACKAGE
*package
, MSIRECORD
*row
)
4330 WCHAR
*filename
, *ptr
, *folder
, *ret
;
4331 const WCHAR
*dirprop
;
4333 filename
= msi_dup_record_field( row
, 2 );
4334 if (filename
&& (ptr
= wcschr( filename
, '|' )))
4339 dirprop
= MSI_RecordGetString( row
, 3 );
4342 folder
= strdupW( msi_get_target_folder( package
, dirprop
) );
4343 if (!folder
) folder
= msi_dup_property( package
->db
, dirprop
);
4346 folder
= msi_dup_property( package
->db
, L
"WindowsFolder" );
4350 ERR("Unable to resolve folder %s\n", debugstr_w(dirprop
));
4351 msi_free( filename
);
4355 ret
= msi_build_directory_name( 2, folder
, ptr
);
4357 msi_free( filename
);
4362 static UINT
ITERATE_WriteIniValues(MSIRECORD
*row
, LPVOID param
)
4364 MSIPACKAGE
*package
= param
;
4365 LPCWSTR component
, section
, key
, value
, identifier
;
4366 LPWSTR deformated_section
, deformated_key
, deformated_value
, fullname
;
4371 component
= MSI_RecordGetString(row
, 8);
4372 comp
= msi_get_loaded_component(package
,component
);
4374 return ERROR_SUCCESS
;
4376 comp
->Action
= msi_get_component_action( package
, comp
);
4377 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
4379 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
4380 return ERROR_SUCCESS
;
4383 identifier
= MSI_RecordGetString(row
,1);
4384 section
= MSI_RecordGetString(row
,4);
4385 key
= MSI_RecordGetString(row
,5);
4386 value
= MSI_RecordGetString(row
,6);
4387 action
= MSI_RecordGetInteger(row
,7);
4389 deformat_string(package
,section
,&deformated_section
);
4390 deformat_string(package
,key
,&deformated_key
);
4391 deformat_string(package
,value
,&deformated_value
);
4393 fullname
= get_ini_file_name(package
, row
);
4397 TRACE("Adding value %s to section %s in %s\n",
4398 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
4399 debugstr_w(fullname
));
4400 WritePrivateProfileStringW(deformated_section
, deformated_key
,
4401 deformated_value
, fullname
);
4403 else if (action
== 1)
4406 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
4407 returned
, 10, fullname
);
4408 if (returned
[0] == 0)
4410 TRACE("Adding value %s to section %s in %s\n",
4411 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
4412 debugstr_w(fullname
));
4414 WritePrivateProfileStringW(deformated_section
, deformated_key
,
4415 deformated_value
, fullname
);
4418 else if (action
== 3)
4419 FIXME("Append to existing section not yet implemented\n");
4421 uirow
= MSI_CreateRecord(4);
4422 MSI_RecordSetStringW(uirow
,1,identifier
);
4423 MSI_RecordSetStringW(uirow
,2,deformated_section
);
4424 MSI_RecordSetStringW(uirow
,3,deformated_key
);
4425 MSI_RecordSetStringW(uirow
,4,deformated_value
);
4426 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4427 msiobj_release( &uirow
->hdr
);
4430 msi_free(deformated_key
);
4431 msi_free(deformated_value
);
4432 msi_free(deformated_section
);
4433 return ERROR_SUCCESS
;
4436 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
4441 if (package
->script
== SCRIPT_NONE
)
4442 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"WriteIniValues");
4444 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `IniFile`", &view
);
4445 if (rc
!= ERROR_SUCCESS
)
4446 return ERROR_SUCCESS
;
4448 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteIniValues
, package
);
4449 msiobj_release(&view
->hdr
);
4453 static UINT
ITERATE_RemoveIniValuesOnUninstall( MSIRECORD
*row
, LPVOID param
)
4455 MSIPACKAGE
*package
= param
;
4456 LPCWSTR component
, section
, key
, value
, identifier
;
4457 LPWSTR deformated_section
, deformated_key
, deformated_value
, filename
;
4462 component
= MSI_RecordGetString( row
, 8 );
4463 comp
= msi_get_loaded_component( package
, component
);
4465 return ERROR_SUCCESS
;
4467 comp
->Action
= msi_get_component_action( package
, comp
);
4468 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
4470 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
4471 return ERROR_SUCCESS
;
4474 identifier
= MSI_RecordGetString( row
, 1 );
4475 section
= MSI_RecordGetString( row
, 4 );
4476 key
= MSI_RecordGetString( row
, 5 );
4477 value
= MSI_RecordGetString( row
, 6 );
4478 action
= MSI_RecordGetInteger( row
, 7 );
4480 deformat_string( package
, section
, &deformated_section
);
4481 deformat_string( package
, key
, &deformated_key
);
4482 deformat_string( package
, value
, &deformated_value
);
4484 if (action
== msidbIniFileActionAddLine
|| action
== msidbIniFileActionCreateLine
)
4486 filename
= get_ini_file_name( package
, row
);
4488 TRACE("Removing key %s from section %s in %s\n",
4489 debugstr_w(deformated_key
), debugstr_w(deformated_section
), debugstr_w(filename
));
4491 if (!WritePrivateProfileStringW( deformated_section
, deformated_key
, NULL
, filename
))
4493 WARN( "unable to remove key %lu\n", GetLastError() );
4495 msi_free( filename
);
4498 FIXME("Unsupported action %d\n", action
);
4501 uirow
= MSI_CreateRecord( 4 );
4502 MSI_RecordSetStringW( uirow
, 1, identifier
);
4503 MSI_RecordSetStringW( uirow
, 2, deformated_section
);
4504 MSI_RecordSetStringW( uirow
, 3, deformated_key
);
4505 MSI_RecordSetStringW( uirow
, 4, deformated_value
);
4506 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4507 msiobj_release( &uirow
->hdr
);
4509 msi_free( deformated_key
);
4510 msi_free( deformated_value
);
4511 msi_free( deformated_section
);
4512 return ERROR_SUCCESS
;
4515 static UINT
ITERATE_RemoveIniValuesOnInstall( MSIRECORD
*row
, LPVOID param
)
4517 MSIPACKAGE
*package
= param
;
4518 LPCWSTR component
, section
, key
, value
, identifier
;
4519 LPWSTR deformated_section
, deformated_key
, deformated_value
, filename
;
4524 component
= MSI_RecordGetString( row
, 8 );
4525 comp
= msi_get_loaded_component( package
, component
);
4527 return ERROR_SUCCESS
;
4529 comp
->Action
= msi_get_component_action( package
, comp
);
4530 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
4532 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
4533 return ERROR_SUCCESS
;
4536 identifier
= MSI_RecordGetString( row
, 1 );
4537 section
= MSI_RecordGetString( row
, 4 );
4538 key
= MSI_RecordGetString( row
, 5 );
4539 value
= MSI_RecordGetString( row
, 6 );
4540 action
= MSI_RecordGetInteger( row
, 7 );
4542 deformat_string( package
, section
, &deformated_section
);
4543 deformat_string( package
, key
, &deformated_key
);
4544 deformat_string( package
, value
, &deformated_value
);
4546 if (action
== msidbIniFileActionRemoveLine
)
4548 filename
= get_ini_file_name( package
, row
);
4550 TRACE("Removing key %s from section %s in %s\n",
4551 debugstr_w(deformated_key
), debugstr_w(deformated_section
), debugstr_w(filename
));
4553 if (!WritePrivateProfileStringW( deformated_section
, deformated_key
, NULL
, filename
))
4555 WARN( "unable to remove key %lu\n", GetLastError() );
4557 msi_free( filename
);
4560 FIXME("Unsupported action %d\n", action
);
4562 uirow
= MSI_CreateRecord( 4 );
4563 MSI_RecordSetStringW( uirow
, 1, identifier
);
4564 MSI_RecordSetStringW( uirow
, 2, deformated_section
);
4565 MSI_RecordSetStringW( uirow
, 3, deformated_key
);
4566 MSI_RecordSetStringW( uirow
, 4, deformated_value
);
4567 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4568 msiobj_release( &uirow
->hdr
);
4570 msi_free( deformated_key
);
4571 msi_free( deformated_value
);
4572 msi_free( deformated_section
);
4573 return ERROR_SUCCESS
;
4576 static UINT
ACTION_RemoveIniValues( MSIPACKAGE
*package
)
4581 if (package
->script
== SCRIPT_NONE
)
4582 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RemoveIniValues");
4584 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `IniFile`", &view
);
4585 if (rc
== ERROR_SUCCESS
)
4587 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveIniValuesOnUninstall
, package
);
4588 msiobj_release( &view
->hdr
);
4589 if (rc
!= ERROR_SUCCESS
)
4592 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `RemoveIniFile`", &view
);
4593 if (rc
== ERROR_SUCCESS
)
4595 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveIniValuesOnInstall
, package
);
4596 msiobj_release( &view
->hdr
);
4597 if (rc
!= ERROR_SUCCESS
)
4600 return ERROR_SUCCESS
;
4603 static void register_dll( const WCHAR
*dll
, BOOL unregister
)
4606 static const WCHAR regW
[] = L
"regsvr32.exe /s \"%s\"";
4607 static const WCHAR unregW
[] = L
"regsvr32.exe /s /u \"%s\"";
4608 #else /* __REACTOS__ */
4609 static const WCHAR regW
[] = L
"regsvr32.exe \"%s\"";
4610 static const WCHAR unregW
[] = L
"regsvr32.exe /u \"%s\"";
4611 #endif /* __REACTOS__ */
4612 PROCESS_INFORMATION pi
;
4616 if (!(cmd
= msi_alloc( lstrlenW(dll
) * sizeof(WCHAR
) + sizeof(unregW
) ))) return;
4618 if (unregister
) swprintf( cmd
, lstrlenW(dll
) + ARRAY_SIZE(unregW
), unregW
, dll
);
4619 else swprintf( cmd
, lstrlenW(dll
) + ARRAY_SIZE(unregW
), regW
, dll
);
4621 memset( &si
, 0, sizeof(STARTUPINFOW
) );
4622 if (CreateProcessW( NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
4624 CloseHandle( pi
.hThread
);
4625 msi_dialog_check_messages( pi
.hProcess
);
4626 CloseHandle( pi
.hProcess
);
4631 static UINT
ITERATE_SelfRegModules(MSIRECORD
*row
, LPVOID param
)
4633 MSIPACKAGE
*package
= param
;
4638 filename
= MSI_RecordGetString( row
, 1 );
4639 file
= msi_get_loaded_file( package
, filename
);
4642 WARN("unable to find file %s\n", debugstr_w(filename
));
4643 return ERROR_SUCCESS
;
4645 file
->Component
->Action
= msi_get_component_action( package
, file
->Component
);
4646 if (file
->Component
->Action
!= INSTALLSTATE_LOCAL
)
4648 TRACE("component not scheduled for installation %s\n", debugstr_w(file
->Component
->Component
));
4649 return ERROR_SUCCESS
;
4652 TRACE("Registering %s\n", debugstr_w( file
->TargetPath
));
4653 register_dll( file
->TargetPath
, FALSE
);
4655 uirow
= MSI_CreateRecord( 2 );
4656 MSI_RecordSetStringW( uirow
, 1, file
->File
);
4657 MSI_RecordSetStringW( uirow
, 2, file
->Component
->Directory
);
4658 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4659 msiobj_release( &uirow
->hdr
);
4661 return ERROR_SUCCESS
;
4664 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
4669 if (package
->script
== SCRIPT_NONE
)
4670 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"SelfRegModules");
4672 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `SelfReg`", &view
);
4673 if (rc
!= ERROR_SUCCESS
)
4674 return ERROR_SUCCESS
;
4676 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_SelfRegModules
, package
);
4677 msiobj_release(&view
->hdr
);
4681 static UINT
ITERATE_SelfUnregModules( MSIRECORD
*row
, LPVOID param
)
4683 MSIPACKAGE
*package
= param
;
4688 filename
= MSI_RecordGetString( row
, 1 );
4689 file
= msi_get_loaded_file( package
, filename
);
4692 WARN("unable to find file %s\n", debugstr_w(filename
));
4693 return ERROR_SUCCESS
;
4695 file
->Component
->Action
= msi_get_component_action( package
, file
->Component
);
4696 if (file
->Component
->Action
!= INSTALLSTATE_ABSENT
)
4698 TRACE("component not scheduled for removal %s\n", debugstr_w(file
->Component
->Component
));
4699 return ERROR_SUCCESS
;
4702 TRACE("Unregistering %s\n", debugstr_w( file
->TargetPath
));
4703 register_dll( file
->TargetPath
, TRUE
);
4705 uirow
= MSI_CreateRecord( 2 );
4706 MSI_RecordSetStringW( uirow
, 1, file
->File
);
4707 MSI_RecordSetStringW( uirow
, 2, file
->Component
->Directory
);
4708 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4709 msiobj_release( &uirow
->hdr
);
4711 return ERROR_SUCCESS
;
4714 static UINT
ACTION_SelfUnregModules( MSIPACKAGE
*package
)
4719 if (package
->script
== SCRIPT_NONE
)
4720 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"SelfUnregModules");
4722 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `SelfReg`", &view
);
4723 if (rc
!= ERROR_SUCCESS
)
4724 return ERROR_SUCCESS
;
4726 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_SelfUnregModules
, package
);
4727 msiobj_release( &view
->hdr
);
4731 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
4733 MSIFEATURE
*feature
;
4735 HKEY hkey
= NULL
, userdata
= NULL
;
4737 if (package
->script
== SCRIPT_NONE
)
4738 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"PublishFeatures");
4740 if (!msi_check_publish(package
))
4741 return ERROR_SUCCESS
;
4743 rc
= MSIREG_OpenFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4745 if (rc
!= ERROR_SUCCESS
)
4748 rc
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4750 if (rc
!= ERROR_SUCCESS
)
4753 /* here the guids are base 85 encoded */
4754 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
4760 BOOL absent
= FALSE
;
4763 if (feature
->Level
<= 0) continue;
4764 if (feature
->Action
== INSTALLSTATE_UNKNOWN
&&
4765 feature
->Installed
!= INSTALLSTATE_ABSENT
) continue;
4767 if (feature
->Action
!= INSTALLSTATE_LOCAL
&&
4768 feature
->Action
!= INSTALLSTATE_SOURCE
&&
4769 feature
->Action
!= INSTALLSTATE_ADVERTISED
) absent
= TRUE
;
4772 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4776 if (feature
->Feature_Parent
)
4777 size
+= lstrlenW( feature
->Feature_Parent
)+2;
4779 data
= msi_alloc(size
* sizeof(WCHAR
));
4782 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
4784 MSICOMPONENT
* component
= cl
->component
;
4788 if (component
->ComponentId
)
4790 TRACE("From %s\n",debugstr_w(component
->ComponentId
));
4791 CLSIDFromString(component
->ComponentId
, &clsid
);
4792 encode_base85_guid(&clsid
,buf
);
4793 TRACE("to %s\n",debugstr_w(buf
));
4798 if (feature
->Feature_Parent
)
4800 lstrcatW(data
, L
"\2");
4801 lstrcatW(data
, feature
->Feature_Parent
);
4804 msi_reg_set_val_str( userdata
, feature
->Feature
, data
);
4808 if (feature
->Feature_Parent
)
4809 size
= lstrlenW(feature
->Feature_Parent
)*sizeof(WCHAR
);
4812 size
+= sizeof(WCHAR
);
4813 RegSetValueExW(hkey
, feature
->Feature
, 0 ,REG_SZ
,
4814 (const BYTE
*)(feature
->Feature_Parent
? feature
->Feature_Parent
: L
""), size
);
4818 size
+= 2*sizeof(WCHAR
);
4819 data
= msi_alloc(size
);
4822 if (feature
->Feature_Parent
)
4823 lstrcpyW( &data
[1], feature
->Feature_Parent
);
4824 RegSetValueExW(hkey
,feature
->Feature
,0,REG_SZ
,
4830 uirow
= MSI_CreateRecord( 1 );
4831 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
4832 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4833 msiobj_release( &uirow
->hdr
);
4834 /* FIXME: call msi_ui_progress? */
4839 RegCloseKey(userdata
);
4843 static UINT
msi_unpublish_feature(MSIPACKAGE
*package
, MSIFEATURE
*feature
)
4849 TRACE("unpublishing feature %s\n", debugstr_w(feature
->Feature
));
4851 r
= MSIREG_OpenFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4853 if (r
== ERROR_SUCCESS
)
4855 RegDeleteValueW(hkey
, feature
->Feature
);
4859 r
= MSIREG_OpenUserDataFeaturesKey(package
->ProductCode
, NULL
, package
->Context
,
4861 if (r
== ERROR_SUCCESS
)
4863 RegDeleteValueW(hkey
, feature
->Feature
);
4867 uirow
= MSI_CreateRecord( 1 );
4868 MSI_RecordSetStringW( uirow
, 1, feature
->Feature
);
4869 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
4870 msiobj_release( &uirow
->hdr
);
4872 return ERROR_SUCCESS
;
4875 static UINT
ACTION_UnpublishFeatures(MSIPACKAGE
*package
)
4877 MSIFEATURE
*feature
;
4879 if (package
->script
== SCRIPT_NONE
)
4880 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"UnpublishFeatures");
4882 if (!msi_check_unpublish(package
))
4883 return ERROR_SUCCESS
;
4885 LIST_FOR_EACH_ENTRY(feature
, &package
->features
, MSIFEATURE
, entry
)
4887 msi_unpublish_feature(package
, feature
);
4890 return ERROR_SUCCESS
;
4893 static UINT
msi_publish_install_properties(MSIPACKAGE
*package
, HKEY hkey
)
4895 static const WCHAR
*propval
[] =
4897 L
"ARPAUTHORIZEDCDFPREFIX", L
"AuthorizedCDFPrefix",
4898 L
"ARPCONTACT", L
"Contact",
4899 L
"ARPCOMMENTS", L
"Comments",
4900 L
"ProductName", L
"DisplayName",
4901 L
"ARPHELPLINK", L
"HelpLink",
4902 L
"ARPHELPTELEPHONE", L
"HelpTelephone",
4903 L
"ARPINSTALLLOCATION", L
"InstallLocation",
4904 L
"SourceDir", L
"InstallSource",
4905 L
"Manufacturer", L
"Publisher",
4906 L
"ARPREADME", L
"ReadMe",
4907 L
"ARPSIZE", L
"Size",
4908 L
"ARPURLINFOABOUT", L
"URLInfoAbout",
4909 L
"ARPURLUPDATEINFO", L
"URLUpdateInfo",
4912 const WCHAR
**p
= propval
;
4915 WCHAR date
[9], *val
, *buffer
;
4916 const WCHAR
*prop
, *key
;
4922 val
= msi_dup_property(package
->db
, prop
);
4923 msi_reg_set_val_str(hkey
, key
, val
);
4927 msi_reg_set_val_dword(hkey
, L
"WindowsInstaller", 1);
4928 if (msi_get_property_int( package
->db
, L
"ARPSYSTEMCOMPONENT", 0 ))
4930 msi_reg_set_val_dword( hkey
, L
"SystemComponent", 1 );
4933 if (msi_get_property_int( package
->db
, L
"ARPNOREMOVE", 0 ))
4934 msi_reg_set_val_dword( hkey
, L
"NoRemove", 1 );
4937 static const WCHAR fmt_install
[] = L
"MsiExec.exe /I[ProductCode]";
4938 static const WCHAR fmt_uninstall
[] = L
"MsiExec.exe /X[ProductCode]";
4939 const WCHAR
*fmt
= fmt_install
;
4941 if (msi_get_property_int( package
->db
, L
"ARPNOREPAIR", 0 ))
4942 msi_reg_set_val_dword( hkey
, L
"NoRepair", 1 );
4944 if (msi_get_property_int( package
->db
, L
"ARPNOMODIFY", 0 ))
4946 msi_reg_set_val_dword( hkey
, L
"NoModify", 1 );
4947 fmt
= fmt_uninstall
;
4950 size
= deformat_string(package
, fmt
, &buffer
) * sizeof(WCHAR
);
4951 RegSetValueExW(hkey
, L
"ModifyPath", 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
4952 RegSetValueExW(hkey
, L
"UninstallString", 0, REG_EXPAND_SZ
, (LPBYTE
)buffer
, size
);
4956 /* FIXME: Write real Estimated Size when we have it */
4957 msi_reg_set_val_dword(hkey
, L
"EstimatedSize", 0);
4959 GetLocalTime(&systime
);
4960 swprintf(date
, ARRAY_SIZE(date
), L
"%d%02d%02d", systime
.wYear
, systime
.wMonth
, systime
.wDay
);
4961 msi_reg_set_val_str(hkey
, INSTALLPROPERTY_INSTALLDATEW
, date
);
4963 langid
= msi_get_property_int(package
->db
, L
"ProductLanguage", 0);
4964 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_LANGUAGEW
, langid
);
4966 buffer
= msi_dup_property(package
->db
, L
"ProductVersion");
4967 msi_reg_set_val_str(hkey
, L
"DisplayVersion", buffer
);
4970 DWORD verdword
= msi_version_str_to_dword(buffer
);
4972 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONW
, verdword
);
4973 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMAJORW
, verdword
>> 24);
4974 msi_reg_set_val_dword(hkey
, INSTALLPROPERTY_VERSIONMINORW
, (verdword
>> 16) & 0xFF);
4978 return ERROR_SUCCESS
;
4981 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
4983 WCHAR
*upgrade_code
, squashed_pc
[SQUASHED_GUID_SIZE
];
4985 HKEY hkey
, props
, upgrade_key
;
4988 if (package
->script
== SCRIPT_NONE
)
4989 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RegisterProduct");
4991 /* FIXME: also need to publish if the product is in advertise mode */
4992 if (!msi_get_property_int( package
->db
, L
"ProductToBeRegistered", 0 )
4993 && !msi_check_publish(package
))
4994 return ERROR_SUCCESS
;
4996 rc
= MSIREG_OpenUninstallKey(package
->ProductCode
, package
->platform
, &hkey
, TRUE
);
4997 if (rc
!= ERROR_SUCCESS
)
5000 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
, NULL
, &props
, TRUE
);
5001 if (rc
!= ERROR_SUCCESS
)
5004 rc
= msi_publish_install_properties(package
, hkey
);
5005 if (rc
!= ERROR_SUCCESS
)
5008 rc
= msi_publish_install_properties(package
, props
);
5009 if (rc
!= ERROR_SUCCESS
)
5012 upgrade_code
= msi_dup_property(package
->db
, L
"UpgradeCode");
5015 rc
= MSIREG_OpenUpgradeCodesKey( upgrade_code
, &upgrade_key
, TRUE
);
5016 if (rc
== ERROR_SUCCESS
)
5018 squash_guid( package
->ProductCode
, squashed_pc
);
5019 msi_reg_set_val_str( upgrade_key
, squashed_pc
, NULL
);
5020 RegCloseKey( upgrade_key
);
5022 msi_free( upgrade_code
);
5024 msi_reg_set_val_str( props
, INSTALLPROPERTY_LOCALPACKAGEW
, package
->localfile
);
5025 package
->delete_on_close
= FALSE
;
5028 uirow
= MSI_CreateRecord( 1 );
5029 MSI_RecordSetStringW( uirow
, 1, package
->ProductCode
);
5030 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5031 msiobj_release( &uirow
->hdr
);
5034 return ERROR_SUCCESS
;
5037 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
5039 return execute_script(package
, SCRIPT_INSTALL
);
5042 static UINT
ITERATE_UnpublishIcon( MSIRECORD
*row
, LPVOID param
)
5044 MSIPACKAGE
*package
= param
;
5045 const WCHAR
*icon
= MSI_RecordGetString( row
, 1 );
5046 WCHAR
*p
, *icon_path
;
5048 if (!icon
) return ERROR_SUCCESS
;
5049 if ((icon_path
= msi_build_icon_path( package
, icon
)))
5051 TRACE("removing icon file %s\n", debugstr_w(icon_path
));
5052 msi_delete_file( package
, icon_path
);
5053 if ((p
= wcsrchr( icon_path
, '\\' )))
5056 msi_remove_directory( package
, icon_path
);
5058 msi_free( icon_path
);
5060 return ERROR_SUCCESS
;
5063 static UINT
msi_unpublish_icons( MSIPACKAGE
*package
)
5068 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Icon`", &view
);
5069 if (r
== ERROR_SUCCESS
)
5071 r
= MSI_IterateRecords( view
, NULL
, ITERATE_UnpublishIcon
, package
);
5072 msiobj_release( &view
->hdr
);
5073 if (r
!= ERROR_SUCCESS
)
5076 return ERROR_SUCCESS
;
5079 static void remove_product_upgrade_code( MSIPACKAGE
*package
)
5081 WCHAR
*code
, product
[SQUASHED_GUID_SIZE
];
5086 squash_guid( package
->ProductCode
, product
);
5087 if (!(code
= msi_dup_property( package
->db
, L
"UpgradeCode" )))
5089 WARN( "upgrade code not found\n" );
5092 if (!MSIREG_OpenUpgradeCodesKey( code
, &hkey
, FALSE
))
5094 RegDeleteValueW( hkey
, product
);
5095 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, &count
, NULL
, NULL
, NULL
, NULL
, NULL
);
5096 RegCloseKey( hkey
);
5097 if (!res
&& !count
) MSIREG_DeleteUpgradeCodesKey( code
);
5099 if (!MSIREG_OpenUserUpgradeCodesKey( code
, &hkey
, FALSE
))
5101 RegDeleteValueW( hkey
, product
);
5102 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, &count
, NULL
, NULL
, NULL
, NULL
, NULL
);
5103 RegCloseKey( hkey
);
5104 if (!res
&& !count
) MSIREG_DeleteUserUpgradeCodesKey( code
);
5106 if (!MSIREG_OpenClassesUpgradeCodesKey( code
, &hkey
, FALSE
))
5108 RegDeleteValueW( hkey
, product
);
5109 res
= RegQueryInfoKeyW( hkey
, NULL
, NULL
, NULL
, NULL
, NULL
, &count
, NULL
, NULL
, NULL
, NULL
, NULL
);
5110 RegCloseKey( hkey
);
5111 if (!res
&& !count
) MSIREG_DeleteClassesUpgradeCodesKey( code
);
5117 static UINT
ACTION_UnpublishProduct(MSIPACKAGE
*package
)
5119 MSIPATCHINFO
*patch
;
5121 MSIREG_DeleteProductKey(package
->ProductCode
);
5122 MSIREG_DeleteUserDataProductKey(package
->ProductCode
, package
->Context
);
5123 MSIREG_DeleteUninstallKey(package
->ProductCode
, package
->platform
);
5125 MSIREG_DeleteLocalClassesProductKey(package
->ProductCode
);
5126 MSIREG_DeleteLocalClassesFeaturesKey(package
->ProductCode
);
5127 MSIREG_DeleteUserProductKey(package
->ProductCode
);
5128 MSIREG_DeleteUserFeaturesKey(package
->ProductCode
);
5130 remove_product_upgrade_code( package
);
5132 LIST_FOR_EACH_ENTRY(patch
, &package
->patches
, MSIPATCHINFO
, entry
)
5134 MSIREG_DeleteUserDataPatchKey(patch
->patchcode
, package
->Context
);
5135 if (!wcscmp( package
->ProductCode
, patch
->products
))
5137 TRACE("removing local patch package %s\n", debugstr_w(patch
->localfile
));
5138 patch
->delete_on_close
= TRUE
;
5140 /* FIXME: remove local patch package if this is the last product */
5142 TRACE("removing local package %s\n", debugstr_w(package
->localfile
));
5143 package
->delete_on_close
= TRUE
;
5145 msi_unpublish_icons( package
);
5146 return ERROR_SUCCESS
;
5149 static BOOL
is_full_uninstall( MSIPACKAGE
*package
)
5151 MSIFEATURE
*feature
;
5153 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
5155 if (feature
->Action
!= INSTALLSTATE_ABSENT
&&
5156 (feature
->Installed
!= INSTALLSTATE_ABSENT
|| feature
->Action
!= INSTALLSTATE_UNKNOWN
))
5163 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
5167 /* first do the same as an InstallExecute */
5168 rc
= execute_script(package
, SCRIPT_INSTALL
);
5169 if (rc
!= ERROR_SUCCESS
)
5172 /* then handle commit actions */
5173 rc
= execute_script(package
, SCRIPT_COMMIT
);
5174 if (rc
!= ERROR_SUCCESS
)
5177 if (is_full_uninstall(package
))
5178 rc
= ACTION_UnpublishProduct(package
);
5183 UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
5185 WCHAR buffer
[256], sysdir
[MAX_PATH
], squashed_pc
[SQUASHED_GUID_SIZE
];
5188 squash_guid( package
->ProductCode
, squashed_pc
);
5190 GetSystemDirectoryW(sysdir
, ARRAY_SIZE(sysdir
));
5191 RegCreateKeyW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce", &hkey
);
5192 swprintf(buffer
, ARRAY_SIZE(buffer
), L
"%s\\MsiExec.exe /@ \"%s\"", sysdir
, squashed_pc
);
5194 msi_reg_set_val_str( hkey
, squashed_pc
, buffer
);
5197 TRACE("Reboot command %s\n",debugstr_w(buffer
));
5199 RegCreateKeyW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\RunOnceEntries",
5201 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"/I \"%s\" AFTERREBOOT=1 RUNONCEENTRY=\"%s\"", package
->ProductCode
,
5204 msi_reg_set_val_str( hkey
, squashed_pc
, buffer
);
5207 return ERROR_INSTALL_SUSPEND
;
5210 static UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
5216 * We are currently doing what should be done here in the top level Install
5217 * however for Administrative and uninstalls this step will be needed
5219 if (!package
->PackagePath
)
5220 return ERROR_SUCCESS
;
5222 msi_set_sourcedir_props(package
, TRUE
);
5224 attrib
= GetFileAttributesW(package
->db
->path
);
5225 if (attrib
== INVALID_FILE_ATTRIBUTES
)
5231 rc
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
5232 package
->Context
, MSICODE_PRODUCT
,
5233 INSTALLPROPERTY_DISKPROMPTW
,NULL
,&size
);
5234 if (rc
== ERROR_MORE_DATA
)
5236 prompt
= msi_alloc(size
* sizeof(WCHAR
));
5237 MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
5238 package
->Context
, MSICODE_PRODUCT
,
5239 INSTALLPROPERTY_DISKPROMPTW
,prompt
,&size
);
5242 prompt
= strdupW(package
->db
->path
);
5244 record
= MSI_CreateRecord(2);
5245 MSI_RecordSetInteger(record
, 1, MSIERR_INSERTDISK
);
5246 MSI_RecordSetStringW(record
, 2, prompt
);
5248 while(attrib
== INVALID_FILE_ATTRIBUTES
)
5250 MSI_RecordSetStringW(record
, 0, NULL
);
5251 rc
= MSI_ProcessMessage(package
, INSTALLMESSAGE_ERROR
, record
);
5253 return ERROR_INSTALL_USEREXIT
;
5254 attrib
= GetFileAttributesW(package
->db
->path
);
5259 return ERROR_SUCCESS
;
5264 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
5266 static const WCHAR szPropKeys
[][80] =
5273 static const WCHAR szRegKeys
[][80] =
5281 LPWSTR buffer
, productid
= NULL
;
5282 UINT i
, rc
= ERROR_SUCCESS
;
5285 if (package
->script
== SCRIPT_NONE
)
5286 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RegisterUser");
5288 if (msi_check_unpublish(package
))
5290 MSIREG_DeleteUserDataProductKey(package
->ProductCode
, package
->Context
);
5294 productid
= msi_dup_property( package
->db
, INSTALLPROPERTY_PRODUCTIDW
);
5298 rc
= MSIREG_OpenInstallProps(package
->ProductCode
, package
->Context
,
5300 if (rc
!= ERROR_SUCCESS
)
5303 for( i
= 0; szPropKeys
[i
][0]; i
++ )
5305 buffer
= msi_dup_property( package
->db
, szPropKeys
[i
] );
5306 msi_reg_set_val_str( hkey
, szRegKeys
[i
], buffer
);
5311 uirow
= MSI_CreateRecord( 1 );
5312 MSI_RecordSetStringW( uirow
, 1, productid
);
5313 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5314 msiobj_release( &uirow
->hdr
);
5316 msi_free(productid
);
5321 static UINT
iterate_properties(MSIRECORD
*record
, void *param
)
5325 uirow
= MSI_CloneRecord(record
);
5326 if (!uirow
) return ERROR_OUTOFMEMORY
;
5327 MSI_RecordSetStringW(uirow
, 0, L
"Property(S): [1] = [2]");
5328 MSI_ProcessMessage(param
, INSTALLMESSAGE_INFO
|MB_ICONHAND
, uirow
);
5329 msiobj_release(&uirow
->hdr
);
5331 return ERROR_SUCCESS
;
5335 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
5339 WCHAR
*info_template
;
5341 MSIRECORD
*uirow
, *uirow_info
;
5344 /* Send COMMONDATA and INFO messages. */
5345 /* FIXME: when should these messages be sent? [see also MsiOpenPackage()] */
5346 uirow
= MSI_CreateRecord(3);
5347 if (!uirow
) return ERROR_OUTOFMEMORY
;
5348 MSI_RecordSetStringW(uirow
, 0, NULL
);
5349 MSI_RecordSetInteger(uirow
, 1, 0);
5350 MSI_RecordSetInteger(uirow
, 2, package
->num_langids
? package
->langids
[0] : 0);
5351 MSI_RecordSetInteger(uirow
, 3, msi_get_string_table_codepage(package
->db
->strings
));
5352 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5353 /* FIXME: send INSTALLMESSAGE_PROGRESS */
5354 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5356 if (!(needs_ui_sequence(package
) && ui_sequence_exists(package
)))
5358 uirow_info
= MSI_CreateRecord(0);
5361 msiobj_release(&uirow
->hdr
);
5362 return ERROR_OUTOFMEMORY
;
5364 info_template
= msi_get_error_message(package
->db
, MSIERR_INFO_LOGGINGSTART
);
5365 MSI_RecordSetStringW(uirow_info
, 0, info_template
);
5366 msi_free(info_template
);
5367 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
|MB_ICONHAND
, uirow_info
);
5368 msiobj_release(&uirow_info
->hdr
);
5371 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5373 productname
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
5374 MSI_RecordSetInteger(uirow
, 1, 1);
5375 MSI_RecordSetStringW(uirow
, 2, productname
);
5376 MSI_RecordSetStringW(uirow
, 3, NULL
);
5377 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5378 msiobj_release(&uirow
->hdr
);
5380 package
->LastActionResult
= MSI_NULL_INTEGER
;
5382 action
= msi_dup_property(package
->db
, L
"EXECUTEACTION");
5383 if (!action
) action
= msi_strdupW(L
"INSTALL", ARRAY_SIZE(L
"INSTALL") - 1);
5385 /* Perform the action. Top-level actions trigger a sequence. */
5386 if (!wcscmp(action
, L
"INSTALL"))
5388 /* Send ACTIONSTART/INFO and INSTALLSTART. */
5389 ui_actionstart(package
, L
"INSTALL", NULL
, NULL
);
5390 ui_actioninfo(package
, L
"INSTALL", TRUE
, 0);
5391 uirow
= MSI_CreateRecord(2);
5394 rc
= ERROR_OUTOFMEMORY
;
5397 MSI_RecordSetStringW(uirow
, 0, NULL
);
5398 MSI_RecordSetStringW(uirow
, 1, productname
);
5399 MSI_RecordSetStringW(uirow
, 2, package
->ProductCode
);
5400 MSI_ProcessMessage(package
, INSTALLMESSAGE_INSTALLSTART
, uirow
);
5401 msiobj_release(&uirow
->hdr
);
5403 /* Perform the installation. Always use the ExecuteSequence. */
5404 package
->InWhatSequence
|= SEQUENCE_EXEC
;
5405 rc
= ACTION_ProcessExecSequence(package
);
5407 /* Send return value and INSTALLEND. */
5408 ui_actioninfo(package
, L
"INSTALL", FALSE
, !rc
);
5409 uirow
= MSI_CreateRecord(3);
5412 rc
= ERROR_OUTOFMEMORY
;
5415 MSI_RecordSetStringW(uirow
, 0, NULL
);
5416 MSI_RecordSetStringW(uirow
, 1, productname
);
5417 MSI_RecordSetStringW(uirow
, 2, package
->ProductCode
);
5418 MSI_RecordSetInteger(uirow
, 3, !rc
);
5419 MSI_ProcessMessage(package
, INSTALLMESSAGE_INSTALLEND
, uirow
);
5420 msiobj_release(&uirow
->hdr
);
5423 rc
= ACTION_PerformAction(package
, action
);
5425 /* Send all set properties. */
5426 if (!MSI_OpenQuery(package
->db
, &view
, L
"SELECT * FROM `_Property`"))
5428 MSI_IterateRecords(view
, NULL
, iterate_properties
, package
);
5429 msiobj_release(&view
->hdr
);
5432 /* And finally, toggle the cancel off and on. */
5433 uirow
= MSI_CreateRecord(2);
5436 rc
= ERROR_OUTOFMEMORY
;
5439 MSI_RecordSetStringW(uirow
, 0, NULL
);
5440 MSI_RecordSetInteger(uirow
, 1, 2);
5441 MSI_RecordSetInteger(uirow
, 2, 0);
5442 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5443 MSI_RecordSetInteger(uirow
, 2, 1);
5444 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, uirow
);
5445 msiobj_release(&uirow
->hdr
);
5448 msi_free(productname
);
5453 static UINT
ACTION_INSTALL(MSIPACKAGE
*package
)
5455 msi_set_property(package
->db
, L
"EXECUTEACTION", L
"INSTALL", -1);
5456 if (needs_ui_sequence(package
) && ui_sequence_exists(package
))
5458 package
->InWhatSequence
|= SEQUENCE_UI
;
5459 return ACTION_ProcessUISequence(package
);
5462 return ACTION_ExecuteAction(package
);
5465 WCHAR
*msi_create_component_advertise_string( MSIPACKAGE
*package
, MSICOMPONENT
*component
, const WCHAR
*feature
)
5467 WCHAR productid_85
[21], component_85
[21], *ret
;
5471 /* > is used if there is a component GUID and < if not. */
5473 productid_85
[0] = 0;
5474 component_85
[0] = 0;
5475 CLSIDFromString( package
->ProductCode
, &clsid
);
5477 encode_base85_guid( &clsid
, productid_85
);
5480 CLSIDFromString( component
->ComponentId
, &clsid
);
5481 encode_base85_guid( &clsid
, component_85
);
5484 TRACE("product=%s feature=%s component=%s\n", debugstr_w(productid_85
), debugstr_w(feature
),
5485 debugstr_w(component_85
));
5487 sz
= 20 + lstrlenW( feature
) + 20 + 3;
5488 ret
= msi_alloc_zero( sz
* sizeof(WCHAR
) );
5489 if (ret
) swprintf( ret
, sz
, L
"%s%s%c%s", productid_85
, feature
, component
? '>' : '<', component_85
);
5493 static UINT
ITERATE_PublishComponent(MSIRECORD
*rec
, LPVOID param
)
5495 MSIPACKAGE
*package
= param
;
5496 LPCWSTR compgroupid
, component
, feature
, qualifier
, text
;
5497 LPWSTR advertise
= NULL
, output
= NULL
, existing
= NULL
, p
, q
;
5506 feature
= MSI_RecordGetString(rec
, 5);
5507 feat
= msi_get_loaded_feature(package
, feature
);
5509 return ERROR_SUCCESS
;
5511 feat
->Action
= msi_get_feature_action( package
, feat
);
5512 if (feat
->Action
!= INSTALLSTATE_LOCAL
&&
5513 feat
->Action
!= INSTALLSTATE_SOURCE
&&
5514 feat
->Action
!= INSTALLSTATE_ADVERTISED
)
5516 TRACE("feature not scheduled for installation %s\n", debugstr_w(feature
));
5517 return ERROR_SUCCESS
;
5520 component
= MSI_RecordGetString(rec
, 3);
5521 comp
= msi_get_loaded_component(package
, component
);
5523 return ERROR_SUCCESS
;
5525 compgroupid
= MSI_RecordGetString(rec
,1);
5526 qualifier
= MSI_RecordGetString(rec
,2);
5528 rc
= MSIREG_OpenUserComponentsKey(compgroupid
, &hkey
, TRUE
);
5529 if (rc
!= ERROR_SUCCESS
)
5532 advertise
= msi_create_component_advertise_string( package
, comp
, feature
);
5533 text
= MSI_RecordGetString( rec
, 4 );
5536 p
= msi_alloc( (lstrlenW( advertise
) + lstrlenW( text
) + 1) * sizeof(WCHAR
) );
5537 lstrcpyW( p
, advertise
);
5538 lstrcatW( p
, text
);
5539 msi_free( advertise
);
5542 existing
= msi_reg_get_val_str( hkey
, qualifier
);
5544 sz
= lstrlenW( advertise
) + 1;
5547 for (p
= existing
; *p
; p
+= len
)
5549 len
= lstrlenW( p
) + 1;
5550 if (wcscmp( advertise
, p
)) sz
+= len
;
5553 if (!(output
= msi_alloc( (sz
+ 1) * sizeof(WCHAR
) )))
5555 rc
= ERROR_OUTOFMEMORY
;
5561 for (p
= existing
; *p
; p
+= len
)
5563 len
= lstrlenW( p
) + 1;
5564 if (wcscmp( advertise
, p
))
5566 memcpy( q
, p
, len
* sizeof(WCHAR
) );
5571 lstrcpyW( q
, advertise
);
5572 q
[lstrlenW( q
) + 1] = 0;
5574 msi_reg_set_val_multi_str( hkey
, qualifier
, output
);
5579 msi_free( advertise
);
5580 msi_free( existing
);
5583 uirow
= MSI_CreateRecord( 2 );
5584 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
5585 MSI_RecordSetStringW( uirow
, 2, qualifier
);
5586 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5587 msiobj_release( &uirow
->hdr
);
5588 /* FIXME: call ui_progress? */
5594 * At present I am ignoring the advertised components part of this and only
5595 * focusing on the qualified component sets
5597 static UINT
ACTION_PublishComponents(MSIPACKAGE
*package
)
5602 if (package
->script
== SCRIPT_NONE
)
5603 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"PublishComponents");
5605 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `PublishComponent`", &view
);
5606 if (rc
!= ERROR_SUCCESS
)
5607 return ERROR_SUCCESS
;
5609 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_PublishComponent
, package
);
5610 msiobj_release(&view
->hdr
);
5614 static UINT
ITERATE_UnpublishComponent( MSIRECORD
*rec
, LPVOID param
)
5616 MSIPACKAGE
*package
= param
;
5617 LPCWSTR compgroupid
, component
, feature
, qualifier
;
5621 WCHAR squashed
[GUID_SIZE
], keypath
[MAX_PATH
];
5624 feature
= MSI_RecordGetString( rec
, 5 );
5625 feat
= msi_get_loaded_feature( package
, feature
);
5627 return ERROR_SUCCESS
;
5629 feat
->Action
= msi_get_feature_action( package
, feat
);
5630 if (feat
->Action
!= INSTALLSTATE_ABSENT
)
5632 TRACE("feature not scheduled for removal %s\n", debugstr_w(feature
));
5633 return ERROR_SUCCESS
;
5636 component
= MSI_RecordGetString( rec
, 3 );
5637 comp
= msi_get_loaded_component( package
, component
);
5639 return ERROR_SUCCESS
;
5641 compgroupid
= MSI_RecordGetString( rec
, 1 );
5642 qualifier
= MSI_RecordGetString( rec
, 2 );
5644 squash_guid( compgroupid
, squashed
);
5645 lstrcpyW( keypath
, L
"Software\\Microsoft\\Installer\\Components\\" );
5646 lstrcatW( keypath
, squashed
);
5648 res
= RegDeleteKeyW( HKEY_CURRENT_USER
, keypath
);
5649 if (res
!= ERROR_SUCCESS
)
5651 WARN( "unable to delete component key %ld\n", res
);
5654 uirow
= MSI_CreateRecord( 2 );
5655 MSI_RecordSetStringW( uirow
, 1, compgroupid
);
5656 MSI_RecordSetStringW( uirow
, 2, qualifier
);
5657 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5658 msiobj_release( &uirow
->hdr
);
5660 return ERROR_SUCCESS
;
5663 static UINT
ACTION_UnpublishComponents( MSIPACKAGE
*package
)
5668 if (package
->script
== SCRIPT_NONE
)
5669 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"UnpublishComponents");
5671 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `PublishComponent`", &view
);
5672 if (rc
!= ERROR_SUCCESS
)
5673 return ERROR_SUCCESS
;
5675 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_UnpublishComponent
, package
);
5676 msiobj_release( &view
->hdr
);
5680 static UINT
ITERATE_InstallService(MSIRECORD
*rec
, LPVOID param
)
5682 MSIPACKAGE
*package
= param
;
5683 MSICOMPONENT
*component
;
5686 SC_HANDLE hscm
= NULL
, service
= NULL
;
5688 LPWSTR name
= NULL
, disp
= NULL
, load_order
= NULL
, serv_name
= NULL
;
5689 LPWSTR depends
= NULL
, pass
= NULL
, args
= NULL
, image_path
= NULL
;
5690 DWORD serv_type
, start_type
, err_control
;
5692 SERVICE_DESCRIPTIONW sd
= {NULL
};
5693 UINT ret
= ERROR_SUCCESS
;
5695 comp
= MSI_RecordGetString( rec
, 12 );
5696 component
= msi_get_loaded_component( package
, comp
);
5699 WARN("service component not found\n");
5702 component
->Action
= msi_get_component_action( package
, component
);
5703 if (component
->Action
!= INSTALLSTATE_LOCAL
)
5705 TRACE("component not scheduled for installation %s\n", debugstr_w(comp
));
5708 hscm
= OpenSCManagerW(NULL
, SERVICES_ACTIVE_DATABASEW
, GENERIC_WRITE
);
5711 ERR("Failed to open the SC Manager!\n");
5715 start_type
= MSI_RecordGetInteger(rec
, 5);
5716 if (start_type
== SERVICE_BOOT_START
|| start_type
== SERVICE_SYSTEM_START
)
5719 deformat_string(package
, MSI_RecordGetString(rec
, 2), &name
);
5720 deformat_string(package
, MSI_RecordGetString(rec
, 3), &disp
);
5721 serv_type
= MSI_RecordGetInteger(rec
, 4);
5722 err_control
= MSI_RecordGetInteger(rec
, 6);
5723 deformat_string(package
, MSI_RecordGetString(rec
, 7), &load_order
);
5724 deformat_string(package
, MSI_RecordGetString(rec
, 8), &depends
);
5725 deformat_string(package
, MSI_RecordGetString(rec
, 9), &serv_name
);
5726 deformat_string(package
, MSI_RecordGetString(rec
, 10), &pass
);
5727 deformat_string(package
, MSI_RecordGetString(rec
, 11), &args
);
5728 deformat_string(package
, MSI_RecordGetString(rec
, 13), &sd
.lpDescription
);
5730 /* Should the complete install fail if CreateService fails? */
5731 is_vital
= (err_control
& msidbServiceInstallErrorControlVital
);
5733 /* Remove the msidbServiceInstallErrorControlVital-flag from err_control.
5734 CreateService (under Windows) would fail if not. */
5735 err_control
&= ~msidbServiceInstallErrorControlVital
;
5737 /* fetch the service path */
5738 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `Component` WHERE `Component` = '%s'", comp
);
5741 ERR("Query failed\n");
5744 if (!(key
= MSI_RecordGetString(row
, 6)))
5746 msiobj_release(&row
->hdr
);
5749 file
= msi_get_loaded_file(package
, key
);
5750 msiobj_release(&row
->hdr
);
5753 ERR("Failed to load the service file\n");
5757 if (!args
|| !args
[0]) image_path
= file
->TargetPath
;
5760 int len
= lstrlenW(file
->TargetPath
) + lstrlenW(args
) + 2;
5761 if (!(image_path
= msi_alloc(len
* sizeof(WCHAR
))))
5763 ret
= ERROR_OUTOFMEMORY
;
5767 lstrcpyW(image_path
, file
->TargetPath
);
5768 lstrcatW(image_path
, L
" ");
5769 lstrcatW(image_path
, args
);
5771 service
= CreateServiceW(hscm
, name
, disp
, GENERIC_ALL
, serv_type
,
5772 start_type
, err_control
, image_path
, load_order
,
5773 NULL
, depends
, serv_name
, pass
);
5777 if (GetLastError() != ERROR_SERVICE_EXISTS
)
5779 WARN( "failed to create service %s (%lu)\n", debugstr_w(name
), GetLastError() );
5781 ret
= ERROR_INSTALL_FAILURE
;
5785 else if (sd
.lpDescription
)
5787 if (!ChangeServiceConfig2W(service
, SERVICE_CONFIG_DESCRIPTION
, &sd
))
5788 WARN( "failed to set service description %lu\n", GetLastError() );
5791 if (image_path
!= file
->TargetPath
) msi_free(image_path
);
5793 if (service
) CloseServiceHandle(service
);
5794 if (hscm
) CloseServiceHandle(hscm
);
5797 msi_free(sd
.lpDescription
);
5798 msi_free(load_order
);
5799 msi_free(serv_name
);
5807 static UINT
ACTION_InstallServices( MSIPACKAGE
*package
)
5812 if (package
->script
== SCRIPT_NONE
)
5813 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"InstallServices");
5815 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `ServiceInstall`", &view
);
5816 if (rc
!= ERROR_SUCCESS
)
5817 return ERROR_SUCCESS
;
5819 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallService
, package
);
5820 msiobj_release(&view
->hdr
);
5824 /* converts arg1[~]arg2[~]arg3 to a list of ptrs to the strings */
5825 static LPCWSTR
*msi_service_args_to_vector(LPWSTR args
, DWORD
*numargs
)
5827 LPCWSTR
*vector
, *temp_vector
;
5832 sep_len
= ARRAY_SIZE(L
"[~]") - 1;
5837 vector
= msi_alloc(sizeof(LPWSTR
));
5845 vector
[*numargs
- 1] = p
;
5847 if ((q
= wcsstr(p
, L
"[~]")))
5851 temp_vector
= msi_realloc(vector
, (*numargs
+ 1) * sizeof(LPWSTR
));
5857 vector
= temp_vector
;
5866 static UINT
ITERATE_StartService(MSIRECORD
*rec
, LPVOID param
)
5868 MSIPACKAGE
*package
= param
;
5871 SC_HANDLE scm
= NULL
, service
= NULL
;
5872 LPCWSTR component
, *vector
= NULL
;
5873 LPWSTR name
, args
, display_name
= NULL
;
5874 DWORD event
, numargs
, len
, wait
, dummy
;
5875 UINT r
= ERROR_FUNCTION_FAILED
;
5876 SERVICE_STATUS_PROCESS status
;
5877 ULONGLONG start_time
;
5879 component
= MSI_RecordGetString(rec
, 6);
5880 comp
= msi_get_loaded_component(package
, component
);
5882 return ERROR_SUCCESS
;
5884 event
= MSI_RecordGetInteger( rec
, 3 );
5885 deformat_string( package
, MSI_RecordGetString( rec
, 2 ), &name
);
5887 comp
->Action
= msi_get_component_action( package
, comp
);
5888 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventStart
)) &&
5889 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallStart
)))
5891 TRACE("not starting %s\n", debugstr_w(name
));
5893 return ERROR_SUCCESS
;
5896 deformat_string(package
, MSI_RecordGetString(rec
, 4), &args
);
5897 wait
= MSI_RecordGetInteger(rec
, 5);
5899 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_CONNECT
);
5902 ERR("Failed to open the service control manager\n");
5907 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
5908 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
5910 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
5911 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
5914 service
= OpenServiceW(scm
, name
, SERVICE_START
|SERVICE_QUERY_STATUS
);
5917 ERR( "failed to open service %s (%lu)\n", debugstr_w(name
), GetLastError() );
5921 vector
= msi_service_args_to_vector(args
, &numargs
);
5923 if (!StartServiceW(service
, numargs
, vector
) &&
5924 GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
)
5926 ERR( "failed to start service %s (%lu)\n", debugstr_w(name
), GetLastError() );
5933 /* wait for at most 30 seconds for the service to be up and running */
5934 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
,
5935 (BYTE
*)&status
, sizeof(SERVICE_STATUS_PROCESS
), &dummy
))
5937 TRACE( "failed to query service status (%lu)\n", GetLastError() );
5940 start_time
= GetTickCount64();
5941 while (status
.dwCurrentState
== SERVICE_START_PENDING
)
5943 if (GetTickCount64() - start_time
> 30000) break;
5945 if (!QueryServiceStatusEx(service
, SC_STATUS_PROCESS_INFO
,
5946 (BYTE
*)&status
, sizeof(SERVICE_STATUS_PROCESS
), &dummy
))
5948 TRACE( "failed to query service status (%lu)\n", GetLastError() );
5952 if (status
.dwCurrentState
!= SERVICE_RUNNING
)
5954 WARN( "service failed to start %lu\n", status
.dwCurrentState
);
5955 r
= ERROR_FUNCTION_FAILED
;
5960 uirow
= MSI_CreateRecord( 2 );
5961 MSI_RecordSetStringW( uirow
, 1, display_name
);
5962 MSI_RecordSetStringW( uirow
, 2, name
);
5963 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
5964 msiobj_release( &uirow
->hdr
);
5966 if (service
) CloseServiceHandle(service
);
5967 if (scm
) CloseServiceHandle(scm
);
5972 msi_free(display_name
);
5976 static UINT
ACTION_StartServices( MSIPACKAGE
*package
)
5981 if (package
->script
== SCRIPT_NONE
)
5982 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"StartServices");
5984 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `ServiceControl`", &view
);
5985 if (rc
!= ERROR_SUCCESS
)
5986 return ERROR_SUCCESS
;
5988 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StartService
, package
);
5989 msiobj_release(&view
->hdr
);
5993 static BOOL
stop_service_dependents(SC_HANDLE scm
, SC_HANDLE service
)
5995 DWORD i
, needed
, count
;
5996 ENUM_SERVICE_STATUSW
*dependencies
;
5999 BOOL stopped
, ret
= FALSE
;
6001 if (EnumDependentServicesW(service
, SERVICE_ACTIVE
, NULL
,
6002 0, &needed
, &count
))
6005 if (GetLastError() != ERROR_MORE_DATA
)
6008 dependencies
= msi_alloc(needed
);
6012 if (!EnumDependentServicesW(service
, SERVICE_ACTIVE
, dependencies
,
6013 needed
, &needed
, &count
))
6016 for (i
= 0; i
< count
; i
++)
6018 depserv
= OpenServiceW(scm
, dependencies
[i
].lpServiceName
,
6019 SERVICE_STOP
| SERVICE_QUERY_STATUS
);
6023 stopped
= ControlService(depserv
, SERVICE_CONTROL_STOP
, &ss
);
6024 CloseServiceHandle(depserv
);
6032 msi_free(dependencies
);
6036 static UINT
stop_service( LPCWSTR name
)
6038 SC_HANDLE scm
= NULL
, service
= NULL
;
6039 SERVICE_STATUS status
;
6040 SERVICE_STATUS_PROCESS ssp
;
6043 scm
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
6046 WARN( "failed to open the SCM (%lu)\n", GetLastError() );
6050 service
= OpenServiceW(scm
, name
, SERVICE_STOP
| SERVICE_QUERY_STATUS
| SERVICE_ENUMERATE_DEPENDENTS
);
6053 WARN( "failed to open service %s (%lu)\n", debugstr_w(name
), GetLastError() );
6057 if (!QueryServiceStatusEx( service
, SC_STATUS_PROCESS_INFO
, (BYTE
*)&ssp
, sizeof(ssp
), &needed
) )
6059 WARN( "failed to query service status %s (%lu)\n", debugstr_w(name
), GetLastError() );
6063 if (ssp
.dwCurrentState
== SERVICE_STOPPED
)
6066 stop_service_dependents(scm
, service
);
6068 if (!ControlService(service
, SERVICE_CONTROL_STOP
, &status
))
6069 WARN( "failed to stop service %s (%lu)\n", debugstr_w(name
), GetLastError() );
6072 if (service
) CloseServiceHandle(service
);
6073 if (scm
) CloseServiceHandle(scm
);
6075 return ERROR_SUCCESS
;
6078 static UINT
ITERATE_StopService( MSIRECORD
*rec
, LPVOID param
)
6080 MSIPACKAGE
*package
= param
;
6084 WCHAR
*name
, *display_name
= NULL
;
6088 component
= MSI_RecordGetString( rec
, 6 );
6089 comp
= msi_get_loaded_component( package
, component
);
6091 return ERROR_SUCCESS
;
6093 event
= MSI_RecordGetInteger( rec
, 3 );
6094 deformat_string( package
, MSI_RecordGetString( rec
, 2 ), &name
);
6096 comp
->Action
= msi_get_component_action( package
, comp
);
6097 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventStop
)) &&
6098 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallStop
)))
6100 TRACE("not stopping %s\n", debugstr_w(name
));
6102 return ERROR_SUCCESS
;
6105 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_CONNECT
);
6108 ERR("Failed to open the service control manager\n");
6113 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
6114 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
6116 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
6117 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
6119 CloseServiceHandle( scm
);
6121 stop_service( name
);
6124 uirow
= MSI_CreateRecord( 2 );
6125 MSI_RecordSetStringW( uirow
, 1, display_name
);
6126 MSI_RecordSetStringW( uirow
, 2, name
);
6127 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6128 msiobj_release( &uirow
->hdr
);
6131 msi_free( display_name
);
6132 return ERROR_SUCCESS
;
6135 static UINT
ACTION_StopServices( MSIPACKAGE
*package
)
6140 if (package
->script
== SCRIPT_NONE
)
6141 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"StopServices");
6143 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `ServiceControl`", &view
);
6144 if (rc
!= ERROR_SUCCESS
)
6145 return ERROR_SUCCESS
;
6147 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_StopService
, package
);
6148 msiobj_release(&view
->hdr
);
6152 static UINT
ITERATE_DeleteService( MSIRECORD
*rec
, LPVOID param
)
6154 MSIPACKAGE
*package
= param
;
6157 LPWSTR name
= NULL
, display_name
= NULL
;
6159 SC_HANDLE scm
= NULL
, service
= NULL
;
6161 comp
= msi_get_loaded_component( package
, MSI_RecordGetString(rec
, 6) );
6163 return ERROR_SUCCESS
;
6165 event
= MSI_RecordGetInteger( rec
, 3 );
6166 deformat_string( package
, MSI_RecordGetString(rec
, 2), &name
);
6168 comp
->Action
= msi_get_component_action( package
, comp
);
6169 if (!(comp
->Action
== INSTALLSTATE_LOCAL
&& (event
& msidbServiceControlEventDelete
)) &&
6170 !(comp
->Action
== INSTALLSTATE_ABSENT
&& (event
& msidbServiceControlEventUninstallDelete
)))
6172 TRACE("service %s not scheduled for removal\n", debugstr_w(name
));
6174 return ERROR_SUCCESS
;
6176 stop_service( name
);
6178 scm
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
6181 WARN( "failed to open the SCM (%lu)\n", GetLastError() );
6186 if (!GetServiceDisplayNameW( scm
, name
, NULL
, &len
) &&
6187 GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
6189 if ((display_name
= msi_alloc( ++len
* sizeof(WCHAR
))))
6190 GetServiceDisplayNameW( scm
, name
, display_name
, &len
);
6193 service
= OpenServiceW( scm
, name
, DELETE
);
6196 WARN( "failed to open service %s (%lu)\n", debugstr_w(name
), GetLastError() );
6200 if (!DeleteService( service
))
6201 WARN( "failed to delete service %s (%lu)\n", debugstr_w(name
), GetLastError() );
6204 uirow
= MSI_CreateRecord( 2 );
6205 MSI_RecordSetStringW( uirow
, 1, display_name
);
6206 MSI_RecordSetStringW( uirow
, 2, name
);
6207 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6208 msiobj_release( &uirow
->hdr
);
6210 if (service
) CloseServiceHandle( service
);
6211 if (scm
) CloseServiceHandle( scm
);
6213 msi_free( display_name
);
6215 return ERROR_SUCCESS
;
6218 static UINT
ACTION_DeleteServices( MSIPACKAGE
*package
)
6223 if (package
->script
== SCRIPT_NONE
)
6224 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"DeleteServices");
6226 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `ServiceControl`", &view
);
6227 if (rc
!= ERROR_SUCCESS
)
6228 return ERROR_SUCCESS
;
6230 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_DeleteService
, package
);
6231 msiobj_release( &view
->hdr
);
6235 static UINT
ITERATE_InstallODBCDriver( MSIRECORD
*rec
, LPVOID param
)
6237 MSIPACKAGE
*package
= param
;
6238 LPWSTR driver
, driver_path
, ptr
;
6239 WCHAR outpath
[MAX_PATH
];
6240 MSIFILE
*driver_file
= NULL
, *setup_file
= NULL
;
6243 LPCWSTR desc
, file_key
, component
;
6245 UINT r
= ERROR_SUCCESS
;
6247 component
= MSI_RecordGetString( rec
, 2 );
6248 comp
= msi_get_loaded_component( package
, component
);
6250 return ERROR_SUCCESS
;
6252 comp
->Action
= msi_get_component_action( package
, comp
);
6253 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6255 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6256 return ERROR_SUCCESS
;
6258 desc
= MSI_RecordGetString(rec
, 3);
6260 file_key
= MSI_RecordGetString( rec
, 4 );
6261 if (file_key
) driver_file
= msi_get_loaded_file( package
, file_key
);
6263 file_key
= MSI_RecordGetString( rec
, 5 );
6264 if (file_key
) setup_file
= msi_get_loaded_file( package
, file_key
);
6268 ERR("ODBC Driver entry not found!\n");
6269 return ERROR_FUNCTION_FAILED
;
6272 len
= lstrlenW(desc
) + lstrlenW(L
"Driver=%s") + lstrlenW(driver_file
->FileName
);
6274 len
+= lstrlenW(L
"Setup=%s") + lstrlenW(setup_file
->FileName
);
6275 len
+= lstrlenW(L
"FileUsage=1") + 2; /* \0\0 */
6277 driver
= msi_alloc(len
* sizeof(WCHAR
));
6279 return ERROR_OUTOFMEMORY
;
6282 lstrcpyW(ptr
, desc
);
6283 ptr
+= lstrlenW(ptr
) + 1;
6285 len
= swprintf(ptr
, len
- (ptr
- driver
), L
"Driver=%s", driver_file
->FileName
);
6290 len
= swprintf(ptr
, len
- (ptr
- driver
), L
"Setup=%s", setup_file
->FileName
);
6294 lstrcpyW(ptr
, L
"FileUsage=1");
6295 ptr
+= lstrlenW(ptr
) + 1;
6298 if (!driver_file
->TargetPath
)
6300 const WCHAR
*dir
= msi_get_target_folder( package
, driver_file
->Component
->Directory
);
6301 driver_file
->TargetPath
= msi_build_directory_name( 2, dir
, driver_file
->FileName
);
6303 driver_path
= strdupW(driver_file
->TargetPath
);
6304 ptr
= wcsrchr(driver_path
, '\\');
6305 if (ptr
) *ptr
= '\0';
6307 if (!SQLInstallDriverExW(driver
, driver_path
, outpath
, MAX_PATH
,
6308 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
6310 ERR("Failed to install SQL driver!\n");
6311 r
= ERROR_FUNCTION_FAILED
;
6314 uirow
= MSI_CreateRecord( 5 );
6315 MSI_RecordSetStringW( uirow
, 1, desc
);
6316 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6317 MSI_RecordSetStringW( uirow
, 3, driver_file
->Component
->Directory
);
6318 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6319 msiobj_release( &uirow
->hdr
);
6322 msi_free(driver_path
);
6327 static UINT
ITERATE_InstallODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
6329 MSIPACKAGE
*package
= param
;
6330 LPWSTR translator
, translator_path
, ptr
;
6331 WCHAR outpath
[MAX_PATH
];
6332 MSIFILE
*translator_file
= NULL
, *setup_file
= NULL
;
6335 LPCWSTR desc
, file_key
, component
;
6337 UINT r
= ERROR_SUCCESS
;
6339 component
= MSI_RecordGetString( rec
, 2 );
6340 comp
= msi_get_loaded_component( package
, component
);
6342 return ERROR_SUCCESS
;
6344 comp
->Action
= msi_get_component_action( package
, comp
);
6345 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6347 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6348 return ERROR_SUCCESS
;
6350 desc
= MSI_RecordGetString(rec
, 3);
6352 file_key
= MSI_RecordGetString( rec
, 4 );
6353 if (file_key
) translator_file
= msi_get_loaded_file( package
, file_key
);
6355 file_key
= MSI_RecordGetString( rec
, 5 );
6356 if (file_key
) setup_file
= msi_get_loaded_file( package
, file_key
);
6358 if (!translator_file
)
6360 ERR("ODBC Translator entry not found!\n");
6361 return ERROR_FUNCTION_FAILED
;
6364 len
= lstrlenW(desc
) + lstrlenW(L
"Translator=%s") + lstrlenW(translator_file
->FileName
) + 2; /* \0\0 */
6366 len
+= lstrlenW(L
"Setup=%s") + lstrlenW(setup_file
->FileName
);
6368 translator
= msi_alloc(len
* sizeof(WCHAR
));
6370 return ERROR_OUTOFMEMORY
;
6373 lstrcpyW(ptr
, desc
);
6374 ptr
+= lstrlenW(ptr
) + 1;
6376 len
= swprintf(ptr
, len
- (ptr
- translator
), L
"Translator=%s", translator_file
->FileName
);
6381 len
= swprintf(ptr
, len
- (ptr
- translator
), L
"Setup=%s", setup_file
->FileName
);
6386 translator_path
= strdupW(translator_file
->TargetPath
);
6387 ptr
= wcsrchr(translator_path
, '\\');
6388 if (ptr
) *ptr
= '\0';
6390 if (!SQLInstallTranslatorExW(translator
, translator_path
, outpath
, MAX_PATH
,
6391 NULL
, ODBC_INSTALL_COMPLETE
, &usage
))
6393 ERR("Failed to install SQL translator!\n");
6394 r
= ERROR_FUNCTION_FAILED
;
6397 uirow
= MSI_CreateRecord( 5 );
6398 MSI_RecordSetStringW( uirow
, 1, desc
);
6399 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6400 MSI_RecordSetStringW( uirow
, 3, translator_file
->Component
->Directory
);
6401 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6402 msiobj_release( &uirow
->hdr
);
6404 msi_free(translator
);
6405 msi_free(translator_path
);
6410 static UINT
ITERATE_InstallODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
6412 MSIPACKAGE
*package
= param
;
6415 LPCWSTR desc
, driver
, component
;
6416 WORD request
= ODBC_ADD_SYS_DSN
;
6419 UINT r
= ERROR_SUCCESS
;
6422 component
= MSI_RecordGetString( rec
, 2 );
6423 comp
= msi_get_loaded_component( package
, component
);
6425 return ERROR_SUCCESS
;
6427 comp
->Action
= msi_get_component_action( package
, comp
);
6428 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6430 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6431 return ERROR_SUCCESS
;
6434 desc
= MSI_RecordGetString(rec
, 3);
6435 driver
= MSI_RecordGetString(rec
, 4);
6436 registration
= MSI_RecordGetInteger(rec
, 5);
6438 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_ADD_SYS_DSN
;
6439 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_ADD_DSN
;
6441 len
= lstrlenW(L
"DSN=%s") + lstrlenW(desc
) + 2; /* \0\0 */
6442 attrs
= msi_alloc(len
* sizeof(WCHAR
));
6444 return ERROR_OUTOFMEMORY
;
6446 len
= swprintf(attrs
, len
, L
"DSN=%s", desc
);
6449 if (!SQLConfigDataSourceW(NULL
, request
, driver
, attrs
))
6450 WARN("Failed to install SQL data source!\n");
6452 uirow
= MSI_CreateRecord( 5 );
6453 MSI_RecordSetStringW( uirow
, 1, desc
);
6454 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6455 MSI_RecordSetInteger( uirow
, 3, request
);
6456 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6457 msiobj_release( &uirow
->hdr
);
6464 static UINT
ACTION_InstallODBC( MSIPACKAGE
*package
)
6469 if (package
->script
== SCRIPT_NONE
)
6470 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"InstallODBC");
6472 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `ODBCDriver`", &view
);
6473 if (rc
== ERROR_SUCCESS
)
6475 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDriver
, package
);
6476 msiobj_release(&view
->hdr
);
6477 if (rc
!= ERROR_SUCCESS
)
6480 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `ODBCTranslator`", &view
);
6481 if (rc
== ERROR_SUCCESS
)
6483 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCTranslator
, package
);
6484 msiobj_release(&view
->hdr
);
6485 if (rc
!= ERROR_SUCCESS
)
6488 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `ODBCDataSource`", &view
);
6489 if (rc
== ERROR_SUCCESS
)
6491 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_InstallODBCDataSource
, package
);
6492 msiobj_release(&view
->hdr
);
6493 if (rc
!= ERROR_SUCCESS
)
6496 return ERROR_SUCCESS
;
6499 static UINT
ITERATE_RemoveODBCDriver( MSIRECORD
*rec
, LPVOID param
)
6501 MSIPACKAGE
*package
= param
;
6505 LPCWSTR desc
, component
;
6507 component
= MSI_RecordGetString( rec
, 2 );
6508 comp
= msi_get_loaded_component( package
, component
);
6510 return ERROR_SUCCESS
;
6512 comp
->Action
= msi_get_component_action( package
, comp
);
6513 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6515 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6516 return ERROR_SUCCESS
;
6519 desc
= MSI_RecordGetString( rec
, 3 );
6520 if (!SQLRemoveDriverW( desc
, FALSE
, &usage
))
6522 WARN("Failed to remove ODBC driver\n");
6526 FIXME("Usage count reached 0\n");
6529 uirow
= MSI_CreateRecord( 2 );
6530 MSI_RecordSetStringW( uirow
, 1, desc
);
6531 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6532 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6533 msiobj_release( &uirow
->hdr
);
6535 return ERROR_SUCCESS
;
6538 static UINT
ITERATE_RemoveODBCTranslator( MSIRECORD
*rec
, LPVOID param
)
6540 MSIPACKAGE
*package
= param
;
6544 LPCWSTR desc
, component
;
6546 component
= MSI_RecordGetString( rec
, 2 );
6547 comp
= msi_get_loaded_component( package
, component
);
6549 return ERROR_SUCCESS
;
6551 comp
->Action
= msi_get_component_action( package
, comp
);
6552 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6554 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6555 return ERROR_SUCCESS
;
6558 desc
= MSI_RecordGetString( rec
, 3 );
6559 if (!SQLRemoveTranslatorW( desc
, &usage
))
6561 WARN("Failed to remove ODBC translator\n");
6565 FIXME("Usage count reached 0\n");
6568 uirow
= MSI_CreateRecord( 2 );
6569 MSI_RecordSetStringW( uirow
, 1, desc
);
6570 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6571 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6572 msiobj_release( &uirow
->hdr
);
6574 return ERROR_SUCCESS
;
6577 static UINT
ITERATE_RemoveODBCDataSource( MSIRECORD
*rec
, LPVOID param
)
6579 MSIPACKAGE
*package
= param
;
6583 LPCWSTR desc
, driver
, component
;
6584 WORD request
= ODBC_REMOVE_SYS_DSN
;
6588 component
= MSI_RecordGetString( rec
, 2 );
6589 comp
= msi_get_loaded_component( package
, component
);
6591 return ERROR_SUCCESS
;
6593 comp
->Action
= msi_get_component_action( package
, comp
);
6594 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
6596 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
6597 return ERROR_SUCCESS
;
6600 desc
= MSI_RecordGetString( rec
, 3 );
6601 driver
= MSI_RecordGetString( rec
, 4 );
6602 registration
= MSI_RecordGetInteger( rec
, 5 );
6604 if (registration
== msidbODBCDataSourceRegistrationPerMachine
) request
= ODBC_REMOVE_SYS_DSN
;
6605 else if (registration
== msidbODBCDataSourceRegistrationPerUser
) request
= ODBC_REMOVE_DSN
;
6607 len
= lstrlenW( L
"DSN=%s" ) + lstrlenW( desc
) + 2; /* \0\0 */
6608 attrs
= msi_alloc( len
* sizeof(WCHAR
) );
6610 return ERROR_OUTOFMEMORY
;
6612 FIXME("Use ODBCSourceAttribute table\n");
6614 len
= swprintf( attrs
, len
, L
"DSN=%s", desc
);
6617 if (!SQLConfigDataSourceW( NULL
, request
, driver
, attrs
))
6619 WARN("Failed to remove ODBC data source\n");
6623 uirow
= MSI_CreateRecord( 3 );
6624 MSI_RecordSetStringW( uirow
, 1, desc
);
6625 MSI_RecordSetStringW( uirow
, 2, MSI_RecordGetString(rec
, 2) );
6626 MSI_RecordSetInteger( uirow
, 3, request
);
6627 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6628 msiobj_release( &uirow
->hdr
);
6630 return ERROR_SUCCESS
;
6633 static UINT
ACTION_RemoveODBC( MSIPACKAGE
*package
)
6638 if (package
->script
== SCRIPT_NONE
)
6639 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RemoveODBC");
6641 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `ODBCDriver`", &view
);
6642 if (rc
== ERROR_SUCCESS
)
6644 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDriver
, package
);
6645 msiobj_release( &view
->hdr
);
6646 if (rc
!= ERROR_SUCCESS
)
6649 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `ODBCTranslator`", &view
);
6650 if (rc
== ERROR_SUCCESS
)
6652 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCTranslator
, package
);
6653 msiobj_release( &view
->hdr
);
6654 if (rc
!= ERROR_SUCCESS
)
6657 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `ODBCDataSource`", &view
);
6658 if (rc
== ERROR_SUCCESS
)
6660 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveODBCDataSource
, package
);
6661 msiobj_release( &view
->hdr
);
6662 if (rc
!= ERROR_SUCCESS
)
6665 return ERROR_SUCCESS
;
6668 #define ENV_ACT_SETALWAYS 0x1
6669 #define ENV_ACT_SETABSENT 0x2
6670 #define ENV_ACT_REMOVE 0x4
6671 #define ENV_ACT_REMOVEMATCH 0x8
6673 #define ENV_MOD_MACHINE 0x20000000
6674 #define ENV_MOD_APPEND 0x40000000
6675 #define ENV_MOD_PREFIX 0x80000000
6676 #define ENV_MOD_MASK 0xC0000000
6678 #define check_flag_combo(x, y) ((x) & ~(y)) == (y)
6680 static UINT
env_parse_flags( LPCWSTR
*name
, LPCWSTR
*value
, DWORD
*flags
)
6682 const WCHAR
*cptr
= *name
;
6688 *flags
|= ENV_ACT_SETALWAYS
;
6689 else if (*cptr
== '+')
6690 *flags
|= ENV_ACT_SETABSENT
;
6691 else if (*cptr
== '-')
6692 *flags
|= ENV_ACT_REMOVE
;
6693 else if (*cptr
== '!')
6694 *flags
|= ENV_ACT_REMOVEMATCH
;
6695 else if (*cptr
== '*')
6696 *flags
|= ENV_MOD_MACHINE
| ENV_ACT_REMOVE
;
6706 ERR("Missing environment variable\n");
6707 return ERROR_FUNCTION_FAILED
;
6712 LPCWSTR ptr
= *value
;
6713 if (!wcsncmp(ptr
, L
"[~]", 3))
6717 *flags
|= ENV_MOD_APPEND
;
6725 else if (lstrlenW(*value
) >= 3)
6727 ptr
+= lstrlenW(ptr
) - 3;
6728 if (!wcscmp( ptr
, L
"[~]" ))
6730 if ((ptr
-1) > *value
&& *(ptr
-1) == ';')
6732 *flags
|= ENV_MOD_PREFIX
;
6733 /* the "[~]" will be removed by deformat_string */;
6743 if (check_flag_combo(*flags
, ENV_ACT_SETALWAYS
| ENV_ACT_SETABSENT
) ||
6744 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETABSENT
) ||
6745 check_flag_combo(*flags
, ENV_ACT_REMOVEMATCH
| ENV_ACT_SETALWAYS
) ||
6746 check_flag_combo(*flags
, ENV_ACT_SETABSENT
| ENV_MOD_MASK
))
6748 ERR( "invalid flags: %#lx\n", *flags
);
6749 return ERROR_FUNCTION_FAILED
;
6753 *flags
= ENV_ACT_SETALWAYS
| ENV_ACT_REMOVE
;
6755 return ERROR_SUCCESS
;
6758 static UINT
open_env_key( DWORD flags
, HKEY
*key
)
6764 if (flags
& ENV_MOD_MACHINE
)
6766 env
= L
"System\\CurrentControlSet\\Control\\Session Manager\\Environment";
6767 root
= HKEY_LOCAL_MACHINE
;
6771 env
= L
"Environment";
6772 root
= HKEY_CURRENT_USER
;
6775 res
= RegOpenKeyExW( root
, env
, 0, KEY_ALL_ACCESS
, key
);
6776 if (res
!= ERROR_SUCCESS
)
6778 WARN( "failed to open key %s (%ld)\n", debugstr_w(env
), res
);
6779 return ERROR_FUNCTION_FAILED
;
6782 return ERROR_SUCCESS
;
6785 static UINT
ITERATE_WriteEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
6787 MSIPACKAGE
*package
= param
;
6788 LPCWSTR name
, value
, component
;
6789 WCHAR
*data
= NULL
, *newval
= NULL
, *deformatted
= NULL
, *p
, *q
;
6790 DWORD flags
, type
, size
, len
, len_value
= 0;
6795 int action
= 0, found
= 0;
6797 component
= MSI_RecordGetString(rec
, 4);
6798 comp
= msi_get_loaded_component(package
, component
);
6800 return ERROR_SUCCESS
;
6802 comp
->Action
= msi_get_component_action( package
, comp
);
6803 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
6805 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
6806 return ERROR_SUCCESS
;
6808 name
= MSI_RecordGetString(rec
, 2);
6809 value
= MSI_RecordGetString(rec
, 3);
6811 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
6813 res
= env_parse_flags(&name
, &value
, &flags
);
6814 if (res
!= ERROR_SUCCESS
|| !value
)
6819 DWORD len
= deformat_string( package
, value
, &deformatted
);
6822 res
= ERROR_OUTOFMEMORY
;
6828 value
= deformatted
;
6829 if (flags
& ENV_MOD_PREFIX
)
6831 p
= wcsrchr( value
, ';' );
6832 len_value
= p
- value
;
6834 else if (flags
& ENV_MOD_APPEND
)
6836 value
= wcschr( value
, ';' ) + 1;
6837 len_value
= lstrlenW( value
);
6839 else len_value
= lstrlenW( value
);
6847 res
= open_env_key( flags
, &env
);
6848 if (res
!= ERROR_SUCCESS
)
6851 if (flags
& ENV_MOD_MACHINE
)
6852 action
|= 0x20000000;
6856 res
= RegQueryValueExW(env
, name
, NULL
, &type
, NULL
, &size
);
6857 if ((res
!= ERROR_SUCCESS
&& res
!= ERROR_FILE_NOT_FOUND
) ||
6858 (res
== ERROR_SUCCESS
&& type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
))
6861 if ((res
== ERROR_FILE_NOT_FOUND
|| !(flags
& ENV_MOD_MASK
)))
6865 /* Nothing to do. */
6868 res
= ERROR_SUCCESS
;
6871 size
= (lstrlenW(value
) + 1) * sizeof(WCHAR
);
6872 newval
= strdupW(value
);
6875 res
= ERROR_OUTOFMEMORY
;
6883 /* Contrary to MSDN, +-variable to [~];path works */
6884 if (flags
& ENV_ACT_SETABSENT
&& !(flags
& ENV_MOD_MASK
))
6886 res
= ERROR_SUCCESS
;
6890 if (!(p
= q
= data
= msi_alloc( size
)))
6892 msi_free(deformatted
);
6894 return ERROR_OUTOFMEMORY
;
6897 res
= RegQueryValueExW( env
, name
, NULL
, &type
, (BYTE
*)data
, &size
);
6898 if (res
!= ERROR_SUCCESS
)
6901 if (flags
& ENV_ACT_REMOVEMATCH
&& (!value
|| !wcscmp( data
, value
)))
6904 res
= RegDeleteValueW(env
, name
);
6905 if (res
!= ERROR_SUCCESS
)
6906 WARN("Failed to remove value %s (%d)\n", debugstr_w(name
), res
);
6912 while (*q
&& *q
!= ';') q
++;
6914 if (value
&& len
== len_value
&& !memcmp( value
, p
, len
* sizeof(WCHAR
) ) &&
6915 (!p
[len
] || p
[len
] == ';'))
6926 TRACE("string already set\n");
6930 size
= (len_value
+ 1 + lstrlenW( data
) + 1) * sizeof(WCHAR
);
6931 if (!(p
= newval
= msi_alloc( size
)))
6933 res
= ERROR_OUTOFMEMORY
;
6937 if (flags
& ENV_MOD_PREFIX
)
6939 memcpy( newval
, value
, len_value
* sizeof(WCHAR
) );
6940 newval
[len_value
] = ';';
6941 p
= newval
+ len_value
+ 1;
6942 action
|= 0x80000000;
6945 lstrcpyW( p
, data
);
6947 if (flags
& ENV_MOD_APPEND
)
6949 p
+= lstrlenW( data
);
6951 memcpy( p
, value
, (len_value
+ 1) * sizeof(WCHAR
) );
6952 action
|= 0x40000000;
6955 TRACE("setting %s to %s\n", debugstr_w(name
), debugstr_w(newval
));
6956 res
= RegSetValueExW( env
, name
, 0, type
, (BYTE
*)newval
, size
);
6959 WARN("Failed to set %s to %s (%d)\n", debugstr_w(name
), debugstr_w(newval
), res
);
6963 uirow
= MSI_CreateRecord( 3 );
6964 MSI_RecordSetStringW( uirow
, 1, name
);
6965 MSI_RecordSetStringW( uirow
, 2, newval
);
6966 MSI_RecordSetInteger( uirow
, 3, action
);
6967 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
6968 msiobj_release( &uirow
->hdr
);
6970 if (env
) RegCloseKey(env
);
6971 msi_free(deformatted
);
6977 static UINT
ACTION_WriteEnvironmentStrings( MSIPACKAGE
*package
)
6982 if (package
->script
== SCRIPT_NONE
)
6983 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"WriteEnvironmentStrings");
6985 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `Environment`", &view
);
6986 if (rc
!= ERROR_SUCCESS
)
6987 return ERROR_SUCCESS
;
6989 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_WriteEnvironmentString
, package
);
6990 msiobj_release(&view
->hdr
);
6994 static UINT
ITERATE_RemoveEnvironmentString( MSIRECORD
*rec
, LPVOID param
)
6996 MSIPACKAGE
*package
= param
;
6997 LPCWSTR name
, value
, component
;
6998 WCHAR
*p
, *q
, *deformatted
= NULL
, *new_value
= NULL
;
6999 DWORD flags
, type
, size
, len
, len_value
= 0, len_new_value
;
7007 component
= MSI_RecordGetString( rec
, 4 );
7008 comp
= msi_get_loaded_component( package
, component
);
7010 return ERROR_SUCCESS
;
7012 comp
->Action
= msi_get_component_action( package
, comp
);
7013 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
7015 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
7016 return ERROR_SUCCESS
;
7018 name
= MSI_RecordGetString( rec
, 2 );
7019 value
= MSI_RecordGetString( rec
, 3 );
7021 TRACE("name %s value %s\n", debugstr_w(name
), debugstr_w(value
));
7023 r
= env_parse_flags( &name
, &value
, &flags
);
7024 if (r
!= ERROR_SUCCESS
)
7027 if (!(flags
& ENV_ACT_REMOVE
))
7029 TRACE("Environment variable %s not marked for removal\n", debugstr_w(name
));
7030 return ERROR_SUCCESS
;
7035 DWORD len
= deformat_string( package
, value
, &deformatted
);
7038 res
= ERROR_OUTOFMEMORY
;
7044 value
= deformatted
;
7045 if (flags
& ENV_MOD_PREFIX
)
7047 p
= wcsrchr( value
, ';' );
7048 len_value
= p
- value
;
7050 else if (flags
& ENV_MOD_APPEND
)
7052 value
= wcschr( value
, ';' ) + 1;
7053 len_value
= lstrlenW( value
);
7055 else len_value
= lstrlenW( value
);
7063 r
= open_env_key( flags
, &env
);
7064 if (r
!= ERROR_SUCCESS
)
7070 if (flags
& ENV_MOD_MACHINE
)
7071 action
|= 0x20000000;
7075 res
= RegQueryValueExW( env
, name
, NULL
, &type
, NULL
, &size
);
7076 if (res
!= ERROR_SUCCESS
|| (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
))
7079 if (!(new_value
= msi_alloc( size
))) goto done
;
7081 res
= RegQueryValueExW( env
, name
, NULL
, &type
, (BYTE
*)new_value
, &size
);
7082 if (res
!= ERROR_SUCCESS
)
7085 len_new_value
= size
/ sizeof(WCHAR
) - 1;
7089 while (*q
&& *q
!= ';') q
++;
7091 if (value
&& len
== len_value
&& !memcmp( value
, p
, len
* sizeof(WCHAR
) ))
7094 memmove( p
, q
, (len_new_value
- (q
- new_value
) + 1) * sizeof(WCHAR
) );
7101 if (!new_value
[0] || !value
)
7103 TRACE("removing %s\n", debugstr_w(name
));
7104 res
= RegDeleteValueW( env
, name
);
7105 if (res
!= ERROR_SUCCESS
)
7106 WARN( "failed to delete value %s (%ld)\n", debugstr_w(name
), res
);
7110 TRACE("setting %s to %s\n", debugstr_w(name
), debugstr_w(new_value
));
7111 size
= (lstrlenW( new_value
) + 1) * sizeof(WCHAR
);
7112 res
= RegSetValueExW( env
, name
, 0, type
, (BYTE
*)new_value
, size
);
7113 if (res
!= ERROR_SUCCESS
)
7114 WARN( "failed to set %s to %s (%ld)\n", debugstr_w(name
), debugstr_w(new_value
), res
);
7118 uirow
= MSI_CreateRecord( 3 );
7119 MSI_RecordSetStringW( uirow
, 1, name
);
7120 MSI_RecordSetStringW( uirow
, 2, value
);
7121 MSI_RecordSetInteger( uirow
, 3, action
);
7122 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
7123 msiobj_release( &uirow
->hdr
);
7125 if (env
) RegCloseKey( env
);
7126 msi_free( deformatted
);
7127 msi_free( new_value
);
7131 static UINT
ACTION_RemoveEnvironmentStrings( MSIPACKAGE
*package
)
7136 if (package
->script
== SCRIPT_NONE
)
7137 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RemoveEnvironmentStrings");
7139 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Environment`", &view
);
7140 if (rc
!= ERROR_SUCCESS
)
7141 return ERROR_SUCCESS
;
7143 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveEnvironmentString
, package
);
7144 msiobj_release( &view
->hdr
);
7148 UINT
msi_validate_product_id( MSIPACKAGE
*package
)
7150 LPWSTR key
, template, id
;
7151 UINT r
= ERROR_SUCCESS
;
7153 id
= msi_dup_property( package
->db
, L
"ProductID" );
7157 return ERROR_SUCCESS
;
7159 template = msi_dup_property( package
->db
, L
"PIDTemplate" );
7160 key
= msi_dup_property( package
->db
, L
"PIDKEY" );
7161 if (key
&& template)
7163 FIXME( "partial stub: template %s key %s\n", debugstr_w(template), debugstr_w(key
) );
7165 WARN("Product key validation HACK, see CORE-14710\n");
7167 r
= msi_set_property( package
->db
, L
"ProductID", key
, -1 );
7170 msi_free( template );
7175 static UINT
ACTION_ValidateProductID( MSIPACKAGE
*package
)
7177 return msi_validate_product_id( package
);
7180 static UINT
ACTION_ScheduleReboot( MSIPACKAGE
*package
)
7183 package
->need_reboot_at_end
= 1;
7184 return ERROR_SUCCESS
;
7187 static UINT
ACTION_AllocateRegistrySpace( MSIPACKAGE
*package
)
7190 int space
= msi_get_property_int( package
->db
, L
"AVAILABLEFREEREG", 0 );
7192 TRACE("%p %d kilobytes\n", package
, space
);
7194 uirow
= MSI_CreateRecord( 1 );
7195 MSI_RecordSetInteger( uirow
, 1, space
);
7196 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
7197 msiobj_release( &uirow
->hdr
);
7199 return ERROR_SUCCESS
;
7202 static UINT
ACTION_DisableRollback( MSIPACKAGE
*package
)
7204 TRACE("%p\n", package
);
7206 msi_set_property( package
->db
, L
"RollbackDisabled", L
"1", -1 );
7207 return ERROR_SUCCESS
;
7210 static UINT
ACTION_InstallAdminPackage( MSIPACKAGE
*package
)
7212 FIXME("%p\n", package
);
7213 return ERROR_SUCCESS
;
7216 static UINT
ACTION_SetODBCFolders( MSIPACKAGE
*package
)
7222 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `ODBCDriver`", &view
);
7223 if (r
== ERROR_SUCCESS
)
7226 r
= MSI_IterateRecords( view
, &count
, NULL
, package
);
7227 msiobj_release( &view
->hdr
);
7228 if (r
!= ERROR_SUCCESS
)
7230 if (count
) FIXME( "ignored %lu rows in ODBCDriver table\n", count
);
7232 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `ODBCTranslator`", &view
);
7233 if (r
== ERROR_SUCCESS
)
7236 r
= MSI_IterateRecords( view
, &count
, NULL
, package
);
7237 msiobj_release( &view
->hdr
);
7238 if (r
!= ERROR_SUCCESS
)
7240 if (count
) FIXME( "ignored %lu rows in ODBCTranslator table\n", count
);
7242 return ERROR_SUCCESS
;
7245 static UINT
ITERATE_RemoveExistingProducts( MSIRECORD
*rec
, LPVOID param
)
7247 MSIPACKAGE
*package
= param
;
7248 const WCHAR
*property
= MSI_RecordGetString( rec
, 7 );
7249 int attrs
= MSI_RecordGetInteger( rec
, 5 );
7250 UINT len
= ARRAY_SIZE( L
"msiexec /qn /i %s REMOVE=%s" );
7251 WCHAR
*product
, *features
, *cmd
;
7253 PROCESS_INFORMATION info
;
7256 if (attrs
& msidbUpgradeAttributesOnlyDetect
) return ERROR_SUCCESS
;
7257 if (!(product
= msi_dup_property( package
->db
, property
))) return ERROR_SUCCESS
;
7259 deformat_string( package
, MSI_RecordGetString( rec
, 6 ), &features
);
7261 len
+= lstrlenW( product
);
7263 len
+= lstrlenW( features
);
7265 len
+= ARRAY_SIZE( L
"ALL" );
7267 if (!(cmd
= msi_alloc( len
* sizeof(WCHAR
) )))
7269 msi_free( product
);
7270 msi_free( features
);
7271 return ERROR_OUTOFMEMORY
;
7273 swprintf( cmd
, len
, L
"msiexec /qn /i %s REMOVE=%s", product
, features
? features
: L
"ALL" );
7274 msi_free( product
);
7275 msi_free( features
);
7277 memset( &si
, 0, sizeof(STARTUPINFOW
) );
7278 ret
= CreateProcessW( NULL
, cmd
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &info
);
7280 if (!ret
) return GetLastError();
7281 CloseHandle( info
.hThread
);
7283 WaitForSingleObject( info
.hProcess
, INFINITE
);
7284 CloseHandle( info
.hProcess
);
7285 return ERROR_SUCCESS
;
7288 static UINT
ACTION_RemoveExistingProducts( MSIPACKAGE
*package
)
7293 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Upgrade`", &view
);
7294 if (r
== ERROR_SUCCESS
)
7296 r
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveExistingProducts
, package
);
7297 msiobj_release( &view
->hdr
);
7298 if (r
!= ERROR_SUCCESS
)
7301 return ERROR_SUCCESS
;
7304 static UINT
ITERATE_MigrateFeatureStates( MSIRECORD
*rec
, LPVOID param
)
7306 MSIPACKAGE
*package
= param
;
7307 int attributes
= MSI_RecordGetInteger( rec
, 5 );
7309 if (attributes
& msidbUpgradeAttributesMigrateFeatures
)
7311 const WCHAR
*upgrade_code
= MSI_RecordGetString( rec
, 1 );
7312 const WCHAR
*version_min
= MSI_RecordGetString( rec
, 2 );
7313 const WCHAR
*version_max
= MSI_RecordGetString( rec
, 3 );
7314 const WCHAR
*language
= MSI_RecordGetString( rec
, 4 );
7318 if (package
->Context
== MSIINSTALLCONTEXT_MACHINE
)
7320 r
= MSIREG_OpenClassesUpgradeCodesKey( upgrade_code
, &hkey
, FALSE
);
7321 if (r
!= ERROR_SUCCESS
)
7322 return ERROR_SUCCESS
;
7326 r
= MSIREG_OpenUserUpgradeCodesKey( upgrade_code
, &hkey
, FALSE
);
7327 if (r
!= ERROR_SUCCESS
)
7328 return ERROR_SUCCESS
;
7330 RegCloseKey( hkey
);
7332 FIXME("migrate feature states from %s version min %s version max %s language %s\n",
7333 debugstr_w(upgrade_code
), debugstr_w(version_min
),
7334 debugstr_w(version_max
), debugstr_w(language
));
7336 return ERROR_SUCCESS
;
7339 static UINT
ACTION_MigrateFeatureStates( MSIPACKAGE
*package
)
7344 if (msi_get_property_int( package
->db
, L
"Installed", 0 ))
7346 TRACE("product is installed, skipping action\n");
7347 return ERROR_SUCCESS
;
7349 if (msi_get_property_int( package
->db
, L
"Preselected", 0 ))
7351 TRACE("Preselected property is set, not migrating feature states\n");
7352 return ERROR_SUCCESS
;
7354 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Upgrade`", &view
);
7355 if (r
== ERROR_SUCCESS
)
7357 r
= MSI_IterateRecords( view
, NULL
, ITERATE_MigrateFeatureStates
, package
);
7358 msiobj_release( &view
->hdr
);
7359 if (r
!= ERROR_SUCCESS
)
7362 return ERROR_SUCCESS
;
7365 static BOOL
msi_bind_image( MSIPACKAGE
*package
, const char *filename
, const char *path
)
7368 msi_disable_fs_redirection( package
);
7369 ret
= BindImage( filename
, path
, NULL
);
7370 msi_revert_fs_redirection( package
);
7374 static void bind_image( MSIPACKAGE
*package
, const char *filename
, const char *path
)
7376 if (!msi_bind_image( package
, filename
, path
))
7378 WARN( "failed to bind image %lu\n", GetLastError() );
7382 static UINT
ITERATE_BindImage( MSIRECORD
*rec
, LPVOID param
)
7386 MSIPACKAGE
*package
= param
;
7387 const WCHAR
*key
= MSI_RecordGetString( rec
, 1 );
7388 const WCHAR
*paths
= MSI_RecordGetString( rec
, 2 );
7389 char *filenameA
, *pathA
;
7390 WCHAR
*pathW
, **path_list
;
7392 if (!(file
= msi_get_loaded_file( package
, key
)))
7394 WARN("file %s not found\n", debugstr_w(key
));
7395 return ERROR_SUCCESS
;
7397 if (!(filenameA
= strdupWtoA( file
->TargetPath
))) return ERROR_SUCCESS
;
7399 path_list
= msi_split_string( paths
, ';' );
7400 if (!path_list
) bind_image( package
, filenameA
, NULL
);
7403 for (i
= 0; path_list
[i
] && path_list
[i
][0]; i
++)
7405 deformat_string( package
, path_list
[i
], &pathW
);
7406 if ((pathA
= strdupWtoA( pathW
)))
7408 bind_image( package
, filenameA
, pathA
);
7414 msi_free( path_list
);
7415 msi_free( filenameA
);
7417 return ERROR_SUCCESS
;
7420 static UINT
ACTION_BindImage( MSIPACKAGE
*package
)
7425 r
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `BindImage`", &view
);
7426 if (r
== ERROR_SUCCESS
)
7428 MSI_IterateRecords( view
, NULL
, ITERATE_BindImage
, package
);
7429 msiobj_release( &view
->hdr
);
7431 return ERROR_SUCCESS
;
7434 static UINT
msi_unimplemented_action_stub( MSIPACKAGE
*package
, LPCSTR action
, LPCWSTR table
)
7440 r
= MSI_OpenQuery( package
->db
, &view
, L
"SELECT * FROM `%s`", table
);
7441 if (r
== ERROR_SUCCESS
)
7443 r
= MSI_IterateRecords(view
, &count
, NULL
, package
);
7444 msiobj_release(&view
->hdr
);
7445 if (r
!= ERROR_SUCCESS
)
7448 if (count
) FIXME( "%s: ignored %lu rows from %s\n", action
, count
, debugstr_w(table
) );
7449 return ERROR_SUCCESS
;
7452 static UINT
ACTION_IsolateComponents( MSIPACKAGE
*package
)
7454 return msi_unimplemented_action_stub( package
, "IsolateComponents", L
"IsolateComponent" );
7457 static UINT
ACTION_RMCCPSearch( MSIPACKAGE
*package
)
7459 return msi_unimplemented_action_stub( package
, "RMCCPSearch", L
"CCPSearch" );
7462 static UINT
ACTION_RegisterComPlus( MSIPACKAGE
*package
)
7464 return msi_unimplemented_action_stub( package
, "RegisterComPlus", L
"Complus" );
7467 static UINT
ACTION_UnregisterComPlus( MSIPACKAGE
*package
)
7469 return msi_unimplemented_action_stub( package
, "UnregisterComPlus", L
"Complus" );
7472 static UINT
ACTION_InstallSFPCatalogFile( MSIPACKAGE
*package
)
7474 return msi_unimplemented_action_stub( package
, "InstallSFPCatalogFile", L
"SFPCatalog" );
7479 const WCHAR
*action
;
7480 const UINT description
;
7481 const UINT
template;
7482 UINT (*handler
)(MSIPACKAGE
*);
7483 const WCHAR
*action_rollback
;
7487 { L
"AllocateRegistrySpace", IDS_DESC_ALLOCATEREGISTRYSPACE
, IDS_TEMP_ALLOCATEREGISTRYSPACE
, ACTION_AllocateRegistrySpace
, NULL
},
7488 { L
"AppSearch", IDS_DESC_APPSEARCH
, IDS_TEMP_APPSEARCH
, ACTION_AppSearch
, NULL
},
7489 { L
"BindImage", IDS_DESC_BINDIMAGE
, IDS_TEMP_BINDIMAGE
, ACTION_BindImage
, NULL
},
7490 { L
"CCPSearch", IDS_DESC_CCPSEARCH
, 0, ACTION_CCPSearch
, NULL
},
7491 { L
"CostFinalize", IDS_DESC_COSTFINALIZE
, 0, ACTION_CostFinalize
, NULL
},
7492 { L
"CostInitialize", IDS_DESC_COSTINITIALIZE
, 0, ACTION_CostInitialize
, NULL
},
7493 { L
"CreateFolders", IDS_DESC_CREATEFOLDERS
, IDS_TEMP_CREATEFOLDERS
, ACTION_CreateFolders
, L
"RemoveFolders" },
7494 { L
"CreateShortcuts", IDS_DESC_CREATESHORTCUTS
, IDS_TEMP_CREATESHORTCUTS
, ACTION_CreateShortcuts
, L
"RemoveShortcuts" },
7495 { L
"DeleteServices", IDS_DESC_DELETESERVICES
, IDS_TEMP_DELETESERVICES
, ACTION_DeleteServices
, L
"InstallServices" },
7496 { L
"DisableRollback", 0, 0, ACTION_DisableRollback
, NULL
},
7497 { L
"DuplicateFiles", IDS_DESC_DUPLICATEFILES
, IDS_TEMP_DUPLICATEFILES
, ACTION_DuplicateFiles
, L
"RemoveDuplicateFiles" },
7498 { L
"ExecuteAction", 0, 0, ACTION_ExecuteAction
, NULL
},
7499 { L
"FileCost", IDS_DESC_FILECOST
, 0, ACTION_FileCost
, NULL
},
7500 { L
"FindRelatedProducts", IDS_DESC_FINDRELATEDPRODUCTS
, IDS_TEMP_FINDRELATEDPRODUCTS
, ACTION_FindRelatedProducts
, NULL
},
7501 { L
"ForceReboot", 0, 0, ACTION_ForceReboot
, NULL
},
7502 { L
"InstallAdminPackage", IDS_DESC_INSTALLADMINPACKAGE
, IDS_TEMP_INSTALLADMINPACKAGE
, ACTION_InstallAdminPackage
, NULL
},
7503 { L
"InstallExecute", 0, 0, ACTION_InstallExecute
, NULL
},
7504 { L
"InstallExecuteAgain", 0, 0, ACTION_InstallExecute
, NULL
},
7505 { L
"InstallFiles", IDS_DESC_INSTALLFILES
, IDS_TEMP_INSTALLFILES
, ACTION_InstallFiles
, L
"RemoveFiles" },
7506 { L
"InstallFinalize", 0, 0, ACTION_InstallFinalize
, NULL
},
7507 { L
"InstallInitialize", 0, 0, ACTION_InstallInitialize
, NULL
},
7508 { L
"InstallODBC", IDS_DESC_INSTALLODBC
, 0, ACTION_InstallODBC
, L
"RemoveODBC" },
7509 { L
"InstallServices", IDS_DESC_INSTALLSERVICES
, IDS_TEMP_INSTALLSERVICES
, ACTION_InstallServices
, L
"DeleteServices" },
7510 { L
"InstallSFPCatalogFile", IDS_DESC_INSTALLSFPCATALOGFILE
, IDS_TEMP_INSTALLSFPCATALOGFILE
, ACTION_InstallSFPCatalogFile
, NULL
},
7511 { L
"InstallValidate", IDS_DESC_INSTALLVALIDATE
, 0, ACTION_InstallValidate
, NULL
},
7512 { L
"IsolateComponents", 0, 0, ACTION_IsolateComponents
, NULL
},
7513 { L
"LaunchConditions", IDS_DESC_LAUNCHCONDITIONS
, 0, ACTION_LaunchConditions
, NULL
},
7514 { L
"MigrateFeutureStates", IDS_DESC_MIGRATEFEATURESTATES
, IDS_TEMP_MIGRATEFEATURESTATES
, ACTION_MigrateFeatureStates
, NULL
},
7515 { L
"MoveFiles", IDS_DESC_MOVEFILES
, IDS_TEMP_MOVEFILES
, ACTION_MoveFiles
, NULL
},
7516 { L
"MsiPublishAssemblies", IDS_DESC_MSIPUBLISHASSEMBLIES
, IDS_TEMP_MSIPUBLISHASSEMBLIES
, ACTION_MsiPublishAssemblies
, L
"MsiUnpublishAssemblies" },
7517 { L
"MsiUnpublishAssemblies", IDS_DESC_MSIUNPUBLISHASSEMBLIES
, IDS_TEMP_MSIUNPUBLISHASSEMBLIES
, ACTION_MsiUnpublishAssemblies
, L
"MsiPublishAssemblies" },
7518 { L
"PatchFiles", IDS_DESC_PATCHFILES
, IDS_TEMP_PATCHFILES
, ACTION_PatchFiles
, NULL
},
7519 { L
"ProcessComponents", IDS_DESC_PROCESSCOMPONENTS
, 0, ACTION_ProcessComponents
, L
"ProcessComponents" },
7520 { L
"PublishComponents", IDS_DESC_PUBLISHCOMPONENTS
, IDS_TEMP_PUBLISHCOMPONENTS
, ACTION_PublishComponents
, L
"UnpublishComponents" },
7521 { L
"PublishFeatures", IDS_DESC_PUBLISHFEATURES
, IDS_TEMP_PUBLISHFEATURES
, ACTION_PublishFeatures
, L
"UnpublishFeatures" },
7522 { L
"PublishProduct", IDS_DESC_PUBLISHPRODUCT
, 0, ACTION_PublishProduct
, L
"UnpublishProduct" },
7523 { L
"RegisterClassInfo", IDS_DESC_REGISTERCLASSINFO
, IDS_TEMP_REGISTERCLASSINFO
, ACTION_RegisterClassInfo
, L
"UnregisterClassInfo" },
7524 { L
"RegisterComPlus", IDS_DESC_REGISTERCOMPLUS
, IDS_TEMP_REGISTERCOMPLUS
, ACTION_RegisterComPlus
, L
"UnregisterComPlus" },
7525 { L
"RegisterExtensionInfo", IDS_DESC_REGISTEREXTENSIONINFO
, 0, ACTION_RegisterExtensionInfo
, L
"UnregisterExtensionInfo" },
7526 { L
"RegisterFonts", IDS_DESC_REGISTERFONTS
, IDS_TEMP_REGISTERFONTS
, ACTION_RegisterFonts
, L
"UnregisterFonts" },
7527 { L
"RegisterMIMEInfo", IDS_DESC_REGISTERMIMEINFO
, IDS_TEMP_REGISTERMIMEINFO
, ACTION_RegisterMIMEInfo
, L
"UnregisterMIMEInfo" },
7528 { L
"RegisterProduct", IDS_DESC_REGISTERPRODUCT
, 0, ACTION_RegisterProduct
, NULL
},
7529 { L
"RegisterProgIdInfo", IDS_DESC_REGISTERPROGIDINFO
, IDS_TEMP_REGISTERPROGIDINFO
, ACTION_RegisterProgIdInfo
, L
"UnregisterProgIdInfo" },
7530 { L
"RegisterTypeLibraries", IDS_DESC_REGISTERTYPELIBRARIES
, IDS_TEMP_REGISTERTYPELIBRARIES
, ACTION_RegisterTypeLibraries
, L
"UnregisterTypeLibraries" },
7531 { L
"RegisterUser", IDS_DESC_REGISTERUSER
, 0, ACTION_RegisterUser
, NULL
},
7532 { L
"RemoveDuplicateFiles", IDS_DESC_REMOVEDUPLICATEFILES
, IDS_TEMP_REMOVEDUPLICATEFILES
, ACTION_RemoveDuplicateFiles
, L
"DuplicateFiles" },
7533 { L
"RemoveEnvironmentStrings", IDS_DESC_REMOVEENVIRONMENTSTRINGS
, IDS_TEMP_REMOVEENVIRONMENTSTRINGS
, ACTION_RemoveEnvironmentStrings
, L
"WriteEnvironmentStrings" },
7534 { L
"RemoveExistingProducts", IDS_DESC_REMOVEEXISTINGPRODUCTS
, IDS_TEMP_REMOVEEXISTINGPRODUCTS
, ACTION_RemoveExistingProducts
, NULL
},
7535 { L
"RemoveFiles", IDS_DESC_REMOVEFILES
, IDS_TEMP_REMOVEFILES
, ACTION_RemoveFiles
, L
"InstallFiles" },
7536 { L
"RemoveFolders", IDS_DESC_REMOVEFOLDERS
, IDS_TEMP_REMOVEFOLDERS
, ACTION_RemoveFolders
, L
"CreateFolders" },
7537 { L
"RemoveIniValues", IDS_DESC_REMOVEINIVALUES
, IDS_TEMP_REMOVEINIVALUES
, ACTION_RemoveIniValues
, L
"WriteIniValues" },
7538 { L
"RemoveODBC", IDS_DESC_REMOVEODBC
, 0, ACTION_RemoveODBC
, L
"InstallODBC" },
7539 { L
"RemoveRegistryValues", IDS_DESC_REMOVEREGISTRYVALUES
, IDS_TEMP_REMOVEREGISTRYVALUES
, ACTION_RemoveRegistryValues
, L
"WriteRegistryValues" },
7540 { L
"RemoveShortcuts", IDS_DESC_REMOVESHORTCUTS
, IDS_TEMP_REMOVESHORTCUTS
, ACTION_RemoveShortcuts
, L
"CreateShortcuts" },
7541 { L
"ResolveSource", 0, 0, ACTION_ResolveSource
, NULL
},
7542 { L
"RMCCPSearch", IDS_DESC_RMCCPSEARCH
, 0, ACTION_RMCCPSearch
, NULL
},
7543 { L
"ScheduleReboot", 0, 0, ACTION_ScheduleReboot
, NULL
},
7544 { L
"SelfRegModules", IDS_DESC_SELFREGMODULES
, IDS_TEMP_SELFREGMODULES
, ACTION_SelfRegModules
, L
"SelfUnregModules" },
7545 { L
"SelfUnregModules", IDS_DESC_SELFUNREGMODULES
, IDS_TEMP_SELFUNREGMODULES
, ACTION_SelfUnregModules
, L
"SelfRegModules" },
7546 { L
"SetODBCFolders", IDS_DESC_SETODBCFOLDERS
, 0, ACTION_SetODBCFolders
, NULL
},
7547 { L
"StartServices", IDS_DESC_STARTSERVICES
, IDS_TEMP_STARTSERVICES
, ACTION_StartServices
, L
"StopServices" },
7548 { L
"StopServices", IDS_DESC_STOPSERVICES
, IDS_TEMP_STOPSERVICES
, ACTION_StopServices
, L
"StartServices" },
7549 { L
"UnpublishComponents", IDS_DESC_UNPUBLISHCOMPONENTS
, IDS_TEMP_UNPUBLISHCOMPONENTS
, ACTION_UnpublishComponents
, L
"PublishComponents" },
7550 { L
"UnpublishFeatures", IDS_DESC_UNPUBLISHFEATURES
, IDS_TEMP_UNPUBLISHFEATURES
, ACTION_UnpublishFeatures
, L
"PublishFeatures" },
7551 { L
"UnpublishProduct", IDS_DESC_UNPUBLISHPRODUCT
, 0, ACTION_UnpublishProduct
, NULL
}, /* for rollback only */
7552 { L
"UnregisterClassInfo", IDS_DESC_UNREGISTERCLASSINFO
, IDS_TEMP_UNREGISTERCLASSINFO
, ACTION_UnregisterClassInfo
, L
"RegisterClassInfo" },
7553 { L
"UnregisterComPlus", IDS_DESC_UNREGISTERCOMPLUS
, IDS_TEMP_UNREGISTERCOMPLUS
, ACTION_UnregisterComPlus
, L
"RegisterComPlus" },
7554 { L
"UnregisterExtensionInfo", IDS_DESC_UNREGISTEREXTENSIONINFO
, IDS_TEMP_UNREGISTEREXTENSIONINFO
, ACTION_UnregisterExtensionInfo
, L
"RegisterExtensionInfo" },
7555 { L
"UnregisterFonts", IDS_DESC_UNREGISTERFONTS
, IDS_TEMP_UNREGISTERFONTS
, ACTION_UnregisterFonts
, L
"RegisterFonts" },
7556 { L
"UnregisterMIMEInfo", IDS_DESC_UNREGISTERMIMEINFO
, IDS_TEMP_UNREGISTERMIMEINFO
, ACTION_UnregisterMIMEInfo
, L
"RegisterMIMEInfo" },
7557 { L
"UnregisterProgIdInfo", IDS_DESC_UNREGISTERPROGIDINFO
, IDS_TEMP_UNREGISTERPROGIDINFO
, ACTION_UnregisterProgIdInfo
, L
"RegisterProgIdInfo" },
7558 { L
"UnregisterTypeLibraries", IDS_DESC_UNREGISTERTYPELIBRARIES
, IDS_TEMP_UNREGISTERTYPELIBRARIES
, ACTION_UnregisterTypeLibraries
, L
"RegisterTypeLibraries" },
7559 { L
"ValidateProductID", 0, 0, ACTION_ValidateProductID
, NULL
},
7560 { L
"WriteEnvironmentStrings", IDS_DESC_WRITEENVIRONMENTSTRINGS
, IDS_TEMP_WRITEENVIRONMENTSTRINGS
, ACTION_WriteEnvironmentStrings
, L
"RemoveEnvironmentStrings" },
7561 { L
"WriteIniValues", IDS_DESC_WRITEINIVALUES
, IDS_TEMP_WRITEINIVALUES
, ACTION_WriteIniValues
, L
"RemoveIniValues" },
7562 { L
"WriteRegistryValues", IDS_DESC_WRITEREGISTRYVALUES
, IDS_TEMP_WRITEREGISTRYVALUES
, ACTION_WriteRegistryValues
, L
"RemoveRegistryValues" },
7563 { L
"INSTALL", 0, 0, ACTION_INSTALL
, NULL
},
7567 static UINT
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
)
7569 UINT rc
= ERROR_FUNCTION_NOT_CALLED
;
7573 while (StandardActions
[i
].action
!= NULL
)
7575 if (!wcscmp( StandardActions
[i
].action
, action
))
7577 WCHAR description
[100] = {0}, template[100] = {0};
7579 if (StandardActions
[i
].description
!= 0)
7580 LoadStringW(msi_hInstance
, StandardActions
[i
].description
, (LPWSTR
)&description
, 100);
7581 if (StandardActions
[i
].template != 0)
7582 LoadStringW(msi_hInstance
, StandardActions
[i
].template, (LPWSTR
)&template, 100);
7584 ui_actionstart(package
, action
, description
, template);
7585 if (StandardActions
[i
].handler
)
7587 ui_actioninfo( package
, action
, TRUE
, 0 );
7588 rc
= StandardActions
[i
].handler( package
);
7589 ui_actioninfo( package
, action
, FALSE
, !rc
);
7591 if (StandardActions
[i
].action_rollback
&& !package
->need_rollback
)
7593 TRACE("scheduling rollback action\n");
7594 msi_schedule_action( package
, SCRIPT_ROLLBACK
, StandardActions
[i
].action_rollback
);
7599 FIXME("unhandled standard action %s\n", debugstr_w(action
));
7610 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
)
7614 TRACE("Performing action (%s)\n", debugstr_w(action
));
7616 package
->action_progress_increment
= 0;
7617 rc
= ACTION_HandleStandardAction(package
, action
);
7619 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
7620 rc
= ACTION_HandleCustomAction(package
, action
);
7622 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
7623 WARN("unhandled msi action %s\n", debugstr_w(action
));
7628 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
)
7630 UINT rc
= ERROR_SUCCESS
;
7633 if (needs_ui_sequence(package
))
7634 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `InstallUISequence` WHERE `Sequence` = %d", seq
);
7636 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `InstallExecuteSequence` WHERE `Sequence` = %d", seq
);
7640 LPCWSTR action
, cond
;
7642 TRACE("Running the actions\n");
7644 /* check conditions */
7645 cond
= MSI_RecordGetString(row
, 2);
7647 /* this is a hack to skip errors in the condition code */
7648 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
7650 msiobj_release(&row
->hdr
);
7651 return ERROR_SUCCESS
;
7654 action
= MSI_RecordGetString(row
, 1);
7657 ERR("failed to fetch action\n");
7658 msiobj_release(&row
->hdr
);
7659 return ERROR_FUNCTION_FAILED
;
7662 rc
= ACTION_PerformAction(package
, action
);
7664 msiobj_release(&row
->hdr
);
7670 DWORD WINAPI
dummy_thread_proc(void *arg
)
7672 struct dummy_thread
*info
= arg
;
7675 hr
= CoInitializeEx(0, COINIT_MULTITHREADED
);
7676 if (FAILED(hr
)) ERR("CoInitializeEx failed %08x\n", hr
);
7678 SetEvent(info
->started
);
7679 WaitForSingleObject(info
->stopped
, INFINITE
);
7685 static void start_dummy_thread(struct dummy_thread
*info
)
7687 if (!(info
->started
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
))) return;
7688 if (!(info
->stopped
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
))) return;
7689 if (!(info
->thread
= CreateThread(NULL
, 0, dummy_thread_proc
, info
, 0, NULL
))) return;
7691 WaitForSingleObject(info
->started
, INFINITE
);
7694 static void stop_dummy_thread(struct dummy_thread
*info
)
7698 SetEvent(info
->stopped
);
7699 WaitForSingleObject(info
->thread
, INFINITE
);
7700 CloseHandle(info
->thread
);
7702 if (info
->started
) CloseHandle(info
->started
);
7703 if (info
->stopped
) CloseHandle(info
->stopped
);
7706 /****************************************************
7707 * TOP level entry points
7708 *****************************************************/
7710 UINT
MSI_InstallPackage( MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
7711 LPCWSTR szCommandLine
)
7713 WCHAR
*reinstall
= NULL
, *productcode
, *action
;
7714 struct dummy_thread thread_info
= {NULL
, NULL
, NULL
};
7723 dir
= strdupW(szPackagePath
);
7724 p
= wcsrchr(dir
, '\\');
7728 file
= szPackagePath
+ (p
- dir
);
7733 dir
= msi_alloc(MAX_PATH
* sizeof(WCHAR
));
7734 GetCurrentDirectoryW(MAX_PATH
, dir
);
7735 lstrcatW(dir
, L
"\\");
7736 file
= szPackagePath
;
7739 msi_free( package
->PackagePath
);
7740 package
->PackagePath
= msi_alloc((lstrlenW(dir
) + lstrlenW(file
) + 1) * sizeof(WCHAR
));
7741 if (!package
->PackagePath
)
7744 return ERROR_OUTOFMEMORY
;
7747 lstrcpyW(package
->PackagePath
, dir
);
7748 lstrcatW(package
->PackagePath
, file
);
7751 msi_set_sourcedir_props(package
, FALSE
);
7754 rc
= msi_parse_command_line( package
, szCommandLine
, FALSE
);
7755 if (rc
!= ERROR_SUCCESS
)
7758 msi_apply_transforms( package
);
7759 msi_apply_patches( package
);
7761 if (msi_get_property( package
->db
, L
"ACTION", NULL
, &len
))
7762 msi_set_property( package
->db
, L
"ACTION", L
"INSTALL", -1 );
7763 action
= msi_dup_property( package
->db
, L
"ACTION" );
7766 msi_set_original_database_property( package
->db
, szPackagePath
);
7767 msi_parse_command_line( package
, szCommandLine
, FALSE
);
7768 msi_adjust_privilege_properties( package
);
7769 msi_set_context( package
);
7771 start_dummy_thread(&thread_info
);
7773 productcode
= msi_dup_property( package
->db
, L
"ProductCode" );
7774 if (wcsicmp( productcode
, package
->ProductCode
))
7776 TRACE( "product code changed %s -> %s\n", debugstr_w(package
->ProductCode
), debugstr_w(productcode
) );
7777 msi_free( package
->ProductCode
);
7778 package
->ProductCode
= productcode
;
7780 else msi_free( productcode
);
7782 if (msi_get_property_int( package
->db
, L
"DISABLEROLLBACK", 0 ))
7784 TRACE("disabling rollback\n");
7785 msi_set_property( package
->db
, L
"RollbackDisabled", L
"1", -1 );
7788 rc
= ACTION_PerformAction(package
, action
);
7790 /* process the ending type action */
7791 if (rc
== ERROR_SUCCESS
)
7792 ACTION_PerformActionSequence(package
, -1);
7793 else if (rc
== ERROR_INSTALL_USEREXIT
)
7794 ACTION_PerformActionSequence(package
, -2);
7795 else if (rc
== ERROR_INSTALL_SUSPEND
)
7796 ACTION_PerformActionSequence(package
, -4);
7799 ACTION_PerformActionSequence(package
, -3);
7800 if (!msi_get_property_int( package
->db
, L
"RollbackDisabled", 0 ))
7802 package
->need_rollback
= TRUE
;
7806 /* finish up running custom actions */
7807 ACTION_FinishCustomActions(package
);
7809 stop_dummy_thread(&thread_info
);
7811 if (package
->need_rollback
&& !(reinstall
= msi_dup_property( package
->db
, L
"REINSTALL" )))
7813 WARN("installation failed, running rollback script\n");
7814 execute_script( package
, SCRIPT_ROLLBACK
);
7816 msi_free( reinstall
);
7819 if (rc
== ERROR_SUCCESS
&& package
->need_reboot_at_end
)
7820 return ERROR_SUCCESS_REBOOT_REQUIRED
;