push 1d8ffbc7e5e31cb02d564185c2f7d29830c376df
[wine/hacks.git] / dlls / msi / msi.c
blob9d8a88a48fea170e50190e9fe0b0cf49fb6dba32
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 msiobj_release( &patch_db->hdr );
545 return ERROR_FUNCTION_FAILED;
548 r = msi_check_patch_applicable( package, si );
549 if (r != ERROR_SUCCESS)
550 TRACE("patch not applicable\n");
552 msiobj_release( &patch_db->hdr );
553 msiobj_release( &si->hdr );
554 return r;
557 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
558 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
560 UINT i, r, ret = ERROR_FUNCTION_FAILED;
561 MSIPACKAGE *package;
563 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
565 r = MSI_OpenPackageW( szProductPackagePath, &package );
566 if (r != ERROR_SUCCESS)
568 ERR("failed to open package %u\n", r);
569 return r;
572 for (i = 0; i < cPatchInfo; i++)
574 switch (pPatchInfo[i].ePatchDataType)
576 case MSIPATCH_DATATYPE_PATCHFILE:
578 FIXME("patch ordering not supported\n");
579 r = MSI_ApplicablePatchW( package, pPatchInfo[i].szPatchData );
580 if (r != ERROR_SUCCESS)
582 pPatchInfo[i].dwOrder = ~0u;
583 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
585 else
587 pPatchInfo[i].dwOrder = i;
588 pPatchInfo[i].uStatus = ret = ERROR_SUCCESS;
590 break;
592 default:
594 FIXME("patch data type %u not supported\n", pPatchInfo[i].ePatchDataType);
595 pPatchInfo[i].dwOrder = ~0u;
596 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
597 break;
601 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo[i].szPatchData));
602 TRACE("ePatchDataType: %u\n", pPatchInfo[i].ePatchDataType);
603 TRACE(" dwOrder: %u\n", pPatchInfo[i].dwOrder);
604 TRACE(" uStatus: %u\n", pPatchInfo[i].uStatus);
606 return ret;
609 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
610 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
612 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
613 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
615 return ERROR_CALL_NOT_IMPLEMENTED;
618 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
619 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
621 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
622 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
624 return ERROR_CALL_NOT_IMPLEMENTED;
627 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
628 MSIPACKAGE **package)
630 UINT r;
631 DWORD sz;
632 HKEY props;
633 LPWSTR localpack;
634 WCHAR sourcepath[MAX_PATH];
635 WCHAR filename[MAX_PATH];
637 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
638 if (r != ERROR_SUCCESS)
639 return ERROR_BAD_CONFIGURATION;
641 localpack = msi_reg_get_val_str(props, szLocalPackage);
642 if (localpack)
644 lstrcpyW(sourcepath, localpack);
645 msi_free(localpack);
648 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
650 sz = sizeof(sourcepath);
651 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
652 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
654 sz = sizeof(filename);
655 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
656 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
658 lstrcatW(sourcepath, filename);
661 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
662 return ERROR_INSTALL_SOURCE_ABSENT;
664 return MSI_OpenPackageW(sourcepath, package);
667 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
668 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
670 MSIPACKAGE* package = NULL;
671 MSIINSTALLCONTEXT context;
672 UINT r;
673 DWORD sz;
674 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
675 LPWSTR commandline;
677 static const WCHAR szInstalled[] = {
678 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
679 static const WCHAR szRemoveAll[] = {
680 ' ','R','E','M','O','V','E','=','A','L','L',0};
681 static const WCHAR szMachine[] = {
682 ' ','A','L','L','U','S','E','R','S','=','1',0};
684 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
685 debugstr_w(szCommandLine));
687 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
688 return ERROR_INVALID_PARAMETER;
690 if (eInstallState == INSTALLSTATE_ADVERTISED ||
691 eInstallState == INSTALLSTATE_SOURCE)
693 FIXME("State %d not implemented\n", eInstallState);
694 return ERROR_CALL_NOT_IMPLEMENTED;
697 r = msi_locate_product(szProduct, &context);
698 if (r != ERROR_SUCCESS)
699 return r;
701 r = msi_open_package(szProduct, context, &package);
702 if (r != ERROR_SUCCESS)
703 return r;
705 sz = lstrlenW(szInstalled) + 1;
707 if (szCommandLine)
708 sz += lstrlenW(szCommandLine);
710 if (eInstallState == INSTALLSTATE_ABSENT)
711 sz += lstrlenW(szRemoveAll);
713 if (context == MSIINSTALLCONTEXT_MACHINE)
714 sz += lstrlenW(szMachine);
716 commandline = msi_alloc(sz * sizeof(WCHAR));
717 if (!commandline)
719 r = ERROR_OUTOFMEMORY;
720 goto end;
723 commandline[0] = 0;
724 if (szCommandLine)
725 lstrcpyW(commandline,szCommandLine);
727 if (eInstallState == INSTALLSTATE_ABSENT)
728 lstrcatW(commandline, szRemoveAll);
730 if (context == MSIINSTALLCONTEXT_MACHINE)
731 lstrcatW(commandline, szMachine);
733 sz = sizeof(sourcepath);
734 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
735 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
737 sz = sizeof(filename);
738 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
739 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
741 strcatW(sourcepath, filename);
743 r = MSI_InstallPackage( package, sourcepath, commandline );
745 msi_free(commandline);
747 end:
748 msiobj_release( &package->hdr );
750 return r;
753 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
754 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
756 LPWSTR szwProduct = NULL;
757 LPWSTR szwCommandLine = NULL;
758 UINT r = ERROR_OUTOFMEMORY;
760 if( szProduct )
762 szwProduct = strdupAtoW( szProduct );
763 if( !szwProduct )
764 goto end;
767 if( szCommandLine)
769 szwCommandLine = strdupAtoW( szCommandLine );
770 if( !szwCommandLine)
771 goto end;
774 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
775 szwCommandLine );
776 end:
777 msi_free( szwProduct );
778 msi_free( szwCommandLine);
780 return r;
783 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
784 INSTALLSTATE eInstallState)
786 LPWSTR szwProduct = NULL;
787 UINT r;
789 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
791 if( szProduct )
793 szwProduct = strdupAtoW( szProduct );
794 if( !szwProduct )
795 return ERROR_OUTOFMEMORY;
798 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
799 msi_free( szwProduct );
801 return r;
804 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
805 INSTALLSTATE eInstallState)
807 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
810 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
812 LPWSTR szwComponent = NULL;
813 UINT r;
814 WCHAR szwBuffer[GUID_SIZE];
816 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
818 if( szComponent )
820 szwComponent = strdupAtoW( szComponent );
821 if( !szwComponent )
822 return ERROR_OUTOFMEMORY;
825 *szwBuffer = '\0';
826 r = MsiGetProductCodeW( szwComponent, szwBuffer );
828 if(*szwBuffer)
829 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
831 msi_free( szwComponent );
833 return r;
836 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
838 UINT rc, index;
839 HKEY compkey, prodkey;
840 WCHAR squished_comp[GUID_SIZE];
841 WCHAR squished_prod[GUID_SIZE];
842 DWORD sz = GUID_SIZE;
844 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
846 if (!szComponent || !*szComponent)
847 return ERROR_INVALID_PARAMETER;
849 if (!squash_guid(szComponent, squished_comp))
850 return ERROR_INVALID_PARAMETER;
852 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
853 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
855 return ERROR_UNKNOWN_COMPONENT;
858 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
859 if (rc != ERROR_SUCCESS)
861 RegCloseKey(compkey);
862 return ERROR_UNKNOWN_COMPONENT;
865 /* check simple case, only one product */
866 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
867 if (rc == ERROR_NO_MORE_ITEMS)
869 rc = ERROR_SUCCESS;
870 goto done;
873 index = 0;
874 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
875 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
877 index++;
878 sz = GUID_SIZE;
879 unsquash_guid(squished_prod, szBuffer);
881 if (MSIREG_OpenProductKey(szBuffer, NULL,
882 MSIINSTALLCONTEXT_USERMANAGED,
883 &prodkey, FALSE) == ERROR_SUCCESS ||
884 MSIREG_OpenProductKey(szBuffer, NULL,
885 MSIINSTALLCONTEXT_USERUNMANAGED,
886 &prodkey, FALSE) == ERROR_SUCCESS ||
887 MSIREG_OpenProductKey(szBuffer, NULL,
888 MSIINSTALLCONTEXT_MACHINE,
889 &prodkey, FALSE) == ERROR_SUCCESS)
891 RegCloseKey(prodkey);
892 rc = ERROR_SUCCESS;
893 goto done;
897 rc = ERROR_INSTALL_FAILURE;
899 done:
900 RegCloseKey(compkey);
901 unsquash_guid(squished_prod, szBuffer);
902 return rc;
905 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
907 DWORD dval;
908 LONG res;
909 WCHAR temp[20];
911 static const WCHAR format[] = {'%','d',0};
913 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
914 if (res != ERROR_SUCCESS)
915 return NULL;
917 if (*type == REG_SZ)
918 return msi_reg_get_val_str(hkey, name);
920 if (!msi_reg_get_val_dword(hkey, name, &dval))
921 return NULL;
923 sprintfW(temp, format, dval);
924 return strdupW(temp);
927 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
928 awstring *szValue, LPDWORD pcchValueBuf)
930 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
931 UINT r = ERROR_UNKNOWN_PROPERTY;
932 HKEY prodkey, userdata, source;
933 LPWSTR val = NULL;
934 WCHAR squished_pc[GUID_SIZE];
935 WCHAR packagecode[GUID_SIZE];
936 BOOL badconfig = FALSE;
937 LONG res;
938 DWORD type = REG_NONE;
940 static WCHAR empty[] = {0};
941 static const WCHAR sourcelist[] = {
942 'S','o','u','r','c','e','L','i','s','t',0};
943 static const WCHAR display_name[] = {
944 'D','i','s','p','l','a','y','N','a','m','e',0};
945 static const WCHAR display_version[] = {
946 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
947 static const WCHAR assignment[] = {
948 'A','s','s','i','g','n','m','e','n','t',0};
950 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
951 debugstr_w(szAttribute), szValue, pcchValueBuf);
953 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
954 return ERROR_INVALID_PARAMETER;
956 if (!squash_guid(szProduct, squished_pc))
957 return ERROR_INVALID_PARAMETER;
959 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
960 MSIINSTALLCONTEXT_USERMANAGED,
961 &prodkey, FALSE)) != ERROR_SUCCESS &&
962 (r = MSIREG_OpenProductKey(szProduct, NULL,
963 MSIINSTALLCONTEXT_USERUNMANAGED,
964 &prodkey, FALSE)) != ERROR_SUCCESS &&
965 (r = MSIREG_OpenProductKey(szProduct, NULL,
966 MSIINSTALLCONTEXT_MACHINE,
967 &prodkey, FALSE)) == ERROR_SUCCESS)
969 context = MSIINSTALLCONTEXT_MACHINE;
972 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
974 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
975 !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
976 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLDATEW) ||
977 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
978 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW) ||
979 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLSOURCEW) ||
980 !lstrcmpW(szAttribute, INSTALLPROPERTY_LOCALPACKAGEW) ||
981 !lstrcmpW(szAttribute, INSTALLPROPERTY_PUBLISHERW) ||
982 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLINFOABOUTW) ||
983 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLUPDATEINFOW) ||
984 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMINORW) ||
985 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMAJORW) ||
986 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW) ||
987 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTIDW) ||
988 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGCOMPANYW) ||
989 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGOWNERW))
991 if (!prodkey)
993 r = ERROR_UNKNOWN_PRODUCT;
994 goto done;
997 if (!userdata)
998 return ERROR_UNKNOWN_PROPERTY;
1000 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
1001 szAttribute = display_name;
1002 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW))
1003 szAttribute = display_version;
1005 val = msi_reg_get_value(userdata, szAttribute, &type);
1006 if (!val)
1007 val = empty;
1009 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTANCETYPEW) ||
1010 !lstrcmpW(szAttribute, INSTALLPROPERTY_TRANSFORMSW) ||
1011 !lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
1012 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW) ||
1013 !lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW) ||
1014 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW) ||
1015 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW) ||
1016 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTICONW) ||
1017 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW) ||
1018 !lstrcmpW(szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1020 if (!prodkey)
1022 r = ERROR_UNKNOWN_PRODUCT;
1023 goto done;
1026 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1027 szAttribute = assignment;
1029 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW))
1031 res = RegOpenKeyW(prodkey, sourcelist, &source);
1032 if (res != ERROR_SUCCESS)
1034 r = ERROR_UNKNOWN_PRODUCT;
1035 goto done;
1038 val = msi_reg_get_value(source, szAttribute, &type);
1039 if (!val)
1040 val = empty;
1042 RegCloseKey(source);
1044 else
1046 val = msi_reg_get_value(prodkey, szAttribute, &type);
1047 if (!val)
1048 val = empty;
1051 if (val != empty && type != REG_DWORD &&
1052 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
1054 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1055 badconfig = TRUE;
1056 else
1058 unsquash_guid(val, packagecode);
1059 msi_free(val);
1060 val = strdupW(packagecode);
1065 if (!val)
1067 r = ERROR_UNKNOWN_PROPERTY;
1068 goto done;
1071 if (pcchValueBuf)
1073 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1074 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1075 * can't rely on its value.
1077 if (szValue->str.a || szValue->str.w)
1079 DWORD size = *pcchValueBuf;
1080 if (strlenW(val) < size)
1081 r = msi_strcpy_to_awstring(val, szValue, &size);
1082 else
1084 r = ERROR_MORE_DATA;
1088 if (!badconfig)
1089 *pcchValueBuf = lstrlenW(val);
1092 if (badconfig)
1093 r = ERROR_BAD_CONFIGURATION;
1095 if (val != empty)
1096 msi_free(val);
1098 done:
1099 RegCloseKey(prodkey);
1100 RegCloseKey(userdata);
1101 return r;
1104 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1105 LPSTR szBuffer, LPDWORD pcchValueBuf)
1107 LPWSTR szwProduct, szwAttribute = NULL;
1108 UINT r = ERROR_OUTOFMEMORY;
1109 awstring buffer;
1111 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1112 szBuffer, pcchValueBuf);
1114 szwProduct = strdupAtoW( szProduct );
1115 if( szProduct && !szwProduct )
1116 goto end;
1118 szwAttribute = strdupAtoW( szAttribute );
1119 if( szAttribute && !szwAttribute )
1120 goto end;
1122 buffer.unicode = FALSE;
1123 buffer.str.a = szBuffer;
1125 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1126 &buffer, pcchValueBuf );
1128 end:
1129 msi_free( szwProduct );
1130 msi_free( szwAttribute );
1132 return r;
1135 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1136 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1138 awstring buffer;
1140 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1141 szBuffer, pcchValueBuf);
1143 buffer.unicode = TRUE;
1144 buffer.str.w = szBuffer;
1146 return MSI_GetProductInfo( szProduct, szAttribute,
1147 &buffer, pcchValueBuf );
1150 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1151 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1152 LPSTR szValue, LPDWORD pcchValue)
1154 LPWSTR product = NULL;
1155 LPWSTR usersid = NULL;
1156 LPWSTR property = NULL;
1157 LPWSTR value = NULL;
1158 DWORD len = 0;
1159 UINT r;
1161 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1162 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1163 szValue, pcchValue);
1165 if (szValue && !pcchValue)
1166 return ERROR_INVALID_PARAMETER;
1168 if (szProductCode) product = strdupAtoW(szProductCode);
1169 if (szUserSid) usersid = strdupAtoW(szUserSid);
1170 if (szProperty) property = strdupAtoW(szProperty);
1172 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1173 NULL, &len);
1174 if (r != ERROR_SUCCESS)
1175 goto done;
1177 value = msi_alloc(++len * sizeof(WCHAR));
1178 if (!value)
1180 r = ERROR_OUTOFMEMORY;
1181 goto done;
1184 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1185 value, &len);
1186 if (r != ERROR_SUCCESS)
1187 goto done;
1189 if (!pcchValue)
1190 goto done;
1192 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1193 if (*pcchValue >= len)
1194 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1195 else if (szValue)
1197 r = ERROR_MORE_DATA;
1198 if (*pcchValue > 0)
1199 *szValue = '\0';
1202 if (*pcchValue <= len || !szValue)
1203 len = len * sizeof(WCHAR) - 1;
1205 *pcchValue = len - 1;
1207 done:
1208 msi_free(product);
1209 msi_free(usersid);
1210 msi_free(property);
1211 msi_free(value);
1213 return r;
1216 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1218 UINT r = ERROR_SUCCESS;
1220 if (!val)
1221 return ERROR_UNKNOWN_PROPERTY;
1223 if (out)
1225 if (strlenW(val) >= *size)
1227 r = ERROR_MORE_DATA;
1228 if (*size > 0)
1229 *out = '\0';
1231 else
1232 lstrcpyW(out, val);
1235 if (size)
1236 *size = lstrlenW(val);
1238 return r;
1241 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1242 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1243 LPWSTR szValue, LPDWORD pcchValue)
1245 WCHAR squished_pc[GUID_SIZE];
1246 LPWSTR val = NULL;
1247 LPCWSTR package = NULL;
1248 HKEY props = NULL, prod;
1249 HKEY classes = NULL, managed;
1250 HKEY hkey = NULL;
1251 DWORD type;
1252 UINT r = ERROR_UNKNOWN_PRODUCT;
1254 static const WCHAR five[] = {'5',0};
1255 static const WCHAR displayname[] = {
1256 'D','i','s','p','l','a','y','N','a','m','e',0};
1257 static const WCHAR displayversion[] = {
1258 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1259 static const WCHAR managed_local_package[] = {
1260 'M','a','n','a','g','e','d','L','o','c','a','l',
1261 'P','a','c','k','a','g','e',0};
1263 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1264 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1265 szValue, pcchValue);
1267 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1268 return ERROR_INVALID_PARAMETER;
1270 if (szValue && !pcchValue)
1271 return ERROR_INVALID_PARAMETER;
1273 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1274 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1275 dwContext != MSIINSTALLCONTEXT_MACHINE)
1276 return ERROR_INVALID_PARAMETER;
1278 if (!szProperty || !*szProperty)
1279 return ERROR_INVALID_PARAMETER;
1281 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1282 return ERROR_INVALID_PARAMETER;
1284 /* FIXME: dwContext is provided, no need to search for it */
1285 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1286 &managed, FALSE);
1287 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1288 &prod, FALSE);
1290 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1292 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1294 package = INSTALLPROPERTY_LOCALPACKAGEW;
1296 if (!props && !prod)
1297 goto done;
1299 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1301 package = managed_local_package;
1303 if (!props && !managed)
1304 goto done;
1306 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1308 package = INSTALLPROPERTY_LOCALPACKAGEW;
1309 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1311 if (!props && !classes)
1312 goto done;
1315 if (!lstrcmpW(szProperty, INSTALLPROPERTY_HELPLINKW) ||
1316 !lstrcmpW(szProperty, INSTALLPROPERTY_HELPTELEPHONEW) ||
1317 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW) ||
1318 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
1319 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLLOCATIONW) ||
1320 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLSOURCEW) ||
1321 !lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW) ||
1322 !lstrcmpW(szProperty, INSTALLPROPERTY_PUBLISHERW) ||
1323 !lstrcmpW(szProperty, INSTALLPROPERTY_URLINFOABOUTW) ||
1324 !lstrcmpW(szProperty, INSTALLPROPERTY_URLUPDATEINFOW) ||
1325 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMINORW) ||
1326 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMAJORW) ||
1327 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW) ||
1328 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTIDW) ||
1329 !lstrcmpW(szProperty, INSTALLPROPERTY_REGCOMPANYW) ||
1330 !lstrcmpW(szProperty, INSTALLPROPERTY_REGOWNERW) ||
1331 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTANCETYPEW))
1333 val = msi_reg_get_value(props, package, &type);
1334 if (!val)
1336 if (prod || classes)
1337 r = ERROR_UNKNOWN_PROPERTY;
1339 goto done;
1342 msi_free(val);
1344 if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
1345 szProperty = displayname;
1346 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW))
1347 szProperty = displayversion;
1349 val = msi_reg_get_value(props, szProperty, &type);
1350 if (!val)
1351 val = strdupW(szEmpty);
1353 r = msi_copy_outval(val, szValue, pcchValue);
1355 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW) ||
1356 !lstrcmpW(szProperty, INSTALLPROPERTY_LANGUAGEW) ||
1357 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTNAMEW) ||
1358 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGECODEW) ||
1359 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONW) ||
1360 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTICONW) ||
1361 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGENAMEW) ||
1362 !lstrcmpW(szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1364 if (!prod && !classes)
1365 goto done;
1367 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1368 hkey = prod;
1369 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1370 hkey = managed;
1371 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1372 hkey = classes;
1374 val = msi_reg_get_value(hkey, szProperty, &type);
1375 if (!val)
1376 val = strdupW(szEmpty);
1378 r = msi_copy_outval(val, szValue, pcchValue);
1380 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTSTATEW))
1382 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1384 if (props)
1386 val = msi_reg_get_value(props, package, &type);
1387 if (!val)
1388 goto done;
1390 msi_free(val);
1391 val = strdupW(five);
1393 else
1394 val = strdupW(szOne);
1396 r = msi_copy_outval(val, szValue, pcchValue);
1397 goto done;
1399 else if (props && (val = msi_reg_get_value(props, package, &type)))
1401 msi_free(val);
1402 val = strdupW(five);
1403 r = msi_copy_outval(val, szValue, pcchValue);
1404 goto done;
1407 if (prod || managed)
1408 val = strdupW(szOne);
1409 else
1410 goto done;
1412 r = msi_copy_outval(val, szValue, pcchValue);
1414 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1416 if (!prod && !classes)
1417 goto done;
1419 /* FIXME */
1420 val = strdupW(szEmpty);
1421 r = msi_copy_outval(val, szValue, pcchValue);
1423 else
1424 r = ERROR_UNKNOWN_PROPERTY;
1426 done:
1427 RegCloseKey(props);
1428 RegCloseKey(prod);
1429 RegCloseKey(managed);
1430 RegCloseKey(classes);
1431 msi_free(val);
1433 return r;
1436 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1437 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1438 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1440 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1441 LPWSTR property = NULL, val = NULL;
1442 DWORD len;
1443 UINT r;
1445 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1446 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1447 debugstr_a(szProperty), lpValue, pcchValue);
1449 if (lpValue && !pcchValue)
1450 return ERROR_INVALID_PARAMETER;
1452 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1453 if (szProductCode) product = strdupAtoW(szProductCode);
1454 if (szUserSid) usersid = strdupAtoW(szUserSid);
1455 if (szProperty) property = strdupAtoW(szProperty);
1457 len = 0;
1458 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1459 NULL, &len);
1460 if (r != ERROR_SUCCESS)
1461 goto done;
1463 val = msi_alloc(++len * sizeof(WCHAR));
1464 if (!val)
1466 r = ERROR_OUTOFMEMORY;
1467 goto done;
1470 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1471 val, &len);
1472 if (r != ERROR_SUCCESS || !pcchValue)
1473 goto done;
1475 if (lpValue)
1476 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1477 *pcchValue - 1, NULL, NULL);
1479 len = lstrlenW(val);
1480 if ((*val && *pcchValue < len + 1) || !lpValue)
1482 if (lpValue)
1484 r = ERROR_MORE_DATA;
1485 lpValue[*pcchValue - 1] = '\0';
1488 *pcchValue = len * sizeof(WCHAR);
1490 else
1491 *pcchValue = len;
1493 done:
1494 msi_free(val);
1495 msi_free(patch);
1496 msi_free(product);
1497 msi_free(usersid);
1498 msi_free(property);
1500 return r;
1503 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1504 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1505 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1507 WCHAR squished_pc[GUID_SIZE];
1508 WCHAR squished_patch[GUID_SIZE];
1509 HKEY udprod = 0, prod = 0, props = 0;
1510 HKEY patch = 0, patches = 0;
1511 HKEY udpatch = 0, datakey = 0;
1512 HKEY prodpatches = 0;
1513 LPWSTR val = NULL;
1514 UINT r = ERROR_UNKNOWN_PRODUCT;
1515 DWORD len;
1516 LONG res;
1518 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1519 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1521 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1522 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1523 debugstr_w(szProperty), lpValue, pcchValue);
1525 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1526 return ERROR_INVALID_PARAMETER;
1528 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1529 return ERROR_INVALID_PARAMETER;
1531 if (!szProperty)
1532 return ERROR_INVALID_PARAMETER;
1534 if (lpValue && !pcchValue)
1535 return ERROR_INVALID_PARAMETER;
1537 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1538 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1539 dwContext != MSIINSTALLCONTEXT_MACHINE)
1540 return ERROR_INVALID_PARAMETER;
1542 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1543 return ERROR_INVALID_PARAMETER;
1545 if (!lstrcmpW(szUserSid, szLocalSid))
1546 return ERROR_INVALID_PARAMETER;
1548 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1549 &udprod, FALSE) != ERROR_SUCCESS)
1550 goto done;
1552 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1553 &props, FALSE) != ERROR_SUCCESS)
1554 goto done;
1556 r = ERROR_UNKNOWN_PATCH;
1558 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_READ, &patches);
1559 if (res != ERROR_SUCCESS)
1560 goto done;
1562 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_READ, &patch);
1563 if (res != ERROR_SUCCESS)
1564 goto done;
1566 if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW))
1568 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1569 &prod, FALSE) != ERROR_SUCCESS)
1570 goto done;
1572 res = RegOpenKeyExW(prod, szPatches, 0, KEY_ALL_ACCESS, &prodpatches);
1573 if (res != ERROR_SUCCESS)
1574 goto done;
1576 datakey = prodpatches;
1577 szProperty = squished_patch;
1579 else
1581 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1582 &udpatch, FALSE) != ERROR_SUCCESS)
1583 goto done;
1585 if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1587 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1588 szProperty = szManagedPackage;
1589 datakey = udpatch;
1591 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW))
1593 datakey = patch;
1594 szProperty = szInstalled;
1596 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1598 datakey = udpatch;
1600 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_UNINSTALLABLEW) ||
1601 !lstrcmpW(szProperty, INSTALLPROPERTY_PATCHSTATEW) ||
1602 !lstrcmpW(szProperty, INSTALLPROPERTY_DISPLAYNAMEW) ||
1603 !lstrcmpW(szProperty, INSTALLPROPERTY_MOREINFOURLW))
1605 datakey = patch;
1607 else
1609 r = ERROR_UNKNOWN_PROPERTY;
1610 goto done;
1614 val = msi_reg_get_val_str(datakey, szProperty);
1615 if (!val)
1616 val = strdupW(szEmpty);
1618 r = ERROR_SUCCESS;
1620 if (!pcchValue)
1621 goto done;
1623 if (lpValue)
1624 lstrcpynW(lpValue, val, *pcchValue);
1626 len = lstrlenW(val);
1627 if ((*val && *pcchValue < len + 1) || !lpValue)
1629 if (lpValue)
1630 r = ERROR_MORE_DATA;
1632 *pcchValue = len * sizeof(WCHAR);
1635 *pcchValue = len;
1637 done:
1638 msi_free(val);
1639 RegCloseKey(prodpatches);
1640 RegCloseKey(prod);
1641 RegCloseKey(patch);
1642 RegCloseKey(patches);
1643 RegCloseKey(udpatch);
1644 RegCloseKey(props);
1645 RegCloseKey(udprod);
1647 return r;
1650 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1652 UINT r = ERROR_OUTOFMEMORY;
1653 DWORD size;
1654 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1656 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1658 if (!patch || !attr)
1659 return ERROR_INVALID_PARAMETER;
1661 if (!(patchW = strdupAtoW( patch )))
1662 goto done;
1664 if (!(attrW = strdupAtoW( attr )))
1665 goto done;
1667 size = 0;
1668 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1669 if (r != ERROR_SUCCESS)
1670 goto done;
1672 size++;
1673 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1675 r = ERROR_OUTOFMEMORY;
1676 goto done;
1679 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1680 if (r == ERROR_SUCCESS)
1682 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1683 if (len > *buflen)
1684 r = ERROR_MORE_DATA;
1685 else if (buffer)
1686 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1688 *buflen = len - 1;
1691 done:
1692 msi_free( patchW );
1693 msi_free( attrW );
1694 msi_free( bufferW );
1695 return r;
1698 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1700 UINT r;
1701 WCHAR product[GUID_SIZE];
1702 DWORD index;
1704 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1706 if (!patch || !attr)
1707 return ERROR_INVALID_PARAMETER;
1709 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1710 return ERROR_UNKNOWN_PROPERTY;
1712 index = 0;
1713 while (1)
1715 r = MsiEnumProductsW( index, product );
1716 if (r != ERROR_SUCCESS)
1717 break;
1719 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1720 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1721 return r;
1723 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1724 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1725 return r;
1727 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1728 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1729 return r;
1731 index++;
1734 return ERROR_UNKNOWN_PRODUCT;
1737 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1739 LPWSTR szwLogFile = NULL;
1740 UINT r;
1742 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1744 if( szLogFile )
1746 szwLogFile = strdupAtoW( szLogFile );
1747 if( !szwLogFile )
1748 return ERROR_OUTOFMEMORY;
1750 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1751 msi_free( szwLogFile );
1752 return r;
1755 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1757 HANDLE file = INVALID_HANDLE_VALUE;
1759 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1761 if (szLogFile)
1763 lstrcpyW(gszLogFile,szLogFile);
1764 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1765 DeleteFileW(szLogFile);
1766 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
1767 FILE_ATTRIBUTE_NORMAL, NULL);
1768 if (file != INVALID_HANDLE_VALUE)
1769 CloseHandle(file);
1770 else
1771 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
1773 else
1774 gszLogFile[0] = '\0';
1776 return ERROR_SUCCESS;
1779 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
1780 DWORD dwIndex, INSTALLSTATE iState,
1781 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
1782 int *piCost, int *pTempCost)
1784 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
1785 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
1786 pcchDriveBuf, piCost, pTempCost);
1788 return ERROR_NO_MORE_ITEMS;
1791 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1792 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1793 LPCSTR szComponent, INSTALLSTATE *pdwState)
1795 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1796 UINT r;
1798 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1799 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1801 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1802 return ERROR_OUTOFMEMORY;
1804 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1805 return ERROR_OUTOFMEMORY;
1807 if (szComponent && !(comp = strdupAtoW(szComponent)))
1808 return ERROR_OUTOFMEMORY;
1810 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1812 msi_free(prodcode);
1813 msi_free(usersid);
1814 msi_free(comp);
1816 return r;
1819 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1821 UINT r;
1822 HKEY hkey;
1824 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1825 RegCloseKey(hkey);
1826 return (r == ERROR_SUCCESS);
1829 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1831 LPCWSTR package;
1832 HKEY hkey;
1833 DWORD sz;
1834 LONG res;
1835 UINT r;
1837 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1838 static const WCHAR managed_local_package[] = {
1839 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1842 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1843 if (r != ERROR_SUCCESS)
1844 return FALSE;
1846 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1847 package = managed_local_package;
1848 else
1849 package = local_package;
1851 sz = 0;
1852 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1853 RegCloseKey(hkey);
1855 return (res == ERROR_SUCCESS);
1858 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1859 MSIINSTALLCONTEXT context,
1860 LPCWSTR comp, LPWSTR val, DWORD *sz)
1862 HKEY hkey;
1863 LONG res;
1864 UINT r;
1866 if (context == MSIINSTALLCONTEXT_MACHINE)
1867 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
1868 else
1869 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
1871 if (r != ERROR_SUCCESS)
1872 return FALSE;
1874 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
1875 if (res != ERROR_SUCCESS)
1876 return FALSE;
1878 RegCloseKey(hkey);
1879 return TRUE;
1882 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
1883 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1884 LPCWSTR szComponent, INSTALLSTATE *pdwState)
1886 WCHAR squished_pc[GUID_SIZE];
1887 WCHAR val[MAX_PATH];
1888 BOOL found;
1889 DWORD sz;
1891 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
1892 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
1894 if (!pdwState || !szComponent)
1895 return ERROR_INVALID_PARAMETER;
1897 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
1898 return ERROR_INVALID_PARAMETER;
1900 if (!squash_guid(szProductCode, squished_pc))
1901 return ERROR_INVALID_PARAMETER;
1903 found = msi_comp_find_prod_key(szProductCode, dwContext);
1905 if (!msi_comp_find_package(szProductCode, dwContext))
1907 if (found)
1909 *pdwState = INSTALLSTATE_UNKNOWN;
1910 return ERROR_UNKNOWN_COMPONENT;
1913 return ERROR_UNKNOWN_PRODUCT;
1916 *pdwState = INSTALLSTATE_UNKNOWN;
1918 sz = MAX_PATH;
1919 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
1920 return ERROR_UNKNOWN_COMPONENT;
1922 if (sz == 0)
1923 *pdwState = INSTALLSTATE_NOTUSED;
1924 else
1926 if (lstrlenW(val) > 2 &&
1927 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
1929 *pdwState = INSTALLSTATE_SOURCE;
1931 else
1932 *pdwState = INSTALLSTATE_LOCAL;
1935 return ERROR_SUCCESS;
1938 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
1940 LPWSTR szwProduct = NULL;
1941 INSTALLSTATE r;
1943 if( szProduct )
1945 szwProduct = strdupAtoW( szProduct );
1946 if( !szwProduct )
1947 return ERROR_OUTOFMEMORY;
1949 r = MsiQueryProductStateW( szwProduct );
1950 msi_free( szwProduct );
1951 return r;
1954 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
1956 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1957 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
1958 HKEY prodkey = 0, userdata = 0;
1959 DWORD val;
1960 UINT r;
1962 static const WCHAR szWindowsInstaller[] = {
1963 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1965 TRACE("%s\n", debugstr_w(szProduct));
1967 if (!szProduct || !*szProduct)
1968 return INSTALLSTATE_INVALIDARG;
1970 if (lstrlenW(szProduct) != GUID_SIZE - 1)
1971 return INSTALLSTATE_INVALIDARG;
1973 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1974 &prodkey, FALSE) != ERROR_SUCCESS &&
1975 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1976 &prodkey, FALSE) != ERROR_SUCCESS &&
1977 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
1978 &prodkey, FALSE) == ERROR_SUCCESS)
1980 context = MSIINSTALLCONTEXT_MACHINE;
1983 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
1984 if (r != ERROR_SUCCESS)
1985 goto done;
1987 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
1988 goto done;
1990 if (val)
1991 state = INSTALLSTATE_DEFAULT;
1992 else
1993 state = INSTALLSTATE_UNKNOWN;
1995 done:
1996 if (!prodkey)
1998 state = INSTALLSTATE_UNKNOWN;
2000 if (userdata)
2001 state = INSTALLSTATE_ABSENT;
2004 RegCloseKey(prodkey);
2005 RegCloseKey(userdata);
2006 return state;
2009 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2011 INSTALLUILEVEL old = gUILevel;
2012 HWND oldwnd = gUIhwnd;
2014 TRACE("%08x %p\n", dwUILevel, phWnd);
2016 gUILevel = dwUILevel;
2017 if (phWnd)
2019 gUIhwnd = *phWnd;
2020 *phWnd = oldwnd;
2022 return old;
2025 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2026 DWORD dwMessageFilter, LPVOID pvContext)
2028 INSTALLUI_HANDLERA prev = gUIHandlerA;
2030 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2032 gUIHandlerA = puiHandler;
2033 gUIHandlerW = NULL;
2034 gUIFilter = dwMessageFilter;
2035 gUIContext = pvContext;
2037 return prev;
2040 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2041 DWORD dwMessageFilter, LPVOID pvContext)
2043 INSTALLUI_HANDLERW prev = gUIHandlerW;
2045 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2047 gUIHandlerA = NULL;
2048 gUIHandlerW = puiHandler;
2049 gUIFilter = dwMessageFilter;
2050 gUIContext = pvContext;
2052 return prev;
2055 /******************************************************************
2056 * MsiLoadStringW [MSI.@]
2058 * Loads a string from MSI's string resources.
2060 * PARAMS
2062 * handle [I] only -1 is handled currently
2063 * id [I] id of the string to be loaded
2064 * lpBuffer [O] buffer for the string to be written to
2065 * nBufferMax [I] maximum size of the buffer in characters
2066 * lang [I] the preferred language for the string
2068 * RETURNS
2070 * If successful, this function returns the language id of the string loaded
2071 * If the function fails, the function returns zero.
2073 * NOTES
2075 * The type of the first parameter is unknown. LoadString's prototype
2076 * suggests that it might be a module handle. I have made it an MSI handle
2077 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2078 * handle. Maybe strings can be stored in an MSI database somehow.
2080 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2081 int nBufferMax, LANGID lang )
2083 HRSRC hres;
2084 HGLOBAL hResData;
2085 LPWSTR p;
2086 DWORD i, len;
2088 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2090 if( handle != -1 )
2091 FIXME("don't know how to deal with handle = %08x\n", handle);
2093 if( !lang )
2094 lang = GetUserDefaultLangID();
2096 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2097 (LPWSTR)1, lang );
2098 if( !hres )
2099 return 0;
2100 hResData = LoadResource( msi_hInstance, hres );
2101 if( !hResData )
2102 return 0;
2103 p = LockResource( hResData );
2104 if( !p )
2105 return 0;
2107 for (i = 0; i < (id&0xf); i++)
2108 p += *p + 1;
2109 len = *p;
2111 if( nBufferMax <= len )
2112 return 0;
2114 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2115 lpBuffer[ len ] = 0;
2117 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2119 return lang;
2122 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2123 int nBufferMax, LANGID lang )
2125 LPWSTR bufW;
2126 LANGID r;
2127 INT len;
2129 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2130 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2131 if( r )
2133 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2134 if( len <= nBufferMax )
2135 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2136 lpBuffer, nBufferMax, NULL, NULL );
2137 else
2138 r = 0;
2140 msi_free(bufW);
2141 return r;
2144 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2145 LPDWORD pcchBuf)
2147 char szProduct[GUID_SIZE];
2149 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2151 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2152 return INSTALLSTATE_UNKNOWN;
2154 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2157 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2158 LPDWORD pcchBuf)
2160 WCHAR szProduct[GUID_SIZE];
2162 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2164 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2165 return INSTALLSTATE_UNKNOWN;
2167 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2170 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2171 WORD wLanguageId, DWORD f)
2173 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2174 uType, wLanguageId, f);
2175 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2178 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2179 WORD wLanguageId, DWORD f)
2181 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2182 uType, wLanguageId, f);
2183 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2186 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2187 DWORD unknown, WORD wLanguageId, DWORD f)
2189 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2190 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2191 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2194 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2195 DWORD unknown, WORD wLanguageId, DWORD f)
2197 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2198 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2199 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2202 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2203 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2204 LPDWORD pcchPathBuf )
2206 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2207 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2208 pcchPathBuf);
2209 return ERROR_CALL_NOT_IMPLEMENTED;
2212 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2213 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2214 LPDWORD pcchPathBuf )
2216 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2217 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2218 pcchPathBuf);
2219 return ERROR_CALL_NOT_IMPLEMENTED;
2222 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2223 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2225 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2226 return ERROR_CALL_NOT_IMPLEMENTED;
2229 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2230 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2232 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2233 return ERROR_CALL_NOT_IMPLEMENTED;
2236 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
2237 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2238 LPDWORD pcbHashData)
2240 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
2241 ppcCertContext, pbHashData, pcbHashData);
2242 return ERROR_CALL_NOT_IMPLEMENTED;
2245 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
2246 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2247 LPDWORD pcbHashData)
2249 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
2250 ppcCertContext, pbHashData, pcbHashData);
2251 return ERROR_CALL_NOT_IMPLEMENTED;
2254 /******************************************************************
2255 * MsiGetProductPropertyA [MSI.@]
2257 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2258 LPSTR szValue, LPDWORD pccbValue)
2260 LPWSTR prop = NULL, val = NULL;
2261 DWORD len;
2262 UINT r;
2264 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2265 szValue, pccbValue);
2267 if (szValue && !pccbValue)
2268 return ERROR_INVALID_PARAMETER;
2270 if (szProperty) prop = strdupAtoW(szProperty);
2272 len = 0;
2273 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2274 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2275 goto done;
2277 if (r == ERROR_SUCCESS)
2279 if (szValue) *szValue = '\0';
2280 if (pccbValue) *pccbValue = 0;
2281 goto done;
2284 val = msi_alloc(++len * sizeof(WCHAR));
2285 if (!val)
2287 r = ERROR_OUTOFMEMORY;
2288 goto done;
2291 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2292 if (r != ERROR_SUCCESS)
2293 goto done;
2295 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2297 if (szValue)
2298 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2299 *pccbValue, NULL, NULL);
2301 if (pccbValue)
2303 if (len > *pccbValue)
2304 r = ERROR_MORE_DATA;
2306 *pccbValue = len - 1;
2309 done:
2310 msi_free(prop);
2311 msi_free(val);
2313 return r;
2316 /******************************************************************
2317 * MsiGetProductPropertyW [MSI.@]
2319 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2320 LPWSTR szValue, LPDWORD pccbValue)
2322 MSIPACKAGE *package;
2323 MSIQUERY *view = NULL;
2324 MSIRECORD *rec = NULL;
2325 LPCWSTR val;
2326 UINT r;
2328 static const WCHAR query[] = {
2329 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2330 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2331 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2333 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2334 szValue, pccbValue);
2336 if (!szProperty)
2337 return ERROR_INVALID_PARAMETER;
2339 if (szValue && !pccbValue)
2340 return ERROR_INVALID_PARAMETER;
2342 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2343 if (!package)
2344 return ERROR_INVALID_HANDLE;
2346 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2347 if (r != ERROR_SUCCESS)
2348 goto done;
2350 r = MSI_ViewExecute(view, 0);
2351 if (r != ERROR_SUCCESS)
2352 goto done;
2354 r = MSI_ViewFetch(view, &rec);
2355 if (r != ERROR_SUCCESS)
2356 goto done;
2358 val = MSI_RecordGetString(rec, 2);
2359 if (!val)
2360 goto done;
2362 if (lstrlenW(val) >= *pccbValue)
2364 lstrcpynW(szValue, val, *pccbValue);
2365 *pccbValue = lstrlenW(val);
2366 r = ERROR_MORE_DATA;
2368 else
2370 lstrcpyW(szValue, val);
2371 *pccbValue = lstrlenW(val);
2372 r = ERROR_SUCCESS;
2375 done:
2376 if (view)
2378 MSI_ViewClose(view);
2379 msiobj_release(&view->hdr);
2380 if (rec) msiobj_release(&rec->hdr);
2383 if (!rec)
2385 if (szValue) *szValue = '\0';
2386 if (pccbValue) *pccbValue = 0;
2387 r = ERROR_SUCCESS;
2390 msiobj_release(&package->hdr);
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;