2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 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
21 /* Msi top level apis directly related to installs */
30 #include "wine/debug.h"
37 #include "msiserver.h"
38 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi);
42 /***********************************************************************
43 * MsiDoActionA (MSI.@)
45 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
50 TRACE("%s\n", debugstr_a(szAction));
52 szwAction = strdupAtoW(szAction);
53 if (szAction && !szwAction)
54 return ERROR_FUNCTION_FAILED;
56 ret = MsiDoActionW( hInstall, szwAction );
57 msi_free( szwAction );
61 /***********************************************************************
62 * MsiDoActionW (MSI.@)
64 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
69 TRACE("%s\n",debugstr_w(szAction));
72 return ERROR_INVALID_PARAMETER;
74 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
79 IWineMsiRemotePackage *remote_package;
81 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
83 return ERROR_INVALID_HANDLE;
85 action = SysAllocString( szAction );
88 IWineMsiRemotePackage_Release( remote_package );
89 return ERROR_OUTOFMEMORY;
92 hr = IWineMsiRemotePackage_DoAction( remote_package, action );
94 SysFreeString( action );
95 IWineMsiRemotePackage_Release( remote_package );
99 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
100 return HRESULT_CODE(hr);
102 return ERROR_FUNCTION_FAILED;
105 return ERROR_SUCCESS;
108 ret = ACTION_PerformUIAction( package, szAction, -1 );
109 msiobj_release( &package->hdr );
114 /***********************************************************************
115 * MsiSequenceA (MSI.@)
117 UINT WINAPI MsiSequenceA( MSIHANDLE hInstall, LPCSTR szTable, INT iSequenceMode )
122 TRACE("%s\n", debugstr_a(szTable));
124 szwTable = strdupAtoW(szTable);
125 if (szTable && !szwTable)
126 return ERROR_FUNCTION_FAILED;
128 ret = MsiSequenceW( hInstall, szwTable, iSequenceMode );
129 msi_free( szwTable );
133 /***********************************************************************
134 * MsiSequenceW (MSI.@)
136 UINT WINAPI MsiSequenceW( MSIHANDLE hInstall, LPCWSTR szTable, INT iSequenceMode )
141 TRACE("%s\n", debugstr_w(szTable));
143 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
148 IWineMsiRemotePackage *remote_package;
150 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
152 return ERROR_INVALID_HANDLE;
154 table = SysAllocString( szTable );
157 IWineMsiRemotePackage_Release( remote_package );
158 return ERROR_OUTOFMEMORY;
161 hr = IWineMsiRemotePackage_Sequence( remote_package, table, iSequenceMode );
163 SysFreeString( table );
164 IWineMsiRemotePackage_Release( remote_package );
168 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
169 return HRESULT_CODE(hr);
171 return ERROR_FUNCTION_FAILED;
174 return ERROR_SUCCESS;
177 ret = MSI_Sequence( package, szTable, iSequenceMode );
178 msiobj_release( &package->hdr );
183 UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz )
185 UINT len, r = ERROR_SUCCESS;
187 if (awbuf->str.w && !sz )
188 return ERROR_INVALID_PARAMETER;
195 len = lstrlenW( str );
197 lstrcpynW( awbuf->str.w, str, *sz );
201 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
204 WideCharToMultiByte( CP_ACP, 0, str, -1, awbuf->str.a, *sz, NULL, NULL );
205 if ( awbuf->str.a && *sz && (len >= *sz) )
206 awbuf->str.a[*sz - 1] = 0;
209 if (awbuf->str.w && len >= *sz)
215 const WCHAR *msi_get_target_folder( MSIPACKAGE *package, const WCHAR *name )
217 MSIFOLDER *folder = msi_get_loaded_folder( package, name );
218 if (folder) return folder->ResolvedTarget;
222 /***********************************************************************
223 * MsiGetTargetPath (internal)
225 static UINT MSI_GetTargetPath( MSIHANDLE hInstall, LPCWSTR szFolder,
226 awstring *szPathBuf, LPDWORD pcchPathBuf )
230 UINT r = ERROR_FUNCTION_FAILED;
233 return ERROR_INVALID_PARAMETER;
235 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
239 IWineMsiRemotePackage *remote_package;
244 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
246 return ERROR_INVALID_HANDLE;
248 folder = SysAllocString( szFolder );
251 IWineMsiRemotePackage_Release( remote_package );
252 return ERROR_OUTOFMEMORY;
256 hr = IWineMsiRemotePackage_GetTargetPath( remote_package, folder, NULL, &len );
261 value = msi_alloc(len * sizeof(WCHAR));
264 r = ERROR_OUTOFMEMORY;
268 hr = IWineMsiRemotePackage_GetTargetPath( remote_package, folder, value, &len );
272 r = msi_strcpy_to_awstring( value, szPathBuf, pcchPathBuf );
275 IWineMsiRemotePackage_Release( remote_package );
276 SysFreeString( folder );
281 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
282 return HRESULT_CODE(hr);
284 return ERROR_FUNCTION_FAILED;
290 path = msi_get_target_folder( package, szFolder );
291 msiobj_release( &package->hdr );
294 return ERROR_DIRECTORY;
296 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
300 /***********************************************************************
301 * MsiGetTargetPathA (MSI.@)
303 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
304 LPSTR szPathBuf, LPDWORD pcchPathBuf )
310 TRACE("%s %p %p\n", debugstr_a(szFolder), szPathBuf, pcchPathBuf);
312 szwFolder = strdupAtoW(szFolder);
313 if (szFolder && !szwFolder)
314 return ERROR_FUNCTION_FAILED;
316 path.unicode = FALSE;
317 path.str.a = szPathBuf;
319 r = MSI_GetTargetPath( hInstall, szwFolder, &path, pcchPathBuf );
321 msi_free( szwFolder );
326 /***********************************************************************
327 * MsiGetTargetPathW (MSI.@)
329 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder,
330 LPWSTR szPathBuf, LPDWORD pcchPathBuf )
334 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf);
337 path.str.w = szPathBuf;
339 return MSI_GetTargetPath( hInstall, szFolder, &path, pcchPathBuf );
342 static WCHAR *get_source_root( MSIDATABASE *db )
346 if ((path = msi_dup_property( db, szSourceDir ))) return path;
347 if ((path = msi_dup_property( db, szDatabase )))
349 if ((p = strrchrW( path, '\\' ))) p[1] = 0;
354 WCHAR *msi_resolve_source_folder( MSIPACKAGE *package, const WCHAR *name, MSIFOLDER **folder )
357 LPWSTR p, path = NULL, parent;
359 TRACE("working to resolve %s\n", debugstr_w(name));
361 if (!strcmpW( name, szSourceDir )) name = szTargetDir;
362 if (!(f = msi_get_loaded_folder( package, name ))) return NULL;
364 /* special resolving for root dir */
365 if (!strcmpW( name, szTargetDir ) && !f->ResolvedSource)
367 f->ResolvedSource = get_source_root( package->db );
369 if (folder) *folder = f;
370 if (f->ResolvedSource)
372 path = strdupW( f->ResolvedSource );
373 TRACE(" already resolved to %s\n", debugstr_w(path));
376 if (!f->Parent) return path;
378 TRACE(" ! parent is %s\n", debugstr_w(parent));
380 p = msi_resolve_source_folder( package, parent, NULL );
382 if (package->WordCount & msidbSumInfoSourceTypeCompressed)
383 path = get_source_root( package->db );
384 else if (package->WordCount & msidbSumInfoSourceTypeSFN)
385 path = msi_build_directory_name( 3, p, f->SourceShortPath, NULL );
387 path = msi_build_directory_name( 3, p, f->SourceLongPath, NULL );
389 TRACE("-> %s\n", debugstr_w(path));
390 f->ResolvedSource = strdupW( path );
396 /***********************************************************************
397 * MSI_GetSourcePath (internal)
399 static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
400 awstring *szPathBuf, LPDWORD pcchPathBuf )
404 UINT r = ERROR_FUNCTION_FAILED;
406 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
409 return ERROR_INVALID_PARAMETER;
411 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
415 IWineMsiRemotePackage *remote_package;
420 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
422 return ERROR_INVALID_HANDLE;
424 folder = SysAllocString( szFolder );
427 IWineMsiRemotePackage_Release( remote_package );
428 return ERROR_OUTOFMEMORY;
432 hr = IWineMsiRemotePackage_GetSourcePath( remote_package, folder, NULL, &len );
437 value = msi_alloc(len * sizeof(WCHAR));
440 r = ERROR_OUTOFMEMORY;
444 hr = IWineMsiRemotePackage_GetSourcePath( remote_package, folder, value, &len );
448 r = msi_strcpy_to_awstring( value, szPathBuf, pcchPathBuf );
451 IWineMsiRemotePackage_Release( remote_package );
452 SysFreeString( folder );
457 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
458 return HRESULT_CODE(hr);
460 return ERROR_FUNCTION_FAILED;
466 if (szPathBuf->str.w && !pcchPathBuf )
468 msiobj_release( &package->hdr );
469 return ERROR_INVALID_PARAMETER;
472 path = msi_resolve_source_folder( package, szFolder, NULL );
473 msiobj_release( &package->hdr );
475 TRACE("path = %s\n", debugstr_w(path));
477 return ERROR_DIRECTORY;
479 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
484 /***********************************************************************
485 * MsiGetSourcePathA (MSI.@)
487 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
488 LPSTR szPathBuf, LPDWORD pcchPathBuf )
494 TRACE("%s %p %p\n", szFolder, debugstr_a(szPathBuf), pcchPathBuf);
497 str.str.a = szPathBuf;
499 folder = strdupAtoW( szFolder );
500 r = MSI_GetSourcePath( hInstall, folder, &str, pcchPathBuf );
506 /***********************************************************************
507 * MsiGetSourcePathW (MSI.@)
509 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder,
510 LPWSTR szPathBuf, LPDWORD pcchPathBuf )
514 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
517 str.str.w = szPathBuf;
519 return MSI_GetSourcePath( hInstall, szFolder, &str, pcchPathBuf );
522 /***********************************************************************
523 * MsiSetTargetPathA (MSI.@)
525 UINT WINAPI MsiSetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
526 LPCSTR szFolderPath )
528 LPWSTR szwFolder = NULL, szwFolderPath = NULL;
529 UINT rc = ERROR_OUTOFMEMORY;
531 if ( !szFolder || !szFolderPath )
532 return ERROR_INVALID_PARAMETER;
534 szwFolder = strdupAtoW(szFolder);
535 szwFolderPath = strdupAtoW(szFolderPath);
536 if (!szwFolder || !szwFolderPath)
539 rc = MsiSetTargetPathW( hInstall, szwFolder, szwFolderPath );
543 msi_free(szwFolderPath);
548 static void set_target_path( MSIPACKAGE *package, MSIFOLDER *folder, const WCHAR *path )
553 msi_free( folder->ResolvedTarget );
554 folder->ResolvedTarget = strdupW( path );
555 msi_clean_path( folder->ResolvedTarget );
556 msi_set_property( package->db, folder->Directory, folder->ResolvedTarget );
558 LIST_FOR_EACH_ENTRY( fl, &folder->children, FolderList, entry )
561 msi_resolve_target_folder( package, child->Directory, FALSE );
565 UINT MSI_SetTargetPathW( MSIPACKAGE *package, LPCWSTR szFolder, LPCWSTR szFolderPath )
571 TRACE("%p %s %s\n", package, debugstr_w(szFolder), debugstr_w(szFolderPath));
573 attrib = GetFileAttributesW(szFolderPath);
574 /* native MSI tests writeability by making temporary files at each drive */
575 if (attrib != INVALID_FILE_ATTRIBUTES &&
576 (attrib & FILE_ATTRIBUTE_OFFLINE || attrib & FILE_ATTRIBUTE_READONLY))
578 return ERROR_FUNCTION_FAILED;
580 if (!(folder = msi_get_loaded_folder( package, szFolder ))) return ERROR_DIRECTORY;
582 len = strlenW( szFolderPath );
583 if (len && szFolderPath[len - 1] != '\\')
585 WCHAR *path = msi_alloc( (len + 2) * sizeof(WCHAR) );
586 memcpy( path, szFolderPath, len * sizeof(WCHAR) );
589 set_target_path( package, folder, path );
592 else set_target_path( package, folder, szFolderPath );
594 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
597 MSICOMPONENT *comp = file->Component;
599 if (!comp->Enabled || (comp->assembly && !comp->assembly->application)) continue;
601 dir = msi_get_target_folder( package, comp->Directory );
602 msi_free( file->TargetPath );
603 file->TargetPath = msi_build_directory_name( 2, dir, file->FileName );
605 return ERROR_SUCCESS;
608 /***********************************************************************
609 * MsiSetTargetPathW (MSI.@)
611 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
612 LPCWSTR szFolderPath)
617 TRACE("%s %s\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
619 if ( !szFolder || !szFolderPath )
620 return ERROR_INVALID_PARAMETER;
622 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
627 IWineMsiRemotePackage *remote_package;
629 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
631 return ERROR_INVALID_HANDLE;
633 folder = SysAllocString( szFolder );
634 path = SysAllocString( szFolderPath );
635 if (!folder || !path)
637 SysFreeString(folder);
639 IWineMsiRemotePackage_Release( remote_package );
640 return ERROR_OUTOFMEMORY;
643 hr = IWineMsiRemotePackage_SetTargetPath( remote_package, folder, path );
645 SysFreeString(folder);
647 IWineMsiRemotePackage_Release( remote_package );
651 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
652 return HRESULT_CODE(hr);
654 return ERROR_FUNCTION_FAILED;
657 return ERROR_SUCCESS;
660 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
661 msiobj_release( &package->hdr );
665 /***********************************************************************
668 * Returns an internal installer state (if it is running in a mode iRunMode)
671 * hInstall [I] Handle to the installation
672 * hRunMode [I] Checking run mode
673 * MSIRUNMODE_ADMIN Administrative mode
674 * MSIRUNMODE_ADVERTISE Advertisement mode
675 * MSIRUNMODE_MAINTENANCE Maintenance mode
676 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
677 * MSIRUNMODE_LOGENABLED Log file is writing
678 * MSIRUNMODE_OPERATIONS Operations in progress??
679 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
680 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
681 * MSIRUNMODE_CABINET Files from cabinet are installed
682 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
683 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
684 * MSIRUNMODE_RESERVED11 Reserved
685 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
686 * MSIRUNMODE_ZAWENABLED Demand installation is supported
687 * MSIRUNMODE_RESERVED14 Reserved
688 * MSIRUNMODE_RESERVED15 Reserved
689 * MSIRUNMODE_SCHEDULED called from install script
690 * MSIRUNMODE_ROLLBACK called from rollback script
691 * MSIRUNMODE_COMMIT called from commit script
695 * Not in the state: FALSE
698 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
703 TRACE("%d %d\n", hInstall, iRunMode);
705 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
710 IWineMsiRemotePackage *remote_package;
712 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
716 hr = IWineMsiRemotePackage_GetMode(remote_package, iRunMode, &ret);
717 IWineMsiRemotePackage_Release(remote_package);
727 case MSIRUNMODE_WINDOWS9X:
728 if (GetVersion() & 0x80000000)
732 case MSIRUNMODE_OPERATIONS:
733 case MSIRUNMODE_RESERVED11:
734 case MSIRUNMODE_RESERVED14:
735 case MSIRUNMODE_RESERVED15:
738 case MSIRUNMODE_SCHEDULED:
739 r = package->scheduled_action_running;
742 case MSIRUNMODE_ROLLBACK:
743 r = package->rollback_action_running;
746 case MSIRUNMODE_COMMIT:
747 r = package->commit_action_running;
750 case MSIRUNMODE_MAINTENANCE:
751 r = msi_get_property_int( package->db, szInstalled, 0 ) != 0;
754 case MSIRUNMODE_REBOOTATEND:
755 r = package->need_reboot;
758 case MSIRUNMODE_LOGENABLED:
759 r = (package->log_file != INVALID_HANDLE_VALUE);
763 FIXME("unimplemented run mode: %d\n", iRunMode);
767 msiobj_release( &package->hdr );
771 /***********************************************************************
774 UINT WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
779 TRACE("%d %d %d\n", hInstall, iRunMode, fState);
781 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
785 IWineMsiRemotePackage *remote_package;
787 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
791 hr = IWineMsiRemotePackage_SetMode( remote_package, iRunMode, fState );
792 IWineMsiRemotePackage_Release( remote_package );
796 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
797 return HRESULT_CODE(hr);
799 return ERROR_FUNCTION_FAILED;
802 return ERROR_SUCCESS;
807 case MSIRUNMODE_REBOOTATEND:
808 package->need_reboot = 1;
812 case MSIRUNMODE_REBOOTNOW:
813 FIXME("unimplemented run mode: %d\n", iRunMode);
814 r = ERROR_FUNCTION_FAILED;
818 r = ERROR_ACCESS_DENIED;
821 msiobj_release( &package->hdr );
825 /***********************************************************************
826 * MsiSetFeatureStateA (MSI.@)
828 * According to the docs, when this is called it immediately recalculates
829 * all the component states as well
831 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
834 LPWSTR szwFeature = NULL;
837 szwFeature = strdupAtoW(szFeature);
840 return ERROR_FUNCTION_FAILED;
842 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
844 msi_free(szwFeature);
849 /* update component state based on a feature change */
850 void ACTION_UpdateComponentStates( MSIPACKAGE *package, MSIFEATURE *feature )
852 INSTALLSTATE newstate;
855 newstate = feature->ActionRequest;
856 if (newstate == INSTALLSTATE_ABSENT) newstate = INSTALLSTATE_UNKNOWN;
858 LIST_FOR_EACH_ENTRY(cl, &feature->Components, ComponentList, entry)
860 MSICOMPONENT *component = cl->component;
862 if (!component->Enabled) continue;
864 TRACE("Modifying (%d): Component %s (Installed %d, Action %d, Request %d)\n",
865 newstate, debugstr_w(component->Component), component->Installed,
866 component->Action, component->ActionRequest);
868 if (newstate == INSTALLSTATE_LOCAL)
870 component->Action = INSTALLSTATE_LOCAL;
871 component->ActionRequest = INSTALLSTATE_LOCAL;
875 ComponentList *clist;
878 component->hasLocalFeature = FALSE;
880 component->Action = newstate;
881 component->ActionRequest = newstate;
882 /* if any other feature wants it local we need to set it local */
883 LIST_FOR_EACH_ENTRY(f, &package->features, MSIFEATURE, entry)
885 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
886 f->ActionRequest != INSTALLSTATE_SOURCE )
890 LIST_FOR_EACH_ENTRY(clist, &f->Components, ComponentList, entry)
892 if (clist->component == component &&
893 (f->ActionRequest == INSTALLSTATE_LOCAL ||
894 f->ActionRequest == INSTALLSTATE_SOURCE))
896 TRACE("Saved by %s\n", debugstr_w(f->Feature));
897 component->hasLocalFeature = TRUE;
899 if (component->Attributes & msidbComponentAttributesOptional)
901 if (f->Attributes & msidbFeatureAttributesFavorSource)
903 component->Action = INSTALLSTATE_SOURCE;
904 component->ActionRequest = INSTALLSTATE_SOURCE;
908 component->Action = INSTALLSTATE_LOCAL;
909 component->ActionRequest = INSTALLSTATE_LOCAL;
912 else if (component->Attributes & msidbComponentAttributesSourceOnly)
914 component->Action = INSTALLSTATE_SOURCE;
915 component->ActionRequest = INSTALLSTATE_SOURCE;
919 component->Action = INSTALLSTATE_LOCAL;
920 component->ActionRequest = INSTALLSTATE_LOCAL;
926 TRACE("Result (%d): Component %s (Installed %d, Action %d, Request %d)\n",
927 newstate, debugstr_w(component->Component), component->Installed,
928 component->Action, component->ActionRequest);
932 UINT WINAPI MSI_SetFeatureStateW( MSIPACKAGE *package, LPCWSTR szFeature, INSTALLSTATE iState )
934 UINT rc = ERROR_SUCCESS;
935 MSIFEATURE *feature, *child;
937 TRACE("%s %i\n", debugstr_w(szFeature), iState);
939 feature = msi_get_loaded_feature( package, szFeature );
941 return ERROR_UNKNOWN_FEATURE;
943 if (iState == INSTALLSTATE_ADVERTISED &&
944 feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
945 return ERROR_FUNCTION_FAILED;
947 feature->ActionRequest = iState;
949 ACTION_UpdateComponentStates( package, feature );
951 /* update all the features that are children of this feature */
952 LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
954 if (child->Feature_Parent && !strcmpW( szFeature, child->Feature_Parent ))
955 MSI_SetFeatureStateW(package, child->Feature, iState);
961 /***********************************************************************
962 * MsiSetFeatureStateW (MSI.@)
964 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
968 UINT rc = ERROR_SUCCESS;
970 TRACE("%s %i\n",debugstr_w(szFeature), iState);
972 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
977 IWineMsiRemotePackage *remote_package;
979 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
981 return ERROR_INVALID_HANDLE;
983 feature = SysAllocString(szFeature);
986 IWineMsiRemotePackage_Release(remote_package);
987 return ERROR_OUTOFMEMORY;
990 hr = IWineMsiRemotePackage_SetFeatureState(remote_package, feature, iState);
992 SysFreeString(feature);
993 IWineMsiRemotePackage_Release(remote_package);
997 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
998 return HRESULT_CODE(hr);
1000 return ERROR_FUNCTION_FAILED;
1003 return ERROR_SUCCESS;
1006 rc = MSI_SetFeatureStateW(package,szFeature,iState);
1008 msiobj_release( &package->hdr );
1012 /***********************************************************************
1013 * MsiGetFeatureStateA (MSI.@)
1015 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
1016 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1018 LPWSTR szwFeature = NULL;
1021 szwFeature = strdupAtoW(szFeature);
1023 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
1025 msi_free( szwFeature);
1030 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPCWSTR szFeature,
1031 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1033 MSIFEATURE *feature;
1035 feature = msi_get_loaded_feature(package,szFeature);
1037 return ERROR_UNKNOWN_FEATURE;
1040 *piInstalled = feature->Installed;
1043 *piAction = feature->ActionRequest;
1045 TRACE("returning %i %i\n", feature->Installed, feature->ActionRequest);
1047 return ERROR_SUCCESS;
1050 /***********************************************************************
1051 * MsiGetFeatureStateW (MSI.@)
1053 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
1054 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1056 MSIPACKAGE* package;
1059 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled, piAction);
1061 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1066 IWineMsiRemotePackage *remote_package;
1068 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1069 if (!remote_package)
1070 return ERROR_INVALID_HANDLE;
1072 feature = SysAllocString(szFeature);
1075 IWineMsiRemotePackage_Release(remote_package);
1076 return ERROR_OUTOFMEMORY;
1079 hr = IWineMsiRemotePackage_GetFeatureState(remote_package, feature,
1080 piInstalled, piAction);
1082 SysFreeString(feature);
1083 IWineMsiRemotePackage_Release(remote_package);
1087 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1088 return HRESULT_CODE(hr);
1090 return ERROR_FUNCTION_FAILED;
1093 return ERROR_SUCCESS;
1096 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
1097 msiobj_release( &package->hdr );
1101 /***********************************************************************
1102 * MsiGetFeatureCostA (MSI.@)
1104 UINT WINAPI MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature,
1105 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1107 LPWSTR szwFeature = NULL;
1110 szwFeature = strdupAtoW(szFeature);
1112 rc = MsiGetFeatureCostW(hInstall, szwFeature, iCostTree, iState, piCost);
1114 msi_free(szwFeature);
1119 static INT feature_cost( MSIFEATURE *feature )
1124 LIST_FOR_EACH_ENTRY( comp, &feature->Components, MSICOMPONENT, entry )
1131 UINT MSI_GetFeatureCost( MSIPACKAGE *package, MSIFEATURE *feature, MSICOSTTREE tree,
1132 INSTALLSTATE state, LPINT cost )
1134 TRACE("%s, %u, %d, %p\n", debugstr_w(feature->Feature), tree, state, cost);
1139 case MSICOSTTREE_CHILDREN:
1143 LIST_FOR_EACH_ENTRY( child, &feature->Children, MSIFEATURE, entry )
1145 if (child->ActionRequest == state)
1146 *cost += feature_cost( child );
1150 case MSICOSTTREE_PARENTS:
1152 const WCHAR *feature_parent = feature->Feature_Parent;
1155 MSIFEATURE *parent = msi_get_loaded_feature( package, feature_parent );
1159 if (parent->ActionRequest == state)
1160 *cost += feature_cost( parent );
1162 feature_parent = parent->Feature_Parent;
1166 case MSICOSTTREE_SELFONLY:
1167 if (feature->ActionRequest == state)
1168 *cost = feature_cost( feature );
1172 WARN("unhandled cost tree %u\n", tree);
1177 return ERROR_SUCCESS;
1180 /***********************************************************************
1181 * MsiGetFeatureCostW (MSI.@)
1183 UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature,
1184 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1186 MSIPACKAGE *package;
1187 MSIFEATURE *feature;
1190 TRACE("(%d %s %i %i %p)\n", hInstall, debugstr_w(szFeature),
1191 iCostTree, iState, piCost);
1193 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1198 IWineMsiRemotePackage *remote_package;
1200 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1201 if (!remote_package)
1202 return ERROR_INVALID_HANDLE;
1204 feature = SysAllocString(szFeature);
1207 IWineMsiRemotePackage_Release(remote_package);
1208 return ERROR_OUTOFMEMORY;
1211 hr = IWineMsiRemotePackage_GetFeatureCost(remote_package, feature,
1212 iCostTree, iState, piCost);
1214 SysFreeString(feature);
1215 IWineMsiRemotePackage_Release(remote_package);
1219 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1220 return HRESULT_CODE(hr);
1222 return ERROR_FUNCTION_FAILED;
1225 return ERROR_SUCCESS;
1228 feature = msi_get_loaded_feature(package, szFeature);
1231 ret = MSI_GetFeatureCost(package, feature, iCostTree, iState, piCost);
1233 ret = ERROR_UNKNOWN_FEATURE;
1235 msiobj_release( &package->hdr );
1239 /***********************************************************************
1240 * MsiSetComponentStateA (MSI.@)
1242 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1243 INSTALLSTATE iState)
1246 LPWSTR szwComponent = strdupAtoW(szComponent);
1248 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
1250 msi_free(szwComponent);
1255 /***********************************************************************
1256 * MsiGetComponentStateA (MSI.@)
1258 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1259 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1261 LPWSTR szwComponent= NULL;
1264 szwComponent= strdupAtoW(szComponent);
1266 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
1268 msi_free( szwComponent);
1273 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1274 INSTALLSTATE iState)
1278 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
1280 comp = msi_get_loaded_component(package, szComponent);
1282 return ERROR_UNKNOWN_COMPONENT;
1285 comp->Action = iState;
1287 return ERROR_SUCCESS;
1290 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1291 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1295 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
1296 piInstalled, piAction);
1298 comp = msi_get_loaded_component(package,szComponent);
1300 return ERROR_UNKNOWN_COMPONENT;
1305 *piInstalled = comp->Installed;
1307 *piInstalled = INSTALLSTATE_UNKNOWN;
1313 *piAction = comp->Action;
1315 *piAction = INSTALLSTATE_UNKNOWN;
1318 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
1319 return ERROR_SUCCESS;
1322 /***********************************************************************
1323 * MsiSetComponentStateW (MSI.@)
1325 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1326 INSTALLSTATE iState)
1328 MSIPACKAGE* package;
1331 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1336 IWineMsiRemotePackage *remote_package;
1338 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1339 if (!remote_package)
1340 return ERROR_INVALID_HANDLE;
1342 component = SysAllocString(szComponent);
1345 IWineMsiRemotePackage_Release(remote_package);
1346 return ERROR_OUTOFMEMORY;
1349 hr = IWineMsiRemotePackage_SetComponentState(remote_package, component, iState);
1351 SysFreeString(component);
1352 IWineMsiRemotePackage_Release(remote_package);
1356 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1357 return HRESULT_CODE(hr);
1359 return ERROR_FUNCTION_FAILED;
1362 return ERROR_SUCCESS;
1365 ret = MSI_SetComponentStateW(package, szComponent, iState);
1366 msiobj_release(&package->hdr);
1370 /***********************************************************************
1371 * MsiGetComponentStateW (MSI.@)
1373 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1374 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1376 MSIPACKAGE* package;
1379 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szComponent),
1380 piInstalled, piAction);
1382 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1387 IWineMsiRemotePackage *remote_package;
1389 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1390 if (!remote_package)
1391 return ERROR_INVALID_HANDLE;
1393 component = SysAllocString(szComponent);
1396 IWineMsiRemotePackage_Release(remote_package);
1397 return ERROR_OUTOFMEMORY;
1400 hr = IWineMsiRemotePackage_GetComponentState(remote_package, component,
1401 piInstalled, piAction);
1403 SysFreeString(component);
1404 IWineMsiRemotePackage_Release(remote_package);
1408 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1409 return HRESULT_CODE(hr);
1411 return ERROR_FUNCTION_FAILED;
1414 return ERROR_SUCCESS;
1417 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
1418 msiobj_release( &package->hdr );
1422 /***********************************************************************
1423 * MsiGetLanguage (MSI.@)
1425 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
1427 MSIPACKAGE* package;
1430 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1435 IWineMsiRemotePackage *remote_package;
1437 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1438 if (!remote_package)
1439 return ERROR_INVALID_HANDLE;
1441 hr = IWineMsiRemotePackage_GetLanguage(remote_package, &lang);
1449 langid = msi_get_property_int( package->db, szProductLanguage, 0 );
1450 msiobj_release( &package->hdr );
1454 UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel )
1456 static const WCHAR fmt[] = { '%','d',0 };
1460 TRACE("%p %i\n", package, iInstallLevel);
1462 if (iInstallLevel > 32767)
1463 return ERROR_INVALID_PARAMETER;
1465 if (iInstallLevel < 1)
1466 return MSI_SetFeatureStates( package );
1468 sprintfW( level, fmt, iInstallLevel );
1469 r = msi_set_property( package->db, szInstallLevel, level );
1470 if ( r == ERROR_SUCCESS )
1471 r = MSI_SetFeatureStates( package );
1476 /***********************************************************************
1477 * MsiSetInstallLevel (MSI.@)
1479 UINT WINAPI MsiSetInstallLevel(MSIHANDLE hInstall, int iInstallLevel)
1481 MSIPACKAGE* package;
1484 TRACE("%d %i\n", hInstall, iInstallLevel);
1486 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1490 IWineMsiRemotePackage *remote_package;
1492 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1493 if (!remote_package)
1494 return ERROR_INVALID_HANDLE;
1496 hr = IWineMsiRemotePackage_SetInstallLevel(remote_package, iInstallLevel);
1498 IWineMsiRemotePackage_Release(remote_package);
1502 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1503 return HRESULT_CODE(hr);
1505 return ERROR_FUNCTION_FAILED;
1508 return ERROR_SUCCESS;
1511 r = MSI_SetInstallLevel( package, iInstallLevel );
1513 msiobj_release( &package->hdr );
1518 /***********************************************************************
1519 * MsiGetFeatureValidStatesW (MSI.@)
1521 UINT WINAPI MsiGetFeatureValidStatesW(MSIHANDLE hInstall, LPCWSTR szFeature,
1522 LPDWORD pInstallState)
1524 if(pInstallState) *pInstallState = 1<<INSTALLSTATE_LOCAL;
1525 FIXME("%d %s %p stub returning %d\n",
1526 hInstall, debugstr_w(szFeature), pInstallState, pInstallState ? *pInstallState : 0);
1528 return ERROR_SUCCESS;
1531 /***********************************************************************
1532 * MsiGetFeatureValidStatesA (MSI.@)
1534 UINT WINAPI MsiGetFeatureValidStatesA(MSIHANDLE hInstall, LPCSTR szFeature,
1535 LPDWORD pInstallState)
1538 LPWSTR szwFeature = strdupAtoW(szFeature);
1540 ret = MsiGetFeatureValidStatesW(hInstall, szwFeature, pInstallState);
1542 msi_free(szwFeature);