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 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1829 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1830 int *cost, int *temp )
1832 UINT r = ERROR_NO_MORE_ITEMS;
1833 MSICOMPONENT *comp = NULL;
1834 MSIPACKAGE *package;
1837 WCHAR path[MAX_PATH];
1839 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1840 state, drive, buflen, cost, temp);
1842 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1843 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1846 IWineMsiRemotePackage *remote_package;
1849 if (!(remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle )))
1850 return ERROR_INVALID_HANDLE;
1852 if (component && !(bname = SysAllocString( component )))
1854 IWineMsiRemotePackage_Release( remote_package );
1855 return ERROR_OUTOFMEMORY;
1857 hr = IWineMsiRemotePackage_EnumComponentCosts( remote_package, bname, index, state, drive, buflen, cost, temp );
1858 IWineMsiRemotePackage_Release( remote_package );
1859 SysFreeString( bname );
1862 if (HRESULT_FACILITY(hr) == FACILITY_WIN32) return HRESULT_CODE(hr);
1863 return ERROR_FUNCTION_FAILED;
1865 return ERROR_SUCCESS;
1868 if (!msi_get_property_int( package->db, szCostingComplete, 0 ))
1870 msiobj_release( &package->hdr );
1871 return ERROR_FUNCTION_NOT_CALLED;
1873 if (component && component[0] && !(comp = msi_get_loaded_component( package, component )))
1875 msiobj_release( &package->hdr );
1876 return ERROR_UNKNOWN_COMPONENT;
1881 msiobj_release( &package->hdr );
1882 return ERROR_MORE_DATA;
1886 msiobj_release( &package->hdr );
1887 return ERROR_NO_MORE_ITEMS;
1892 GetWindowsDirectoryW( path, MAX_PATH );
1893 if (component && component[0])
1895 if (comp->assembly && !comp->assembly->application) *temp = comp->Cost;
1896 if (!comp->Enabled || !comp->KeyPath)
1905 else if ((file = msi_get_loaded_file( package, comp->KeyPath )))
1907 *cost = max( 8, comp->Cost / 512 );
1908 drive[0] = file->TargetPath[0];
1915 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
1917 *temp = max( 8, stat.cbSize.QuadPart / 512 );
1924 msiobj_release( &package->hdr );
1928 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1929 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1930 LPCSTR szComponent, INSTALLSTATE *pdwState)
1932 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1935 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1936 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1938 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1939 return ERROR_OUTOFMEMORY;
1941 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1942 return ERROR_OUTOFMEMORY;
1944 if (szComponent && !(comp = strdupAtoW(szComponent)))
1945 return ERROR_OUTOFMEMORY;
1947 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1956 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1961 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1963 return (r == ERROR_SUCCESS);
1966 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1974 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1975 static const WCHAR managed_local_package[] = {
1976 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1979 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1980 if (r != ERROR_SUCCESS)
1983 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1984 package = managed_local_package;
1986 package = local_package;
1989 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1992 return (res == ERROR_SUCCESS);
1995 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1996 MSIINSTALLCONTEXT context,
1997 LPCWSTR comp, LPWSTR val, DWORD *sz)
2003 if (context == MSIINSTALLCONTEXT_MACHINE)
2004 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2006 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2008 if (r != ERROR_SUCCESS)
2011 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
2012 if (res != ERROR_SUCCESS)
2019 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
2020 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2021 LPCWSTR szComponent, INSTALLSTATE *pdwState)
2023 WCHAR squished_pc[GUID_SIZE];
2024 WCHAR val[MAX_PATH];
2028 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
2029 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
2031 if (!pdwState || !szComponent)
2032 return ERROR_INVALID_PARAMETER;
2034 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2035 return ERROR_INVALID_PARAMETER;
2037 if (!squash_guid(szProductCode, squished_pc))
2038 return ERROR_INVALID_PARAMETER;
2040 found = msi_comp_find_prod_key(szProductCode, dwContext);
2042 if (!msi_comp_find_package(szProductCode, dwContext))
2046 *pdwState = INSTALLSTATE_UNKNOWN;
2047 return ERROR_UNKNOWN_COMPONENT;
2050 return ERROR_UNKNOWN_PRODUCT;
2053 *pdwState = INSTALLSTATE_UNKNOWN;
2056 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
2057 return ERROR_UNKNOWN_COMPONENT;
2060 *pdwState = INSTALLSTATE_NOTUSED;
2063 if (lstrlenW(val) > 2 &&
2064 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
2066 *pdwState = INSTALLSTATE_SOURCE;
2069 *pdwState = INSTALLSTATE_LOCAL;
2072 TRACE("-> %d\n", *pdwState);
2073 return ERROR_SUCCESS;
2076 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2078 LPWSTR szwProduct = NULL;
2083 szwProduct = strdupAtoW( szProduct );
2085 return ERROR_OUTOFMEMORY;
2087 r = MsiQueryProductStateW( szwProduct );
2088 msi_free( szwProduct );
2092 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2094 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2095 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2096 HKEY prodkey = 0, userdata = 0;
2100 TRACE("%s\n", debugstr_w(szProduct));
2102 if (!szProduct || !*szProduct)
2103 return INSTALLSTATE_INVALIDARG;
2105 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2106 return INSTALLSTATE_INVALIDARG;
2108 if (szProduct[0] != '{' || szProduct[37] != '}')
2109 return INSTALLSTATE_UNKNOWN;
2111 SetLastError( ERROR_SUCCESS );
2113 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2114 &prodkey, FALSE) != ERROR_SUCCESS &&
2115 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2116 &prodkey, FALSE) != ERROR_SUCCESS &&
2117 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2118 &prodkey, FALSE) == ERROR_SUCCESS)
2120 context = MSIINSTALLCONTEXT_MACHINE;
2123 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2124 if (r != ERROR_SUCCESS)
2127 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
2131 state = INSTALLSTATE_DEFAULT;
2133 state = INSTALLSTATE_UNKNOWN;
2138 state = INSTALLSTATE_UNKNOWN;
2141 state = INSTALLSTATE_ABSENT;
2144 RegCloseKey(prodkey);
2145 RegCloseKey(userdata);
2146 TRACE("-> %d\n", state);
2150 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2152 INSTALLUILEVEL old = gUILevel;
2153 HWND oldwnd = gUIhwnd;
2155 TRACE("%08x %p\n", dwUILevel, phWnd);
2157 gUILevel = dwUILevel;
2166 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2167 DWORD dwMessageFilter, LPVOID pvContext)
2169 INSTALLUI_HANDLERA prev = gUIHandlerA;
2171 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2173 gUIHandlerA = puiHandler;
2175 gUIFilter = dwMessageFilter;
2176 gUIContext = pvContext;
2181 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2182 DWORD dwMessageFilter, LPVOID pvContext)
2184 INSTALLUI_HANDLERW prev = gUIHandlerW;
2186 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2189 gUIHandlerW = puiHandler;
2190 gUIFilter = dwMessageFilter;
2191 gUIContext = pvContext;
2196 /******************************************************************
2197 * MsiLoadStringW [MSI.@]
2199 * Loads a string from MSI's string resources.
2203 * handle [I] only -1 is handled currently
2204 * id [I] id of the string to be loaded
2205 * lpBuffer [O] buffer for the string to be written to
2206 * nBufferMax [I] maximum size of the buffer in characters
2207 * lang [I] the preferred language for the string
2211 * If successful, this function returns the language id of the string loaded
2212 * If the function fails, the function returns zero.
2216 * The type of the first parameter is unknown. LoadString's prototype
2217 * suggests that it might be a module handle. I have made it an MSI handle
2218 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2219 * handle. Maybe strings can be stored in an MSI database somehow.
2221 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2222 int nBufferMax, LANGID lang )
2229 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2232 FIXME("don't know how to deal with handle = %08x\n", handle);
2235 lang = GetUserDefaultLangID();
2237 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2241 hResData = LoadResource( msi_hInstance, hres );
2244 p = LockResource( hResData );
2248 for (i = 0; i < (id&0xf); i++)
2252 if( nBufferMax <= len )
2255 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2256 lpBuffer[ len ] = 0;
2258 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2263 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2264 int nBufferMax, LANGID lang )
2270 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2271 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2274 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2275 if( len <= nBufferMax )
2276 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2277 lpBuffer, nBufferMax, NULL, NULL );
2285 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2288 char szProduct[GUID_SIZE];
2290 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2292 if (!szComponent || !pcchBuf)
2293 return INSTALLSTATE_INVALIDARG;
2295 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2296 return INSTALLSTATE_UNKNOWN;
2298 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2301 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2304 WCHAR szProduct[GUID_SIZE];
2306 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2308 if (!szComponent || !pcchBuf)
2309 return INSTALLSTATE_INVALIDARG;
2311 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2312 return INSTALLSTATE_UNKNOWN;
2314 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2317 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2318 WORD wLanguageId, DWORD f)
2320 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2321 uType, wLanguageId, f);
2322 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2325 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2326 WORD wLanguageId, DWORD f)
2328 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2329 uType, wLanguageId, f);
2330 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2333 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2334 DWORD unknown, WORD wLanguageId, DWORD f)
2336 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2337 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2338 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2341 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2342 DWORD unknown, WORD wLanguageId, DWORD f)
2344 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2345 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2346 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2349 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2350 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2351 LPDWORD pcchPathBuf )
2353 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2354 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2356 return ERROR_CALL_NOT_IMPLEMENTED;
2359 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2360 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2361 LPDWORD pcchPathBuf )
2363 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2364 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2366 return ERROR_CALL_NOT_IMPLEMENTED;
2369 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2370 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2372 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2373 return ERROR_CALL_NOT_IMPLEMENTED;
2376 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2377 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2379 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2380 return ERROR_CALL_NOT_IMPLEMENTED;
2383 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2384 LPBYTE hash, LPDWORD hashlen )
2387 WCHAR *pathW = NULL;
2389 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2391 if (path && !(pathW = strdupAtoW( path ))) return ERROR_OUTOFMEMORY;
2392 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2397 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2398 LPBYTE hash, LPDWORD hashlen )
2400 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2403 WINTRUST_FILE_INFO info;
2404 CRYPT_PROVIDER_SGNR *signer;
2405 CRYPT_PROVIDER_CERT *provider;
2407 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2409 if (!path || !cert) return E_INVALIDARG;
2411 info.cbStruct = sizeof(info);
2412 info.pcwszFilePath = path;
2414 info.pgKnownSubject = NULL;
2416 data.cbStruct = sizeof(data);
2417 data.pPolicyCallbackData = NULL;
2418 data.pSIPClientData = NULL;
2419 data.dwUIChoice = WTD_UI_NONE;
2420 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2421 data.dwUnionChoice = WTD_CHOICE_FILE;
2422 data.u.pFile = &info;
2423 data.dwStateAction = WTD_STATEACTION_VERIFY;
2424 data.hWVTStateData = NULL;
2425 data.pwszURLReference = NULL;
2426 data.dwProvFlags = 0;
2427 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2428 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2429 if (FAILED(hr)) goto done;
2431 if (!(signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 )))
2433 hr = TRUST_E_NOSIGNATURE;
2438 DWORD len = signer->psSigner->EncryptedHash.cbData;
2442 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2445 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2448 if (!(provider = WTHelperGetProvCertFromChain( signer, 0 )))
2450 hr = TRUST_E_PROVIDER_UNKNOWN;
2453 *cert = CertDuplicateCertificateContext( provider->pCert );
2456 data.dwStateAction = WTD_STATEACTION_CLOSE;
2457 WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2461 /******************************************************************
2462 * MsiGetProductPropertyA [MSI.@]
2464 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2465 LPSTR szValue, LPDWORD pccbValue)
2467 LPWSTR prop = NULL, val = NULL;
2471 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2472 szValue, pccbValue);
2474 if (szValue && !pccbValue)
2475 return ERROR_INVALID_PARAMETER;
2477 if (szProperty) prop = strdupAtoW(szProperty);
2480 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2481 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2484 if (r == ERROR_SUCCESS)
2486 if (szValue) *szValue = '\0';
2487 if (pccbValue) *pccbValue = 0;
2491 val = msi_alloc(++len * sizeof(WCHAR));
2494 r = ERROR_OUTOFMEMORY;
2498 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2499 if (r != ERROR_SUCCESS)
2502 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2505 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2506 *pccbValue, NULL, NULL);
2510 if (len > *pccbValue)
2511 r = ERROR_MORE_DATA;
2513 *pccbValue = len - 1;
2523 /******************************************************************
2524 * MsiGetProductPropertyW [MSI.@]
2526 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2527 LPWSTR szValue, LPDWORD pccbValue)
2529 MSIPACKAGE *package;
2530 MSIQUERY *view = NULL;
2531 MSIRECORD *rec = NULL;
2535 static const WCHAR query[] = {
2536 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2537 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2538 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2540 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2541 szValue, pccbValue);
2544 return ERROR_INVALID_PARAMETER;
2546 if (szValue && !pccbValue)
2547 return ERROR_INVALID_PARAMETER;
2549 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2551 return ERROR_INVALID_HANDLE;
2553 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2554 if (r != ERROR_SUCCESS)
2557 r = MSI_ViewExecute(view, 0);
2558 if (r != ERROR_SUCCESS)
2561 r = MSI_ViewFetch(view, &rec);
2562 if (r != ERROR_SUCCESS)
2565 val = MSI_RecordGetString(rec, 2);
2569 if (lstrlenW(val) >= *pccbValue)
2571 lstrcpynW(szValue, val, *pccbValue);
2572 *pccbValue = lstrlenW(val);
2573 r = ERROR_MORE_DATA;
2577 lstrcpyW(szValue, val);
2578 *pccbValue = lstrlenW(val);
2585 MSI_ViewClose(view);
2586 msiobj_release(&view->hdr);
2587 if (rec) msiobj_release(&rec->hdr);
2592 if (szValue) *szValue = '\0';
2593 if (pccbValue) *pccbValue = 0;
2597 msiobj_release(&package->hdr);
2601 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2604 LPWSTR szPack = NULL;
2606 TRACE("%s\n", debugstr_a(szPackage) );
2610 szPack = strdupAtoW( szPackage );
2612 return ERROR_OUTOFMEMORY;
2615 r = MsiVerifyPackageW( szPack );
2622 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2627 TRACE("%s\n", debugstr_w(szPackage) );
2629 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2630 MsiCloseHandle( handle );
2635 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2636 awstring* lpPathBuf, LPDWORD pcchBuf)
2638 WCHAR squished_pc[GUID_SIZE];
2639 WCHAR squished_comp[GUID_SIZE];
2645 static const WCHAR wininstaller[] = {
2646 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2648 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2649 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2651 if (!szProduct || !szComponent)
2652 return INSTALLSTATE_INVALIDARG;
2654 if (lpPathBuf->str.w && !pcchBuf)
2655 return INSTALLSTATE_INVALIDARG;
2657 if (!squash_guid(szProduct, squished_pc) ||
2658 !squash_guid(szComponent, squished_comp))
2659 return INSTALLSTATE_INVALIDARG;
2661 state = INSTALLSTATE_UNKNOWN;
2663 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2664 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2666 path = msi_reg_get_val_str(hkey, squished_pc);
2669 state = INSTALLSTATE_ABSENT;
2671 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2672 &hkey, FALSE) == ERROR_SUCCESS ||
2673 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2674 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2675 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2676 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2679 state = INSTALLSTATE_LOCAL;
2683 if (state != INSTALLSTATE_LOCAL &&
2684 (MSIREG_OpenProductKey(szProduct, NULL,
2685 MSIINSTALLCONTEXT_USERUNMANAGED,
2686 &hkey, FALSE) == ERROR_SUCCESS ||
2687 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2688 &hkey, FALSE) == ERROR_SUCCESS))
2692 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2693 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2696 path = msi_reg_get_val_str(hkey, squished_pc);
2699 state = INSTALLSTATE_ABSENT;
2701 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2702 state = INSTALLSTATE_LOCAL;
2707 return INSTALLSTATE_UNKNOWN;
2709 if (state == INSTALLSTATE_LOCAL && !*path)
2710 state = INSTALLSTATE_NOTUSED;
2712 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2717 /******************************************************************
2718 * MsiGetComponentPathW [MSI.@]
2720 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2721 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2725 path.unicode = TRUE;
2726 path.str.w = lpPathBuf;
2728 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2731 /******************************************************************
2732 * MsiGetComponentPathA [MSI.@]
2734 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2735 LPSTR lpPathBuf, LPDWORD pcchBuf)
2737 LPWSTR szwProduct, szwComponent = NULL;
2738 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2741 szwProduct = strdupAtoW( szProduct );
2742 if( szProduct && !szwProduct)
2745 szwComponent = strdupAtoW( szComponent );
2746 if( szComponent && !szwComponent )
2749 path.unicode = FALSE;
2750 path.str.a = lpPathBuf;
2752 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2755 msi_free( szwProduct );
2756 msi_free( szwComponent );
2761 /******************************************************************
2762 * MsiQueryFeatureStateA [MSI.@]
2764 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2766 LPWSTR szwProduct = NULL, szwFeature= NULL;
2767 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2769 szwProduct = strdupAtoW( szProduct );
2770 if ( szProduct && !szwProduct )
2773 szwFeature = strdupAtoW( szFeature );
2774 if ( szFeature && !szwFeature )
2777 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2780 msi_free( szwProduct);
2781 msi_free( szwFeature);
2786 /******************************************************************
2787 * MsiQueryFeatureStateW [MSI.@]
2789 * Checks the state of a feature
2792 * szProduct [I] Product's GUID string
2793 * szFeature [I] Feature's GUID string
2796 * INSTALLSTATE_LOCAL Feature is installed and usable
2797 * INSTALLSTATE_ABSENT Feature is absent
2798 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2799 * INSTALLSTATE_UNKNOWN An error occurred
2800 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2803 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2805 WCHAR squishProduct[33], comp[GUID_SIZE];
2807 LPWSTR components, p, parent_feature, path;
2811 BOOL missing = FALSE;
2812 BOOL machine = FALSE;
2813 BOOL source = FALSE;
2815 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2817 if (!szProduct || !szFeature)
2818 return INSTALLSTATE_INVALIDARG;
2820 if (!squash_guid( szProduct, squishProduct ))
2821 return INSTALLSTATE_INVALIDARG;
2823 SetLastError( ERROR_SUCCESS );
2825 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2826 &hkey, FALSE) != ERROR_SUCCESS &&
2827 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2828 &hkey, FALSE) != ERROR_SUCCESS)
2830 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2832 if (rc != ERROR_SUCCESS)
2833 return INSTALLSTATE_UNKNOWN;
2838 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2841 if (!parent_feature)
2842 return INSTALLSTATE_UNKNOWN;
2844 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2845 msi_free(parent_feature);
2846 if (r == INSTALLSTATE_ABSENT)
2850 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2851 MSIINSTALLCONTEXT_MACHINE,
2854 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2855 MSIINSTALLCONTEXT_USERUNMANAGED,
2858 if (rc != ERROR_SUCCESS)
2859 return INSTALLSTATE_ADVERTISED;
2861 components = msi_reg_get_val_str( hkey, szFeature );
2864 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2867 return INSTALLSTATE_ADVERTISED;
2869 for( p = components; *p && *p != 2 ; p += 20)
2871 if (!decode_base85_guid( p, &guid ))
2873 if (p != components)
2876 msi_free(components);
2877 return INSTALLSTATE_BADCONFIG;
2880 StringFromGUID2(&guid, comp, GUID_SIZE);
2883 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2885 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2887 if (rc != ERROR_SUCCESS)
2889 msi_free(components);
2890 return INSTALLSTATE_ADVERTISED;
2893 path = msi_reg_get_val_str(hkey, squishProduct);
2896 else if (lstrlenW(path) > 2 &&
2897 path[0] >= '0' && path[0] <= '9' &&
2898 path[1] >= '0' && path[1] <= '9')
2905 msi_free(components);
2908 r = INSTALLSTATE_ADVERTISED;
2910 r = INSTALLSTATE_SOURCE;
2912 r = INSTALLSTATE_LOCAL;
2914 TRACE("-> %d\n", r);
2918 /******************************************************************
2919 * MsiGetFileVersionA [MSI.@]
2921 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2922 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2924 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2925 UINT ret = ERROR_OUTOFMEMORY;
2927 if ((lpVersionBuf && !pcchVersionBuf) ||
2928 (lpLangBuf && !pcchLangBuf))
2929 return ERROR_INVALID_PARAMETER;
2933 szwFilePath = strdupAtoW( szFilePath );
2938 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2940 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2941 if( !lpwVersionBuff )
2945 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2947 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2952 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2953 lpwLangBuff, pcchLangBuf);
2955 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2956 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2957 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2958 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2959 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2960 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2963 msi_free(szwFilePath);
2964 msi_free(lpwVersionBuff);
2965 msi_free(lpwLangBuff);
2970 /******************************************************************
2971 * MsiGetFileVersionW [MSI.@]
2973 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2974 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2976 static const WCHAR szVersionResource[] = {'\\',0};
2977 static const WCHAR szVersionFormat[] = {
2978 '%','d','.','%','d','.','%','d','.','%','d',0};
2979 static const WCHAR szLangResource[] = {
2980 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2981 'T','r','a','n','s','l','a','t','i','o','n',0};
2982 static const WCHAR szLangFormat[] = {'%','d',0};
2984 DWORD dwVerLen, gle;
2985 LPVOID lpVer = NULL;
2986 VS_FIXEDFILEINFO *ffi;
2991 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2992 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2993 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2995 if ((lpVersionBuf && !pcchVersionBuf) ||
2996 (lpLangBuf && !pcchLangBuf))
2997 return ERROR_INVALID_PARAMETER;
2999 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
3002 gle = GetLastError();
3003 if (gle == ERROR_BAD_PATHNAME)
3004 return ERROR_FILE_NOT_FOUND;
3005 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
3006 return ERROR_FILE_INVALID;
3011 lpVer = msi_alloc(dwVerLen);
3014 ret = ERROR_OUTOFMEMORY;
3018 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
3020 ret = GetLastError();
3026 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
3029 wsprintfW(tmp, szVersionFormat,
3030 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
3031 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
3032 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
3034 if (strlenW(tmp) >= *pcchVersionBuf)
3035 ret = ERROR_MORE_DATA;
3037 *pcchVersionBuf = lstrlenW(tmp);
3041 if (lpVersionBuf) *lpVersionBuf = 0;
3042 *pcchVersionBuf = 0;
3048 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
3051 wsprintfW(tmp, szLangFormat, *lang);
3052 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
3054 if (strlenW(tmp) >= *pcchLangBuf)
3055 ret = ERROR_MORE_DATA;
3057 *pcchLangBuf = lstrlenW(tmp);
3061 if (lpLangBuf) *lpLangBuf = 0;
3071 /***********************************************************************
3072 * MsiGetFeatureUsageW [MSI.@]
3074 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
3075 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3077 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
3078 pdwUseCount, pwDateUsed);
3079 return ERROR_CALL_NOT_IMPLEMENTED;
3082 /***********************************************************************
3083 * MsiGetFeatureUsageA [MSI.@]
3085 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
3086 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3088 LPWSTR prod = NULL, feat = NULL;
3089 UINT ret = ERROR_OUTOFMEMORY;
3091 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
3092 pdwUseCount, pwDateUsed);
3094 prod = strdupAtoW( szProduct );
3095 if (szProduct && !prod)
3098 feat = strdupAtoW( szFeature );
3099 if (szFeature && !feat)
3102 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
3111 /***********************************************************************
3112 * MsiUseFeatureExW [MSI.@]
3114 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
3115 DWORD dwInstallMode, DWORD dwReserved )
3119 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3120 dwInstallMode, dwReserved);
3122 state = MsiQueryFeatureStateW( szProduct, szFeature );
3125 return INSTALLSTATE_INVALIDARG;
3127 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
3129 FIXME("mark product %s feature %s as used\n",
3130 debugstr_w(szProduct), debugstr_w(szFeature) );
3136 /***********************************************************************
3137 * MsiUseFeatureExA [MSI.@]
3139 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
3140 DWORD dwInstallMode, DWORD dwReserved )
3142 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
3143 LPWSTR prod = NULL, feat = NULL;
3145 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3146 dwInstallMode, dwReserved);
3148 prod = strdupAtoW( szProduct );
3149 if (szProduct && !prod)
3152 feat = strdupAtoW( szFeature );
3153 if (szFeature && !feat)
3156 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
3165 /***********************************************************************
3166 * MsiUseFeatureW [MSI.@]
3168 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
3170 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
3173 /***********************************************************************
3174 * MsiUseFeatureA [MSI.@]
3176 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
3178 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
3181 /***********************************************************************
3182 * MSI_ProvideQualifiedComponentEx [internal]
3184 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
3185 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3186 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
3187 LPDWORD pcchPathBuf)
3189 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
3190 feature[MAX_FEATURE_CHARS+1];
3196 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
3197 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
3198 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3200 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
3201 if (rc != ERROR_SUCCESS)
3202 return ERROR_INDEX_ABSENT;
3204 info = msi_reg_get_val_str( hkey, szQualifier );
3208 return ERROR_INDEX_ABSENT;
3210 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
3213 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
3215 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
3219 if (rc != INSTALLSTATE_LOCAL)
3220 return ERROR_FILE_NOT_FOUND;
3222 return ERROR_SUCCESS;
3225 /***********************************************************************
3226 * MsiProvideQualifiedComponentExW [MSI.@]
3228 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3229 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3230 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3231 LPDWORD pcchPathBuf)
3235 path.unicode = TRUE;
3236 path.str.w = lpPathBuf;
3238 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3239 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3242 /***********************************************************************
3243 * MsiProvideQualifiedComponentExA [MSI.@]
3245 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3246 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3247 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3248 LPDWORD pcchPathBuf)
3250 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3251 UINT r = ERROR_OUTOFMEMORY;
3254 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3255 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3256 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3258 szwComponent = strdupAtoW( szComponent );
3259 if (szComponent && !szwComponent)
3262 szwQualifier = strdupAtoW( szQualifier );
3263 if (szQualifier && !szwQualifier)
3266 szwProduct = strdupAtoW( szProduct );
3267 if (szProduct && !szwProduct)
3270 path.unicode = FALSE;
3271 path.str.a = lpPathBuf;
3273 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3274 dwInstallMode, szwProduct, Unused1,
3275 Unused2, &path, pcchPathBuf);
3277 msi_free(szwProduct);
3278 msi_free(szwComponent);
3279 msi_free(szwQualifier);
3284 /***********************************************************************
3285 * MsiProvideQualifiedComponentW [MSI.@]
3287 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3288 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3289 LPDWORD pcchPathBuf)
3291 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3292 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3295 /***********************************************************************
3296 * MsiProvideQualifiedComponentA [MSI.@]
3298 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3299 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3300 LPDWORD pcchPathBuf)
3302 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3303 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3306 /***********************************************************************
3307 * MSI_GetUserInfo [internal]
3309 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3310 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3311 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3312 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3314 WCHAR squished_pc[SQUISH_GUID_SIZE];
3315 LPWSTR user, org, serial;
3316 USERINFOSTATE state;
3321 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3322 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3325 if (!szProduct || !squash_guid(szProduct, squished_pc))
3326 return USERINFOSTATE_INVALIDARG;
3328 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3329 &hkey, FALSE) != ERROR_SUCCESS &&
3330 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3331 &hkey, FALSE) != ERROR_SUCCESS &&
3332 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3333 &hkey, FALSE) != ERROR_SUCCESS)
3335 return USERINFOSTATE_UNKNOWN;
3338 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3339 NULL, &props, FALSE) != ERROR_SUCCESS &&
3340 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3341 NULL, &props, FALSE) != ERROR_SUCCESS)
3344 return USERINFOSTATE_ABSENT;
3347 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3348 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3349 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3350 state = USERINFOSTATE_ABSENT;
3356 state = USERINFOSTATE_PRESENT;
3358 if (pcchUserNameBuf)
3360 if (lpUserNameBuf && !user)
3362 (*pcchUserNameBuf)--;
3366 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3367 if (r == ERROR_MORE_DATA)
3369 state = USERINFOSTATE_MOREDATA;
3377 if (!orgptr) orgptr = szEmpty;
3379 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3380 if (r == ERROR_MORE_DATA)
3382 state = USERINFOSTATE_MOREDATA;
3395 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3396 if (r == ERROR_MORE_DATA)
3397 state = USERINFOSTATE_MOREDATA;
3408 /***********************************************************************
3409 * MsiGetUserInfoW [MSI.@]
3411 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3412 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3413 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3414 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3416 awstring user, org, serial;
3418 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3419 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3420 (lpSerialBuf && !pcchSerialBuf))
3421 return USERINFOSTATE_INVALIDARG;
3423 user.unicode = TRUE;
3424 user.str.w = lpUserNameBuf;
3426 org.str.w = lpOrgNameBuf;
3427 serial.unicode = TRUE;
3428 serial.str.w = lpSerialBuf;
3430 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3431 &org, pcchOrgNameBuf,
3432 &serial, pcchSerialBuf );
3435 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3436 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3437 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3438 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3440 awstring user, org, serial;
3444 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3445 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3446 (lpSerialBuf && !pcchSerialBuf))
3447 return USERINFOSTATE_INVALIDARG;
3449 prod = strdupAtoW( szProduct );
3450 if (szProduct && !prod)
3451 return ERROR_OUTOFMEMORY;
3453 user.unicode = FALSE;
3454 user.str.a = lpUserNameBuf;
3455 org.unicode = FALSE;
3456 org.str.a = lpOrgNameBuf;
3457 serial.unicode = FALSE;
3458 serial.str.a = lpSerialBuf;
3460 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3461 &org, pcchOrgNameBuf,
3462 &serial, pcchSerialBuf );
3469 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3473 MSIPACKAGE *package;
3474 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3476 TRACE("(%s)\n",debugstr_w(szProduct));
3478 rc = MsiOpenProductW(szProduct,&handle);
3479 if (rc != ERROR_SUCCESS)
3480 return ERROR_INVALID_PARAMETER;
3482 /* MsiCollectUserInfo cannot be called from a custom action. */
3483 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3485 return ERROR_CALL_NOT_IMPLEMENTED;
3487 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3488 msiobj_release( &package->hdr );
3490 MsiCloseHandle(handle);
3495 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3499 MSIPACKAGE *package;
3500 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3502 TRACE("(%s)\n",debugstr_a(szProduct));
3504 rc = MsiOpenProductA(szProduct,&handle);
3505 if (rc != ERROR_SUCCESS)
3506 return ERROR_INVALID_PARAMETER;
3508 /* MsiCollectUserInfo cannot be called from a custom action. */
3509 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3511 return ERROR_CALL_NOT_IMPLEMENTED;
3513 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3514 msiobj_release( &package->hdr );
3516 MsiCloseHandle(handle);
3521 /***********************************************************************
3522 * MsiConfigureFeatureA [MSI.@]
3524 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3526 LPWSTR prod, feat = NULL;
3527 UINT r = ERROR_OUTOFMEMORY;
3529 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3531 prod = strdupAtoW( szProduct );
3532 if (szProduct && !prod)
3535 feat = strdupAtoW( szFeature );
3536 if (szFeature && !feat)
3539 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3548 /***********************************************************************
3549 * MsiConfigureFeatureW [MSI.@]
3551 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3553 MSIPACKAGE *package = NULL;
3555 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3558 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3560 if (!szProduct || !szFeature)
3561 return ERROR_INVALID_PARAMETER;
3563 switch (eInstallState)
3565 case INSTALLSTATE_DEFAULT:
3566 /* FIXME: how do we figure out the default location? */
3567 eInstallState = INSTALLSTATE_LOCAL;
3569 case INSTALLSTATE_LOCAL:
3570 case INSTALLSTATE_SOURCE:
3571 case INSTALLSTATE_ABSENT:
3572 case INSTALLSTATE_ADVERTISED:
3575 return ERROR_INVALID_PARAMETER;
3578 r = MSI_OpenProductW( szProduct, &package );
3579 if (r != ERROR_SUCCESS)
3582 sz = sizeof(sourcepath);
3583 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3584 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3586 sz = sizeof(filename);
3587 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3588 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3590 lstrcatW( sourcepath, filename );
3592 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3594 r = ACTION_PerformUIAction( package, szCostInitialize, -1 );
3595 if (r != ERROR_SUCCESS)
3598 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3599 if (r != ERROR_SUCCESS)
3602 r = MSI_InstallPackage( package, sourcepath, NULL );
3605 msiobj_release( &package->hdr );
3610 /***********************************************************************
3611 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3613 * Notes: undocumented
3615 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3617 WCHAR path[MAX_PATH];
3619 TRACE("%d\n", dwReserved);
3623 FIXME("dwReserved=%d\n", dwReserved);
3624 return ERROR_INVALID_PARAMETER;
3627 if (!GetWindowsDirectoryW(path, MAX_PATH))
3628 return ERROR_FUNCTION_FAILED;
3630 lstrcatW(path, installerW);
3632 if (!CreateDirectoryW(path, NULL))
3633 return ERROR_FUNCTION_FAILED;
3635 return ERROR_SUCCESS;
3638 /***********************************************************************
3639 * MsiGetShortcutTargetA [MSI.@]
3641 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3642 LPSTR szProductCode, LPSTR szFeatureId,
3643 LPSTR szComponentCode )
3646 const int len = MAX_FEATURE_CHARS+1;
3647 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3650 target = strdupAtoW( szShortcutTarget );
3651 if (szShortcutTarget && !target )
3652 return ERROR_OUTOFMEMORY;
3656 r = MsiGetShortcutTargetW( target, product, feature, component );
3658 if (r == ERROR_SUCCESS)
3660 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3661 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3662 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3667 /***********************************************************************
3668 * MsiGetShortcutTargetW [MSI.@]
3670 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3671 LPWSTR szProductCode, LPWSTR szFeatureId,
3672 LPWSTR szComponentCode )
3674 IShellLinkDataList *dl = NULL;
3675 IPersistFile *pf = NULL;
3676 LPEXP_DARWIN_LINK darwin = NULL;
3679 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3680 szProductCode, szFeatureId, szComponentCode );
3682 init = CoInitialize(NULL);
3684 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3685 &IID_IPersistFile, (LPVOID*) &pf );
3686 if( SUCCEEDED( r ) )
3688 r = IPersistFile_Load( pf, szShortcutTarget,
3689 STGM_READ | STGM_SHARE_DENY_WRITE );
3690 if( SUCCEEDED( r ) )
3692 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3694 if( SUCCEEDED( r ) )
3696 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3698 IShellLinkDataList_Release( dl );
3701 IPersistFile_Release( pf );
3704 if (SUCCEEDED(init))
3707 TRACE("darwin = %p\n", darwin);
3714 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3715 szProductCode, szFeatureId, szComponentCode, &sz );
3716 LocalFree( darwin );
3720 return ERROR_FUNCTION_FAILED;
3723 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3724 DWORD dwReinstallMode )
3726 MSIPACKAGE* package = NULL;
3728 WCHAR sourcepath[MAX_PATH];
3729 WCHAR filename[MAX_PATH];
3730 static const WCHAR szLogVerbose[] = {
3731 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3732 WCHAR reinstallmode[11];
3736 FIXME("%s %s 0x%08x\n",
3737 debugstr_w(szProduct), debugstr_w(szFeature), dwReinstallMode);
3739 ptr = reinstallmode;
3741 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3743 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3745 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3747 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3749 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3751 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3753 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3755 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3757 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3759 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3763 sz = sizeof(sourcepath);
3764 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3765 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3767 sz = sizeof(filename);
3768 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3769 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3771 lstrcatW( sourcepath, filename );
3773 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3774 r = MSI_OpenPackageW( sourcepath, &package );
3776 r = MSI_OpenProductW( szProduct, &package );
3778 if (r != ERROR_SUCCESS)
3781 msi_set_property( package->db, szReinstallMode, reinstallmode );
3782 msi_set_property( package->db, szInstalled, szOne );
3783 msi_set_property( package->db, szLogVerbose, szOne );
3784 msi_set_property( package->db, szReinstall, szFeature );
3786 r = MSI_InstallPackage( package, sourcepath, NULL );
3788 msiobj_release( &package->hdr );
3793 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3794 DWORD dwReinstallMode )
3800 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3803 wszProduct = strdupAtoW(szProduct);
3804 wszFeature = strdupAtoW(szFeature);
3806 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3808 msi_free(wszProduct);
3809 msi_free(wszFeature);
3816 unsigned int buf[4];
3817 unsigned char in[64];
3818 unsigned char digest[16];
3821 extern VOID WINAPI MD5Init( MD5_CTX *);
3822 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3823 extern VOID WINAPI MD5Final( MD5_CTX *);
3825 /***********************************************************************
3826 * MsiGetFileHashW [MSI.@]
3828 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3829 PMSIFILEHASHINFO pHash )
3831 HANDLE handle, mapping;
3834 UINT r = ERROR_FUNCTION_FAILED;
3836 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3839 return ERROR_INVALID_PARAMETER;
3842 return ERROR_PATH_NOT_FOUND;
3845 return ERROR_INVALID_PARAMETER;
3847 return ERROR_INVALID_PARAMETER;
3848 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3849 return ERROR_INVALID_PARAMETER;
3851 handle = CreateFileW( szFilePath, GENERIC_READ,
3852 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3853 if (handle == INVALID_HANDLE_VALUE)
3855 WARN("can't open file %u\n", GetLastError());
3856 return ERROR_FILE_NOT_FOUND;
3858 length = GetFileSize( handle, NULL );
3860 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3863 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3869 MD5Update( &ctx, p, length );
3871 UnmapViewOfFile( p );
3873 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3876 CloseHandle( mapping );
3878 CloseHandle( handle );
3883 /***********************************************************************
3884 * MsiGetFileHashA [MSI.@]
3886 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3887 PMSIFILEHASHINFO pHash )
3892 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3894 file = strdupAtoW( szFilePath );
3895 if (szFilePath && !file)
3896 return ERROR_OUTOFMEMORY;
3898 r = MsiGetFileHashW( file, dwOptions, pHash );
3903 /***********************************************************************
3904 * MsiAdvertiseScriptW [MSI.@]
3906 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3907 PHKEY phRegData, BOOL fRemoveItems )
3909 FIXME("%s %08x %p %d\n",
3910 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3911 return ERROR_CALL_NOT_IMPLEMENTED;
3914 /***********************************************************************
3915 * MsiAdvertiseScriptA [MSI.@]
3917 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3918 PHKEY phRegData, BOOL fRemoveItems )
3920 FIXME("%s %08x %p %d\n",
3921 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3922 return ERROR_CALL_NOT_IMPLEMENTED;
3925 /***********************************************************************
3926 * MsiIsProductElevatedW [MSI.@]
3928 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3930 FIXME("%s %p - stub\n",
3931 debugstr_w( szProduct ), pfElevated );
3933 return ERROR_SUCCESS;
3936 /***********************************************************************
3937 * MsiIsProductElevatedA [MSI.@]
3939 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3941 FIXME("%s %p - stub\n",
3942 debugstr_a( szProduct ), pfElevated );
3944 return ERROR_SUCCESS;
3947 /***********************************************************************
3948 * MsiSetExternalUIRecord [MSI.@]
3950 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
3951 DWORD filter, LPVOID context,
3952 PINSTALLUI_HANDLER_RECORD prev )
3954 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
3957 *prev = gUIHandlerRecord;
3959 gUIHandlerRecord = handler;
3961 gUIContext = context;
3963 return ERROR_SUCCESS;
3966 /***********************************************************************
3967 * MsiInstallMissingComponentA [MSI.@]
3969 UINT WINAPI MsiInstallMissingComponentA( LPCSTR product, LPCSTR component, INSTALLSTATE state )
3972 WCHAR *productW = NULL, *componentW = NULL;
3974 TRACE("%s, %s, %d\n", debugstr_a(product), debugstr_a(component), state);
3976 if (product && !(productW = strdupAtoW( product )))
3977 return ERROR_OUTOFMEMORY;
3979 if (component && !(componentW = strdupAtoW( component )))
3981 msi_free( productW );
3982 return ERROR_OUTOFMEMORY;
3985 r = MsiInstallMissingComponentW( productW, componentW, state );
3986 msi_free( productW );
3987 msi_free( componentW );
3991 /***********************************************************************
3992 * MsiInstallMissingComponentW [MSI.@]
3994 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
3996 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
3997 return ERROR_SUCCESS;
4000 /***********************************************************************
4001 * MsiBeginTransactionA [MSI.@]
4003 UINT WINAPI MsiBeginTransactionA( LPCSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4008 FIXME("%s %u %p %p\n", debugstr_a(name), attrs, id, event);
4010 nameW = strdupAtoW( name );
4012 return ERROR_OUTOFMEMORY;
4014 r = MsiBeginTransactionW( nameW, attrs, id, event );
4019 /***********************************************************************
4020 * MsiBeginTransactionW [MSI.@]
4022 UINT WINAPI MsiBeginTransactionW( LPCWSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4024 FIXME("%s %u %p %p\n", debugstr_w(name), attrs, id, event);
4026 *id = (MSIHANDLE)0xdeadbeef;
4027 *event = (HANDLE)0xdeadbeef;
4029 return ERROR_SUCCESS;
4032 /***********************************************************************
4033 * MsiEndTransaction [MSI.@]
4035 UINT WINAPI MsiEndTransaction( DWORD state )
4037 FIXME("%u\n", state);
4038 return ERROR_SUCCESS;