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");
738 case MSIRUNMODE_WINDOWS9X:
739 if (GetVersion() & 0x80000000)
743 case MSIRUNMODE_OPERATIONS:
744 case MSIRUNMODE_RESERVED11:
745 case MSIRUNMODE_RESERVED14:
746 case MSIRUNMODE_RESERVED15:
749 case MSIRUNMODE_SCHEDULED:
750 r = package->scheduled_action_running;
753 case MSIRUNMODE_ROLLBACK:
754 r = package->rollback_action_running;
757 case MSIRUNMODE_COMMIT:
758 r = package->commit_action_running;
761 case MSIRUNMODE_MAINTENANCE:
762 r = msi_get_property_int( package->db, szInstalled, 0 ) != 0;
765 case MSIRUNMODE_ROLLBACKENABLED:
766 r = msi_get_property_int( package->db, szRollbackDisabled, 0 ) == 0;
769 case MSIRUNMODE_REBOOTATEND:
770 r = package->need_reboot;
773 case MSIRUNMODE_LOGENABLED:
774 r = (package->log_file != INVALID_HANDLE_VALUE);
778 FIXME("unimplemented run mode: %d\n", iRunMode);
782 msiobj_release( &package->hdr );
786 /***********************************************************************
789 UINT WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
794 TRACE("%d %d %d\n", hInstall, iRunMode, fState);
796 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
800 IWineMsiRemotePackage *remote_package;
802 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
806 hr = IWineMsiRemotePackage_SetMode( remote_package, iRunMode, fState );
807 IWineMsiRemotePackage_Release( remote_package );
811 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
812 return HRESULT_CODE(hr);
814 return ERROR_FUNCTION_FAILED;
817 return ERROR_SUCCESS;
822 case MSIRUNMODE_REBOOTATEND:
823 package->need_reboot = 1;
827 case MSIRUNMODE_REBOOTNOW:
828 FIXME("unimplemented run mode: %d\n", iRunMode);
829 r = ERROR_FUNCTION_FAILED;
833 r = ERROR_ACCESS_DENIED;
836 msiobj_release( &package->hdr );
840 /***********************************************************************
841 * MsiSetFeatureStateA (MSI.@)
843 * According to the docs, when this is called it immediately recalculates
844 * all the component states as well
846 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
849 LPWSTR szwFeature = NULL;
852 szwFeature = strdupAtoW(szFeature);
855 return ERROR_FUNCTION_FAILED;
857 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
859 msi_free(szwFeature);
864 /* update component state based on a feature change */
865 void ACTION_UpdateComponentStates( MSIPACKAGE *package, MSIFEATURE *feature )
867 INSTALLSTATE newstate;
870 newstate = feature->ActionRequest;
871 if (newstate == INSTALLSTATE_ABSENT) newstate = INSTALLSTATE_UNKNOWN;
873 LIST_FOR_EACH_ENTRY(cl, &feature->Components, ComponentList, entry)
875 MSICOMPONENT *component = cl->component;
877 if (!component->Enabled) continue;
879 TRACE("Modifying (%d): Component %s (Installed %d, Action %d, Request %d)\n",
880 newstate, debugstr_w(component->Component), component->Installed,
881 component->Action, component->ActionRequest);
883 if (newstate == INSTALLSTATE_LOCAL)
885 component->Action = INSTALLSTATE_LOCAL;
886 component->ActionRequest = INSTALLSTATE_LOCAL;
890 ComponentList *clist;
893 component->hasLocalFeature = FALSE;
895 component->Action = newstate;
896 component->ActionRequest = newstate;
897 /* if any other feature wants it local we need to set it local */
898 LIST_FOR_EACH_ENTRY(f, &package->features, MSIFEATURE, entry)
900 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
901 f->ActionRequest != INSTALLSTATE_SOURCE )
905 LIST_FOR_EACH_ENTRY(clist, &f->Components, ComponentList, entry)
907 if (clist->component == component &&
908 (f->ActionRequest == INSTALLSTATE_LOCAL ||
909 f->ActionRequest == INSTALLSTATE_SOURCE))
911 TRACE("Saved by %s\n", debugstr_w(f->Feature));
912 component->hasLocalFeature = TRUE;
914 if (component->Attributes & msidbComponentAttributesOptional)
916 if (f->Attributes & msidbFeatureAttributesFavorSource)
918 component->Action = INSTALLSTATE_SOURCE;
919 component->ActionRequest = INSTALLSTATE_SOURCE;
923 component->Action = INSTALLSTATE_LOCAL;
924 component->ActionRequest = INSTALLSTATE_LOCAL;
927 else if (component->Attributes & msidbComponentAttributesSourceOnly)
929 component->Action = INSTALLSTATE_SOURCE;
930 component->ActionRequest = INSTALLSTATE_SOURCE;
934 component->Action = INSTALLSTATE_LOCAL;
935 component->ActionRequest = INSTALLSTATE_LOCAL;
941 TRACE("Result (%d): Component %s (Installed %d, Action %d, Request %d)\n",
942 newstate, debugstr_w(component->Component), component->Installed,
943 component->Action, component->ActionRequest);
947 UINT WINAPI MSI_SetFeatureStateW( MSIPACKAGE *package, LPCWSTR szFeature, INSTALLSTATE iState )
949 UINT rc = ERROR_SUCCESS;
950 MSIFEATURE *feature, *child;
952 TRACE("%s %i\n", debugstr_w(szFeature), iState);
954 feature = msi_get_loaded_feature( package, szFeature );
956 return ERROR_UNKNOWN_FEATURE;
958 if (iState == INSTALLSTATE_ADVERTISED &&
959 feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
960 return ERROR_FUNCTION_FAILED;
962 feature->ActionRequest = iState;
964 ACTION_UpdateComponentStates( package, feature );
966 /* update all the features that are children of this feature */
967 LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
969 if (child->Feature_Parent && !strcmpW( szFeature, child->Feature_Parent ))
970 MSI_SetFeatureStateW(package, child->Feature, iState);
976 /***********************************************************************
977 * MsiSetFeatureStateW (MSI.@)
979 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
983 UINT rc = ERROR_SUCCESS;
985 TRACE("%s %i\n",debugstr_w(szFeature), iState);
987 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
992 IWineMsiRemotePackage *remote_package;
994 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
996 return ERROR_INVALID_HANDLE;
998 feature = SysAllocString(szFeature);
1001 IWineMsiRemotePackage_Release(remote_package);
1002 return ERROR_OUTOFMEMORY;
1005 hr = IWineMsiRemotePackage_SetFeatureState(remote_package, feature, iState);
1007 SysFreeString(feature);
1008 IWineMsiRemotePackage_Release(remote_package);
1012 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1013 return HRESULT_CODE(hr);
1015 return ERROR_FUNCTION_FAILED;
1018 return ERROR_SUCCESS;
1021 rc = MSI_SetFeatureStateW(package,szFeature,iState);
1023 msiobj_release( &package->hdr );
1027 /***********************************************************************
1028 * MsiGetFeatureStateA (MSI.@)
1030 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
1031 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1033 LPWSTR szwFeature = NULL;
1036 szwFeature = strdupAtoW(szFeature);
1038 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
1040 msi_free( szwFeature);
1045 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPCWSTR szFeature,
1046 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1048 MSIFEATURE *feature;
1050 feature = msi_get_loaded_feature(package,szFeature);
1052 return ERROR_UNKNOWN_FEATURE;
1055 *piInstalled = feature->Installed;
1058 *piAction = feature->ActionRequest;
1060 TRACE("returning %i %i\n", feature->Installed, feature->ActionRequest);
1062 return ERROR_SUCCESS;
1065 /***********************************************************************
1066 * MsiGetFeatureStateW (MSI.@)
1068 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
1069 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1071 MSIPACKAGE* package;
1074 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled, piAction);
1076 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1081 IWineMsiRemotePackage *remote_package;
1083 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1084 if (!remote_package)
1085 return ERROR_INVALID_HANDLE;
1087 feature = SysAllocString(szFeature);
1090 IWineMsiRemotePackage_Release(remote_package);
1091 return ERROR_OUTOFMEMORY;
1094 hr = IWineMsiRemotePackage_GetFeatureState(remote_package, feature,
1095 piInstalled, piAction);
1097 SysFreeString(feature);
1098 IWineMsiRemotePackage_Release(remote_package);
1102 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1103 return HRESULT_CODE(hr);
1105 return ERROR_FUNCTION_FAILED;
1108 return ERROR_SUCCESS;
1111 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
1112 msiobj_release( &package->hdr );
1116 /***********************************************************************
1117 * MsiGetFeatureCostA (MSI.@)
1119 UINT WINAPI MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature,
1120 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1122 LPWSTR szwFeature = NULL;
1125 szwFeature = strdupAtoW(szFeature);
1127 rc = MsiGetFeatureCostW(hInstall, szwFeature, iCostTree, iState, piCost);
1129 msi_free(szwFeature);
1134 static INT feature_cost( MSIFEATURE *feature )
1139 LIST_FOR_EACH_ENTRY( comp, &feature->Components, MSICOMPONENT, entry )
1146 UINT MSI_GetFeatureCost( MSIPACKAGE *package, MSIFEATURE *feature, MSICOSTTREE tree,
1147 INSTALLSTATE state, LPINT cost )
1149 TRACE("%s, %u, %d, %p\n", debugstr_w(feature->Feature), tree, state, cost);
1154 case MSICOSTTREE_CHILDREN:
1158 LIST_FOR_EACH_ENTRY( child, &feature->Children, MSIFEATURE, entry )
1160 if (child->ActionRequest == state)
1161 *cost += feature_cost( child );
1165 case MSICOSTTREE_PARENTS:
1167 const WCHAR *feature_parent = feature->Feature_Parent;
1170 MSIFEATURE *parent = msi_get_loaded_feature( package, feature_parent );
1174 if (parent->ActionRequest == state)
1175 *cost += feature_cost( parent );
1177 feature_parent = parent->Feature_Parent;
1181 case MSICOSTTREE_SELFONLY:
1182 if (feature->ActionRequest == state)
1183 *cost = feature_cost( feature );
1187 WARN("unhandled cost tree %u\n", tree);
1192 return ERROR_SUCCESS;
1195 /***********************************************************************
1196 * MsiGetFeatureCostW (MSI.@)
1198 UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature,
1199 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1201 MSIPACKAGE *package;
1202 MSIFEATURE *feature;
1205 TRACE("(%d %s %i %i %p)\n", hInstall, debugstr_w(szFeature),
1206 iCostTree, iState, piCost);
1208 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1213 IWineMsiRemotePackage *remote_package;
1215 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1216 if (!remote_package)
1217 return ERROR_INVALID_HANDLE;
1219 feature = SysAllocString(szFeature);
1222 IWineMsiRemotePackage_Release(remote_package);
1223 return ERROR_OUTOFMEMORY;
1226 hr = IWineMsiRemotePackage_GetFeatureCost(remote_package, feature,
1227 iCostTree, iState, piCost);
1229 SysFreeString(feature);
1230 IWineMsiRemotePackage_Release(remote_package);
1234 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1235 return HRESULT_CODE(hr);
1237 return ERROR_FUNCTION_FAILED;
1240 return ERROR_SUCCESS;
1243 feature = msi_get_loaded_feature(package, szFeature);
1246 ret = MSI_GetFeatureCost(package, feature, iCostTree, iState, piCost);
1248 ret = ERROR_UNKNOWN_FEATURE;
1250 msiobj_release( &package->hdr );
1254 /***********************************************************************
1255 * MsiSetComponentStateA (MSI.@)
1257 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1258 INSTALLSTATE iState)
1261 LPWSTR szwComponent = strdupAtoW(szComponent);
1263 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
1265 msi_free(szwComponent);
1270 /***********************************************************************
1271 * MsiGetComponentStateA (MSI.@)
1273 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1274 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1276 LPWSTR szwComponent= NULL;
1279 szwComponent= strdupAtoW(szComponent);
1281 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
1283 msi_free( szwComponent);
1288 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1289 INSTALLSTATE iState)
1293 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
1295 comp = msi_get_loaded_component(package, szComponent);
1297 return ERROR_UNKNOWN_COMPONENT;
1300 comp->Action = iState;
1302 return ERROR_SUCCESS;
1305 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1306 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1310 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
1311 piInstalled, piAction);
1313 comp = msi_get_loaded_component(package,szComponent);
1315 return ERROR_UNKNOWN_COMPONENT;
1320 *piInstalled = comp->Installed;
1322 *piInstalled = INSTALLSTATE_UNKNOWN;
1328 *piAction = comp->Action;
1330 *piAction = INSTALLSTATE_UNKNOWN;
1333 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
1334 return ERROR_SUCCESS;
1337 /***********************************************************************
1338 * MsiSetComponentStateW (MSI.@)
1340 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1341 INSTALLSTATE iState)
1343 MSIPACKAGE* package;
1346 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1351 IWineMsiRemotePackage *remote_package;
1353 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1354 if (!remote_package)
1355 return ERROR_INVALID_HANDLE;
1357 component = SysAllocString(szComponent);
1360 IWineMsiRemotePackage_Release(remote_package);
1361 return ERROR_OUTOFMEMORY;
1364 hr = IWineMsiRemotePackage_SetComponentState(remote_package, component, iState);
1366 SysFreeString(component);
1367 IWineMsiRemotePackage_Release(remote_package);
1371 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1372 return HRESULT_CODE(hr);
1374 return ERROR_FUNCTION_FAILED;
1377 return ERROR_SUCCESS;
1380 ret = MSI_SetComponentStateW(package, szComponent, iState);
1381 msiobj_release(&package->hdr);
1385 /***********************************************************************
1386 * MsiGetComponentStateW (MSI.@)
1388 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1389 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1391 MSIPACKAGE* package;
1394 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szComponent),
1395 piInstalled, piAction);
1397 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1402 IWineMsiRemotePackage *remote_package;
1404 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1405 if (!remote_package)
1406 return ERROR_INVALID_HANDLE;
1408 component = SysAllocString(szComponent);
1411 IWineMsiRemotePackage_Release(remote_package);
1412 return ERROR_OUTOFMEMORY;
1415 hr = IWineMsiRemotePackage_GetComponentState(remote_package, component,
1416 piInstalled, piAction);
1418 SysFreeString(component);
1419 IWineMsiRemotePackage_Release(remote_package);
1423 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1424 return HRESULT_CODE(hr);
1426 return ERROR_FUNCTION_FAILED;
1429 return ERROR_SUCCESS;
1432 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
1433 msiobj_release( &package->hdr );
1437 /***********************************************************************
1438 * MsiGetLanguage (MSI.@)
1440 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
1442 MSIPACKAGE* package;
1445 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1450 IWineMsiRemotePackage *remote_package;
1452 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1453 if (!remote_package)
1454 return ERROR_INVALID_HANDLE;
1456 hr = IWineMsiRemotePackage_GetLanguage(remote_package, &lang);
1464 langid = msi_get_property_int( package->db, szProductLanguage, 0 );
1465 msiobj_release( &package->hdr );
1469 UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel )
1471 static const WCHAR fmt[] = { '%','d',0 };
1475 TRACE("%p %i\n", package, iInstallLevel);
1477 if (iInstallLevel > 32767)
1478 return ERROR_INVALID_PARAMETER;
1480 if (iInstallLevel < 1)
1481 return MSI_SetFeatureStates( package );
1483 sprintfW( level, fmt, iInstallLevel );
1484 r = msi_set_property( package->db, szInstallLevel, level );
1485 if ( r == ERROR_SUCCESS )
1486 r = MSI_SetFeatureStates( package );
1491 /***********************************************************************
1492 * MsiSetInstallLevel (MSI.@)
1494 UINT WINAPI MsiSetInstallLevel(MSIHANDLE hInstall, int iInstallLevel)
1496 MSIPACKAGE* package;
1499 TRACE("%d %i\n", hInstall, iInstallLevel);
1501 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1505 IWineMsiRemotePackage *remote_package;
1507 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1508 if (!remote_package)
1509 return ERROR_INVALID_HANDLE;
1511 hr = IWineMsiRemotePackage_SetInstallLevel(remote_package, iInstallLevel);
1513 IWineMsiRemotePackage_Release(remote_package);
1517 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1518 return HRESULT_CODE(hr);
1520 return ERROR_FUNCTION_FAILED;
1523 return ERROR_SUCCESS;
1526 r = MSI_SetInstallLevel( package, iInstallLevel );
1528 msiobj_release( &package->hdr );
1533 /***********************************************************************
1534 * MsiGetFeatureValidStatesW (MSI.@)
1536 UINT WINAPI MsiGetFeatureValidStatesW(MSIHANDLE hInstall, LPCWSTR szFeature,
1537 LPDWORD pInstallState)
1539 if(pInstallState) *pInstallState = 1<<INSTALLSTATE_LOCAL;
1540 FIXME("%d %s %p stub returning %d\n",
1541 hInstall, debugstr_w(szFeature), pInstallState, pInstallState ? *pInstallState : 0);
1543 return ERROR_SUCCESS;
1546 /***********************************************************************
1547 * MsiGetFeatureValidStatesA (MSI.@)
1549 UINT WINAPI MsiGetFeatureValidStatesA(MSIHANDLE hInstall, LPCSTR szFeature,
1550 LPDWORD pInstallState)
1553 LPWSTR szwFeature = strdupAtoW(szFeature);
1555 ret = MsiGetFeatureValidStatesW(hInstall, szwFeature, pInstallState);
1557 msi_free(szwFeature);