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 * MsiSetFeatureAttributesA (MSI.@)
1033 UINT WINAPI MsiSetFeatureAttributesA( MSIHANDLE handle, LPCSTR feature, DWORD attrs )
1036 WCHAR *featureW = NULL;
1038 TRACE("%u, %s, 0x%08x\n", handle, debugstr_a(feature), attrs);
1040 if (feature && !(featureW = strdupAtoW( feature ))) return ERROR_OUTOFMEMORY;
1042 r = MsiSetFeatureAttributesW( handle, featureW, attrs );
1043 msi_free( featureW );
1047 static DWORD unmap_feature_attributes( DWORD attrs )
1051 if (attrs & INSTALLFEATUREATTRIBUTE_FAVORLOCAL) ret = msidbFeatureAttributesFavorLocal;
1052 if (attrs & INSTALLFEATUREATTRIBUTE_FAVORSOURCE) ret |= msidbFeatureAttributesFavorSource;
1053 if (attrs & INSTALLFEATUREATTRIBUTE_FOLLOWPARENT) ret |= msidbFeatureAttributesFollowParent;
1054 if (attrs & INSTALLFEATUREATTRIBUTE_FAVORADVERTISE) ret |= msidbFeatureAttributesFavorAdvertise;
1055 if (attrs & INSTALLFEATUREATTRIBUTE_DISALLOWADVERTISE) ret |= msidbFeatureAttributesDisallowAdvertise;
1056 if (attrs & INSTALLFEATUREATTRIBUTE_NOUNSUPPORTEDADVERTISE) ret |= msidbFeatureAttributesNoUnsupportedAdvertise;
1060 /***********************************************************************
1061 * MsiSetFeatureAttributesW (MSI.@)
1063 UINT WINAPI MsiSetFeatureAttributesW( MSIHANDLE handle, LPCWSTR name, DWORD attrs )
1065 MSIPACKAGE *package;
1066 MSIFEATURE *feature;
1069 TRACE("%u, %s, 0x%08x\n", handle, debugstr_w(name), attrs);
1071 if (!name || !name[0]) return ERROR_UNKNOWN_FEATURE;
1073 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1074 return ERROR_INVALID_HANDLE;
1076 costing = msi_dup_property( package->db, szCostingComplete );
1077 if (!costing || !strcmpW( costing, szOne ))
1079 msi_free( costing );
1080 msiobj_release( &package->hdr );
1081 return ERROR_FUNCTION_FAILED;
1083 msi_free( costing );
1084 if (!(feature = msi_get_loaded_feature( package, name )))
1086 msiobj_release( &package->hdr );
1087 return ERROR_UNKNOWN_FEATURE;
1089 feature->Attributes = unmap_feature_attributes( attrs );
1090 msiobj_release( &package->hdr );
1091 return ERROR_SUCCESS;
1094 /***********************************************************************
1095 * MsiGetFeatureStateA (MSI.@)
1097 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
1098 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1100 LPWSTR szwFeature = NULL;
1103 if (szFeature && !(szwFeature = strdupAtoW(szFeature))) return ERROR_OUTOFMEMORY;
1105 rc = MsiGetFeatureStateW(hInstall, szwFeature, piInstalled, piAction);
1106 msi_free( szwFeature);
1110 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPCWSTR szFeature,
1111 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1113 MSIFEATURE *feature;
1115 feature = msi_get_loaded_feature(package,szFeature);
1117 return ERROR_UNKNOWN_FEATURE;
1120 *piInstalled = feature->Installed;
1123 *piAction = feature->ActionRequest;
1125 TRACE("returning %i %i\n", feature->Installed, feature->ActionRequest);
1127 return ERROR_SUCCESS;
1130 /***********************************************************************
1131 * MsiGetFeatureStateW (MSI.@)
1133 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
1134 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1136 MSIPACKAGE* package;
1139 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled, piAction);
1141 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1146 IWineMsiRemotePackage *remote_package;
1148 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1149 if (!remote_package)
1150 return ERROR_INVALID_HANDLE;
1152 feature = SysAllocString(szFeature);
1155 IWineMsiRemotePackage_Release(remote_package);
1156 return ERROR_OUTOFMEMORY;
1159 hr = IWineMsiRemotePackage_GetFeatureState(remote_package, feature,
1160 piInstalled, piAction);
1162 SysFreeString(feature);
1163 IWineMsiRemotePackage_Release(remote_package);
1167 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1168 return HRESULT_CODE(hr);
1170 return ERROR_FUNCTION_FAILED;
1173 return ERROR_SUCCESS;
1176 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
1177 msiobj_release( &package->hdr );
1181 /***********************************************************************
1182 * MsiGetFeatureCostA (MSI.@)
1184 UINT WINAPI MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature,
1185 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1187 LPWSTR szwFeature = NULL;
1190 szwFeature = strdupAtoW(szFeature);
1192 rc = MsiGetFeatureCostW(hInstall, szwFeature, iCostTree, iState, piCost);
1194 msi_free(szwFeature);
1199 static INT feature_cost( MSIFEATURE *feature )
1204 LIST_FOR_EACH_ENTRY( comp, &feature->Components, MSICOMPONENT, entry )
1211 UINT MSI_GetFeatureCost( MSIPACKAGE *package, MSIFEATURE *feature, MSICOSTTREE tree,
1212 INSTALLSTATE state, LPINT cost )
1214 TRACE("%s, %u, %d, %p\n", debugstr_w(feature->Feature), tree, state, cost);
1219 case MSICOSTTREE_CHILDREN:
1223 LIST_FOR_EACH_ENTRY( child, &feature->Children, MSIFEATURE, entry )
1225 if (child->ActionRequest == state)
1226 *cost += feature_cost( child );
1230 case MSICOSTTREE_PARENTS:
1232 const WCHAR *feature_parent = feature->Feature_Parent;
1235 MSIFEATURE *parent = msi_get_loaded_feature( package, feature_parent );
1239 if (parent->ActionRequest == state)
1240 *cost += feature_cost( parent );
1242 feature_parent = parent->Feature_Parent;
1246 case MSICOSTTREE_SELFONLY:
1247 if (feature->ActionRequest == state)
1248 *cost = feature_cost( feature );
1252 WARN("unhandled cost tree %u\n", tree);
1257 return ERROR_SUCCESS;
1260 /***********************************************************************
1261 * MsiGetFeatureCostW (MSI.@)
1263 UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature,
1264 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1266 MSIPACKAGE *package;
1267 MSIFEATURE *feature;
1270 TRACE("(%d %s %i %i %p)\n", hInstall, debugstr_w(szFeature),
1271 iCostTree, iState, piCost);
1273 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1278 IWineMsiRemotePackage *remote_package;
1280 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1281 if (!remote_package)
1282 return ERROR_INVALID_HANDLE;
1284 feature = SysAllocString(szFeature);
1287 IWineMsiRemotePackage_Release(remote_package);
1288 return ERROR_OUTOFMEMORY;
1291 hr = IWineMsiRemotePackage_GetFeatureCost(remote_package, feature,
1292 iCostTree, iState, piCost);
1294 SysFreeString(feature);
1295 IWineMsiRemotePackage_Release(remote_package);
1299 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1300 return HRESULT_CODE(hr);
1302 return ERROR_FUNCTION_FAILED;
1305 return ERROR_SUCCESS;
1308 feature = msi_get_loaded_feature(package, szFeature);
1311 ret = MSI_GetFeatureCost(package, feature, iCostTree, iState, piCost);
1313 ret = ERROR_UNKNOWN_FEATURE;
1315 msiobj_release( &package->hdr );
1319 /***********************************************************************
1320 * MsiGetFeatureInfoA (MSI.@)
1322 UINT WINAPI MsiGetFeatureInfoA( MSIHANDLE handle, LPCSTR feature, LPDWORD attrs,
1323 LPSTR title, LPDWORD title_len, LPSTR help, LPDWORD help_len )
1326 WCHAR *titleW = NULL, *helpW = NULL, *featureW = NULL;
1328 TRACE("%u, %s, %p, %p, %p, %p, %p\n", handle, debugstr_a(feature), attrs, title,
1329 title_len, help, help_len);
1331 if (feature && !(featureW = strdupAtoW( feature ))) return ERROR_OUTOFMEMORY;
1333 if (title && title_len && !(titleW = msi_alloc( *title_len * sizeof(WCHAR) )))
1335 msi_free( featureW );
1336 return ERROR_OUTOFMEMORY;
1338 if (help && help_len && !(helpW = msi_alloc( *help_len * sizeof(WCHAR) )))
1340 msi_free( featureW );
1342 return ERROR_OUTOFMEMORY;
1344 r = MsiGetFeatureInfoW( handle, featureW, attrs, titleW, title_len, helpW, help_len );
1345 if (r == ERROR_SUCCESS)
1347 if (titleW) WideCharToMultiByte( CP_ACP, 0, titleW, -1, title, *title_len + 1, NULL, NULL );
1348 if (helpW) WideCharToMultiByte( CP_ACP, 0, helpW, -1, help, *help_len + 1, NULL, NULL );
1352 msi_free( featureW );
1356 static DWORD map_feature_attributes( DWORD attrs )
1360 if (attrs == msidbFeatureAttributesFavorLocal) ret |= INSTALLFEATUREATTRIBUTE_FAVORLOCAL;
1361 if (attrs & msidbFeatureAttributesFavorSource) ret |= INSTALLFEATUREATTRIBUTE_FAVORSOURCE;
1362 if (attrs & msidbFeatureAttributesFollowParent) ret |= INSTALLFEATUREATTRIBUTE_FOLLOWPARENT;
1363 if (attrs & msidbFeatureAttributesFavorAdvertise) ret |= INSTALLFEATUREATTRIBUTE_FAVORADVERTISE;
1364 if (attrs & msidbFeatureAttributesDisallowAdvertise) ret |= INSTALLFEATUREATTRIBUTE_DISALLOWADVERTISE;
1365 if (attrs & msidbFeatureAttributesNoUnsupportedAdvertise) ret |= INSTALLFEATUREATTRIBUTE_NOUNSUPPORTEDADVERTISE;
1369 static UINT MSI_GetFeatureInfo( MSIPACKAGE *package, LPCWSTR name, LPDWORD attrs,
1370 LPWSTR title, LPDWORD title_len, LPWSTR help, LPDWORD help_len )
1372 UINT r = ERROR_SUCCESS;
1373 MSIFEATURE *feature = msi_get_loaded_feature( package, name );
1376 if (!feature) return ERROR_UNKNOWN_FEATURE;
1377 if (attrs) *attrs = map_feature_attributes( feature->Attributes );
1380 if (feature->Title) len = strlenW( feature->Title );
1382 if (*title_len <= len)
1385 if (title) r = ERROR_MORE_DATA;
1389 if (feature->Title) strcpyW( title, feature->Title );
1396 if (feature->Description) len = strlenW( feature->Description );
1398 if (*help_len <= len)
1401 if (help) r = ERROR_MORE_DATA;
1405 if (feature->Description) strcpyW( help, feature->Description );
1413 /***********************************************************************
1414 * MsiGetFeatureInfoW (MSI.@)
1416 UINT WINAPI MsiGetFeatureInfoW( MSIHANDLE handle, LPCWSTR feature, LPDWORD attrs,
1417 LPWSTR title, LPDWORD title_len, LPWSTR help, LPDWORD help_len )
1420 MSIPACKAGE *package;
1422 TRACE("%u, %s, %p, %p, %p, %p, %p\n", handle, debugstr_w(feature), attrs, title,
1423 title_len, help, help_len);
1425 if (!feature) return ERROR_INVALID_PARAMETER;
1427 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1428 return ERROR_INVALID_HANDLE;
1430 /* features may not have been loaded yet */
1431 msi_load_all_components( package );
1432 msi_load_all_features( package );
1434 r = MSI_GetFeatureInfo( package, feature, attrs, title, title_len, help, help_len );
1435 msiobj_release( &package->hdr );
1439 /***********************************************************************
1440 * MsiSetComponentStateA (MSI.@)
1442 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1443 INSTALLSTATE iState)
1446 LPWSTR szwComponent = strdupAtoW(szComponent);
1448 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
1450 msi_free(szwComponent);
1455 /***********************************************************************
1456 * MsiGetComponentStateA (MSI.@)
1458 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1459 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1461 LPWSTR szwComponent= NULL;
1464 szwComponent= strdupAtoW(szComponent);
1466 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
1468 msi_free( szwComponent);
1473 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1474 INSTALLSTATE iState)
1478 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
1480 comp = msi_get_loaded_component(package, szComponent);
1482 return ERROR_UNKNOWN_COMPONENT;
1485 comp->Action = iState;
1487 return ERROR_SUCCESS;
1490 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1491 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1495 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
1496 piInstalled, piAction);
1498 comp = msi_get_loaded_component(package,szComponent);
1500 return ERROR_UNKNOWN_COMPONENT;
1505 *piInstalled = comp->Installed;
1507 *piInstalled = INSTALLSTATE_UNKNOWN;
1513 *piAction = comp->Action;
1515 *piAction = INSTALLSTATE_UNKNOWN;
1518 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
1519 return ERROR_SUCCESS;
1522 /***********************************************************************
1523 * MsiSetComponentStateW (MSI.@)
1525 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1526 INSTALLSTATE iState)
1528 MSIPACKAGE* package;
1531 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1536 IWineMsiRemotePackage *remote_package;
1538 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1539 if (!remote_package)
1540 return ERROR_INVALID_HANDLE;
1542 component = SysAllocString(szComponent);
1545 IWineMsiRemotePackage_Release(remote_package);
1546 return ERROR_OUTOFMEMORY;
1549 hr = IWineMsiRemotePackage_SetComponentState(remote_package, component, iState);
1551 SysFreeString(component);
1552 IWineMsiRemotePackage_Release(remote_package);
1556 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1557 return HRESULT_CODE(hr);
1559 return ERROR_FUNCTION_FAILED;
1562 return ERROR_SUCCESS;
1565 ret = MSI_SetComponentStateW(package, szComponent, iState);
1566 msiobj_release(&package->hdr);
1570 /***********************************************************************
1571 * MsiGetComponentStateW (MSI.@)
1573 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1574 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1576 MSIPACKAGE* package;
1579 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szComponent),
1580 piInstalled, piAction);
1582 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1587 IWineMsiRemotePackage *remote_package;
1589 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1590 if (!remote_package)
1591 return ERROR_INVALID_HANDLE;
1593 component = SysAllocString(szComponent);
1596 IWineMsiRemotePackage_Release(remote_package);
1597 return ERROR_OUTOFMEMORY;
1600 hr = IWineMsiRemotePackage_GetComponentState(remote_package, component,
1601 piInstalled, piAction);
1603 SysFreeString(component);
1604 IWineMsiRemotePackage_Release(remote_package);
1608 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1609 return HRESULT_CODE(hr);
1611 return ERROR_FUNCTION_FAILED;
1614 return ERROR_SUCCESS;
1617 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
1618 msiobj_release( &package->hdr );
1622 /***********************************************************************
1623 * MsiGetLanguage (MSI.@)
1625 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
1627 MSIPACKAGE* package;
1630 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1635 IWineMsiRemotePackage *remote_package;
1637 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1638 if (!remote_package)
1639 return ERROR_INVALID_HANDLE;
1641 hr = IWineMsiRemotePackage_GetLanguage(remote_package, &lang);
1649 langid = msi_get_property_int( package->db, szProductLanguage, 0 );
1650 msiobj_release( &package->hdr );
1654 UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel )
1656 static const WCHAR fmt[] = { '%','d',0 };
1660 TRACE("%p %i\n", package, iInstallLevel);
1662 if (iInstallLevel > 32767)
1663 return ERROR_INVALID_PARAMETER;
1665 if (iInstallLevel < 1)
1666 return MSI_SetFeatureStates( package );
1668 sprintfW( level, fmt, iInstallLevel );
1669 r = msi_set_property( package->db, szInstallLevel, level );
1670 if ( r == ERROR_SUCCESS )
1671 r = MSI_SetFeatureStates( package );
1676 /***********************************************************************
1677 * MsiSetInstallLevel (MSI.@)
1679 UINT WINAPI MsiSetInstallLevel(MSIHANDLE hInstall, int iInstallLevel)
1681 MSIPACKAGE* package;
1684 TRACE("%d %i\n", hInstall, iInstallLevel);
1686 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1690 IWineMsiRemotePackage *remote_package;
1692 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1693 if (!remote_package)
1694 return ERROR_INVALID_HANDLE;
1696 hr = IWineMsiRemotePackage_SetInstallLevel(remote_package, iInstallLevel);
1698 IWineMsiRemotePackage_Release(remote_package);
1702 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1703 return HRESULT_CODE(hr);
1705 return ERROR_FUNCTION_FAILED;
1708 return ERROR_SUCCESS;
1711 r = MSI_SetInstallLevel( package, iInstallLevel );
1713 msiobj_release( &package->hdr );
1718 /***********************************************************************
1719 * MsiGetFeatureValidStatesW (MSI.@)
1721 UINT WINAPI MsiGetFeatureValidStatesW(MSIHANDLE hInstall, LPCWSTR szFeature,
1722 LPDWORD pInstallState)
1724 if(pInstallState) *pInstallState = 1<<INSTALLSTATE_LOCAL;
1725 FIXME("%d %s %p stub returning %d\n",
1726 hInstall, debugstr_w(szFeature), pInstallState, pInstallState ? *pInstallState : 0);
1728 return ERROR_SUCCESS;
1731 /***********************************************************************
1732 * MsiGetFeatureValidStatesA (MSI.@)
1734 UINT WINAPI MsiGetFeatureValidStatesA(MSIHANDLE hInstall, LPCSTR szFeature,
1735 LPDWORD pInstallState)
1738 LPWSTR szwFeature = strdupAtoW(szFeature);
1740 ret = MsiGetFeatureValidStatesW(hInstall, szwFeature, pInstallState);
1742 msi_free(szwFeature);