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 */
28 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msi);
36 /***********************************************************************
37 * MsiDoActionA (MSI.@)
39 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
44 TRACE("%s\n", debugstr_a(szAction));
46 szwAction = strdupAtoW(szAction);
47 if (szAction && !szwAction)
48 return ERROR_FUNCTION_FAILED;
50 ret = MsiDoActionW( hInstall, szwAction );
51 msi_free( szwAction );
55 /***********************************************************************
56 * MsiDoActionW (MSI.@)
58 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
63 TRACE("%s\n",debugstr_w(szAction));
66 return ERROR_INVALID_PARAMETER;
68 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
70 return ERROR_INVALID_HANDLE;
72 ret = ACTION_PerformUIAction( package, szAction );
73 msiobj_release( &package->hdr );
78 /***********************************************************************
79 * MsiSequenceA (MSI.@)
81 UINT WINAPI MsiSequenceA( MSIHANDLE hInstall, LPCSTR szTable, INT iSequenceMode )
86 TRACE("%s\n", debugstr_a(szTable));
88 szwTable = strdupAtoW(szTable);
89 if (szTable && !szwTable)
90 return ERROR_FUNCTION_FAILED;
92 ret = MsiSequenceW( hInstall, szwTable, iSequenceMode );
97 /***********************************************************************
98 * MsiSequenceW (MSI.@)
100 UINT WINAPI MsiSequenceW( MSIHANDLE hInstall, LPCWSTR szTable, INT iSequenceMode )
105 TRACE("%s\n", debugstr_w(szTable));
107 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
109 return ERROR_INVALID_HANDLE;
111 ret = MSI_Sequence( package, szTable, iSequenceMode );
112 msiobj_release( &package->hdr );
117 UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz )
119 UINT len, r = ERROR_SUCCESS;
121 if (awbuf->str.w && !sz )
122 return ERROR_INVALID_PARAMETER;
129 len = lstrlenW( str );
131 lstrcpynW( awbuf->str.w, str, *sz );
135 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
138 WideCharToMultiByte( CP_ACP, 0, str, -1, awbuf->str.a, *sz, NULL, NULL );
139 if ( awbuf->str.a && *sz && (len >= *sz) )
140 awbuf->str.a[*sz - 1] = 0;
143 if (awbuf->str.w && len >= *sz)
149 /***********************************************************************
150 * MsiGetTargetPath (internal)
152 static UINT WINAPI MSI_GetTargetPath( MSIHANDLE hInstall, LPCWSTR szFolder,
153 awstring *szPathBuf, DWORD* pcchPathBuf )
160 return ERROR_INVALID_PARAMETER;
162 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
164 return ERROR_INVALID_HANDLE;
166 path = resolve_folder( package, szFolder, FALSE, FALSE, TRUE, NULL );
167 msiobj_release( &package->hdr );
170 return ERROR_DIRECTORY;
172 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
177 /***********************************************************************
178 * MsiGetTargetPathA (MSI.@)
180 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
181 LPSTR szPathBuf, DWORD* pcchPathBuf )
187 TRACE("%s %p %p\n", debugstr_a(szFolder), szPathBuf, pcchPathBuf);
189 szwFolder = strdupAtoW(szFolder);
190 if (szFolder && !szwFolder)
191 return ERROR_FUNCTION_FAILED;
193 path.unicode = FALSE;
194 path.str.a = szPathBuf;
196 r = MSI_GetTargetPath( hInstall, szwFolder, &path, pcchPathBuf );
198 msi_free( szwFolder );
203 /***********************************************************************
204 * MsiGetTargetPathW (MSI.@)
206 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder,
207 LPWSTR szPathBuf, DWORD* pcchPathBuf )
211 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf);
214 path.str.w = szPathBuf;
216 return MSI_GetTargetPath( hInstall, szFolder, &path, pcchPathBuf );
219 /***********************************************************************
220 * MsiGetSourcePath (internal)
222 static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
223 awstring *szPathBuf, DWORD* pcchPathBuf )
229 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
232 return ERROR_INVALID_PARAMETER;
234 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
236 return ERROR_INVALID_HANDLE;
238 if (szPathBuf->str.w && !pcchPathBuf )
240 msiobj_release( &package->hdr );
241 return ERROR_INVALID_PARAMETER;
244 path = resolve_folder(package, szFolder, TRUE, FALSE, TRUE, NULL);
245 msiobj_release( &package->hdr );
247 TRACE("path = %s\n",debugstr_w(path));
249 return ERROR_DIRECTORY;
251 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
256 /***********************************************************************
257 * MsiGetSourcePathA (MSI.@)
259 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
260 LPSTR szPathBuf, DWORD* pcchPathBuf )
266 TRACE("%s %p %p\n", szFolder, debugstr_a(szPathBuf), pcchPathBuf);
269 str.str.a = szPathBuf;
271 folder = strdupAtoW( szFolder );
272 r = MSI_GetSourcePath( hInstall, folder, &str, pcchPathBuf );
278 /***********************************************************************
279 * MsiGetSourcePathW (MSI.@)
281 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder,
282 LPWSTR szPathBuf, DWORD* pcchPathBuf )
286 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
289 str.str.w = szPathBuf;
291 return MSI_GetSourcePath( hInstall, szFolder, &str, pcchPathBuf );
294 /***********************************************************************
295 * MsiSetTargetPathA (MSI.@)
297 UINT WINAPI MsiSetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
298 LPCSTR szFolderPath )
300 LPWSTR szwFolder = NULL, szwFolderPath = NULL;
301 UINT rc = ERROR_OUTOFMEMORY;
303 if ( !szFolder || !szFolderPath )
304 return ERROR_INVALID_PARAMETER;
306 szwFolder = strdupAtoW(szFolder);
307 szwFolderPath = strdupAtoW(szFolderPath);
308 if (!szwFolder || !szwFolderPath)
311 rc = MsiSetTargetPathW( hInstall, szwFolder, szwFolderPath );
315 msi_free(szwFolderPath);
321 * Ok my original interpretation of this was wrong. And it looks like msdn has
322 * changed a bit also. The given folder path does not have to actually already
323 * exist, it just cannot be read only and must be a legal folder path.
325 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
326 LPCWSTR szFolderPath)
334 TRACE("%p %s %s\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
336 attrib = GetFileAttributesW(szFolderPath);
337 /* native MSI tests writeability by making temporary files at each drive */
338 if ( attrib != INVALID_FILE_ATTRIBUTES &&
339 (attrib & FILE_ATTRIBUTE_OFFLINE ||
340 attrib & FILE_ATTRIBUTE_READONLY))
341 return ERROR_FUNCTION_FAILED;
343 path = resolve_folder(package,szFolder,FALSE,FALSE,FALSE,&folder);
345 return ERROR_DIRECTORY;
347 msi_free(folder->Property);
348 folder->Property = build_directory_name(2, szFolderPath, NULL);
350 if (lstrcmpiW(path, folder->Property) == 0)
353 * Resolved Target has not really changed, so just
354 * set this folder and do not recalculate everything.
356 msi_free(folder->ResolvedTarget);
357 folder->ResolvedTarget = NULL;
358 path2 = resolve_folder(package,szFolder,FALSE,TRUE,FALSE,NULL);
365 LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
367 msi_free(f->ResolvedTarget);
368 f->ResolvedTarget=NULL;
371 LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
373 path2 = resolve_folder(package, f->Directory, FALSE, TRUE, FALSE, NULL);
377 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
379 MSICOMPONENT *comp = file->Component;
385 p = resolve_folder(package, comp->Directory, FALSE, FALSE, FALSE, NULL);
386 msi_free(file->TargetPath);
388 file->TargetPath = build_directory_name(2, p, file->FileName);
394 return ERROR_SUCCESS;
397 /***********************************************************************
398 * MsiSetTargetPathW (MSI.@)
400 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
401 LPCWSTR szFolderPath)
406 TRACE("%s %s\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
408 if ( !szFolder || !szFolderPath )
409 return ERROR_INVALID_PARAMETER;
411 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
413 return ERROR_INVALID_HANDLE;
415 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
416 msiobj_release( &package->hdr );
420 /***********************************************************************
423 * Returns an internal installer state (if it is running in a mode iRunMode)
426 * hInstall [I] Handle to the installation
427 * hRunMode [I] Checking run mode
428 * MSIRUNMODE_ADMIN Administrative mode
429 * MSIRUNMODE_ADVERTISE Advertisement mode
430 * MSIRUNMODE_MAINTENANCE Maintenance mode
431 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
432 * MSIRUNMODE_LOGENABLED Log file is writing
433 * MSIRUNMODE_OPERATIONS Operations in progress??
434 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
435 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
436 * MSIRUNMODE_CABINET Files from cabinet are installed
437 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
438 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
439 * MSIRUNMODE_RESERVED11 Reserved
440 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
441 * MSIRUNMODE_ZAWENABLED Demand installation is supported
442 * MSIRUNMODE_RESERVED14 Reserved
443 * MSIRUNMODE_RESERVED15 Reserved
444 * MSIRUNMODE_SCHEDULED called from install script
445 * MSIRUNMODE_ROLLBACK called from rollback script
446 * MSIRUNMODE_COMMIT called from commit script
450 * Not in the state: FALSE
453 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
459 case MSIRUNMODE_WINDOWS9X:
460 if (GetVersion() & 0x80000000)
464 case MSIRUNMODE_RESERVED11:
465 case MSIRUNMODE_RESERVED14:
466 case MSIRUNMODE_RESERVED15:
469 case MSIRUNMODE_SCHEDULED:
470 case MSIRUNMODE_ROLLBACK:
471 case MSIRUNMODE_COMMIT:
475 FIXME("%ld %d\n", hInstall, iRunMode);
482 /***********************************************************************
485 BOOL WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
489 case MSIRUNMODE_RESERVED11:
490 case MSIRUNMODE_WINDOWS9X:
491 case MSIRUNMODE_RESERVED14:
492 case MSIRUNMODE_RESERVED15:
495 FIXME("%ld %d %d\n", hInstall, iRunMode, fState);
500 /***********************************************************************
501 * MsiSetFeatureStateA (MSI.@)
503 * According to the docs, when this is called it immediately recalculates
504 * all the component states as well
506 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
509 LPWSTR szwFeature = NULL;
512 szwFeature = strdupAtoW(szFeature);
515 return ERROR_FUNCTION_FAILED;
517 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
519 msi_free(szwFeature);
526 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
529 UINT rc = ERROR_SUCCESS;
530 MSIFEATURE *feature, *child;
532 TRACE("%s %i\n", debugstr_w(szFeature), iState);
534 feature = get_loaded_feature(package,szFeature);
536 return ERROR_UNKNOWN_FEATURE;
538 if (iState == INSTALLSTATE_ADVERTISED &&
539 feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
540 return ERROR_FUNCTION_FAILED;
542 msi_feature_set_state( feature, iState );
544 ACTION_UpdateComponentStates(package,szFeature);
546 /* update all the features that are children of this feature */
547 LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
549 if (lstrcmpW(szFeature, child->Feature_Parent) == 0)
550 MSI_SetFeatureStateW(package, child->Feature, iState);
556 /***********************************************************************
557 * MsiSetFeatureStateW (MSI.@)
559 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
563 UINT rc = ERROR_SUCCESS;
565 TRACE("%s %i\n",debugstr_w(szFeature), iState);
567 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
569 return ERROR_INVALID_HANDLE;
571 rc = MSI_SetFeatureStateW(package,szFeature,iState);
573 msiobj_release( &package->hdr );
577 /***********************************************************************
578 * MsiGetFeatureStateA (MSI.@)
580 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
581 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
583 LPWSTR szwFeature = NULL;
586 szwFeature = strdupAtoW(szFeature);
588 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
590 msi_free( szwFeature);
595 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPCWSTR szFeature,
596 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
600 feature = get_loaded_feature(package,szFeature);
602 return ERROR_UNKNOWN_FEATURE;
605 *piInstalled = feature->Installed;
608 *piAction = feature->Action;
610 TRACE("returning %i %i\n", feature->Installed, feature->Action);
612 return ERROR_SUCCESS;
615 /***********************************************************************
616 * MsiGetFeatureStateW (MSI.@)
618 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
619 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
624 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled, piAction);
626 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
628 return ERROR_INVALID_HANDLE;
629 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
630 msiobj_release( &package->hdr );
634 /***********************************************************************
635 * MsiGetFeatureCostA (MSI.@)
637 UINT WINAPI MsiGetFeatureCostA(MSIHANDLE hInstall, LPCSTR szFeature,
638 MSICOSTTREE iCostTree, INSTALLSTATE iState, INT *piCost)
640 FIXME("(%ld %s %i %i %p): stub\n", hInstall, debugstr_a(szFeature),
641 iCostTree, iState, piCost);
642 if (piCost) *piCost = 0;
643 return ERROR_SUCCESS;
646 /***********************************************************************
647 * MsiGetFeatureCostW (MSI.@)
649 UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature,
650 MSICOSTTREE iCostTree, INSTALLSTATE iState, INT *piCost)
652 FIXME("(%ld %s %i %i %p): stub\n", hInstall, debugstr_w(szFeature),
653 iCostTree, iState, piCost);
654 if (piCost) *piCost = 0;
655 return ERROR_SUCCESS;
658 /***********************************************************************
659 * MsiSetComponentStateA (MSI.@)
661 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
665 LPWSTR szwComponent = strdupAtoW(szComponent);
667 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
669 msi_free(szwComponent);
674 /***********************************************************************
675 * MsiGetComponentStateA (MSI.@)
677 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
678 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
680 LPWSTR szwComponent= NULL;
683 szwComponent= strdupAtoW(szComponent);
685 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
687 msi_free( szwComponent);
692 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
697 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
699 comp = get_loaded_component(package, szComponent);
701 return ERROR_UNKNOWN_COMPONENT;
703 comp->Installed = iState;
705 return ERROR_SUCCESS;
708 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
709 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
713 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
714 piInstalled, piAction);
716 comp = get_loaded_component(package,szComponent);
718 return ERROR_UNKNOWN_COMPONENT;
721 *piInstalled = comp->Installed;
724 *piAction = comp->Action;
726 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
728 return ERROR_SUCCESS;
731 /***********************************************************************
732 * MsiSetComponentStateW (MSI.@)
734 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
740 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
742 return ERROR_INVALID_HANDLE;
743 ret = MSI_SetComponentStateW(package, szComponent, iState);
744 msiobj_release(&package->hdr);
748 /***********************************************************************
749 * MsiGetComponentStateW (MSI.@)
751 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
752 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
757 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
758 piInstalled, piAction);
760 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
762 return ERROR_INVALID_HANDLE;
763 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
764 msiobj_release( &package->hdr );
768 /***********************************************************************
769 * MsiGetLanguage (MSI.@)
771 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
775 static const WCHAR szProductLanguage[] =
776 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
778 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
780 return ERROR_INVALID_HANDLE;
782 langid = msi_get_property_int( package, szProductLanguage, 0 );
783 msiobj_release( &package->hdr );
787 UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel )
789 static const WCHAR szInstallLevel[] = {
790 'I','N','S','T','A','L','L','L','E','V','E','L',0 };
791 static const WCHAR fmt[] = { '%','d',0 };
795 TRACE("%p %i\n", package, iInstallLevel);
797 if (iInstallLevel<1 || iInstallLevel>32767)
798 return ERROR_INVALID_PARAMETER;
800 sprintfW( level, fmt, iInstallLevel );
801 r = MSI_SetPropertyW( package, szInstallLevel, level );
802 if ( r == ERROR_SUCCESS )
804 r = MSI_SetFeatureStates( package );
810 /***********************************************************************
811 * MsiSetInstallLevel (MSI.@)
813 UINT WINAPI MsiSetInstallLevel(MSIHANDLE hInstall, int iInstallLevel)
818 TRACE("%ld %i\n", hInstall, iInstallLevel);
820 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
822 return ERROR_INVALID_HANDLE;
824 r = MSI_SetInstallLevel( package, iInstallLevel );
826 msiobj_release( &package->hdr );
831 /***********************************************************************
832 * MsiGetFeatureValidStatesW (MSI.@)
834 UINT WINAPI MsiGetFeatureValidStatesW(MSIHANDLE hInstall, LPCWSTR szFeature,
835 DWORD* pInstallState)
837 if(pInstallState) *pInstallState = 1<<INSTALLSTATE_LOCAL;
838 FIXME("%ld %s %p stub returning %d\n",
839 hInstall, debugstr_w(szFeature), pInstallState, pInstallState ? *pInstallState : 0);
841 return ERROR_SUCCESS;
844 /***********************************************************************
845 * MsiGetFeatureValidStatesA (MSI.@)
847 UINT WINAPI MsiGetFeatureValidStatesA(MSIHANDLE hInstall, LPCSTR szFeature,
848 DWORD* pInstallState)
851 LPWSTR szwFeature = strdupAtoW(szFeature);
853 ret = MsiGetFeatureValidStatesW(hInstall, szwFeature, pInstallState);
855 msi_free(szwFeature);