Release 1.5.0.
[wine/multimedia.git] / dlls / msi / install.c
blob83b8b7d17389a23efc178f97531ffe50999f9f38
1 /*
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 */
23 #define COBJMACROS
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "wine/debug.h"
31 #include "msi.h"
32 #include "msidefs.h"
33 #include "objbase.h"
34 #include "oleauto.h"
36 #include "msipriv.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 )
47 LPWSTR szwAction;
48 UINT ret;
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 );
58 return ret;
61 /***********************************************************************
62 * MsiDoActionW (MSI.@)
64 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
66 MSIPACKAGE *package;
67 UINT ret;
69 TRACE("%s\n",debugstr_w(szAction));
71 if (!szAction)
72 return ERROR_INVALID_PARAMETER;
74 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
75 if (!package)
77 HRESULT hr;
78 BSTR action;
79 IWineMsiRemotePackage *remote_package;
81 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
82 if (!remote_package)
83 return ERROR_INVALID_HANDLE;
85 action = SysAllocString( szAction );
86 if (!action)
88 IWineMsiRemotePackage_Release( remote_package );
89 return ERROR_OUTOFMEMORY;
92 hr = IWineMsiRemotePackage_DoAction( remote_package, action );
94 SysFreeString( action );
95 IWineMsiRemotePackage_Release( remote_package );
97 if (FAILED(hr))
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, SCRIPT_NONE );
109 msiobj_release( &package->hdr );
111 return ret;
114 /***********************************************************************
115 * MsiSequenceA (MSI.@)
117 UINT WINAPI MsiSequenceA( MSIHANDLE hInstall, LPCSTR szTable, INT iSequenceMode )
119 LPWSTR szwTable;
120 UINT ret;
122 TRACE("%s, %d\n", debugstr_a(szTable), iSequenceMode);
124 szwTable = strdupAtoW(szTable);
125 if (szTable && !szwTable)
126 return ERROR_FUNCTION_FAILED;
128 ret = MsiSequenceW( hInstall, szwTable, iSequenceMode );
129 msi_free( szwTable );
130 return ret;
133 /***********************************************************************
134 * MsiSequenceW (MSI.@)
136 UINT WINAPI MsiSequenceW( MSIHANDLE hInstall, LPCWSTR szTable, INT iSequenceMode )
138 MSIPACKAGE *package;
139 UINT ret;
141 TRACE("%s, %d\n", debugstr_w(szTable), iSequenceMode);
143 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
144 if (!package)
146 HRESULT hr;
147 BSTR table;
148 IWineMsiRemotePackage *remote_package;
150 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
151 if (!remote_package)
152 return ERROR_INVALID_HANDLE;
154 table = SysAllocString( szTable );
155 if (!table)
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 );
166 if (FAILED(hr))
168 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
169 return HRESULT_CODE(hr);
171 return ERROR_FUNCTION_FAILED;
174 return ERROR_SUCCESS;
176 ret = MSI_Sequence( package, szTable );
177 msiobj_release( &package->hdr );
178 return ret;
181 UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz )
183 UINT len, r = ERROR_SUCCESS;
185 if (awbuf->str.w && !sz )
186 return ERROR_INVALID_PARAMETER;
188 if (!sz)
189 return r;
191 if (awbuf->unicode)
193 len = lstrlenW( str );
194 if (awbuf->str.w)
195 lstrcpynW( awbuf->str.w, str, *sz );
197 else
199 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
200 if (len)
201 len--;
202 WideCharToMultiByte( CP_ACP, 0, str, -1, awbuf->str.a, *sz, NULL, NULL );
203 if ( awbuf->str.a && *sz && (len >= *sz) )
204 awbuf->str.a[*sz - 1] = 0;
207 if (awbuf->str.w && len >= *sz)
208 r = ERROR_MORE_DATA;
209 *sz = len;
210 return r;
213 const WCHAR *msi_get_target_folder( MSIPACKAGE *package, const WCHAR *name )
215 MSIFOLDER *folder = msi_get_loaded_folder( package, name );
217 if (!folder) return NULL;
218 if (!folder->ResolvedTarget)
220 MSIFOLDER *parent = folder;
221 while (parent->Parent && strcmpW( parent->Parent, parent->Directory ))
223 parent = msi_get_loaded_folder( package, parent->Parent );
225 msi_resolve_target_folder( package, parent->Directory, TRUE );
227 return folder->ResolvedTarget;
230 /***********************************************************************
231 * MsiGetTargetPath (internal)
233 static UINT MSI_GetTargetPath( MSIHANDLE hInstall, LPCWSTR szFolder,
234 awstring *szPathBuf, LPDWORD pcchPathBuf )
236 MSIPACKAGE *package;
237 const WCHAR *path;
238 UINT r = ERROR_FUNCTION_FAILED;
240 if (!szFolder)
241 return ERROR_INVALID_PARAMETER;
243 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
244 if (!package)
246 HRESULT hr;
247 IWineMsiRemotePackage *remote_package;
248 LPWSTR value = NULL;
249 BSTR folder;
250 DWORD len;
252 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
253 if (!remote_package)
254 return ERROR_INVALID_HANDLE;
256 folder = SysAllocString( szFolder );
257 if (!folder)
259 IWineMsiRemotePackage_Release( remote_package );
260 return ERROR_OUTOFMEMORY;
263 len = 0;
264 hr = IWineMsiRemotePackage_GetTargetPath( remote_package, folder, NULL, &len );
265 if (FAILED(hr))
266 goto done;
268 len++;
269 value = msi_alloc(len * sizeof(WCHAR));
270 if (!value)
272 r = ERROR_OUTOFMEMORY;
273 goto done;
276 hr = IWineMsiRemotePackage_GetTargetPath( remote_package, folder, value, &len );
277 if (FAILED(hr))
278 goto done;
280 r = msi_strcpy_to_awstring( value, szPathBuf, pcchPathBuf );
282 done:
283 IWineMsiRemotePackage_Release( remote_package );
284 SysFreeString( folder );
285 msi_free( value );
287 if (FAILED(hr))
289 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
290 return HRESULT_CODE(hr);
292 return ERROR_FUNCTION_FAILED;
295 return r;
298 path = msi_get_target_folder( package, szFolder );
299 msiobj_release( &package->hdr );
301 if (!path)
302 return ERROR_DIRECTORY;
304 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
305 return r;
308 /***********************************************************************
309 * MsiGetTargetPathA (MSI.@)
311 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
312 LPSTR szPathBuf, LPDWORD pcchPathBuf )
314 LPWSTR szwFolder;
315 awstring path;
316 UINT r;
318 TRACE("%s %p %p\n", debugstr_a(szFolder), szPathBuf, pcchPathBuf);
320 szwFolder = strdupAtoW(szFolder);
321 if (szFolder && !szwFolder)
322 return ERROR_FUNCTION_FAILED;
324 path.unicode = FALSE;
325 path.str.a = szPathBuf;
327 r = MSI_GetTargetPath( hInstall, szwFolder, &path, pcchPathBuf );
329 msi_free( szwFolder );
331 return r;
334 /***********************************************************************
335 * MsiGetTargetPathW (MSI.@)
337 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder,
338 LPWSTR szPathBuf, LPDWORD pcchPathBuf )
340 awstring path;
342 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf);
344 path.unicode = TRUE;
345 path.str.w = szPathBuf;
347 return MSI_GetTargetPath( hInstall, szFolder, &path, pcchPathBuf );
350 static WCHAR *get_source_root( MSIPACKAGE *package )
352 msi_set_sourcedir_props( package, FALSE );
353 return msi_dup_property( package->db, szSourceDir );
356 WCHAR *msi_resolve_source_folder( MSIPACKAGE *package, const WCHAR *name, MSIFOLDER **folder )
358 MSIFOLDER *f;
359 LPWSTR p, path = NULL, parent;
361 TRACE("working to resolve %s\n", debugstr_w(name));
363 if (!strcmpW( name, szSourceDir )) name = szTargetDir;
364 if (!(f = msi_get_loaded_folder( package, name ))) return NULL;
366 /* special resolving for root dir */
367 if (!strcmpW( name, szTargetDir ) && !f->ResolvedSource)
369 f->ResolvedSource = get_source_root( package );
371 if (folder) *folder = f;
372 if (f->ResolvedSource)
374 path = strdupW( f->ResolvedSource );
375 TRACE(" already resolved to %s\n", debugstr_w(path));
376 return path;
378 if (!f->Parent) return path;
379 parent = f->Parent;
380 TRACE(" ! parent is %s\n", debugstr_w(parent));
382 p = msi_resolve_source_folder( package, parent, NULL );
384 if (package->WordCount & msidbSumInfoSourceTypeCompressed)
385 path = get_source_root( package );
386 else if (package->WordCount & msidbSumInfoSourceTypeSFN)
387 path = msi_build_directory_name( 3, p, f->SourceShortPath, NULL );
388 else
389 path = msi_build_directory_name( 3, p, f->SourceLongPath, NULL );
391 TRACE("-> %s\n", debugstr_w(path));
392 f->ResolvedSource = strdupW( path );
393 msi_free( p );
395 return path;
398 /***********************************************************************
399 * MSI_GetSourcePath (internal)
401 static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
402 awstring *szPathBuf, LPDWORD pcchPathBuf )
404 MSIPACKAGE *package;
405 LPWSTR path;
406 UINT r = ERROR_FUNCTION_FAILED;
408 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
410 if (!szFolder)
411 return ERROR_INVALID_PARAMETER;
413 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
414 if (!package)
416 HRESULT hr;
417 IWineMsiRemotePackage *remote_package;
418 LPWSTR value = NULL;
419 BSTR folder;
420 DWORD len;
422 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
423 if (!remote_package)
424 return ERROR_INVALID_HANDLE;
426 folder = SysAllocString( szFolder );
427 if (!folder)
429 IWineMsiRemotePackage_Release( remote_package );
430 return ERROR_OUTOFMEMORY;
433 len = 0;
434 hr = IWineMsiRemotePackage_GetSourcePath( remote_package, folder, NULL, &len );
435 if (FAILED(hr))
436 goto done;
438 len++;
439 value = msi_alloc(len * sizeof(WCHAR));
440 if (!value)
442 r = ERROR_OUTOFMEMORY;
443 goto done;
446 hr = IWineMsiRemotePackage_GetSourcePath( remote_package, folder, value, &len );
447 if (FAILED(hr))
448 goto done;
450 r = msi_strcpy_to_awstring( value, szPathBuf, pcchPathBuf );
452 done:
453 IWineMsiRemotePackage_Release( remote_package );
454 SysFreeString( folder );
455 msi_free( value );
457 if (FAILED(hr))
459 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
460 return HRESULT_CODE(hr);
462 return ERROR_FUNCTION_FAILED;
465 return r;
468 if (szPathBuf->str.w && !pcchPathBuf )
470 msiobj_release( &package->hdr );
471 return ERROR_INVALID_PARAMETER;
474 path = msi_resolve_source_folder( package, szFolder, NULL );
475 msiobj_release( &package->hdr );
477 TRACE("path = %s\n", debugstr_w(path));
478 if (!path)
479 return ERROR_DIRECTORY;
481 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
482 msi_free( path );
483 return r;
486 /***********************************************************************
487 * MsiGetSourcePathA (MSI.@)
489 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
490 LPSTR szPathBuf, LPDWORD pcchPathBuf )
492 LPWSTR folder;
493 awstring str;
494 UINT r;
496 TRACE("%s %p %p\n", debugstr_a(szFolder), szPathBuf, pcchPathBuf);
498 str.unicode = FALSE;
499 str.str.a = szPathBuf;
501 folder = strdupAtoW( szFolder );
502 r = MSI_GetSourcePath( hInstall, folder, &str, pcchPathBuf );
503 msi_free( folder );
505 return r;
508 /***********************************************************************
509 * MsiGetSourcePathW (MSI.@)
511 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder,
512 LPWSTR szPathBuf, LPDWORD pcchPathBuf )
514 awstring str;
516 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
518 str.unicode = TRUE;
519 str.str.w = szPathBuf;
521 return MSI_GetSourcePath( hInstall, szFolder, &str, pcchPathBuf );
524 /***********************************************************************
525 * MsiSetTargetPathA (MSI.@)
527 UINT WINAPI MsiSetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
528 LPCSTR szFolderPath )
530 LPWSTR szwFolder = NULL, szwFolderPath = NULL;
531 UINT rc = ERROR_OUTOFMEMORY;
533 if ( !szFolder || !szFolderPath )
534 return ERROR_INVALID_PARAMETER;
536 szwFolder = strdupAtoW(szFolder);
537 szwFolderPath = strdupAtoW(szFolderPath);
538 if (!szwFolder || !szwFolderPath)
539 goto end;
541 rc = MsiSetTargetPathW( hInstall, szwFolder, szwFolderPath );
543 end:
544 msi_free(szwFolder);
545 msi_free(szwFolderPath);
547 return rc;
550 static void set_target_path( MSIPACKAGE *package, MSIFOLDER *folder, const WCHAR *path )
552 FolderList *fl;
553 MSIFOLDER *child;
554 WCHAR *target_path;
556 if (!(target_path = msi_normalize_path( path ))) return;
557 if (strcmpW( target_path, folder->ResolvedTarget ))
559 msi_free( folder->ResolvedTarget );
560 folder->ResolvedTarget = target_path;
561 msi_set_property( package->db, folder->Directory, folder->ResolvedTarget );
563 LIST_FOR_EACH_ENTRY( fl, &folder->children, FolderList, entry )
565 child = fl->folder;
566 msi_resolve_target_folder( package, child->Directory, FALSE );
569 else msi_free( target_path );
572 UINT MSI_SetTargetPathW( MSIPACKAGE *package, LPCWSTR szFolder, LPCWSTR szFolderPath )
574 DWORD attrib;
575 MSIFOLDER *folder;
576 MSIFILE *file;
578 TRACE("%p %s %s\n", package, debugstr_w(szFolder), debugstr_w(szFolderPath));
580 attrib = GetFileAttributesW(szFolderPath);
581 /* native MSI tests writeability by making temporary files at each drive */
582 if (attrib != INVALID_FILE_ATTRIBUTES &&
583 (attrib & FILE_ATTRIBUTE_OFFLINE || attrib & FILE_ATTRIBUTE_READONLY))
585 return ERROR_FUNCTION_FAILED;
587 if (!(folder = msi_get_loaded_folder( package, szFolder ))) return ERROR_DIRECTORY;
589 set_target_path( package, folder, szFolderPath );
591 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
593 const WCHAR *dir;
594 MSICOMPONENT *comp = file->Component;
596 if (!comp->Enabled || (comp->assembly && !comp->assembly->application)) continue;
598 dir = msi_get_target_folder( package, comp->Directory );
599 msi_free( file->TargetPath );
600 file->TargetPath = msi_build_directory_name( 2, dir, file->FileName );
602 return ERROR_SUCCESS;
605 /***********************************************************************
606 * MsiSetTargetPathW (MSI.@)
608 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
609 LPCWSTR szFolderPath)
611 MSIPACKAGE *package;
612 UINT ret;
614 TRACE("%s %s\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
616 if ( !szFolder || !szFolderPath )
617 return ERROR_INVALID_PARAMETER;
619 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
620 if (!package)
622 HRESULT hr;
623 BSTR folder, path;
624 IWineMsiRemotePackage *remote_package;
626 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
627 if (!remote_package)
628 return ERROR_INVALID_HANDLE;
630 folder = SysAllocString( szFolder );
631 path = SysAllocString( szFolderPath );
632 if (!folder || !path)
634 SysFreeString(folder);
635 SysFreeString(path);
636 IWineMsiRemotePackage_Release( remote_package );
637 return ERROR_OUTOFMEMORY;
640 hr = IWineMsiRemotePackage_SetTargetPath( remote_package, folder, path );
642 SysFreeString(folder);
643 SysFreeString(path);
644 IWineMsiRemotePackage_Release( remote_package );
646 if (FAILED(hr))
648 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
649 return HRESULT_CODE(hr);
651 return ERROR_FUNCTION_FAILED;
654 return ERROR_SUCCESS;
657 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
658 msiobj_release( &package->hdr );
659 return ret;
662 /***********************************************************************
663 * MsiGetMode (MSI.@)
665 * Returns an internal installer state (if it is running in a mode iRunMode)
667 * PARAMS
668 * hInstall [I] Handle to the installation
669 * hRunMode [I] Checking run mode
670 * MSIRUNMODE_ADMIN Administrative mode
671 * MSIRUNMODE_ADVERTISE Advertisement mode
672 * MSIRUNMODE_MAINTENANCE Maintenance mode
673 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
674 * MSIRUNMODE_LOGENABLED Log file is writing
675 * MSIRUNMODE_OPERATIONS Operations in progress??
676 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
677 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
678 * MSIRUNMODE_CABINET Files from cabinet are installed
679 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
680 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
681 * MSIRUNMODE_RESERVED11 Reserved
682 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
683 * MSIRUNMODE_ZAWENABLED Demand installation is supported
684 * MSIRUNMODE_RESERVED14 Reserved
685 * MSIRUNMODE_RESERVED15 Reserved
686 * MSIRUNMODE_SCHEDULED called from install script
687 * MSIRUNMODE_ROLLBACK called from rollback script
688 * MSIRUNMODE_COMMIT called from commit script
690 * RETURNS
691 * In the state: TRUE
692 * Not in the state: FALSE
695 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
697 MSIPACKAGE *package;
698 BOOL r = FALSE;
700 TRACE("%d %d\n", hInstall, iRunMode);
702 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
703 if (!package)
705 BOOL ret;
706 HRESULT hr;
707 IWineMsiRemotePackage *remote_package;
709 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
710 if (!remote_package)
711 return FALSE;
713 hr = IWineMsiRemotePackage_GetMode(remote_package, iRunMode, &ret);
714 IWineMsiRemotePackage_Release(remote_package);
716 if (hr == S_OK)
717 return ret;
719 return FALSE;
722 switch (iRunMode)
724 case MSIRUNMODE_ADMIN:
725 FIXME("no support for administrative installs\n");
726 break;
728 case MSIRUNMODE_ADVERTISE:
729 FIXME("no support for advertised installs\n");
730 break;
732 case MSIRUNMODE_WINDOWS9X:
733 if (GetVersion() & 0x80000000)
734 r = TRUE;
735 break;
737 case MSIRUNMODE_OPERATIONS:
738 case MSIRUNMODE_RESERVED11:
739 case MSIRUNMODE_RESERVED14:
740 case MSIRUNMODE_RESERVED15:
741 break;
743 case MSIRUNMODE_SCHEDULED:
744 r = package->scheduled_action_running;
745 break;
747 case MSIRUNMODE_ROLLBACK:
748 r = package->rollback_action_running;
749 break;
751 case MSIRUNMODE_COMMIT:
752 r = package->commit_action_running;
753 break;
755 case MSIRUNMODE_MAINTENANCE:
756 r = msi_get_property_int( package->db, szInstalled, 0 ) != 0;
757 break;
759 case MSIRUNMODE_ROLLBACKENABLED:
760 r = msi_get_property_int( package->db, szRollbackDisabled, 0 ) == 0;
761 break;
763 case MSIRUNMODE_REBOOTATEND:
764 r = package->need_reboot;
765 break;
767 case MSIRUNMODE_LOGENABLED:
768 r = (package->log_file != INVALID_HANDLE_VALUE);
769 break;
771 default:
772 FIXME("unimplemented run mode: %d\n", iRunMode);
773 r = TRUE;
776 msiobj_release( &package->hdr );
777 return r;
780 /***********************************************************************
781 * MsiSetMode (MSI.@)
783 UINT WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
785 MSIPACKAGE *package;
786 UINT r;
788 TRACE("%d %d %d\n", hInstall, iRunMode, fState);
790 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
791 if (!package)
793 HRESULT hr;
794 IWineMsiRemotePackage *remote_package;
796 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
797 if (!remote_package)
798 return FALSE;
800 hr = IWineMsiRemotePackage_SetMode( remote_package, iRunMode, fState );
801 IWineMsiRemotePackage_Release( remote_package );
803 if (FAILED(hr))
805 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
806 return HRESULT_CODE(hr);
808 return ERROR_FUNCTION_FAILED;
811 return ERROR_SUCCESS;
814 switch (iRunMode)
816 case MSIRUNMODE_REBOOTATEND:
817 package->need_reboot = 1;
818 r = ERROR_SUCCESS;
819 break;
821 case MSIRUNMODE_REBOOTNOW:
822 FIXME("unimplemented run mode: %d\n", iRunMode);
823 r = ERROR_FUNCTION_FAILED;
824 break;
826 default:
827 r = ERROR_ACCESS_DENIED;
830 msiobj_release( &package->hdr );
831 return r;
834 /***********************************************************************
835 * MsiSetFeatureStateA (MSI.@)
837 * According to the docs, when this is called it immediately recalculates
838 * all the component states as well
840 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
841 INSTALLSTATE iState)
843 LPWSTR szwFeature = NULL;
844 UINT rc;
846 szwFeature = strdupAtoW(szFeature);
848 if (!szwFeature)
849 return ERROR_FUNCTION_FAILED;
851 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
853 msi_free(szwFeature);
855 return rc;
858 /* update component state based on a feature change */
859 void ACTION_UpdateComponentStates( MSIPACKAGE *package, MSIFEATURE *feature )
861 INSTALLSTATE newstate;
862 ComponentList *cl;
864 newstate = feature->ActionRequest;
865 if (newstate == INSTALLSTATE_ABSENT) newstate = INSTALLSTATE_UNKNOWN;
867 LIST_FOR_EACH_ENTRY(cl, &feature->Components, ComponentList, entry)
869 MSICOMPONENT *component = cl->component;
871 if (!component->Enabled) continue;
873 TRACE("Modifying (%d): Component %s (Installed %d, Action %d, Request %d)\n",
874 newstate, debugstr_w(component->Component), component->Installed,
875 component->Action, component->ActionRequest);
877 if (newstate == INSTALLSTATE_LOCAL)
879 component->Action = INSTALLSTATE_LOCAL;
880 component->ActionRequest = INSTALLSTATE_LOCAL;
882 else
884 ComponentList *clist;
885 MSIFEATURE *f;
887 component->hasLocalFeature = FALSE;
889 component->Action = newstate;
890 component->ActionRequest = newstate;
891 /* if any other feature wants it local we need to set it local */
892 LIST_FOR_EACH_ENTRY(f, &package->features, MSIFEATURE, entry)
894 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
895 f->ActionRequest != INSTALLSTATE_SOURCE )
897 continue;
899 LIST_FOR_EACH_ENTRY(clist, &f->Components, ComponentList, entry)
901 if (clist->component == component &&
902 (f->ActionRequest == INSTALLSTATE_LOCAL ||
903 f->ActionRequest == INSTALLSTATE_SOURCE))
905 TRACE("Saved by %s\n", debugstr_w(f->Feature));
906 component->hasLocalFeature = TRUE;
908 if (component->Attributes & msidbComponentAttributesOptional)
910 if (f->Attributes & msidbFeatureAttributesFavorSource)
912 component->Action = INSTALLSTATE_SOURCE;
913 component->ActionRequest = INSTALLSTATE_SOURCE;
915 else
917 component->Action = INSTALLSTATE_LOCAL;
918 component->ActionRequest = INSTALLSTATE_LOCAL;
921 else if (component->Attributes & msidbComponentAttributesSourceOnly)
923 component->Action = INSTALLSTATE_SOURCE;
924 component->ActionRequest = INSTALLSTATE_SOURCE;
926 else
928 component->Action = INSTALLSTATE_LOCAL;
929 component->ActionRequest = INSTALLSTATE_LOCAL;
935 TRACE("Result (%d): Component %s (Installed %d, Action %d, Request %d)\n",
936 newstate, debugstr_w(component->Component), component->Installed,
937 component->Action, component->ActionRequest);
941 UINT MSI_SetFeatureStateW( MSIPACKAGE *package, LPCWSTR szFeature, INSTALLSTATE iState )
943 UINT rc = ERROR_SUCCESS;
944 MSIFEATURE *feature, *child;
946 TRACE("%s %i\n", debugstr_w(szFeature), iState);
948 feature = msi_get_loaded_feature( package, szFeature );
949 if (!feature)
950 return ERROR_UNKNOWN_FEATURE;
952 if (iState == INSTALLSTATE_ADVERTISED &&
953 feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
954 return ERROR_FUNCTION_FAILED;
956 feature->ActionRequest = iState;
958 ACTION_UpdateComponentStates( package, feature );
960 /* update all the features that are children of this feature */
961 LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
963 if (child->Feature_Parent && !strcmpW( szFeature, child->Feature_Parent ))
964 MSI_SetFeatureStateW(package, child->Feature, iState);
967 return rc;
970 /***********************************************************************
971 * MsiSetFeatureStateW (MSI.@)
973 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
974 INSTALLSTATE iState)
976 MSIPACKAGE* package;
977 UINT rc = ERROR_SUCCESS;
979 TRACE("%s %i\n",debugstr_w(szFeature), iState);
981 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
982 if (!package)
984 HRESULT hr;
985 BSTR feature;
986 IWineMsiRemotePackage *remote_package;
988 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
989 if (!remote_package)
990 return ERROR_INVALID_HANDLE;
992 feature = SysAllocString(szFeature);
993 if (!feature)
995 IWineMsiRemotePackage_Release(remote_package);
996 return ERROR_OUTOFMEMORY;
999 hr = IWineMsiRemotePackage_SetFeatureState(remote_package, feature, iState);
1001 SysFreeString(feature);
1002 IWineMsiRemotePackage_Release(remote_package);
1004 if (FAILED(hr))
1006 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1007 return HRESULT_CODE(hr);
1009 return ERROR_FUNCTION_FAILED;
1012 return ERROR_SUCCESS;
1015 rc = MSI_SetFeatureStateW(package,szFeature,iState);
1017 msiobj_release( &package->hdr );
1018 return rc;
1021 /***********************************************************************
1022 * MsiSetFeatureAttributesA (MSI.@)
1024 UINT WINAPI MsiSetFeatureAttributesA( MSIHANDLE handle, LPCSTR feature, DWORD attrs )
1026 UINT r;
1027 WCHAR *featureW = NULL;
1029 TRACE("%u, %s, 0x%08x\n", handle, debugstr_a(feature), attrs);
1031 if (feature && !(featureW = strdupAtoW( feature ))) return ERROR_OUTOFMEMORY;
1033 r = MsiSetFeatureAttributesW( handle, featureW, attrs );
1034 msi_free( featureW );
1035 return r;
1038 static DWORD unmap_feature_attributes( DWORD attrs )
1040 DWORD ret = 0;
1042 if (attrs & INSTALLFEATUREATTRIBUTE_FAVORLOCAL) ret = msidbFeatureAttributesFavorLocal;
1043 if (attrs & INSTALLFEATUREATTRIBUTE_FAVORSOURCE) ret |= msidbFeatureAttributesFavorSource;
1044 if (attrs & INSTALLFEATUREATTRIBUTE_FOLLOWPARENT) ret |= msidbFeatureAttributesFollowParent;
1045 if (attrs & INSTALLFEATUREATTRIBUTE_FAVORADVERTISE) ret |= msidbFeatureAttributesFavorAdvertise;
1046 if (attrs & INSTALLFEATUREATTRIBUTE_DISALLOWADVERTISE) ret |= msidbFeatureAttributesDisallowAdvertise;
1047 if (attrs & INSTALLFEATUREATTRIBUTE_NOUNSUPPORTEDADVERTISE) ret |= msidbFeatureAttributesNoUnsupportedAdvertise;
1048 return ret;
1051 /***********************************************************************
1052 * MsiSetFeatureAttributesW (MSI.@)
1054 UINT WINAPI MsiSetFeatureAttributesW( MSIHANDLE handle, LPCWSTR name, DWORD attrs )
1056 MSIPACKAGE *package;
1057 MSIFEATURE *feature;
1058 WCHAR *costing;
1060 TRACE("%u, %s, 0x%08x\n", handle, debugstr_w(name), attrs);
1062 if (!name || !name[0]) return ERROR_UNKNOWN_FEATURE;
1064 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1065 return ERROR_INVALID_HANDLE;
1067 costing = msi_dup_property( package->db, szCostingComplete );
1068 if (!costing || !strcmpW( costing, szOne ))
1070 msi_free( costing );
1071 msiobj_release( &package->hdr );
1072 return ERROR_FUNCTION_FAILED;
1074 msi_free( costing );
1075 if (!(feature = msi_get_loaded_feature( package, name )))
1077 msiobj_release( &package->hdr );
1078 return ERROR_UNKNOWN_FEATURE;
1080 feature->Attributes = unmap_feature_attributes( attrs );
1081 msiobj_release( &package->hdr );
1082 return ERROR_SUCCESS;
1085 /***********************************************************************
1086 * MsiGetFeatureStateA (MSI.@)
1088 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
1089 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1091 LPWSTR szwFeature = NULL;
1092 UINT rc;
1094 if (szFeature && !(szwFeature = strdupAtoW(szFeature))) return ERROR_OUTOFMEMORY;
1096 rc = MsiGetFeatureStateW(hInstall, szwFeature, piInstalled, piAction);
1097 msi_free( szwFeature);
1098 return rc;
1101 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPCWSTR szFeature,
1102 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1104 MSIFEATURE *feature;
1106 feature = msi_get_loaded_feature(package,szFeature);
1107 if (!feature)
1108 return ERROR_UNKNOWN_FEATURE;
1110 if (piInstalled)
1111 *piInstalled = feature->Installed;
1113 if (piAction)
1114 *piAction = feature->ActionRequest;
1116 TRACE("returning %i %i\n", feature->Installed, feature->ActionRequest);
1118 return ERROR_SUCCESS;
1121 /***********************************************************************
1122 * MsiGetFeatureStateW (MSI.@)
1124 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
1125 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1127 MSIPACKAGE* package;
1128 UINT ret;
1130 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled, piAction);
1132 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1133 if (!package)
1135 HRESULT hr;
1136 BSTR feature;
1137 IWineMsiRemotePackage *remote_package;
1139 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1140 if (!remote_package)
1141 return ERROR_INVALID_HANDLE;
1143 feature = SysAllocString(szFeature);
1144 if (!feature)
1146 IWineMsiRemotePackage_Release(remote_package);
1147 return ERROR_OUTOFMEMORY;
1150 hr = IWineMsiRemotePackage_GetFeatureState(remote_package, feature,
1151 piInstalled, piAction);
1153 SysFreeString(feature);
1154 IWineMsiRemotePackage_Release(remote_package);
1156 if (FAILED(hr))
1158 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1159 return HRESULT_CODE(hr);
1161 return ERROR_FUNCTION_FAILED;
1164 return ERROR_SUCCESS;
1167 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
1168 msiobj_release( &package->hdr );
1169 return ret;
1172 /***********************************************************************
1173 * MsiGetFeatureCostA (MSI.@)
1175 UINT WINAPI MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature,
1176 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1178 LPWSTR szwFeature = NULL;
1179 UINT rc;
1181 szwFeature = strdupAtoW(szFeature);
1183 rc = MsiGetFeatureCostW(hInstall, szwFeature, iCostTree, iState, piCost);
1185 msi_free(szwFeature);
1187 return rc;
1190 static INT feature_cost( MSIFEATURE *feature )
1192 INT cost = 0;
1193 MSICOMPONENT *comp;
1195 LIST_FOR_EACH_ENTRY( comp, &feature->Components, MSICOMPONENT, entry )
1197 cost += comp->Cost;
1199 return cost;
1202 UINT MSI_GetFeatureCost( MSIPACKAGE *package, MSIFEATURE *feature, MSICOSTTREE tree,
1203 INSTALLSTATE state, LPINT cost )
1205 TRACE("%s, %u, %d, %p\n", debugstr_w(feature->Feature), tree, state, cost);
1207 *cost = 0;
1208 switch (tree)
1210 case MSICOSTTREE_CHILDREN:
1212 MSIFEATURE *child;
1214 LIST_FOR_EACH_ENTRY( child, &feature->Children, MSIFEATURE, entry )
1216 if (child->ActionRequest == state)
1217 *cost += feature_cost( child );
1219 break;
1221 case MSICOSTTREE_PARENTS:
1223 const WCHAR *feature_parent = feature->Feature_Parent;
1224 for (;;)
1226 MSIFEATURE *parent = msi_get_loaded_feature( package, feature_parent );
1227 if (!parent)
1228 break;
1230 if (parent->ActionRequest == state)
1231 *cost += feature_cost( parent );
1233 feature_parent = parent->Feature_Parent;
1235 break;
1237 case MSICOSTTREE_SELFONLY:
1238 if (feature->ActionRequest == state)
1239 *cost = feature_cost( feature );
1240 break;
1242 default:
1243 WARN("unhandled cost tree %u\n", tree);
1244 break;
1247 *cost /= 512;
1248 return ERROR_SUCCESS;
1251 /***********************************************************************
1252 * MsiGetFeatureCostW (MSI.@)
1254 UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature,
1255 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
1257 MSIPACKAGE *package;
1258 MSIFEATURE *feature;
1259 UINT ret;
1261 TRACE("(%d %s %i %i %p)\n", hInstall, debugstr_w(szFeature),
1262 iCostTree, iState, piCost);
1264 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1265 if (!package)
1267 HRESULT hr;
1268 BSTR feature;
1269 IWineMsiRemotePackage *remote_package;
1271 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1272 if (!remote_package)
1273 return ERROR_INVALID_HANDLE;
1275 feature = SysAllocString(szFeature);
1276 if (!feature)
1278 IWineMsiRemotePackage_Release(remote_package);
1279 return ERROR_OUTOFMEMORY;
1282 hr = IWineMsiRemotePackage_GetFeatureCost(remote_package, feature,
1283 iCostTree, iState, piCost);
1285 SysFreeString(feature);
1286 IWineMsiRemotePackage_Release(remote_package);
1288 if (FAILED(hr))
1290 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1291 return HRESULT_CODE(hr);
1293 return ERROR_FUNCTION_FAILED;
1296 return ERROR_SUCCESS;
1299 feature = msi_get_loaded_feature(package, szFeature);
1301 if (feature)
1302 ret = MSI_GetFeatureCost(package, feature, iCostTree, iState, piCost);
1303 else
1304 ret = ERROR_UNKNOWN_FEATURE;
1306 msiobj_release( &package->hdr );
1307 return ret;
1310 /***********************************************************************
1311 * MsiGetFeatureInfoA (MSI.@)
1313 UINT WINAPI MsiGetFeatureInfoA( MSIHANDLE handle, LPCSTR feature, LPDWORD attrs,
1314 LPSTR title, LPDWORD title_len, LPSTR help, LPDWORD help_len )
1316 UINT r;
1317 WCHAR *titleW = NULL, *helpW = NULL, *featureW = NULL;
1319 TRACE("%u, %s, %p, %p, %p, %p, %p\n", handle, debugstr_a(feature), attrs, title,
1320 title_len, help, help_len);
1322 if (feature && !(featureW = strdupAtoW( feature ))) return ERROR_OUTOFMEMORY;
1324 if (title && title_len && !(titleW = msi_alloc( *title_len * sizeof(WCHAR) )))
1326 msi_free( featureW );
1327 return ERROR_OUTOFMEMORY;
1329 if (help && help_len && !(helpW = msi_alloc( *help_len * sizeof(WCHAR) )))
1331 msi_free( featureW );
1332 msi_free( titleW );
1333 return ERROR_OUTOFMEMORY;
1335 r = MsiGetFeatureInfoW( handle, featureW, attrs, titleW, title_len, helpW, help_len );
1336 if (r == ERROR_SUCCESS)
1338 if (titleW) WideCharToMultiByte( CP_ACP, 0, titleW, -1, title, *title_len + 1, NULL, NULL );
1339 if (helpW) WideCharToMultiByte( CP_ACP, 0, helpW, -1, help, *help_len + 1, NULL, NULL );
1341 msi_free( titleW );
1342 msi_free( helpW );
1343 msi_free( featureW );
1344 return r;
1347 static DWORD map_feature_attributes( DWORD attrs )
1349 DWORD ret = 0;
1351 if (attrs == msidbFeatureAttributesFavorLocal) ret |= INSTALLFEATUREATTRIBUTE_FAVORLOCAL;
1352 if (attrs & msidbFeatureAttributesFavorSource) ret |= INSTALLFEATUREATTRIBUTE_FAVORSOURCE;
1353 if (attrs & msidbFeatureAttributesFollowParent) ret |= INSTALLFEATUREATTRIBUTE_FOLLOWPARENT;
1354 if (attrs & msidbFeatureAttributesFavorAdvertise) ret |= INSTALLFEATUREATTRIBUTE_FAVORADVERTISE;
1355 if (attrs & msidbFeatureAttributesDisallowAdvertise) ret |= INSTALLFEATUREATTRIBUTE_DISALLOWADVERTISE;
1356 if (attrs & msidbFeatureAttributesNoUnsupportedAdvertise) ret |= INSTALLFEATUREATTRIBUTE_NOUNSUPPORTEDADVERTISE;
1357 return ret;
1360 static UINT MSI_GetFeatureInfo( MSIPACKAGE *package, LPCWSTR name, LPDWORD attrs,
1361 LPWSTR title, LPDWORD title_len, LPWSTR help, LPDWORD help_len )
1363 UINT r = ERROR_SUCCESS;
1364 MSIFEATURE *feature = msi_get_loaded_feature( package, name );
1365 int len;
1367 if (!feature) return ERROR_UNKNOWN_FEATURE;
1368 if (attrs) *attrs = map_feature_attributes( feature->Attributes );
1369 if (title_len)
1371 if (feature->Title) len = strlenW( feature->Title );
1372 else len = 0;
1373 if (*title_len <= len)
1375 *title_len = len;
1376 if (title) r = ERROR_MORE_DATA;
1378 else if (title)
1380 if (feature->Title) strcpyW( title, feature->Title );
1381 else *title = 0;
1382 *title_len = len;
1385 if (help_len)
1387 if (feature->Description) len = strlenW( feature->Description );
1388 else len = 0;
1389 if (*help_len <= len)
1391 *help_len = len;
1392 if (help) r = ERROR_MORE_DATA;
1394 else if (help)
1396 if (feature->Description) strcpyW( help, feature->Description );
1397 else *help = 0;
1398 *help_len = len;
1401 return r;
1404 /***********************************************************************
1405 * MsiGetFeatureInfoW (MSI.@)
1407 UINT WINAPI MsiGetFeatureInfoW( MSIHANDLE handle, LPCWSTR feature, LPDWORD attrs,
1408 LPWSTR title, LPDWORD title_len, LPWSTR help, LPDWORD help_len )
1410 UINT r;
1411 MSIPACKAGE *package;
1413 TRACE("%u, %s, %p, %p, %p, %p, %p\n", handle, debugstr_w(feature), attrs, title,
1414 title_len, help, help_len);
1416 if (!feature) return ERROR_INVALID_PARAMETER;
1418 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1419 return ERROR_INVALID_HANDLE;
1421 /* features may not have been loaded yet */
1422 msi_load_all_components( package );
1423 msi_load_all_features( package );
1425 r = MSI_GetFeatureInfo( package, feature, attrs, title, title_len, help, help_len );
1426 msiobj_release( &package->hdr );
1427 return r;
1430 /***********************************************************************
1431 * MsiSetComponentStateA (MSI.@)
1433 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1434 INSTALLSTATE iState)
1436 UINT rc;
1437 LPWSTR szwComponent = strdupAtoW(szComponent);
1439 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
1441 msi_free(szwComponent);
1443 return rc;
1446 /***********************************************************************
1447 * MsiGetComponentStateA (MSI.@)
1449 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1450 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1452 LPWSTR szwComponent= NULL;
1453 UINT rc;
1455 szwComponent= strdupAtoW(szComponent);
1457 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
1459 msi_free( szwComponent);
1461 return rc;
1464 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1465 INSTALLSTATE iState)
1467 MSICOMPONENT *comp;
1469 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
1471 comp = msi_get_loaded_component(package, szComponent);
1472 if (!comp)
1473 return ERROR_UNKNOWN_COMPONENT;
1475 if (comp->Enabled)
1476 comp->Action = iState;
1478 return ERROR_SUCCESS;
1481 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1482 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1484 MSICOMPONENT *comp;
1486 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
1487 piInstalled, piAction);
1489 comp = msi_get_loaded_component(package,szComponent);
1490 if (!comp)
1491 return ERROR_UNKNOWN_COMPONENT;
1493 if (piInstalled)
1495 if (comp->Enabled)
1496 *piInstalled = comp->Installed;
1497 else
1498 *piInstalled = INSTALLSTATE_UNKNOWN;
1501 if (piAction)
1503 if (comp->Enabled)
1504 *piAction = comp->Action;
1505 else
1506 *piAction = INSTALLSTATE_UNKNOWN;
1509 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
1510 return ERROR_SUCCESS;
1513 /***********************************************************************
1514 * MsiSetComponentStateW (MSI.@)
1516 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1517 INSTALLSTATE iState)
1519 MSIPACKAGE* package;
1520 UINT ret;
1522 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1523 if (!package)
1525 HRESULT hr;
1526 BSTR component;
1527 IWineMsiRemotePackage *remote_package;
1529 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1530 if (!remote_package)
1531 return ERROR_INVALID_HANDLE;
1533 component = SysAllocString(szComponent);
1534 if (!component)
1536 IWineMsiRemotePackage_Release(remote_package);
1537 return ERROR_OUTOFMEMORY;
1540 hr = IWineMsiRemotePackage_SetComponentState(remote_package, component, iState);
1542 SysFreeString(component);
1543 IWineMsiRemotePackage_Release(remote_package);
1545 if (FAILED(hr))
1547 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1548 return HRESULT_CODE(hr);
1550 return ERROR_FUNCTION_FAILED;
1553 return ERROR_SUCCESS;
1556 ret = MSI_SetComponentStateW(package, szComponent, iState);
1557 msiobj_release(&package->hdr);
1558 return ret;
1561 /***********************************************************************
1562 * MsiGetComponentStateW (MSI.@)
1564 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1565 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1567 MSIPACKAGE* package;
1568 UINT ret;
1570 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szComponent),
1571 piInstalled, piAction);
1573 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1574 if (!package)
1576 HRESULT hr;
1577 BSTR component;
1578 IWineMsiRemotePackage *remote_package;
1580 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1581 if (!remote_package)
1582 return ERROR_INVALID_HANDLE;
1584 component = SysAllocString(szComponent);
1585 if (!component)
1587 IWineMsiRemotePackage_Release(remote_package);
1588 return ERROR_OUTOFMEMORY;
1591 hr = IWineMsiRemotePackage_GetComponentState(remote_package, component,
1592 piInstalled, piAction);
1594 SysFreeString(component);
1595 IWineMsiRemotePackage_Release(remote_package);
1597 if (FAILED(hr))
1599 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1600 return HRESULT_CODE(hr);
1602 return ERROR_FUNCTION_FAILED;
1605 return ERROR_SUCCESS;
1608 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
1609 msiobj_release( &package->hdr );
1610 return ret;
1613 /***********************************************************************
1614 * MsiGetLanguage (MSI.@)
1616 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
1618 MSIPACKAGE* package;
1619 LANGID langid;
1621 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1622 if (!package)
1624 HRESULT hr;
1625 LANGID lang;
1626 IWineMsiRemotePackage *remote_package;
1628 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1629 if (!remote_package)
1630 return ERROR_INVALID_HANDLE;
1632 hr = IWineMsiRemotePackage_GetLanguage(remote_package, &lang);
1634 if (SUCCEEDED(hr))
1635 return lang;
1637 return 0;
1640 langid = msi_get_property_int( package->db, szProductLanguage, 0 );
1641 msiobj_release( &package->hdr );
1642 return langid;
1645 UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel )
1647 static const WCHAR fmt[] = { '%','d',0 };
1648 WCHAR level[6];
1649 UINT r;
1651 TRACE("%p %i\n", package, iInstallLevel);
1653 if (iInstallLevel > 32767)
1654 return ERROR_INVALID_PARAMETER;
1656 if (iInstallLevel < 1)
1657 return MSI_SetFeatureStates( package );
1659 sprintfW( level, fmt, iInstallLevel );
1660 r = msi_set_property( package->db, szInstallLevel, level );
1661 if ( r == ERROR_SUCCESS )
1662 r = MSI_SetFeatureStates( package );
1664 return r;
1667 /***********************************************************************
1668 * MsiSetInstallLevel (MSI.@)
1670 UINT WINAPI MsiSetInstallLevel(MSIHANDLE hInstall, int iInstallLevel)
1672 MSIPACKAGE* package;
1673 UINT r;
1675 TRACE("%d %i\n", hInstall, iInstallLevel);
1677 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1678 if (!package)
1680 HRESULT hr;
1681 IWineMsiRemotePackage *remote_package;
1683 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1684 if (!remote_package)
1685 return ERROR_INVALID_HANDLE;
1687 hr = IWineMsiRemotePackage_SetInstallLevel(remote_package, iInstallLevel);
1689 IWineMsiRemotePackage_Release(remote_package);
1691 if (FAILED(hr))
1693 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1694 return HRESULT_CODE(hr);
1696 return ERROR_FUNCTION_FAILED;
1699 return ERROR_SUCCESS;
1702 r = MSI_SetInstallLevel( package, iInstallLevel );
1704 msiobj_release( &package->hdr );
1706 return r;
1709 /***********************************************************************
1710 * MsiGetFeatureValidStatesW (MSI.@)
1712 UINT WINAPI MsiGetFeatureValidStatesW(MSIHANDLE hInstall, LPCWSTR szFeature,
1713 LPDWORD pInstallState)
1715 if(pInstallState) *pInstallState = 1<<INSTALLSTATE_LOCAL;
1716 FIXME("%d %s %p stub returning %d\n",
1717 hInstall, debugstr_w(szFeature), pInstallState, pInstallState ? *pInstallState : 0);
1719 return ERROR_SUCCESS;
1722 /***********************************************************************
1723 * MsiGetFeatureValidStatesA (MSI.@)
1725 UINT WINAPI MsiGetFeatureValidStatesA(MSIHANDLE hInstall, LPCSTR szFeature,
1726 LPDWORD pInstallState)
1728 UINT ret;
1729 LPWSTR szwFeature = strdupAtoW(szFeature);
1731 ret = MsiGetFeatureValidStatesW(hInstall, szwFeature, pInstallState);
1733 msi_free(szwFeature);
1735 return ret;