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
31 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
48 static UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
52 *context = MSIINSTALLCONTEXT_NONE;
54 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
55 &hkey, FALSE) == ERROR_SUCCESS)
56 *context = MSIINSTALLCONTEXT_USERMANAGED;
57 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
58 &hkey, FALSE) == ERROR_SUCCESS)
59 *context = MSIINSTALLCONTEXT_MACHINE;
60 else if (MSIREG_OpenProductKey(szProduct, NULL,
61 MSIINSTALLCONTEXT_USERUNMANAGED,
62 &hkey, FALSE) == ERROR_SUCCESS)
63 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
67 if (*context == MSIINSTALLCONTEXT_NONE)
68 return ERROR_UNKNOWN_PRODUCT;
73 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
76 LPWSTR szwProd = NULL;
78 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
82 szwProd = strdupAtoW( szProduct );
84 return ERROR_OUTOFMEMORY;
87 r = MsiOpenProductW( szwProd, phProduct );
94 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
99 MSIINSTALLCONTEXT context;
101 static const WCHAR managed[] = {
102 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
103 static const WCHAR local[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
105 TRACE("%s %p\n", debugstr_w(szProduct), package);
107 r = msi_locate_product(szProduct, &context);
108 if (r != ERROR_SUCCESS)
111 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
112 if (r != ERROR_SUCCESS)
113 return ERROR_UNKNOWN_PRODUCT;
115 if (context == MSIINSTALLCONTEXT_USERMANAGED)
116 path = msi_reg_get_val_str(props, managed);
118 path = msi_reg_get_val_str(props, local);
120 r = ERROR_UNKNOWN_PRODUCT;
122 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
125 if (PathIsRelativeW(path))
127 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
131 r = MSI_OpenPackageW(path, package);
139 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
141 MSIPACKAGE *package = NULL;
142 WCHAR squished_pc[GUID_SIZE];
145 if (!szProduct || !squash_guid(szProduct, squished_pc))
146 return ERROR_INVALID_PARAMETER;
149 return ERROR_INVALID_PARAMETER;
151 r = MSI_OpenProductW(szProduct, &package);
152 if (r != ERROR_SUCCESS)
155 *phProduct = alloc_msihandle(&package->hdr);
157 r = ERROR_NOT_ENOUGH_MEMORY;
159 msiobj_release(&package->hdr);
163 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
164 LPCSTR szTransforms, LANGID lgidLanguage)
166 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
167 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
168 return ERROR_CALL_NOT_IMPLEMENTED;
171 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
172 LPCWSTR szTransforms, LANGID lgidLanguage)
174 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
175 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
176 return ERROR_CALL_NOT_IMPLEMENTED;
179 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
180 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
182 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
183 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
184 lgidLanguage, dwPlatform, dwOptions);
185 return ERROR_CALL_NOT_IMPLEMENTED;
188 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
189 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
191 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
192 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
193 lgidLanguage, dwPlatform, dwOptions);
194 return ERROR_CALL_NOT_IMPLEMENTED;
197 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
199 LPWSTR szwPath = NULL, szwCommand = NULL;
200 UINT r = ERROR_OUTOFMEMORY;
202 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
206 szwPath = strdupAtoW( szPackagePath );
213 szwCommand = strdupAtoW( szCommandLine );
218 r = MsiInstallProductW( szwPath, szwCommand );
222 msi_free( szwCommand );
227 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
229 MSIPACKAGE *package = NULL;
232 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
235 return ERROR_INVALID_PARAMETER;
238 return ERROR_PATH_NOT_FOUND;
240 r = MSI_OpenPackageW( szPackagePath, &package );
241 if (r == ERROR_SUCCESS)
243 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
244 msiobj_release( &package->hdr );
250 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
255 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
257 wszProduct = strdupAtoW(szProduct);
259 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
261 msi_free(wszProduct);
265 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
267 static const WCHAR szAll[] = {'A','L','L',0};
269 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
271 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
274 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
275 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
277 LPWSTR patch_package = NULL;
278 LPWSTR install_package = NULL;
279 LPWSTR command_line = NULL;
280 UINT r = ERROR_OUTOFMEMORY;
282 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
283 eInstallType, debugstr_a(szCommandLine));
285 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
288 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
291 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
294 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
297 msi_free(patch_package);
298 msi_free(install_package);
299 msi_free(command_line);
304 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
306 MSIHANDLE patch = 0, info = 0;
307 UINT r = ERROR_SUCCESS, type;
309 LPCWSTR cmd_ptr = szCommandLine;
310 LPCWSTR product_code = szProductCode;
312 LPWSTR cmd = NULL, codes = NULL;
314 static const WCHAR space[] = {' ',0};
315 static const WCHAR patcheq[] = {'P','A','T','C','H','=',0};
316 static WCHAR empty[] = {0};
318 if (!szPatchPackage || !szPatchPackage[0])
319 return ERROR_INVALID_PARAMETER;
323 r = MsiOpenDatabaseW(szPatchPackage, MSIDBOPEN_READONLY, &patch);
324 if (r != ERROR_SUCCESS)
327 r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
328 if (r != ERROR_SUCCESS)
331 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, empty, &size);
332 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
334 ERR("Failed to read product codes from patch\n");
338 codes = msi_alloc(++size * sizeof(WCHAR));
341 r = ERROR_OUTOFMEMORY;
345 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
346 if (r != ERROR_SUCCESS)
349 product_code = codes;
355 size = lstrlenW(cmd_ptr) + lstrlenW(patcheq) + lstrlenW(szPatchPackage) + 1;
356 cmd = msi_alloc(size * sizeof(WCHAR));
359 r = ERROR_OUTOFMEMORY;
363 lstrcpyW(cmd, cmd_ptr);
364 if (szCommandLine) lstrcatW(cmd, space);
365 lstrcatW(cmd, patcheq);
366 lstrcatW(cmd, szPatchPackage);
369 while ((end = strchrW(beg, '}')))
373 r = MsiConfigureProductExW(beg, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
374 if (r != ERROR_SUCCESS)
384 MsiCloseHandle(info);
385 MsiCloseHandle(patch);
390 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
391 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
393 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
394 eInstallType, debugstr_w(szCommandLine));
396 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
397 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
399 FIXME("Only reading target products from patch\n");
400 return ERROR_CALL_NOT_IMPLEMENTED;
403 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
406 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
407 LPCSTR szProductCode, LPCSTR szPropertiesList)
409 LPWSTR patch_packages = NULL;
410 LPWSTR product_code = NULL;
411 LPWSTR properties_list = NULL;
412 UINT r = ERROR_OUTOFMEMORY;
414 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
415 debugstr_a(szPropertiesList));
417 if (!szPatchPackages || !szPatchPackages[0])
418 return ERROR_INVALID_PARAMETER;
420 if (!(patch_packages = strdupAtoW(szPatchPackages)))
421 return ERROR_OUTOFMEMORY;
423 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
426 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
429 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
432 msi_free(patch_packages);
433 msi_free(product_code);
434 msi_free(properties_list);
439 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
440 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
442 UINT r = ERROR_SUCCESS;
445 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
446 debugstr_w(szPropertiesList));
448 if (!szPatchPackages || !szPatchPackages[0])
449 return ERROR_INVALID_PARAMETER;
451 beg = end = szPatchPackages;
457 while (*beg == ' ') beg++;
458 while (*end && *end != ';') end++;
461 while (len && beg[len - 1] == ' ') len--;
463 if (!len) return ERROR_INVALID_NAME;
465 patch = msi_alloc((len + 1) * sizeof(WCHAR));
467 return ERROR_OUTOFMEMORY;
469 memcpy(patch, beg, len * sizeof(WCHAR));
472 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
475 if (r != ERROR_SUCCESS)
483 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
484 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
486 FIXME("(%s, %d, %p): stub!\n", debugstr_a(szProductPackagePath),
487 cPatchInfo, pPatchInfo);
489 return ERROR_CALL_NOT_IMPLEMENTED;
492 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
495 MSIDATABASE *patch_db;
496 UINT r = ERROR_SUCCESS;
498 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
499 if (r != ERROR_SUCCESS)
501 WARN("failed to open patch file %s\n", debugstr_w(patch));
505 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
508 r = ERROR_FUNCTION_FAILED;
512 r = msi_check_patch_applicable( package, si );
513 if (r != ERROR_SUCCESS)
514 TRACE("patch not applicable\n");
517 msiobj_release( &patch_db->hdr );
518 msiobj_release( &si->hdr );
522 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
523 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
525 UINT i, r, ret = ERROR_FUNCTION_FAILED;
528 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
530 r = MSI_OpenPackageW( szProductPackagePath, &package );
531 if (r != ERROR_SUCCESS)
533 ERR("failed to open package %u\n", r);
537 for (i = 0; i < cPatchInfo; i++)
539 switch (pPatchInfo[i].ePatchDataType)
541 case MSIPATCH_DATATYPE_PATCHFILE:
543 FIXME("patch ordering not supported\n");
544 r = MSI_ApplicablePatchW( package, pPatchInfo[i].szPatchData );
545 if (r != ERROR_SUCCESS)
547 pPatchInfo[i].dwOrder = ~0u;
548 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
552 pPatchInfo[i].dwOrder = i;
553 pPatchInfo[i].uStatus = ret = ERROR_SUCCESS;
559 FIXME("patch data type %u not supported\n", pPatchInfo[i].ePatchDataType);
560 pPatchInfo[i].dwOrder = ~0u;
561 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
566 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo[i].szPatchData));
567 TRACE("ePatchDataType: %u\n", pPatchInfo[i].ePatchDataType);
568 TRACE(" dwOrder: %u\n", pPatchInfo[i].dwOrder);
569 TRACE(" uStatus: %u\n", pPatchInfo[i].uStatus);
574 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
575 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
577 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
578 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
580 return ERROR_CALL_NOT_IMPLEMENTED;
583 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
584 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
586 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
587 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
589 return ERROR_CALL_NOT_IMPLEMENTED;
592 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
593 MSIPACKAGE **package)
599 WCHAR sourcepath[MAX_PATH];
600 WCHAR filename[MAX_PATH];
602 static const WCHAR szLocalPackage[] = {
603 'L','o','c','a','l','P','a','c','k','a','g','e',0};
606 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
607 if (r != ERROR_SUCCESS)
608 return ERROR_BAD_CONFIGURATION;
610 localpack = msi_reg_get_val_str(props, szLocalPackage);
613 lstrcpyW(sourcepath, localpack);
617 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
619 sz = sizeof(sourcepath);
620 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
621 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
623 sz = sizeof(filename);
624 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
625 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
627 lstrcatW(sourcepath, filename);
630 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
631 return ERROR_INSTALL_SOURCE_ABSENT;
633 return MSI_OpenPackageW(sourcepath, package);
636 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
637 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
639 MSIPACKAGE* package = NULL;
640 MSIINSTALLCONTEXT context;
643 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
646 static const WCHAR szInstalled[] = {
647 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
648 static const WCHAR szRemoveAll[] = {
649 ' ','R','E','M','O','V','E','=','A','L','L',0};
650 static const WCHAR szMachine[] = {
651 ' ','A','L','L','U','S','E','R','S','=','1',0};
653 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
654 debugstr_w(szCommandLine));
656 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
657 return ERROR_INVALID_PARAMETER;
659 if (eInstallState == INSTALLSTATE_ADVERTISED ||
660 eInstallState == INSTALLSTATE_SOURCE)
662 FIXME("State %d not implemented\n", eInstallState);
663 return ERROR_CALL_NOT_IMPLEMENTED;
666 r = msi_locate_product(szProduct, &context);
667 if (r != ERROR_SUCCESS)
670 r = msi_open_package(szProduct, context, &package);
671 if (r != ERROR_SUCCESS)
674 sz = lstrlenW(szInstalled) + 1;
677 sz += lstrlenW(szCommandLine);
679 if (eInstallState == INSTALLSTATE_ABSENT)
680 sz += lstrlenW(szRemoveAll);
682 if (context == MSIINSTALLCONTEXT_MACHINE)
683 sz += lstrlenW(szMachine);
685 commandline = msi_alloc(sz * sizeof(WCHAR));
688 r = ERROR_OUTOFMEMORY;
694 lstrcpyW(commandline,szCommandLine);
696 if (eInstallState == INSTALLSTATE_ABSENT)
697 lstrcatW(commandline, szRemoveAll);
699 if (context == MSIINSTALLCONTEXT_MACHINE)
700 lstrcatW(commandline, szMachine);
702 sz = sizeof(sourcepath);
703 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
704 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
706 sz = sizeof(filename);
707 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
708 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
710 strcatW(sourcepath, filename);
712 r = MSI_InstallPackage( package, sourcepath, commandline );
714 msi_free(commandline);
717 msiobj_release( &package->hdr );
722 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
723 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
725 LPWSTR szwProduct = NULL;
726 LPWSTR szwCommandLine = NULL;
727 UINT r = ERROR_OUTOFMEMORY;
731 szwProduct = strdupAtoW( szProduct );
738 szwCommandLine = strdupAtoW( szCommandLine );
743 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
746 msi_free( szwProduct );
747 msi_free( szwCommandLine);
752 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
753 INSTALLSTATE eInstallState)
755 LPWSTR szwProduct = NULL;
758 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
762 szwProduct = strdupAtoW( szProduct );
764 return ERROR_OUTOFMEMORY;
767 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
768 msi_free( szwProduct );
773 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
774 INSTALLSTATE eInstallState)
776 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
779 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
781 LPWSTR szwComponent = NULL;
783 WCHAR szwBuffer[GUID_SIZE];
785 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
789 szwComponent = strdupAtoW( szComponent );
791 return ERROR_OUTOFMEMORY;
795 r = MsiGetProductCodeW( szwComponent, szwBuffer );
798 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
800 msi_free( szwComponent );
805 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
808 HKEY compkey, prodkey;
809 WCHAR squished_comp[GUID_SIZE];
810 WCHAR squished_prod[GUID_SIZE];
811 DWORD sz = GUID_SIZE;
813 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
815 if (!szComponent || !*szComponent)
816 return ERROR_INVALID_PARAMETER;
818 if (!squash_guid(szComponent, squished_comp))
819 return ERROR_INVALID_PARAMETER;
821 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
822 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
824 return ERROR_UNKNOWN_COMPONENT;
827 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
828 if (rc != ERROR_SUCCESS)
830 RegCloseKey(compkey);
831 return ERROR_UNKNOWN_COMPONENT;
834 /* check simple case, only one product */
835 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
836 if (rc == ERROR_NO_MORE_ITEMS)
843 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
844 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
848 unsquash_guid(squished_prod, szBuffer);
850 if (MSIREG_OpenProductKey(szBuffer, NULL,
851 MSIINSTALLCONTEXT_USERMANAGED,
852 &prodkey, FALSE) == ERROR_SUCCESS ||
853 MSIREG_OpenProductKey(szBuffer, NULL,
854 MSIINSTALLCONTEXT_USERUNMANAGED,
855 &prodkey, FALSE) == ERROR_SUCCESS ||
856 MSIREG_OpenProductKey(szBuffer, NULL,
857 MSIINSTALLCONTEXT_MACHINE,
858 &prodkey, FALSE) == ERROR_SUCCESS)
860 RegCloseKey(prodkey);
866 rc = ERROR_INSTALL_FAILURE;
869 RegCloseKey(compkey);
870 unsquash_guid(squished_prod, szBuffer);
874 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
880 static const WCHAR format[] = {'%','d',0};
882 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
883 if (res != ERROR_SUCCESS)
887 return msi_reg_get_val_str(hkey, name);
889 if (!msi_reg_get_val_dword(hkey, name, &dval))
892 sprintfW(temp, format, dval);
893 return strdupW(temp);
896 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
897 awstring *szValue, LPDWORD pcchValueBuf)
899 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
900 UINT r = ERROR_UNKNOWN_PROPERTY;
901 HKEY prodkey, userdata, source;
903 WCHAR squished_pc[GUID_SIZE];
904 WCHAR packagecode[GUID_SIZE];
905 BOOL badconfig = FALSE;
907 DWORD save, type = REG_NONE;
909 static WCHAR empty[] = {0};
910 static const WCHAR sourcelist[] = {
911 'S','o','u','r','c','e','L','i','s','t',0};
912 static const WCHAR display_name[] = {
913 'D','i','s','p','l','a','y','N','a','m','e',0};
914 static const WCHAR display_version[] = {
915 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
916 static const WCHAR assignment[] = {
917 'A','s','s','i','g','n','m','e','n','t',0};
919 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
920 debugstr_w(szAttribute), szValue, pcchValueBuf);
922 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
923 return ERROR_INVALID_PARAMETER;
925 if (!squash_guid(szProduct, squished_pc))
926 return ERROR_INVALID_PARAMETER;
928 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
929 MSIINSTALLCONTEXT_USERMANAGED,
930 &prodkey, FALSE)) != ERROR_SUCCESS &&
931 (r = MSIREG_OpenProductKey(szProduct, NULL,
932 MSIINSTALLCONTEXT_USERUNMANAGED,
933 &prodkey, FALSE)) != ERROR_SUCCESS &&
934 (r = MSIREG_OpenProductKey(szProduct, NULL,
935 MSIINSTALLCONTEXT_MACHINE,
936 &prodkey, FALSE)) == ERROR_SUCCESS)
938 context = MSIINSTALLCONTEXT_MACHINE;
941 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
943 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
944 !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
945 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLDATEW) ||
946 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
947 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW) ||
948 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLSOURCEW) ||
949 !lstrcmpW(szAttribute, INSTALLPROPERTY_LOCALPACKAGEW) ||
950 !lstrcmpW(szAttribute, INSTALLPROPERTY_PUBLISHERW) ||
951 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLINFOABOUTW) ||
952 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLUPDATEINFOW) ||
953 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMINORW) ||
954 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMAJORW) ||
955 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW) ||
956 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTIDW) ||
957 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGCOMPANYW) ||
958 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGOWNERW))
962 r = ERROR_UNKNOWN_PRODUCT;
967 return ERROR_UNKNOWN_PROPERTY;
969 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
970 szAttribute = display_name;
971 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW))
972 szAttribute = display_version;
974 val = msi_reg_get_value(userdata, szAttribute, &type);
978 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTANCETYPEW) ||
979 !lstrcmpW(szAttribute, INSTALLPROPERTY_TRANSFORMSW) ||
980 !lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
981 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW) ||
982 !lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW) ||
983 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW) ||
984 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW) ||
985 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTICONW) ||
986 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW) ||
987 !lstrcmpW(szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
991 r = ERROR_UNKNOWN_PRODUCT;
995 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
996 szAttribute = assignment;
998 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW))
1000 res = RegOpenKeyW(prodkey, sourcelist, &source);
1001 if (res != ERROR_SUCCESS)
1003 r = ERROR_UNKNOWN_PRODUCT;
1007 val = msi_reg_get_value(source, szAttribute, &type);
1011 RegCloseKey(source);
1015 val = msi_reg_get_value(prodkey, szAttribute, &type);
1020 if (val != empty && type != REG_DWORD &&
1021 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
1023 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1027 unsquash_guid(val, packagecode);
1029 val = strdupW(packagecode);
1036 r = ERROR_UNKNOWN_PROPERTY;
1042 save = *pcchValueBuf;
1044 if (strlenW(val) < *pcchValueBuf)
1045 r = msi_strcpy_to_awstring(val, szValue, pcchValueBuf);
1046 else if (szValue->str.a || szValue->str.w)
1047 r = ERROR_MORE_DATA;
1050 *pcchValueBuf = lstrlenW(val);
1051 else if (r == ERROR_SUCCESS)
1053 *pcchValueBuf = save;
1054 r = ERROR_BAD_CONFIGURATION;
1058 r = ERROR_BAD_CONFIGURATION;
1064 RegCloseKey(prodkey);
1065 RegCloseKey(userdata);
1069 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1070 LPSTR szBuffer, LPDWORD pcchValueBuf)
1072 LPWSTR szwProduct, szwAttribute = NULL;
1073 UINT r = ERROR_OUTOFMEMORY;
1076 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1077 szBuffer, pcchValueBuf);
1079 szwProduct = strdupAtoW( szProduct );
1080 if( szProduct && !szwProduct )
1083 szwAttribute = strdupAtoW( szAttribute );
1084 if( szAttribute && !szwAttribute )
1087 buffer.unicode = FALSE;
1088 buffer.str.a = szBuffer;
1090 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1091 &buffer, pcchValueBuf );
1094 msi_free( szwProduct );
1095 msi_free( szwAttribute );
1100 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1101 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1105 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1106 szBuffer, pcchValueBuf);
1108 buffer.unicode = TRUE;
1109 buffer.str.w = szBuffer;
1111 return MSI_GetProductInfo( szProduct, szAttribute,
1112 &buffer, pcchValueBuf );
1115 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1116 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1117 LPSTR szValue, LPDWORD pcchValue)
1119 LPWSTR product = NULL;
1120 LPWSTR usersid = NULL;
1121 LPWSTR property = NULL;
1122 LPWSTR value = NULL;
1126 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1127 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1128 szValue, pcchValue);
1130 if (szValue && !pcchValue)
1131 return ERROR_INVALID_PARAMETER;
1133 if (szProductCode) product = strdupAtoW(szProductCode);
1134 if (szUserSid) usersid = strdupAtoW(szUserSid);
1135 if (szProperty) property = strdupAtoW(szProperty);
1137 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1139 if (r != ERROR_SUCCESS)
1142 value = msi_alloc(++len * sizeof(WCHAR));
1145 r = ERROR_OUTOFMEMORY;
1149 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1151 if (r != ERROR_SUCCESS)
1157 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1158 if (*pcchValue >= len)
1159 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1162 r = ERROR_MORE_DATA;
1167 if (*pcchValue <= len || !szValue)
1168 len = len * sizeof(WCHAR) - 1;
1170 *pcchValue = len - 1;
1181 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1186 return ERROR_UNKNOWN_PROPERTY;
1190 if (strlenW(val) >= *size)
1192 r = ERROR_MORE_DATA;
1201 *size = lstrlenW(val);
1203 return ERROR_SUCCESS;
1206 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1207 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1208 LPWSTR szValue, LPDWORD pcchValue)
1210 WCHAR squished_pc[GUID_SIZE];
1212 LPCWSTR package = NULL;
1213 HKEY props = NULL, prod;
1214 HKEY classes = NULL, managed;
1217 UINT r = ERROR_UNKNOWN_PRODUCT;
1219 static const WCHAR one[] = {'1',0};
1220 static const WCHAR five[] = {'5',0};
1221 static const WCHAR empty[] = {0};
1222 static const WCHAR displayname[] = {
1223 'D','i','s','p','l','a','y','N','a','m','e',0};
1224 static const WCHAR displayversion[] = {
1225 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1226 static const WCHAR managed_local_package[] = {
1227 'M','a','n','a','g','e','d','L','o','c','a','l',
1228 'P','a','c','k','a','g','e',0};
1230 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1231 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1232 szValue, pcchValue);
1234 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1235 return ERROR_INVALID_PARAMETER;
1237 if (szValue && !pcchValue)
1238 return ERROR_INVALID_PARAMETER;
1240 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1241 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1242 dwContext != MSIINSTALLCONTEXT_MACHINE)
1243 return ERROR_INVALID_PARAMETER;
1245 if (!szProperty || !*szProperty)
1246 return ERROR_INVALID_PARAMETER;
1248 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1249 return ERROR_INVALID_PARAMETER;
1251 /* FIXME: dwContext is provided, no need to search for it */
1252 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1254 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1257 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1259 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1261 package = INSTALLPROPERTY_LOCALPACKAGEW;
1263 if (!props && !prod)
1266 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1268 package = managed_local_package;
1270 if (!props && !managed)
1273 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1275 package = INSTALLPROPERTY_LOCALPACKAGEW;
1276 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1278 if (!props && !classes)
1282 if (!lstrcmpW(szProperty, INSTALLPROPERTY_HELPLINKW) ||
1283 !lstrcmpW(szProperty, INSTALLPROPERTY_HELPTELEPHONEW) ||
1284 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW) ||
1285 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
1286 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLLOCATIONW) ||
1287 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLSOURCEW) ||
1288 !lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW) ||
1289 !lstrcmpW(szProperty, INSTALLPROPERTY_PUBLISHERW) ||
1290 !lstrcmpW(szProperty, INSTALLPROPERTY_URLINFOABOUTW) ||
1291 !lstrcmpW(szProperty, INSTALLPROPERTY_URLUPDATEINFOW) ||
1292 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMINORW) ||
1293 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMAJORW) ||
1294 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW) ||
1295 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTIDW) ||
1296 !lstrcmpW(szProperty, INSTALLPROPERTY_REGCOMPANYW) ||
1297 !lstrcmpW(szProperty, INSTALLPROPERTY_REGOWNERW) ||
1298 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTANCETYPEW))
1300 val = msi_reg_get_value(props, package, &type);
1303 if (prod || classes)
1304 r = ERROR_UNKNOWN_PROPERTY;
1311 if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
1312 szProperty = displayname;
1313 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW))
1314 szProperty = displayversion;
1316 val = msi_reg_get_value(props, szProperty, &type);
1318 val = strdupW(empty);
1320 r = msi_copy_outval(val, szValue, pcchValue);
1322 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW) ||
1323 !lstrcmpW(szProperty, INSTALLPROPERTY_LANGUAGEW) ||
1324 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTNAMEW) ||
1325 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGECODEW) ||
1326 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONW) ||
1327 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTICONW) ||
1328 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGENAMEW) ||
1329 !lstrcmpW(szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1331 if (!prod && !classes)
1334 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1336 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1338 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1341 val = msi_reg_get_value(hkey, szProperty, &type);
1343 val = strdupW(empty);
1345 r = msi_copy_outval(val, szValue, pcchValue);
1347 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTSTATEW))
1349 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1353 val = msi_reg_get_value(props, package, &type);
1358 val = strdupW(five);
1363 r = msi_copy_outval(val, szValue, pcchValue);
1366 else if (props && (val = msi_reg_get_value(props, package, &type)))
1369 val = strdupW(five);
1370 r = msi_copy_outval(val, szValue, pcchValue);
1374 if (prod || managed)
1379 r = msi_copy_outval(val, szValue, pcchValue);
1381 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1383 if (!prod && !classes)
1387 val = strdupW(empty);
1388 r = msi_copy_outval(val, szValue, pcchValue);
1391 r = ERROR_UNKNOWN_PROPERTY;
1396 RegCloseKey(managed);
1397 RegCloseKey(classes);
1403 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1404 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1405 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1407 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1408 LPWSTR property = NULL, val = NULL;
1412 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1413 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1414 debugstr_a(szProperty), lpValue, pcchValue);
1416 if (lpValue && !pcchValue)
1417 return ERROR_INVALID_PARAMETER;
1419 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1420 if (szProductCode) product = strdupAtoW(szProductCode);
1421 if (szUserSid) usersid = strdupAtoW(szUserSid);
1422 if (szProperty) property = strdupAtoW(szProperty);
1425 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1427 if (r != ERROR_SUCCESS)
1430 val = msi_alloc(++len * sizeof(WCHAR));
1433 r = ERROR_OUTOFMEMORY;
1437 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1439 if (r != ERROR_SUCCESS || !pcchValue)
1443 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1444 *pcchValue - 1, NULL, NULL);
1446 len = lstrlenW(val);
1447 if ((*val && *pcchValue < len + 1) || !lpValue)
1451 r = ERROR_MORE_DATA;
1452 lpValue[*pcchValue - 1] = '\0';
1455 *pcchValue = len * sizeof(WCHAR);
1470 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1471 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1472 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1474 WCHAR squished_pc[GUID_SIZE];
1475 WCHAR squished_patch[GUID_SIZE];
1476 HKEY udprod = 0, prod = 0, props = 0;
1477 HKEY patch = 0, patches = 0;
1478 HKEY udpatch = 0, datakey = 0;
1479 HKEY prodpatches = 0;
1481 UINT r = ERROR_UNKNOWN_PRODUCT;
1485 static const WCHAR szEmpty[] = {0};
1486 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1487 static const WCHAR szInstalled[] = {'I','n','s','t','a','l','l','e','d',0};
1488 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1489 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1491 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1492 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1493 debugstr_w(szProperty), lpValue, pcchValue);
1495 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1496 return ERROR_INVALID_PARAMETER;
1498 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1499 return ERROR_INVALID_PARAMETER;
1502 return ERROR_INVALID_PARAMETER;
1504 if (lpValue && !pcchValue)
1505 return ERROR_INVALID_PARAMETER;
1507 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1508 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1509 dwContext != MSIINSTALLCONTEXT_MACHINE)
1510 return ERROR_INVALID_PARAMETER;
1512 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1513 return ERROR_INVALID_PARAMETER;
1515 if (!lstrcmpW(szUserSid, szLocalSid))
1516 return ERROR_INVALID_PARAMETER;
1518 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1519 &udprod, FALSE) != ERROR_SUCCESS)
1522 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1523 &props, FALSE) != ERROR_SUCCESS)
1526 r = ERROR_UNKNOWN_PATCH;
1528 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_READ, &patches);
1529 if (res != ERROR_SUCCESS)
1532 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_READ, &patch);
1533 if (res != ERROR_SUCCESS)
1536 if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW))
1538 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1539 &prod, FALSE) != ERROR_SUCCESS)
1542 res = RegOpenKeyExW(prod, szPatches, 0, KEY_ALL_ACCESS, &prodpatches);
1543 if (res != ERROR_SUCCESS)
1546 datakey = prodpatches;
1547 szProperty = squished_patch;
1551 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1552 &udpatch, FALSE) != ERROR_SUCCESS)
1555 if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1557 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1558 szProperty = szManagedPackage;
1561 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW))
1564 szProperty = szInstalled;
1566 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1570 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_UNINSTALLABLEW) ||
1571 !lstrcmpW(szProperty, INSTALLPROPERTY_PATCHSTATEW) ||
1572 !lstrcmpW(szProperty, INSTALLPROPERTY_DISPLAYNAMEW) ||
1573 !lstrcmpW(szProperty, INSTALLPROPERTY_MOREINFOURLW))
1579 r = ERROR_UNKNOWN_PROPERTY;
1584 val = msi_reg_get_val_str(datakey, szProperty);
1586 val = strdupW(szEmpty);
1594 lstrcpynW(lpValue, val, *pcchValue);
1596 len = lstrlenW(val);
1597 if ((*val && *pcchValue < len + 1) || !lpValue)
1600 r = ERROR_MORE_DATA;
1602 *pcchValue = len * sizeof(WCHAR);
1609 RegCloseKey(prodpatches);
1612 RegCloseKey(patches);
1613 RegCloseKey(udpatch);
1615 RegCloseKey(udprod);
1620 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1622 LPWSTR szwLogFile = NULL;
1625 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1629 szwLogFile = strdupAtoW( szLogFile );
1631 return ERROR_OUTOFMEMORY;
1633 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1634 msi_free( szwLogFile );
1638 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1640 HANDLE file = INVALID_HANDLE_VALUE;
1642 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1646 lstrcpyW(gszLogFile,szLogFile);
1647 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1648 DeleteFileW(szLogFile);
1649 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
1650 FILE_ATTRIBUTE_NORMAL, NULL);
1651 if (file != INVALID_HANDLE_VALUE)
1654 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
1657 gszLogFile[0] = '\0';
1659 return ERROR_SUCCESS;
1662 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
1663 DWORD dwIndex, INSTALLSTATE iState,
1664 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
1665 int *piCost, int *pTempCost)
1667 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
1668 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
1669 pcchDriveBuf, piCost, pTempCost);
1671 return ERROR_NO_MORE_ITEMS;
1674 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1675 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1676 LPCSTR szComponent, INSTALLSTATE *pdwState)
1678 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1681 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1682 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1684 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1685 return ERROR_OUTOFMEMORY;
1687 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1688 return ERROR_OUTOFMEMORY;
1690 if (szComponent && !(comp = strdupAtoW(szComponent)))
1691 return ERROR_OUTOFMEMORY;
1693 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1702 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1707 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1709 return (r == ERROR_SUCCESS);
1712 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1720 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1721 static const WCHAR managed_local_package[] = {
1722 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1725 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1726 if (r != ERROR_SUCCESS)
1729 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1730 package = managed_local_package;
1732 package = local_package;
1735 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1738 return (res == ERROR_SUCCESS);
1741 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1742 MSIINSTALLCONTEXT context,
1743 LPCWSTR comp, LPWSTR val, DWORD *sz)
1749 if (context == MSIINSTALLCONTEXT_MACHINE)
1750 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
1752 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
1754 if (r != ERROR_SUCCESS)
1757 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
1758 if (res != ERROR_SUCCESS)
1765 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
1766 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1767 LPCWSTR szComponent, INSTALLSTATE *pdwState)
1769 WCHAR squished_pc[GUID_SIZE];
1770 WCHAR val[MAX_PATH];
1774 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
1775 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
1777 if (!pdwState || !szComponent)
1778 return ERROR_INVALID_PARAMETER;
1780 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
1781 return ERROR_INVALID_PARAMETER;
1783 if (!squash_guid(szProductCode, squished_pc))
1784 return ERROR_INVALID_PARAMETER;
1786 found = msi_comp_find_prod_key(szProductCode, dwContext);
1788 if (!msi_comp_find_package(szProductCode, dwContext))
1792 *pdwState = INSTALLSTATE_UNKNOWN;
1793 return ERROR_UNKNOWN_COMPONENT;
1796 return ERROR_UNKNOWN_PRODUCT;
1799 *pdwState = INSTALLSTATE_UNKNOWN;
1802 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
1803 return ERROR_UNKNOWN_COMPONENT;
1806 *pdwState = INSTALLSTATE_NOTUSED;
1809 if (lstrlenW(val) > 2 &&
1810 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
1812 *pdwState = INSTALLSTATE_SOURCE;
1815 *pdwState = INSTALLSTATE_LOCAL;
1818 return ERROR_SUCCESS;
1821 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
1823 LPWSTR szwProduct = NULL;
1828 szwProduct = strdupAtoW( szProduct );
1830 return ERROR_OUTOFMEMORY;
1832 r = MsiQueryProductStateW( szwProduct );
1833 msi_free( szwProduct );
1837 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
1839 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1840 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
1841 HKEY prodkey = 0, userdata = 0;
1845 static const WCHAR szWindowsInstaller[] = {
1846 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1848 TRACE("%s\n", debugstr_w(szProduct));
1850 if (!szProduct || !*szProduct)
1851 return INSTALLSTATE_INVALIDARG;
1853 if (lstrlenW(szProduct) != GUID_SIZE - 1)
1854 return INSTALLSTATE_INVALIDARG;
1856 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1857 &prodkey, FALSE) != ERROR_SUCCESS &&
1858 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1859 &prodkey, FALSE) != ERROR_SUCCESS &&
1860 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
1861 &prodkey, FALSE) == ERROR_SUCCESS)
1863 context = MSIINSTALLCONTEXT_MACHINE;
1866 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
1867 if (r != ERROR_SUCCESS)
1870 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
1874 state = INSTALLSTATE_DEFAULT;
1876 state = INSTALLSTATE_UNKNOWN;
1881 state = INSTALLSTATE_UNKNOWN;
1884 state = INSTALLSTATE_ABSENT;
1887 RegCloseKey(prodkey);
1888 RegCloseKey(userdata);
1892 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
1894 INSTALLUILEVEL old = gUILevel;
1895 HWND oldwnd = gUIhwnd;
1897 TRACE("%08x %p\n", dwUILevel, phWnd);
1899 gUILevel = dwUILevel;
1908 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
1909 DWORD dwMessageFilter, LPVOID pvContext)
1911 INSTALLUI_HANDLERA prev = gUIHandlerA;
1913 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
1914 gUIHandlerA = puiHandler;
1915 gUIFilter = dwMessageFilter;
1916 gUIContext = pvContext;
1921 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
1922 DWORD dwMessageFilter, LPVOID pvContext)
1924 INSTALLUI_HANDLERW prev = gUIHandlerW;
1926 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
1927 gUIHandlerW = puiHandler;
1928 gUIFilter = dwMessageFilter;
1929 gUIContext = pvContext;
1934 /******************************************************************
1935 * MsiLoadStringW [MSI.@]
1937 * Loads a string from MSI's string resources.
1941 * handle [I] only -1 is handled currently
1942 * id [I] id of the string to be loaded
1943 * lpBuffer [O] buffer for the string to be written to
1944 * nBufferMax [I] maximum size of the buffer in characters
1945 * lang [I] the preferred language for the string
1949 * If successful, this function returns the language id of the string loaded
1950 * If the function fails, the function returns zero.
1954 * The type of the first parameter is unknown. LoadString's prototype
1955 * suggests that it might be a module handle. I have made it an MSI handle
1956 * for starters, as -1 is an invalid MSI handle, but not an invalid module
1957 * handle. Maybe strings can be stored in an MSI database somehow.
1959 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
1960 int nBufferMax, LANGID lang )
1967 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
1970 FIXME("don't know how to deal with handle = %08x\n", handle);
1973 lang = GetUserDefaultLangID();
1975 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
1979 hResData = LoadResource( msi_hInstance, hres );
1982 p = LockResource( hResData );
1986 for (i = 0; i < (id&0xf); i++)
1990 if( nBufferMax <= len )
1993 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
1994 lpBuffer[ len ] = 0;
1996 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2001 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2002 int nBufferMax, LANGID lang )
2008 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2009 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2012 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2013 if( len <= nBufferMax )
2014 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2015 lpBuffer, nBufferMax, NULL, NULL );
2023 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2026 char szProduct[GUID_SIZE];
2028 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2030 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2031 return INSTALLSTATE_UNKNOWN;
2033 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2036 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2039 WCHAR szProduct[GUID_SIZE];
2041 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2043 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2044 return INSTALLSTATE_UNKNOWN;
2046 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2049 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2050 WORD wLanguageId, DWORD f)
2052 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2053 uType, wLanguageId, f);
2054 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2057 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2058 WORD wLanguageId, DWORD f)
2060 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2061 uType, wLanguageId, f);
2062 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2065 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2066 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2067 LPDWORD pcchPathBuf )
2069 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2070 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2072 return ERROR_CALL_NOT_IMPLEMENTED;
2075 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2076 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2077 LPDWORD pcchPathBuf )
2079 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2080 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2082 return ERROR_CALL_NOT_IMPLEMENTED;
2085 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2086 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2088 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2089 return ERROR_CALL_NOT_IMPLEMENTED;
2092 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2093 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2095 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2096 return ERROR_CALL_NOT_IMPLEMENTED;
2099 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
2100 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2101 LPDWORD pcbHashData)
2103 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
2104 ppcCertContext, pbHashData, pcbHashData);
2105 return ERROR_CALL_NOT_IMPLEMENTED;
2108 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
2109 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2110 LPDWORD pcbHashData)
2112 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
2113 ppcCertContext, pbHashData, pcbHashData);
2114 return ERROR_CALL_NOT_IMPLEMENTED;
2117 /******************************************************************
2118 * MsiGetProductPropertyA [MSI.@]
2120 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2121 LPSTR szValue, LPDWORD pccbValue)
2123 LPWSTR prop = NULL, val = NULL;
2127 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2128 szValue, pccbValue);
2130 if (szValue && !pccbValue)
2131 return ERROR_INVALID_PARAMETER;
2133 if (szProperty) prop = strdupAtoW(szProperty);
2136 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2137 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2140 if (r == ERROR_SUCCESS)
2142 if (szValue) *szValue = '\0';
2143 if (pccbValue) *pccbValue = 0;
2147 val = msi_alloc(++len * sizeof(WCHAR));
2150 r = ERROR_OUTOFMEMORY;
2154 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2155 if (r != ERROR_SUCCESS)
2158 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2161 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2162 *pccbValue, NULL, NULL);
2166 if (len > *pccbValue)
2167 r = ERROR_MORE_DATA;
2169 *pccbValue = len - 1;
2179 /******************************************************************
2180 * MsiGetProductPropertyW [MSI.@]
2182 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2183 LPWSTR szValue, LPDWORD pccbValue)
2185 MSIPACKAGE *package;
2186 MSIQUERY *view = NULL;
2187 MSIRECORD *rec = NULL;
2191 static const WCHAR query[] = {
2192 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2193 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2194 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2196 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2197 szValue, pccbValue);
2200 return ERROR_INVALID_PARAMETER;
2202 if (szValue && !pccbValue)
2203 return ERROR_INVALID_PARAMETER;
2205 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2207 return ERROR_INVALID_HANDLE;
2209 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2210 if (r != ERROR_SUCCESS)
2213 r = MSI_ViewExecute(view, 0);
2214 if (r != ERROR_SUCCESS)
2217 r = MSI_ViewFetch(view, &rec);
2218 if (r != ERROR_SUCCESS)
2221 val = MSI_RecordGetString(rec, 2);
2225 if (lstrlenW(val) >= *pccbValue)
2227 lstrcpynW(szValue, val, *pccbValue);
2228 *pccbValue = lstrlenW(val);
2229 r = ERROR_MORE_DATA;
2233 lstrcpyW(szValue, val);
2234 *pccbValue = lstrlenW(val);
2241 MSI_ViewClose(view);
2242 msiobj_release(&view->hdr);
2243 if (rec) msiobj_release(&rec->hdr);
2248 if (szValue) *szValue = '\0';
2249 if (pccbValue) *pccbValue = 0;
2256 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2259 LPWSTR szPack = NULL;
2261 TRACE("%s\n", debugstr_a(szPackage) );
2265 szPack = strdupAtoW( szPackage );
2267 return ERROR_OUTOFMEMORY;
2270 r = MsiVerifyPackageW( szPack );
2277 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2282 TRACE("%s\n", debugstr_w(szPackage) );
2284 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2285 MsiCloseHandle( handle );
2290 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2291 awstring* lpPathBuf, LPDWORD pcchBuf)
2293 WCHAR squished_pc[GUID_SIZE];
2294 WCHAR squished_comp[GUID_SIZE];
2300 static const WCHAR wininstaller[] = {
2301 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2303 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2304 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2306 if (!szProduct || !szComponent)
2307 return INSTALLSTATE_INVALIDARG;
2309 if (lpPathBuf->str.w && !pcchBuf)
2310 return INSTALLSTATE_INVALIDARG;
2312 if (!squash_guid(szProduct, squished_pc) ||
2313 !squash_guid(szComponent, squished_comp))
2314 return INSTALLSTATE_INVALIDARG;
2316 state = INSTALLSTATE_UNKNOWN;
2318 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2319 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2321 path = msi_reg_get_val_str(hkey, squished_pc);
2324 state = INSTALLSTATE_ABSENT;
2326 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2327 &hkey, FALSE) == ERROR_SUCCESS ||
2328 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2329 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2330 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2331 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2334 state = INSTALLSTATE_LOCAL;
2338 if (state != INSTALLSTATE_LOCAL &&
2339 (MSIREG_OpenProductKey(szProduct, NULL,
2340 MSIINSTALLCONTEXT_USERUNMANAGED,
2341 &hkey, FALSE) == ERROR_SUCCESS ||
2342 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2343 &hkey, FALSE) == ERROR_SUCCESS))
2347 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2348 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2351 path = msi_reg_get_val_str(hkey, squished_pc);
2354 state = INSTALLSTATE_ABSENT;
2356 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2357 state = INSTALLSTATE_LOCAL;
2362 return INSTALLSTATE_UNKNOWN;
2364 if (state == INSTALLSTATE_LOCAL && !*path)
2365 state = INSTALLSTATE_NOTUSED;
2367 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2372 /******************************************************************
2373 * MsiGetComponentPathW [MSI.@]
2375 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2376 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2380 path.unicode = TRUE;
2381 path.str.w = lpPathBuf;
2383 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2386 /******************************************************************
2387 * MsiGetComponentPathA [MSI.@]
2389 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2390 LPSTR lpPathBuf, LPDWORD pcchBuf)
2392 LPWSTR szwProduct, szwComponent = NULL;
2393 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2396 szwProduct = strdupAtoW( szProduct );
2397 if( szProduct && !szwProduct)
2400 szwComponent = strdupAtoW( szComponent );
2401 if( szComponent && !szwComponent )
2404 path.unicode = FALSE;
2405 path.str.a = lpPathBuf;
2407 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2410 msi_free( szwProduct );
2411 msi_free( szwComponent );
2416 /******************************************************************
2417 * MsiQueryFeatureStateA [MSI.@]
2419 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2421 LPWSTR szwProduct = NULL, szwFeature= NULL;
2422 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2424 szwProduct = strdupAtoW( szProduct );
2425 if ( szProduct && !szwProduct )
2428 szwFeature = strdupAtoW( szFeature );
2429 if ( szFeature && !szwFeature )
2432 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2435 msi_free( szwProduct);
2436 msi_free( szwFeature);
2441 /******************************************************************
2442 * MsiQueryFeatureStateW [MSI.@]
2444 * Checks the state of a feature
2447 * szProduct [I] Product's GUID string
2448 * szFeature [I] Feature's GUID string
2451 * INSTALLSTATE_LOCAL Feature is installed and usable
2452 * INSTALLSTATE_ABSENT Feature is absent
2453 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2454 * INSTALLSTATE_UNKNOWN An error occurred
2455 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2458 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2460 WCHAR squishProduct[33], comp[GUID_SIZE];
2462 LPWSTR components, p, parent_feature, path;
2466 BOOL missing = FALSE;
2467 BOOL machine = FALSE;
2468 BOOL source = FALSE;
2470 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2472 if (!szProduct || !szFeature)
2473 return INSTALLSTATE_INVALIDARG;
2475 if (!squash_guid( szProduct, squishProduct ))
2476 return INSTALLSTATE_INVALIDARG;
2478 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2479 &hkey, FALSE) != ERROR_SUCCESS &&
2480 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2481 &hkey, FALSE) != ERROR_SUCCESS)
2483 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2485 if (rc != ERROR_SUCCESS)
2486 return INSTALLSTATE_UNKNOWN;
2491 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2494 if (!parent_feature)
2495 return INSTALLSTATE_UNKNOWN;
2497 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2498 msi_free(parent_feature);
2499 if (r == INSTALLSTATE_ABSENT)
2503 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2504 MSIINSTALLCONTEXT_MACHINE,
2507 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2508 MSIINSTALLCONTEXT_USERUNMANAGED,
2511 if (rc != ERROR_SUCCESS)
2512 return INSTALLSTATE_ADVERTISED;
2514 components = msi_reg_get_val_str( hkey, szFeature );
2517 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2520 return INSTALLSTATE_ADVERTISED;
2522 for( p = components; *p && *p != 2 ; p += 20)
2524 if (!decode_base85_guid( p, &guid ))
2526 if (p != components)
2529 msi_free(components);
2530 return INSTALLSTATE_BADCONFIG;
2533 StringFromGUID2(&guid, comp, GUID_SIZE);
2536 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2538 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2540 if (rc != ERROR_SUCCESS)
2542 msi_free(components);
2543 return INSTALLSTATE_ADVERTISED;
2546 path = msi_reg_get_val_str(hkey, squishProduct);
2549 else if (lstrlenW(path) > 2 &&
2550 path[0] >= '0' && path[0] <= '9' &&
2551 path[1] >= '0' && path[1] <= '9')
2559 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
2560 msi_free(components);
2563 return INSTALLSTATE_ADVERTISED;
2566 return INSTALLSTATE_SOURCE;
2568 return INSTALLSTATE_LOCAL;
2571 /******************************************************************
2572 * MsiGetFileVersionA [MSI.@]
2574 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2575 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2577 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2578 UINT ret = ERROR_OUTOFMEMORY;
2580 if ((lpVersionBuf && !pcchVersionBuf) ||
2581 (lpLangBuf && !pcchLangBuf))
2582 return ERROR_INVALID_PARAMETER;
2586 szwFilePath = strdupAtoW( szFilePath );
2591 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2593 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2594 if( !lpwVersionBuff )
2598 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2600 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2605 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2606 lpwLangBuff, pcchLangBuf);
2608 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2609 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2610 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2611 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2612 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2613 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2616 msi_free(szwFilePath);
2617 msi_free(lpwVersionBuff);
2618 msi_free(lpwLangBuff);
2623 /******************************************************************
2624 * MsiGetFileVersionW [MSI.@]
2626 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2627 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2629 static const WCHAR szVersionResource[] = {'\\',0};
2630 static const WCHAR szVersionFormat[] = {
2631 '%','d','.','%','d','.','%','d','.','%','d',0};
2632 static const WCHAR szLangResource[] = {
2633 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2634 'T','r','a','n','s','l','a','t','i','o','n',0};
2635 static const WCHAR szLangFormat[] = {'%','d',0};
2637 DWORD dwVerLen, gle;
2638 LPVOID lpVer = NULL;
2639 VS_FIXEDFILEINFO *ffi;
2644 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2645 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2646 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2648 if ((lpVersionBuf && !pcchVersionBuf) ||
2649 (lpLangBuf && !pcchLangBuf))
2650 return ERROR_INVALID_PARAMETER;
2652 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
2655 gle = GetLastError();
2656 if (gle == ERROR_BAD_PATHNAME)
2657 return ERROR_FILE_NOT_FOUND;
2658 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
2659 return ERROR_FILE_INVALID;
2664 lpVer = msi_alloc(dwVerLen);
2667 ret = ERROR_OUTOFMEMORY;
2671 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
2673 ret = GetLastError();
2679 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
2682 wsprintfW(tmp, szVersionFormat,
2683 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
2684 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
2685 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
2687 if (strlenW(tmp) >= *pcchVersionBuf)
2688 ret = ERROR_MORE_DATA;
2690 *pcchVersionBuf = lstrlenW(tmp);
2694 if (lpVersionBuf) *lpVersionBuf = 0;
2695 *pcchVersionBuf = 0;
2701 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
2704 wsprintfW(tmp, szLangFormat, *lang);
2705 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
2707 if (strlenW(tmp) >= *pcchLangBuf)
2708 ret = ERROR_MORE_DATA;
2710 *pcchLangBuf = lstrlenW(tmp);
2714 if (lpLangBuf) *lpLangBuf = 0;
2724 /***********************************************************************
2725 * MsiGetFeatureUsageW [MSI.@]
2727 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
2728 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2730 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
2731 pdwUseCount, pwDateUsed);
2732 return ERROR_CALL_NOT_IMPLEMENTED;
2735 /***********************************************************************
2736 * MsiGetFeatureUsageA [MSI.@]
2738 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
2739 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2741 LPWSTR prod = NULL, feat = NULL;
2742 UINT ret = ERROR_OUTOFMEMORY;
2744 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
2745 pdwUseCount, pwDateUsed);
2747 prod = strdupAtoW( szProduct );
2748 if (szProduct && !prod)
2751 feat = strdupAtoW( szFeature );
2752 if (szFeature && !feat)
2755 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
2764 /***********************************************************************
2765 * MsiUseFeatureExW [MSI.@]
2767 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
2768 DWORD dwInstallMode, DWORD dwReserved )
2772 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2773 dwInstallMode, dwReserved);
2775 state = MsiQueryFeatureStateW( szProduct, szFeature );
2778 return INSTALLSTATE_INVALIDARG;
2780 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
2782 FIXME("mark product %s feature %s as used\n",
2783 debugstr_w(szProduct), debugstr_w(szFeature) );
2789 /***********************************************************************
2790 * MsiUseFeatureExA [MSI.@]
2792 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
2793 DWORD dwInstallMode, DWORD dwReserved )
2795 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
2796 LPWSTR prod = NULL, feat = NULL;
2798 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2799 dwInstallMode, dwReserved);
2801 prod = strdupAtoW( szProduct );
2802 if (szProduct && !prod)
2805 feat = strdupAtoW( szFeature );
2806 if (szFeature && !feat)
2809 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
2818 /***********************************************************************
2819 * MsiUseFeatureW [MSI.@]
2821 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
2823 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
2826 /***********************************************************************
2827 * MsiUseFeatureA [MSI.@]
2829 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
2831 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
2834 /***********************************************************************
2835 * MSI_ProvideQualifiedComponentEx [internal]
2837 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
2838 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2839 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
2840 LPDWORD pcchPathBuf)
2842 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
2843 feature[MAX_FEATURE_CHARS+1];
2849 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
2850 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
2851 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2853 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
2854 if (rc != ERROR_SUCCESS)
2855 return ERROR_INDEX_ABSENT;
2857 info = msi_reg_get_val_str( hkey, szQualifier );
2861 return ERROR_INDEX_ABSENT;
2863 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
2866 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
2868 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
2872 if (rc != INSTALLSTATE_LOCAL)
2873 return ERROR_FILE_NOT_FOUND;
2875 return ERROR_SUCCESS;
2878 /***********************************************************************
2879 * MsiProvideQualifiedComponentExW [MSI.@]
2881 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
2882 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2883 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
2884 LPDWORD pcchPathBuf)
2888 path.unicode = TRUE;
2889 path.str.w = lpPathBuf;
2891 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
2892 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
2895 /***********************************************************************
2896 * MsiProvideQualifiedComponentExA [MSI.@]
2898 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
2899 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
2900 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
2901 LPDWORD pcchPathBuf)
2903 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
2904 UINT r = ERROR_OUTOFMEMORY;
2907 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
2908 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
2909 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2911 szwComponent = strdupAtoW( szComponent );
2912 if (szComponent && !szwComponent)
2915 szwQualifier = strdupAtoW( szQualifier );
2916 if (szQualifier && !szwQualifier)
2919 szwProduct = strdupAtoW( szProduct );
2920 if (szProduct && !szwProduct)
2923 path.unicode = FALSE;
2924 path.str.a = lpPathBuf;
2926 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
2927 dwInstallMode, szwProduct, Unused1,
2928 Unused2, &path, pcchPathBuf);
2930 msi_free(szwProduct);
2931 msi_free(szwComponent);
2932 msi_free(szwQualifier);
2937 /***********************************************************************
2938 * MsiProvideQualifiedComponentW [MSI.@]
2940 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
2941 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
2942 LPDWORD pcchPathBuf)
2944 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
2945 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
2948 /***********************************************************************
2949 * MsiProvideQualifiedComponentA [MSI.@]
2951 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
2952 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
2953 LPDWORD pcchPathBuf)
2955 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
2956 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
2959 /***********************************************************************
2960 * MSI_GetUserInfo [internal]
2962 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
2963 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
2964 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2965 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
2967 WCHAR squished_pc[SQUISH_GUID_SIZE];
2968 LPWSTR user, org, serial;
2969 USERINFOSTATE state;
2974 static const WCHAR szEmpty[] = {0};
2976 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
2977 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
2980 if (!szProduct || !squash_guid(szProduct, squished_pc))
2981 return USERINFOSTATE_INVALIDARG;
2983 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2984 &hkey, FALSE) != ERROR_SUCCESS &&
2985 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2986 &hkey, FALSE) != ERROR_SUCCESS &&
2987 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2988 &hkey, FALSE) != ERROR_SUCCESS)
2990 return USERINFOSTATE_UNKNOWN;
2993 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2994 NULL, &props, FALSE) != ERROR_SUCCESS &&
2995 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
2996 NULL, &props, FALSE) != ERROR_SUCCESS)
2999 return USERINFOSTATE_ABSENT;
3002 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3003 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3004 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3005 state = USERINFOSTATE_ABSENT;
3011 state = USERINFOSTATE_PRESENT;
3013 if (pcchUserNameBuf)
3015 if (lpUserNameBuf && !user)
3017 (*pcchUserNameBuf)--;
3021 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3022 if (r == ERROR_MORE_DATA)
3024 state = USERINFOSTATE_MOREDATA;
3032 if (!orgptr) orgptr = szEmpty;
3034 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3035 if (r == ERROR_MORE_DATA)
3037 state = USERINFOSTATE_MOREDATA;
3050 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3051 if (r == ERROR_MORE_DATA)
3052 state = USERINFOSTATE_MOREDATA;
3063 /***********************************************************************
3064 * MsiGetUserInfoW [MSI.@]
3066 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3067 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3068 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3069 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3071 awstring user, org, serial;
3073 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3074 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3075 (lpSerialBuf && !pcchSerialBuf))
3076 return USERINFOSTATE_INVALIDARG;
3078 user.unicode = TRUE;
3079 user.str.w = lpUserNameBuf;
3081 org.str.w = lpOrgNameBuf;
3082 serial.unicode = TRUE;
3083 serial.str.w = lpSerialBuf;
3085 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3086 &org, pcchOrgNameBuf,
3087 &serial, pcchSerialBuf );
3090 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3091 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3092 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3093 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3095 awstring user, org, serial;
3099 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3100 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3101 (lpSerialBuf && !pcchSerialBuf))
3102 return USERINFOSTATE_INVALIDARG;
3104 prod = strdupAtoW( szProduct );
3105 if (szProduct && !prod)
3106 return ERROR_OUTOFMEMORY;
3108 user.unicode = FALSE;
3109 user.str.a = lpUserNameBuf;
3110 org.unicode = FALSE;
3111 org.str.a = lpOrgNameBuf;
3112 serial.unicode = FALSE;
3113 serial.str.a = lpSerialBuf;
3115 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3116 &org, pcchOrgNameBuf,
3117 &serial, pcchSerialBuf );
3124 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3128 MSIPACKAGE *package;
3129 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3131 TRACE("(%s)\n",debugstr_w(szProduct));
3133 rc = MsiOpenProductW(szProduct,&handle);
3134 if (rc != ERROR_SUCCESS)
3135 return ERROR_INVALID_PARAMETER;
3137 /* MsiCollectUserInfo cannot be called from a custom action. */
3138 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3140 return ERROR_CALL_NOT_IMPLEMENTED;
3142 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3143 msiobj_release( &package->hdr );
3145 MsiCloseHandle(handle);
3150 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3154 MSIPACKAGE *package;
3155 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3157 TRACE("(%s)\n",debugstr_a(szProduct));
3159 rc = MsiOpenProductA(szProduct,&handle);
3160 if (rc != ERROR_SUCCESS)
3161 return ERROR_INVALID_PARAMETER;
3163 /* MsiCollectUserInfo cannot be called from a custom action. */
3164 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3166 return ERROR_CALL_NOT_IMPLEMENTED;
3168 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3169 msiobj_release( &package->hdr );
3171 MsiCloseHandle(handle);
3176 /***********************************************************************
3177 * MsiConfigureFeatureA [MSI.@]
3179 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3181 LPWSTR prod, feat = NULL;
3182 UINT r = ERROR_OUTOFMEMORY;
3184 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3186 prod = strdupAtoW( szProduct );
3187 if (szProduct && !prod)
3190 feat = strdupAtoW( szFeature );
3191 if (szFeature && !feat)
3194 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3203 /***********************************************************************
3204 * MsiConfigureFeatureW [MSI.@]
3206 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3208 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3209 MSIPACKAGE *package = NULL;
3211 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3214 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3216 if (!szProduct || !szFeature)
3217 return ERROR_INVALID_PARAMETER;
3219 switch (eInstallState)
3221 case INSTALLSTATE_DEFAULT:
3222 /* FIXME: how do we figure out the default location? */
3223 eInstallState = INSTALLSTATE_LOCAL;
3225 case INSTALLSTATE_LOCAL:
3226 case INSTALLSTATE_SOURCE:
3227 case INSTALLSTATE_ABSENT:
3228 case INSTALLSTATE_ADVERTISED:
3231 return ERROR_INVALID_PARAMETER;
3234 r = MSI_OpenProductW( szProduct, &package );
3235 if (r != ERROR_SUCCESS)
3238 sz = sizeof(sourcepath);
3239 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3240 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3242 sz = sizeof(filename);
3243 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3244 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3246 lstrcatW( sourcepath, filename );
3248 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3250 r = ACTION_PerformUIAction( package, szCostInit, -1 );
3251 if (r != ERROR_SUCCESS)
3254 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3255 if (r != ERROR_SUCCESS)
3258 r = MSI_InstallPackage( package, sourcepath, NULL );
3261 msiobj_release( &package->hdr );
3266 /***********************************************************************
3267 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3269 * Notes: undocumented
3271 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3273 WCHAR path[MAX_PATH];
3275 TRACE("%d\n", dwReserved);
3279 FIXME("dwReserved=%d\n", dwReserved);
3280 return ERROR_INVALID_PARAMETER;
3283 if (!GetWindowsDirectoryW(path, MAX_PATH))
3284 return ERROR_FUNCTION_FAILED;
3286 lstrcatW(path, installerW);
3288 if (!CreateDirectoryW(path, NULL))
3289 return ERROR_FUNCTION_FAILED;
3291 return ERROR_SUCCESS;
3294 /***********************************************************************
3295 * MsiGetShortcutTargetA [MSI.@]
3297 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3298 LPSTR szProductCode, LPSTR szFeatureId,
3299 LPSTR szComponentCode )
3302 const int len = MAX_FEATURE_CHARS+1;
3303 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3306 target = strdupAtoW( szShortcutTarget );
3307 if (szShortcutTarget && !target )
3308 return ERROR_OUTOFMEMORY;
3312 r = MsiGetShortcutTargetW( target, product, feature, component );
3314 if (r == ERROR_SUCCESS)
3316 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3317 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3318 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3323 /***********************************************************************
3324 * MsiGetShortcutTargetW [MSI.@]
3326 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3327 LPWSTR szProductCode, LPWSTR szFeatureId,
3328 LPWSTR szComponentCode )
3330 IShellLinkDataList *dl = NULL;
3331 IPersistFile *pf = NULL;
3332 LPEXP_DARWIN_LINK darwin = NULL;
3335 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3336 szProductCode, szFeatureId, szComponentCode );
3338 init = CoInitialize(NULL);
3340 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3341 &IID_IPersistFile, (LPVOID*) &pf );
3342 if( SUCCEEDED( r ) )
3344 r = IPersistFile_Load( pf, szShortcutTarget,
3345 STGM_READ | STGM_SHARE_DENY_WRITE );
3346 if( SUCCEEDED( r ) )
3348 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3350 if( SUCCEEDED( r ) )
3352 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3354 IShellLinkDataList_Release( dl );
3357 IPersistFile_Release( pf );
3360 if (SUCCEEDED(init))
3363 TRACE("darwin = %p\n", darwin);
3370 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3371 szProductCode, szFeatureId, szComponentCode, &sz );
3372 LocalFree( darwin );
3376 return ERROR_FUNCTION_FAILED;
3379 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3380 DWORD dwReinstallMode )
3382 MSIPACKAGE* package = NULL;
3384 WCHAR sourcepath[MAX_PATH];
3385 WCHAR filename[MAX_PATH];
3386 static const WCHAR szLogVerbose[] = {
3387 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3388 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
3389 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
3390 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
3391 static const WCHAR szOne[] = {'1',0};
3392 WCHAR reinstallmode[11];
3396 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3399 ptr = reinstallmode;
3401 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3403 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3405 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3407 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3409 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3411 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3413 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3415 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3417 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3419 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3423 sz = sizeof(sourcepath);
3424 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3425 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3427 sz = sizeof(filename);
3428 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3429 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3431 lstrcatW( sourcepath, filename );
3433 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3434 r = MSI_OpenPackageW( sourcepath, &package );
3436 r = MSI_OpenProductW( szProduct, &package );
3438 if (r != ERROR_SUCCESS)
3441 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
3442 MSI_SetPropertyW( package, szInstalled, szOne );
3443 MSI_SetPropertyW( package, szLogVerbose, szOne );
3444 MSI_SetPropertyW( package, szReinstall, szFeature );
3446 r = MSI_InstallPackage( package, sourcepath, NULL );
3448 msiobj_release( &package->hdr );
3453 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3454 DWORD dwReinstallMode )
3460 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3463 wszProduct = strdupAtoW(szProduct);
3464 wszFeature = strdupAtoW(szFeature);
3466 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3468 msi_free(wszProduct);
3469 msi_free(wszFeature);
3476 unsigned int buf[4];
3477 unsigned char in[64];
3478 unsigned char digest[16];
3481 extern VOID WINAPI MD5Init( MD5_CTX *);
3482 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3483 extern VOID WINAPI MD5Final( MD5_CTX *);
3485 /***********************************************************************
3486 * MsiGetFileHashW [MSI.@]
3488 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3489 PMSIFILEHASHINFO pHash )
3491 HANDLE handle, mapping;
3494 UINT r = ERROR_FUNCTION_FAILED;
3496 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3499 return ERROR_INVALID_PARAMETER;
3502 return ERROR_PATH_NOT_FOUND;
3505 return ERROR_INVALID_PARAMETER;
3507 return ERROR_INVALID_PARAMETER;
3508 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3509 return ERROR_INVALID_PARAMETER;
3511 handle = CreateFileW( szFilePath, GENERIC_READ,
3512 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3513 if (handle == INVALID_HANDLE_VALUE)
3514 return ERROR_FILE_NOT_FOUND;
3516 length = GetFileSize( handle, NULL );
3518 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3521 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3527 MD5Update( &ctx, p, length );
3529 UnmapViewOfFile( p );
3531 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3534 CloseHandle( mapping );
3536 CloseHandle( handle );
3541 /***********************************************************************
3542 * MsiGetFileHashA [MSI.@]
3544 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3545 PMSIFILEHASHINFO pHash )
3550 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3552 file = strdupAtoW( szFilePath );
3553 if (szFilePath && !file)
3554 return ERROR_OUTOFMEMORY;
3556 r = MsiGetFileHashW( file, dwOptions, pHash );
3561 /***********************************************************************
3562 * MsiAdvertiseScriptW [MSI.@]
3564 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3565 PHKEY phRegData, BOOL fRemoveItems )
3567 FIXME("%s %08x %p %d\n",
3568 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3569 return ERROR_CALL_NOT_IMPLEMENTED;
3572 /***********************************************************************
3573 * MsiAdvertiseScriptA [MSI.@]
3575 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3576 PHKEY phRegData, BOOL fRemoveItems )
3578 FIXME("%s %08x %p %d\n",
3579 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3580 return ERROR_CALL_NOT_IMPLEMENTED;
3583 /***********************************************************************
3584 * MsiIsProductElevatedW [MSI.@]
3586 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3588 FIXME("%s %p - stub\n",
3589 debugstr_w( szProduct ), pfElevated );
3591 return ERROR_SUCCESS;
3594 /***********************************************************************
3595 * MsiIsProductElevatedA [MSI.@]
3597 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3599 FIXME("%s %p - stub\n",
3600 debugstr_a( szProduct ), pfElevated );
3602 return ERROR_SUCCESS;
3605 /***********************************************************************
3606 * MsiSetExternalUIRecord [MSI.@]
3608 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD puiHandler,
3609 DWORD dwMessageFilter, LPVOID pvContext,
3610 PINSTALLUI_HANDLER_RECORD ppuiPrevHandler)
3612 FIXME("%p %08x %p %p\n", puiHandler, dwMessageFilter ,pvContext,
3614 return ERROR_CALL_NOT_IMPLEMENTED;
3617 /***********************************************************************
3618 * MsiInstallMissingComponentW [MSI.@]
3620 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
3622 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
3623 return ERROR_SUCCESS;