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);
154 /***********************************************************************
155 * MsiGetSourcePathA (MSI.@)
157 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
158 LPSTR szPathBuf, DWORD* pcchPathBuf)
164 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
167 return ERROR_FUNCTION_FAILED;
169 return ERROR_FUNCTION_FAILED;
171 szwFolder = strdupAtoW(szFolder);
173 return ERROR_FUNCTION_FAILED;
175 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
177 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
179 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
180 *pcchPathBuf, NULL, NULL );
182 HeapFree(GetProcessHeap(),0,szwFolder);
183 HeapFree(GetProcessHeap(),0,szwPathBuf);
188 /***********************************************************************
189 * MsiGetSourcePathW (MSI.@)
191 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
192 szPathBuf, DWORD* pcchPathBuf)
195 UINT rc = ERROR_FUNCTION_FAILED;
198 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
200 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
202 return ERROR_INVALID_HANDLE;
203 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
204 msiobj_release( &package->hdr );
206 if (path && strlenW(path) > *pcchPathBuf)
208 *pcchPathBuf = strlenW(path)+1;
209 rc = ERROR_MORE_DATA;
213 *pcchPathBuf = strlenW(path)+1;
214 strcpyW(szPathBuf,path);
215 TRACE("Returning Path %s\n",debugstr_w(path));
218 HeapFree(GetProcessHeap(),0,path);
224 /***********************************************************************
225 * MsiSetTargetPathA (MSI.@)
227 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
231 LPWSTR szwFolderPath;
235 return ERROR_FUNCTION_FAILED;
237 return ERROR_FUNCTION_FAILED;
239 szwFolder = strdupAtoW(szFolder);
241 return ERROR_FUNCTION_FAILED;
243 szwFolderPath = strdupAtoW(szFolderPath);
246 HeapFree(GetProcessHeap(),0,szwFolder);
247 return ERROR_FUNCTION_FAILED;
250 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
252 HeapFree(GetProcessHeap(),0,szwFolder);
253 HeapFree(GetProcessHeap(),0,szwFolderPath);
258 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
259 LPCWSTR szFolderPath)
266 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
269 return ERROR_INVALID_HANDLE;
271 if (szFolderPath[0]==0)
272 return ERROR_FUNCTION_FAILED;
274 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
275 return ERROR_FUNCTION_FAILED;
277 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
280 return ERROR_INVALID_PARAMETER;
282 HeapFree(GetProcessHeap(),0,folder->Property);
283 folder->Property = build_directory_name(2, szFolderPath, NULL);
285 if (lstrcmpiW(path, folder->Property) == 0)
288 * Resolved Target has not really changed, so just
289 * set this folder and do not recalculate everything.
291 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
292 folder->ResolvedTarget = NULL;
293 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
294 HeapFree(GetProcessHeap(),0,path2);
298 for (i = 0; i < package->loaded_folders; i++)
300 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
301 package->folders[i].ResolvedTarget=NULL;
304 for (i = 0; i < package->loaded_folders; i++)
306 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
308 HeapFree(GetProcessHeap(),0,path2);
311 HeapFree(GetProcessHeap(),0,path);
313 return ERROR_SUCCESS;
316 /***********************************************************************
317 * MsiSetTargetPathW (MSI.@)
319 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
320 LPCWSTR szFolderPath)
325 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
327 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
328 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
329 msiobj_release( &package->hdr );
333 /***********************************************************************
336 * Returns an internal installer state (if it is running in a mode iRunMode)
339 * hInstall [I] Handle to the installation
340 * hRunMode [I] Checking run mode
341 * MSIRUNMODE_ADMIN Administrative mode
342 * MSIRUNMODE_ADVERTISE Advertisement mode
343 * MSIRUNMODE_MAINTENANCE Maintenance mode
344 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
345 * MSIRUNMODE_LOGENABLED Log file is writing
346 * MSIRUNMODE_OPERATIONS Operations in progress??
347 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
348 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
349 * MSIRUNMODE_CABINET Files from cabinet are installed
350 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
351 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
352 * MSIRUNMODE_RESERVED11 Reserved
353 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
354 * MSIRUNMODE_ZAWENABLED Demand installation is supported
355 * MSIRUNMODE_RESERVED14 Reserved
356 * MSIRUNMODE_RESERVED15 Reserved
357 * MSIRUNMODE_SCHEDULED called from install script
358 * MSIRUNMODE_ROLLBACK called from rollback script
359 * MSIRUNMODE_COMMIT called from commit script
363 * Not in the state: FALSE
367 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
369 FIXME("STUB (iRunMode=%i)\n",iRunMode);
373 /***********************************************************************
374 * MsiSetFeatureStateA (MSI.@)
376 * According to the docs, when this is called it immediately recalculates
377 * all the component states as well
379 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
382 LPWSTR szwFeature = NULL;
385 szwFeature = strdupAtoW(szFeature);
388 return ERROR_FUNCTION_FAILED;
390 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
392 HeapFree(GetProcessHeap(),0,szwFeature);
399 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
403 UINT rc = ERROR_SUCCESS;
405 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
407 index = get_loaded_feature(package,szFeature);
409 return ERROR_UNKNOWN_FEATURE;
411 if (iState == INSTALLSTATE_ADVERTISED &&
412 package->features[index].Attributes &
413 msidbFeatureAttributesDisallowAdvertise)
414 return ERROR_FUNCTION_FAILED;
416 package->features[index].ActionRequest= iState;
417 package->features[index].Action= iState;
419 ACTION_UpdateComponentStates(package,szFeature);
421 /* update all the features that are children of this feature */
422 for (i = 0; i < package->loaded_features; i++)
424 if (strcmpW(szFeature, package->features[i].Feature_Parent) == 0)
425 MSI_SetFeatureStateW(package, package->features[i].Feature, iState);
431 /***********************************************************************
432 * MsiSetFeatureStateW (MSI.@)
434 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
438 UINT rc = ERROR_SUCCESS;
440 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
442 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
444 return ERROR_INVALID_HANDLE;
446 rc = MSI_SetFeatureStateW(package,szFeature,iState);
448 msiobj_release( &package->hdr );
452 /***********************************************************************
453 * MsiGetFeatureStateA (MSI.@)
455 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
456 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
458 LPWSTR szwFeature = NULL;
461 szwFeature = strdupAtoW(szFeature);
463 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
465 HeapFree( GetProcessHeap(), 0 , szwFeature);
470 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
471 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
475 index = get_loaded_feature(package,szFeature);
477 return ERROR_UNKNOWN_FEATURE;
480 *piInstalled = package->features[index].Installed;
483 *piAction = package->features[index].Action;
485 TRACE("returning %i %i\n",*piInstalled,*piAction);
487 return ERROR_SUCCESS;
490 /***********************************************************************
491 * MsiGetFeatureStateW (MSI.@)
493 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
494 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
499 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
502 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
504 return ERROR_INVALID_HANDLE;
505 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
506 msiobj_release( &package->hdr );
510 /***********************************************************************
511 * MsiGetComponentStateA (MSI.@)
513 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
514 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
516 LPWSTR szwComponent= NULL;
519 szwComponent= strdupAtoW(szComponent);
521 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
523 HeapFree( GetProcessHeap(), 0 , szwComponent);
528 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
529 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
533 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
536 index = get_loaded_component(package,szComponent);
538 return ERROR_UNKNOWN_COMPONENT;
541 *piInstalled = package->components[index].Installed;
544 *piAction = package->components[index].Action;
546 TRACE("states (%i, %i)\n",
547 (piInstalled)?*piInstalled:-1,(piAction)?*piAction:-1);
549 return ERROR_SUCCESS;
552 /***********************************************************************
553 * MsiGetComponentStateW (MSI.@)
555 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
556 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
561 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
562 piInstalled, piAction);
564 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
566 return ERROR_INVALID_HANDLE;
567 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
568 msiobj_release( &package->hdr );