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 )
554 if (!(target_path = strdupW( path ))) return;
555 msi_clean_path( target_path );
556 if (strcmpW( target_path, folder->ResolvedTarget ))
558 msi_free( folder->ResolvedTarget );
559 folder->ResolvedTarget = target_path;
560 msi_set_property( package->db, folder->Directory, folder->ResolvedTarget );
562 LIST_FOR_EACH_ENTRY( fl, &folder->children, FolderList, entry )
565 msi_resolve_target_folder( package, child->Directory, FALSE );
568 else msi_free( target_path );
571 UINT MSI_SetTargetPathW( MSIPACKAGE *package, LPCWSTR szFolder, LPCWSTR szFolderPath )
577 TRACE("%p %s %s\n", package, debugstr_w(szFolder), debugstr_w(szFolderPath));
579 attrib = GetFileAttributesW(szFolderPath);
580 /* native MSI tests writeability by making temporary files at each drive */
581 if (attrib != INVALID_FILE_ATTRIBUTES &&
582 (attrib & FILE_ATTRIBUTE_OFFLINE || attrib & FILE_ATTRIBUTE_READONLY))
584 return ERROR_FUNCTION_FAILED;
586 if (!(folder = msi_get_loaded_folder( package, szFolder ))) return ERROR_DIRECTORY;
588 len = strlenW( szFolderPath );
589 if (len && szFolderPath[len - 1] != '\\')
591 WCHAR *path = msi_alloc( (len + 2) * sizeof(WCHAR) );
592 memcpy( path, szFolderPath, len * sizeof(WCHAR) );
595 set_target_path( package, folder, path );
598 else set_target_path( package, folder, szFolderPath );
600 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
603 MSICOMPONENT *comp = file->Component;
605 if (!comp->Enabled || (comp->assembly && !comp->assembly->application)) continue;
607 dir = msi_get_target_folder( package, comp->Directory );
608 msi_free( file->TargetPath );
609 file->TargetPath = msi_build_directory_name( 2, dir, file->FileName );
611 return ERROR_SUCCESS;
614 /***********************************************************************
615 * MsiSetTargetPathW (MSI.@)
617 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
618 LPCWSTR szFolderPath)
623 TRACE("%s %s\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
625 if ( !szFolder || !szFolderPath )
626 return ERROR_INVALID_PARAMETER;
628 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
633 IWineMsiRemotePackage *remote_package;
635 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
637 return ERROR_INVALID_HANDLE;
639 folder = SysAllocString( szFolder );
640 path = SysAllocString( szFolderPath );
641 if (!folder || !path)
643 SysFreeString(folder);
645 IWineMsiRemotePackage_Release( remote_package );
646 return ERROR_OUTOFMEMORY;
649 hr = IWineMsiRemotePackage_SetTargetPath( remote_package, folder, path );
651 SysFreeString(folder);
653 IWineMsiRemotePackage_Release( remote_package );
657 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
658 return HRESULT_CODE(hr);
660 return ERROR_FUNCTION_FAILED;
663 return ERROR_SUCCESS;
666 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
667 msiobj_release( &package->hdr );
671 /***********************************************************************
674 * Returns an internal installer state (if it is running in a mode iRunMode)
677 * hInstall [I] Handle to the installation
678 * hRunMode [I] Checking run mode
679 * MSIRUNMODE_ADMIN Administrative mode
680 * MSIRUNMODE_ADVERTISE Advertisement mode
681 * MSIRUNMODE_MAINTENANCE Maintenance mode
682 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
683 * MSIRUNMODE_LOGENABLED Log file is writing
684 * MSIRUNMODE_OPERATIONS Operations in progress??
685 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
686 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
687 * MSIRUNMODE_CABINET Files from cabinet are installed
688 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
689 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
690 * MSIRUNMODE_RESERVED11 Reserved
691 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
692 * MSIRUNMODE_ZAWENABLED Demand installation is supported
693 * MSIRUNMODE_RESERVED14 Reserved
694 * MSIRUNMODE_RESERVED15 Reserved
695 * MSIRUNMODE_SCHEDULED called from install script
696 * MSIRUNMODE_ROLLBACK called from rollback script
697 * MSIRUNMODE_COMMIT called from commit script
701 * Not in the state: FALSE
704 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
709 TRACE("%d %d\n", hInstall, iRunMode);
711 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
716 IWineMsiRemotePackage *remote_package;
718 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
722 hr = IWineMsiRemotePackage_GetMode(remote_package, iRunMode, &ret);
723 IWineMsiRemotePackage_Release(remote_package);
733 case MSIRUNMODE_ADMIN:
734 FIXME("no support for administrative installs\n");
737 case MSIRUNMODE_ADVERTISE:
738 FIXME("no support for advertised installs\n");
741 case MSIRUNMODE_WINDOWS9X:
742 if (GetVersion() & 0x80000000)
746 case MSIRUNMODE_OPERATIONS:
747 case MSIRUNMODE_RESERVED11:
748 case MSIRUNMODE_RESERVED14:
749 case MSIRUNMODE_RESERVED15:
752 case MSIRUNMODE_SCHEDULED:
753 r = package->scheduled_action_running;
756 case MSIRUNMODE_ROLLBACK:
757 r = package->rollback_action_running;
760 case MSIRUNMODE_COMMIT:
761 r = package->commit_action_running;
764 case MSIRUNMODE_MAINTENANCE:
765 r = msi_get_property_int( package->db, szInstalled, 0 ) != 0;
768 case MSIRUNMODE_ROLLBACKENABLED:
769 r = msi_get_property_int( package->db, szRollbackDisabled, 0 ) == 0;
772 case MSIRUNMODE_REBOOTATEND:
773 r = package->need_reboot;
776 case MSIRUNMODE_LOGENABLED:
777 r = (package->log_file != INVALID_HANDLE_VALUE);
781 FIXME("unimplemented run mode: %d\n", iRunMode);
785 msiobj_release( &package->hdr );
789 /***********************************************************************
792 UINT WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
797 TRACE("%d %d %d\n", hInstall, iRunMode, fState);
799 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
803 IWineMsiRemotePackage *remote_package;
805 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
809 hr = IWineMsiRemotePackage_SetMode( remote_package, iRunMode, fState );
810 IWineMsiRemotePackage_Release( remote_package );
814 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
815 return HRESULT_CODE(hr);
817 return ERROR_FUNCTION_FAILED;
820 return ERROR_SUCCESS;
825 case MSIRUNMODE_REBOOTATEND:
826 package->need_reboot = 1;
830 case MSIRUNMODE_REBOOTNOW:
831 FIXME("unimplemented run mode: %d\n", iRunMode);
832 r = ERROR_FUNCTION_FAILED;
836 r = ERROR_ACCESS_DENIED;
839 msiobj_release( &package->hdr );
843 /***********************************************************************
844 * MsiSetFeatureStateA (MSI.@)
846 * According to the docs, when this is called it immediately recalculates
847 * all the component states as well
849 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
852 LPWSTR szwFeature = NULL;
855 szwFeature = strdupAtoW(szFeature);
858 return ERROR_FUNCTION_FAILED;
860 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
862 msi_free(szwFeature);
867 /* update component state based on a feature change */
868 void ACTION_UpdateComponentStates( MSIPACKAGE *package, MSIFEATURE *feature )
870 INSTALLSTATE newstate;
873 newstate = feature->ActionRequest;
874 if (newstate == INSTALLSTATE_ABSENT) newstate = INSTALLSTATE_UNKNOWN;
876 LIST_FOR_EACH_ENTRY(cl, &feature->Components, ComponentList, entry)
878 MSICOMPONENT *component = cl->component;
880 if (!component->Enabled) continue;
882 TRACE("Modifying (%d): Component %s (Installed %d, Action %d, Request %d)\n",
883 newstate, debugstr_w(component->Component), component->Installed,
884 component->Action, component->ActionRequest);
886 if (newstate == INSTALLSTATE_LOCAL)
888 component->Action = INSTALLSTATE_LOCAL;
889 component->ActionRequest = INSTALLSTATE_LOCAL;
893 ComponentList *clist;
896 component->hasLocalFeature = FALSE;
898 component->Action = newstate;
899 component->ActionRequest = newstate;
900 /* if any other feature wants it local we need to set it local */
901 LIST_FOR_EACH_ENTRY(f, &package->features, MSIFEATURE, entry)
903 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
904 f->ActionRequest != INSTALLSTATE_SOURCE )
908 LIST_FOR_EACH_ENTRY(clist, &f->Components, ComponentList, entry)
910 if (clist->component == component &&
911 (f->ActionRequest == INSTALLSTATE_LOCAL ||
912 f->ActionRequest == INSTALLSTATE_SOURCE))
914 TRACE("Saved by %s\n", debugstr_w(f->Feature));
915 component->hasLocalFeature = TRUE;
917 if (component->Attributes & msidbComponentAttributesOptional)
919 if (f->Attributes & msidbFeatureAttributesFavorSource)
921 component->Action = INSTALLSTATE_SOURCE;
922 component->ActionRequest = INSTALLSTATE_SOURCE;
926 component->Action = INSTALLSTATE_LOCAL;
927 component->ActionRequest = INSTALLSTATE_LOCAL;
930 else if (component->Attributes & msidbComponentAttributesSourceOnly)
932 component->Action = INSTALLSTATE_SOURCE;
933 component->ActionRequest = INSTALLSTATE_SOURCE;
937 component->Action = INSTALLSTATE_LOCAL;
938 component->ActionRequest = INSTALLSTATE_LOCAL;
944 TRACE("Result (%d): Component %s (Installed %d, Action %d, Request %d)\n",
945 newstate, debugstr_w(component->Component), component->Installed,
946 component->Action, component->ActionRequest);
950 UINT WINAPI MSI_SetFeatureStateW( MSIPACKAGE *package, LPCWSTR szFeature, INSTALLSTATE iState )
952 UINT rc = ERROR_SUCCESS;
953 MSIFEATURE *feature, *child;
955 TRACE("%s %i\n", debugstr_w(szFeature), iState);
957 feature = msi_get_loaded_feature( package, szFeature );
959 return ERROR_UNKNOWN_FEATURE;
961 if (iState == INSTALLSTATE_ADVERTISED &&
962 feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
963 return ERROR_FUNCTION_FAILED;
965 feature->ActionRequest = iState;
967 ACTION_UpdateComponentStates( package, feature );
969 /* update all the features that are children of this feature */
970 LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
972 if (child->Feature_Parent && !strcmpW( szFeature, child->Feature_Parent ))
973 MSI_SetFeatureStateW(package, child->Feature, iState);
979 /***********************************************************************
980 * MsiSetFeatureStateW (MSI.@)
982 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
986 UINT rc = ERROR_SUCCESS;
988 TRACE("%s %i\n",debugstr_w(szFeature), iState);
990 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
995 IWineMsiRemotePackage *remote_package;
997 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
999 return ERROR_INVALID_HANDLE;
1001 feature = SysAllocString(szFeature);
1004 IWineMsiRemotePackage_Release(remote_package);
1005 return ERROR_OUTOFMEMORY;
1008 hr = IWineMsiRemotePackage_SetFeatureState(remote_package, feature, iState);
1010 SysFreeString(feature);
1011 IWineMsiRemotePackage_Release(remote_package);
1015 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1016 return HRESULT_CODE(hr);
1018 return ERROR_FUNCTION_FAILED;
1021 return ERROR_SUCCESS;
1024 rc = MSI_SetFeatureStateW(package,szFeature,iState);
1026 msiobj_release( &package->hdr );
1030 /***********************************************************************
1031 * MsiGetFeatureStateA (MSI.@)
1033 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
1034 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1036 LPWSTR szwFeature = NULL;
1039 szwFeature = strdupAtoW(szFeature);
1041 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
1043 msi_free( szwFeature);
1048 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPCWSTR szFeature,
1049 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1051 MSIFEATURE *feature;
1053 feature = msi_get_loaded_feature(package,szFeature);
1055 return ERROR_UNKNOWN_FEATURE;
1058 *piInstalled = feature->Installed;
1061 *piAction = feature->ActionRequest;
1063 TRACE("returning %i %i\n", feature->Installed, feature->ActionRequest);
1065 return ERROR_SUCCESS;
1068 /***********************************************************************
1069 * MsiGetFeatureStateW (MSI.@)
1071 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
1072 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1074 MSIPACKAGE* package;
1077 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled, piAction);
1079 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1084 IWineMsiRemotePackage *remote_package;
1086 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1087 if (!remote_package)
1088 return ERROR_INVALID_HANDLE;
1090 feature = SysAllocString(szFeature);
1093 IWineMsiRemotePackage_Release(remote_package);
1094 return ERROR_OUTOFMEMORY;
1097 hr = IWineMsiRemotePackage_GetFeatureState(remote_package, feature,
1098 piInstalled, piAction);
1100 SysFreeString(feature);
1101 IWineMsiRemotePackage_Release(remote_package);
1105 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1106 return HRESULT_CODE(hr);
1108 return ERROR_FUNCTION_FAILED;
1111 return ERROR_SUCCESS;
1114 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
1115 msiobj_release( &package->hdr );
1119 /***********************************************************************
1120 * MsiGetFeatureCostA (MSI.@)
1122 UINT WINAPI MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature,
1123 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1125 LPWSTR szwFeature = NULL;
1128 szwFeature = strdupAtoW(szFeature);
1130 rc = MsiGetFeatureCostW(hInstall, szwFeature, iCostTree, iState, piCost);
1132 msi_free(szwFeature);
1137 static INT feature_cost( MSIFEATURE *feature )
1142 LIST_FOR_EACH_ENTRY( comp, &feature->Components, MSICOMPONENT, entry )
1149 UINT MSI_GetFeatureCost( MSIPACKAGE *package, MSIFEATURE *feature, MSICOSTTREE tree,
1150 INSTALLSTATE state, LPINT cost )
1152 TRACE("%s, %u, %d, %p\n", debugstr_w(feature->Feature), tree, state, cost);
1157 case MSICOSTTREE_CHILDREN:
1161 LIST_FOR_EACH_ENTRY( child, &feature->Children, MSIFEATURE, entry )
1163 if (child->ActionRequest == state)
1164 *cost += feature_cost( child );
1168 case MSICOSTTREE_PARENTS:
1170 const WCHAR *feature_parent = feature->Feature_Parent;
1173 MSIFEATURE *parent = msi_get_loaded_feature( package, feature_parent );
1177 if (parent->ActionRequest == state)
1178 *cost += feature_cost( parent );
1180 feature_parent = parent->Feature_Parent;
1184 case MSICOSTTREE_SELFONLY:
1185 if (feature->ActionRequest == state)
1186 *cost = feature_cost( feature );
1190 WARN("unhandled cost tree %u\n", tree);
1195 return ERROR_SUCCESS;
1198 /***********************************************************************
1199 * MsiGetFeatureCostW (MSI.@)
1201 UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature,
1202 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1204 MSIPACKAGE *package;
1205 MSIFEATURE *feature;
1208 TRACE("(%d %s %i %i %p)\n", hInstall, debugstr_w(szFeature),
1209 iCostTree, iState, piCost);
1211 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1216 IWineMsiRemotePackage *remote_package;
1218 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1219 if (!remote_package)
1220 return ERROR_INVALID_HANDLE;
1222 feature = SysAllocString(szFeature);
1225 IWineMsiRemotePackage_Release(remote_package);
1226 return ERROR_OUTOFMEMORY;
1229 hr = IWineMsiRemotePackage_GetFeatureCost(remote_package, feature,
1230 iCostTree, iState, piCost);
1232 SysFreeString(feature);
1233 IWineMsiRemotePackage_Release(remote_package);
1237 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1238 return HRESULT_CODE(hr);
1240 return ERROR_FUNCTION_FAILED;
1243 return ERROR_SUCCESS;
1246 feature = msi_get_loaded_feature(package, szFeature);
1249 ret = MSI_GetFeatureCost(package, feature, iCostTree, iState, piCost);
1251 ret = ERROR_UNKNOWN_FEATURE;
1253 msiobj_release( &package->hdr );
1257 /***********************************************************************
1258 * MsiSetComponentStateA (MSI.@)
1260 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1261 INSTALLSTATE iState)
1264 LPWSTR szwComponent = strdupAtoW(szComponent);
1266 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
1268 msi_free(szwComponent);
1273 /***********************************************************************
1274 * MsiGetComponentStateA (MSI.@)
1276 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1277 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1279 LPWSTR szwComponent= NULL;
1282 szwComponent= strdupAtoW(szComponent);
1284 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
1286 msi_free( szwComponent);
1291 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1292 INSTALLSTATE iState)
1296 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
1298 comp = msi_get_loaded_component(package, szComponent);
1300 return ERROR_UNKNOWN_COMPONENT;
1303 comp->Action = iState;
1305 return ERROR_SUCCESS;
1308 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1309 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1313 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
1314 piInstalled, piAction);
1316 comp = msi_get_loaded_component(package,szComponent);
1318 return ERROR_UNKNOWN_COMPONENT;
1323 *piInstalled = comp->Installed;
1325 *piInstalled = INSTALLSTATE_UNKNOWN;
1331 *piAction = comp->Action;
1333 *piAction = INSTALLSTATE_UNKNOWN;
1336 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
1337 return ERROR_SUCCESS;
1340 /***********************************************************************
1341 * MsiSetComponentStateW (MSI.@)
1343 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1344 INSTALLSTATE iState)
1346 MSIPACKAGE* package;
1349 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1354 IWineMsiRemotePackage *remote_package;
1356 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1357 if (!remote_package)
1358 return ERROR_INVALID_HANDLE;
1360 component = SysAllocString(szComponent);
1363 IWineMsiRemotePackage_Release(remote_package);
1364 return ERROR_OUTOFMEMORY;
1367 hr = IWineMsiRemotePackage_SetComponentState(remote_package, component, iState);
1369 SysFreeString(component);
1370 IWineMsiRemotePackage_Release(remote_package);
1374 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1375 return HRESULT_CODE(hr);
1377 return ERROR_FUNCTION_FAILED;
1380 return ERROR_SUCCESS;
1383 ret = MSI_SetComponentStateW(package, szComponent, iState);
1384 msiobj_release(&package->hdr);
1388 /***********************************************************************
1389 * MsiGetComponentStateW (MSI.@)
1391 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1392 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1394 MSIPACKAGE* package;
1397 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szComponent),
1398 piInstalled, piAction);
1400 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1405 IWineMsiRemotePackage *remote_package;
1407 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1408 if (!remote_package)
1409 return ERROR_INVALID_HANDLE;
1411 component = SysAllocString(szComponent);
1414 IWineMsiRemotePackage_Release(remote_package);
1415 return ERROR_OUTOFMEMORY;
1418 hr = IWineMsiRemotePackage_GetComponentState(remote_package, component,
1419 piInstalled, piAction);
1421 SysFreeString(component);
1422 IWineMsiRemotePackage_Release(remote_package);
1426 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1427 return HRESULT_CODE(hr);
1429 return ERROR_FUNCTION_FAILED;
1432 return ERROR_SUCCESS;
1435 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
1436 msiobj_release( &package->hdr );
1440 /***********************************************************************
1441 * MsiGetLanguage (MSI.@)
1443 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
1445 MSIPACKAGE* package;
1448 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1453 IWineMsiRemotePackage *remote_package;
1455 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1456 if (!remote_package)
1457 return ERROR_INVALID_HANDLE;
1459 hr = IWineMsiRemotePackage_GetLanguage(remote_package, &lang);
1467 langid = msi_get_property_int( package->db, szProductLanguage, 0 );
1468 msiobj_release( &package->hdr );
1472 UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel )
1474 static const WCHAR fmt[] = { '%','d',0 };
1478 TRACE("%p %i\n", package, iInstallLevel);
1480 if (iInstallLevel > 32767)
1481 return ERROR_INVALID_PARAMETER;
1483 if (iInstallLevel < 1)
1484 return MSI_SetFeatureStates( package );
1486 sprintfW( level, fmt, iInstallLevel );
1487 r = msi_set_property( package->db, szInstallLevel, level );
1488 if ( r == ERROR_SUCCESS )
1489 r = MSI_SetFeatureStates( package );
1494 /***********************************************************************
1495 * MsiSetInstallLevel (MSI.@)
1497 UINT WINAPI MsiSetInstallLevel(MSIHANDLE hInstall, int iInstallLevel)
1499 MSIPACKAGE* package;
1502 TRACE("%d %i\n", hInstall, iInstallLevel);
1504 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1508 IWineMsiRemotePackage *remote_package;
1510 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1511 if (!remote_package)
1512 return ERROR_INVALID_HANDLE;
1514 hr = IWineMsiRemotePackage_SetInstallLevel(remote_package, iInstallLevel);
1516 IWineMsiRemotePackage_Release(remote_package);
1520 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1521 return HRESULT_CODE(hr);
1523 return ERROR_FUNCTION_FAILED;
1526 return ERROR_SUCCESS;
1529 r = MSI_SetInstallLevel( package, iInstallLevel );
1531 msiobj_release( &package->hdr );
1536 /***********************************************************************
1537 * MsiGetFeatureValidStatesW (MSI.@)
1539 UINT WINAPI MsiGetFeatureValidStatesW(MSIHANDLE hInstall, LPCWSTR szFeature,
1540 LPDWORD pInstallState)
1542 if(pInstallState) *pInstallState = 1<<INSTALLSTATE_LOCAL;
1543 FIXME("%d %s %p stub returning %d\n",
1544 hInstall, debugstr_w(szFeature), pInstallState, pInstallState ? *pInstallState : 0);
1546 return ERROR_SUCCESS;
1549 /***********************************************************************
1550 * MsiGetFeatureValidStatesA (MSI.@)
1552 UINT WINAPI MsiGetFeatureValidStatesA(MSIHANDLE hInstall, LPCSTR szFeature,
1553 LPDWORD pInstallState)
1556 LPWSTR szwFeature = strdupAtoW(szFeature);
1558 ret = MsiGetFeatureValidStatesW(hInstall, szwFeature, pInstallState);
1560 msi_free(szwFeature);