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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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(" exteral attempt at action %s\n",szAction);
49 return ERROR_FUNCTION_FAILED;
51 return ERROR_FUNCTION_FAILED;
53 szwAction = strdupAtoW(szAction);
56 return ERROR_FUNCTION_FAILED;
59 rc = MsiDoActionW(hInstall, szwAction);
60 HeapFree(GetProcessHeap(),0,szwAction);
64 /***********************************************************************
65 * MsiDoActionW (MSI.@)
67 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
70 UINT ret = ERROR_INVALID_HANDLE;
72 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
74 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
77 ret = ACTION_PerformUIAction(package,szAction);
78 msiobj_release( &package->hdr );
83 /***********************************************************************
84 * MsiGetTargetPathA (MSI.@)
86 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
87 LPSTR szPathBuf, DWORD* pcchPathBuf)
93 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
96 return ERROR_FUNCTION_FAILED;
98 return ERROR_FUNCTION_FAILED;
100 szwFolder = strdupAtoW(szFolder);
103 return ERROR_FUNCTION_FAILED;
105 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
107 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
109 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
110 *pcchPathBuf, NULL, NULL );
112 HeapFree(GetProcessHeap(),0,szwFolder);
113 HeapFree(GetProcessHeap(),0,szwPathBuf);
118 /***********************************************************************
119 * MsiGetTargetPathW (MSI.@)
121 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
122 szPathBuf, DWORD* pcchPathBuf)
125 UINT rc = ERROR_FUNCTION_FAILED;
128 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
130 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
132 return ERROR_INVALID_HANDLE;
133 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
134 msiobj_release( &package->hdr );
136 if (path && (strlenW(path) > *pcchPathBuf))
138 *pcchPathBuf = strlenW(path)+1;
139 rc = ERROR_MORE_DATA;
143 *pcchPathBuf = strlenW(path)+1;
144 strcpyW(szPathBuf,path);
145 TRACE("Returning Path %s\n",debugstr_w(path));
148 HeapFree(GetProcessHeap(),0,path);
153 /***********************************************************************
154 * MsiGetSourcePath (internal)
156 static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
157 awstring *szPathBuf, DWORD* pcchPathBuf )
163 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
166 return ERROR_INVALID_PARAMETER;
168 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
170 return ERROR_INVALID_HANDLE;
172 if (szPathBuf->str.w && !pcchPathBuf )
174 msiobj_release( &package->hdr );
175 return ERROR_INVALID_PARAMETER;
178 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
179 msiobj_release( &package->hdr );
181 TRACE("path = %s\n",debugstr_w(path));
183 return ERROR_DIRECTORY;
188 if (szPathBuf->unicode)
190 len = lstrlenW( path );
191 if (szPathBuf->str.w)
192 lstrcpynW( szPathBuf->str.w, path, *pcchPathBuf );
196 len = WideCharToMultiByte( CP_ACP, 0, path, -1,
197 szPathBuf->str.a, *pcchPathBuf, NULL, NULL );
201 if (len >= *pcchPathBuf)
205 HeapFree( GetProcessHeap(), 0, path );
209 /***********************************************************************
210 * MsiGetSourcePathA (MSI.@)
212 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
213 LPSTR szPathBuf, DWORD* pcchPathBuf )
219 TRACE("%s %p %p\n", szFolder, debugstr_a(szPathBuf), pcchPathBuf);
222 str.str.a = szPathBuf;
224 folder = strdupAtoW( szFolder );
225 r = MSI_GetSourcePath( hInstall, folder, &str, pcchPathBuf );
226 HeapFree( GetProcessHeap(), 0, folder );
231 /***********************************************************************
232 * MsiGetSourcePathW (MSI.@)
234 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder,
235 LPWSTR szPathBuf, DWORD* pcchPathBuf )
239 TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
242 str.str.w = szPathBuf;
244 return MSI_GetSourcePath( hInstall, szFolder, &str, pcchPathBuf );
247 /***********************************************************************
248 * MsiSetTargetPathA (MSI.@)
250 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
254 LPWSTR szwFolderPath;
258 return ERROR_FUNCTION_FAILED;
260 return ERROR_FUNCTION_FAILED;
262 szwFolder = strdupAtoW(szFolder);
264 return ERROR_FUNCTION_FAILED;
266 szwFolderPath = strdupAtoW(szFolderPath);
269 HeapFree(GetProcessHeap(),0,szwFolder);
270 return ERROR_FUNCTION_FAILED;
273 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
275 HeapFree(GetProcessHeap(),0,szwFolder);
276 HeapFree(GetProcessHeap(),0,szwFolderPath);
282 * Ok my original interpretation of this was wrong. And it looks like msdn has
283 * changed a bit also. The given folder path does not have to actually already
284 * exist, it just cannot be read only and must be a legal folder path.
286 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
287 LPCWSTR szFolderPath)
294 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
297 return ERROR_INVALID_HANDLE;
299 if (szFolderPath[0]==0)
300 return ERROR_FUNCTION_FAILED;
302 attrib = GetFileAttributesW(szFolderPath);
303 if ( attrib != INVALID_FILE_ATTRIBUTES &&
304 (!(attrib & FILE_ATTRIBUTE_DIRECTORY) ||
305 attrib & FILE_ATTRIBUTE_OFFLINE ||
306 attrib & FILE_ATTRIBUTE_READONLY))
307 return ERROR_FUNCTION_FAILED;
309 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
312 return ERROR_INVALID_PARAMETER;
314 if (attrib == INVALID_FILE_ATTRIBUTES)
316 if (!CreateDirectoryW(szFolderPath,NULL))
317 return ERROR_FUNCTION_FAILED;
318 RemoveDirectoryW(szFolderPath);
321 HeapFree(GetProcessHeap(),0,folder->Property);
322 folder->Property = build_directory_name(2, szFolderPath, NULL);
324 if (lstrcmpiW(path, folder->Property) == 0)
327 * Resolved Target has not really changed, so just
328 * set this folder and do not recalculate everything.
330 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
331 folder->ResolvedTarget = NULL;
332 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
333 HeapFree(GetProcessHeap(),0,path2);
339 LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
341 HeapFree( GetProcessHeap(),0,f->ResolvedTarget);
342 f->ResolvedTarget=NULL;
345 LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
347 path2 = resolve_folder(package, f->Directory, FALSE, TRUE, NULL);
348 HeapFree(GetProcessHeap(),0,path2);
351 HeapFree(GetProcessHeap(),0,path);
353 return ERROR_SUCCESS;
356 /***********************************************************************
357 * MsiSetTargetPathW (MSI.@)
359 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
360 LPCWSTR szFolderPath)
365 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
367 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
368 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
369 msiobj_release( &package->hdr );
373 /***********************************************************************
376 * Returns an internal installer state (if it is running in a mode iRunMode)
379 * hInstall [I] Handle to the installation
380 * hRunMode [I] Checking run mode
381 * MSIRUNMODE_ADMIN Administrative mode
382 * MSIRUNMODE_ADVERTISE Advertisement mode
383 * MSIRUNMODE_MAINTENANCE Maintenance mode
384 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
385 * MSIRUNMODE_LOGENABLED Log file is writing
386 * MSIRUNMODE_OPERATIONS Operations in progress??
387 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
388 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
389 * MSIRUNMODE_CABINET Files from cabinet are installed
390 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
391 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
392 * MSIRUNMODE_RESERVED11 Reserved
393 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
394 * MSIRUNMODE_ZAWENABLED Demand installation is supported
395 * MSIRUNMODE_RESERVED14 Reserved
396 * MSIRUNMODE_RESERVED15 Reserved
397 * MSIRUNMODE_SCHEDULED called from install script
398 * MSIRUNMODE_ROLLBACK called from rollback script
399 * MSIRUNMODE_COMMIT called from commit script
403 * Not in the state: FALSE
407 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
409 FIXME("STUB (iRunMode=%i)\n",iRunMode);
413 /***********************************************************************
414 * MsiSetFeatureStateA (MSI.@)
416 * According to the docs, when this is called it immediately recalculates
417 * all the component states as well
419 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
422 LPWSTR szwFeature = NULL;
425 szwFeature = strdupAtoW(szFeature);
428 return ERROR_FUNCTION_FAILED;
430 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
432 HeapFree(GetProcessHeap(),0,szwFeature);
439 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
442 UINT rc = ERROR_SUCCESS;
443 MSIFEATURE *feature, *child;
445 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
447 feature = get_loaded_feature(package,szFeature);
449 return ERROR_UNKNOWN_FEATURE;
451 if (iState == INSTALLSTATE_ADVERTISED &&
452 feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
453 return ERROR_FUNCTION_FAILED;
455 feature->ActionRequest = iState;
456 feature->Action = iState;
458 ACTION_UpdateComponentStates(package,szFeature);
460 /* update all the features that are children of this feature */
461 LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
463 if (lstrcmpW(szFeature, child->Feature_Parent) == 0)
464 MSI_SetFeatureStateW(package, child->Feature, iState);
470 /***********************************************************************
471 * MsiSetFeatureStateW (MSI.@)
473 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
477 UINT rc = ERROR_SUCCESS;
479 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
481 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
483 return ERROR_INVALID_HANDLE;
485 rc = MSI_SetFeatureStateW(package,szFeature,iState);
487 msiobj_release( &package->hdr );
491 /***********************************************************************
492 * MsiGetFeatureStateA (MSI.@)
494 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
495 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
497 LPWSTR szwFeature = NULL;
500 szwFeature = strdupAtoW(szFeature);
502 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
504 HeapFree( GetProcessHeap(), 0 , szwFeature);
509 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
510 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
514 feature = get_loaded_feature(package,szFeature);
516 return ERROR_UNKNOWN_FEATURE;
519 *piInstalled = feature->Installed;
522 *piAction = feature->Action;
524 TRACE("returning %i %i\n", feature->Installed, feature->Action);
526 return ERROR_SUCCESS;
529 /***********************************************************************
530 * MsiGetFeatureStateW (MSI.@)
532 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
533 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
538 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
541 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
543 return ERROR_INVALID_HANDLE;
544 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
545 msiobj_release( &package->hdr );
549 /***********************************************************************
550 * MsiSetComponentStateA (MSI.@)
552 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
556 LPWSTR szwComponent = strdupAtoW(szComponent);
558 rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
560 HeapFree(GetProcessHeap(), 0, szwComponent);
565 /***********************************************************************
566 * MsiGetComponentStateA (MSI.@)
568 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
569 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
571 LPWSTR szwComponent= NULL;
574 szwComponent= strdupAtoW(szComponent);
576 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
578 HeapFree( GetProcessHeap(), 0 , szwComponent);
583 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
588 TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
590 comp = get_loaded_component(package, szComponent);
592 return ERROR_UNKNOWN_COMPONENT;
594 comp->Installed = iState;
596 return ERROR_SUCCESS;
599 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
600 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
604 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
605 piInstalled, piAction);
607 comp = get_loaded_component(package,szComponent);
609 return ERROR_UNKNOWN_COMPONENT;
612 *piInstalled = comp->Installed;
615 *piAction = comp->Action;
617 TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
619 return ERROR_SUCCESS;
622 /***********************************************************************
623 * MsiSetComponentStateW (MSI.@)
625 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
631 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
633 return ERROR_INVALID_HANDLE;
634 ret = MSI_SetComponentStateW(package, szComponent, iState);
635 msiobj_release(&package->hdr);
639 /***********************************************************************
640 * MsiGetComponentStateW (MSI.@)
642 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
643 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
648 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
649 piInstalled, piAction);
651 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
653 return ERROR_INVALID_HANDLE;
654 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
655 msiobj_release( &package->hdr );
659 /***********************************************************************
660 * MsiGetLanguage (MSI.@)
662 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
667 static const WCHAR szProductLanguage[] =
668 {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
670 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
672 return ERROR_INVALID_HANDLE;
674 buffer = load_dynamic_property(package,szProductLanguage,NULL);
675 langid = atoiW(buffer);
677 HeapFree(GetProcessHeap(),0,buffer);
678 msiobj_release (&package->hdr);