pop 7b3ecd624d768eecb2eda237f54815110f480faa
[wine/hacks.git] / dlls / msi / msi.c
blob646963d1fe930d8ea88f2443ef75a6a0fa5d2cd3
1 /*
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
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "wine/debug.h"
32 #include "msi.h"
33 #include "msidefs.h"
34 #include "msiquery.h"
35 #include "msipriv.h"
36 #include "wincrypt.h"
37 #include "winver.h"
38 #include "winuser.h"
39 #include "shlobj.h"
40 #include "shobjidl.h"
41 #include "objidl.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)
50 HKEY hkey = NULL;
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;
65 RegCloseKey(hkey);
67 if (*context == MSIINSTALLCONTEXT_NONE)
68 return ERROR_UNKNOWN_PRODUCT;
70 return ERROR_SUCCESS;
73 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
75 UINT r;
76 LPWSTR szwProd = NULL;
78 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
80 if( szProduct )
82 szwProd = strdupAtoW( szProduct );
83 if( !szwProd )
84 return ERROR_OUTOFMEMORY;
87 r = MsiOpenProductW( szwProd, phProduct );
89 msi_free( szwProd );
91 return r;
94 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
96 UINT r;
97 HKEY props;
98 LPWSTR path;
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)
109 return r;
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);
117 else
118 path = msi_reg_get_val_str(props, local);
120 r = ERROR_UNKNOWN_PRODUCT;
122 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
123 goto done;
125 if (PathIsRelativeW(path))
127 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
128 goto done;
131 r = MSI_OpenPackageW(path, package);
133 done:
134 RegCloseKey(props);
135 msi_free(path);
136 return r;
139 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
141 MSIPACKAGE *package = NULL;
142 WCHAR squished_pc[GUID_SIZE];
143 UINT r;
145 if (!szProduct || !squash_guid(szProduct, squished_pc))
146 return ERROR_INVALID_PARAMETER;
148 if (!phProduct)
149 return ERROR_INVALID_PARAMETER;
151 r = MSI_OpenProductW(szProduct, &package);
152 if (r != ERROR_SUCCESS)
153 return r;
155 *phProduct = alloc_msihandle(&package->hdr);
156 if (!*phProduct)
157 r = ERROR_NOT_ENOUGH_MEMORY;
159 msiobj_release(&package->hdr);
160 return r;
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));
204 if( szPackagePath )
206 szwPath = strdupAtoW( szPackagePath );
207 if( !szwPath )
208 goto end;
211 if( szCommandLine )
213 szwCommand = strdupAtoW( szCommandLine );
214 if( !szwCommand )
215 goto end;
218 r = MsiInstallProductW( szwPath, szwCommand );
220 end:
221 msi_free( szwPath );
222 msi_free( szwCommand );
224 return r;
227 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
229 MSIPACKAGE *package = NULL;
230 UINT r;
232 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
234 if (!szPackagePath)
235 return ERROR_INVALID_PARAMETER;
237 if (!*szPackagePath)
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 );
247 return r;
250 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
252 LPWSTR wszProduct;
253 UINT rc;
255 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
257 wszProduct = strdupAtoW(szProduct);
259 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
261 msi_free(wszProduct);
262 return rc;
265 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
267 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
269 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
272 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
273 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
275 LPWSTR patch_package = NULL;
276 LPWSTR install_package = NULL;
277 LPWSTR command_line = NULL;
278 UINT r = ERROR_OUTOFMEMORY;
280 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
281 eInstallType, debugstr_a(szCommandLine));
283 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
284 goto done;
286 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
287 goto done;
289 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
290 goto done;
292 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
294 done:
295 msi_free(patch_package);
296 msi_free(install_package);
297 msi_free(command_line);
299 return r;
302 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
304 MSIHANDLE patch = 0, info = 0;
305 UINT r = ERROR_SUCCESS, type;
306 DWORD size = 0;
307 LPCWSTR cmd_ptr = szCommandLine;
308 LPWSTR beg, end, cmd = NULL, codes = NULL;
309 BOOL succeeded = FALSE;
311 static const WCHAR patcheq[] = {'P','A','T','C','H','=',0};
312 static WCHAR empty[] = {0};
314 if (!szPatchPackage || !szPatchPackage[0])
315 return ERROR_INVALID_PARAMETER;
317 if (!szProductCode)
319 r = MsiOpenDatabaseW(szPatchPackage, MSIDBOPEN_READONLY, &patch);
320 if (r != ERROR_SUCCESS)
321 return r;
323 r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
324 if (r != ERROR_SUCCESS)
325 goto done;
327 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, empty, &size);
328 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
330 ERR("Failed to read product codes from patch\n");
331 goto done;
334 codes = msi_alloc(++size * sizeof(WCHAR));
335 if (!codes)
337 r = ERROR_OUTOFMEMORY;
338 goto done;
341 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
342 if (r != ERROR_SUCCESS)
343 goto done;
346 if (!szCommandLine)
347 cmd_ptr = empty;
349 size = lstrlenW(cmd_ptr) + lstrlenW(patcheq) + lstrlenW(szPatchPackage) + 1;
350 cmd = msi_alloc(size * sizeof(WCHAR));
351 if (!cmd)
353 r = ERROR_OUTOFMEMORY;
354 goto done;
357 lstrcpyW(cmd, cmd_ptr);
358 if (szCommandLine) lstrcatW(cmd, szSpace);
359 lstrcatW(cmd, patcheq);
360 lstrcatW(cmd, szPatchPackage);
362 if (szProductCode)
363 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
364 else
366 beg = codes;
367 while ((end = strchrW(beg, '}')))
369 *(end + 1) = '\0';
370 r = MsiConfigureProductExW(beg, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
371 if (r == ERROR_SUCCESS)
373 TRACE("patch applied\n");
374 succeeded = TRUE;
376 beg = end + 2;
379 if (succeeded)
380 r = ERROR_SUCCESS;
383 done:
384 msi_free(cmd);
385 msi_free(codes);
387 MsiCloseHandle(info);
388 MsiCloseHandle(patch);
390 return r;
393 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
394 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
396 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
397 eInstallType, debugstr_w(szCommandLine));
399 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
400 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
402 FIXME("Only reading target products from patch\n");
403 return ERROR_CALL_NOT_IMPLEMENTED;
406 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
409 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
410 LPCSTR szProductCode, LPCSTR szPropertiesList)
412 LPWSTR patch_packages = NULL;
413 LPWSTR product_code = NULL;
414 LPWSTR properties_list = NULL;
415 UINT r = ERROR_OUTOFMEMORY;
417 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
418 debugstr_a(szPropertiesList));
420 if (!szPatchPackages || !szPatchPackages[0])
421 return ERROR_INVALID_PARAMETER;
423 if (!(patch_packages = strdupAtoW(szPatchPackages)))
424 return ERROR_OUTOFMEMORY;
426 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
427 goto done;
429 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
430 goto done;
432 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
434 done:
435 msi_free(patch_packages);
436 msi_free(product_code);
437 msi_free(properties_list);
439 return r;
442 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
443 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
445 UINT r = ERROR_SUCCESS;
446 LPCWSTR beg, end;
448 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
449 debugstr_w(szPropertiesList));
451 if (!szPatchPackages || !szPatchPackages[0])
452 return ERROR_INVALID_PARAMETER;
454 beg = end = szPatchPackages;
455 while (*beg)
457 DWORD len;
458 LPWSTR patch;
460 while (*beg == ' ') beg++;
461 while (*end && *end != ';') end++;
463 len = end - beg;
464 while (len && beg[len - 1] == ' ') len--;
466 if (!len) return ERROR_INVALID_NAME;
468 patch = msi_alloc((len + 1) * sizeof(WCHAR));
469 if (!patch)
470 return ERROR_OUTOFMEMORY;
472 memcpy(patch, beg, len * sizeof(WCHAR));
473 patch[len] = '\0';
475 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
476 msi_free(patch);
478 if (r != ERROR_SUCCESS)
479 break;
481 beg = ++end;
483 return r;
486 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
487 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
489 UINT i, r;
490 WCHAR *package_path = NULL;
491 MSIPATCHSEQUENCEINFOW *psi;
493 TRACE("(%s, %d, %p)\n", debugstr_a(szProductPackagePath), cPatchInfo, pPatchInfo);
495 if (szProductPackagePath && !(package_path = strdupAtoW( szProductPackagePath )))
496 return ERROR_OUTOFMEMORY;
498 psi = msi_alloc( cPatchInfo * sizeof(*psi) );
499 if (!psi)
501 msi_free( package_path );
502 return ERROR_OUTOFMEMORY;
505 for (i = 0; i < cPatchInfo; i++)
507 psi[i].szPatchData = strdupAtoW( pPatchInfo[i].szPatchData );
508 psi[i].ePatchDataType = pPatchInfo[i].ePatchDataType;
511 r = MsiDetermineApplicablePatchesW( package_path, cPatchInfo, psi );
512 if (r == ERROR_SUCCESS)
514 for (i = 0; i < cPatchInfo; i++)
516 pPatchInfo[i].dwOrder = psi[i].dwOrder;
517 pPatchInfo[i].uStatus = psi[i].uStatus;
521 msi_free( package_path );
522 for (i = 0; i < cPatchInfo; i++)
523 msi_free( (WCHAR *)psi[i].szPatchData );
524 msi_free( psi );
525 return r;
528 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
530 MSISUMMARYINFO *si;
531 MSIDATABASE *patch_db;
532 UINT r = ERROR_SUCCESS;
534 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
535 if (r != ERROR_SUCCESS)
537 WARN("failed to open patch file %s\n", debugstr_w(patch));
538 return r;
541 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
542 if (!si)
544 r = ERROR_FUNCTION_FAILED;
545 goto done;
548 r = msi_check_patch_applicable( package, si );
549 if (r != ERROR_SUCCESS)
550 TRACE("patch not applicable\n");
552 done:
553 msiobj_release( &patch_db->hdr );
554 msiobj_release( &si->hdr );
555 return r;
558 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
559 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
561 UINT i, r, ret = ERROR_FUNCTION_FAILED;
562 MSIPACKAGE *package;
564 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
566 r = MSI_OpenPackageW( szProductPackagePath, &package );
567 if (r != ERROR_SUCCESS)
569 ERR("failed to open package %u\n", r);
570 return r;
573 for (i = 0; i < cPatchInfo; i++)
575 switch (pPatchInfo[i].ePatchDataType)
577 case MSIPATCH_DATATYPE_PATCHFILE:
579 FIXME("patch ordering not supported\n");
580 r = MSI_ApplicablePatchW( package, pPatchInfo[i].szPatchData );
581 if (r != ERROR_SUCCESS)
583 pPatchInfo[i].dwOrder = ~0u;
584 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
586 else
588 pPatchInfo[i].dwOrder = i;
589 pPatchInfo[i].uStatus = ret = ERROR_SUCCESS;
591 break;
593 default:
595 FIXME("patch data type %u not supported\n", pPatchInfo[i].ePatchDataType);
596 pPatchInfo[i].dwOrder = ~0u;
597 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
598 break;
602 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo[i].szPatchData));
603 TRACE("ePatchDataType: %u\n", pPatchInfo[i].ePatchDataType);
604 TRACE(" dwOrder: %u\n", pPatchInfo[i].dwOrder);
605 TRACE(" uStatus: %u\n", pPatchInfo[i].uStatus);
607 return ret;
610 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
611 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
613 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
614 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
616 return ERROR_CALL_NOT_IMPLEMENTED;
619 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
620 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
622 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
623 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
625 return ERROR_CALL_NOT_IMPLEMENTED;
628 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
629 MSIPACKAGE **package)
631 UINT r;
632 DWORD sz;
633 HKEY props;
634 LPWSTR localpack;
635 WCHAR sourcepath[MAX_PATH];
636 WCHAR filename[MAX_PATH];
638 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
639 if (r != ERROR_SUCCESS)
640 return ERROR_BAD_CONFIGURATION;
642 localpack = msi_reg_get_val_str(props, szLocalPackage);
643 if (localpack)
645 lstrcpyW(sourcepath, localpack);
646 msi_free(localpack);
649 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
651 sz = sizeof(sourcepath);
652 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
653 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
655 sz = sizeof(filename);
656 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
657 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
659 lstrcatW(sourcepath, filename);
662 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
663 return ERROR_INSTALL_SOURCE_ABSENT;
665 return MSI_OpenPackageW(sourcepath, package);
668 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
669 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
671 MSIPACKAGE* package = NULL;
672 MSIINSTALLCONTEXT context;
673 UINT r;
674 DWORD sz;
675 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
676 LPWSTR commandline;
678 static const WCHAR szInstalled[] = {
679 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
680 static const WCHAR szRemoveAll[] = {
681 ' ','R','E','M','O','V','E','=','A','L','L',0};
682 static const WCHAR szMachine[] = {
683 ' ','A','L','L','U','S','E','R','S','=','1',0};
685 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
686 debugstr_w(szCommandLine));
688 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
689 return ERROR_INVALID_PARAMETER;
691 if (eInstallState == INSTALLSTATE_ADVERTISED ||
692 eInstallState == INSTALLSTATE_SOURCE)
694 FIXME("State %d not implemented\n", eInstallState);
695 return ERROR_CALL_NOT_IMPLEMENTED;
698 r = msi_locate_product(szProduct, &context);
699 if (r != ERROR_SUCCESS)
700 return r;
702 r = msi_open_package(szProduct, context, &package);
703 if (r != ERROR_SUCCESS)
704 return r;
706 sz = lstrlenW(szInstalled) + 1;
708 if (szCommandLine)
709 sz += lstrlenW(szCommandLine);
711 if (eInstallState == INSTALLSTATE_ABSENT)
712 sz += lstrlenW(szRemoveAll);
714 if (context == MSIINSTALLCONTEXT_MACHINE)
715 sz += lstrlenW(szMachine);
717 commandline = msi_alloc(sz * sizeof(WCHAR));
718 if (!commandline)
720 r = ERROR_OUTOFMEMORY;
721 goto end;
724 commandline[0] = 0;
725 if (szCommandLine)
726 lstrcpyW(commandline,szCommandLine);
728 if (eInstallState == INSTALLSTATE_ABSENT)
729 lstrcatW(commandline, szRemoveAll);
731 if (context == MSIINSTALLCONTEXT_MACHINE)
732 lstrcatW(commandline, szMachine);
734 sz = sizeof(sourcepath);
735 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
736 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
738 sz = sizeof(filename);
739 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
740 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
742 strcatW(sourcepath, filename);
744 r = MSI_InstallPackage( package, sourcepath, commandline );
746 msi_free(commandline);
748 end:
749 msiobj_release( &package->hdr );
751 return r;
754 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
755 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
757 LPWSTR szwProduct = NULL;
758 LPWSTR szwCommandLine = NULL;
759 UINT r = ERROR_OUTOFMEMORY;
761 if( szProduct )
763 szwProduct = strdupAtoW( szProduct );
764 if( !szwProduct )
765 goto end;
768 if( szCommandLine)
770 szwCommandLine = strdupAtoW( szCommandLine );
771 if( !szwCommandLine)
772 goto end;
775 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
776 szwCommandLine );
777 end:
778 msi_free( szwProduct );
779 msi_free( szwCommandLine);
781 return r;
784 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
785 INSTALLSTATE eInstallState)
787 LPWSTR szwProduct = NULL;
788 UINT r;
790 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
792 if( szProduct )
794 szwProduct = strdupAtoW( szProduct );
795 if( !szwProduct )
796 return ERROR_OUTOFMEMORY;
799 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
800 msi_free( szwProduct );
802 return r;
805 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
806 INSTALLSTATE eInstallState)
808 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
811 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
813 LPWSTR szwComponent = NULL;
814 UINT r;
815 WCHAR szwBuffer[GUID_SIZE];
817 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
819 if( szComponent )
821 szwComponent = strdupAtoW( szComponent );
822 if( !szwComponent )
823 return ERROR_OUTOFMEMORY;
826 *szwBuffer = '\0';
827 r = MsiGetProductCodeW( szwComponent, szwBuffer );
829 if(*szwBuffer)
830 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
832 msi_free( szwComponent );
834 return r;
837 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
839 UINT rc, index;
840 HKEY compkey, prodkey;
841 WCHAR squished_comp[GUID_SIZE];
842 WCHAR squished_prod[GUID_SIZE];
843 DWORD sz = GUID_SIZE;
845 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
847 if (!szComponent || !*szComponent)
848 return ERROR_INVALID_PARAMETER;
850 if (!squash_guid(szComponent, squished_comp))
851 return ERROR_INVALID_PARAMETER;
853 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
854 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
856 return ERROR_UNKNOWN_COMPONENT;
859 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
860 if (rc != ERROR_SUCCESS)
862 RegCloseKey(compkey);
863 return ERROR_UNKNOWN_COMPONENT;
866 /* check simple case, only one product */
867 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
868 if (rc == ERROR_NO_MORE_ITEMS)
870 rc = ERROR_SUCCESS;
871 goto done;
874 index = 0;
875 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
876 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
878 index++;
879 sz = GUID_SIZE;
880 unsquash_guid(squished_prod, szBuffer);
882 if (MSIREG_OpenProductKey(szBuffer, NULL,
883 MSIINSTALLCONTEXT_USERMANAGED,
884 &prodkey, FALSE) == ERROR_SUCCESS ||
885 MSIREG_OpenProductKey(szBuffer, NULL,
886 MSIINSTALLCONTEXT_USERUNMANAGED,
887 &prodkey, FALSE) == ERROR_SUCCESS ||
888 MSIREG_OpenProductKey(szBuffer, NULL,
889 MSIINSTALLCONTEXT_MACHINE,
890 &prodkey, FALSE) == ERROR_SUCCESS)
892 RegCloseKey(prodkey);
893 rc = ERROR_SUCCESS;
894 goto done;
898 rc = ERROR_INSTALL_FAILURE;
900 done:
901 RegCloseKey(compkey);
902 unsquash_guid(squished_prod, szBuffer);
903 return rc;
906 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
908 DWORD dval;
909 LONG res;
910 WCHAR temp[20];
912 static const WCHAR format[] = {'%','d',0};
914 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
915 if (res != ERROR_SUCCESS)
916 return NULL;
918 if (*type == REG_SZ)
919 return msi_reg_get_val_str(hkey, name);
921 if (!msi_reg_get_val_dword(hkey, name, &dval))
922 return NULL;
924 sprintfW(temp, format, dval);
925 return strdupW(temp);
928 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
929 awstring *szValue, LPDWORD pcchValueBuf)
931 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
932 UINT r = ERROR_UNKNOWN_PROPERTY;
933 HKEY prodkey, userdata, source;
934 LPWSTR val = NULL;
935 WCHAR squished_pc[GUID_SIZE];
936 WCHAR packagecode[GUID_SIZE];
937 BOOL badconfig = FALSE;
938 LONG res;
939 DWORD type = REG_NONE;
941 static WCHAR empty[] = {0};
942 static const WCHAR sourcelist[] = {
943 'S','o','u','r','c','e','L','i','s','t',0};
944 static const WCHAR display_name[] = {
945 'D','i','s','p','l','a','y','N','a','m','e',0};
946 static const WCHAR display_version[] = {
947 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
948 static const WCHAR assignment[] = {
949 'A','s','s','i','g','n','m','e','n','t',0};
951 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
952 debugstr_w(szAttribute), szValue, pcchValueBuf);
954 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
955 return ERROR_INVALID_PARAMETER;
957 if (!squash_guid(szProduct, squished_pc))
958 return ERROR_INVALID_PARAMETER;
960 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
961 MSIINSTALLCONTEXT_USERMANAGED,
962 &prodkey, FALSE)) != ERROR_SUCCESS &&
963 (r = MSIREG_OpenProductKey(szProduct, NULL,
964 MSIINSTALLCONTEXT_USERUNMANAGED,
965 &prodkey, FALSE)) != ERROR_SUCCESS &&
966 (r = MSIREG_OpenProductKey(szProduct, NULL,
967 MSIINSTALLCONTEXT_MACHINE,
968 &prodkey, FALSE)) == ERROR_SUCCESS)
970 context = MSIINSTALLCONTEXT_MACHINE;
973 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
975 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
976 !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
977 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLDATEW) ||
978 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
979 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW) ||
980 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLSOURCEW) ||
981 !lstrcmpW(szAttribute, INSTALLPROPERTY_LOCALPACKAGEW) ||
982 !lstrcmpW(szAttribute, INSTALLPROPERTY_PUBLISHERW) ||
983 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLINFOABOUTW) ||
984 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLUPDATEINFOW) ||
985 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMINORW) ||
986 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMAJORW) ||
987 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW) ||
988 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTIDW) ||
989 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGCOMPANYW) ||
990 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGOWNERW))
992 if (!prodkey)
994 r = ERROR_UNKNOWN_PRODUCT;
995 goto done;
998 if (!userdata)
999 return ERROR_UNKNOWN_PROPERTY;
1001 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
1002 szAttribute = display_name;
1003 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW))
1004 szAttribute = display_version;
1006 val = msi_reg_get_value(userdata, szAttribute, &type);
1007 if (!val)
1008 val = empty;
1010 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTANCETYPEW) ||
1011 !lstrcmpW(szAttribute, INSTALLPROPERTY_TRANSFORMSW) ||
1012 !lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
1013 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW) ||
1014 !lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW) ||
1015 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW) ||
1016 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW) ||
1017 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTICONW) ||
1018 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW) ||
1019 !lstrcmpW(szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1021 if (!prodkey)
1023 r = ERROR_UNKNOWN_PRODUCT;
1024 goto done;
1027 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1028 szAttribute = assignment;
1030 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW))
1032 res = RegOpenKeyW(prodkey, sourcelist, &source);
1033 if (res != ERROR_SUCCESS)
1035 r = ERROR_UNKNOWN_PRODUCT;
1036 goto done;
1039 val = msi_reg_get_value(source, szAttribute, &type);
1040 if (!val)
1041 val = empty;
1043 RegCloseKey(source);
1045 else
1047 val = msi_reg_get_value(prodkey, szAttribute, &type);
1048 if (!val)
1049 val = empty;
1052 if (val != empty && type != REG_DWORD &&
1053 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
1055 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1056 badconfig = TRUE;
1057 else
1059 unsquash_guid(val, packagecode);
1060 msi_free(val);
1061 val = strdupW(packagecode);
1066 if (!val)
1068 r = ERROR_UNKNOWN_PROPERTY;
1069 goto done;
1072 if (pcchValueBuf)
1074 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1075 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1076 * can't rely on its value.
1078 if (szValue->str.a || szValue->str.w)
1080 DWORD size = *pcchValueBuf;
1081 if (strlenW(val) < size)
1082 r = msi_strcpy_to_awstring(val, szValue, &size);
1083 else
1085 r = ERROR_MORE_DATA;
1089 if (!badconfig)
1090 *pcchValueBuf = lstrlenW(val);
1093 if (badconfig)
1094 r = ERROR_BAD_CONFIGURATION;
1096 if (val != empty)
1097 msi_free(val);
1099 done:
1100 RegCloseKey(prodkey);
1101 RegCloseKey(userdata);
1102 return r;
1105 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1106 LPSTR szBuffer, LPDWORD pcchValueBuf)
1108 LPWSTR szwProduct, szwAttribute = NULL;
1109 UINT r = ERROR_OUTOFMEMORY;
1110 awstring buffer;
1112 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1113 szBuffer, pcchValueBuf);
1115 szwProduct = strdupAtoW( szProduct );
1116 if( szProduct && !szwProduct )
1117 goto end;
1119 szwAttribute = strdupAtoW( szAttribute );
1120 if( szAttribute && !szwAttribute )
1121 goto end;
1123 buffer.unicode = FALSE;
1124 buffer.str.a = szBuffer;
1126 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1127 &buffer, pcchValueBuf );
1129 end:
1130 msi_free( szwProduct );
1131 msi_free( szwAttribute );
1133 return r;
1136 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1137 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1139 awstring buffer;
1141 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1142 szBuffer, pcchValueBuf);
1144 buffer.unicode = TRUE;
1145 buffer.str.w = szBuffer;
1147 return MSI_GetProductInfo( szProduct, szAttribute,
1148 &buffer, pcchValueBuf );
1151 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1152 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1153 LPSTR szValue, LPDWORD pcchValue)
1155 LPWSTR product = NULL;
1156 LPWSTR usersid = NULL;
1157 LPWSTR property = NULL;
1158 LPWSTR value = NULL;
1159 DWORD len = 0;
1160 UINT r;
1162 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1163 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1164 szValue, pcchValue);
1166 if (szValue && !pcchValue)
1167 return ERROR_INVALID_PARAMETER;
1169 if (szProductCode) product = strdupAtoW(szProductCode);
1170 if (szUserSid) usersid = strdupAtoW(szUserSid);
1171 if (szProperty) property = strdupAtoW(szProperty);
1173 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1174 NULL, &len);
1175 if (r != ERROR_SUCCESS)
1176 goto done;
1178 value = msi_alloc(++len * sizeof(WCHAR));
1179 if (!value)
1181 r = ERROR_OUTOFMEMORY;
1182 goto done;
1185 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1186 value, &len);
1187 if (r != ERROR_SUCCESS)
1188 goto done;
1190 if (!pcchValue)
1191 goto done;
1193 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1194 if (*pcchValue >= len)
1195 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1196 else if (szValue)
1198 r = ERROR_MORE_DATA;
1199 if (*pcchValue > 0)
1200 *szValue = '\0';
1203 if (*pcchValue <= len || !szValue)
1204 len = len * sizeof(WCHAR) - 1;
1206 *pcchValue = len - 1;
1208 done:
1209 msi_free(product);
1210 msi_free(usersid);
1211 msi_free(property);
1212 msi_free(value);
1214 return r;
1217 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1219 UINT r;
1221 if (!val)
1222 return ERROR_UNKNOWN_PROPERTY;
1224 if (out)
1226 if (strlenW(val) >= *size)
1228 r = ERROR_MORE_DATA;
1229 if (*size > 0)
1230 *out = '\0';
1232 else
1233 lstrcpyW(out, val);
1236 if (size)
1237 *size = lstrlenW(val);
1239 return ERROR_SUCCESS;
1242 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1243 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1244 LPWSTR szValue, LPDWORD pcchValue)
1246 WCHAR squished_pc[GUID_SIZE];
1247 LPWSTR val = NULL;
1248 LPCWSTR package = NULL;
1249 HKEY props = NULL, prod;
1250 HKEY classes = NULL, managed;
1251 HKEY hkey = NULL;
1252 DWORD type;
1253 UINT r = ERROR_UNKNOWN_PRODUCT;
1255 static const WCHAR five[] = {'5',0};
1256 static const WCHAR displayname[] = {
1257 'D','i','s','p','l','a','y','N','a','m','e',0};
1258 static const WCHAR displayversion[] = {
1259 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1260 static const WCHAR managed_local_package[] = {
1261 'M','a','n','a','g','e','d','L','o','c','a','l',
1262 'P','a','c','k','a','g','e',0};
1264 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1265 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1266 szValue, pcchValue);
1268 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1269 return ERROR_INVALID_PARAMETER;
1271 if (szValue && !pcchValue)
1272 return ERROR_INVALID_PARAMETER;
1274 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1275 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1276 dwContext != MSIINSTALLCONTEXT_MACHINE)
1277 return ERROR_INVALID_PARAMETER;
1279 if (!szProperty || !*szProperty)
1280 return ERROR_INVALID_PARAMETER;
1282 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1283 return ERROR_INVALID_PARAMETER;
1285 /* FIXME: dwContext is provided, no need to search for it */
1286 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1287 &managed, FALSE);
1288 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1289 &prod, FALSE);
1291 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1293 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1295 package = INSTALLPROPERTY_LOCALPACKAGEW;
1297 if (!props && !prod)
1298 goto done;
1300 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1302 package = managed_local_package;
1304 if (!props && !managed)
1305 goto done;
1307 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1309 package = INSTALLPROPERTY_LOCALPACKAGEW;
1310 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1312 if (!props && !classes)
1313 goto done;
1316 if (!lstrcmpW(szProperty, INSTALLPROPERTY_HELPLINKW) ||
1317 !lstrcmpW(szProperty, INSTALLPROPERTY_HELPTELEPHONEW) ||
1318 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW) ||
1319 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
1320 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLLOCATIONW) ||
1321 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLSOURCEW) ||
1322 !lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW) ||
1323 !lstrcmpW(szProperty, INSTALLPROPERTY_PUBLISHERW) ||
1324 !lstrcmpW(szProperty, INSTALLPROPERTY_URLINFOABOUTW) ||
1325 !lstrcmpW(szProperty, INSTALLPROPERTY_URLUPDATEINFOW) ||
1326 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMINORW) ||
1327 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMAJORW) ||
1328 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW) ||
1329 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTIDW) ||
1330 !lstrcmpW(szProperty, INSTALLPROPERTY_REGCOMPANYW) ||
1331 !lstrcmpW(szProperty, INSTALLPROPERTY_REGOWNERW) ||
1332 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTANCETYPEW))
1334 val = msi_reg_get_value(props, package, &type);
1335 if (!val)
1337 if (prod || classes)
1338 r = ERROR_UNKNOWN_PROPERTY;
1340 goto done;
1343 msi_free(val);
1345 if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
1346 szProperty = displayname;
1347 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW))
1348 szProperty = displayversion;
1350 val = msi_reg_get_value(props, szProperty, &type);
1351 if (!val)
1352 val = strdupW(szEmpty);
1354 r = msi_copy_outval(val, szValue, pcchValue);
1356 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW) ||
1357 !lstrcmpW(szProperty, INSTALLPROPERTY_LANGUAGEW) ||
1358 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTNAMEW) ||
1359 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGECODEW) ||
1360 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONW) ||
1361 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTICONW) ||
1362 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGENAMEW) ||
1363 !lstrcmpW(szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1365 if (!prod && !classes)
1366 goto done;
1368 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1369 hkey = prod;
1370 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1371 hkey = managed;
1372 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1373 hkey = classes;
1375 val = msi_reg_get_value(hkey, szProperty, &type);
1376 if (!val)
1377 val = strdupW(szEmpty);
1379 r = msi_copy_outval(val, szValue, pcchValue);
1381 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTSTATEW))
1383 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1385 if (props)
1387 val = msi_reg_get_value(props, package, &type);
1388 if (!val)
1389 goto done;
1391 msi_free(val);
1392 val = strdupW(five);
1394 else
1395 val = strdupW(szOne);
1397 r = msi_copy_outval(val, szValue, pcchValue);
1398 goto done;
1400 else if (props && (val = msi_reg_get_value(props, package, &type)))
1402 msi_free(val);
1403 val = strdupW(five);
1404 r = msi_copy_outval(val, szValue, pcchValue);
1405 goto done;
1408 if (prod || managed)
1409 val = strdupW(szOne);
1410 else
1411 goto done;
1413 r = msi_copy_outval(val, szValue, pcchValue);
1415 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1417 if (!prod && !classes)
1418 goto done;
1420 /* FIXME */
1421 val = strdupW(szEmpty);
1422 r = msi_copy_outval(val, szValue, pcchValue);
1424 else
1425 r = ERROR_UNKNOWN_PROPERTY;
1427 done:
1428 RegCloseKey(props);
1429 RegCloseKey(prod);
1430 RegCloseKey(managed);
1431 RegCloseKey(classes);
1432 msi_free(val);
1434 return r;
1437 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1438 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1439 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1441 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1442 LPWSTR property = NULL, val = NULL;
1443 DWORD len;
1444 UINT r;
1446 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1447 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1448 debugstr_a(szProperty), lpValue, pcchValue);
1450 if (lpValue && !pcchValue)
1451 return ERROR_INVALID_PARAMETER;
1453 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1454 if (szProductCode) product = strdupAtoW(szProductCode);
1455 if (szUserSid) usersid = strdupAtoW(szUserSid);
1456 if (szProperty) property = strdupAtoW(szProperty);
1458 len = 0;
1459 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1460 NULL, &len);
1461 if (r != ERROR_SUCCESS)
1462 goto done;
1464 val = msi_alloc(++len * sizeof(WCHAR));
1465 if (!val)
1467 r = ERROR_OUTOFMEMORY;
1468 goto done;
1471 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1472 val, &len);
1473 if (r != ERROR_SUCCESS || !pcchValue)
1474 goto done;
1476 if (lpValue)
1477 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1478 *pcchValue - 1, NULL, NULL);
1480 len = lstrlenW(val);
1481 if ((*val && *pcchValue < len + 1) || !lpValue)
1483 if (lpValue)
1485 r = ERROR_MORE_DATA;
1486 lpValue[*pcchValue - 1] = '\0';
1489 *pcchValue = len * sizeof(WCHAR);
1491 else
1492 *pcchValue = len;
1494 done:
1495 msi_free(val);
1496 msi_free(patch);
1497 msi_free(product);
1498 msi_free(usersid);
1499 msi_free(property);
1501 return r;
1504 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1505 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1506 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1508 WCHAR squished_pc[GUID_SIZE];
1509 WCHAR squished_patch[GUID_SIZE];
1510 HKEY udprod = 0, prod = 0, props = 0;
1511 HKEY patch = 0, patches = 0;
1512 HKEY udpatch = 0, datakey = 0;
1513 HKEY prodpatches = 0;
1514 LPWSTR val = NULL;
1515 UINT r = ERROR_UNKNOWN_PRODUCT;
1516 DWORD len;
1517 LONG res;
1519 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1520 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1522 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1523 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1524 debugstr_w(szProperty), lpValue, pcchValue);
1526 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1527 return ERROR_INVALID_PARAMETER;
1529 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1530 return ERROR_INVALID_PARAMETER;
1532 if (!szProperty)
1533 return ERROR_INVALID_PARAMETER;
1535 if (lpValue && !pcchValue)
1536 return ERROR_INVALID_PARAMETER;
1538 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1539 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1540 dwContext != MSIINSTALLCONTEXT_MACHINE)
1541 return ERROR_INVALID_PARAMETER;
1543 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1544 return ERROR_INVALID_PARAMETER;
1546 if (!lstrcmpW(szUserSid, szLocalSid))
1547 return ERROR_INVALID_PARAMETER;
1549 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1550 &udprod, FALSE) != ERROR_SUCCESS)
1551 goto done;
1553 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1554 &props, FALSE) != ERROR_SUCCESS)
1555 goto done;
1557 r = ERROR_UNKNOWN_PATCH;
1559 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_READ, &patches);
1560 if (res != ERROR_SUCCESS)
1561 goto done;
1563 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_READ, &patch);
1564 if (res != ERROR_SUCCESS)
1565 goto done;
1567 if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW))
1569 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1570 &prod, FALSE) != ERROR_SUCCESS)
1571 goto done;
1573 res = RegOpenKeyExW(prod, szPatches, 0, KEY_ALL_ACCESS, &prodpatches);
1574 if (res != ERROR_SUCCESS)
1575 goto done;
1577 datakey = prodpatches;
1578 szProperty = squished_patch;
1580 else
1582 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1583 &udpatch, FALSE) != ERROR_SUCCESS)
1584 goto done;
1586 if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1588 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1589 szProperty = szManagedPackage;
1590 datakey = udpatch;
1592 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW))
1594 datakey = patch;
1595 szProperty = szInstalled;
1597 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1599 datakey = udpatch;
1601 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_UNINSTALLABLEW) ||
1602 !lstrcmpW(szProperty, INSTALLPROPERTY_PATCHSTATEW) ||
1603 !lstrcmpW(szProperty, INSTALLPROPERTY_DISPLAYNAMEW) ||
1604 !lstrcmpW(szProperty, INSTALLPROPERTY_MOREINFOURLW))
1606 datakey = patch;
1608 else
1610 r = ERROR_UNKNOWN_PROPERTY;
1611 goto done;
1615 val = msi_reg_get_val_str(datakey, szProperty);
1616 if (!val)
1617 val = strdupW(szEmpty);
1619 r = ERROR_SUCCESS;
1621 if (!pcchValue)
1622 goto done;
1624 if (lpValue)
1625 lstrcpynW(lpValue, val, *pcchValue);
1627 len = lstrlenW(val);
1628 if ((*val && *pcchValue < len + 1) || !lpValue)
1630 if (lpValue)
1631 r = ERROR_MORE_DATA;
1633 *pcchValue = len * sizeof(WCHAR);
1636 *pcchValue = len;
1638 done:
1639 msi_free(val);
1640 RegCloseKey(prodpatches);
1641 RegCloseKey(prod);
1642 RegCloseKey(patch);
1643 RegCloseKey(patches);
1644 RegCloseKey(udpatch);
1645 RegCloseKey(props);
1646 RegCloseKey(udprod);
1648 return r;
1651 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1653 UINT r = ERROR_OUTOFMEMORY;
1654 DWORD size;
1655 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1657 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1659 if (!patch || !attr)
1660 return ERROR_INVALID_PARAMETER;
1662 if (!(patchW = strdupAtoW( patch )))
1663 goto done;
1665 if (!(attrW = strdupAtoW( attr )))
1666 goto done;
1668 size = 0;
1669 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1670 if (r != ERROR_SUCCESS)
1671 goto done;
1673 size++;
1674 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1676 r = ERROR_OUTOFMEMORY;
1677 goto done;
1680 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1681 if (r == ERROR_SUCCESS)
1683 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1684 if (len > *buflen)
1685 r = ERROR_MORE_DATA;
1686 else if (buffer)
1687 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1689 *buflen = len - 1;
1692 done:
1693 msi_free( patchW );
1694 msi_free( attrW );
1695 msi_free( bufferW );
1696 return r;
1699 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1701 UINT r;
1702 WCHAR product[GUID_SIZE];
1703 DWORD index;
1705 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1707 if (!patch || !attr)
1708 return ERROR_INVALID_PARAMETER;
1710 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1711 return ERROR_UNKNOWN_PROPERTY;
1713 index = 0;
1714 while (1)
1716 r = MsiEnumProductsW( index, product );
1717 if (r != ERROR_SUCCESS)
1718 break;
1720 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1721 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1722 return r;
1724 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1725 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1726 return r;
1728 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1729 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1730 return r;
1732 index++;
1735 return ERROR_UNKNOWN_PRODUCT;
1738 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1740 LPWSTR szwLogFile = NULL;
1741 UINT r;
1743 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1745 if( szLogFile )
1747 szwLogFile = strdupAtoW( szLogFile );
1748 if( !szwLogFile )
1749 return ERROR_OUTOFMEMORY;
1751 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1752 msi_free( szwLogFile );
1753 return r;
1756 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1758 HANDLE file = INVALID_HANDLE_VALUE;
1760 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1762 if (szLogFile)
1764 lstrcpyW(gszLogFile,szLogFile);
1765 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1766 DeleteFileW(szLogFile);
1767 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
1768 FILE_ATTRIBUTE_NORMAL, NULL);
1769 if (file != INVALID_HANDLE_VALUE)
1770 CloseHandle(file);
1771 else
1772 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
1774 else
1775 gszLogFile[0] = '\0';
1777 return ERROR_SUCCESS;
1780 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
1781 DWORD dwIndex, INSTALLSTATE iState,
1782 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
1783 int *piCost, int *pTempCost)
1785 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
1786 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
1787 pcchDriveBuf, piCost, pTempCost);
1789 return ERROR_NO_MORE_ITEMS;
1792 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1793 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1794 LPCSTR szComponent, INSTALLSTATE *pdwState)
1796 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1797 UINT r;
1799 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1800 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1802 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1803 return ERROR_OUTOFMEMORY;
1805 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1806 return ERROR_OUTOFMEMORY;
1808 if (szComponent && !(comp = strdupAtoW(szComponent)))
1809 return ERROR_OUTOFMEMORY;
1811 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1813 msi_free(prodcode);
1814 msi_free(usersid);
1815 msi_free(comp);
1817 return r;
1820 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1822 UINT r;
1823 HKEY hkey;
1825 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1826 RegCloseKey(hkey);
1827 return (r == ERROR_SUCCESS);
1830 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1832 LPCWSTR package;
1833 HKEY hkey;
1834 DWORD sz;
1835 LONG res;
1836 UINT r;
1838 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1839 static const WCHAR managed_local_package[] = {
1840 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1843 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1844 if (r != ERROR_SUCCESS)
1845 return FALSE;
1847 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1848 package = managed_local_package;
1849 else
1850 package = local_package;
1852 sz = 0;
1853 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1854 RegCloseKey(hkey);
1856 return (res == ERROR_SUCCESS);
1859 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1860 MSIINSTALLCONTEXT context,
1861 LPCWSTR comp, LPWSTR val, DWORD *sz)
1863 HKEY hkey;
1864 LONG res;
1865 UINT r;
1867 if (context == MSIINSTALLCONTEXT_MACHINE)
1868 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
1869 else
1870 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
1872 if (r != ERROR_SUCCESS)
1873 return FALSE;
1875 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
1876 if (res != ERROR_SUCCESS)
1877 return FALSE;
1879 RegCloseKey(hkey);
1880 return TRUE;
1883 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
1884 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1885 LPCWSTR szComponent, INSTALLSTATE *pdwState)
1887 WCHAR squished_pc[GUID_SIZE];
1888 WCHAR val[MAX_PATH];
1889 BOOL found;
1890 DWORD sz;
1892 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
1893 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
1895 if (!pdwState || !szComponent)
1896 return ERROR_INVALID_PARAMETER;
1898 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
1899 return ERROR_INVALID_PARAMETER;
1901 if (!squash_guid(szProductCode, squished_pc))
1902 return ERROR_INVALID_PARAMETER;
1904 found = msi_comp_find_prod_key(szProductCode, dwContext);
1906 if (!msi_comp_find_package(szProductCode, dwContext))
1908 if (found)
1910 *pdwState = INSTALLSTATE_UNKNOWN;
1911 return ERROR_UNKNOWN_COMPONENT;
1914 return ERROR_UNKNOWN_PRODUCT;
1917 *pdwState = INSTALLSTATE_UNKNOWN;
1919 sz = MAX_PATH;
1920 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
1921 return ERROR_UNKNOWN_COMPONENT;
1923 if (sz == 0)
1924 *pdwState = INSTALLSTATE_NOTUSED;
1925 else
1927 if (lstrlenW(val) > 2 &&
1928 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
1930 *pdwState = INSTALLSTATE_SOURCE;
1932 else
1933 *pdwState = INSTALLSTATE_LOCAL;
1936 return ERROR_SUCCESS;
1939 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
1941 LPWSTR szwProduct = NULL;
1942 INSTALLSTATE r;
1944 if( szProduct )
1946 szwProduct = strdupAtoW( szProduct );
1947 if( !szwProduct )
1948 return ERROR_OUTOFMEMORY;
1950 r = MsiQueryProductStateW( szwProduct );
1951 msi_free( szwProduct );
1952 return r;
1955 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
1957 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1958 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
1959 HKEY prodkey = 0, userdata = 0;
1960 DWORD val;
1961 UINT r;
1963 static const WCHAR szWindowsInstaller[] = {
1964 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1966 TRACE("%s\n", debugstr_w(szProduct));
1968 if (!szProduct || !*szProduct)
1969 return INSTALLSTATE_INVALIDARG;
1971 if (lstrlenW(szProduct) != GUID_SIZE - 1)
1972 return INSTALLSTATE_INVALIDARG;
1974 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1975 &prodkey, FALSE) != ERROR_SUCCESS &&
1976 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1977 &prodkey, FALSE) != ERROR_SUCCESS &&
1978 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
1979 &prodkey, FALSE) == ERROR_SUCCESS)
1981 context = MSIINSTALLCONTEXT_MACHINE;
1984 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
1985 if (r != ERROR_SUCCESS)
1986 goto done;
1988 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
1989 goto done;
1991 if (val)
1992 state = INSTALLSTATE_DEFAULT;
1993 else
1994 state = INSTALLSTATE_UNKNOWN;
1996 done:
1997 if (!prodkey)
1999 state = INSTALLSTATE_UNKNOWN;
2001 if (userdata)
2002 state = INSTALLSTATE_ABSENT;
2005 RegCloseKey(prodkey);
2006 RegCloseKey(userdata);
2007 return state;
2010 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2012 INSTALLUILEVEL old = gUILevel;
2013 HWND oldwnd = gUIhwnd;
2015 TRACE("%08x %p\n", dwUILevel, phWnd);
2017 gUILevel = dwUILevel;
2018 if (phWnd)
2020 gUIhwnd = *phWnd;
2021 *phWnd = oldwnd;
2023 return old;
2026 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2027 DWORD dwMessageFilter, LPVOID pvContext)
2029 INSTALLUI_HANDLERA prev = gUIHandlerA;
2031 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2033 gUIHandlerA = puiHandler;
2034 gUIHandlerW = NULL;
2035 gUIFilter = dwMessageFilter;
2036 gUIContext = pvContext;
2038 return prev;
2041 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2042 DWORD dwMessageFilter, LPVOID pvContext)
2044 INSTALLUI_HANDLERW prev = gUIHandlerW;
2046 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2048 gUIHandlerA = NULL;
2049 gUIHandlerW = puiHandler;
2050 gUIFilter = dwMessageFilter;
2051 gUIContext = pvContext;
2053 return prev;
2056 /******************************************************************
2057 * MsiLoadStringW [MSI.@]
2059 * Loads a string from MSI's string resources.
2061 * PARAMS
2063 * handle [I] only -1 is handled currently
2064 * id [I] id of the string to be loaded
2065 * lpBuffer [O] buffer for the string to be written to
2066 * nBufferMax [I] maximum size of the buffer in characters
2067 * lang [I] the preferred language for the string
2069 * RETURNS
2071 * If successful, this function returns the language id of the string loaded
2072 * If the function fails, the function returns zero.
2074 * NOTES
2076 * The type of the first parameter is unknown. LoadString's prototype
2077 * suggests that it might be a module handle. I have made it an MSI handle
2078 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2079 * handle. Maybe strings can be stored in an MSI database somehow.
2081 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2082 int nBufferMax, LANGID lang )
2084 HRSRC hres;
2085 HGLOBAL hResData;
2086 LPWSTR p;
2087 DWORD i, len;
2089 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2091 if( handle != -1 )
2092 FIXME("don't know how to deal with handle = %08x\n", handle);
2094 if( !lang )
2095 lang = GetUserDefaultLangID();
2097 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2098 (LPWSTR)1, lang );
2099 if( !hres )
2100 return 0;
2101 hResData = LoadResource( msi_hInstance, hres );
2102 if( !hResData )
2103 return 0;
2104 p = LockResource( hResData );
2105 if( !p )
2106 return 0;
2108 for (i = 0; i < (id&0xf); i++)
2109 p += *p + 1;
2110 len = *p;
2112 if( nBufferMax <= len )
2113 return 0;
2115 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2116 lpBuffer[ len ] = 0;
2118 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2120 return lang;
2123 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2124 int nBufferMax, LANGID lang )
2126 LPWSTR bufW;
2127 LANGID r;
2128 INT len;
2130 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2131 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2132 if( r )
2134 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2135 if( len <= nBufferMax )
2136 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2137 lpBuffer, nBufferMax, NULL, NULL );
2138 else
2139 r = 0;
2141 msi_free(bufW);
2142 return r;
2145 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2146 LPDWORD pcchBuf)
2148 char szProduct[GUID_SIZE];
2150 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2152 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2153 return INSTALLSTATE_UNKNOWN;
2155 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2158 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2159 LPDWORD pcchBuf)
2161 WCHAR szProduct[GUID_SIZE];
2163 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2165 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2166 return INSTALLSTATE_UNKNOWN;
2168 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2171 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2172 WORD wLanguageId, DWORD f)
2174 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2175 uType, wLanguageId, f);
2176 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2179 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2180 WORD wLanguageId, DWORD f)
2182 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2183 uType, wLanguageId, f);
2184 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2187 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2188 DWORD unknown, WORD wLanguageId, DWORD f)
2190 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2191 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2192 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2195 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2196 DWORD unknown, WORD wLanguageId, DWORD f)
2198 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2199 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2200 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2203 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2204 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2205 LPDWORD pcchPathBuf )
2207 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2208 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2209 pcchPathBuf);
2210 return ERROR_CALL_NOT_IMPLEMENTED;
2213 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2214 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2215 LPDWORD pcchPathBuf )
2217 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2218 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2219 pcchPathBuf);
2220 return ERROR_CALL_NOT_IMPLEMENTED;
2223 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2224 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2226 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2227 return ERROR_CALL_NOT_IMPLEMENTED;
2230 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2231 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2233 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2234 return ERROR_CALL_NOT_IMPLEMENTED;
2237 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
2238 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2239 LPDWORD pcbHashData)
2241 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
2242 ppcCertContext, pbHashData, pcbHashData);
2243 return ERROR_CALL_NOT_IMPLEMENTED;
2246 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
2247 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2248 LPDWORD pcbHashData)
2250 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
2251 ppcCertContext, pbHashData, pcbHashData);
2252 return ERROR_CALL_NOT_IMPLEMENTED;
2255 /******************************************************************
2256 * MsiGetProductPropertyA [MSI.@]
2258 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2259 LPSTR szValue, LPDWORD pccbValue)
2261 LPWSTR prop = NULL, val = NULL;
2262 DWORD len;
2263 UINT r;
2265 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2266 szValue, pccbValue);
2268 if (szValue && !pccbValue)
2269 return ERROR_INVALID_PARAMETER;
2271 if (szProperty) prop = strdupAtoW(szProperty);
2273 len = 0;
2274 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2275 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2276 goto done;
2278 if (r == ERROR_SUCCESS)
2280 if (szValue) *szValue = '\0';
2281 if (pccbValue) *pccbValue = 0;
2282 goto done;
2285 val = msi_alloc(++len * sizeof(WCHAR));
2286 if (!val)
2288 r = ERROR_OUTOFMEMORY;
2289 goto done;
2292 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2293 if (r != ERROR_SUCCESS)
2294 goto done;
2296 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2298 if (szValue)
2299 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2300 *pccbValue, NULL, NULL);
2302 if (pccbValue)
2304 if (len > *pccbValue)
2305 r = ERROR_MORE_DATA;
2307 *pccbValue = len - 1;
2310 done:
2311 msi_free(prop);
2312 msi_free(val);
2314 return r;
2317 /******************************************************************
2318 * MsiGetProductPropertyW [MSI.@]
2320 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2321 LPWSTR szValue, LPDWORD pccbValue)
2323 MSIPACKAGE *package;
2324 MSIQUERY *view = NULL;
2325 MSIRECORD *rec = NULL;
2326 LPCWSTR val;
2327 UINT r;
2329 static const WCHAR query[] = {
2330 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2331 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2332 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2334 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2335 szValue, pccbValue);
2337 if (!szProperty)
2338 return ERROR_INVALID_PARAMETER;
2340 if (szValue && !pccbValue)
2341 return ERROR_INVALID_PARAMETER;
2343 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2344 if (!package)
2345 return ERROR_INVALID_HANDLE;
2347 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2348 if (r != ERROR_SUCCESS)
2349 goto done;
2351 r = MSI_ViewExecute(view, 0);
2352 if (r != ERROR_SUCCESS)
2353 goto done;
2355 r = MSI_ViewFetch(view, &rec);
2356 if (r != ERROR_SUCCESS)
2357 goto done;
2359 val = MSI_RecordGetString(rec, 2);
2360 if (!val)
2361 goto done;
2363 if (lstrlenW(val) >= *pccbValue)
2365 lstrcpynW(szValue, val, *pccbValue);
2366 *pccbValue = lstrlenW(val);
2367 r = ERROR_MORE_DATA;
2369 else
2371 lstrcpyW(szValue, val);
2372 *pccbValue = lstrlenW(val);
2373 r = ERROR_SUCCESS;
2376 done:
2377 if (view)
2379 MSI_ViewClose(view);
2380 msiobj_release(&view->hdr);
2381 if (rec) msiobj_release(&rec->hdr);
2384 if (!rec)
2386 if (szValue) *szValue = '\0';
2387 if (pccbValue) *pccbValue = 0;
2388 r = ERROR_SUCCESS;
2391 return r;
2394 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2396 UINT r;
2397 LPWSTR szPack = NULL;
2399 TRACE("%s\n", debugstr_a(szPackage) );
2401 if( szPackage )
2403 szPack = strdupAtoW( szPackage );
2404 if( !szPack )
2405 return ERROR_OUTOFMEMORY;
2408 r = MsiVerifyPackageW( szPack );
2410 msi_free( szPack );
2412 return r;
2415 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2417 MSIHANDLE handle;
2418 UINT r;
2420 TRACE("%s\n", debugstr_w(szPackage) );
2422 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2423 MsiCloseHandle( handle );
2425 return r;
2428 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2429 awstring* lpPathBuf, LPDWORD pcchBuf)
2431 WCHAR squished_pc[GUID_SIZE];
2432 WCHAR squished_comp[GUID_SIZE];
2433 HKEY hkey;
2434 LPWSTR path = NULL;
2435 INSTALLSTATE state;
2436 DWORD version;
2438 static const WCHAR wininstaller[] = {
2439 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2441 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2442 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2444 if (!szProduct || !szComponent)
2445 return INSTALLSTATE_INVALIDARG;
2447 if (lpPathBuf->str.w && !pcchBuf)
2448 return INSTALLSTATE_INVALIDARG;
2450 if (!squash_guid(szProduct, squished_pc) ||
2451 !squash_guid(szComponent, squished_comp))
2452 return INSTALLSTATE_INVALIDARG;
2454 state = INSTALLSTATE_UNKNOWN;
2456 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2457 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2459 path = msi_reg_get_val_str(hkey, squished_pc);
2460 RegCloseKey(hkey);
2462 state = INSTALLSTATE_ABSENT;
2464 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2465 &hkey, FALSE) == ERROR_SUCCESS ||
2466 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2467 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2468 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2469 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2471 RegCloseKey(hkey);
2472 state = INSTALLSTATE_LOCAL;
2476 if (state != INSTALLSTATE_LOCAL &&
2477 (MSIREG_OpenProductKey(szProduct, NULL,
2478 MSIINSTALLCONTEXT_USERUNMANAGED,
2479 &hkey, FALSE) == ERROR_SUCCESS ||
2480 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2481 &hkey, FALSE) == ERROR_SUCCESS))
2483 RegCloseKey(hkey);
2485 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2486 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2488 msi_free(path);
2489 path = msi_reg_get_val_str(hkey, squished_pc);
2490 RegCloseKey(hkey);
2492 state = INSTALLSTATE_ABSENT;
2494 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2495 state = INSTALLSTATE_LOCAL;
2499 if (!path)
2500 return INSTALLSTATE_UNKNOWN;
2502 if (state == INSTALLSTATE_LOCAL && !*path)
2503 state = INSTALLSTATE_NOTUSED;
2505 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2506 msi_free(path);
2507 return state;
2510 /******************************************************************
2511 * MsiGetComponentPathW [MSI.@]
2513 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2514 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2516 awstring path;
2518 path.unicode = TRUE;
2519 path.str.w = lpPathBuf;
2521 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2524 /******************************************************************
2525 * MsiGetComponentPathA [MSI.@]
2527 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2528 LPSTR lpPathBuf, LPDWORD pcchBuf)
2530 LPWSTR szwProduct, szwComponent = NULL;
2531 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2532 awstring path;
2534 szwProduct = strdupAtoW( szProduct );
2535 if( szProduct && !szwProduct)
2536 goto end;
2538 szwComponent = strdupAtoW( szComponent );
2539 if( szComponent && !szwComponent )
2540 goto end;
2542 path.unicode = FALSE;
2543 path.str.a = lpPathBuf;
2545 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2547 end:
2548 msi_free( szwProduct );
2549 msi_free( szwComponent );
2551 return r;
2554 /******************************************************************
2555 * MsiQueryFeatureStateA [MSI.@]
2557 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2559 LPWSTR szwProduct = NULL, szwFeature= NULL;
2560 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2562 szwProduct = strdupAtoW( szProduct );
2563 if ( szProduct && !szwProduct )
2564 goto end;
2566 szwFeature = strdupAtoW( szFeature );
2567 if ( szFeature && !szwFeature )
2568 goto end;
2570 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2572 end:
2573 msi_free( szwProduct);
2574 msi_free( szwFeature);
2576 return rc;
2579 /******************************************************************
2580 * MsiQueryFeatureStateW [MSI.@]
2582 * Checks the state of a feature
2584 * PARAMS
2585 * szProduct [I] Product's GUID string
2586 * szFeature [I] Feature's GUID string
2588 * RETURNS
2589 * INSTALLSTATE_LOCAL Feature is installed and usable
2590 * INSTALLSTATE_ABSENT Feature is absent
2591 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2592 * INSTALLSTATE_UNKNOWN An error occurred
2593 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2596 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2598 WCHAR squishProduct[33], comp[GUID_SIZE];
2599 GUID guid;
2600 LPWSTR components, p, parent_feature, path;
2601 UINT rc;
2602 HKEY hkey;
2603 INSTALLSTATE r;
2604 BOOL missing = FALSE;
2605 BOOL machine = FALSE;
2606 BOOL source = FALSE;
2608 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2610 if (!szProduct || !szFeature)
2611 return INSTALLSTATE_INVALIDARG;
2613 if (!squash_guid( szProduct, squishProduct ))
2614 return INSTALLSTATE_INVALIDARG;
2616 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2617 &hkey, FALSE) != ERROR_SUCCESS &&
2618 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2619 &hkey, FALSE) != ERROR_SUCCESS)
2621 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2622 &hkey, FALSE);
2623 if (rc != ERROR_SUCCESS)
2624 return INSTALLSTATE_UNKNOWN;
2626 machine = TRUE;
2629 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2630 RegCloseKey(hkey);
2632 if (!parent_feature)
2633 return INSTALLSTATE_UNKNOWN;
2635 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2636 msi_free(parent_feature);
2637 if (r == INSTALLSTATE_ABSENT)
2638 return r;
2640 if (machine)
2641 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2642 MSIINSTALLCONTEXT_MACHINE,
2643 &hkey, FALSE);
2644 else
2645 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2646 MSIINSTALLCONTEXT_USERUNMANAGED,
2647 &hkey, FALSE);
2649 if (rc != ERROR_SUCCESS)
2650 return INSTALLSTATE_ADVERTISED;
2652 components = msi_reg_get_val_str( hkey, szFeature );
2653 RegCloseKey(hkey);
2655 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2657 if (!components)
2658 return INSTALLSTATE_ADVERTISED;
2660 for( p = components; *p && *p != 2 ; p += 20)
2662 if (!decode_base85_guid( p, &guid ))
2664 if (p != components)
2665 break;
2667 msi_free(components);
2668 return INSTALLSTATE_BADCONFIG;
2671 StringFromGUID2(&guid, comp, GUID_SIZE);
2673 if (machine)
2674 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2675 else
2676 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2678 if (rc != ERROR_SUCCESS)
2680 msi_free(components);
2681 return INSTALLSTATE_ADVERTISED;
2684 path = msi_reg_get_val_str(hkey, squishProduct);
2685 if (!path)
2686 missing = TRUE;
2687 else if (lstrlenW(path) > 2 &&
2688 path[0] >= '0' && path[0] <= '9' &&
2689 path[1] >= '0' && path[1] <= '9')
2691 source = TRUE;
2694 msi_free(path);
2697 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
2698 msi_free(components);
2700 if (missing)
2701 return INSTALLSTATE_ADVERTISED;
2703 if (source)
2704 return INSTALLSTATE_SOURCE;
2706 return INSTALLSTATE_LOCAL;
2709 /******************************************************************
2710 * MsiGetFileVersionA [MSI.@]
2712 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2713 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2715 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2716 UINT ret = ERROR_OUTOFMEMORY;
2718 if ((lpVersionBuf && !pcchVersionBuf) ||
2719 (lpLangBuf && !pcchLangBuf))
2720 return ERROR_INVALID_PARAMETER;
2722 if( szFilePath )
2724 szwFilePath = strdupAtoW( szFilePath );
2725 if( !szwFilePath )
2726 goto end;
2729 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2731 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2732 if( !lpwVersionBuff )
2733 goto end;
2736 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2738 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2739 if( !lpwLangBuff )
2740 goto end;
2743 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2744 lpwLangBuff, pcchLangBuf);
2746 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2747 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2748 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2749 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2750 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2751 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2753 end:
2754 msi_free(szwFilePath);
2755 msi_free(lpwVersionBuff);
2756 msi_free(lpwLangBuff);
2758 return ret;
2761 /******************************************************************
2762 * MsiGetFileVersionW [MSI.@]
2764 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2765 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2767 static const WCHAR szVersionResource[] = {'\\',0};
2768 static const WCHAR szVersionFormat[] = {
2769 '%','d','.','%','d','.','%','d','.','%','d',0};
2770 static const WCHAR szLangResource[] = {
2771 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2772 'T','r','a','n','s','l','a','t','i','o','n',0};
2773 static const WCHAR szLangFormat[] = {'%','d',0};
2774 UINT ret = 0;
2775 DWORD dwVerLen, gle;
2776 LPVOID lpVer = NULL;
2777 VS_FIXEDFILEINFO *ffi;
2778 USHORT *lang;
2779 UINT puLen;
2780 WCHAR tmp[32];
2782 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2783 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2784 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2786 if ((lpVersionBuf && !pcchVersionBuf) ||
2787 (lpLangBuf && !pcchLangBuf))
2788 return ERROR_INVALID_PARAMETER;
2790 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
2791 if( !dwVerLen )
2793 gle = GetLastError();
2794 if (gle == ERROR_BAD_PATHNAME)
2795 return ERROR_FILE_NOT_FOUND;
2796 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
2797 return ERROR_FILE_INVALID;
2799 return gle;
2802 lpVer = msi_alloc(dwVerLen);
2803 if( !lpVer )
2805 ret = ERROR_OUTOFMEMORY;
2806 goto end;
2809 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
2811 ret = GetLastError();
2812 goto end;
2815 if (pcchVersionBuf)
2817 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
2818 (puLen > 0) )
2820 wsprintfW(tmp, szVersionFormat,
2821 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
2822 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
2823 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
2825 if (strlenW(tmp) >= *pcchVersionBuf)
2826 ret = ERROR_MORE_DATA;
2828 *pcchVersionBuf = lstrlenW(tmp);
2830 else
2832 if (lpVersionBuf) *lpVersionBuf = 0;
2833 *pcchVersionBuf = 0;
2837 if (pcchLangBuf)
2839 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
2840 (puLen > 0))
2842 wsprintfW(tmp, szLangFormat, *lang);
2843 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
2845 if (strlenW(tmp) >= *pcchLangBuf)
2846 ret = ERROR_MORE_DATA;
2848 *pcchLangBuf = lstrlenW(tmp);
2850 else
2852 if (lpLangBuf) *lpLangBuf = 0;
2853 *pcchLangBuf = 0;
2857 end:
2858 msi_free(lpVer);
2859 return ret;
2862 /***********************************************************************
2863 * MsiGetFeatureUsageW [MSI.@]
2865 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
2866 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2868 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
2869 pdwUseCount, pwDateUsed);
2870 return ERROR_CALL_NOT_IMPLEMENTED;
2873 /***********************************************************************
2874 * MsiGetFeatureUsageA [MSI.@]
2876 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
2877 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2879 LPWSTR prod = NULL, feat = NULL;
2880 UINT ret = ERROR_OUTOFMEMORY;
2882 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
2883 pdwUseCount, pwDateUsed);
2885 prod = strdupAtoW( szProduct );
2886 if (szProduct && !prod)
2887 goto end;
2889 feat = strdupAtoW( szFeature );
2890 if (szFeature && !feat)
2891 goto end;
2893 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
2895 end:
2896 msi_free( prod );
2897 msi_free( feat );
2899 return ret;
2902 /***********************************************************************
2903 * MsiUseFeatureExW [MSI.@]
2905 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
2906 DWORD dwInstallMode, DWORD dwReserved )
2908 INSTALLSTATE state;
2910 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2911 dwInstallMode, dwReserved);
2913 state = MsiQueryFeatureStateW( szProduct, szFeature );
2915 if (dwReserved)
2916 return INSTALLSTATE_INVALIDARG;
2918 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
2920 FIXME("mark product %s feature %s as used\n",
2921 debugstr_w(szProduct), debugstr_w(szFeature) );
2924 return state;
2927 /***********************************************************************
2928 * MsiUseFeatureExA [MSI.@]
2930 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
2931 DWORD dwInstallMode, DWORD dwReserved )
2933 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
2934 LPWSTR prod = NULL, feat = NULL;
2936 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2937 dwInstallMode, dwReserved);
2939 prod = strdupAtoW( szProduct );
2940 if (szProduct && !prod)
2941 goto end;
2943 feat = strdupAtoW( szFeature );
2944 if (szFeature && !feat)
2945 goto end;
2947 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
2949 end:
2950 msi_free( prod );
2951 msi_free( feat );
2953 return ret;
2956 /***********************************************************************
2957 * MsiUseFeatureW [MSI.@]
2959 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
2961 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
2964 /***********************************************************************
2965 * MsiUseFeatureA [MSI.@]
2967 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
2969 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
2972 /***********************************************************************
2973 * MSI_ProvideQualifiedComponentEx [internal]
2975 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
2976 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2977 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
2978 LPDWORD pcchPathBuf)
2980 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
2981 feature[MAX_FEATURE_CHARS+1];
2982 LPWSTR info;
2983 HKEY hkey;
2984 DWORD sz;
2985 UINT rc;
2987 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
2988 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
2989 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2991 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
2992 if (rc != ERROR_SUCCESS)
2993 return ERROR_INDEX_ABSENT;
2995 info = msi_reg_get_val_str( hkey, szQualifier );
2996 RegCloseKey(hkey);
2998 if (!info)
2999 return ERROR_INDEX_ABSENT;
3001 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
3003 if (!szProduct)
3004 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
3005 else
3006 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
3008 msi_free( info );
3010 if (rc != INSTALLSTATE_LOCAL)
3011 return ERROR_FILE_NOT_FOUND;
3013 return ERROR_SUCCESS;
3016 /***********************************************************************
3017 * MsiProvideQualifiedComponentExW [MSI.@]
3019 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3020 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3021 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3022 LPDWORD pcchPathBuf)
3024 awstring path;
3026 path.unicode = TRUE;
3027 path.str.w = lpPathBuf;
3029 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3030 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3033 /***********************************************************************
3034 * MsiProvideQualifiedComponentExA [MSI.@]
3036 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3037 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3038 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3039 LPDWORD pcchPathBuf)
3041 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3042 UINT r = ERROR_OUTOFMEMORY;
3043 awstring path;
3045 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3046 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3047 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3049 szwComponent = strdupAtoW( szComponent );
3050 if (szComponent && !szwComponent)
3051 goto end;
3053 szwQualifier = strdupAtoW( szQualifier );
3054 if (szQualifier && !szwQualifier)
3055 goto end;
3057 szwProduct = strdupAtoW( szProduct );
3058 if (szProduct && !szwProduct)
3059 goto end;
3061 path.unicode = FALSE;
3062 path.str.a = lpPathBuf;
3064 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3065 dwInstallMode, szwProduct, Unused1,
3066 Unused2, &path, pcchPathBuf);
3067 end:
3068 msi_free(szwProduct);
3069 msi_free(szwComponent);
3070 msi_free(szwQualifier);
3072 return r;
3075 /***********************************************************************
3076 * MsiProvideQualifiedComponentW [MSI.@]
3078 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3079 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3080 LPDWORD pcchPathBuf)
3082 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3083 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3086 /***********************************************************************
3087 * MsiProvideQualifiedComponentA [MSI.@]
3089 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3090 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3091 LPDWORD pcchPathBuf)
3093 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3094 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3097 /***********************************************************************
3098 * MSI_GetUserInfo [internal]
3100 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3101 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3102 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3103 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3105 WCHAR squished_pc[SQUISH_GUID_SIZE];
3106 LPWSTR user, org, serial;
3107 USERINFOSTATE state;
3108 HKEY hkey, props;
3109 LPCWSTR orgptr;
3110 UINT r;
3112 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3113 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3114 pcchSerialBuf);
3116 if (!szProduct || !squash_guid(szProduct, squished_pc))
3117 return USERINFOSTATE_INVALIDARG;
3119 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3120 &hkey, FALSE) != ERROR_SUCCESS &&
3121 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3122 &hkey, FALSE) != ERROR_SUCCESS &&
3123 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3124 &hkey, FALSE) != ERROR_SUCCESS)
3126 return USERINFOSTATE_UNKNOWN;
3129 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3130 NULL, &props, FALSE) != ERROR_SUCCESS &&
3131 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3132 NULL, &props, FALSE) != ERROR_SUCCESS)
3134 RegCloseKey(hkey);
3135 return USERINFOSTATE_ABSENT;
3138 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3139 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3140 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3141 state = USERINFOSTATE_ABSENT;
3143 RegCloseKey(hkey);
3144 RegCloseKey(props);
3146 if (user && serial)
3147 state = USERINFOSTATE_PRESENT;
3149 if (pcchUserNameBuf)
3151 if (lpUserNameBuf && !user)
3153 (*pcchUserNameBuf)--;
3154 goto done;
3157 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3158 if (r == ERROR_MORE_DATA)
3160 state = USERINFOSTATE_MOREDATA;
3161 goto done;
3165 if (pcchOrgNameBuf)
3167 orgptr = org;
3168 if (!orgptr) orgptr = szEmpty;
3170 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3171 if (r == ERROR_MORE_DATA)
3173 state = USERINFOSTATE_MOREDATA;
3174 goto done;
3178 if (pcchSerialBuf)
3180 if (!serial)
3182 (*pcchSerialBuf)--;
3183 goto done;
3186 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3187 if (r == ERROR_MORE_DATA)
3188 state = USERINFOSTATE_MOREDATA;
3191 done:
3192 msi_free(user);
3193 msi_free(org);
3194 msi_free(serial);
3196 return state;
3199 /***********************************************************************
3200 * MsiGetUserInfoW [MSI.@]
3202 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3203 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3204 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3205 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3207 awstring user, org, serial;
3209 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3210 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3211 (lpSerialBuf && !pcchSerialBuf))
3212 return USERINFOSTATE_INVALIDARG;
3214 user.unicode = TRUE;
3215 user.str.w = lpUserNameBuf;
3216 org.unicode = TRUE;
3217 org.str.w = lpOrgNameBuf;
3218 serial.unicode = TRUE;
3219 serial.str.w = lpSerialBuf;
3221 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3222 &org, pcchOrgNameBuf,
3223 &serial, pcchSerialBuf );
3226 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3227 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3228 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3229 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3231 awstring user, org, serial;
3232 LPWSTR prod;
3233 UINT r;
3235 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3236 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3237 (lpSerialBuf && !pcchSerialBuf))
3238 return USERINFOSTATE_INVALIDARG;
3240 prod = strdupAtoW( szProduct );
3241 if (szProduct && !prod)
3242 return ERROR_OUTOFMEMORY;
3244 user.unicode = FALSE;
3245 user.str.a = lpUserNameBuf;
3246 org.unicode = FALSE;
3247 org.str.a = lpOrgNameBuf;
3248 serial.unicode = FALSE;
3249 serial.str.a = lpSerialBuf;
3251 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3252 &org, pcchOrgNameBuf,
3253 &serial, pcchSerialBuf );
3255 msi_free( prod );
3257 return r;
3260 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3262 MSIHANDLE handle;
3263 UINT rc;
3264 MSIPACKAGE *package;
3265 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3267 TRACE("(%s)\n",debugstr_w(szProduct));
3269 rc = MsiOpenProductW(szProduct,&handle);
3270 if (rc != ERROR_SUCCESS)
3271 return ERROR_INVALID_PARAMETER;
3273 /* MsiCollectUserInfo cannot be called from a custom action. */
3274 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3275 if (!package)
3276 return ERROR_CALL_NOT_IMPLEMENTED;
3278 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3279 msiobj_release( &package->hdr );
3281 MsiCloseHandle(handle);
3283 return rc;
3286 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3288 MSIHANDLE handle;
3289 UINT rc;
3290 MSIPACKAGE *package;
3291 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3293 TRACE("(%s)\n",debugstr_a(szProduct));
3295 rc = MsiOpenProductA(szProduct,&handle);
3296 if (rc != ERROR_SUCCESS)
3297 return ERROR_INVALID_PARAMETER;
3299 /* MsiCollectUserInfo cannot be called from a custom action. */
3300 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3301 if (!package)
3302 return ERROR_CALL_NOT_IMPLEMENTED;
3304 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3305 msiobj_release( &package->hdr );
3307 MsiCloseHandle(handle);
3309 return rc;
3312 /***********************************************************************
3313 * MsiConfigureFeatureA [MSI.@]
3315 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3317 LPWSTR prod, feat = NULL;
3318 UINT r = ERROR_OUTOFMEMORY;
3320 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3322 prod = strdupAtoW( szProduct );
3323 if (szProduct && !prod)
3324 goto end;
3326 feat = strdupAtoW( szFeature );
3327 if (szFeature && !feat)
3328 goto end;
3330 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3332 end:
3333 msi_free(feat);
3334 msi_free(prod);
3336 return r;
3339 /***********************************************************************
3340 * MsiConfigureFeatureW [MSI.@]
3342 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3344 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3345 MSIPACKAGE *package = NULL;
3346 UINT r;
3347 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3348 DWORD sz;
3350 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3352 if (!szProduct || !szFeature)
3353 return ERROR_INVALID_PARAMETER;
3355 switch (eInstallState)
3357 case INSTALLSTATE_DEFAULT:
3358 /* FIXME: how do we figure out the default location? */
3359 eInstallState = INSTALLSTATE_LOCAL;
3360 break;
3361 case INSTALLSTATE_LOCAL:
3362 case INSTALLSTATE_SOURCE:
3363 case INSTALLSTATE_ABSENT:
3364 case INSTALLSTATE_ADVERTISED:
3365 break;
3366 default:
3367 return ERROR_INVALID_PARAMETER;
3370 r = MSI_OpenProductW( szProduct, &package );
3371 if (r != ERROR_SUCCESS)
3372 return r;
3374 sz = sizeof(sourcepath);
3375 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3376 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3378 sz = sizeof(filename);
3379 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3380 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3382 lstrcatW( sourcepath, filename );
3384 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3386 r = ACTION_PerformUIAction( package, szCostInit, -1 );
3387 if (r != ERROR_SUCCESS)
3388 goto end;
3390 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3391 if (r != ERROR_SUCCESS)
3392 goto end;
3394 r = MSI_InstallPackage( package, sourcepath, NULL );
3396 end:
3397 msiobj_release( &package->hdr );
3399 return r;
3402 /***********************************************************************
3403 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3405 * Notes: undocumented
3407 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3409 WCHAR path[MAX_PATH];
3411 TRACE("%d\n", dwReserved);
3413 if (dwReserved)
3415 FIXME("dwReserved=%d\n", dwReserved);
3416 return ERROR_INVALID_PARAMETER;
3419 if (!GetWindowsDirectoryW(path, MAX_PATH))
3420 return ERROR_FUNCTION_FAILED;
3422 lstrcatW(path, installerW);
3424 if (!CreateDirectoryW(path, NULL))
3425 return ERROR_FUNCTION_FAILED;
3427 return ERROR_SUCCESS;
3430 /***********************************************************************
3431 * MsiGetShortcutTargetA [MSI.@]
3433 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3434 LPSTR szProductCode, LPSTR szFeatureId,
3435 LPSTR szComponentCode )
3437 LPWSTR target;
3438 const int len = MAX_FEATURE_CHARS+1;
3439 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3440 UINT r;
3442 target = strdupAtoW( szShortcutTarget );
3443 if (szShortcutTarget && !target )
3444 return ERROR_OUTOFMEMORY;
3445 product[0] = 0;
3446 feature[0] = 0;
3447 component[0] = 0;
3448 r = MsiGetShortcutTargetW( target, product, feature, component );
3449 msi_free( target );
3450 if (r == ERROR_SUCCESS)
3452 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3453 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3454 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3456 return r;
3459 /***********************************************************************
3460 * MsiGetShortcutTargetW [MSI.@]
3462 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3463 LPWSTR szProductCode, LPWSTR szFeatureId,
3464 LPWSTR szComponentCode )
3466 IShellLinkDataList *dl = NULL;
3467 IPersistFile *pf = NULL;
3468 LPEXP_DARWIN_LINK darwin = NULL;
3469 HRESULT r, init;
3471 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3472 szProductCode, szFeatureId, szComponentCode );
3474 init = CoInitialize(NULL);
3476 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3477 &IID_IPersistFile, (LPVOID*) &pf );
3478 if( SUCCEEDED( r ) )
3480 r = IPersistFile_Load( pf, szShortcutTarget,
3481 STGM_READ | STGM_SHARE_DENY_WRITE );
3482 if( SUCCEEDED( r ) )
3484 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3485 (LPVOID*) &dl );
3486 if( SUCCEEDED( r ) )
3488 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3489 (LPVOID) &darwin );
3490 IShellLinkDataList_Release( dl );
3493 IPersistFile_Release( pf );
3496 if (SUCCEEDED(init))
3497 CoUninitialize();
3499 TRACE("darwin = %p\n", darwin);
3501 if (darwin)
3503 DWORD sz;
3504 UINT ret;
3506 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3507 szProductCode, szFeatureId, szComponentCode, &sz );
3508 LocalFree( darwin );
3509 return ret;
3512 return ERROR_FUNCTION_FAILED;
3515 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3516 DWORD dwReinstallMode )
3518 MSIPACKAGE* package = NULL;
3519 UINT r;
3520 WCHAR sourcepath[MAX_PATH];
3521 WCHAR filename[MAX_PATH];
3522 static const WCHAR szLogVerbose[] = {
3523 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3524 WCHAR reinstallmode[11];
3525 LPWSTR ptr;
3526 DWORD sz;
3528 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3529 dwReinstallMode);
3531 ptr = reinstallmode;
3533 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3534 *ptr++ = 'p';
3535 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3536 *ptr++ = 'o';
3537 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3538 *ptr++ = 'w';
3539 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3540 *ptr++ = 'd';
3541 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3542 *ptr++ = 'c';
3543 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3544 *ptr++ = 'a';
3545 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3546 *ptr++ = 'u';
3547 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3548 *ptr++ = 'm';
3549 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3550 *ptr++ = 's';
3551 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3552 *ptr++ = 'v';
3553 *ptr = 0;
3555 sz = sizeof(sourcepath);
3556 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3557 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3559 sz = sizeof(filename);
3560 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3561 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3563 lstrcatW( sourcepath, filename );
3565 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3566 r = MSI_OpenPackageW( sourcepath, &package );
3567 else
3568 r = MSI_OpenProductW( szProduct, &package );
3570 if (r != ERROR_SUCCESS)
3571 return r;
3573 msi_set_property( package->db, szReinstallMode, reinstallmode );
3574 msi_set_property( package->db, szInstalled, szOne );
3575 msi_set_property( package->db, szLogVerbose, szOne );
3576 msi_set_property( package->db, szReinstall, szFeature );
3578 r = MSI_InstallPackage( package, sourcepath, NULL );
3580 msiobj_release( &package->hdr );
3582 return r;
3585 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3586 DWORD dwReinstallMode )
3588 LPWSTR wszProduct;
3589 LPWSTR wszFeature;
3590 UINT rc;
3592 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3593 dwReinstallMode);
3595 wszProduct = strdupAtoW(szProduct);
3596 wszFeature = strdupAtoW(szFeature);
3598 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3600 msi_free(wszProduct);
3601 msi_free(wszFeature);
3602 return rc;
3605 typedef struct
3607 unsigned int i[2];
3608 unsigned int buf[4];
3609 unsigned char in[64];
3610 unsigned char digest[16];
3611 } MD5_CTX;
3613 extern VOID WINAPI MD5Init( MD5_CTX *);
3614 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3615 extern VOID WINAPI MD5Final( MD5_CTX *);
3617 /***********************************************************************
3618 * MsiGetFileHashW [MSI.@]
3620 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3621 PMSIFILEHASHINFO pHash )
3623 HANDLE handle, mapping;
3624 void *p;
3625 DWORD length;
3626 UINT r = ERROR_FUNCTION_FAILED;
3628 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3630 if (!szFilePath)
3631 return ERROR_INVALID_PARAMETER;
3633 if (!*szFilePath)
3634 return ERROR_PATH_NOT_FOUND;
3636 if (dwOptions)
3637 return ERROR_INVALID_PARAMETER;
3638 if (!pHash)
3639 return ERROR_INVALID_PARAMETER;
3640 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3641 return ERROR_INVALID_PARAMETER;
3643 handle = CreateFileW( szFilePath, GENERIC_READ,
3644 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3645 if (handle == INVALID_HANDLE_VALUE)
3646 return ERROR_FILE_NOT_FOUND;
3648 length = GetFileSize( handle, NULL );
3650 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3651 if (mapping)
3653 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3654 if (p)
3656 MD5_CTX ctx;
3658 MD5Init( &ctx );
3659 MD5Update( &ctx, p, length );
3660 MD5Final( &ctx );
3661 UnmapViewOfFile( p );
3663 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3664 r = ERROR_SUCCESS;
3666 CloseHandle( mapping );
3668 CloseHandle( handle );
3670 return r;
3673 /***********************************************************************
3674 * MsiGetFileHashA [MSI.@]
3676 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3677 PMSIFILEHASHINFO pHash )
3679 LPWSTR file;
3680 UINT r;
3682 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3684 file = strdupAtoW( szFilePath );
3685 if (szFilePath && !file)
3686 return ERROR_OUTOFMEMORY;
3688 r = MsiGetFileHashW( file, dwOptions, pHash );
3689 msi_free( file );
3690 return r;
3693 /***********************************************************************
3694 * MsiAdvertiseScriptW [MSI.@]
3696 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3697 PHKEY phRegData, BOOL fRemoveItems )
3699 FIXME("%s %08x %p %d\n",
3700 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3701 return ERROR_CALL_NOT_IMPLEMENTED;
3704 /***********************************************************************
3705 * MsiAdvertiseScriptA [MSI.@]
3707 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3708 PHKEY phRegData, BOOL fRemoveItems )
3710 FIXME("%s %08x %p %d\n",
3711 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3712 return ERROR_CALL_NOT_IMPLEMENTED;
3715 /***********************************************************************
3716 * MsiIsProductElevatedW [MSI.@]
3718 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3720 FIXME("%s %p - stub\n",
3721 debugstr_w( szProduct ), pfElevated );
3722 *pfElevated = TRUE;
3723 return ERROR_SUCCESS;
3726 /***********************************************************************
3727 * MsiIsProductElevatedA [MSI.@]
3729 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3731 FIXME("%s %p - stub\n",
3732 debugstr_a( szProduct ), pfElevated );
3733 *pfElevated = TRUE;
3734 return ERROR_SUCCESS;
3737 /***********************************************************************
3738 * MsiSetExternalUIRecord [MSI.@]
3740 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
3741 DWORD filter, LPVOID context,
3742 PINSTALLUI_HANDLER_RECORD prev )
3744 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
3746 if (prev)
3747 *prev = gUIHandlerRecord;
3749 gUIHandlerRecord = handler;
3750 gUIFilter = filter;
3751 gUIContext = context;
3753 return ERROR_SUCCESS;
3756 /***********************************************************************
3757 * MsiInstallMissingComponentW [MSI.@]
3759 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
3761 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
3762 return ERROR_SUCCESS;