2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack 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
24 #define NONAMELESSUNION
35 #include "msiserver.h"
48 #include "wine/debug.h"
49 #include "wine/unicode.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(msi);
53 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
55 UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
59 *context = MSIINSTALLCONTEXT_NONE;
60 if (!szProduct) return ERROR_UNKNOWN_PRODUCT;
62 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
63 &hkey, FALSE) == ERROR_SUCCESS)
64 *context = MSIINSTALLCONTEXT_USERMANAGED;
65 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
66 &hkey, FALSE) == ERROR_SUCCESS)
67 *context = MSIINSTALLCONTEXT_MACHINE;
68 else if (MSIREG_OpenProductKey(szProduct, NULL,
69 MSIINSTALLCONTEXT_USERUNMANAGED,
70 &hkey, FALSE) == ERROR_SUCCESS)
71 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
75 if (*context == MSIINSTALLCONTEXT_NONE)
76 return ERROR_UNKNOWN_PRODUCT;
81 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
84 LPWSTR szwProd = NULL;
86 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
90 szwProd = strdupAtoW( szProduct );
92 return ERROR_OUTOFMEMORY;
95 r = MsiOpenProductW( szwProd, phProduct );
102 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
107 MSIINSTALLCONTEXT context;
109 static const WCHAR managed[] = {
110 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
111 static const WCHAR local[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
113 TRACE("%s %p\n", debugstr_w(szProduct), package);
115 r = msi_locate_product(szProduct, &context);
116 if (r != ERROR_SUCCESS)
119 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
120 if (r != ERROR_SUCCESS)
121 return ERROR_UNKNOWN_PRODUCT;
123 if (context == MSIINSTALLCONTEXT_USERMANAGED)
124 path = msi_reg_get_val_str(props, managed);
126 path = msi_reg_get_val_str(props, local);
128 r = ERROR_UNKNOWN_PRODUCT;
130 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
133 if (PathIsRelativeW(path))
135 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
139 r = MSI_OpenPackageW(path, package);
147 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
149 MSIPACKAGE *package = NULL;
150 WCHAR squished_pc[GUID_SIZE];
153 if (!szProduct || !squash_guid(szProduct, squished_pc))
154 return ERROR_INVALID_PARAMETER;
157 return ERROR_INVALID_PARAMETER;
159 r = MSI_OpenProductW(szProduct, &package);
160 if (r != ERROR_SUCCESS)
163 *phProduct = alloc_msihandle(&package->hdr);
165 r = ERROR_NOT_ENOUGH_MEMORY;
167 msiobj_release(&package->hdr);
171 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
172 LPCSTR szTransforms, LANGID lgidLanguage)
174 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
175 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
176 return ERROR_CALL_NOT_IMPLEMENTED;
179 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
180 LPCWSTR szTransforms, LANGID lgidLanguage)
182 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
183 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
184 return ERROR_CALL_NOT_IMPLEMENTED;
187 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
188 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
190 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
191 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
192 lgidLanguage, dwPlatform, dwOptions);
193 return ERROR_CALL_NOT_IMPLEMENTED;
196 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
197 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
199 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
200 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
201 lgidLanguage, dwPlatform, dwOptions);
202 return ERROR_CALL_NOT_IMPLEMENTED;
205 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
207 LPWSTR szwPath = NULL, szwCommand = NULL;
208 UINT r = ERROR_OUTOFMEMORY;
210 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
214 szwPath = strdupAtoW( szPackagePath );
221 szwCommand = strdupAtoW( szCommandLine );
226 r = MsiInstallProductW( szwPath, szwCommand );
230 msi_free( szwCommand );
235 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
237 MSIPACKAGE *package = NULL;
240 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
243 return ERROR_INVALID_PARAMETER;
246 return ERROR_PATH_NOT_FOUND;
248 r = MSI_OpenPackageW( szPackagePath, &package );
249 if (r == ERROR_SUCCESS)
251 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
252 msiobj_release( &package->hdr );
258 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
263 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
265 wszProduct = strdupAtoW(szProduct);
267 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
269 msi_free(wszProduct);
273 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
275 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
277 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
280 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
281 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
283 LPWSTR patch_package = NULL;
284 LPWSTR install_package = NULL;
285 LPWSTR command_line = NULL;
286 UINT r = ERROR_OUTOFMEMORY;
288 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
289 eInstallType, debugstr_a(szCommandLine));
291 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
294 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
297 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
300 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
303 msi_free(patch_package);
304 msi_free(install_package);
305 msi_free(command_line);
310 static UINT get_patch_product_codes( LPCWSTR szPatchPackage, WCHAR ***product_codes )
312 MSIHANDLE patch, info = 0;
315 static WCHAR empty[] = {0};
318 r = MsiOpenDatabaseW( szPatchPackage, MSIDBOPEN_READONLY, &patch );
319 if (r != ERROR_SUCCESS)
322 r = MsiGetSummaryInformationW( patch, NULL, 0, &info );
323 if (r != ERROR_SUCCESS)
327 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, empty, &size );
328 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
330 ERR("Failed to read product codes from patch\n");
331 r = ERROR_FUNCTION_FAILED;
335 codes = msi_alloc( ++size * sizeof(WCHAR) );
338 r = ERROR_OUTOFMEMORY;
342 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, codes, &size );
343 if (r == ERROR_SUCCESS)
344 *product_codes = msi_split_string( codes, ';' );
347 MsiCloseHandle( info );
348 MsiCloseHandle( patch );
353 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
355 UINT i, r = ERROR_FUNCTION_FAILED;
357 LPCWSTR cmd_ptr = szCommandLine;
358 LPWSTR cmd, *codes = NULL;
359 BOOL succeeded = FALSE;
361 static const WCHAR fmt[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
362 static WCHAR empty[] = {0};
364 if (!szPatchPackage || !szPatchPackage[0])
365 return ERROR_INVALID_PARAMETER;
367 if (!szProductCode && (r = get_patch_product_codes( szPatchPackage, &codes )))
373 size = strlenW(cmd_ptr) + strlenW(fmt) + strlenW(szPatchPackage) + 1;
374 cmd = msi_alloc(size * sizeof(WCHAR));
378 return ERROR_OUTOFMEMORY;
380 sprintfW(cmd, fmt, cmd_ptr, szPatchPackage);
383 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
386 for (i = 0; codes[i]; i++)
388 r = MsiConfigureProductExW(codes[i], INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
389 if (r == ERROR_SUCCESS)
391 TRACE("patch applied\n");
405 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
406 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
408 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
409 eInstallType, debugstr_w(szCommandLine));
411 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
412 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
414 FIXME("Only reading target products from patch\n");
415 return ERROR_CALL_NOT_IMPLEMENTED;
418 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
421 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
422 LPCSTR szProductCode, LPCSTR szPropertiesList)
424 LPWSTR patch_packages = NULL;
425 LPWSTR product_code = NULL;
426 LPWSTR properties_list = NULL;
427 UINT r = ERROR_OUTOFMEMORY;
429 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
430 debugstr_a(szPropertiesList));
432 if (!szPatchPackages || !szPatchPackages[0])
433 return ERROR_INVALID_PARAMETER;
435 if (!(patch_packages = strdupAtoW(szPatchPackages)))
436 return ERROR_OUTOFMEMORY;
438 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
441 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
444 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
447 msi_free(patch_packages);
448 msi_free(product_code);
449 msi_free(properties_list);
454 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
455 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
457 UINT r = ERROR_SUCCESS;
460 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
461 debugstr_w(szPropertiesList));
463 if (!szPatchPackages || !szPatchPackages[0])
464 return ERROR_INVALID_PARAMETER;
466 beg = end = szPatchPackages;
472 while (*beg == ' ') beg++;
473 while (*end && *end != ';') end++;
476 while (len && beg[len - 1] == ' ') len--;
478 if (!len) return ERROR_INVALID_NAME;
480 patch = msi_alloc((len + 1) * sizeof(WCHAR));
482 return ERROR_OUTOFMEMORY;
484 memcpy(patch, beg, len * sizeof(WCHAR));
487 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
490 if (r != ERROR_SUCCESS)
498 static void free_patchinfo( DWORD count, MSIPATCHSEQUENCEINFOW *info )
501 for (i = 0; i < count; i++) msi_free( (WCHAR *)info[i].szPatchData );
505 static MSIPATCHSEQUENCEINFOW *patchinfoAtoW( DWORD count, const MSIPATCHSEQUENCEINFOA *info )
508 MSIPATCHSEQUENCEINFOW *ret;
510 if (!(ret = msi_alloc( count * sizeof(MSIPATCHSEQUENCEINFOW) ))) return NULL;
511 for (i = 0; i < count; i++)
513 if (info[i].szPatchData && !(ret[i].szPatchData = strdupAtoW( info[i].szPatchData )))
515 free_patchinfo( i, ret );
518 ret[i].ePatchDataType = info[i].ePatchDataType;
519 ret[i].dwOrder = info[i].dwOrder;
520 ret[i].uStatus = info[i].uStatus;
525 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
526 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
529 WCHAR *package_path = NULL;
530 MSIPATCHSEQUENCEINFOW *psi;
532 TRACE("%s, %u, %p\n", debugstr_a(szProductPackagePath), cPatchInfo, pPatchInfo);
534 if (szProductPackagePath && !(package_path = strdupAtoW( szProductPackagePath )))
535 return ERROR_OUTOFMEMORY;
537 if (!(psi = patchinfoAtoW( cPatchInfo, pPatchInfo )))
539 msi_free( package_path );
540 return ERROR_OUTOFMEMORY;
542 r = MsiDetermineApplicablePatchesW( package_path, cPatchInfo, psi );
543 if (r == ERROR_SUCCESS)
545 for (i = 0; i < cPatchInfo; i++)
547 pPatchInfo[i].dwOrder = psi[i].dwOrder;
548 pPatchInfo[i].uStatus = psi[i].uStatus;
551 msi_free( package_path );
552 free_patchinfo( cPatchInfo, psi );
556 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
559 MSIDATABASE *patch_db;
560 UINT r = ERROR_SUCCESS;
562 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
563 if (r != ERROR_SUCCESS)
565 WARN("failed to open patch file %s\n", debugstr_w(patch));
569 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
572 msiobj_release( &patch_db->hdr );
573 return ERROR_FUNCTION_FAILED;
576 r = msi_check_patch_applicable( package, si );
577 if (r != ERROR_SUCCESS)
578 TRACE("patch not applicable\n");
580 msiobj_release( &patch_db->hdr );
581 msiobj_release( &si->hdr );
585 /* IXMLDOMDocument should be set to XPath mode already */
586 static UINT MSI_ApplicablePatchXML( MSIPACKAGE *package, IXMLDOMDocument *desc )
588 static const WCHAR queryW[] = {'M','s','i','P','a','t','c','h','/',
589 'T','a','r','g','e','t','P','r','o','d','u','c','t','/',
590 'T','a','r','g','e','t','P','r','o','d','u','c','t','C','o','d','e',0};
591 UINT r = ERROR_FUNCTION_FAILED;
592 IXMLDOMNodeList *list;
598 product_code = msi_dup_property( package->db, szProductCode );
601 /* FIXME: the property ProductCode should be written into the DB somewhere */
602 ERR("no product code to check\n");
603 return ERROR_SUCCESS;
606 s = SysAllocString(queryW);
607 hr = IXMLDOMDocument_selectNodes( desc, s, &list );
610 return ERROR_INVALID_PATCH_XML;
612 while (IXMLDOMNodeList_nextNode( list, &node ) == S_OK && r != ERROR_SUCCESS)
614 hr = IXMLDOMNode_get_text( node, &s );
615 IXMLDOMNode_Release( node );
616 if (!strcmpW( s, product_code )) r = ERROR_SUCCESS;
619 IXMLDOMNodeList_Release( list );
621 if (r != ERROR_SUCCESS)
622 TRACE("patch not applicable\n");
624 msi_free( product_code );
628 static UINT determine_patch_sequence( MSIPACKAGE *package, DWORD count, MSIPATCHSEQUENCEINFOW *info )
630 IXMLDOMDocument *desc = NULL;
634 FIXME("patch ordering not supported\n");
636 for (i = 0; i < count; i++)
638 switch (info[i].ePatchDataType)
640 case MSIPATCH_DATATYPE_PATCHFILE:
642 if (MSI_ApplicablePatchW( package, info[i].szPatchData ) != ERROR_SUCCESS)
644 info[i].dwOrder = ~0u;
645 info[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
650 info[i].uStatus = ERROR_SUCCESS;
654 case MSIPATCH_DATATYPE_XMLBLOB:
662 hr = CoCreateInstance( &CLSID_DOMDocument30, NULL, CLSCTX_INPROC_SERVER,
663 &IID_IXMLDOMDocument, (void**)&desc );
666 ERR("failed to create DOMDocument30 instance, 0x%08x\n", hr);
667 return ERROR_FUNCTION_FAILED;
671 s = SysAllocString( info[i].szPatchData );
672 hr = IXMLDOMDocument_loadXML( desc, s, &b );
676 ERR("failed to parse patch description\n");
677 IXMLDOMDocument_Release( desc );
681 if (MSI_ApplicablePatchXML( package, desc ) != ERROR_SUCCESS)
683 info[i].dwOrder = ~0u;
684 info[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
689 info[i].uStatus = ERROR_SUCCESS;
695 FIXME("patch data type %u not supported\n", info[i].ePatchDataType);
697 info[i].uStatus = ERROR_SUCCESS;
702 TRACE("szPatchData: %s\n", debugstr_w(info[i].szPatchData));
703 TRACE("ePatchDataType: %u\n", info[i].ePatchDataType);
704 TRACE("dwOrder: %u\n", info[i].dwOrder);
705 TRACE("uStatus: %u\n", info[i].uStatus);
708 if (desc) IXMLDOMDocument_Release( desc );
710 return ERROR_SUCCESS;
713 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
714 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
719 TRACE("%s, %u, %p\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
721 r = MSI_OpenPackageW( szProductPackagePath, &package );
722 if (r != ERROR_SUCCESS)
724 ERR("failed to open package %u\n", r);
727 r = determine_patch_sequence( package, cPatchInfo, pPatchInfo );
728 msiobj_release( &package->hdr );
732 UINT WINAPI MsiDeterminePatchSequenceA( LPCSTR product, LPCSTR usersid,
733 MSIINSTALLCONTEXT context, DWORD count, PMSIPATCHSEQUENCEINFOA patchinfo )
736 WCHAR *productW, *usersidW = NULL;
737 MSIPATCHSEQUENCEINFOW *patchinfoW;
739 TRACE("%s, %s, %d, %d, %p\n", debugstr_a(product), debugstr_a(usersid),
740 context, count, patchinfo);
742 if (!product) return ERROR_INVALID_PARAMETER;
743 if (!(productW = strdupAtoW( product ))) return ERROR_OUTOFMEMORY;
744 if (usersid && !(usersidW = strdupAtoW( usersid )))
746 msi_free( productW );
747 return ERROR_OUTOFMEMORY;
749 if (!(patchinfoW = patchinfoAtoW( count, patchinfo )))
751 msi_free( productW );
752 msi_free( usersidW );
753 return ERROR_OUTOFMEMORY;
755 r = MsiDeterminePatchSequenceW( productW, usersidW, context, count, patchinfoW );
756 if (r == ERROR_SUCCESS)
758 for (i = 0; i < count; i++)
760 patchinfo[i].dwOrder = patchinfoW[i].dwOrder;
761 patchinfo[i].uStatus = patchinfoW[i].uStatus;
764 msi_free( productW );
765 msi_free( usersidW );
766 free_patchinfo( count, patchinfoW );
770 static UINT open_package( const WCHAR *product, const WCHAR *usersid,
771 MSIINSTALLCONTEXT context, MSIPACKAGE **package )
775 WCHAR *localpath, sourcepath[MAX_PATH], filename[MAX_PATH];
777 r = MSIREG_OpenInstallProps( product, context, usersid, &props, FALSE );
778 if (r != ERROR_SUCCESS) return ERROR_BAD_CONFIGURATION;
780 if ((localpath = msi_reg_get_val_str( props, szLocalPackage )))
782 strcpyW( sourcepath, localpath );
783 msi_free( localpath );
785 RegCloseKey( props );
786 if (!localpath || GetFileAttributesW( sourcepath ) == INVALID_FILE_ATTRIBUTES)
788 DWORD sz = sizeof(sourcepath);
789 MsiSourceListGetInfoW( product, usersid, context, MSICODE_PRODUCT,
790 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz );
791 sz = sizeof(filename);
792 MsiSourceListGetInfoW( product, usersid, context, MSICODE_PRODUCT,
793 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz );
794 strcatW( sourcepath, filename );
796 if (GetFileAttributesW( sourcepath ) == INVALID_FILE_ATTRIBUTES)
797 return ERROR_INSTALL_SOURCE_ABSENT;
799 return MSI_OpenPackageW( sourcepath, package );
802 UINT WINAPI MsiDeterminePatchSequenceW( LPCWSTR product, LPCWSTR usersid,
803 MSIINSTALLCONTEXT context, DWORD count, PMSIPATCHSEQUENCEINFOW patchinfo )
808 TRACE("%s, %s, %d, %d, %p\n", debugstr_w(product), debugstr_w(usersid),
809 context, count, patchinfo);
811 if (!product) return ERROR_INVALID_PARAMETER;
812 r = open_package( product, usersid, context, &package );
813 if (r != ERROR_SUCCESS) return r;
815 r = determine_patch_sequence( package, count, patchinfo );
816 msiobj_release( &package->hdr );
820 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
821 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
823 MSIPACKAGE* package = NULL;
824 MSIINSTALLCONTEXT context;
827 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
830 static const WCHAR szInstalled[] = {
831 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
832 static const WCHAR szMaxInstallLevel[] = {
833 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
834 static const WCHAR szRemoveAll[] = {
835 ' ','R','E','M','O','V','E','=','A','L','L',0};
836 static const WCHAR szMachine[] = {
837 ' ','A','L','L','U','S','E','R','S','=','1',0};
839 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
840 debugstr_w(szCommandLine));
842 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
843 return ERROR_INVALID_PARAMETER;
845 if (eInstallState == INSTALLSTATE_ADVERTISED ||
846 eInstallState == INSTALLSTATE_SOURCE)
848 FIXME("State %d not implemented\n", eInstallState);
849 return ERROR_CALL_NOT_IMPLEMENTED;
852 r = msi_locate_product(szProduct, &context);
853 if (r != ERROR_SUCCESS)
856 r = open_package(szProduct, NULL, context, &package);
857 if (r != ERROR_SUCCESS)
860 sz = lstrlenW(szInstalled) + 1;
863 sz += lstrlenW(szCommandLine);
865 if (eInstallState != INSTALLSTATE_DEFAULT)
866 sz += lstrlenW(szMaxInstallLevel);
868 if (eInstallState == INSTALLSTATE_ABSENT)
869 sz += lstrlenW(szRemoveAll);
871 if (context == MSIINSTALLCONTEXT_MACHINE)
872 sz += lstrlenW(szMachine);
874 commandline = msi_alloc(sz * sizeof(WCHAR));
877 r = ERROR_OUTOFMEMORY;
883 lstrcpyW(commandline,szCommandLine);
885 if (eInstallState != INSTALLSTATE_DEFAULT)
886 lstrcatW(commandline, szMaxInstallLevel);
888 if (eInstallState == INSTALLSTATE_ABSENT)
889 lstrcatW(commandline, szRemoveAll);
891 if (context == MSIINSTALLCONTEXT_MACHINE)
892 lstrcatW(commandline, szMachine);
894 sz = sizeof(sourcepath);
895 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
896 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
898 sz = sizeof(filename);
899 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
900 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
902 strcatW(sourcepath, filename);
904 r = MSI_InstallPackage( package, sourcepath, commandline );
906 msi_free(commandline);
909 msiobj_release( &package->hdr );
914 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
915 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
917 LPWSTR szwProduct = NULL;
918 LPWSTR szwCommandLine = NULL;
919 UINT r = ERROR_OUTOFMEMORY;
923 szwProduct = strdupAtoW( szProduct );
930 szwCommandLine = strdupAtoW( szCommandLine );
935 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
938 msi_free( szwProduct );
939 msi_free( szwCommandLine);
944 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
945 INSTALLSTATE eInstallState)
947 LPWSTR szwProduct = NULL;
950 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
954 szwProduct = strdupAtoW( szProduct );
956 return ERROR_OUTOFMEMORY;
959 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
960 msi_free( szwProduct );
965 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
966 INSTALLSTATE eInstallState)
968 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
971 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
973 LPWSTR szwComponent = NULL;
975 WCHAR szwBuffer[GUID_SIZE];
977 TRACE("%s %p\n", debugstr_a(szComponent), szBuffer);
981 szwComponent = strdupAtoW( szComponent );
983 return ERROR_OUTOFMEMORY;
987 r = MsiGetProductCodeW( szwComponent, szwBuffer );
990 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
992 msi_free( szwComponent );
997 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
1000 HKEY compkey, prodkey;
1001 WCHAR squished_comp[GUID_SIZE];
1002 WCHAR squished_prod[GUID_SIZE];
1003 DWORD sz = GUID_SIZE;
1005 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
1007 if (!szComponent || !*szComponent)
1008 return ERROR_INVALID_PARAMETER;
1010 if (!squash_guid(szComponent, squished_comp))
1011 return ERROR_INVALID_PARAMETER;
1013 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
1014 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
1016 return ERROR_UNKNOWN_COMPONENT;
1019 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
1020 if (rc != ERROR_SUCCESS)
1022 RegCloseKey(compkey);
1023 return ERROR_UNKNOWN_COMPONENT;
1026 /* check simple case, only one product */
1027 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
1028 if (rc == ERROR_NO_MORE_ITEMS)
1035 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
1036 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
1040 unsquash_guid(squished_prod, szBuffer);
1042 if (MSIREG_OpenProductKey(szBuffer, NULL,
1043 MSIINSTALLCONTEXT_USERMANAGED,
1044 &prodkey, FALSE) == ERROR_SUCCESS ||
1045 MSIREG_OpenProductKey(szBuffer, NULL,
1046 MSIINSTALLCONTEXT_USERUNMANAGED,
1047 &prodkey, FALSE) == ERROR_SUCCESS ||
1048 MSIREG_OpenProductKey(szBuffer, NULL,
1049 MSIINSTALLCONTEXT_MACHINE,
1050 &prodkey, FALSE) == ERROR_SUCCESS)
1052 RegCloseKey(prodkey);
1058 rc = ERROR_INSTALL_FAILURE;
1061 RegCloseKey(compkey);
1062 unsquash_guid(squished_prod, szBuffer);
1066 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
1072 static const WCHAR format[] = {'%','d',0};
1074 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
1075 if (res != ERROR_SUCCESS)
1078 if (*type == REG_SZ)
1079 return msi_reg_get_val_str(hkey, name);
1081 if (!msi_reg_get_val_dword(hkey, name, &dval))
1084 sprintfW(temp, format, dval);
1085 return strdupW(temp);
1088 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
1089 awstring *szValue, LPDWORD pcchValueBuf)
1091 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1092 UINT r = ERROR_UNKNOWN_PROPERTY;
1093 HKEY prodkey, userdata, source;
1095 WCHAR squished_pc[GUID_SIZE];
1096 WCHAR packagecode[GUID_SIZE];
1097 BOOL badconfig = FALSE;
1099 DWORD type = REG_NONE;
1101 static WCHAR empty[] = {0};
1102 static const WCHAR sourcelist[] = {
1103 'S','o','u','r','c','e','L','i','s','t',0};
1104 static const WCHAR display_name[] = {
1105 'D','i','s','p','l','a','y','N','a','m','e',0};
1106 static const WCHAR display_version[] = {
1107 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1108 static const WCHAR assignment[] = {
1109 'A','s','s','i','g','n','m','e','n','t',0};
1111 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1112 debugstr_w(szAttribute), szValue, pcchValueBuf);
1114 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
1115 return ERROR_INVALID_PARAMETER;
1117 if (!squash_guid(szProduct, squished_pc))
1118 return ERROR_INVALID_PARAMETER;
1120 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
1121 MSIINSTALLCONTEXT_USERMANAGED,
1122 &prodkey, FALSE)) != ERROR_SUCCESS &&
1123 (r = MSIREG_OpenProductKey(szProduct, NULL,
1124 MSIINSTALLCONTEXT_USERUNMANAGED,
1125 &prodkey, FALSE)) != ERROR_SUCCESS &&
1126 (r = MSIREG_OpenProductKey(szProduct, NULL,
1127 MSIINSTALLCONTEXT_MACHINE,
1128 &prodkey, FALSE)) == ERROR_SUCCESS)
1130 context = MSIINSTALLCONTEXT_MACHINE;
1133 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
1135 if (!strcmpW( szAttribute, INSTALLPROPERTY_HELPLINKW ) ||
1136 !strcmpW( szAttribute, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1137 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLDATEW ) ||
1138 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1139 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1140 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1141 !strcmpW( szAttribute, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1142 !strcmpW( szAttribute, INSTALLPROPERTY_PUBLISHERW ) ||
1143 !strcmpW( szAttribute, INSTALLPROPERTY_URLINFOABOUTW ) ||
1144 !strcmpW( szAttribute, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1145 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMINORW ) ||
1146 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMAJORW ) ||
1147 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1148 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTIDW ) ||
1149 !strcmpW( szAttribute, INSTALLPROPERTY_REGCOMPANYW ) ||
1150 !strcmpW( szAttribute, INSTALLPROPERTY_REGOWNERW ))
1154 r = ERROR_UNKNOWN_PRODUCT;
1159 return ERROR_UNKNOWN_PROPERTY;
1161 if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1162 szAttribute = display_name;
1163 else if (!strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
1164 szAttribute = display_version;
1166 val = msi_reg_get_value(userdata, szAttribute, &type);
1170 else if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTANCETYPEW ) ||
1171 !strcmpW( szAttribute, INSTALLPROPERTY_TRANSFORMSW ) ||
1172 !strcmpW( szAttribute, INSTALLPROPERTY_LANGUAGEW ) ||
1173 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1174 !strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ) ||
1175 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ) ||
1176 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONW ) ||
1177 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTICONW ) ||
1178 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ) ||
1179 !strcmpW( szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1183 r = ERROR_UNKNOWN_PRODUCT;
1187 if (!strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1188 szAttribute = assignment;
1190 if (!strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ))
1192 res = RegOpenKeyW(prodkey, sourcelist, &source);
1193 if (res != ERROR_SUCCESS)
1195 r = ERROR_UNKNOWN_PRODUCT;
1199 val = msi_reg_get_value(source, szAttribute, &type);
1203 RegCloseKey(source);
1207 val = msi_reg_get_value(prodkey, szAttribute, &type);
1212 if (val != empty && type != REG_DWORD &&
1213 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ))
1215 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1219 unsquash_guid(val, packagecode);
1221 val = strdupW(packagecode);
1228 r = ERROR_UNKNOWN_PROPERTY;
1234 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1235 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1236 * can't rely on its value.
1238 if (szValue->str.a || szValue->str.w)
1240 DWORD size = *pcchValueBuf;
1241 if (strlenW(val) < size)
1242 r = msi_strcpy_to_awstring(val, szValue, &size);
1245 r = ERROR_MORE_DATA;
1250 *pcchValueBuf = lstrlenW(val);
1254 r = ERROR_BAD_CONFIGURATION;
1260 RegCloseKey(prodkey);
1261 RegCloseKey(userdata);
1265 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1266 LPSTR szBuffer, LPDWORD pcchValueBuf)
1268 LPWSTR szwProduct, szwAttribute = NULL;
1269 UINT r = ERROR_OUTOFMEMORY;
1272 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1273 szBuffer, pcchValueBuf);
1275 szwProduct = strdupAtoW( szProduct );
1276 if( szProduct && !szwProduct )
1279 szwAttribute = strdupAtoW( szAttribute );
1280 if( szAttribute && !szwAttribute )
1283 buffer.unicode = FALSE;
1284 buffer.str.a = szBuffer;
1286 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1287 &buffer, pcchValueBuf );
1290 msi_free( szwProduct );
1291 msi_free( szwAttribute );
1296 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1297 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1301 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1302 szBuffer, pcchValueBuf);
1304 buffer.unicode = TRUE;
1305 buffer.str.w = szBuffer;
1307 return MSI_GetProductInfo( szProduct, szAttribute,
1308 &buffer, pcchValueBuf );
1311 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1312 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1313 LPSTR szValue, LPDWORD pcchValue)
1315 LPWSTR product = NULL;
1316 LPWSTR usersid = NULL;
1317 LPWSTR property = NULL;
1318 LPWSTR value = NULL;
1322 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1323 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1324 szValue, pcchValue);
1326 if (szValue && !pcchValue)
1327 return ERROR_INVALID_PARAMETER;
1329 if (szProductCode) product = strdupAtoW(szProductCode);
1330 if (szUserSid) usersid = strdupAtoW(szUserSid);
1331 if (szProperty) property = strdupAtoW(szProperty);
1333 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1335 if (r != ERROR_SUCCESS)
1338 value = msi_alloc(++len * sizeof(WCHAR));
1341 r = ERROR_OUTOFMEMORY;
1345 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1347 if (r != ERROR_SUCCESS)
1353 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1354 if (*pcchValue >= len)
1355 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1358 r = ERROR_MORE_DATA;
1363 if (*pcchValue <= len || !szValue)
1364 len = len * sizeof(WCHAR) - 1;
1366 *pcchValue = len - 1;
1377 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1379 UINT r = ERROR_SUCCESS;
1382 return ERROR_UNKNOWN_PROPERTY;
1386 if (strlenW(val) >= *size)
1388 r = ERROR_MORE_DATA;
1397 *size = lstrlenW(val);
1402 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1403 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1404 LPWSTR szValue, LPDWORD pcchValue)
1406 WCHAR squished_pc[GUID_SIZE];
1408 LPCWSTR package = NULL;
1409 HKEY props = NULL, prod;
1410 HKEY classes = NULL, managed;
1413 UINT r = ERROR_UNKNOWN_PRODUCT;
1415 static const WCHAR five[] = {'5',0};
1416 static const WCHAR displayname[] = {
1417 'D','i','s','p','l','a','y','N','a','m','e',0};
1418 static const WCHAR displayversion[] = {
1419 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1420 static const WCHAR managed_local_package[] = {
1421 'M','a','n','a','g','e','d','L','o','c','a','l',
1422 'P','a','c','k','a','g','e',0};
1424 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1425 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1426 szValue, pcchValue);
1428 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1429 return ERROR_INVALID_PARAMETER;
1431 if (szValue && !pcchValue)
1432 return ERROR_INVALID_PARAMETER;
1434 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1435 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1436 dwContext != MSIINSTALLCONTEXT_MACHINE)
1437 return ERROR_INVALID_PARAMETER;
1439 if (!szProperty || !*szProperty)
1440 return ERROR_INVALID_PARAMETER;
1442 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1443 return ERROR_INVALID_PARAMETER;
1445 /* FIXME: dwContext is provided, no need to search for it */
1446 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1448 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1451 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1453 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1455 package = INSTALLPROPERTY_LOCALPACKAGEW;
1457 if (!props && !prod)
1460 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1462 package = managed_local_package;
1464 if (!props && !managed)
1467 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1469 package = INSTALLPROPERTY_LOCALPACKAGEW;
1470 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1472 if (!props && !classes)
1476 if (!strcmpW( szProperty, INSTALLPROPERTY_HELPLINKW ) ||
1477 !strcmpW( szProperty, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1478 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ) ||
1479 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1480 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1481 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1482 !strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1483 !strcmpW( szProperty, INSTALLPROPERTY_PUBLISHERW ) ||
1484 !strcmpW( szProperty, INSTALLPROPERTY_URLINFOABOUTW ) ||
1485 !strcmpW( szProperty, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1486 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMINORW ) ||
1487 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMAJORW ) ||
1488 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1489 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTIDW ) ||
1490 !strcmpW( szProperty, INSTALLPROPERTY_REGCOMPANYW ) ||
1491 !strcmpW( szProperty, INSTALLPROPERTY_REGOWNERW ) ||
1492 !strcmpW( szProperty, INSTALLPROPERTY_INSTANCETYPEW ))
1494 val = msi_reg_get_value(props, package, &type);
1497 if (prod || classes)
1498 r = ERROR_UNKNOWN_PROPERTY;
1505 if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1506 szProperty = displayname;
1507 else if (!strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ))
1508 szProperty = displayversion;
1510 val = msi_reg_get_value(props, szProperty, &type);
1512 val = strdupW(szEmpty);
1514 r = msi_copy_outval(val, szValue, pcchValue);
1516 else if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ) ||
1517 !strcmpW( szProperty, INSTALLPROPERTY_LANGUAGEW ) ||
1518 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1519 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGECODEW ) ||
1520 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONW ) ||
1521 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTICONW ) ||
1522 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ) ||
1523 !strcmpW( szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1525 if (!prod && !classes)
1528 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1530 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1532 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1535 val = msi_reg_get_value(hkey, szProperty, &type);
1537 val = strdupW(szEmpty);
1539 r = msi_copy_outval(val, szValue, pcchValue);
1541 else if (!strcmpW( szProperty, INSTALLPROPERTY_PRODUCTSTATEW ))
1543 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1547 val = msi_reg_get_value(props, package, &type);
1552 val = strdupW(five);
1555 val = strdupW(szOne);
1557 r = msi_copy_outval(val, szValue, pcchValue);
1560 else if (props && (val = msi_reg_get_value(props, package, &type)))
1563 val = strdupW(five);
1564 r = msi_copy_outval(val, szValue, pcchValue);
1568 if (prod || managed)
1569 val = strdupW(szOne);
1573 r = msi_copy_outval(val, szValue, pcchValue);
1575 else if (!strcmpW( szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1577 if (!prod && !classes)
1581 val = strdupW(szEmpty);
1582 r = msi_copy_outval(val, szValue, pcchValue);
1585 r = ERROR_UNKNOWN_PROPERTY;
1590 RegCloseKey(managed);
1591 RegCloseKey(classes);
1597 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1598 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1599 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1601 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1602 LPWSTR property = NULL, val = NULL;
1606 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1607 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1608 debugstr_a(szProperty), lpValue, pcchValue);
1610 if (lpValue && !pcchValue)
1611 return ERROR_INVALID_PARAMETER;
1613 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1614 if (szProductCode) product = strdupAtoW(szProductCode);
1615 if (szUserSid) usersid = strdupAtoW(szUserSid);
1616 if (szProperty) property = strdupAtoW(szProperty);
1619 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1621 if (r != ERROR_SUCCESS)
1624 val = msi_alloc(++len * sizeof(WCHAR));
1627 r = ERROR_OUTOFMEMORY;
1631 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1633 if (r != ERROR_SUCCESS || !pcchValue)
1637 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1638 *pcchValue - 1, NULL, NULL);
1640 len = lstrlenW(val);
1641 if ((*val && *pcchValue < len + 1) || !lpValue)
1645 r = ERROR_MORE_DATA;
1646 lpValue[*pcchValue - 1] = '\0';
1649 *pcchValue = len * sizeof(WCHAR);
1664 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1665 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1666 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1668 WCHAR squished_pc[GUID_SIZE];
1669 WCHAR squished_patch[GUID_SIZE];
1670 HKEY udprod = 0, prod = 0, props = 0;
1671 HKEY patch = 0, patches = 0;
1672 HKEY udpatch = 0, datakey = 0;
1673 HKEY prodpatches = 0;
1675 UINT r = ERROR_UNKNOWN_PRODUCT;
1679 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1680 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1682 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1683 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1684 debugstr_w(szProperty), lpValue, pcchValue);
1686 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1687 return ERROR_INVALID_PARAMETER;
1689 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1690 return ERROR_INVALID_PARAMETER;
1693 return ERROR_INVALID_PARAMETER;
1695 if (lpValue && !pcchValue)
1696 return ERROR_INVALID_PARAMETER;
1698 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1699 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1700 dwContext != MSIINSTALLCONTEXT_MACHINE)
1701 return ERROR_INVALID_PARAMETER;
1703 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1704 return ERROR_INVALID_PARAMETER;
1706 if (szUserSid && !strcmpW( szUserSid, szLocalSid ))
1707 return ERROR_INVALID_PARAMETER;
1709 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1710 &udprod, FALSE) != ERROR_SUCCESS)
1713 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1714 &props, FALSE) != ERROR_SUCCESS)
1717 r = ERROR_UNKNOWN_PATCH;
1719 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_WOW64_64KEY|KEY_READ, &patches);
1720 if (res != ERROR_SUCCESS)
1723 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_WOW64_64KEY|KEY_READ, &patch);
1724 if (res != ERROR_SUCCESS)
1727 if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ))
1729 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1730 &prod, FALSE) != ERROR_SUCCESS)
1733 res = RegOpenKeyExW(prod, szPatches, 0, KEY_WOW64_64KEY|KEY_ALL_ACCESS, &prodpatches);
1734 if (res != ERROR_SUCCESS)
1737 datakey = prodpatches;
1738 szProperty = squished_patch;
1742 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1743 &udpatch, FALSE) != ERROR_SUCCESS)
1746 if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1748 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1749 szProperty = szManagedPackage;
1752 else if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ))
1755 szProperty = szInstalled;
1757 else if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1761 else if (!strcmpW( szProperty, INSTALLPROPERTY_UNINSTALLABLEW ) ||
1762 !strcmpW( szProperty, INSTALLPROPERTY_PATCHSTATEW ) ||
1763 !strcmpW( szProperty, INSTALLPROPERTY_DISPLAYNAMEW ) ||
1764 !strcmpW( szProperty, INSTALLPROPERTY_MOREINFOURLW ))
1770 r = ERROR_UNKNOWN_PROPERTY;
1775 val = msi_reg_get_val_str(datakey, szProperty);
1777 val = strdupW(szEmpty);
1785 lstrcpynW(lpValue, val, *pcchValue);
1787 len = lstrlenW(val);
1788 if ((*val && *pcchValue < len + 1) || !lpValue)
1791 r = ERROR_MORE_DATA;
1793 *pcchValue = len * sizeof(WCHAR);
1800 RegCloseKey(prodpatches);
1803 RegCloseKey(patches);
1804 RegCloseKey(udpatch);
1806 RegCloseKey(udprod);
1811 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1813 UINT r = ERROR_OUTOFMEMORY;
1815 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1817 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1819 if (!patch || !attr)
1820 return ERROR_INVALID_PARAMETER;
1822 if (!(patchW = strdupAtoW( patch )))
1825 if (!(attrW = strdupAtoW( attr )))
1829 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1830 if (r != ERROR_SUCCESS)
1834 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1836 r = ERROR_OUTOFMEMORY;
1840 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1841 if (r == ERROR_SUCCESS)
1843 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1845 r = ERROR_MORE_DATA;
1847 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1855 msi_free( bufferW );
1859 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1862 WCHAR product[GUID_SIZE];
1865 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1867 if (!patch || !attr)
1868 return ERROR_INVALID_PARAMETER;
1870 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1871 return ERROR_UNKNOWN_PROPERTY;
1876 r = MsiEnumProductsW( index, product );
1877 if (r != ERROR_SUCCESS)
1880 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1881 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1884 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1885 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1888 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1889 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1895 return ERROR_UNKNOWN_PRODUCT;
1898 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1900 LPWSTR szwLogFile = NULL;
1903 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1907 szwLogFile = strdupAtoW( szLogFile );
1909 return ERROR_OUTOFMEMORY;
1911 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1912 msi_free( szwLogFile );
1916 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1918 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1920 msi_free(gszLogFile);
1926 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1927 DeleteFileW(szLogFile);
1928 file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
1929 FILE_ATTRIBUTE_NORMAL, NULL);
1930 if (file != INVALID_HANDLE_VALUE)
1932 gszLogFile = strdupW(szLogFile);
1936 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
1939 return ERROR_SUCCESS;
1942 UINT WINAPI MsiEnumComponentCostsA( MSIHANDLE handle, LPCSTR component, DWORD index,
1943 INSTALLSTATE state, LPSTR drive, DWORD *buflen,
1944 int *cost, int *temp )
1948 WCHAR *driveW, *componentW = NULL;
1950 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_a(component), index,
1951 state, drive, buflen, cost, temp);
1953 if (!drive || !buflen) return ERROR_INVALID_PARAMETER;
1954 if (component && !(componentW = strdupAtoW( component ))) return ERROR_OUTOFMEMORY;
1957 if (!(driveW = msi_alloc( len * sizeof(WCHAR) )))
1959 msi_free( componentW );
1960 return ERROR_OUTOFMEMORY;
1962 r = MsiEnumComponentCostsW( handle, componentW, index, state, driveW, buflen, cost, temp );
1965 WideCharToMultiByte( CP_ACP, 0, driveW, -1, drive, len, NULL, NULL );
1967 msi_free( componentW );
1972 static UINT set_drive( WCHAR *buffer, WCHAR letter )
1980 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1981 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1982 int *cost, int *temp )
1984 UINT r = ERROR_NO_MORE_ITEMS;
1985 MSICOMPONENT *comp = NULL;
1986 MSIPACKAGE *package;
1989 WCHAR path[MAX_PATH];
1991 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1992 state, drive, buflen, cost, temp);
1994 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1995 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1998 IWineMsiRemotePackage *remote_package;
2001 if (!(remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle )))
2002 return ERROR_INVALID_HANDLE;
2004 if (component && !(bname = SysAllocString( component )))
2006 IWineMsiRemotePackage_Release( remote_package );
2007 return ERROR_OUTOFMEMORY;
2009 hr = IWineMsiRemotePackage_EnumComponentCosts( remote_package, bname, index, state, drive, buflen, cost, temp );
2010 IWineMsiRemotePackage_Release( remote_package );
2011 SysFreeString( bname );
2014 if (HRESULT_FACILITY(hr) == FACILITY_WIN32) return HRESULT_CODE(hr);
2015 return ERROR_FUNCTION_FAILED;
2017 return ERROR_SUCCESS;
2020 if (!msi_get_property_int( package->db, szCostingComplete, 0 ))
2022 msiobj_release( &package->hdr );
2023 return ERROR_FUNCTION_NOT_CALLED;
2025 if (component && component[0] && !(comp = msi_get_loaded_component( package, component )))
2027 msiobj_release( &package->hdr );
2028 return ERROR_UNKNOWN_COMPONENT;
2033 msiobj_release( &package->hdr );
2034 return ERROR_MORE_DATA;
2038 msiobj_release( &package->hdr );
2039 return ERROR_NO_MORE_ITEMS;
2044 GetWindowsDirectoryW( path, MAX_PATH );
2045 if (component && component[0])
2047 if (comp->assembly && !comp->assembly->application) *temp = comp->Cost;
2048 if (!comp->Enabled || !comp->KeyPath)
2051 *buflen = set_drive( drive, path[0] );
2054 else if ((file = msi_get_loaded_file( package, comp->KeyPath )))
2056 *cost = max( 8, comp->Cost / 512 );
2057 *buflen = set_drive( drive, file->TargetPath[0] );
2061 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
2063 *temp = max( 8, stat.cbSize.QuadPart / 512 );
2064 *buflen = set_drive( drive, path[0] );
2067 msiobj_release( &package->hdr );
2071 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
2072 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2073 LPCSTR szComponent, INSTALLSTATE *pdwState)
2075 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
2078 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
2079 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
2081 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
2082 return ERROR_OUTOFMEMORY;
2084 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
2085 return ERROR_OUTOFMEMORY;
2087 if (szComponent && !(comp = strdupAtoW(szComponent)))
2088 return ERROR_OUTOFMEMORY;
2090 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
2099 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2104 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
2106 return (r == ERROR_SUCCESS);
2109 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2117 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
2118 static const WCHAR managed_local_package[] = {
2119 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
2122 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
2123 if (r != ERROR_SUCCESS)
2126 if (context == MSIINSTALLCONTEXT_USERMANAGED)
2127 package = managed_local_package;
2129 package = local_package;
2132 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
2135 return (res == ERROR_SUCCESS);
2138 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
2139 MSIINSTALLCONTEXT context,
2140 LPCWSTR comp, LPWSTR val, DWORD *sz)
2146 if (context == MSIINSTALLCONTEXT_MACHINE)
2147 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2149 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2151 if (r != ERROR_SUCCESS)
2154 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
2155 if (res != ERROR_SUCCESS)
2162 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
2163 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2164 LPCWSTR szComponent, INSTALLSTATE *pdwState)
2166 WCHAR squished_pc[GUID_SIZE];
2167 WCHAR val[MAX_PATH];
2171 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
2172 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
2174 if (!pdwState || !szComponent)
2175 return ERROR_INVALID_PARAMETER;
2177 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2178 return ERROR_INVALID_PARAMETER;
2180 if (!squash_guid(szProductCode, squished_pc))
2181 return ERROR_INVALID_PARAMETER;
2183 found = msi_comp_find_prod_key(szProductCode, dwContext);
2185 if (!msi_comp_find_package(szProductCode, dwContext))
2189 *pdwState = INSTALLSTATE_UNKNOWN;
2190 return ERROR_UNKNOWN_COMPONENT;
2193 return ERROR_UNKNOWN_PRODUCT;
2196 *pdwState = INSTALLSTATE_UNKNOWN;
2199 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
2200 return ERROR_UNKNOWN_COMPONENT;
2203 *pdwState = INSTALLSTATE_NOTUSED;
2206 if (lstrlenW(val) > 2 &&
2207 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
2209 *pdwState = INSTALLSTATE_SOURCE;
2212 *pdwState = INSTALLSTATE_LOCAL;
2215 TRACE("-> %d\n", *pdwState);
2216 return ERROR_SUCCESS;
2219 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2221 LPWSTR szwProduct = NULL;
2226 szwProduct = strdupAtoW( szProduct );
2228 return ERROR_OUTOFMEMORY;
2230 r = MsiQueryProductStateW( szwProduct );
2231 msi_free( szwProduct );
2235 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2237 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2238 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2239 HKEY prodkey = 0, userdata = 0;
2243 TRACE("%s\n", debugstr_w(szProduct));
2245 if (!szProduct || !*szProduct)
2246 return INSTALLSTATE_INVALIDARG;
2248 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2249 return INSTALLSTATE_INVALIDARG;
2251 if (szProduct[0] != '{' || szProduct[37] != '}')
2252 return INSTALLSTATE_UNKNOWN;
2254 SetLastError( ERROR_SUCCESS );
2256 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2257 &prodkey, FALSE) != ERROR_SUCCESS &&
2258 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2259 &prodkey, FALSE) != ERROR_SUCCESS &&
2260 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2261 &prodkey, FALSE) == ERROR_SUCCESS)
2263 context = MSIINSTALLCONTEXT_MACHINE;
2266 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2267 if (r != ERROR_SUCCESS)
2270 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
2274 state = INSTALLSTATE_DEFAULT;
2276 state = INSTALLSTATE_UNKNOWN;
2281 state = INSTALLSTATE_UNKNOWN;
2284 state = INSTALLSTATE_ABSENT;
2287 RegCloseKey(prodkey);
2288 RegCloseKey(userdata);
2289 TRACE("-> %d\n", state);
2293 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2295 INSTALLUILEVEL old = gUILevel;
2296 HWND oldwnd = gUIhwnd;
2298 TRACE("%08x %p\n", dwUILevel, phWnd);
2300 gUILevel = dwUILevel;
2309 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2310 DWORD dwMessageFilter, LPVOID pvContext)
2312 INSTALLUI_HANDLERA prev = gUIHandlerA;
2314 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2316 gUIHandlerA = puiHandler;
2318 gUIFilter = dwMessageFilter;
2319 gUIContext = pvContext;
2324 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2325 DWORD dwMessageFilter, LPVOID pvContext)
2327 INSTALLUI_HANDLERW prev = gUIHandlerW;
2329 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2332 gUIHandlerW = puiHandler;
2333 gUIFilter = dwMessageFilter;
2334 gUIContext = pvContext;
2339 /******************************************************************
2340 * MsiLoadStringW [MSI.@]
2342 * Loads a string from MSI's string resources.
2346 * handle [I] only -1 is handled currently
2347 * id [I] id of the string to be loaded
2348 * lpBuffer [O] buffer for the string to be written to
2349 * nBufferMax [I] maximum size of the buffer in characters
2350 * lang [I] the preferred language for the string
2354 * If successful, this function returns the language id of the string loaded
2355 * If the function fails, the function returns zero.
2359 * The type of the first parameter is unknown. LoadString's prototype
2360 * suggests that it might be a module handle. I have made it an MSI handle
2361 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2362 * handle. Maybe strings can be stored in an MSI database somehow.
2364 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2365 int nBufferMax, LANGID lang )
2372 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2375 FIXME("don't know how to deal with handle = %08x\n", handle);
2378 lang = GetUserDefaultLangID();
2380 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2384 hResData = LoadResource( msi_hInstance, hres );
2387 p = LockResource( hResData );
2391 for (i = 0; i < (id & 0xf); i++) p += *p + 1;
2394 if( nBufferMax <= len )
2397 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2398 lpBuffer[ len ] = 0;
2400 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2404 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2405 int nBufferMax, LANGID lang )
2411 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2412 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2415 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2416 if( len <= nBufferMax )
2417 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2418 lpBuffer, nBufferMax, NULL, NULL );
2426 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2429 char szProduct[GUID_SIZE];
2431 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2433 if (!szComponent || !pcchBuf)
2434 return INSTALLSTATE_INVALIDARG;
2436 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2437 return INSTALLSTATE_UNKNOWN;
2439 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2442 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2445 WCHAR szProduct[GUID_SIZE];
2447 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2449 if (!szComponent || !pcchBuf)
2450 return INSTALLSTATE_INVALIDARG;
2452 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2453 return INSTALLSTATE_UNKNOWN;
2455 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2458 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2459 WORD wLanguageId, DWORD f)
2461 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2462 uType, wLanguageId, f);
2463 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2466 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2467 WORD wLanguageId, DWORD f)
2469 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2470 uType, wLanguageId, f);
2471 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2474 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2475 DWORD unknown, WORD wLanguageId, DWORD f)
2477 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2478 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2479 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2482 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2483 DWORD unknown, WORD wLanguageId, DWORD f)
2485 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2486 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2487 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2490 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2491 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2492 LPDWORD pcchPathBuf )
2494 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2495 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2497 return ERROR_CALL_NOT_IMPLEMENTED;
2500 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2501 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2502 LPDWORD pcchPathBuf )
2504 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2505 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2507 return ERROR_CALL_NOT_IMPLEMENTED;
2510 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2511 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2513 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2514 return ERROR_CALL_NOT_IMPLEMENTED;
2517 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2518 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2520 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2521 return ERROR_CALL_NOT_IMPLEMENTED;
2524 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2525 LPBYTE hash, LPDWORD hashlen )
2528 WCHAR *pathW = NULL;
2530 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2532 if (path && !(pathW = strdupAtoW( path ))) return ERROR_OUTOFMEMORY;
2533 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2538 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2539 LPBYTE hash, LPDWORD hashlen )
2541 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2544 WINTRUST_FILE_INFO info;
2545 CRYPT_PROVIDER_SGNR *signer;
2546 CRYPT_PROVIDER_CERT *provider;
2548 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2550 if (!path || !cert) return E_INVALIDARG;
2552 info.cbStruct = sizeof(info);
2553 info.pcwszFilePath = path;
2555 info.pgKnownSubject = NULL;
2557 data.cbStruct = sizeof(data);
2558 data.pPolicyCallbackData = NULL;
2559 data.pSIPClientData = NULL;
2560 data.dwUIChoice = WTD_UI_NONE;
2561 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2562 data.dwUnionChoice = WTD_CHOICE_FILE;
2563 data.u.pFile = &info;
2564 data.dwStateAction = WTD_STATEACTION_VERIFY;
2565 data.hWVTStateData = NULL;
2566 data.pwszURLReference = NULL;
2567 data.dwProvFlags = 0;
2568 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2569 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2570 if (FAILED(hr)) goto done;
2572 if (!(signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 )))
2574 hr = TRUST_E_NOSIGNATURE;
2579 DWORD len = signer->psSigner->EncryptedHash.cbData;
2583 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2586 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2589 if (!(provider = WTHelperGetProvCertFromChain( signer, 0 )))
2591 hr = TRUST_E_PROVIDER_UNKNOWN;
2594 *cert = CertDuplicateCertificateContext( provider->pCert );
2597 data.dwStateAction = WTD_STATEACTION_CLOSE;
2598 WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2602 /******************************************************************
2603 * MsiGetProductPropertyA [MSI.@]
2605 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2606 LPSTR szValue, LPDWORD pccbValue)
2608 LPWSTR prop = NULL, val = NULL;
2612 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2613 szValue, pccbValue);
2615 if (szValue && !pccbValue)
2616 return ERROR_INVALID_PARAMETER;
2618 if (szProperty) prop = strdupAtoW(szProperty);
2621 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2622 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2625 if (r == ERROR_SUCCESS)
2627 if (szValue) *szValue = '\0';
2628 if (pccbValue) *pccbValue = 0;
2632 val = msi_alloc(++len * sizeof(WCHAR));
2635 r = ERROR_OUTOFMEMORY;
2639 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2640 if (r != ERROR_SUCCESS)
2643 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2646 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2647 *pccbValue, NULL, NULL);
2651 if (len > *pccbValue)
2652 r = ERROR_MORE_DATA;
2654 *pccbValue = len - 1;
2664 /******************************************************************
2665 * MsiGetProductPropertyW [MSI.@]
2667 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2668 LPWSTR szValue, LPDWORD pccbValue)
2670 MSIPACKAGE *package;
2671 MSIQUERY *view = NULL;
2672 MSIRECORD *rec = NULL;
2676 static const WCHAR query[] = {
2677 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2678 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2679 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2681 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2682 szValue, pccbValue);
2685 return ERROR_INVALID_PARAMETER;
2687 if (szValue && !pccbValue)
2688 return ERROR_INVALID_PARAMETER;
2690 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2692 return ERROR_INVALID_HANDLE;
2694 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2695 if (r != ERROR_SUCCESS)
2698 r = MSI_ViewExecute(view, 0);
2699 if (r != ERROR_SUCCESS)
2702 r = MSI_ViewFetch(view, &rec);
2703 if (r != ERROR_SUCCESS)
2706 val = MSI_RecordGetString(rec, 2);
2710 if (lstrlenW(val) >= *pccbValue)
2712 lstrcpynW(szValue, val, *pccbValue);
2713 *pccbValue = lstrlenW(val);
2714 r = ERROR_MORE_DATA;
2718 lstrcpyW(szValue, val);
2719 *pccbValue = lstrlenW(val);
2726 MSI_ViewClose(view);
2727 msiobj_release(&view->hdr);
2728 if (rec) msiobj_release(&rec->hdr);
2733 if (szValue) *szValue = '\0';
2734 if (pccbValue) *pccbValue = 0;
2738 msiobj_release(&package->hdr);
2742 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2745 LPWSTR szPack = NULL;
2747 TRACE("%s\n", debugstr_a(szPackage) );
2751 szPack = strdupAtoW( szPackage );
2753 return ERROR_OUTOFMEMORY;
2756 r = MsiVerifyPackageW( szPack );
2763 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2768 TRACE("%s\n", debugstr_w(szPackage) );
2770 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2771 MsiCloseHandle( handle );
2776 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2777 awstring* lpPathBuf, LPDWORD pcchBuf)
2779 static const WCHAR wininstaller[] =
2780 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2781 WCHAR squished_pc[GUID_SIZE];
2782 WCHAR squished_comp[GUID_SIZE];
2788 if (!szProduct || !szComponent)
2789 return INSTALLSTATE_INVALIDARG;
2791 if (lpPathBuf->str.w && !pcchBuf)
2792 return INSTALLSTATE_INVALIDARG;
2794 if (!squash_guid(szProduct, squished_pc) ||
2795 !squash_guid(szComponent, squished_comp))
2796 return INSTALLSTATE_INVALIDARG;
2798 state = INSTALLSTATE_UNKNOWN;
2800 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2801 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2803 path = msi_reg_get_val_str(hkey, squished_pc);
2806 state = INSTALLSTATE_ABSENT;
2808 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2809 &hkey, FALSE) == ERROR_SUCCESS ||
2810 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2811 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2812 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2813 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2816 state = INSTALLSTATE_LOCAL;
2820 if (state != INSTALLSTATE_LOCAL &&
2821 (MSIREG_OpenProductKey(szProduct, NULL,
2822 MSIINSTALLCONTEXT_USERUNMANAGED,
2823 &hkey, FALSE) == ERROR_SUCCESS ||
2824 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2825 &hkey, FALSE) == ERROR_SUCCESS))
2829 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2830 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2833 path = msi_reg_get_val_str(hkey, squished_pc);
2836 state = INSTALLSTATE_ABSENT;
2838 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2839 state = INSTALLSTATE_LOCAL;
2844 return INSTALLSTATE_UNKNOWN;
2846 if (state == INSTALLSTATE_LOCAL && !*path)
2847 state = INSTALLSTATE_NOTUSED;
2849 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2854 /******************************************************************
2855 * MsiGetComponentPathW [MSI.@]
2857 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2858 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2862 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szComponent), lpPathBuf, pcchBuf);
2864 path.unicode = TRUE;
2865 path.str.w = lpPathBuf;
2867 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2870 /******************************************************************
2871 * MsiGetComponentPathA [MSI.@]
2873 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2874 LPSTR lpPathBuf, LPDWORD pcchBuf)
2876 LPWSTR szwProduct, szwComponent = NULL;
2877 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2880 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szComponent), lpPathBuf, pcchBuf);
2882 szwProduct = strdupAtoW( szProduct );
2883 if( szProduct && !szwProduct)
2886 szwComponent = strdupAtoW( szComponent );
2887 if( szComponent && !szwComponent )
2890 path.unicode = FALSE;
2891 path.str.a = lpPathBuf;
2893 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2896 msi_free( szwProduct );
2897 msi_free( szwComponent );
2902 /******************************************************************
2903 * MsiQueryFeatureStateA [MSI.@]
2905 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2907 LPWSTR szwProduct = NULL, szwFeature= NULL;
2908 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2910 szwProduct = strdupAtoW( szProduct );
2911 if ( szProduct && !szwProduct )
2914 szwFeature = strdupAtoW( szFeature );
2915 if ( szFeature && !szwFeature )
2918 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2921 msi_free( szwProduct);
2922 msi_free( szwFeature);
2927 /******************************************************************
2928 * MsiQueryFeatureStateW [MSI.@]
2930 * Checks the state of a feature
2933 * szProduct [I] Product's GUID string
2934 * szFeature [I] Feature's GUID string
2937 * INSTALLSTATE_LOCAL Feature is installed and usable
2938 * INSTALLSTATE_ABSENT Feature is absent
2939 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2940 * INSTALLSTATE_UNKNOWN An error occurred
2941 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2944 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2946 WCHAR squishProduct[33], comp[GUID_SIZE];
2948 LPWSTR components, p, parent_feature, path;
2952 BOOL missing = FALSE;
2953 BOOL machine = FALSE;
2954 BOOL source = FALSE;
2956 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2958 if (!szProduct || !szFeature)
2959 return INSTALLSTATE_INVALIDARG;
2961 if (!squash_guid( szProduct, squishProduct ))
2962 return INSTALLSTATE_INVALIDARG;
2964 SetLastError( ERROR_SUCCESS );
2966 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2967 &hkey, FALSE) != ERROR_SUCCESS &&
2968 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2969 &hkey, FALSE) != ERROR_SUCCESS)
2971 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2973 if (rc != ERROR_SUCCESS)
2974 return INSTALLSTATE_UNKNOWN;
2979 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2982 if (!parent_feature)
2983 return INSTALLSTATE_UNKNOWN;
2985 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2986 msi_free(parent_feature);
2987 if (r == INSTALLSTATE_ABSENT)
2991 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2992 MSIINSTALLCONTEXT_MACHINE,
2995 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2996 MSIINSTALLCONTEXT_USERUNMANAGED,
2999 if (rc != ERROR_SUCCESS)
3000 return INSTALLSTATE_ADVERTISED;
3002 components = msi_reg_get_val_str( hkey, szFeature );
3005 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
3008 return INSTALLSTATE_ADVERTISED;
3010 for( p = components; *p && *p != 2 ; p += 20)
3012 if (!decode_base85_guid( p, &guid ))
3014 if (p != components)
3017 msi_free(components);
3018 return INSTALLSTATE_BADCONFIG;
3021 StringFromGUID2(&guid, comp, GUID_SIZE);
3024 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
3026 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
3028 if (rc != ERROR_SUCCESS)
3030 msi_free(components);
3031 return INSTALLSTATE_ADVERTISED;
3034 path = msi_reg_get_val_str(hkey, squishProduct);
3037 else if (lstrlenW(path) > 2 &&
3038 path[0] >= '0' && path[0] <= '9' &&
3039 path[1] >= '0' && path[1] <= '9')
3046 msi_free(components);
3049 r = INSTALLSTATE_ADVERTISED;
3051 r = INSTALLSTATE_SOURCE;
3053 r = INSTALLSTATE_LOCAL;
3055 TRACE("-> %d\n", r);
3059 /******************************************************************
3060 * MsiGetFileVersionA [MSI.@]
3062 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
3063 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
3065 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
3066 UINT ret = ERROR_OUTOFMEMORY;
3068 if ((lpVersionBuf && !pcchVersionBuf) ||
3069 (lpLangBuf && !pcchLangBuf))
3070 return ERROR_INVALID_PARAMETER;
3074 szwFilePath = strdupAtoW( szFilePath );
3079 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
3081 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
3082 if( !lpwVersionBuff )
3086 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
3088 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
3093 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
3094 lpwLangBuff, pcchLangBuf);
3096 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
3097 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
3098 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
3099 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
3100 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
3101 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
3104 msi_free(szwFilePath);
3105 msi_free(lpwVersionBuff);
3106 msi_free(lpwLangBuff);
3111 static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
3112 WCHAR *langbuf, DWORD *langlen )
3114 static const WCHAR szVersionResource[] = {'\\',0};
3115 static const WCHAR szVersionFormat[] = {
3116 '%','d','.','%','d','.','%','d','.','%','d',0};
3117 static const WCHAR szLangResource[] = {
3118 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
3119 'T','r','a','n','s','l','a','t','i','o','n',0};
3120 static const WCHAR szLangFormat[] = {'%','d',0};
3121 UINT ret = ERROR_SUCCESS;
3124 VS_FIXEDFILEINFO *ffi;
3128 if (!(len = GetFileVersionInfoSizeW( path, NULL )))
3130 error = GetLastError();
3131 if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
3134 if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
3135 if (!GetFileVersionInfoW( path, 0, len, version ))
3137 msi_free( version );
3138 return GetLastError();
3142 if (VerQueryValueW( version, szVersionResource, (LPVOID *)&ffi, &len ) && len > 0)
3144 sprintfW( tmp, szVersionFormat,
3145 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
3146 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS) );
3147 if (verbuf) lstrcpynW( verbuf, tmp, *verlen );
3148 len = strlenW( tmp );
3149 if (len >= *verlen) ret = ERROR_MORE_DATA;
3154 if (verbuf) *verbuf = 0;
3160 if (VerQueryValueW( version, szLangResource, (LPVOID *)&lang, &len ) && len > 0)
3162 sprintfW( tmp, szLangFormat, *lang );
3163 if (langbuf) lstrcpynW( langbuf, tmp, *langlen );
3164 len = strlenW( tmp );
3165 if (len >= *langlen) ret = ERROR_MORE_DATA;
3170 if (langbuf) *langbuf = 0;
3174 msi_free( version );
3179 /******************************************************************
3180 * MsiGetFileVersionW [MSI.@]
3182 UINT WINAPI MsiGetFileVersionW( LPCWSTR path, LPWSTR verbuf, LPDWORD verlen,
3183 LPWSTR langbuf, LPDWORD langlen )
3187 TRACE("%s %p %u %p %u\n", debugstr_w(path), verbuf, verlen ? *verlen : 0,
3188 langbuf, langlen ? *langlen : 0);
3190 if ((verbuf && !verlen) || (langbuf && !langlen))
3191 return ERROR_INVALID_PARAMETER;
3193 ret = get_file_version( path, verbuf, verlen, langbuf, langlen );
3194 if (ret == ERROR_RESOURCE_DATA_NOT_FOUND)
3197 WCHAR *version = msi_font_version_from_file( path );
3198 if (!version) return ERROR_FILE_INVALID;
3199 len = strlenW( version );
3202 strcpyW( verbuf, version );
3203 ret = ERROR_SUCCESS;
3205 else ret = ERROR_MORE_DATA;
3207 msi_free( version );
3212 /***********************************************************************
3213 * MsiGetFeatureUsageW [MSI.@]
3215 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
3216 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3218 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
3219 pdwUseCount, pwDateUsed);
3220 return ERROR_CALL_NOT_IMPLEMENTED;
3223 /***********************************************************************
3224 * MsiGetFeatureUsageA [MSI.@]
3226 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
3227 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3229 LPWSTR prod = NULL, feat = NULL;
3230 UINT ret = ERROR_OUTOFMEMORY;
3232 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
3233 pdwUseCount, pwDateUsed);
3235 prod = strdupAtoW( szProduct );
3236 if (szProduct && !prod)
3239 feat = strdupAtoW( szFeature );
3240 if (szFeature && !feat)
3243 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
3252 /***********************************************************************
3253 * MsiUseFeatureExW [MSI.@]
3255 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
3256 DWORD dwInstallMode, DWORD dwReserved )
3260 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3261 dwInstallMode, dwReserved);
3263 state = MsiQueryFeatureStateW( szProduct, szFeature );
3266 return INSTALLSTATE_INVALIDARG;
3268 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
3270 FIXME("mark product %s feature %s as used\n",
3271 debugstr_w(szProduct), debugstr_w(szFeature) );
3277 /***********************************************************************
3278 * MsiUseFeatureExA [MSI.@]
3280 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
3281 DWORD dwInstallMode, DWORD dwReserved )
3283 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
3284 LPWSTR prod = NULL, feat = NULL;
3286 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3287 dwInstallMode, dwReserved);
3289 prod = strdupAtoW( szProduct );
3290 if (szProduct && !prod)
3293 feat = strdupAtoW( szFeature );
3294 if (szFeature && !feat)
3297 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
3306 /***********************************************************************
3307 * MsiUseFeatureW [MSI.@]
3309 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
3311 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
3314 /***********************************************************************
3315 * MsiUseFeatureA [MSI.@]
3317 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
3319 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
3322 /***********************************************************************
3323 * MSI_ProvideQualifiedComponentEx [internal]
3325 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
3326 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3327 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
3328 LPDWORD pcchPathBuf)
3330 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
3331 feature[MAX_FEATURE_CHARS+1];
3337 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
3338 if (rc != ERROR_SUCCESS)
3339 return ERROR_INDEX_ABSENT;
3341 info = msi_reg_get_val_str( hkey, szQualifier );
3345 return ERROR_INDEX_ABSENT;
3347 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
3350 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
3352 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
3356 if (rc != INSTALLSTATE_LOCAL)
3357 return ERROR_FILE_NOT_FOUND;
3359 return ERROR_SUCCESS;
3362 /***********************************************************************
3363 * MsiProvideQualifiedComponentExW [MSI.@]
3365 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3366 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3367 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3368 LPDWORD pcchPathBuf)
3372 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_w(szComponent),
3373 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
3374 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3376 path.unicode = TRUE;
3377 path.str.w = lpPathBuf;
3379 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3380 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3383 /***********************************************************************
3384 * MsiProvideQualifiedComponentExA [MSI.@]
3386 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3387 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3388 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3389 LPDWORD pcchPathBuf)
3391 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3392 UINT r = ERROR_OUTOFMEMORY;
3395 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3396 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3397 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3399 szwComponent = strdupAtoW( szComponent );
3400 if (szComponent && !szwComponent)
3403 szwQualifier = strdupAtoW( szQualifier );
3404 if (szQualifier && !szwQualifier)
3407 szwProduct = strdupAtoW( szProduct );
3408 if (szProduct && !szwProduct)
3411 path.unicode = FALSE;
3412 path.str.a = lpPathBuf;
3414 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3415 dwInstallMode, szwProduct, Unused1,
3416 Unused2, &path, pcchPathBuf);
3418 msi_free(szwProduct);
3419 msi_free(szwComponent);
3420 msi_free(szwQualifier);
3425 /***********************************************************************
3426 * MsiProvideQualifiedComponentW [MSI.@]
3428 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3429 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3430 LPDWORD pcchPathBuf)
3432 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3433 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3436 /***********************************************************************
3437 * MsiProvideQualifiedComponentA [MSI.@]
3439 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3440 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3441 LPDWORD pcchPathBuf)
3443 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3444 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3447 /***********************************************************************
3448 * MSI_GetUserInfo [internal]
3450 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3451 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3452 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3453 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3455 WCHAR squished_pc[SQUISH_GUID_SIZE];
3456 LPWSTR user, org, serial;
3457 USERINFOSTATE state;
3462 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3463 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3466 if (!szProduct || !squash_guid(szProduct, squished_pc))
3467 return USERINFOSTATE_INVALIDARG;
3469 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3470 &hkey, FALSE) != ERROR_SUCCESS &&
3471 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3472 &hkey, FALSE) != ERROR_SUCCESS &&
3473 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3474 &hkey, FALSE) != ERROR_SUCCESS)
3476 return USERINFOSTATE_UNKNOWN;
3479 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3480 NULL, &props, FALSE) != ERROR_SUCCESS &&
3481 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3482 NULL, &props, FALSE) != ERROR_SUCCESS)
3485 return USERINFOSTATE_ABSENT;
3488 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3489 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3490 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3491 state = USERINFOSTATE_ABSENT;
3497 state = USERINFOSTATE_PRESENT;
3499 if (pcchUserNameBuf)
3501 if (lpUserNameBuf && !user)
3503 (*pcchUserNameBuf)--;
3507 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3508 if (r == ERROR_MORE_DATA)
3510 state = USERINFOSTATE_MOREDATA;
3518 if (!orgptr) orgptr = szEmpty;
3520 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3521 if (r == ERROR_MORE_DATA)
3523 state = USERINFOSTATE_MOREDATA;
3536 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3537 if (r == ERROR_MORE_DATA)
3538 state = USERINFOSTATE_MOREDATA;
3549 /***********************************************************************
3550 * MsiGetUserInfoW [MSI.@]
3552 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3553 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3554 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3555 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3557 awstring user, org, serial;
3559 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3560 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3561 (lpSerialBuf && !pcchSerialBuf))
3562 return USERINFOSTATE_INVALIDARG;
3564 user.unicode = TRUE;
3565 user.str.w = lpUserNameBuf;
3567 org.str.w = lpOrgNameBuf;
3568 serial.unicode = TRUE;
3569 serial.str.w = lpSerialBuf;
3571 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3572 &org, pcchOrgNameBuf,
3573 &serial, pcchSerialBuf );
3576 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3577 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3578 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3579 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3581 awstring user, org, serial;
3585 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3586 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3587 (lpSerialBuf && !pcchSerialBuf))
3588 return USERINFOSTATE_INVALIDARG;
3590 prod = strdupAtoW( szProduct );
3591 if (szProduct && !prod)
3592 return ERROR_OUTOFMEMORY;
3594 user.unicode = FALSE;
3595 user.str.a = lpUserNameBuf;
3596 org.unicode = FALSE;
3597 org.str.a = lpOrgNameBuf;
3598 serial.unicode = FALSE;
3599 serial.str.a = lpSerialBuf;
3601 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3602 &org, pcchOrgNameBuf,
3603 &serial, pcchSerialBuf );
3610 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3614 MSIPACKAGE *package;
3615 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3617 TRACE("(%s)\n",debugstr_w(szProduct));
3619 rc = MsiOpenProductW(szProduct,&handle);
3620 if (rc != ERROR_SUCCESS)
3621 return ERROR_INVALID_PARAMETER;
3623 /* MsiCollectUserInfo cannot be called from a custom action. */
3624 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3626 return ERROR_CALL_NOT_IMPLEMENTED;
3628 rc = ACTION_PerformUIAction(package, szFirstRun, SCRIPT_NONE);
3629 msiobj_release( &package->hdr );
3631 MsiCloseHandle(handle);
3636 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3640 MSIPACKAGE *package;
3641 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3643 TRACE("(%s)\n",debugstr_a(szProduct));
3645 rc = MsiOpenProductA(szProduct,&handle);
3646 if (rc != ERROR_SUCCESS)
3647 return ERROR_INVALID_PARAMETER;
3649 /* MsiCollectUserInfo cannot be called from a custom action. */
3650 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3652 return ERROR_CALL_NOT_IMPLEMENTED;
3654 rc = ACTION_PerformUIAction(package, szFirstRun, SCRIPT_NONE);
3655 msiobj_release( &package->hdr );
3657 MsiCloseHandle(handle);
3662 /***********************************************************************
3663 * MsiConfigureFeatureA [MSI.@]
3665 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3667 LPWSTR prod, feat = NULL;
3668 UINT r = ERROR_OUTOFMEMORY;
3670 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3672 prod = strdupAtoW( szProduct );
3673 if (szProduct && !prod)
3676 feat = strdupAtoW( szFeature );
3677 if (szFeature && !feat)
3680 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3689 /***********************************************************************
3690 * MsiConfigureFeatureW [MSI.@]
3692 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3694 MSIPACKAGE *package = NULL;
3696 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3699 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3701 if (!szProduct || !szFeature)
3702 return ERROR_INVALID_PARAMETER;
3704 switch (eInstallState)
3706 case INSTALLSTATE_DEFAULT:
3707 /* FIXME: how do we figure out the default location? */
3708 eInstallState = INSTALLSTATE_LOCAL;
3710 case INSTALLSTATE_LOCAL:
3711 case INSTALLSTATE_SOURCE:
3712 case INSTALLSTATE_ABSENT:
3713 case INSTALLSTATE_ADVERTISED:
3716 return ERROR_INVALID_PARAMETER;
3719 r = MSI_OpenProductW( szProduct, &package );
3720 if (r != ERROR_SUCCESS)
3723 sz = sizeof(sourcepath);
3724 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3725 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3727 sz = sizeof(filename);
3728 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3729 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3731 lstrcatW( sourcepath, filename );
3733 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3735 r = ACTION_PerformUIAction( package, szCostInitialize, SCRIPT_NONE );
3736 if (r != ERROR_SUCCESS)
3739 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3740 if (r != ERROR_SUCCESS)
3743 r = MSI_InstallPackage( package, sourcepath, NULL );
3746 msiobj_release( &package->hdr );
3751 /***********************************************************************
3752 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3754 * Notes: undocumented
3756 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3758 WCHAR path[MAX_PATH];
3760 TRACE("%d\n", dwReserved);
3764 FIXME("dwReserved=%d\n", dwReserved);
3765 return ERROR_INVALID_PARAMETER;
3768 if (!GetWindowsDirectoryW(path, MAX_PATH))
3769 return ERROR_FUNCTION_FAILED;
3771 lstrcatW(path, installerW);
3773 if (!CreateDirectoryW(path, NULL))
3774 return ERROR_FUNCTION_FAILED;
3776 return ERROR_SUCCESS;
3779 /***********************************************************************
3780 * MsiGetShortcutTargetA [MSI.@]
3782 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3783 LPSTR szProductCode, LPSTR szFeatureId,
3784 LPSTR szComponentCode )
3787 const int len = MAX_FEATURE_CHARS+1;
3788 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3791 target = strdupAtoW( szShortcutTarget );
3792 if (szShortcutTarget && !target )
3793 return ERROR_OUTOFMEMORY;
3797 r = MsiGetShortcutTargetW( target, product, feature, component );
3799 if (r == ERROR_SUCCESS)
3801 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3802 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3803 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3808 /***********************************************************************
3809 * MsiGetShortcutTargetW [MSI.@]
3811 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3812 LPWSTR szProductCode, LPWSTR szFeatureId,
3813 LPWSTR szComponentCode )
3815 IShellLinkDataList *dl = NULL;
3816 IPersistFile *pf = NULL;
3817 LPEXP_DARWIN_LINK darwin = NULL;
3820 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3821 szProductCode, szFeatureId, szComponentCode );
3823 init = CoInitialize(NULL);
3825 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3826 &IID_IPersistFile, (LPVOID*) &pf );
3827 if( SUCCEEDED( r ) )
3829 r = IPersistFile_Load( pf, szShortcutTarget,
3830 STGM_READ | STGM_SHARE_DENY_WRITE );
3831 if( SUCCEEDED( r ) )
3833 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3835 if( SUCCEEDED( r ) )
3837 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3839 IShellLinkDataList_Release( dl );
3842 IPersistFile_Release( pf );
3845 if (SUCCEEDED(init))
3848 TRACE("darwin = %p\n", darwin);
3855 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3856 szProductCode, szFeatureId, szComponentCode, &sz );
3857 LocalFree( darwin );
3861 return ERROR_FUNCTION_FAILED;
3864 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature, DWORD dwReinstallMode )
3866 static const WCHAR fmtW[] = {'%','s','=','%','s',' ','%','s','=','%','s',0};
3867 MSIPACKAGE *package;
3868 MSIINSTALLCONTEXT context;
3870 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH], reinstallmode[11];
3871 WCHAR *ptr, *cmdline;
3874 TRACE("%s, %s, 0x%08x\n", debugstr_w(szProduct), debugstr_w(szFeature), dwReinstallMode);
3876 r = msi_locate_product( szProduct, &context );
3877 if (r != ERROR_SUCCESS)
3880 ptr = reinstallmode;
3882 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3884 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3886 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3888 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3890 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3892 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3894 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3896 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3898 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3900 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3904 sz = sizeof(sourcepath);
3905 MsiSourceListGetInfoW( szProduct, NULL, context, MSICODE_PRODUCT,
3906 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz );
3907 sz = sizeof(filename);
3908 MsiSourceListGetInfoW( szProduct, NULL, context, MSICODE_PRODUCT,
3909 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz );
3910 strcatW( sourcepath, filename );
3912 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3913 r = MSI_OpenPackageW( sourcepath, &package );
3915 r = MSI_OpenProductW( szProduct, &package );
3917 if (r != ERROR_SUCCESS)
3920 sz = (strlenW( fmtW ) + strlenW( szReinstallMode ) + strlenW( reinstallmode )) * sizeof(WCHAR);
3921 sz += (strlenW( szReinstall ) + strlenW( szFeature )) * sizeof(WCHAR);
3922 if (!(cmdline = msi_alloc( sz )))
3924 msiobj_release( &package->hdr );
3925 return ERROR_OUTOFMEMORY;
3927 sprintfW( cmdline, fmtW, szReinstallMode, reinstallmode, szReinstall, szFeature );
3929 r = MSI_InstallPackage( package, sourcepath, cmdline );
3930 msiobj_release( &package->hdr );
3931 msi_free( cmdline );
3936 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3937 DWORD dwReinstallMode )
3943 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3946 wszProduct = strdupAtoW(szProduct);
3947 wszFeature = strdupAtoW(szFeature);
3949 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3951 msi_free(wszProduct);
3952 msi_free(wszFeature);
3959 unsigned int buf[4];
3960 unsigned char in[64];
3961 unsigned char digest[16];
3964 extern VOID WINAPI MD5Init( MD5_CTX *);
3965 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3966 extern VOID WINAPI MD5Final( MD5_CTX *);
3968 /***********************************************************************
3969 * MsiGetFileHashW [MSI.@]
3971 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3972 PMSIFILEHASHINFO pHash )
3974 HANDLE handle, mapping;
3977 UINT r = ERROR_FUNCTION_FAILED;
3979 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3982 return ERROR_INVALID_PARAMETER;
3985 return ERROR_PATH_NOT_FOUND;
3988 return ERROR_INVALID_PARAMETER;
3990 return ERROR_INVALID_PARAMETER;
3991 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3992 return ERROR_INVALID_PARAMETER;
3994 handle = CreateFileW( szFilePath, GENERIC_READ,
3995 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3996 if (handle == INVALID_HANDLE_VALUE)
3998 WARN("can't open file %u\n", GetLastError());
3999 return ERROR_FILE_NOT_FOUND;
4001 length = GetFileSize( handle, NULL );
4003 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
4006 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
4012 MD5Update( &ctx, p, length );
4014 UnmapViewOfFile( p );
4016 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
4019 CloseHandle( mapping );
4021 CloseHandle( handle );
4026 /***********************************************************************
4027 * MsiGetFileHashA [MSI.@]
4029 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
4030 PMSIFILEHASHINFO pHash )
4035 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
4037 file = strdupAtoW( szFilePath );
4038 if (szFilePath && !file)
4039 return ERROR_OUTOFMEMORY;
4041 r = MsiGetFileHashW( file, dwOptions, pHash );
4046 /***********************************************************************
4047 * MsiAdvertiseScriptW [MSI.@]
4049 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
4050 PHKEY phRegData, BOOL fRemoveItems )
4052 FIXME("%s %08x %p %d\n",
4053 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
4054 return ERROR_CALL_NOT_IMPLEMENTED;
4057 /***********************************************************************
4058 * MsiAdvertiseScriptA [MSI.@]
4060 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
4061 PHKEY phRegData, BOOL fRemoveItems )
4063 FIXME("%s %08x %p %d\n",
4064 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
4065 return ERROR_CALL_NOT_IMPLEMENTED;
4068 /***********************************************************************
4069 * MsiIsProductElevatedW [MSI.@]
4071 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
4073 FIXME("%s %p - stub\n",
4074 debugstr_w( szProduct ), pfElevated );
4076 return ERROR_SUCCESS;
4079 /***********************************************************************
4080 * MsiIsProductElevatedA [MSI.@]
4082 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
4084 FIXME("%s %p - stub\n",
4085 debugstr_a( szProduct ), pfElevated );
4087 return ERROR_SUCCESS;
4090 /***********************************************************************
4091 * MsiSetExternalUIRecord [MSI.@]
4093 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
4094 DWORD filter, LPVOID context,
4095 PINSTALLUI_HANDLER_RECORD prev )
4097 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
4100 *prev = gUIHandlerRecord;
4102 gUIHandlerRecord = handler;
4104 gUIContext = context;
4106 return ERROR_SUCCESS;
4109 /***********************************************************************
4110 * MsiInstallMissingComponentA [MSI.@]
4112 UINT WINAPI MsiInstallMissingComponentA( LPCSTR product, LPCSTR component, INSTALLSTATE state )
4115 WCHAR *productW = NULL, *componentW = NULL;
4117 TRACE("%s, %s, %d\n", debugstr_a(product), debugstr_a(component), state);
4119 if (product && !(productW = strdupAtoW( product )))
4120 return ERROR_OUTOFMEMORY;
4122 if (component && !(componentW = strdupAtoW( component )))
4124 msi_free( productW );
4125 return ERROR_OUTOFMEMORY;
4128 r = MsiInstallMissingComponentW( productW, componentW, state );
4129 msi_free( productW );
4130 msi_free( componentW );
4134 /***********************************************************************
4135 * MsiInstallMissingComponentW [MSI.@]
4137 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
4139 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
4140 return ERROR_SUCCESS;
4143 /***********************************************************************
4144 * MsiBeginTransactionA [MSI.@]
4146 UINT WINAPI MsiBeginTransactionA( LPCSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4151 FIXME("%s %u %p %p\n", debugstr_a(name), attrs, id, event);
4153 nameW = strdupAtoW( name );
4155 return ERROR_OUTOFMEMORY;
4157 r = MsiBeginTransactionW( nameW, attrs, id, event );
4162 /***********************************************************************
4163 * MsiBeginTransactionW [MSI.@]
4165 UINT WINAPI MsiBeginTransactionW( LPCWSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4167 FIXME("%s %u %p %p\n", debugstr_w(name), attrs, id, event);
4169 *id = (MSIHANDLE)0xdeadbeef;
4170 *event = (HANDLE)0xdeadbeef;
4172 return ERROR_SUCCESS;
4175 /***********************************************************************
4176 * MsiEndTransaction [MSI.@]
4178 UINT WINAPI MsiEndTransaction( DWORD state )
4180 FIXME("%u\n", state);
4181 return ERROR_SUCCESS;