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"
33 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi);
38 /***********************************************************************
39 * MsiDoActionA (MSI.@)
41 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
46 TRACE("%s\n", debugstr_a(szAction));
48 szwAction = strdupAtoW(szAction);
49 if (szAction && !szwAction)
50 return ERROR_FUNCTION_FAILED;
52 ret = MsiDoActionW( hInstall, szwAction );
53 msi_free( szwAction );
57 /***********************************************************************
58 * MsiDoActionW (MSI.@)
60 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
65 TRACE("%s\n",debugstr_w(szAction));
68 return ERROR_INVALID_PARAMETER;
70 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
72 return ERROR_INVALID_HANDLE;
74 ret = ACTION_PerformUIAction( package, szAction );
75 msiobj_release( &package->hdr );
80 /***********************************************************************
81 * MsiSequenceA (MSI.@)
83 UINT WINAPI MsiSequenceA( MSIHANDLE hInstall, LPCSTR szTable, INT iSequenceMode )
88 TRACE("%s\n", debugstr_a(szTable));
90 szwTable = strdupAtoW(szTable);
91 if (szTable && !szwTable)
92 return ERROR_FUNCTION_FAILED;
94 ret = MsiSequenceW( hInstall, szwTable, iSequenceMode );
99 /***********************************************************************
100 * MsiSequenceW (MSI.@)
102 UINT WINAPI MsiSequenceW( MSIHANDLE hInstall, LPCWSTR szTable, INT iSequenceMode )
107 TRACE("%s\n", debugstr_w(szTable));
109 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
111 return ERROR_INVALID_HANDLE;
113 ret = MSI_Sequence( package, szTable, iSequenceMode );
114 msiobj_release( &package->hdr );
119 UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz )
121 UINT len, r = ERROR_SUCCESS;
123 if (awbuf->str.w && !sz )
124 return ERROR_INVALID_PARAMETER;
131 len = lstrlenW( str );
133 lstrcpynW( awbuf->str.w, str, *sz );
137 len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
140 WideCharToMultiByte( CP_ACP, 0, str, -1, awbuf->str.a, *sz, NULL, NULL );
141 if ( *sz && (len >= *sz) )
142 awbuf->str.a[*sz - 1] = 0;
145 if (awbuf->str.w && len >= *sz)
151 /***********************************************************************
152 * MsiGetTargetPath (internal)
154 UINT WINAPI MSI_GetTargetPath( MSIHANDLE hInstall, LPCWSTR szFolder,
155 awstring *szPathBuf, DWORD* pcchPathBuf )
162 return ERROR_INVALID_PARAMETER;
164 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
166 return ERROR_INVALID_HANDLE;
168 path = resolve_folder( package, szFolder, FALSE, FALSE, NULL );
169 msiobj_release( &package->hdr );
172 return ERROR_DIRECTORY;
174 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
179 /***********************************************************************
180 * MsiGetTargetPathA (MSI.@)
182 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
183 LPSTR szPathBuf, DWORD* pcchPathBuf )
189 TRACE("%s %p %p\n", debugstr_a(szFolder), szPathBuf, pcchPathBuf);
191 szwFolder = strdupAtoW(szFolder);
192 if (szFolder && !szwFolder)
193 return ERROR_FUNCTION_FAILED;
195 path.unicode = FALSE;
196 path.str.a = szPathBuf;
198 r = MSI_GetTargetPath( hInstall, szwFolder, &path, pcchPathBuf );
200 msi_free( szwFolder );
205 /***********************************************************************
206 * MsiGetTargetPathW (MSI.@)
208 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder,
209 LPWSTR szPathBuf, DWORD* pcchPathBuf )
213 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf);
216 path.str.w = szPathBuf;
218 return MSI_GetTargetPath( hInstall, szFolder, &path, pcchPathBuf );
221 /***********************************************************************
222 * MsiGetSourcePath (internal)
224 static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
225 awstring *szPathBuf, DWORD* pcchPathBuf )
231 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
234 return ERROR_INVALID_PARAMETER;
236 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
238 return ERROR_INVALID_HANDLE;
240 if (szPathBuf->str.w && !pcchPathBuf )
242 msiobj_release( &package->hdr );
243 return ERROR_INVALID_PARAMETER;
246 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
247 msiobj_release( &package->hdr );
249 TRACE("path = %s\n",debugstr_w(path));
251 return ERROR_DIRECTORY;
253 r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
258 /***********************************************************************
259 * MsiGetSourcePathA (MSI.@)
261 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
262 LPSTR szPathBuf, DWORD* pcchPathBuf )
268 TRACE("%s %p %p\n", szFolder, debugstr_a(szPathBuf), pcchPathBuf);
271 str.str.a = szPathBuf;
273 folder = strdupAtoW( szFolder );
274 r = MSI_GetSourcePath( hInstall, folder, &str, pcchPathBuf );
280 /***********************************************************************
281 * MsiGetSourcePathW (MSI.@)
283 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder,
284 LPWSTR szPathBuf, DWORD* pcchPathBuf )
288 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
291 str.str.w = szPathBuf;
293 return MSI_GetSourcePath( hInstall, szFolder, &str, pcchPathBuf );
296 /***********************************************************************
297 * MsiSetTargetPathA (MSI.@)
299 UINT WINAPI MsiSetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
300 LPCSTR szFolderPath )
302 LPWSTR szwFolder = NULL, szwFolderPath = NULL;
303 UINT rc = ERROR_OUTOFMEMORY;
305 if ( !szFolder || !szFolderPath )
306 return ERROR_INVALID_PARAMETER;
308 szwFolder = strdupAtoW(szFolder);
309 szwFolderPath = strdupAtoW(szFolderPath);
310 if (!szwFolder || !szwFolderPath)
313 rc = MsiSetTargetPathW( hInstall, szwFolder, szwFolderPath );
317 msi_free(szwFolderPath);
323 * Ok my original interpretation of this was wrong. And it looks like msdn has
324 * changed a bit also. The given folder path does not have to actually already
325 * exist, it just cannot be read only and must be a legal folder path.
327 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
328 LPCWSTR szFolderPath)
336 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
338 attrib = GetFileAttributesW(szFolderPath);
339 if ( attrib != INVALID_FILE_ATTRIBUTES &&
340 (attrib & FILE_ATTRIBUTE_OFFLINE ||
341 attrib & FILE_ATTRIBUTE_READONLY)) /* actually native MSI tests writeability by making temporary files at each drive */
342 return ERROR_FUNCTION_FAILED;
344 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
346 return ERROR_DIRECTORY;
349 msi_free(folder->Property);
350 folder->Property = build_directory_name(2, szFolderPath, NULL);
352 if (lstrcmpiW(path, folder->Property) == 0)
355 * Resolved Target has not really changed, so just
356 * set this folder and do not recalculate everything.
358 msi_free(folder->ResolvedTarget);
359 folder->ResolvedTarget = NULL;
360 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
367 LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
369 msi_free(f->ResolvedTarget);
370 f->ResolvedTarget=NULL;
373 LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
375 path2 = resolve_folder(package, f->Directory, FALSE, TRUE, NULL);
379 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
381 MSICOMPONENT *comp = file->Component;
387 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
388 msi_free(file->TargetPath);
390 file->TargetPath = build_directory_name(2, p, file->FileName);
396 return ERROR_SUCCESS;
399 /***********************************************************************
400 * MsiSetTargetPathW (MSI.@)
402 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
403 LPCWSTR szFolderPath)
408 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
410 if ( !szFolder || !szFolderPath )
411 return ERROR_INVALID_PARAMETER;
413 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
415 return ERROR_INVALID_HANDLE;
417 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
418 msiobj_release( &package->hdr );
422 /***********************************************************************
425 * Returns an internal installer state (if it is running in a mode iRunMode)
428 * hInstall [I] Handle to the installation
429 * hRunMode [I] Checking run mode
430 * MSIRUNMODE_ADMIN Administrative mode
431 * MSIRUNMODE_ADVERTISE Advertisement mode
432 * MSIRUNMODE_MAINTENANCE Maintenance mode
433 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
434 * MSIRUNMODE_LOGENABLED Log file is writing
435 * MSIRUNMODE_OPERATIONS Operations in progress??
436 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
437 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
438 * MSIRUNMODE_CABINET Files from cabinet are installed
439 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
440 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
441 * MSIRUNMODE_RESERVED11 Reserved
442 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
443 * MSIRUNMODE_ZAWENABLED Demand installation is supported
444 * MSIRUNMODE_RESERVED14 Reserved
445 * MSIRUNMODE_RESERVED15 Reserved
446 * MSIRUNMODE_SCHEDULED called from install script
447 * MSIRUNMODE_ROLLBACK called from rollback script
448 * MSIRUNMODE_COMMIT called from commit script
452 * Not in the state: FALSE
456 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
462 case MSIRUNMODE_WINDOWS9X:
463 if (GetVersion() & 0x80000000)
467 case MSIRUNMODE_RESERVED11:
468 case MSIRUNMODE_RESERVED14:
469 case MSIRUNMODE_RESERVED15:
472 case MSIRUNMODE_SCHEDULED:
473 case MSIRUNMODE_ROLLBACK:
474 case MSIRUNMODE_COMMIT:
478 FIXME("%ld %d\n", hInstall, iRunMode);
485 /***********************************************************************
488 BOOL WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
492 case MSIRUNMODE_RESERVED11:
493 case MSIRUNMODE_WINDOWS9X:
494 case MSIRUNMODE_RESERVED14:
495 case MSIRUNMODE_RESERVED15:
498 FIXME("%ld %d %d\n", hInstall, iRunMode, fState);
503 /***********************************************************************
504 * MsiSetFeatureStateA (MSI.@)
506 * According to the docs, when this is called it immediately recalculates
507 * all the component states as well
509 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
512 LPWSTR szwFeature = NULL;
515 szwFeature = strdupAtoW(szFeature);
518 return ERROR_FUNCTION_FAILED;
520 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
522 msi_free(szwFeature);
529 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
532 UINT rc = ERROR_SUCCESS;
533 MSIFEATURE *feature, *child;
535 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
537 feature = get_loaded_feature(package,szFeature);
539 return ERROR_UNKNOWN_FEATURE;
541 if (iState == INSTALLSTATE_ADVERTISED &&
542 feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
543 return ERROR_FUNCTION_FAILED;
545 feature->ActionRequest = iState;
546 feature->Action = iState;
548 ACTION_UpdateComponentStates(package,szFeature);
550 /* update all the features that are children of this feature */
551 LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
553 if (lstrcmpW(szFeature, child->Feature_Parent) == 0)
554 MSI_SetFeatureStateW(package, child->Feature, iState);
560 /***********************************************************************
561 * MsiSetFeatureStateW (MSI.@)
563 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
567 UINT rc = ERROR_SUCCESS;
569 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
571 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
573 return ERROR_INVALID_HANDLE;
575 rc = MSI_SetFeatureStateW(package,szFeature,iState);
577 msiobj_release( &package->hdr );
581 /***********************************************************************
582 * MsiGetFeatureStateA (MSI.@)
584 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
585 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
587 LPWSTR szwFeature = NULL;
590 szwFeature = strdupAtoW(szFeature);
592 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
594 msi_free( szwFeature);
599 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
600 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
604 feature = get_loaded_feature(package,szFeature);
606 return ERROR_UNKNOWN_FEATURE;
609 *piInstalled = feature->Installed;
612 *piAction = feature->Action;
614 TRACE("returning %i %i\n", feature->Installed, feature->Action);
616 return ERROR_SUCCESS;
619 /***********************************************************************
620 * MsiGetFeatureStateW (MSI.@)
622 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
623 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
628 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
631 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
633 return ERROR_INVALID_HANDLE;
634 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
635 msiobj_release( &package->hdr );
639 /***********************************************************************
640 * MsiSetComponentStateA (MSI.@)
642 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
646 LPWSTR szwComponent = strdupAtoW(szComponent);
648 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
650 msi_free(szwComponent);
655 /***********************************************************************
656 * MsiGetComponentStateA (MSI.@)
658 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
659 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
661 LPWSTR szwComponent= NULL;
664 szwComponent= strdupAtoW(szComponent);
666 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
668 msi_free( szwComponent);
673 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
678 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
680 comp = get_loaded_component(package, szComponent);
682 return ERROR_UNKNOWN_COMPONENT;
684 comp->Installed = iState;
686 return ERROR_SUCCESS;
689 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
690 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
694 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
695 piInstalled, piAction);
697 comp = get_loaded_component(package,szComponent);
699 return ERROR_UNKNOWN_COMPONENT;
702 *piInstalled = comp->Installed;
705 *piAction = comp->Action;
707 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
709 return ERROR_SUCCESS;
712 /***********************************************************************
713 * MsiSetComponentStateW (MSI.@)
715 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
721 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
723 return ERROR_INVALID_HANDLE;
724 ret = MSI_SetComponentStateW(package, szComponent, iState);
725 msiobj_release(&package->hdr);
729 /***********************************************************************
730 * MsiGetComponentStateW (MSI.@)
732 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
733 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
738 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
739 piInstalled, piAction);
741 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
743 return ERROR_INVALID_HANDLE;
744 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
745 msiobj_release( &package->hdr );
749 /***********************************************************************
750 * MsiGetLanguage (MSI.@)
752 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
757 static const WCHAR szProductLanguage[] =
758 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
760 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
762 return ERROR_INVALID_HANDLE;
764 buffer = msi_dup_property( package, szProductLanguage );
765 langid = atoiW(buffer);
768 msiobj_release (&package->hdr);