winedos: Merge all of winedos back into krnl386.
[wine/multimedia.git] / dlls / msi / install.c
blobb1d741a1625e3be1e6d9e83c914164e394edad33
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, -1 );
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\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 );
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\n", debugstr_w(szTable));
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;
177 ret = MSI_Sequence( package, szTable, iSequenceMode );
178 msiobj_release( &package->hdr );
180 return ret;
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;
190 if (!sz)
191 return r;
193 if (awbuf->unicode)
195 len = lstrlenW( str );
196 if (awbuf->str.w)
197 lstrcpynW( awbuf->str.w, str, *sz );
199 else
201 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
202 if (len)
203 len--;
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)
210 r = ERROR_MORE_DATA;
211 *sz = len;
212 return r;
215 /***********************************************************************
216 * MsiGetTargetPath (internal)
218 static UINT MSI_GetTargetPath( MSIHANDLE hInstall, LPCWSTR szFolder,
219 awstring *szPathBuf, LPDWORD pcchPathBuf )
221 MSIPACKAGE *package;
222 LPWSTR path;
223 UINT r = ERROR_FUNCTION_FAILED;
225 if (!szFolder)
226 return ERROR_INVALID_PARAMETER;
228 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
229 if (!package)
231 HRESULT hr;
232 IWineMsiRemotePackage *remote_package;
233 LPWSTR value = NULL;
234 BSTR folder;
235 DWORD len;
237 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
238 if (!remote_package)
239 return ERROR_INVALID_HANDLE;
241 folder = SysAllocString( szFolder );
242 if (!folder)
244 IWineMsiRemotePackage_Release( remote_package );
245 return ERROR_OUTOFMEMORY;
248 len = 0;
249 hr = IWineMsiRemotePackage_GetTargetPath( remote_package, folder,
250 NULL, &len );
251 if (FAILED(hr))
252 goto done;
254 len++;
255 value = msi_alloc(len * sizeof(WCHAR));
256 if (!value)
258 r = ERROR_OUTOFMEMORY;
259 goto done;
262 hr = IWineMsiRemotePackage_GetTargetPath( remote_package, folder,
263 (BSTR *)value, &len);
264 if (FAILED(hr))
265 goto done;
267 r = msi_strcpy_to_awstring( value, szPathBuf, pcchPathBuf );
269 done:
270 IWineMsiRemotePackage_Release( remote_package );
271 SysFreeString( folder );
272 msi_free( value );
274 if (FAILED(hr))
276 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
277 return HRESULT_CODE(hr);
279 return ERROR_FUNCTION_FAILED;
282 return r;
285 path = resolve_folder( package, szFolder, FALSE, FALSE, TRUE, NULL );
286 msiobj_release( &package->hdr );
288 if (!path)
289 return ERROR_DIRECTORY;
291 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
292 msi_free( path );
293 return r;
296 /***********************************************************************
297 * MsiGetTargetPathA (MSI.@)
299 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
300 LPSTR szPathBuf, LPDWORD pcchPathBuf )
302 LPWSTR szwFolder;
303 awstring path;
304 UINT r;
306 TRACE("%s %p %p\n", debugstr_a(szFolder), szPathBuf, pcchPathBuf);
308 szwFolder = strdupAtoW(szFolder);
309 if (szFolder && !szwFolder)
310 return ERROR_FUNCTION_FAILED;
312 path.unicode = FALSE;
313 path.str.a = szPathBuf;
315 r = MSI_GetTargetPath( hInstall, szwFolder, &path, pcchPathBuf );
317 msi_free( szwFolder );
319 return r;
322 /***********************************************************************
323 * MsiGetTargetPathW (MSI.@)
325 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder,
326 LPWSTR szPathBuf, LPDWORD pcchPathBuf )
328 awstring path;
330 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf);
332 path.unicode = TRUE;
333 path.str.w = szPathBuf;
335 return MSI_GetTargetPath( hInstall, szFolder, &path, pcchPathBuf );
338 /***********************************************************************
339 * MsiGetSourcePath (internal)
341 static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
342 awstring *szPathBuf, LPDWORD pcchPathBuf )
344 MSIPACKAGE *package;
345 LPWSTR path;
346 UINT r = ERROR_FUNCTION_FAILED;
348 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
350 if (!szFolder)
351 return ERROR_INVALID_PARAMETER;
353 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
354 if (!package)
356 HRESULT hr;
357 IWineMsiRemotePackage *remote_package;
358 LPWSTR value = NULL;
359 BSTR folder;
360 DWORD len;
362 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
363 if (!remote_package)
364 return ERROR_INVALID_HANDLE;
366 folder = SysAllocString( szFolder );
367 if (!folder)
369 IWineMsiRemotePackage_Release( remote_package );
370 return ERROR_OUTOFMEMORY;
373 len = 0;
374 hr = IWineMsiRemotePackage_GetSourcePath( remote_package, folder,
375 NULL, &len );
376 if (FAILED(hr))
377 goto done;
379 len++;
380 value = msi_alloc(len * sizeof(WCHAR));
381 if (!value)
383 r = ERROR_OUTOFMEMORY;
384 goto done;
387 hr = IWineMsiRemotePackage_GetSourcePath( remote_package, folder,
388 (BSTR *)value, &len);
389 if (FAILED(hr))
390 goto done;
392 r = msi_strcpy_to_awstring( value, szPathBuf, pcchPathBuf );
394 done:
395 IWineMsiRemotePackage_Release( remote_package );
396 SysFreeString( folder );
397 msi_free( value );
399 if (FAILED(hr))
401 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
402 return HRESULT_CODE(hr);
404 return ERROR_FUNCTION_FAILED;
407 return r;
410 if (szPathBuf->str.w && !pcchPathBuf )
412 msiobj_release( &package->hdr );
413 return ERROR_INVALID_PARAMETER;
416 path = resolve_folder(package, szFolder, TRUE, FALSE, TRUE, NULL);
417 msiobj_release( &package->hdr );
419 TRACE("path = %s\n",debugstr_w(path));
420 if (!path)
421 return ERROR_DIRECTORY;
423 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
424 msi_free( path );
425 return r;
428 /***********************************************************************
429 * MsiGetSourcePathA (MSI.@)
431 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
432 LPSTR szPathBuf, LPDWORD pcchPathBuf )
434 LPWSTR folder;
435 awstring str;
436 UINT r;
438 TRACE("%s %p %p\n", szFolder, debugstr_a(szPathBuf), pcchPathBuf);
440 str.unicode = FALSE;
441 str.str.a = szPathBuf;
443 folder = strdupAtoW( szFolder );
444 r = MSI_GetSourcePath( hInstall, folder, &str, pcchPathBuf );
445 msi_free( folder );
447 return r;
450 /***********************************************************************
451 * MsiGetSourcePathW (MSI.@)
453 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder,
454 LPWSTR szPathBuf, LPDWORD pcchPathBuf )
456 awstring str;
458 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
460 str.unicode = TRUE;
461 str.str.w = szPathBuf;
463 return MSI_GetSourcePath( hInstall, szFolder, &str, pcchPathBuf );
466 /***********************************************************************
467 * MsiSetTargetPathA (MSI.@)
469 UINT WINAPI MsiSetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
470 LPCSTR szFolderPath )
472 LPWSTR szwFolder = NULL, szwFolderPath = NULL;
473 UINT rc = ERROR_OUTOFMEMORY;
475 if ( !szFolder || !szFolderPath )
476 return ERROR_INVALID_PARAMETER;
478 szwFolder = strdupAtoW(szFolder);
479 szwFolderPath = strdupAtoW(szFolderPath);
480 if (!szwFolder || !szwFolderPath)
481 goto end;
483 rc = MsiSetTargetPathW( hInstall, szwFolder, szwFolderPath );
485 end:
486 msi_free(szwFolder);
487 msi_free(szwFolderPath);
489 return rc;
493 * Ok my original interpretation of this was wrong. And it looks like msdn has
494 * changed a bit also. The given folder path does not have to actually already
495 * exist, it just cannot be read only and must be a legal folder path.
497 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
498 LPCWSTR szFolderPath)
500 DWORD attrib;
501 LPWSTR path = NULL;
502 LPWSTR path2 = NULL;
503 MSIFOLDER *folder;
504 MSIFILE *file;
506 TRACE("%p %s %s\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
508 attrib = GetFileAttributesW(szFolderPath);
509 /* native MSI tests writeability by making temporary files at each drive */
510 if ( attrib != INVALID_FILE_ATTRIBUTES &&
511 (attrib & FILE_ATTRIBUTE_OFFLINE ||
512 attrib & FILE_ATTRIBUTE_READONLY))
513 return ERROR_FUNCTION_FAILED;
515 path = resolve_folder(package,szFolder,FALSE,FALSE,FALSE,&folder);
516 if (!path)
517 return ERROR_DIRECTORY;
519 msi_free(folder->Property);
520 folder->Property = build_directory_name(2, szFolderPath, NULL);
522 if (lstrcmpiW(path, folder->Property) == 0)
525 * Resolved Target has not really changed, so just
526 * set this folder and do not recalculate everything.
528 msi_free(folder->ResolvedTarget);
529 folder->ResolvedTarget = NULL;
530 path2 = resolve_folder(package,szFolder,FALSE,TRUE,FALSE,NULL);
531 msi_free(path2);
533 else
535 MSIFOLDER *f;
537 LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
539 msi_free(f->ResolvedTarget);
540 f->ResolvedTarget=NULL;
543 LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
545 path2 = resolve_folder(package, f->Directory, FALSE, TRUE, FALSE, NULL);
546 msi_free(path2);
549 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
551 MSICOMPONENT *comp = file->Component;
552 LPWSTR p;
554 if (!comp)
555 continue;
557 p = resolve_folder(package, comp->Directory, FALSE, FALSE, FALSE, NULL);
558 msi_free(file->TargetPath);
560 file->TargetPath = build_directory_name(2, p, file->FileName);
561 msi_free(p);
564 msi_free(path);
566 return ERROR_SUCCESS;
569 /***********************************************************************
570 * MsiSetTargetPathW (MSI.@)
572 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
573 LPCWSTR szFolderPath)
575 MSIPACKAGE *package;
576 UINT ret;
578 TRACE("%s %s\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
580 if ( !szFolder || !szFolderPath )
581 return ERROR_INVALID_PARAMETER;
583 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
584 if (!package)
586 HRESULT hr;
587 BSTR folder, path;
588 IWineMsiRemotePackage *remote_package;
590 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
591 if (!remote_package)
592 return ERROR_INVALID_HANDLE;
594 folder = SysAllocString( szFolder );
595 path = SysAllocString( szFolderPath );
596 if (!folder || !path)
598 SysFreeString(folder);
599 SysFreeString(path);
600 IWineMsiRemotePackage_Release( remote_package );
601 return ERROR_OUTOFMEMORY;
604 hr = IWineMsiRemotePackage_SetTargetPath( remote_package, folder, path );
606 SysFreeString(folder);
607 SysFreeString(path);
608 IWineMsiRemotePackage_Release( remote_package );
610 if (FAILED(hr))
612 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
613 return HRESULT_CODE(hr);
615 return ERROR_FUNCTION_FAILED;
618 return ERROR_SUCCESS;
621 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
622 msiobj_release( &package->hdr );
623 return ret;
626 /***********************************************************************
627 * MsiGetMode (MSI.@)
629 * Returns an internal installer state (if it is running in a mode iRunMode)
631 * PARAMS
632 * hInstall [I] Handle to the installation
633 * hRunMode [I] Checking run mode
634 * MSIRUNMODE_ADMIN Administrative mode
635 * MSIRUNMODE_ADVERTISE Advertisement mode
636 * MSIRUNMODE_MAINTENANCE Maintenance mode
637 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
638 * MSIRUNMODE_LOGENABLED Log file is writing
639 * MSIRUNMODE_OPERATIONS Operations in progress??
640 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
641 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
642 * MSIRUNMODE_CABINET Files from cabinet are installed
643 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
644 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
645 * MSIRUNMODE_RESERVED11 Reserved
646 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
647 * MSIRUNMODE_ZAWENABLED Demand installation is supported
648 * MSIRUNMODE_RESERVED14 Reserved
649 * MSIRUNMODE_RESERVED15 Reserved
650 * MSIRUNMODE_SCHEDULED called from install script
651 * MSIRUNMODE_ROLLBACK called from rollback script
652 * MSIRUNMODE_COMMIT called from commit script
654 * RETURNS
655 * In the state: TRUE
656 * Not in the state: FALSE
659 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
661 MSIPACKAGE *package;
662 BOOL r = FALSE;
664 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
665 if (!package)
667 BOOL ret;
668 HRESULT hr;
669 IWineMsiRemotePackage *remote_package;
671 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
672 if (!remote_package)
673 return FALSE;
675 hr = IWineMsiRemotePackage_GetMode(remote_package, iRunMode, &ret);
676 IWineMsiRemotePackage_Release(remote_package);
678 if (hr == S_OK)
679 return ret;
681 return FALSE;
684 switch (iRunMode)
686 case MSIRUNMODE_WINDOWS9X:
687 if (GetVersion() & 0x80000000)
688 r = TRUE;
689 break;
691 case MSIRUNMODE_OPERATIONS:
692 case MSIRUNMODE_RESERVED11:
693 case MSIRUNMODE_RESERVED14:
694 case MSIRUNMODE_RESERVED15:
695 break;
697 case MSIRUNMODE_SCHEDULED:
698 r = package->scheduled_action_running;
699 break;
701 case MSIRUNMODE_ROLLBACK:
702 r = package->rollback_action_running;
703 break;
705 case MSIRUNMODE_COMMIT:
706 r = package->commit_action_running;
707 break;
709 default:
710 FIXME("%d %d\n", hInstall, iRunMode);
711 r = TRUE;
714 return r;
717 /***********************************************************************
718 * MsiSetMode (MSI.@)
720 UINT WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
722 FIXME("%d %d %d\n", hInstall, iRunMode, fState);
723 return ERROR_SUCCESS;
726 /***********************************************************************
727 * MsiSetFeatureStateA (MSI.@)
729 * According to the docs, when this is called it immediately recalculates
730 * all the component states as well
732 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
733 INSTALLSTATE iState)
735 LPWSTR szwFeature = NULL;
736 UINT rc;
738 szwFeature = strdupAtoW(szFeature);
740 if (!szwFeature)
741 return ERROR_FUNCTION_FAILED;
743 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
745 msi_free(szwFeature);
747 return rc;
752 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
753 INSTALLSTATE iState)
755 UINT rc = ERROR_SUCCESS;
756 MSIFEATURE *feature, *child;
758 TRACE("%s %i\n", debugstr_w(szFeature), iState);
760 feature = get_loaded_feature(package,szFeature);
761 if (!feature)
762 return ERROR_UNKNOWN_FEATURE;
764 if (iState == INSTALLSTATE_ADVERTISED &&
765 feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
766 return ERROR_FUNCTION_FAILED;
768 msi_feature_set_state(package, feature, iState);
770 ACTION_UpdateComponentStates(package,szFeature);
772 /* update all the features that are children of this feature */
773 LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
775 if (lstrcmpW(szFeature, child->Feature_Parent) == 0)
776 MSI_SetFeatureStateW(package, child->Feature, iState);
779 return rc;
782 /***********************************************************************
783 * MsiSetFeatureStateW (MSI.@)
785 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
786 INSTALLSTATE iState)
788 MSIPACKAGE* package;
789 UINT rc = ERROR_SUCCESS;
791 TRACE("%s %i\n",debugstr_w(szFeature), iState);
793 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
794 if (!package)
796 HRESULT hr;
797 BSTR feature;
798 IWineMsiRemotePackage *remote_package;
800 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
801 if (!remote_package)
802 return ERROR_INVALID_HANDLE;
804 feature = SysAllocString(szFeature);
805 if (!feature)
807 IWineMsiRemotePackage_Release(remote_package);
808 return ERROR_OUTOFMEMORY;
811 hr = IWineMsiRemotePackage_SetFeatureState(remote_package, feature, iState);
813 SysFreeString(feature);
814 IWineMsiRemotePackage_Release(remote_package);
816 if (FAILED(hr))
818 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
819 return HRESULT_CODE(hr);
821 return ERROR_FUNCTION_FAILED;
824 return ERROR_SUCCESS;
827 rc = MSI_SetFeatureStateW(package,szFeature,iState);
829 msiobj_release( &package->hdr );
830 return rc;
833 /***********************************************************************
834 * MsiGetFeatureStateA (MSI.@)
836 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
837 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
839 LPWSTR szwFeature = NULL;
840 UINT rc;
842 szwFeature = strdupAtoW(szFeature);
844 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
846 msi_free( szwFeature);
848 return rc;
851 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPCWSTR szFeature,
852 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
854 MSIFEATURE *feature;
856 feature = get_loaded_feature(package,szFeature);
857 if (!feature)
858 return ERROR_UNKNOWN_FEATURE;
860 if (piInstalled)
861 *piInstalled = feature->Installed;
863 if (piAction)
864 *piAction = feature->Action;
866 TRACE("returning %i %i\n", feature->Installed, feature->Action);
868 return ERROR_SUCCESS;
871 /***********************************************************************
872 * MsiGetFeatureStateW (MSI.@)
874 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
875 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
877 MSIPACKAGE* package;
878 UINT ret;
880 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled, piAction);
882 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
883 if (!package)
885 HRESULT hr;
886 BSTR feature;
887 IWineMsiRemotePackage *remote_package;
889 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
890 if (!remote_package)
891 return ERROR_INVALID_HANDLE;
893 feature = SysAllocString(szFeature);
894 if (!feature)
896 IWineMsiRemotePackage_Release(remote_package);
897 return ERROR_OUTOFMEMORY;
900 hr = IWineMsiRemotePackage_GetFeatureState(remote_package, feature,
901 piInstalled, piAction);
903 SysFreeString(feature);
904 IWineMsiRemotePackage_Release(remote_package);
906 if (FAILED(hr))
908 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
909 return HRESULT_CODE(hr);
911 return ERROR_FUNCTION_FAILED;
914 return ERROR_SUCCESS;
917 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
918 msiobj_release( &package->hdr );
919 return ret;
922 /***********************************************************************
923 * MsiGetFeatureCostA (MSI.@)
925 UINT WINAPI MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature,
926 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
928 LPWSTR szwFeature = NULL;
929 UINT rc;
931 szwFeature = strdupAtoW(szFeature);
933 rc = MsiGetFeatureCostW(hInstall, szwFeature, iCostTree, iState, piCost);
935 msi_free(szwFeature);
937 return rc;
940 UINT MSI_GetFeatureCost(MSIPACKAGE *package, MSIFEATURE *feature,
941 MSICOSTTREE iCostTree, INSTALLSTATE iState,
942 LPINT piCost)
944 FIXME("(%s %i %i %p): not implemented yet\n",
945 debugstr_w(feature->Feature), iCostTree, iState, piCost);
946 if (piCost) *piCost = 0;
947 return ERROR_SUCCESS;
950 /***********************************************************************
951 * MsiGetFeatureCostW (MSI.@)
953 UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature,
954 MSICOSTTREE iCostTree, INSTALLSTATE iState, LPINT piCost)
956 MSIPACKAGE *package;
957 MSIFEATURE *feature;
958 UINT ret;
960 TRACE("(%d %s %i %i %p)\n", hInstall, debugstr_w(szFeature),
961 iCostTree, iState, piCost);
963 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
964 if (!package)
966 HRESULT hr;
967 BSTR feature;
968 IWineMsiRemotePackage *remote_package;
970 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
971 if (!remote_package)
972 return ERROR_INVALID_HANDLE;
974 feature = SysAllocString(szFeature);
975 if (!feature)
977 IWineMsiRemotePackage_Release(remote_package);
978 return ERROR_OUTOFMEMORY;
981 hr = IWineMsiRemotePackage_GetFeatureCost(remote_package, feature,
982 iCostTree, iState, piCost);
984 SysFreeString(feature);
985 IWineMsiRemotePackage_Release(remote_package);
987 if (FAILED(hr))
989 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
990 return HRESULT_CODE(hr);
992 return ERROR_FUNCTION_FAILED;
995 return ERROR_SUCCESS;
998 feature = get_loaded_feature(package, szFeature);
1000 if (feature)
1001 ret = MSI_GetFeatureCost(package, feature, iCostTree, iState, piCost);
1002 else
1003 ret = ERROR_UNKNOWN_FEATURE;
1005 msiobj_release( &package->hdr );
1006 return ret;
1009 /***********************************************************************
1010 * MsiSetComponentStateA (MSI.@)
1012 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1013 INSTALLSTATE iState)
1015 UINT rc;
1016 LPWSTR szwComponent = strdupAtoW(szComponent);
1018 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
1020 msi_free(szwComponent);
1022 return rc;
1025 /***********************************************************************
1026 * MsiGetComponentStateA (MSI.@)
1028 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
1029 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1031 LPWSTR szwComponent= NULL;
1032 UINT rc;
1034 szwComponent= strdupAtoW(szComponent);
1036 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
1038 msi_free( szwComponent);
1040 return rc;
1043 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1044 INSTALLSTATE iState)
1046 MSICOMPONENT *comp;
1048 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
1050 comp = get_loaded_component(package, szComponent);
1051 if (!comp)
1052 return ERROR_UNKNOWN_COMPONENT;
1054 comp->Installed = iState;
1056 return ERROR_SUCCESS;
1059 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
1060 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1062 MSICOMPONENT *comp;
1064 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
1065 piInstalled, piAction);
1067 comp = get_loaded_component(package,szComponent);
1068 if (!comp)
1069 return ERROR_UNKNOWN_COMPONENT;
1071 if (piInstalled)
1072 *piInstalled = comp->Installed;
1074 if (piAction)
1075 *piAction = comp->Action;
1077 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
1079 return ERROR_SUCCESS;
1082 /***********************************************************************
1083 * MsiSetComponentStateW (MSI.@)
1085 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1086 INSTALLSTATE iState)
1088 MSIPACKAGE* package;
1089 UINT ret;
1091 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1092 if (!package)
1094 HRESULT hr;
1095 BSTR component;
1096 IWineMsiRemotePackage *remote_package;
1098 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1099 if (!remote_package)
1100 return ERROR_INVALID_HANDLE;
1102 component = SysAllocString(szComponent);
1103 if (!component)
1105 IWineMsiRemotePackage_Release(remote_package);
1106 return ERROR_OUTOFMEMORY;
1109 hr = IWineMsiRemotePackage_SetComponentState(remote_package, component, iState);
1111 SysFreeString(component);
1112 IWineMsiRemotePackage_Release(remote_package);
1114 if (FAILED(hr))
1116 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1117 return HRESULT_CODE(hr);
1119 return ERROR_FUNCTION_FAILED;
1122 return ERROR_SUCCESS;
1125 ret = MSI_SetComponentStateW(package, szComponent, iState);
1126 msiobj_release(&package->hdr);
1127 return ret;
1130 /***********************************************************************
1131 * MsiGetComponentStateW (MSI.@)
1133 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
1134 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
1136 MSIPACKAGE* package;
1137 UINT ret;
1139 TRACE("%d %s %p %p\n", hInstall, debugstr_w(szComponent),
1140 piInstalled, piAction);
1142 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1143 if (!package)
1145 HRESULT hr;
1146 BSTR component;
1147 IWineMsiRemotePackage *remote_package;
1149 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1150 if (!remote_package)
1151 return ERROR_INVALID_HANDLE;
1153 component = SysAllocString(szComponent);
1154 if (!component)
1156 IWineMsiRemotePackage_Release(remote_package);
1157 return ERROR_OUTOFMEMORY;
1160 hr = IWineMsiRemotePackage_GetComponentState(remote_package, component,
1161 piInstalled, piAction);
1163 SysFreeString(component);
1164 IWineMsiRemotePackage_Release(remote_package);
1166 if (FAILED(hr))
1168 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1169 return HRESULT_CODE(hr);
1171 return ERROR_FUNCTION_FAILED;
1174 return ERROR_SUCCESS;
1177 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
1178 msiobj_release( &package->hdr );
1179 return ret;
1182 /***********************************************************************
1183 * MsiGetLanguage (MSI.@)
1185 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
1187 MSIPACKAGE* package;
1188 LANGID langid;
1189 static const WCHAR szProductLanguage[] =
1190 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
1192 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1193 if (!package)
1195 HRESULT hr;
1196 LANGID lang;
1197 IWineMsiRemotePackage *remote_package;
1199 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1200 if (!remote_package)
1201 return ERROR_INVALID_HANDLE;
1203 hr = IWineMsiRemotePackage_GetLanguage(remote_package, &lang);
1205 if (SUCCEEDED(hr))
1206 return lang;
1208 return 0;
1211 langid = msi_get_property_int( package, szProductLanguage, 0 );
1212 msiobj_release( &package->hdr );
1213 return langid;
1216 UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel )
1218 static const WCHAR szInstallLevel[] = {
1219 'I','N','S','T','A','L','L','L','E','V','E','L',0 };
1220 static const WCHAR fmt[] = { '%','d',0 };
1221 WCHAR level[6];
1222 UINT r;
1224 TRACE("%p %i\n", package, iInstallLevel);
1226 if (iInstallLevel > 32767)
1227 return ERROR_INVALID_PARAMETER;
1229 if (iInstallLevel < 1)
1230 return MSI_SetFeatureStates( package );
1232 sprintfW( level, fmt, iInstallLevel );
1233 r = MSI_SetPropertyW( package, szInstallLevel, level );
1234 if ( r == ERROR_SUCCESS )
1235 r = MSI_SetFeatureStates( package );
1237 return r;
1240 /***********************************************************************
1241 * MsiSetInstallLevel (MSI.@)
1243 UINT WINAPI MsiSetInstallLevel(MSIHANDLE hInstall, int iInstallLevel)
1245 MSIPACKAGE* package;
1246 UINT r;
1248 TRACE("%d %i\n", hInstall, iInstallLevel);
1250 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
1251 if (!package)
1253 HRESULT hr;
1254 IWineMsiRemotePackage *remote_package;
1256 remote_package = (IWineMsiRemotePackage *)msi_get_remote(hInstall);
1257 if (!remote_package)
1258 return ERROR_INVALID_HANDLE;
1260 hr = IWineMsiRemotePackage_SetInstallLevel(remote_package, iInstallLevel);
1262 IWineMsiRemotePackage_Release(remote_package);
1264 if (FAILED(hr))
1266 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1267 return HRESULT_CODE(hr);
1269 return ERROR_FUNCTION_FAILED;
1272 return ERROR_SUCCESS;
1275 r = MSI_SetInstallLevel( package, iInstallLevel );
1277 msiobj_release( &package->hdr );
1279 return r;
1282 /***********************************************************************
1283 * MsiGetFeatureValidStatesW (MSI.@)
1285 UINT WINAPI MsiGetFeatureValidStatesW(MSIHANDLE hInstall, LPCWSTR szFeature,
1286 LPDWORD pInstallState)
1288 if(pInstallState) *pInstallState = 1<<INSTALLSTATE_LOCAL;
1289 FIXME("%d %s %p stub returning %d\n",
1290 hInstall, debugstr_w(szFeature), pInstallState, pInstallState ? *pInstallState : 0);
1292 return ERROR_SUCCESS;
1295 /***********************************************************************
1296 * MsiGetFeatureValidStatesA (MSI.@)
1298 UINT WINAPI MsiGetFeatureValidStatesA(MSIHANDLE hInstall, LPCSTR szFeature,
1299 LPDWORD pInstallState)
1301 UINT ret;
1302 LPWSTR szwFeature = strdupAtoW(szFeature);
1304 ret = MsiGetFeatureValidStatesW(hInstall, szwFeature, pInstallState);
1306 msi_free(szwFeature);
1308 return ret;