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"
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
52 static UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
56 *context = MSIINSTALLCONTEXT_NONE;
58 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
59 &hkey, FALSE) == ERROR_SUCCESS)
60 *context = MSIINSTALLCONTEXT_USERMANAGED;
61 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
62 &hkey, FALSE) == ERROR_SUCCESS)
63 *context = MSIINSTALLCONTEXT_MACHINE;
64 else if (MSIREG_OpenProductKey(szProduct, NULL,
65 MSIINSTALLCONTEXT_USERUNMANAGED,
66 &hkey, FALSE) == ERROR_SUCCESS)
67 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
71 if (*context == MSIINSTALLCONTEXT_NONE)
72 return ERROR_UNKNOWN_PRODUCT;
77 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
80 LPWSTR szwProd = NULL;
82 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
86 szwProd = strdupAtoW( szProduct );
88 return ERROR_OUTOFMEMORY;
91 r = MsiOpenProductW( szwProd, phProduct );
98 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
103 MSIINSTALLCONTEXT context;
105 static const WCHAR managed[] = {
106 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
107 static const WCHAR local[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
109 TRACE("%s %p\n", debugstr_w(szProduct), package);
111 r = msi_locate_product(szProduct, &context);
112 if (r != ERROR_SUCCESS)
115 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
116 if (r != ERROR_SUCCESS)
117 return ERROR_UNKNOWN_PRODUCT;
119 if (context == MSIINSTALLCONTEXT_USERMANAGED)
120 path = msi_reg_get_val_str(props, managed);
122 path = msi_reg_get_val_str(props, local);
124 r = ERROR_UNKNOWN_PRODUCT;
126 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
129 if (PathIsRelativeW(path))
131 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
135 r = MSI_OpenPackageW(path, package);
143 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
145 MSIPACKAGE *package = NULL;
146 WCHAR squished_pc[GUID_SIZE];
149 if (!szProduct || !squash_guid(szProduct, squished_pc))
150 return ERROR_INVALID_PARAMETER;
153 return ERROR_INVALID_PARAMETER;
155 r = MSI_OpenProductW(szProduct, &package);
156 if (r != ERROR_SUCCESS)
159 *phProduct = alloc_msihandle(&package->hdr);
161 r = ERROR_NOT_ENOUGH_MEMORY;
163 msiobj_release(&package->hdr);
167 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
168 LPCSTR szTransforms, LANGID lgidLanguage)
170 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
171 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
172 return ERROR_CALL_NOT_IMPLEMENTED;
175 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
176 LPCWSTR szTransforms, LANGID lgidLanguage)
178 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
179 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
180 return ERROR_CALL_NOT_IMPLEMENTED;
183 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
184 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
186 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
187 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
188 lgidLanguage, dwPlatform, dwOptions);
189 return ERROR_CALL_NOT_IMPLEMENTED;
192 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
193 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
195 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
196 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
197 lgidLanguage, dwPlatform, dwOptions);
198 return ERROR_CALL_NOT_IMPLEMENTED;
201 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
203 LPWSTR szwPath = NULL, szwCommand = NULL;
204 UINT r = ERROR_OUTOFMEMORY;
206 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
210 szwPath = strdupAtoW( szPackagePath );
217 szwCommand = strdupAtoW( szCommandLine );
222 r = MsiInstallProductW( szwPath, szwCommand );
226 msi_free( szwCommand );
231 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
233 MSIPACKAGE *package = NULL;
236 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
239 return ERROR_INVALID_PARAMETER;
242 return ERROR_PATH_NOT_FOUND;
244 r = MSI_OpenPackageW( szPackagePath, &package );
245 if (r == ERROR_SUCCESS)
247 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
248 msiobj_release( &package->hdr );
254 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
259 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
261 wszProduct = strdupAtoW(szProduct);
263 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
265 msi_free(wszProduct);
269 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
271 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
273 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
276 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
277 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
279 LPWSTR patch_package = NULL;
280 LPWSTR install_package = NULL;
281 LPWSTR command_line = NULL;
282 UINT r = ERROR_OUTOFMEMORY;
284 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
285 eInstallType, debugstr_a(szCommandLine));
287 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
290 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
293 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
296 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
299 msi_free(patch_package);
300 msi_free(install_package);
301 msi_free(command_line);
307 static UINT get_patch_product_codes( LPCWSTR szPatchPackage, WCHAR ***product_codes )
309 MSIHANDLE patch, info = 0;
312 static WCHAR empty[] = {0};
315 r = MsiOpenDatabaseW( szPatchPackage, MSIDBOPEN_READONLY, &patch );
316 if (r != ERROR_SUCCESS)
319 r = MsiGetSummaryInformationW( patch, NULL, 0, &info );
320 if (r != ERROR_SUCCESS)
324 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, empty, &size );
325 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
327 ERR("Failed to read product codes from patch\n");
328 r = ERROR_FUNCTION_FAILED;
332 codes = msi_alloc( ++size * sizeof(WCHAR) );
335 r = ERROR_OUTOFMEMORY;
339 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, codes, &size );
340 if (r == ERROR_SUCCESS)
341 *product_codes = msi_split_string( codes, ';' );
344 MsiCloseHandle( info );
345 MsiCloseHandle( patch );
350 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
354 LPCWSTR cmd_ptr = szCommandLine;
355 LPWSTR cmd, *codes = NULL;
356 BOOL succeeded = FALSE;
358 static const WCHAR fmt[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
359 static WCHAR empty[] = {0};
361 if (!szPatchPackage || !szPatchPackage[0])
362 return ERROR_INVALID_PARAMETER;
364 if (!szProductCode && (r = get_patch_product_codes( szPatchPackage, &codes )))
370 size = strlenW(cmd_ptr) + strlenW(fmt) + strlenW(szPatchPackage) + 1;
371 cmd = msi_alloc(size * sizeof(WCHAR));
375 return ERROR_OUTOFMEMORY;
377 sprintfW(cmd, fmt, cmd_ptr, szPatchPackage);
380 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
383 for (i = 0; codes[i]; i++)
385 r = MsiConfigureProductExW(codes[i], INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
386 if (r == ERROR_SUCCESS)
388 TRACE("patch applied\n");
402 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
403 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
405 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
406 eInstallType, debugstr_w(szCommandLine));
408 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
409 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
411 FIXME("Only reading target products from patch\n");
412 return ERROR_CALL_NOT_IMPLEMENTED;
415 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
418 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
419 LPCSTR szProductCode, LPCSTR szPropertiesList)
421 LPWSTR patch_packages = NULL;
422 LPWSTR product_code = NULL;
423 LPWSTR properties_list = NULL;
424 UINT r = ERROR_OUTOFMEMORY;
426 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
427 debugstr_a(szPropertiesList));
429 if (!szPatchPackages || !szPatchPackages[0])
430 return ERROR_INVALID_PARAMETER;
432 if (!(patch_packages = strdupAtoW(szPatchPackages)))
433 return ERROR_OUTOFMEMORY;
435 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
438 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
441 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
444 msi_free(patch_packages);
445 msi_free(product_code);
446 msi_free(properties_list);
451 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
452 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
454 UINT r = ERROR_SUCCESS;
457 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
458 debugstr_w(szPropertiesList));
460 if (!szPatchPackages || !szPatchPackages[0])
461 return ERROR_INVALID_PARAMETER;
463 beg = end = szPatchPackages;
469 while (*beg == ' ') beg++;
470 while (*end && *end != ';') end++;
473 while (len && beg[len - 1] == ' ') len--;
475 if (!len) return ERROR_INVALID_NAME;
477 patch = msi_alloc((len + 1) * sizeof(WCHAR));
479 return ERROR_OUTOFMEMORY;
481 memcpy(patch, beg, len * sizeof(WCHAR));
484 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
487 if (r != ERROR_SUCCESS)
495 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
496 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
499 WCHAR *package_path = NULL;
500 MSIPATCHSEQUENCEINFOW *psi;
502 TRACE("(%s, %d, %p)\n", debugstr_a(szProductPackagePath), cPatchInfo, pPatchInfo);
504 if (szProductPackagePath && !(package_path = strdupAtoW( szProductPackagePath )))
505 return ERROR_OUTOFMEMORY;
507 psi = msi_alloc( cPatchInfo * sizeof(*psi) );
510 msi_free( package_path );
511 return ERROR_OUTOFMEMORY;
514 for (i = 0; i < cPatchInfo; i++)
516 psi[i].szPatchData = strdupAtoW( pPatchInfo[i].szPatchData );
517 psi[i].ePatchDataType = pPatchInfo[i].ePatchDataType;
520 r = MsiDetermineApplicablePatchesW( package_path, cPatchInfo, psi );
521 if (r == ERROR_SUCCESS)
523 for (i = 0; i < cPatchInfo; i++)
525 pPatchInfo[i].dwOrder = psi[i].dwOrder;
526 pPatchInfo[i].uStatus = psi[i].uStatus;
530 msi_free( package_path );
531 for (i = 0; i < cPatchInfo; i++)
532 msi_free( (WCHAR *)psi[i].szPatchData );
537 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
540 MSIDATABASE *patch_db;
541 UINT r = ERROR_SUCCESS;
543 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
544 if (r != ERROR_SUCCESS)
546 WARN("failed to open patch file %s\n", debugstr_w(patch));
550 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
553 msiobj_release( &patch_db->hdr );
554 return ERROR_FUNCTION_FAILED;
557 r = msi_check_patch_applicable( package, si );
558 if (r != ERROR_SUCCESS)
559 TRACE("patch not applicable\n");
561 msiobj_release( &patch_db->hdr );
562 msiobj_release( &si->hdr );
566 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
567 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
569 UINT i, r, ret = ERROR_FUNCTION_FAILED;
572 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
574 r = MSI_OpenPackageW( szProductPackagePath, &package );
575 if (r != ERROR_SUCCESS)
577 ERR("failed to open package %u\n", r);
581 for (i = 0; i < cPatchInfo; i++)
583 switch (pPatchInfo[i].ePatchDataType)
585 case MSIPATCH_DATATYPE_PATCHFILE:
587 FIXME("patch ordering not supported\n");
588 r = MSI_ApplicablePatchW( package, pPatchInfo[i].szPatchData );
589 if (r != ERROR_SUCCESS)
591 pPatchInfo[i].dwOrder = ~0u;
592 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
596 pPatchInfo[i].dwOrder = i;
597 pPatchInfo[i].uStatus = ret = ERROR_SUCCESS;
603 FIXME("patch data type %u not supported\n", pPatchInfo[i].ePatchDataType);
604 pPatchInfo[i].dwOrder = ~0u;
605 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
610 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo[i].szPatchData));
611 TRACE("ePatchDataType: %u\n", pPatchInfo[i].ePatchDataType);
612 TRACE(" dwOrder: %u\n", pPatchInfo[i].dwOrder);
613 TRACE(" uStatus: %u\n", pPatchInfo[i].uStatus);
618 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
619 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
621 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
622 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
624 return ERROR_CALL_NOT_IMPLEMENTED;
627 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
628 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
630 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
631 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
633 return ERROR_CALL_NOT_IMPLEMENTED;
636 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
637 MSIPACKAGE **package)
643 WCHAR sourcepath[MAX_PATH];
644 WCHAR filename[MAX_PATH];
646 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
647 if (r != ERROR_SUCCESS)
648 return ERROR_BAD_CONFIGURATION;
650 localpack = msi_reg_get_val_str(props, szLocalPackage);
653 lstrcpyW(sourcepath, localpack);
657 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
659 sz = sizeof(sourcepath);
660 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
661 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
663 sz = sizeof(filename);
664 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
665 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
667 lstrcatW(sourcepath, filename);
670 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
671 return ERROR_INSTALL_SOURCE_ABSENT;
673 return MSI_OpenPackageW(sourcepath, package);
676 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
677 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
679 MSIPACKAGE* package = NULL;
680 MSIINSTALLCONTEXT context;
683 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
686 static const WCHAR szInstalled[] = {
687 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
688 static const WCHAR szMaxInstallLevel[] = {
689 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
690 static const WCHAR szRemoveAll[] = {
691 ' ','R','E','M','O','V','E','=','A','L','L',0};
692 static const WCHAR szMachine[] = {
693 ' ','A','L','L','U','S','E','R','S','=','1',0};
695 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
696 debugstr_w(szCommandLine));
698 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
699 return ERROR_INVALID_PARAMETER;
701 if (eInstallState == INSTALLSTATE_ADVERTISED ||
702 eInstallState == INSTALLSTATE_SOURCE)
704 FIXME("State %d not implemented\n", eInstallState);
705 return ERROR_CALL_NOT_IMPLEMENTED;
708 r = msi_locate_product(szProduct, &context);
709 if (r != ERROR_SUCCESS)
712 r = msi_open_package(szProduct, context, &package);
713 if (r != ERROR_SUCCESS)
716 sz = lstrlenW(szInstalled) + 1;
719 sz += lstrlenW(szCommandLine);
721 if (eInstallState != INSTALLSTATE_DEFAULT)
722 sz += lstrlenW(szMaxInstallLevel);
724 if (eInstallState == INSTALLSTATE_ABSENT)
725 sz += lstrlenW(szRemoveAll);
727 if (context == MSIINSTALLCONTEXT_MACHINE)
728 sz += lstrlenW(szMachine);
730 commandline = msi_alloc(sz * sizeof(WCHAR));
733 r = ERROR_OUTOFMEMORY;
739 lstrcpyW(commandline,szCommandLine);
741 if (eInstallState != INSTALLSTATE_DEFAULT)
742 lstrcatW(commandline, szMaxInstallLevel);
744 if (eInstallState == INSTALLSTATE_ABSENT)
745 lstrcatW(commandline, szRemoveAll);
747 if (context == MSIINSTALLCONTEXT_MACHINE)
748 lstrcatW(commandline, szMachine);
750 sz = sizeof(sourcepath);
751 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
752 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
754 sz = sizeof(filename);
755 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
756 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
758 strcatW(sourcepath, filename);
760 r = MSI_InstallPackage( package, sourcepath, commandline );
762 msi_free(commandline);
765 msiobj_release( &package->hdr );
770 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
771 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
773 LPWSTR szwProduct = NULL;
774 LPWSTR szwCommandLine = NULL;
775 UINT r = ERROR_OUTOFMEMORY;
779 szwProduct = strdupAtoW( szProduct );
786 szwCommandLine = strdupAtoW( szCommandLine );
791 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
794 msi_free( szwProduct );
795 msi_free( szwCommandLine);
800 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
801 INSTALLSTATE eInstallState)
803 LPWSTR szwProduct = NULL;
806 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
810 szwProduct = strdupAtoW( szProduct );
812 return ERROR_OUTOFMEMORY;
815 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
816 msi_free( szwProduct );
821 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
822 INSTALLSTATE eInstallState)
824 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
827 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
829 LPWSTR szwComponent = NULL;
831 WCHAR szwBuffer[GUID_SIZE];
833 TRACE("%s %p\n", debugstr_a(szComponent), szBuffer);
837 szwComponent = strdupAtoW( szComponent );
839 return ERROR_OUTOFMEMORY;
843 r = MsiGetProductCodeW( szwComponent, szwBuffer );
846 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
848 msi_free( szwComponent );
853 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
856 HKEY compkey, prodkey;
857 WCHAR squished_comp[GUID_SIZE];
858 WCHAR squished_prod[GUID_SIZE];
859 DWORD sz = GUID_SIZE;
861 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
863 if (!szComponent || !*szComponent)
864 return ERROR_INVALID_PARAMETER;
866 if (!squash_guid(szComponent, squished_comp))
867 return ERROR_INVALID_PARAMETER;
869 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
870 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
872 return ERROR_UNKNOWN_COMPONENT;
875 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
876 if (rc != ERROR_SUCCESS)
878 RegCloseKey(compkey);
879 return ERROR_UNKNOWN_COMPONENT;
882 /* check simple case, only one product */
883 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
884 if (rc == ERROR_NO_MORE_ITEMS)
891 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
892 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
896 unsquash_guid(squished_prod, szBuffer);
898 if (MSIREG_OpenProductKey(szBuffer, NULL,
899 MSIINSTALLCONTEXT_USERMANAGED,
900 &prodkey, FALSE) == ERROR_SUCCESS ||
901 MSIREG_OpenProductKey(szBuffer, NULL,
902 MSIINSTALLCONTEXT_USERUNMANAGED,
903 &prodkey, FALSE) == ERROR_SUCCESS ||
904 MSIREG_OpenProductKey(szBuffer, NULL,
905 MSIINSTALLCONTEXT_MACHINE,
906 &prodkey, FALSE) == ERROR_SUCCESS)
908 RegCloseKey(prodkey);
914 rc = ERROR_INSTALL_FAILURE;
917 RegCloseKey(compkey);
918 unsquash_guid(squished_prod, szBuffer);
922 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
928 static const WCHAR format[] = {'%','d',0};
930 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
931 if (res != ERROR_SUCCESS)
935 return msi_reg_get_val_str(hkey, name);
937 if (!msi_reg_get_val_dword(hkey, name, &dval))
940 sprintfW(temp, format, dval);
941 return strdupW(temp);
944 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
945 awstring *szValue, LPDWORD pcchValueBuf)
947 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
948 UINT r = ERROR_UNKNOWN_PROPERTY;
949 HKEY prodkey, userdata, source;
951 WCHAR squished_pc[GUID_SIZE];
952 WCHAR packagecode[GUID_SIZE];
953 BOOL badconfig = FALSE;
955 DWORD type = REG_NONE;
957 static WCHAR empty[] = {0};
958 static const WCHAR sourcelist[] = {
959 'S','o','u','r','c','e','L','i','s','t',0};
960 static const WCHAR display_name[] = {
961 'D','i','s','p','l','a','y','N','a','m','e',0};
962 static const WCHAR display_version[] = {
963 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
964 static const WCHAR assignment[] = {
965 'A','s','s','i','g','n','m','e','n','t',0};
967 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
968 debugstr_w(szAttribute), szValue, pcchValueBuf);
970 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
971 return ERROR_INVALID_PARAMETER;
973 if (!squash_guid(szProduct, squished_pc))
974 return ERROR_INVALID_PARAMETER;
976 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
977 MSIINSTALLCONTEXT_USERMANAGED,
978 &prodkey, FALSE)) != ERROR_SUCCESS &&
979 (r = MSIREG_OpenProductKey(szProduct, NULL,
980 MSIINSTALLCONTEXT_USERUNMANAGED,
981 &prodkey, FALSE)) != ERROR_SUCCESS &&
982 (r = MSIREG_OpenProductKey(szProduct, NULL,
983 MSIINSTALLCONTEXT_MACHINE,
984 &prodkey, FALSE)) == ERROR_SUCCESS)
986 context = MSIINSTALLCONTEXT_MACHINE;
989 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
991 if (!strcmpW( szAttribute, INSTALLPROPERTY_HELPLINKW ) ||
992 !strcmpW( szAttribute, INSTALLPROPERTY_HELPTELEPHONEW ) ||
993 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLDATEW ) ||
994 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
995 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
996 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLSOURCEW ) ||
997 !strcmpW( szAttribute, INSTALLPROPERTY_LOCALPACKAGEW ) ||
998 !strcmpW( szAttribute, INSTALLPROPERTY_PUBLISHERW ) ||
999 !strcmpW( szAttribute, INSTALLPROPERTY_URLINFOABOUTW ) ||
1000 !strcmpW( szAttribute, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1001 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMINORW ) ||
1002 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMAJORW ) ||
1003 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1004 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTIDW ) ||
1005 !strcmpW( szAttribute, INSTALLPROPERTY_REGCOMPANYW ) ||
1006 !strcmpW( szAttribute, INSTALLPROPERTY_REGOWNERW ))
1010 r = ERROR_UNKNOWN_PRODUCT;
1015 return ERROR_UNKNOWN_PROPERTY;
1017 if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1018 szAttribute = display_name;
1019 else if (!strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
1020 szAttribute = display_version;
1022 val = msi_reg_get_value(userdata, szAttribute, &type);
1026 else if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTANCETYPEW ) ||
1027 !strcmpW( szAttribute, INSTALLPROPERTY_TRANSFORMSW ) ||
1028 !strcmpW( szAttribute, INSTALLPROPERTY_LANGUAGEW ) ||
1029 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1030 !strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ) ||
1031 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ) ||
1032 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONW ) ||
1033 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTICONW ) ||
1034 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ) ||
1035 !strcmpW( szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1039 r = ERROR_UNKNOWN_PRODUCT;
1043 if (!strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1044 szAttribute = assignment;
1046 if (!strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ))
1048 res = RegOpenKeyW(prodkey, sourcelist, &source);
1049 if (res != ERROR_SUCCESS)
1051 r = ERROR_UNKNOWN_PRODUCT;
1055 val = msi_reg_get_value(source, szAttribute, &type);
1059 RegCloseKey(source);
1063 val = msi_reg_get_value(prodkey, szAttribute, &type);
1068 if (val != empty && type != REG_DWORD &&
1069 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ))
1071 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1075 unsquash_guid(val, packagecode);
1077 val = strdupW(packagecode);
1084 r = ERROR_UNKNOWN_PROPERTY;
1090 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1091 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1092 * can't rely on its value.
1094 if (szValue->str.a || szValue->str.w)
1096 DWORD size = *pcchValueBuf;
1097 if (strlenW(val) < size)
1098 r = msi_strcpy_to_awstring(val, szValue, &size);
1101 r = ERROR_MORE_DATA;
1106 *pcchValueBuf = lstrlenW(val);
1110 r = ERROR_BAD_CONFIGURATION;
1116 RegCloseKey(prodkey);
1117 RegCloseKey(userdata);
1121 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1122 LPSTR szBuffer, LPDWORD pcchValueBuf)
1124 LPWSTR szwProduct, szwAttribute = NULL;
1125 UINT r = ERROR_OUTOFMEMORY;
1128 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1129 szBuffer, pcchValueBuf);
1131 szwProduct = strdupAtoW( szProduct );
1132 if( szProduct && !szwProduct )
1135 szwAttribute = strdupAtoW( szAttribute );
1136 if( szAttribute && !szwAttribute )
1139 buffer.unicode = FALSE;
1140 buffer.str.a = szBuffer;
1142 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1143 &buffer, pcchValueBuf );
1146 msi_free( szwProduct );
1147 msi_free( szwAttribute );
1152 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1153 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1157 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1158 szBuffer, pcchValueBuf);
1160 buffer.unicode = TRUE;
1161 buffer.str.w = szBuffer;
1163 return MSI_GetProductInfo( szProduct, szAttribute,
1164 &buffer, pcchValueBuf );
1167 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1168 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1169 LPSTR szValue, LPDWORD pcchValue)
1171 LPWSTR product = NULL;
1172 LPWSTR usersid = NULL;
1173 LPWSTR property = NULL;
1174 LPWSTR value = NULL;
1178 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1179 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1180 szValue, pcchValue);
1182 if (szValue && !pcchValue)
1183 return ERROR_INVALID_PARAMETER;
1185 if (szProductCode) product = strdupAtoW(szProductCode);
1186 if (szUserSid) usersid = strdupAtoW(szUserSid);
1187 if (szProperty) property = strdupAtoW(szProperty);
1189 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1191 if (r != ERROR_SUCCESS)
1194 value = msi_alloc(++len * sizeof(WCHAR));
1197 r = ERROR_OUTOFMEMORY;
1201 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1203 if (r != ERROR_SUCCESS)
1209 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1210 if (*pcchValue >= len)
1211 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1214 r = ERROR_MORE_DATA;
1219 if (*pcchValue <= len || !szValue)
1220 len = len * sizeof(WCHAR) - 1;
1222 *pcchValue = len - 1;
1233 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1235 UINT r = ERROR_SUCCESS;
1238 return ERROR_UNKNOWN_PROPERTY;
1242 if (strlenW(val) >= *size)
1244 r = ERROR_MORE_DATA;
1253 *size = lstrlenW(val);
1258 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1259 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1260 LPWSTR szValue, LPDWORD pcchValue)
1262 WCHAR squished_pc[GUID_SIZE];
1264 LPCWSTR package = NULL;
1265 HKEY props = NULL, prod;
1266 HKEY classes = NULL, managed;
1269 UINT r = ERROR_UNKNOWN_PRODUCT;
1271 static const WCHAR five[] = {'5',0};
1272 static const WCHAR displayname[] = {
1273 'D','i','s','p','l','a','y','N','a','m','e',0};
1274 static const WCHAR displayversion[] = {
1275 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1276 static const WCHAR managed_local_package[] = {
1277 'M','a','n','a','g','e','d','L','o','c','a','l',
1278 'P','a','c','k','a','g','e',0};
1280 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1281 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1282 szValue, pcchValue);
1284 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1285 return ERROR_INVALID_PARAMETER;
1287 if (szValue && !pcchValue)
1288 return ERROR_INVALID_PARAMETER;
1290 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1291 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1292 dwContext != MSIINSTALLCONTEXT_MACHINE)
1293 return ERROR_INVALID_PARAMETER;
1295 if (!szProperty || !*szProperty)
1296 return ERROR_INVALID_PARAMETER;
1298 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1299 return ERROR_INVALID_PARAMETER;
1301 /* FIXME: dwContext is provided, no need to search for it */
1302 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1304 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1307 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1309 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1311 package = INSTALLPROPERTY_LOCALPACKAGEW;
1313 if (!props && !prod)
1316 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1318 package = managed_local_package;
1320 if (!props && !managed)
1323 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1325 package = INSTALLPROPERTY_LOCALPACKAGEW;
1326 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1328 if (!props && !classes)
1332 if (!strcmpW( szProperty, INSTALLPROPERTY_HELPLINKW ) ||
1333 !strcmpW( szProperty, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1334 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ) ||
1335 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1336 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1337 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1338 !strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1339 !strcmpW( szProperty, INSTALLPROPERTY_PUBLISHERW ) ||
1340 !strcmpW( szProperty, INSTALLPROPERTY_URLINFOABOUTW ) ||
1341 !strcmpW( szProperty, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1342 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMINORW ) ||
1343 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMAJORW ) ||
1344 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1345 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTIDW ) ||
1346 !strcmpW( szProperty, INSTALLPROPERTY_REGCOMPANYW ) ||
1347 !strcmpW( szProperty, INSTALLPROPERTY_REGOWNERW ) ||
1348 !strcmpW( szProperty, INSTALLPROPERTY_INSTANCETYPEW ))
1350 val = msi_reg_get_value(props, package, &type);
1353 if (prod || classes)
1354 r = ERROR_UNKNOWN_PROPERTY;
1361 if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1362 szProperty = displayname;
1363 else if (!strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ))
1364 szProperty = displayversion;
1366 val = msi_reg_get_value(props, szProperty, &type);
1368 val = strdupW(szEmpty);
1370 r = msi_copy_outval(val, szValue, pcchValue);
1372 else if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ) ||
1373 !strcmpW( szProperty, INSTALLPROPERTY_LANGUAGEW ) ||
1374 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1375 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGECODEW ) ||
1376 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONW ) ||
1377 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTICONW ) ||
1378 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ) ||
1379 !strcmpW( szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1381 if (!prod && !classes)
1384 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1386 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1388 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1391 val = msi_reg_get_value(hkey, szProperty, &type);
1393 val = strdupW(szEmpty);
1395 r = msi_copy_outval(val, szValue, pcchValue);
1397 else if (!strcmpW( szProperty, INSTALLPROPERTY_PRODUCTSTATEW ))
1399 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1403 val = msi_reg_get_value(props, package, &type);
1408 val = strdupW(five);
1411 val = strdupW(szOne);
1413 r = msi_copy_outval(val, szValue, pcchValue);
1416 else if (props && (val = msi_reg_get_value(props, package, &type)))
1419 val = strdupW(five);
1420 r = msi_copy_outval(val, szValue, pcchValue);
1424 if (prod || managed)
1425 val = strdupW(szOne);
1429 r = msi_copy_outval(val, szValue, pcchValue);
1431 else if (!strcmpW( szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1433 if (!prod && !classes)
1437 val = strdupW(szEmpty);
1438 r = msi_copy_outval(val, szValue, pcchValue);
1441 r = ERROR_UNKNOWN_PROPERTY;
1446 RegCloseKey(managed);
1447 RegCloseKey(classes);
1453 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1454 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1455 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1457 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1458 LPWSTR property = NULL, val = NULL;
1462 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1463 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1464 debugstr_a(szProperty), lpValue, pcchValue);
1466 if (lpValue && !pcchValue)
1467 return ERROR_INVALID_PARAMETER;
1469 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1470 if (szProductCode) product = strdupAtoW(szProductCode);
1471 if (szUserSid) usersid = strdupAtoW(szUserSid);
1472 if (szProperty) property = strdupAtoW(szProperty);
1475 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1477 if (r != ERROR_SUCCESS)
1480 val = msi_alloc(++len * sizeof(WCHAR));
1483 r = ERROR_OUTOFMEMORY;
1487 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1489 if (r != ERROR_SUCCESS || !pcchValue)
1493 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1494 *pcchValue - 1, NULL, NULL);
1496 len = lstrlenW(val);
1497 if ((*val && *pcchValue < len + 1) || !lpValue)
1501 r = ERROR_MORE_DATA;
1502 lpValue[*pcchValue - 1] = '\0';
1505 *pcchValue = len * sizeof(WCHAR);
1520 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1521 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1522 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1524 WCHAR squished_pc[GUID_SIZE];
1525 WCHAR squished_patch[GUID_SIZE];
1526 HKEY udprod = 0, prod = 0, props = 0;
1527 HKEY patch = 0, patches = 0;
1528 HKEY udpatch = 0, datakey = 0;
1529 HKEY prodpatches = 0;
1531 UINT r = ERROR_UNKNOWN_PRODUCT;
1535 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1536 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1538 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1539 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1540 debugstr_w(szProperty), lpValue, pcchValue);
1542 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1543 return ERROR_INVALID_PARAMETER;
1545 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1546 return ERROR_INVALID_PARAMETER;
1549 return ERROR_INVALID_PARAMETER;
1551 if (lpValue && !pcchValue)
1552 return ERROR_INVALID_PARAMETER;
1554 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1555 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1556 dwContext != MSIINSTALLCONTEXT_MACHINE)
1557 return ERROR_INVALID_PARAMETER;
1559 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1560 return ERROR_INVALID_PARAMETER;
1562 if (szUserSid && !strcmpW( szUserSid, szLocalSid ))
1563 return ERROR_INVALID_PARAMETER;
1565 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1566 &udprod, FALSE) != ERROR_SUCCESS)
1569 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1570 &props, FALSE) != ERROR_SUCCESS)
1573 r = ERROR_UNKNOWN_PATCH;
1575 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_WOW64_64KEY|KEY_READ, &patches);
1576 if (res != ERROR_SUCCESS)
1579 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_WOW64_64KEY|KEY_READ, &patch);
1580 if (res != ERROR_SUCCESS)
1583 if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ))
1585 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1586 &prod, FALSE) != ERROR_SUCCESS)
1589 res = RegOpenKeyExW(prod, szPatches, 0, KEY_WOW64_64KEY|KEY_ALL_ACCESS, &prodpatches);
1590 if (res != ERROR_SUCCESS)
1593 datakey = prodpatches;
1594 szProperty = squished_patch;
1598 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1599 &udpatch, FALSE) != ERROR_SUCCESS)
1602 if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1604 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1605 szProperty = szManagedPackage;
1608 else if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ))
1611 szProperty = szInstalled;
1613 else if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1617 else if (!strcmpW( szProperty, INSTALLPROPERTY_UNINSTALLABLEW ) ||
1618 !strcmpW( szProperty, INSTALLPROPERTY_PATCHSTATEW ) ||
1619 !strcmpW( szProperty, INSTALLPROPERTY_DISPLAYNAMEW ) ||
1620 !strcmpW( szProperty, INSTALLPROPERTY_MOREINFOURLW ))
1626 r = ERROR_UNKNOWN_PROPERTY;
1631 val = msi_reg_get_val_str(datakey, szProperty);
1633 val = strdupW(szEmpty);
1641 lstrcpynW(lpValue, val, *pcchValue);
1643 len = lstrlenW(val);
1644 if ((*val && *pcchValue < len + 1) || !lpValue)
1647 r = ERROR_MORE_DATA;
1649 *pcchValue = len * sizeof(WCHAR);
1656 RegCloseKey(prodpatches);
1659 RegCloseKey(patches);
1660 RegCloseKey(udpatch);
1662 RegCloseKey(udprod);
1667 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1669 UINT r = ERROR_OUTOFMEMORY;
1671 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1673 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1675 if (!patch || !attr)
1676 return ERROR_INVALID_PARAMETER;
1678 if (!(patchW = strdupAtoW( patch )))
1681 if (!(attrW = strdupAtoW( attr )))
1685 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1686 if (r != ERROR_SUCCESS)
1690 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1692 r = ERROR_OUTOFMEMORY;
1696 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1697 if (r == ERROR_SUCCESS)
1699 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1701 r = ERROR_MORE_DATA;
1703 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1711 msi_free( bufferW );
1715 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1718 WCHAR product[GUID_SIZE];
1721 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1723 if (!patch || !attr)
1724 return ERROR_INVALID_PARAMETER;
1726 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1727 return ERROR_UNKNOWN_PROPERTY;
1732 r = MsiEnumProductsW( index, product );
1733 if (r != ERROR_SUCCESS)
1736 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1737 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1740 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1741 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1744 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1745 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1751 return ERROR_UNKNOWN_PRODUCT;
1754 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1756 LPWSTR szwLogFile = NULL;
1759 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1763 szwLogFile = strdupAtoW( szLogFile );
1765 return ERROR_OUTOFMEMORY;
1767 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1768 msi_free( szwLogFile );
1772 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1774 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1776 msi_free(gszLogFile);
1782 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1783 DeleteFileW(szLogFile);
1784 file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
1785 FILE_ATTRIBUTE_NORMAL, NULL);
1786 if (file != INVALID_HANDLE_VALUE)
1788 gszLogFile = strdupW(szLogFile);
1792 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
1795 return ERROR_SUCCESS;
1798 UINT WINAPI MsiEnumComponentCostsA( MSIHANDLE handle, LPCSTR component, DWORD index,
1799 INSTALLSTATE state, LPSTR drive, DWORD *buflen,
1800 int *cost, int *temp )
1804 WCHAR *driveW, *componentW = NULL;
1806 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_a(component), index,
1807 state, drive, buflen, cost, temp);
1809 if (!drive || !buflen) return ERROR_INVALID_PARAMETER;
1810 if (component && !(componentW = strdupAtoW( component ))) return ERROR_OUTOFMEMORY;
1813 if (!(driveW = msi_alloc( len * sizeof(WCHAR) )))
1815 msi_free( componentW );
1816 return ERROR_OUTOFMEMORY;
1818 r = MsiEnumComponentCostsW( handle, componentW, index, state, driveW, buflen, cost, temp );
1821 WideCharToMultiByte( CP_ACP, 0, driveW, -1, drive, len, NULL, NULL );
1823 msi_free( componentW );
1828 static UINT set_drive( WCHAR *buffer, WCHAR letter )
1836 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1837 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1838 int *cost, int *temp )
1840 UINT r = ERROR_NO_MORE_ITEMS;
1841 MSICOMPONENT *comp = NULL;
1842 MSIPACKAGE *package;
1845 WCHAR path[MAX_PATH];
1847 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1848 state, drive, buflen, cost, temp);
1850 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1851 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1854 IWineMsiRemotePackage *remote_package;
1857 if (!(remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle )))
1858 return ERROR_INVALID_HANDLE;
1860 if (component && !(bname = SysAllocString( component )))
1862 IWineMsiRemotePackage_Release( remote_package );
1863 return ERROR_OUTOFMEMORY;
1865 hr = IWineMsiRemotePackage_EnumComponentCosts( remote_package, bname, index, state, drive, buflen, cost, temp );
1866 IWineMsiRemotePackage_Release( remote_package );
1867 SysFreeString( bname );
1870 if (HRESULT_FACILITY(hr) == FACILITY_WIN32) return HRESULT_CODE(hr);
1871 return ERROR_FUNCTION_FAILED;
1873 return ERROR_SUCCESS;
1876 if (!msi_get_property_int( package->db, szCostingComplete, 0 ))
1878 msiobj_release( &package->hdr );
1879 return ERROR_FUNCTION_NOT_CALLED;
1881 if (component && component[0] && !(comp = msi_get_loaded_component( package, component )))
1883 msiobj_release( &package->hdr );
1884 return ERROR_UNKNOWN_COMPONENT;
1889 msiobj_release( &package->hdr );
1890 return ERROR_MORE_DATA;
1894 msiobj_release( &package->hdr );
1895 return ERROR_NO_MORE_ITEMS;
1900 GetWindowsDirectoryW( path, MAX_PATH );
1901 if (component && component[0])
1903 if (comp->assembly && !comp->assembly->application) *temp = comp->Cost;
1904 if (!comp->Enabled || !comp->KeyPath)
1907 *buflen = set_drive( drive, path[0] );
1910 else if ((file = msi_get_loaded_file( package, comp->KeyPath )))
1912 *cost = max( 8, comp->Cost / 512 );
1913 *buflen = set_drive( drive, file->TargetPath[0] );
1917 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
1919 *temp = max( 8, stat.cbSize.QuadPart / 512 );
1920 *buflen = set_drive( drive, path[0] );
1923 msiobj_release( &package->hdr );
1927 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1928 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1929 LPCSTR szComponent, INSTALLSTATE *pdwState)
1931 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1934 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1935 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1937 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1938 return ERROR_OUTOFMEMORY;
1940 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1941 return ERROR_OUTOFMEMORY;
1943 if (szComponent && !(comp = strdupAtoW(szComponent)))
1944 return ERROR_OUTOFMEMORY;
1946 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1955 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1960 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1962 return (r == ERROR_SUCCESS);
1965 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1973 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1974 static const WCHAR managed_local_package[] = {
1975 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1978 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1979 if (r != ERROR_SUCCESS)
1982 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1983 package = managed_local_package;
1985 package = local_package;
1988 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1991 return (res == ERROR_SUCCESS);
1994 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1995 MSIINSTALLCONTEXT context,
1996 LPCWSTR comp, LPWSTR val, DWORD *sz)
2002 if (context == MSIINSTALLCONTEXT_MACHINE)
2003 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2005 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2007 if (r != ERROR_SUCCESS)
2010 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
2011 if (res != ERROR_SUCCESS)
2018 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
2019 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2020 LPCWSTR szComponent, INSTALLSTATE *pdwState)
2022 WCHAR squished_pc[GUID_SIZE];
2023 WCHAR val[MAX_PATH];
2027 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
2028 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
2030 if (!pdwState || !szComponent)
2031 return ERROR_INVALID_PARAMETER;
2033 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2034 return ERROR_INVALID_PARAMETER;
2036 if (!squash_guid(szProductCode, squished_pc))
2037 return ERROR_INVALID_PARAMETER;
2039 found = msi_comp_find_prod_key(szProductCode, dwContext);
2041 if (!msi_comp_find_package(szProductCode, dwContext))
2045 *pdwState = INSTALLSTATE_UNKNOWN;
2046 return ERROR_UNKNOWN_COMPONENT;
2049 return ERROR_UNKNOWN_PRODUCT;
2052 *pdwState = INSTALLSTATE_UNKNOWN;
2055 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
2056 return ERROR_UNKNOWN_COMPONENT;
2059 *pdwState = INSTALLSTATE_NOTUSED;
2062 if (lstrlenW(val) > 2 &&
2063 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
2065 *pdwState = INSTALLSTATE_SOURCE;
2068 *pdwState = INSTALLSTATE_LOCAL;
2071 TRACE("-> %d\n", *pdwState);
2072 return ERROR_SUCCESS;
2075 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2077 LPWSTR szwProduct = NULL;
2082 szwProduct = strdupAtoW( szProduct );
2084 return ERROR_OUTOFMEMORY;
2086 r = MsiQueryProductStateW( szwProduct );
2087 msi_free( szwProduct );
2091 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2093 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2094 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2095 HKEY prodkey = 0, userdata = 0;
2099 TRACE("%s\n", debugstr_w(szProduct));
2101 if (!szProduct || !*szProduct)
2102 return INSTALLSTATE_INVALIDARG;
2104 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2105 return INSTALLSTATE_INVALIDARG;
2107 if (szProduct[0] != '{' || szProduct[37] != '}')
2108 return INSTALLSTATE_UNKNOWN;
2110 SetLastError( ERROR_SUCCESS );
2112 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2113 &prodkey, FALSE) != ERROR_SUCCESS &&
2114 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2115 &prodkey, FALSE) != ERROR_SUCCESS &&
2116 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2117 &prodkey, FALSE) == ERROR_SUCCESS)
2119 context = MSIINSTALLCONTEXT_MACHINE;
2122 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2123 if (r != ERROR_SUCCESS)
2126 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
2130 state = INSTALLSTATE_DEFAULT;
2132 state = INSTALLSTATE_UNKNOWN;
2137 state = INSTALLSTATE_UNKNOWN;
2140 state = INSTALLSTATE_ABSENT;
2143 RegCloseKey(prodkey);
2144 RegCloseKey(userdata);
2145 TRACE("-> %d\n", state);
2149 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2151 INSTALLUILEVEL old = gUILevel;
2152 HWND oldwnd = gUIhwnd;
2154 TRACE("%08x %p\n", dwUILevel, phWnd);
2156 gUILevel = dwUILevel;
2165 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2166 DWORD dwMessageFilter, LPVOID pvContext)
2168 INSTALLUI_HANDLERA prev = gUIHandlerA;
2170 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2172 gUIHandlerA = puiHandler;
2174 gUIFilter = dwMessageFilter;
2175 gUIContext = pvContext;
2180 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2181 DWORD dwMessageFilter, LPVOID pvContext)
2183 INSTALLUI_HANDLERW prev = gUIHandlerW;
2185 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2188 gUIHandlerW = puiHandler;
2189 gUIFilter = dwMessageFilter;
2190 gUIContext = pvContext;
2195 /******************************************************************
2196 * MsiLoadStringW [MSI.@]
2198 * Loads a string from MSI's string resources.
2202 * handle [I] only -1 is handled currently
2203 * id [I] id of the string to be loaded
2204 * lpBuffer [O] buffer for the string to be written to
2205 * nBufferMax [I] maximum size of the buffer in characters
2206 * lang [I] the preferred language for the string
2210 * If successful, this function returns the language id of the string loaded
2211 * If the function fails, the function returns zero.
2215 * The type of the first parameter is unknown. LoadString's prototype
2216 * suggests that it might be a module handle. I have made it an MSI handle
2217 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2218 * handle. Maybe strings can be stored in an MSI database somehow.
2220 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2221 int nBufferMax, LANGID lang )
2228 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2231 FIXME("don't know how to deal with handle = %08x\n", handle);
2234 lang = GetUserDefaultLangID();
2236 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2240 hResData = LoadResource( msi_hInstance, hres );
2243 p = LockResource( hResData );
2247 for (i = 0; i < (id&0xf); i++)
2251 if( nBufferMax <= len )
2254 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2255 lpBuffer[ len ] = 0;
2257 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2262 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2263 int nBufferMax, LANGID lang )
2269 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2270 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2273 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2274 if( len <= nBufferMax )
2275 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2276 lpBuffer, nBufferMax, NULL, NULL );
2284 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2287 char szProduct[GUID_SIZE];
2289 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2291 if (!szComponent || !pcchBuf)
2292 return INSTALLSTATE_INVALIDARG;
2294 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2295 return INSTALLSTATE_UNKNOWN;
2297 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2300 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2303 WCHAR szProduct[GUID_SIZE];
2305 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2307 if (!szComponent || !pcchBuf)
2308 return INSTALLSTATE_INVALIDARG;
2310 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2311 return INSTALLSTATE_UNKNOWN;
2313 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2316 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2317 WORD wLanguageId, DWORD f)
2319 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2320 uType, wLanguageId, f);
2321 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2324 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2325 WORD wLanguageId, DWORD f)
2327 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2328 uType, wLanguageId, f);
2329 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2332 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2333 DWORD unknown, WORD wLanguageId, DWORD f)
2335 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2336 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2337 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2340 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2341 DWORD unknown, WORD wLanguageId, DWORD f)
2343 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2344 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2345 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2348 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2349 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2350 LPDWORD pcchPathBuf )
2352 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2353 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2355 return ERROR_CALL_NOT_IMPLEMENTED;
2358 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2359 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2360 LPDWORD pcchPathBuf )
2362 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2363 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2365 return ERROR_CALL_NOT_IMPLEMENTED;
2368 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2369 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2371 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2372 return ERROR_CALL_NOT_IMPLEMENTED;
2375 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2376 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2378 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2379 return ERROR_CALL_NOT_IMPLEMENTED;
2382 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2383 LPBYTE hash, LPDWORD hashlen )
2386 WCHAR *pathW = NULL;
2388 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2390 if (path && !(pathW = strdupAtoW( path ))) return ERROR_OUTOFMEMORY;
2391 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2396 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2397 LPBYTE hash, LPDWORD hashlen )
2399 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2402 WINTRUST_FILE_INFO info;
2403 CRYPT_PROVIDER_SGNR *signer;
2404 CRYPT_PROVIDER_CERT *provider;
2406 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2408 if (!path || !cert) return E_INVALIDARG;
2410 info.cbStruct = sizeof(info);
2411 info.pcwszFilePath = path;
2413 info.pgKnownSubject = NULL;
2415 data.cbStruct = sizeof(data);
2416 data.pPolicyCallbackData = NULL;
2417 data.pSIPClientData = NULL;
2418 data.dwUIChoice = WTD_UI_NONE;
2419 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2420 data.dwUnionChoice = WTD_CHOICE_FILE;
2421 data.u.pFile = &info;
2422 data.dwStateAction = WTD_STATEACTION_VERIFY;
2423 data.hWVTStateData = NULL;
2424 data.pwszURLReference = NULL;
2425 data.dwProvFlags = 0;
2426 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2427 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2428 if (FAILED(hr)) goto done;
2430 if (!(signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 )))
2432 hr = TRUST_E_NOSIGNATURE;
2437 DWORD len = signer->psSigner->EncryptedHash.cbData;
2441 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2444 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2447 if (!(provider = WTHelperGetProvCertFromChain( signer, 0 )))
2449 hr = TRUST_E_PROVIDER_UNKNOWN;
2452 *cert = CertDuplicateCertificateContext( provider->pCert );
2455 data.dwStateAction = WTD_STATEACTION_CLOSE;
2456 WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2460 /******************************************************************
2461 * MsiGetProductPropertyA [MSI.@]
2463 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2464 LPSTR szValue, LPDWORD pccbValue)
2466 LPWSTR prop = NULL, val = NULL;
2470 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2471 szValue, pccbValue);
2473 if (szValue && !pccbValue)
2474 return ERROR_INVALID_PARAMETER;
2476 if (szProperty) prop = strdupAtoW(szProperty);
2479 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2480 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2483 if (r == ERROR_SUCCESS)
2485 if (szValue) *szValue = '\0';
2486 if (pccbValue) *pccbValue = 0;
2490 val = msi_alloc(++len * sizeof(WCHAR));
2493 r = ERROR_OUTOFMEMORY;
2497 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2498 if (r != ERROR_SUCCESS)
2501 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2504 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2505 *pccbValue, NULL, NULL);
2509 if (len > *pccbValue)
2510 r = ERROR_MORE_DATA;
2512 *pccbValue = len - 1;
2522 /******************************************************************
2523 * MsiGetProductPropertyW [MSI.@]
2525 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2526 LPWSTR szValue, LPDWORD pccbValue)
2528 MSIPACKAGE *package;
2529 MSIQUERY *view = NULL;
2530 MSIRECORD *rec = NULL;
2534 static const WCHAR query[] = {
2535 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2536 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2537 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2539 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2540 szValue, pccbValue);
2543 return ERROR_INVALID_PARAMETER;
2545 if (szValue && !pccbValue)
2546 return ERROR_INVALID_PARAMETER;
2548 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2550 return ERROR_INVALID_HANDLE;
2552 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2553 if (r != ERROR_SUCCESS)
2556 r = MSI_ViewExecute(view, 0);
2557 if (r != ERROR_SUCCESS)
2560 r = MSI_ViewFetch(view, &rec);
2561 if (r != ERROR_SUCCESS)
2564 val = MSI_RecordGetString(rec, 2);
2568 if (lstrlenW(val) >= *pccbValue)
2570 lstrcpynW(szValue, val, *pccbValue);
2571 *pccbValue = lstrlenW(val);
2572 r = ERROR_MORE_DATA;
2576 lstrcpyW(szValue, val);
2577 *pccbValue = lstrlenW(val);
2584 MSI_ViewClose(view);
2585 msiobj_release(&view->hdr);
2586 if (rec) msiobj_release(&rec->hdr);
2591 if (szValue) *szValue = '\0';
2592 if (pccbValue) *pccbValue = 0;
2596 msiobj_release(&package->hdr);
2600 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2603 LPWSTR szPack = NULL;
2605 TRACE("%s\n", debugstr_a(szPackage) );
2609 szPack = strdupAtoW( szPackage );
2611 return ERROR_OUTOFMEMORY;
2614 r = MsiVerifyPackageW( szPack );
2621 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2626 TRACE("%s\n", debugstr_w(szPackage) );
2628 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2629 MsiCloseHandle( handle );
2634 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2635 awstring* lpPathBuf, LPDWORD pcchBuf)
2637 WCHAR squished_pc[GUID_SIZE];
2638 WCHAR squished_comp[GUID_SIZE];
2644 static const WCHAR wininstaller[] = {
2645 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2647 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2648 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2650 if (!szProduct || !szComponent)
2651 return INSTALLSTATE_INVALIDARG;
2653 if (lpPathBuf->str.w && !pcchBuf)
2654 return INSTALLSTATE_INVALIDARG;
2656 if (!squash_guid(szProduct, squished_pc) ||
2657 !squash_guid(szComponent, squished_comp))
2658 return INSTALLSTATE_INVALIDARG;
2660 state = INSTALLSTATE_UNKNOWN;
2662 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2663 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2665 path = msi_reg_get_val_str(hkey, squished_pc);
2668 state = INSTALLSTATE_ABSENT;
2670 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2671 &hkey, FALSE) == ERROR_SUCCESS ||
2672 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2673 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2674 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2675 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2678 state = INSTALLSTATE_LOCAL;
2682 if (state != INSTALLSTATE_LOCAL &&
2683 (MSIREG_OpenProductKey(szProduct, NULL,
2684 MSIINSTALLCONTEXT_USERUNMANAGED,
2685 &hkey, FALSE) == ERROR_SUCCESS ||
2686 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2687 &hkey, FALSE) == ERROR_SUCCESS))
2691 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2692 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2695 path = msi_reg_get_val_str(hkey, squished_pc);
2698 state = INSTALLSTATE_ABSENT;
2700 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2701 state = INSTALLSTATE_LOCAL;
2706 return INSTALLSTATE_UNKNOWN;
2708 if (state == INSTALLSTATE_LOCAL && !*path)
2709 state = INSTALLSTATE_NOTUSED;
2711 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2716 /******************************************************************
2717 * MsiGetComponentPathW [MSI.@]
2719 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2720 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2724 path.unicode = TRUE;
2725 path.str.w = lpPathBuf;
2727 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2730 /******************************************************************
2731 * MsiGetComponentPathA [MSI.@]
2733 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2734 LPSTR lpPathBuf, LPDWORD pcchBuf)
2736 LPWSTR szwProduct, szwComponent = NULL;
2737 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2740 szwProduct = strdupAtoW( szProduct );
2741 if( szProduct && !szwProduct)
2744 szwComponent = strdupAtoW( szComponent );
2745 if( szComponent && !szwComponent )
2748 path.unicode = FALSE;
2749 path.str.a = lpPathBuf;
2751 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2754 msi_free( szwProduct );
2755 msi_free( szwComponent );
2760 /******************************************************************
2761 * MsiQueryFeatureStateA [MSI.@]
2763 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2765 LPWSTR szwProduct = NULL, szwFeature= NULL;
2766 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2768 szwProduct = strdupAtoW( szProduct );
2769 if ( szProduct && !szwProduct )
2772 szwFeature = strdupAtoW( szFeature );
2773 if ( szFeature && !szwFeature )
2776 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2779 msi_free( szwProduct);
2780 msi_free( szwFeature);
2785 /******************************************************************
2786 * MsiQueryFeatureStateW [MSI.@]
2788 * Checks the state of a feature
2791 * szProduct [I] Product's GUID string
2792 * szFeature [I] Feature's GUID string
2795 * INSTALLSTATE_LOCAL Feature is installed and usable
2796 * INSTALLSTATE_ABSENT Feature is absent
2797 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2798 * INSTALLSTATE_UNKNOWN An error occurred
2799 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2802 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2804 WCHAR squishProduct[33], comp[GUID_SIZE];
2806 LPWSTR components, p, parent_feature, path;
2810 BOOL missing = FALSE;
2811 BOOL machine = FALSE;
2812 BOOL source = FALSE;
2814 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2816 if (!szProduct || !szFeature)
2817 return INSTALLSTATE_INVALIDARG;
2819 if (!squash_guid( szProduct, squishProduct ))
2820 return INSTALLSTATE_INVALIDARG;
2822 SetLastError( ERROR_SUCCESS );
2824 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2825 &hkey, FALSE) != ERROR_SUCCESS &&
2826 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2827 &hkey, FALSE) != ERROR_SUCCESS)
2829 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2831 if (rc != ERROR_SUCCESS)
2832 return INSTALLSTATE_UNKNOWN;
2837 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2840 if (!parent_feature)
2841 return INSTALLSTATE_UNKNOWN;
2843 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2844 msi_free(parent_feature);
2845 if (r == INSTALLSTATE_ABSENT)
2849 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2850 MSIINSTALLCONTEXT_MACHINE,
2853 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2854 MSIINSTALLCONTEXT_USERUNMANAGED,
2857 if (rc != ERROR_SUCCESS)
2858 return INSTALLSTATE_ADVERTISED;
2860 components = msi_reg_get_val_str( hkey, szFeature );
2863 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2866 return INSTALLSTATE_ADVERTISED;
2868 for( p = components; *p && *p != 2 ; p += 20)
2870 if (!decode_base85_guid( p, &guid ))
2872 if (p != components)
2875 msi_free(components);
2876 return INSTALLSTATE_BADCONFIG;
2879 StringFromGUID2(&guid, comp, GUID_SIZE);
2882 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2884 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2886 if (rc != ERROR_SUCCESS)
2888 msi_free(components);
2889 return INSTALLSTATE_ADVERTISED;
2892 path = msi_reg_get_val_str(hkey, squishProduct);
2895 else if (lstrlenW(path) > 2 &&
2896 path[0] >= '0' && path[0] <= '9' &&
2897 path[1] >= '0' && path[1] <= '9')
2904 msi_free(components);
2907 r = INSTALLSTATE_ADVERTISED;
2909 r = INSTALLSTATE_SOURCE;
2911 r = INSTALLSTATE_LOCAL;
2913 TRACE("-> %d\n", r);
2917 /******************************************************************
2918 * MsiGetFileVersionA [MSI.@]
2920 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2921 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2923 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2924 UINT ret = ERROR_OUTOFMEMORY;
2926 if ((lpVersionBuf && !pcchVersionBuf) ||
2927 (lpLangBuf && !pcchLangBuf))
2928 return ERROR_INVALID_PARAMETER;
2932 szwFilePath = strdupAtoW( szFilePath );
2937 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2939 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2940 if( !lpwVersionBuff )
2944 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2946 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2951 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2952 lpwLangBuff, pcchLangBuf);
2954 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2955 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2956 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2957 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2958 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2959 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2962 msi_free(szwFilePath);
2963 msi_free(lpwVersionBuff);
2964 msi_free(lpwLangBuff);
2969 /******************************************************************
2970 * MsiGetFileVersionW [MSI.@]
2972 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2973 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2975 static const WCHAR szVersionResource[] = {'\\',0};
2976 static const WCHAR szVersionFormat[] = {
2977 '%','d','.','%','d','.','%','d','.','%','d',0};
2978 static const WCHAR szLangResource[] = {
2979 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2980 'T','r','a','n','s','l','a','t','i','o','n',0};
2981 static const WCHAR szLangFormat[] = {'%','d',0};
2983 DWORD dwVerLen, gle;
2984 LPVOID lpVer = NULL;
2985 VS_FIXEDFILEINFO *ffi;
2990 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2991 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2992 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2994 if ((lpVersionBuf && !pcchVersionBuf) ||
2995 (lpLangBuf && !pcchLangBuf))
2996 return ERROR_INVALID_PARAMETER;
2998 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
3001 gle = GetLastError();
3002 if (gle == ERROR_BAD_PATHNAME)
3003 return ERROR_FILE_NOT_FOUND;
3004 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
3005 return ERROR_FILE_INVALID;
3010 lpVer = msi_alloc(dwVerLen);
3013 ret = ERROR_OUTOFMEMORY;
3017 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
3019 ret = GetLastError();
3025 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
3028 wsprintfW(tmp, szVersionFormat,
3029 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
3030 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
3031 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
3033 if (strlenW(tmp) >= *pcchVersionBuf)
3034 ret = ERROR_MORE_DATA;
3036 *pcchVersionBuf = lstrlenW(tmp);
3040 if (lpVersionBuf) *lpVersionBuf = 0;
3041 *pcchVersionBuf = 0;
3047 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
3050 wsprintfW(tmp, szLangFormat, *lang);
3051 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
3053 if (strlenW(tmp) >= *pcchLangBuf)
3054 ret = ERROR_MORE_DATA;
3056 *pcchLangBuf = lstrlenW(tmp);
3060 if (lpLangBuf) *lpLangBuf = 0;
3070 /***********************************************************************
3071 * MsiGetFeatureUsageW [MSI.@]
3073 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
3074 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3076 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
3077 pdwUseCount, pwDateUsed);
3078 return ERROR_CALL_NOT_IMPLEMENTED;
3081 /***********************************************************************
3082 * MsiGetFeatureUsageA [MSI.@]
3084 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
3085 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3087 LPWSTR prod = NULL, feat = NULL;
3088 UINT ret = ERROR_OUTOFMEMORY;
3090 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
3091 pdwUseCount, pwDateUsed);
3093 prod = strdupAtoW( szProduct );
3094 if (szProduct && !prod)
3097 feat = strdupAtoW( szFeature );
3098 if (szFeature && !feat)
3101 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
3110 /***********************************************************************
3111 * MsiUseFeatureExW [MSI.@]
3113 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
3114 DWORD dwInstallMode, DWORD dwReserved )
3118 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3119 dwInstallMode, dwReserved);
3121 state = MsiQueryFeatureStateW( szProduct, szFeature );
3124 return INSTALLSTATE_INVALIDARG;
3126 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
3128 FIXME("mark product %s feature %s as used\n",
3129 debugstr_w(szProduct), debugstr_w(szFeature) );
3135 /***********************************************************************
3136 * MsiUseFeatureExA [MSI.@]
3138 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
3139 DWORD dwInstallMode, DWORD dwReserved )
3141 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
3142 LPWSTR prod = NULL, feat = NULL;
3144 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3145 dwInstallMode, dwReserved);
3147 prod = strdupAtoW( szProduct );
3148 if (szProduct && !prod)
3151 feat = strdupAtoW( szFeature );
3152 if (szFeature && !feat)
3155 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
3164 /***********************************************************************
3165 * MsiUseFeatureW [MSI.@]
3167 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
3169 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
3172 /***********************************************************************
3173 * MsiUseFeatureA [MSI.@]
3175 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
3177 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
3180 /***********************************************************************
3181 * MSI_ProvideQualifiedComponentEx [internal]
3183 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
3184 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3185 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
3186 LPDWORD pcchPathBuf)
3188 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
3189 feature[MAX_FEATURE_CHARS+1];
3195 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
3196 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
3197 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3199 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
3200 if (rc != ERROR_SUCCESS)
3201 return ERROR_INDEX_ABSENT;
3203 info = msi_reg_get_val_str( hkey, szQualifier );
3207 return ERROR_INDEX_ABSENT;
3209 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
3212 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
3214 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
3218 if (rc != INSTALLSTATE_LOCAL)
3219 return ERROR_FILE_NOT_FOUND;
3221 return ERROR_SUCCESS;
3224 /***********************************************************************
3225 * MsiProvideQualifiedComponentExW [MSI.@]
3227 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3228 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3229 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3230 LPDWORD pcchPathBuf)
3234 path.unicode = TRUE;
3235 path.str.w = lpPathBuf;
3237 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3238 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3241 /***********************************************************************
3242 * MsiProvideQualifiedComponentExA [MSI.@]
3244 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3245 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3246 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3247 LPDWORD pcchPathBuf)
3249 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3250 UINT r = ERROR_OUTOFMEMORY;
3253 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3254 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3255 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3257 szwComponent = strdupAtoW( szComponent );
3258 if (szComponent && !szwComponent)
3261 szwQualifier = strdupAtoW( szQualifier );
3262 if (szQualifier && !szwQualifier)
3265 szwProduct = strdupAtoW( szProduct );
3266 if (szProduct && !szwProduct)
3269 path.unicode = FALSE;
3270 path.str.a = lpPathBuf;
3272 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3273 dwInstallMode, szwProduct, Unused1,
3274 Unused2, &path, pcchPathBuf);
3276 msi_free(szwProduct);
3277 msi_free(szwComponent);
3278 msi_free(szwQualifier);
3283 /***********************************************************************
3284 * MsiProvideQualifiedComponentW [MSI.@]
3286 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3287 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3288 LPDWORD pcchPathBuf)
3290 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3291 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3294 /***********************************************************************
3295 * MsiProvideQualifiedComponentA [MSI.@]
3297 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3298 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3299 LPDWORD pcchPathBuf)
3301 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3302 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3305 /***********************************************************************
3306 * MSI_GetUserInfo [internal]
3308 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3309 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3310 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3311 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3313 WCHAR squished_pc[SQUISH_GUID_SIZE];
3314 LPWSTR user, org, serial;
3315 USERINFOSTATE state;
3320 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3321 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3324 if (!szProduct || !squash_guid(szProduct, squished_pc))
3325 return USERINFOSTATE_INVALIDARG;
3327 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3328 &hkey, FALSE) != ERROR_SUCCESS &&
3329 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3330 &hkey, FALSE) != ERROR_SUCCESS &&
3331 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3332 &hkey, FALSE) != ERROR_SUCCESS)
3334 return USERINFOSTATE_UNKNOWN;
3337 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3338 NULL, &props, FALSE) != ERROR_SUCCESS &&
3339 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3340 NULL, &props, FALSE) != ERROR_SUCCESS)
3343 return USERINFOSTATE_ABSENT;
3346 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3347 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3348 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3349 state = USERINFOSTATE_ABSENT;
3355 state = USERINFOSTATE_PRESENT;
3357 if (pcchUserNameBuf)
3359 if (lpUserNameBuf && !user)
3361 (*pcchUserNameBuf)--;
3365 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3366 if (r == ERROR_MORE_DATA)
3368 state = USERINFOSTATE_MOREDATA;
3376 if (!orgptr) orgptr = szEmpty;
3378 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3379 if (r == ERROR_MORE_DATA)
3381 state = USERINFOSTATE_MOREDATA;
3394 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3395 if (r == ERROR_MORE_DATA)
3396 state = USERINFOSTATE_MOREDATA;
3407 /***********************************************************************
3408 * MsiGetUserInfoW [MSI.@]
3410 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3411 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3412 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3413 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3415 awstring user, org, serial;
3417 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3418 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3419 (lpSerialBuf && !pcchSerialBuf))
3420 return USERINFOSTATE_INVALIDARG;
3422 user.unicode = TRUE;
3423 user.str.w = lpUserNameBuf;
3425 org.str.w = lpOrgNameBuf;
3426 serial.unicode = TRUE;
3427 serial.str.w = lpSerialBuf;
3429 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3430 &org, pcchOrgNameBuf,
3431 &serial, pcchSerialBuf );
3434 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3435 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3436 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3437 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3439 awstring user, org, serial;
3443 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3444 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3445 (lpSerialBuf && !pcchSerialBuf))
3446 return USERINFOSTATE_INVALIDARG;
3448 prod = strdupAtoW( szProduct );
3449 if (szProduct && !prod)
3450 return ERROR_OUTOFMEMORY;
3452 user.unicode = FALSE;
3453 user.str.a = lpUserNameBuf;
3454 org.unicode = FALSE;
3455 org.str.a = lpOrgNameBuf;
3456 serial.unicode = FALSE;
3457 serial.str.a = lpSerialBuf;
3459 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3460 &org, pcchOrgNameBuf,
3461 &serial, pcchSerialBuf );
3468 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3472 MSIPACKAGE *package;
3473 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3475 TRACE("(%s)\n",debugstr_w(szProduct));
3477 rc = MsiOpenProductW(szProduct,&handle);
3478 if (rc != ERROR_SUCCESS)
3479 return ERROR_INVALID_PARAMETER;
3481 /* MsiCollectUserInfo cannot be called from a custom action. */
3482 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3484 return ERROR_CALL_NOT_IMPLEMENTED;
3486 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3487 msiobj_release( &package->hdr );
3489 MsiCloseHandle(handle);
3494 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3498 MSIPACKAGE *package;
3499 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3501 TRACE("(%s)\n",debugstr_a(szProduct));
3503 rc = MsiOpenProductA(szProduct,&handle);
3504 if (rc != ERROR_SUCCESS)
3505 return ERROR_INVALID_PARAMETER;
3507 /* MsiCollectUserInfo cannot be called from a custom action. */
3508 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3510 return ERROR_CALL_NOT_IMPLEMENTED;
3512 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3513 msiobj_release( &package->hdr );
3515 MsiCloseHandle(handle);
3520 /***********************************************************************
3521 * MsiConfigureFeatureA [MSI.@]
3523 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3525 LPWSTR prod, feat = NULL;
3526 UINT r = ERROR_OUTOFMEMORY;
3528 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3530 prod = strdupAtoW( szProduct );
3531 if (szProduct && !prod)
3534 feat = strdupAtoW( szFeature );
3535 if (szFeature && !feat)
3538 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3547 /***********************************************************************
3548 * MsiConfigureFeatureW [MSI.@]
3550 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3552 MSIPACKAGE *package = NULL;
3554 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3557 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3559 if (!szProduct || !szFeature)
3560 return ERROR_INVALID_PARAMETER;
3562 switch (eInstallState)
3564 case INSTALLSTATE_DEFAULT:
3565 /* FIXME: how do we figure out the default location? */
3566 eInstallState = INSTALLSTATE_LOCAL;
3568 case INSTALLSTATE_LOCAL:
3569 case INSTALLSTATE_SOURCE:
3570 case INSTALLSTATE_ABSENT:
3571 case INSTALLSTATE_ADVERTISED:
3574 return ERROR_INVALID_PARAMETER;
3577 r = MSI_OpenProductW( szProduct, &package );
3578 if (r != ERROR_SUCCESS)
3581 sz = sizeof(sourcepath);
3582 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3583 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3585 sz = sizeof(filename);
3586 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3587 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3589 lstrcatW( sourcepath, filename );
3591 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3593 r = ACTION_PerformUIAction( package, szCostInitialize, -1 );
3594 if (r != ERROR_SUCCESS)
3597 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3598 if (r != ERROR_SUCCESS)
3601 r = MSI_InstallPackage( package, sourcepath, NULL );
3604 msiobj_release( &package->hdr );
3609 /***********************************************************************
3610 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3612 * Notes: undocumented
3614 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3616 WCHAR path[MAX_PATH];
3618 TRACE("%d\n", dwReserved);
3622 FIXME("dwReserved=%d\n", dwReserved);
3623 return ERROR_INVALID_PARAMETER;
3626 if (!GetWindowsDirectoryW(path, MAX_PATH))
3627 return ERROR_FUNCTION_FAILED;
3629 lstrcatW(path, installerW);
3631 if (!CreateDirectoryW(path, NULL))
3632 return ERROR_FUNCTION_FAILED;
3634 return ERROR_SUCCESS;
3637 /***********************************************************************
3638 * MsiGetShortcutTargetA [MSI.@]
3640 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3641 LPSTR szProductCode, LPSTR szFeatureId,
3642 LPSTR szComponentCode )
3645 const int len = MAX_FEATURE_CHARS+1;
3646 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3649 target = strdupAtoW( szShortcutTarget );
3650 if (szShortcutTarget && !target )
3651 return ERROR_OUTOFMEMORY;
3655 r = MsiGetShortcutTargetW( target, product, feature, component );
3657 if (r == ERROR_SUCCESS)
3659 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3660 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3661 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3666 /***********************************************************************
3667 * MsiGetShortcutTargetW [MSI.@]
3669 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3670 LPWSTR szProductCode, LPWSTR szFeatureId,
3671 LPWSTR szComponentCode )
3673 IShellLinkDataList *dl = NULL;
3674 IPersistFile *pf = NULL;
3675 LPEXP_DARWIN_LINK darwin = NULL;
3678 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3679 szProductCode, szFeatureId, szComponentCode );
3681 init = CoInitialize(NULL);
3683 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3684 &IID_IPersistFile, (LPVOID*) &pf );
3685 if( SUCCEEDED( r ) )
3687 r = IPersistFile_Load( pf, szShortcutTarget,
3688 STGM_READ | STGM_SHARE_DENY_WRITE );
3689 if( SUCCEEDED( r ) )
3691 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3693 if( SUCCEEDED( r ) )
3695 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3697 IShellLinkDataList_Release( dl );
3700 IPersistFile_Release( pf );
3703 if (SUCCEEDED(init))
3706 TRACE("darwin = %p\n", darwin);
3713 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3714 szProductCode, szFeatureId, szComponentCode, &sz );
3715 LocalFree( darwin );
3719 return ERROR_FUNCTION_FAILED;
3722 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3723 DWORD dwReinstallMode )
3725 MSIPACKAGE* package = NULL;
3727 WCHAR sourcepath[MAX_PATH];
3728 WCHAR filename[MAX_PATH];
3729 static const WCHAR szLogVerbose[] = {
3730 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3731 WCHAR reinstallmode[11];
3735 FIXME("%s %s 0x%08x\n",
3736 debugstr_w(szProduct), debugstr_w(szFeature), dwReinstallMode);
3738 ptr = reinstallmode;
3740 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3742 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3744 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3746 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3748 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3750 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3752 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3754 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3756 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3758 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3762 sz = sizeof(sourcepath);
3763 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3764 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3766 sz = sizeof(filename);
3767 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3768 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3770 lstrcatW( sourcepath, filename );
3772 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3773 r = MSI_OpenPackageW( sourcepath, &package );
3775 r = MSI_OpenProductW( szProduct, &package );
3777 if (r != ERROR_SUCCESS)
3780 msi_set_property( package->db, szReinstallMode, reinstallmode );
3781 msi_set_property( package->db, szInstalled, szOne );
3782 msi_set_property( package->db, szLogVerbose, szOne );
3783 msi_set_property( package->db, szReinstall, szFeature );
3785 r = MSI_InstallPackage( package, sourcepath, NULL );
3787 msiobj_release( &package->hdr );
3792 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3793 DWORD dwReinstallMode )
3799 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3802 wszProduct = strdupAtoW(szProduct);
3803 wszFeature = strdupAtoW(szFeature);
3805 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3807 msi_free(wszProduct);
3808 msi_free(wszFeature);
3815 unsigned int buf[4];
3816 unsigned char in[64];
3817 unsigned char digest[16];
3820 extern VOID WINAPI MD5Init( MD5_CTX *);
3821 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3822 extern VOID WINAPI MD5Final( MD5_CTX *);
3824 /***********************************************************************
3825 * MsiGetFileHashW [MSI.@]
3827 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3828 PMSIFILEHASHINFO pHash )
3830 HANDLE handle, mapping;
3833 UINT r = ERROR_FUNCTION_FAILED;
3835 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3838 return ERROR_INVALID_PARAMETER;
3841 return ERROR_PATH_NOT_FOUND;
3844 return ERROR_INVALID_PARAMETER;
3846 return ERROR_INVALID_PARAMETER;
3847 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3848 return ERROR_INVALID_PARAMETER;
3850 handle = CreateFileW( szFilePath, GENERIC_READ,
3851 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3852 if (handle == INVALID_HANDLE_VALUE)
3854 WARN("can't open file %u\n", GetLastError());
3855 return ERROR_FILE_NOT_FOUND;
3857 length = GetFileSize( handle, NULL );
3859 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3862 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3868 MD5Update( &ctx, p, length );
3870 UnmapViewOfFile( p );
3872 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3875 CloseHandle( mapping );
3877 CloseHandle( handle );
3882 /***********************************************************************
3883 * MsiGetFileHashA [MSI.@]
3885 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3886 PMSIFILEHASHINFO pHash )
3891 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3893 file = strdupAtoW( szFilePath );
3894 if (szFilePath && !file)
3895 return ERROR_OUTOFMEMORY;
3897 r = MsiGetFileHashW( file, dwOptions, pHash );
3902 /***********************************************************************
3903 * MsiAdvertiseScriptW [MSI.@]
3905 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3906 PHKEY phRegData, BOOL fRemoveItems )
3908 FIXME("%s %08x %p %d\n",
3909 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3910 return ERROR_CALL_NOT_IMPLEMENTED;
3913 /***********************************************************************
3914 * MsiAdvertiseScriptA [MSI.@]
3916 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3917 PHKEY phRegData, BOOL fRemoveItems )
3919 FIXME("%s %08x %p %d\n",
3920 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3921 return ERROR_CALL_NOT_IMPLEMENTED;
3924 /***********************************************************************
3925 * MsiIsProductElevatedW [MSI.@]
3927 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3929 FIXME("%s %p - stub\n",
3930 debugstr_w( szProduct ), pfElevated );
3932 return ERROR_SUCCESS;
3935 /***********************************************************************
3936 * MsiIsProductElevatedA [MSI.@]
3938 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3940 FIXME("%s %p - stub\n",
3941 debugstr_a( szProduct ), pfElevated );
3943 return ERROR_SUCCESS;
3946 /***********************************************************************
3947 * MsiSetExternalUIRecord [MSI.@]
3949 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
3950 DWORD filter, LPVOID context,
3951 PINSTALLUI_HANDLER_RECORD prev )
3953 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
3956 *prev = gUIHandlerRecord;
3958 gUIHandlerRecord = handler;
3960 gUIContext = context;
3962 return ERROR_SUCCESS;
3965 /***********************************************************************
3966 * MsiInstallMissingComponentA [MSI.@]
3968 UINT WINAPI MsiInstallMissingComponentA( LPCSTR product, LPCSTR component, INSTALLSTATE state )
3971 WCHAR *productW = NULL, *componentW = NULL;
3973 TRACE("%s, %s, %d\n", debugstr_a(product), debugstr_a(component), state);
3975 if (product && !(productW = strdupAtoW( product )))
3976 return ERROR_OUTOFMEMORY;
3978 if (component && !(componentW = strdupAtoW( component )))
3980 msi_free( productW );
3981 return ERROR_OUTOFMEMORY;
3984 r = MsiInstallMissingComponentW( productW, componentW, state );
3985 msi_free( productW );
3986 msi_free( componentW );
3990 /***********************************************************************
3991 * MsiInstallMissingComponentW [MSI.@]
3993 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
3995 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
3996 return ERROR_SUCCESS;
3999 /***********************************************************************
4000 * MsiBeginTransactionA [MSI.@]
4002 UINT WINAPI MsiBeginTransactionA( LPCSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4007 FIXME("%s %u %p %p\n", debugstr_a(name), attrs, id, event);
4009 nameW = strdupAtoW( name );
4011 return ERROR_OUTOFMEMORY;
4013 r = MsiBeginTransactionW( nameW, attrs, id, event );
4018 /***********************************************************************
4019 * MsiBeginTransactionW [MSI.@]
4021 UINT WINAPI MsiBeginTransactionW( LPCWSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4023 FIXME("%s %u %p %p\n", debugstr_w(name), attrs, id, event);
4025 *id = (MSIHANDLE)0xdeadbeef;
4026 *event = (HANDLE)0xdeadbeef;
4028 return ERROR_SUCCESS;
4031 /***********************************************************************
4032 * MsiEndTransaction [MSI.@]
4034 UINT WINAPI MsiEndTransaction( DWORD state )
4036 FIXME("%u\n", state);
4037 return ERROR_SUCCESS;